Exemple #1
0
// ----------------------------------------------------------------------------
// Widget
// ----------------------------------------------------------------------------
Widget::Widget(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::Widget)
{
    ui->setupUi(this);
    initializeControl();
}
Exemple #2
0
MainWindow::MainWindow(QWidget *parent) :
  QMainWindow(parent),
  ui(new Ui::MainWindow)
{
  ui->setupUi(this);
  initializeControl();
}
Exemple #3
0
// Accessing and changing the different control widgets (QComboBox, QSpinBox
// etc.) requires different member functions and so the controls cannot be
// treated polymorphically.  The following routine initializes the controls and
// (in the initializeControl subroutines) also binds Actions to be used later to
// reset and update the controls.  This allows all the controls to be treated in
// a similar way.  What this means is that this function should be the only one
// that has the implementation case switch logic and also the only one that needs
// to perform dynamic casts on the controls.
void InputDialog::initializeControls() {

   QList<QWidget*> controls(findChildren<QWidget*>());
   QWidget* control;
   QString name, value;
   Option opt;

   for (int i = 0; i < controls.count(); ++i) {
       control = controls[i];
       name = control->objectName().toUpper();

       if (m_db.get(name, opt)) {

          switch (opt.getImplementation()) {

             case Option::Impl_None:
             break;

             case Option::Impl_Combo: {
                QComboBox* combo = qobject_cast<QComboBox*>(control);
                Q_ASSERT(combo);
                initializeControl(opt, combo);
             }
             break;

             case Option::Impl_Check: {
                QCheckBox* check = qobject_cast<QCheckBox*>(control);
                Q_ASSERT(check);
                initializeControl(opt, check);
             }
             break;

             case Option::Impl_Text: {
                QLineEdit* edit = qobject_cast<QLineEdit*>(control);
                Q_ASSERT(edit);
                initializeControl(opt, edit);
             }
             break;

             case Option::Impl_Spin: {
                QSpinBox* spin = qobject_cast<QSpinBox*>(control);
                Q_ASSERT(spin);
                initializeControl(opt, spin);
             }
             break;

             case Option::Impl_DSpin: {
                QDoubleSpinBox* dspin = qobject_cast<QDoubleSpinBox*>(control);
                Q_ASSERT(dspin);
                initializeControl(opt, dspin);
             }
             break;

             case Option::Impl_Radio: {
                QRadioButton* radio = qobject_cast<QRadioButton*>(control);
                Q_ASSERT(radio);
                initializeControl(opt, radio);
             }
             break;

             default: {
                qDebug() << "Error in QChem::InputDialog::initializeControl():\n"
                         << "  Could not initialize control " << name << "\n"
                         << "  Widget does not match database.  Impl:"
                         << opt.getImplementation();
             }
             break;
          }


          if (m_reg.exists(name)) m_reg.get(name).setValue(opt.getDefaultValue());

       }

    }
}