Changeset 15 in flair-src for trunk/tools/FlairGCS/src/DoubleSpinBox.cpp


Ignore:
Timestamp:
Apr 8, 2016, 3:40:57 PM (5 years ago)
Author:
Bayard Gildas
Message:

sources reformatted with flair-format-dir script

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tools/FlairGCS/src/DoubleSpinBox.cpp

    r10 r15  
    1111#include <QFormLayout>
    1212
    13 DoubleSpinBox::DoubleSpinBox(Layout* parent,int row, int col,QString name,QString suffix,QString value,float min,float max,float step,int decimals): FormLayout(parent,row,col,name,"DoubleSpinBox")
    14 {
    15     doublespinbox = new QDoubleSpinBox();
     13DoubleSpinBox::DoubleSpinBox(Layout *parent, int row, int col, QString name,
     14                             QString suffix, QString value, float min,
     15                             float max, float step, int decimals)
     16    : FormLayout(parent, row, col, name, "DoubleSpinBox") {
     17  doublespinbox = new QDoubleSpinBox();
    1618
    17     doublespinbox->setRange(min,max);
    18     doublespinbox->setSingleStep(step);
    19     doublespinbox->setDecimals(decimals);
    20     if(suffix!="") doublespinbox->setSuffix(suffix);
    21     adjust_decimals(value);
    22     doublespinbox->setValue(value.toDouble());
    23     doublespinbox_value=doublespinbox->cleanText();
     19  doublespinbox->setRange(min, max);
     20  doublespinbox->setSingleStep(step);
     21  doublespinbox->setDecimals(decimals);
     22  if (suffix != "")
     23    doublespinbox->setSuffix(suffix);
     24  adjust_decimals(value);
     25  doublespinbox->setValue(value.toDouble());
     26  doublespinbox_value = doublespinbox->cleanText();
    2427
    25     //event filter for qdoublespinbox and its child (qlinedit and incremnt qbuttons)
    26     doublespinbox->installEventFilter(this);
    27     QObjectList o_list = doublespinbox->children();
    28     for(int i = 0; i < o_list.length(); i++)
    29     {
    30         QLineEdit *cast = qobject_cast<QLineEdit*>(o_list[i]);
    31         if(cast)
    32             cast->installEventFilter(this);
    33     }
     28  // event filter for qdoublespinbox and its child (qlinedit and incremnt
     29  // qbuttons)
     30  doublespinbox->installEventFilter(this);
     31  QObjectList o_list = doublespinbox->children();
     32  for (int i = 0; i < o_list.length(); i++) {
     33    QLineEdit *cast = qobject_cast<QLineEdit *>(o_list[i]);
     34    if (cast)
     35      cast->installEventFilter(this);
     36  }
    3437
    35     object_layout->addRow(name,doublespinbox);
     38  object_layout->addRow(name, doublespinbox);
    3639
    37     connect(doublespinbox,SIGNAL(valueChanged(const QString &)),this, SLOT(valuechanged(const QString &)));
     40  connect(doublespinbox, SIGNAL(valueChanged(const QString &)), this,
     41          SLOT(valuechanged(const QString &)));
    3842
    39     SetValue(value);
     43  SetValue(value);
    4044}
    4145
    42 DoubleSpinBox::~DoubleSpinBox()
    43 {
    44     delete doublespinbox;
     46DoubleSpinBox::~DoubleSpinBox() { delete doublespinbox; }
     47
     48void DoubleSpinBox::adjust_decimals(QString value) {
     49  // auto adjust decimals
     50  QLocale locale;
     51  value.remove(locale.groupSeparator());
     52
     53  QStringList parts = value.split(locale.decimalPoint());
     54  if (parts.count() == 2) {
     55    doublespinbox->setDecimals(parts[1].size());
     56  }
    4557}
    4658
    47 void DoubleSpinBox::adjust_decimals(QString value)
    48 {
    49     //auto adjust decimals
    50     QLocale locale;
    51     value.remove(locale.groupSeparator());
     59bool DoubleSpinBox::eventFilter(QObject *object, QEvent *event) {
     60  if (object == doublespinbox && event->type() == QEvent::MouseButtonPress) {
     61    if (((QMouseEvent *)event)->button() == Qt::RightButton) {
     62      QMenu *menu = new QMenu("menu", doublespinbox);
     63      QAction *a, *b, *c, *z;
    5264
    53     QStringList parts = value.split(locale.decimalPoint());
    54     if(parts.count() == 2)
    55     {
    56         doublespinbox->setDecimals(parts[1].size());
     65      a = menu->addAction("add decimal");
     66      b = menu->addAction("remove decimal");
     67
     68      if (doublespinbox->decimals() == 0)
     69        b->setEnabled(false);
     70      z = menu->exec(((QMouseEvent *)event)->globalPos());
     71
     72      if (z == a)
     73        doublespinbox->setDecimals(doublespinbox->decimals() + 1);
     74      if (z == b)
     75        doublespinbox->setDecimals(doublespinbox->decimals() - 1);
     76      delete menu;
     77      return true;
    5778    }
     79  }
     80
     81  return object->eventFilter(object, event);
    5882}
    5983
    60 bool DoubleSpinBox::eventFilter(QObject *object, QEvent *event)
    61 {
    62     if(object==doublespinbox && event->type()==QEvent::MouseButtonPress)
    63     {
    64         if (((QMouseEvent*)event)->button() == Qt::RightButton)
    65         {
    66             QMenu * menu = new QMenu("menu", doublespinbox);
    67             QAction *a,*b,*c,*z;
    68 
    69             a=menu->addAction("add decimal");
    70             b=menu->addAction("remove decimal");
    71 
    72             if(doublespinbox->decimals()==0) b->setEnabled(false);
    73             z=menu->exec(((QMouseEvent*)event)->globalPos());
    74 
    75             if(z==a) doublespinbox->setDecimals(doublespinbox->decimals()+1);
    76             if(z==b) doublespinbox->setDecimals(doublespinbox->decimals()-1);
    77             delete menu;
    78             return true;
    79         }
    80     }
    81 
    82     return object->eventFilter(object, event);
     84void DoubleSpinBox::SetUptodate(void) {
     85  ui_to_var();
     86  ui_to_xml();
     87  visible_widget->setPalette(black_pal);
    8388}
    8489
    85 void DoubleSpinBox::SetUptodate(void)
    86 {
    87     ui_to_var();
    88     ui_to_xml();
    89     visible_widget->setPalette(black_pal);
     90void DoubleSpinBox::ui_to_var(void) {
     91  doublespinbox_value = doublespinbox->cleanText();
    9092}
    9193
    92 void DoubleSpinBox::ui_to_var(void)
    93 {
    94     doublespinbox_value=doublespinbox->cleanText();
     94void DoubleSpinBox::ui_to_xml(void) { SetValue(doublespinbox->cleanText()); }
     95
     96void DoubleSpinBox::Reset(void) {
     97  // le setvalue fait un arrondi pour l'affichage, la variable n'est donc plus
     98  // egale
     99  // on reprend la valeur de la boite et on force la couleur a noir
     100  adjust_decimals(doublespinbox_value);
     101  doublespinbox->setValue(doublespinbox_value.toDouble());
     102  doublespinbox_value = doublespinbox->cleanText();
     103  visible_widget->setPalette(black_pal);
    95104}
    96105
    97 void DoubleSpinBox::ui_to_xml(void)
    98 {
    99     SetValue(doublespinbox->cleanText());
     106void DoubleSpinBox::LoadEvent(QDomElement dom) {
     107  if (doublespinbox->isEnabled() == true) {
     108    doublespinbox->setValue((dom.attribute("value")).toDouble());
     109  }
    100110}
    101111
    102 void DoubleSpinBox::Reset(void)
    103 {
    104     //le setvalue fait un arrondi pour l'affichage, la variable n'est donc plus egale
    105     //on reprend la valeur de la boite et on force la couleur a noir
    106     adjust_decimals(doublespinbox_value);
    107     doublespinbox->setValue(doublespinbox_value.toDouble());
    108     doublespinbox_value= doublespinbox->cleanText();
     112void DoubleSpinBox::valuechanged(const QString &value) {
     113  if (value != doublespinbox_value) {
     114    visible_widget->setPalette(red_pal);
     115  } else {
    109116    visible_widget->setPalette(black_pal);
    110 
     117  }
    111118}
    112 
    113 void DoubleSpinBox::LoadEvent(QDomElement dom)
    114 {
    115     if(doublespinbox->isEnabled()==true)
    116     {
    117         doublespinbox->setValue((dom.attribute("value")).toDouble());
    118     }
    119 }
    120 
    121 void DoubleSpinBox::valuechanged(const QString &value)
    122 {
    123     if(value!=doublespinbox_value)
    124     {
    125         visible_widget->setPalette(red_pal);
    126     }
    127     else
    128     {
    129         visible_widget->setPalette(black_pal);
    130     }
    131 }
Note: See TracChangeset for help on using the changeset viewer.