Logo Search packages:      
Sourcecode: palapeli version File versions  Download package

void Palapeli::PatternConfiguration::populateWidget ( QWidget *  widget  )  [inherited]

Creates a layout with configuration widgets inside the given widget.

Definition at line 151 of file pattern-configuration.cpp.

References Palapeli::PatternConfiguration::Boolean, Palapeli::PatternConfiguration::Integer, Palapeli::PatternConfiguration::String, and Palapeli::PatternConfiguration::Variant.

{
      //temporary variables
      QWidget* widget = 0;
      KIntSpinBox* spinner = 0;
      QCheckBox* checker = 0;
      KLineEdit* lineEditor = 0;
      KComboBox* combo = 0;
      int currentIndex = -1;
      //create layout with configuration widgets in it
      QFormLayout* layout = new QFormLayout;
      QMapIterator<QByteArray, QString> iterConfigCaptions(p->m_configurationCaptions); //iterate over this to exclude everything which should not be visible to the user
      while (iterConfigCaptions.hasNext())
      {
            QByteArray key = iterConfigCaptions.next().key();
            QVariant value = p->m_configurationValues[key];
            QVariantList params = p->m_configurationParameters.value(key);
            switch (p->m_configurationDataTypes[key])
            {
                  case Integer:
                        widget = spinner = new KIntSpinBox(parentWidget);
                        spinner->setMinimum(params.value(0, 0).toInt());
                        spinner->setMaximum(params.value(1, 100).toInt());
                        spinner->setValue(value.toInt());
                        connect(spinner, SIGNAL(valueChanged(int)), &p->m_mapper, SLOT(map(int)));
                        break;
                  case Boolean:
                        widget = checker = new QCheckBox(parentWidget);
                        checker->setChecked(value.toBool());
                        connect(checker, SIGNAL(toggled(bool)), &p->m_mapper, SLOT(map(bool)));
                        break;
                  case String: case Variant:
                        if (params.isEmpty())
                        {
                              widget = lineEditor = new KLineEdit(parentWidget);
                              lineEditor->setText(value.toString());
                              connect(lineEditor, SIGNAL(textChanged(const QString&)), &p->m_mapper, SLOT(map(const QString&)));
                        }
                        else //use parameters as possible values
                        {
                              widget = combo = new KComboBox(parentWidget);
                              //while adding the options, try to locate the currently selected one
                              currentIndex = -1;
                              foreach (const QVariant &option, params)
                              {
                                    combo->addItem(option.toString());
                                    if (option.toString() == value.toString())
                                          currentIndex = combo->count() - 1; //because the item was inserted at the end of the list
                              }
                              if (currentIndex != -1)
                                    combo->setCurrentIndex(currentIndex);
                              connect(combo, SIGNAL(currentIndexChanged(const QString&)), &p->m_mapper, SLOT(map(const QString&)));
                        }
                        break;
            }
            p->m_mapper.addMapping(widget, key);
            layout->addRow(iterConfigCaptions.value(), widget);
      }
      parentWidget->setLayout(layout);
}


Generated by  Doxygen 1.6.0   Back to index