bool QgsAttributeEditor::setValue( QWidget *editor, QgsVectorLayer *vl, int idx, const QVariant &value )
{
  if ( !editor )
    return false;

  QgsVectorLayer::EditType editType = vl->editType( idx );
  const QgsField &field = vl->pendingFields()[idx];
  QVariant::Type myFieldType = field.type();

  QSettings settings;
  QString nullValue = settings.value( "qgis/nullValue", "NULL" ).toString();

  switch ( editType )
  {
    case QgsVectorLayer::Classification:
    case QgsVectorLayer::UniqueValues:
    case QgsVectorLayer::Enumeration:
    case QgsVectorLayer::ValueMap:
    case QgsVectorLayer::ValueRelation:
    {
      QVariant v = value;
      QComboBox *cb = qobject_cast<QComboBox *>( editor );
      if ( !cb )
        return false;

      if ( v.isNull() )
      {
        v = nullValue;
      }

      int idx = cb->findData( v );
      if ( idx < 0 )
        return false;

      cb->setCurrentIndex( idx );
    }
    break;

    case QgsVectorLayer::DialRange:
    case QgsVectorLayer::SliderRange:
    case QgsVectorLayer::EditRange:
    {
      if ( myFieldType == QVariant::Int )
      {
        if ( editType == QgsVectorLayer::EditRange )
        {
          QSpinBox *sb = qobject_cast<QSpinBox *>( editor );
          if ( !sb )
            return false;
          sb->setValue( value.toInt() );
        }
        else
        {
          QAbstractSlider *sl = qobject_cast<QAbstractSlider *>( editor );
          if ( !sl )
            return false;
          sl->setValue( value.toInt() );
        }
        break;
      }
      else if ( myFieldType == QVariant::Double )
      {
        QDoubleSpinBox *dsb = qobject_cast<QDoubleSpinBox *>( editor );
        if ( !dsb )
          return false;
        dsb->setValue( value.toDouble() );
      }
    }

    case QgsVectorLayer::CheckBox:
    {
      QCheckBox *cb = qobject_cast<QCheckBox *>( editor );
      if ( cb )
      {
        QPair<QString, QString> states = vl->checkedState( idx );
        cb->setChecked( value == states.first );
        break;
      }
    }

    // fall-through

    case QgsVectorLayer::LineEdit:
    case QgsVectorLayer::UniqueValuesEditable:
    case QgsVectorLayer::Immutable:
    case QgsVectorLayer::UuidGenerator:
    default:
    {
      QLineEdit *le = qobject_cast<QLineEdit *>( editor );
      QTextEdit *te = qobject_cast<QTextEdit *>( editor );
      QPlainTextEdit *pte = qobject_cast<QPlainTextEdit *>( editor );
      if ( !le && !te && !pte )
        return false;

      QString text;
      if ( value.isNull() )
      {
        if ( myFieldType == QVariant::Int || myFieldType == QVariant::Double || myFieldType == QVariant::LongLong )
          text = "";
        else if ( editType == QgsVectorLayer::UuidGenerator )
          text = QUuid::createUuid().toString();
        else
          text = nullValue;
      }
      else
      {
        text = value.toString();
      }

      if ( le )
        le->setText( text );
      if ( te )
        te->setHtml( text );
      if ( pte )
        pte->setPlainText( text );
    }
    break;

    case QgsVectorLayer::FileName:
    case QgsVectorLayer::Calendar:
    {
      QLineEdit* le = qobject_cast<QLineEdit*>( editor );
      if ( !le )
      {
        le = editor->findChild<QLineEdit *>();
      }
      if ( !le )
      {
        return false;
      }
      le->setText( value.toString() );
    }
    break;
  }

  return true;
}
/**
  @brief Initialise un widget avec une liste de parametres
  @param widget Widget parent
  @param list Liste des parametres
  @remarks Les noms des widgets doivent correspondres avec les noms de paramètres
*/
void Configurable::configToWidget(QObject* widget,ConfigParamList& list){

    //scan les elements enfants
    for(ConfigParamList::const_iterator cur = list.begin(); cur != list.end(); cur++){
        QString name = cur->first;
        QString value = cur->second->getValue();
        QWidget* child = widget->findChild<QWidget*>(name);
        if(child==0){
            QPRINT("configToWidget: "+name+" not found");
            continue;
        }

        // QLineEdit ?
        QLineEdit *lineEdit = qobject_cast<QLineEdit *>(child);
        if(lineEdit){
           lineEdit->setText(value);
           continue;
        }

        // QComboBox ?
        QComboBox *comboBox = qobject_cast<QComboBox *>(child);
        if(comboBox){
            comboBox->setCurrentIndex(comboBox->findText(value));
            continue;
         }

        // QSpinBox ?
        QSpinBox *spinBox = qobject_cast<QSpinBox *>(child);
        if(spinBox){
            spinBox->setValue(value.toInt());
            continue;
         }


        // QDoubleSpinBox ?
        QDoubleSpinBox *doubleSpinBox = qobject_cast<QDoubleSpinBox *>(child);
        if(doubleSpinBox){
            doubleSpinBox->setValue(value.toInt());
            continue;
         }

        // QTextEdit ?
        QTextEdit *textEdit = qobject_cast<QTextEdit *>(child);
        if(textEdit){
            textEdit->setPlainText(value);
            continue;
         }

        // QPlainTextEdit ?
        QPlainTextEdit *plainTextEdit = qobject_cast<QPlainTextEdit *>(child);
        if(plainTextEdit){
            plainTextEdit->setPlainText(value);
            continue;
         }

        // QTimeEdit ?
        QTimeEdit *timeEdit = qobject_cast<QTimeEdit *>(child);
        if(timeEdit){
            timeEdit->setTime(QTime::fromString(value));
            continue;
         }

        // QDateTimeEdit ?
        QDateTimeEdit *dateTimeEdit = qobject_cast<QDateTimeEdit *>(child);
        if(dateTimeEdit){
            timeEdit->setDateTime(QDateTime::fromString(value));
            continue;
         }

        // QDateEdit ?
        QDateEdit *dateEdit = qobject_cast<QDateEdit *>(child);
        if(dateEdit){
            dateEdit->setDate(QDate::fromString(value));
            continue;
         }

        // QDial ?
        QDial *dial = qobject_cast<QDial *>(child);
        if(dial){
            dial->setValue(value.toInt());
            continue;
         }

        // QSlider ?
        QSlider *slider = qobject_cast<QSlider *>(child);
        if(slider){
            slider->setValue(value.toInt());
            continue;
         }

    }

}
Example #3
0
QmlItemNode QmlModelView::createQmlItemNode(const ItemLibraryEntry &itemLibraryEntry, const QPointF &position, QmlItemNode parentNode)
{
    if (!parentNode.isValid())
        parentNode = rootQmlItemNode();

    Q_ASSERT(parentNode.isValid());

    QmlItemNode newNode;

    try {
        RewriterTransaction transaction = beginRewriterTransaction();
        if (itemLibraryEntry.typeName().contains('.')) {

            const QString newImportUrl = itemLibraryEntry.requiredImport();

            if (!itemLibraryEntry.requiredImport().isEmpty()) {
                const QString newImportVersion = QString("%1.%2").arg(QString::number(itemLibraryEntry.majorVersion()), QString::number(itemLibraryEntry.minorVersion()));
                Import newImport = Import::createLibraryImport(newImportUrl, newImportVersion);

                foreach (const Import &import, model()->imports()) {
                    if (import.isLibraryImport()
                            && import.url() == newImport.url()
                            && import.version() == newImport.version()) {
                        // reuse this import
                        newImport = import;
                        break;
                    }
                }

                if (!model()->hasImport(newImport, true, true)) {
                    model()->changeImports(QList<Import>() << newImport, QList<Import>());
                }
            }
        }

        QList<QPair<QString, QVariant> > propertyPairList;
        propertyPairList.append(qMakePair(QString("x"), QVariant(round(position.x(), 4))));
        propertyPairList.append(qMakePair(QString("y"), QVariant(round(position.y(), 4))));

        if (itemLibraryEntry.qml().isEmpty()) {
            foreach (const PropertyContainer &property, itemLibraryEntry.properties())
                propertyPairList.append(qMakePair(property.name(), property.value()));

            newNode = createQmlItemNode(itemLibraryEntry.typeName(), itemLibraryEntry.majorVersion(), itemLibraryEntry.minorVersion(), propertyPairList);
        } else {
            QScopedPointer<Model> inputModel(Model::create("QtQuick.Rectangle", 1, 0, model()));
            inputModel->setFileUrl(model()->fileUrl());
            QPlainTextEdit textEdit;


            textEdit.setPlainText(Utils::FileReader::fetchQrc(itemLibraryEntry.qml()));
            NotIndentingTextEditModifier modifier(&textEdit);

            QScopedPointer<RewriterView> rewriterView(new RewriterView(RewriterView::Amend, 0));
            rewriterView->setCheckSemanticErrors(false);
            rewriterView->setTextModifier(&modifier);
            inputModel->attachView(rewriterView.data());

            if (rewriterView->errors().isEmpty() && rewriterView->rootModelNode().isValid()) {
                ModelNode rootModelNode = rewriterView->rootModelNode();
                inputModel->detachView(rewriterView.data());

                rootModelNode.variantProperty("x") = propertyPairList.first().second;
                rootModelNode.variantProperty("y") = propertyPairList.at(1).second;

                ModelMerger merger(this);
                newNode = merger.insertModel(rootModelNode);               
            }
        }

        if (parentNode.hasDefaultProperty()) {
            parentNode.nodeAbstractProperty(parentNode.defaultProperty()).reparentHere(newNode);
        }

        if (!newNode.isValid())
            return newNode;

        QString id;
        int i = 1;
        QString name(itemLibraryEntry.name().toLower());
        //remove forbidden characters
        name.replace(QRegExp(QLatin1String("[^a-zA-Z0-9_]")), QLatin1String("_"));
        do {
            id = name + QString::number(i);
            i++;
        } while (hasId(id)); //If the name already exists count upwards

        newNode.setId(id);

        if (!currentState().isBaseState()) {
            newNode.modelNode().variantProperty("opacity") = 0;
            newNode.setVariantProperty("opacity", 1);
        }

        Q_ASSERT(newNode.isValid());
    }
void SettingWidget::createValueWidget()
{
    rsArgument* argument = task->getArgument(option->name);
    
    switch(option->type) {
        case G_OPTION_ARG_FILENAME:
        case G_OPTION_ARG_STRING:
        case G_OPTION_ARG_STRING_ARRAY:
        case G_OPTION_ARG_CALLBACK:
        case G_OPTION_ARG_INT:
        case G_OPTION_ARG_INT64:
        case G_OPTION_ARG_DOUBLE:
            {
                // Display text box if number of values is not restricted
                if ( option->allowedValues == NULL ) {
                    if ( option->nLines < 2 ) {
                        QLineEdit *w = new QLineEdit();
                        valueWidget = w;
                        w->setPlaceholderText(option->cli_arg_description);
                        connect(w, SIGNAL(textChanged(QString)), this, SLOT(textChanged(QString)));
                        if ( argument != NULL ) {
                            w->setText(argument->value);
                        } else if ( option->defaultValue != NULL ) {
                            w->setText(option->defaultValue);
                        }
                    } else { // create a QTextEdit field instead
                        QPlainTextEdit *w = new QPlainTextEdit();
                        valueWidget = w;
                        connect(w, SIGNAL(textChanged()), this, SLOT(textChanged()));
                        if ( argument != NULL ) {
                            w->setPlainText(argument->value);
                        } else if ( option->defaultValue != NULL ) {
                            w->setPlainText(option->defaultValue);
                        }
                        QFontMetrics m(w->font()) ;
                        int rowHeight = m.lineSpacing() ;
                        w->setFixedHeight(option->nLines * rowHeight) ;
                        w->setLineWrapMode(QPlainTextEdit::NoWrap);
                    }
                } else { // if the allowed values are restricted display radio buttons instead
                    QWidget *w = new QWidget();
                    QBoxLayout *wLayout = new QBoxLayout(QBoxLayout::TopToBottom);
                    QButtonGroup *buttonGroup = new QButtonGroup();
                    buttonGroup->setExclusive(true);
                    valueWidget = w;
                    connect(buttonGroup, SIGNAL(buttonClicked(int)), this, SLOT(buttonClicked(int)));
                    
                    // go through all options and add a radio button for them
                    rsUIOptionValue** values = option->allowedValues;
                    for (size_t i=0; values[i] != NULL; i++ ) {
                        // add radio button
                        QRadioButton *b = new QRadioButton(QString("'")+QString(values[i]->name)+QString("'"));
                        QFont f("Arial", 12, QFont::Bold);
                        b->setFont(f);
                        buttonGroup->addButton(b, (int)i);
                        wLayout->addWidget(b);
                        
                        // set it to checked if it is the default or set value
                        b->setChecked(false);
                        if ( argument != NULL ) {
                            if ( ! strcmp(argument->value,values[i]->name) ) {
                                b->setChecked(true);
                            }
                        } else if ( ! strcmp(option->defaultValue,values[i]->name) ) {
                            b->setChecked(true);
                        }
                        
                        // add its description
                        QLabel *label = new QLabel(values[i]->description);
                        label->setIndent(22);
                        label->setWordWrap(true);
                        label->setContentsMargins(0, 0, 0, 4);
                        QFont f2("Arial", 11, QFont::Normal);
                        label->setFont(f2);
                        wLayout->addWidget(label);
                    }
                    w->setLayout(wLayout);
                }
            }
            break;
        /*
        case G_OPTION_ARG_INT:
        case G_OPTION_ARG_INT64:
            valueWidget = new QSpinBox();
            break;
        case G_OPTION_ARG_DOUBLE:
            valueWidget = new QDoubleSpinBox();
            break;
        */
        case G_OPTION_ARG_NONE:
            {
                QCheckBox *w = new QCheckBox("Enabled"); // new SwitchWidget();
                valueWidget = w;
                connect(w, SIGNAL(stateChanged(int)), this, SLOT(stateChanged(int)));
                if ( argument != NULL ) {
                    w->setCheckState(Qt::Checked);
                } else {
                    w->setCheckState(Qt::Unchecked);
                }
            }
            break;
        default:
            throw std::invalid_argument("UI argument type unknown");
    }
}
Example #5
0
ByteArrayModifier* ByteArrayModifier::create(const QString& data)
{
    QPlainTextEdit* edit = new QPlainTextEdit;
    edit->setPlainText(data);
    return new ByteArrayModifier(edit);
}
Example #6
0
void protoObject::propertyUpdated(QString propertyName){
    QObject *receiver = mapper->mapping(propertyName);
    QWidget *widget;

    if (receiver) return; //if not binding, just leave

    widget = qobject_cast<QLabel*>(receiver);
    if (widget) {
        QLabel* edit = qobject_cast<QLabel*>(receiver);
        QString value = this->property(propertyName.toLatin1()).toString();
        edit->blockSignals(true);
        edit->setText(edit->text().arg(value));
        edit->blockSignals(false);
    };

    widget = qobject_cast<QLineEdit*>(receiver);
    if (widget) {
        QLineEdit* edit = qobject_cast<QLineEdit*>(receiver);
        QString value = this->property(propertyName.toLatin1()).toString();
        edit->blockSignals(true);
        edit->setText(value);
        edit->blockSignals(false);
    };

    widget = qobject_cast<QComboBox*>(receiver);
    if (widget) {
        QComboBox* edit = qobject_cast<QComboBox*>(receiver);
        edit->blockSignals(true);
        edit->setCurrentIndex(edit->findData(this->property(propertyName.toLatin1()), Qt::UserRole));
        edit->blockSignals(false);
    };

    widget = qobject_cast<QRadioButton*>(receiver);
    if (widget) {
        QRadioButton* edit = qobject_cast<QRadioButton*>(receiver);
        bool value = this->property(propertyName.toLatin1()).toBool();
        edit->blockSignals(true);
        edit->setChecked(value);
        edit->blockSignals(false);
    };

    widget = qobject_cast<QCheckBox*>(receiver);
    if (widget) {
        QCheckBox* edit = qobject_cast<QCheckBox*>(receiver);
        bool value = this->property(propertyName.toLatin1()).toBool();
        edit->blockSignals(true);
        edit->setChecked(value);
        edit->blockSignals(false);
    };

    widget = qobject_cast<QPlainTextEdit*>(receiver);
    if (widget) {
        QPlainTextEdit* edit = qobject_cast<QPlainTextEdit*>(receiver);
        QString value = this->property(propertyName.toLatin1()).toString();
        edit->blockSignals(true);
        edit->setPlainText(value);
        edit->blockSignals(false);
    };

    widget = qobject_cast<QSpinBox*>(receiver);
    if (widget) {
        QSpinBox* edit = qobject_cast<QSpinBox*>(receiver);
        int value = this->property(propertyName.toLatin1()).toInt();
        edit->blockSignals(true);
        edit->setValue(value);
        edit->blockSignals(false);
    };

    widget = qobject_cast<QDoubleSpinBox*>(receiver);
    if (widget) {
        QDoubleSpinBox* edit = qobject_cast<QDoubleSpinBox*>(receiver);
        double value = this->property(propertyName.toLatin1()).toDouble();
        edit->blockSignals(true);
        edit->setValue(value);
        edit->blockSignals(false);
    };

    widget = qobject_cast<QDateTimeEdit*>(receiver);
    if (widget) {
        QDateTimeEdit* edit = qobject_cast<QDateTimeEdit*>(receiver);
        QDateTime value = this->property(propertyName.toLatin1()).toDateTime();
        edit->blockSignals(true);
        edit->setDateTime(value);
        edit->blockSignals(false);
    };
}
Example #7
0
void ResourceWizard::PageChanged(int PageId)
{
    //qDebug()<<"start"<<"PageId"<<PageId<<"CurrentPageId"<<CurrentPageId;
    if(CurrentPageId == 0)
    {
        MultiLanguageString str;
        str.SetTranslation("en",ui->DescriptionEn->text());
        str.SetTranslation("ru",ui->DescripnionRu->text());

        ResourceWidget->SetVariableName(ui->Name->text());
        ResourceWidget->SetDescription(str);
    }else if(CurrentPageId == 1)
    {
        ResourceWidget->SetTypeId(Type);

    }else if(CurrentPageId == 2)
    {
        if(Type == "FixedString")
        {
            QCheckBox * e = ResourceWidget->GetTemplateWidgetByType(false,Type)->findChild<QCheckBox *>("NotEmptyCheckBox");
            if(e)
                e->setChecked(ui->StringNotEmpty->isChecked());

            QLineEdit * FixedStringValue = ResourceWidget->GetTemplateWidgetByType(true,Type)->findChild<QLineEdit *>("FixedStringValue");
            if(FixedStringValue)
                FixedStringValue->setText(ui->StringDefaultValue->text());
        }
    }else if(CurrentPageId == 10)
    {
        if(IsAdditionalTab)
        {
            IsAdditionalTab = false;
            MultiLanguageString str;
            str.SetTranslation("en",ui->TabEn->text());
            str.SetTranslation("ru",ui->TabRu->text());
            ResourceWidget->SetSectionName(str);
        }
    }else if(CurrentPageId == 9)
    {
        if(IsAdditionalIf)
        {
            IsAdditionalIf = false;
            ResourceWidget->SetVisibilityConditionValue(ui->VisibilityValue->text());
            ResourceWidget->SetVisibilityConditionVariable(ui->VisibilityName->text());

        }
    }else if(CurrentPageId == 8)
    {
        if(Type == "Select")
        {
            QComboBox * SelectTypeCombo = ResourceWidget->GetTemplateWidgetByType(false,Type)->findChild<QComboBox *>("SelectTypeCombo");
            if(SelectTypeCombo)
                SelectTypeCombo->setCurrentText(ui->SelectType->currentText());

            QPlainTextEdit * SelectValuesEdit = ResourceWidget->GetTemplateWidgetByType(false,Type)->findChild<QPlainTextEdit *>("SelectValuesEdit");
            if(SelectValuesEdit)
                SelectValuesEdit->setPlainText(ui->SelectLines->toPlainText());

            QWidget *child = ResourceWidget->GetTemplateWidgetByType(true,Type)->findChild<QWidget *>("SelectWidget");
            QLayout * layout = child->layout();

            /*MultiSelect * OldSelect = child->findChild<MultiSelect *>();
            if(OldSelect)
                OldSelect->deleteLater();

            MultiSelect * Select = new MultiSelect(child);*/

            MultiSelect * Select = child->findChild<MultiSelect *>();

            QStringList list = ui->SelectLines->toPlainText().split(QRegExp("[\r\n]"),QString::SkipEmptyParts);

            MultiSelect *multi = ui->SelectDefaultValueContainer->findChild<MultiSelect *>();

            Select->Update(ui->SelectType->currentText(), list, multi->GetSelectedIndex());
            layout->addWidget(Select);


        }
    }else if(CurrentPageId == 7)
    {
        if(Type == "RandomString")
        {
            QLineEdit * RandomStringValue = ResourceWidget->GetTemplateWidgetByType(true,Type)->findChild<QLineEdit *>("RandomStringValue");
            if(RandomStringValue)
                RandomStringValue->setText(ui->RandomStringValue->text());
        }
    }else if(CurrentPageId == 4)
    {
        if(Type == "FixedInteger")
        {
            QSpinBox * min = ResourceWidget->GetTemplateWidgetByType(false,Type)->findChild<QSpinBox *>("EditMinimum");
            QSpinBox * max = ResourceWidget->GetTemplateWidgetByType(false,Type)->findChild<QSpinBox *>("EditMaximum");
            if(min)
                min->setValue(ui->MinValueNumber->value());
            if(max)
                max->setValue(ui->MaxValueNumber->value());

            QSpinBox * FixedIntegerValue = ResourceWidget->GetTemplateWidgetByType(true,Type)->findChild<QSpinBox *>("FixedIntegerValue");
            if(FixedIntegerValue)
                FixedIntegerValue->setValue(ui->Number->value());


        }

    }else if(CurrentPageId == 3)
    {

        if(Type == "RandomInteger")
        {
            QSpinBox * min = ResourceWidget->GetTemplateWidgetByType(false,Type)->findChild<QSpinBox *>("EditMinimum_2");
            QSpinBox * max = ResourceWidget->GetTemplateWidgetByType(false,Type)->findChild<QSpinBox *>("EditMaximum_2");
            if(min)
                min->setValue(ui->MinValueRange->value());
            if(max)
                max->setValue(ui->MaxValueRange->value());

            QSpinBox * RIMinimumValue = ResourceWidget->GetTemplateWidgetByType(true,Type)->findChild<QSpinBox *>("RIMinimumValue");
            if(RIMinimumValue)
                RIMinimumValue->setValue(ui->NumberMin->value());

            QSpinBox * RIMaximumValue = ResourceWidget->GetTemplateWidgetByType(true,Type)->findChild<QSpinBox *>("RIMaximumValue");
            if(RIMaximumValue)
                RIMaximumValue->setValue(ui->NumberMax->value());
        }
    }else if(CurrentPageId == 5)
    {
        if(Type == "LinesFromFile")
        {

            QCheckBox * FileRead = ResourceWidget->GetTemplateWidgetByType(true,Type)->findChild<QCheckBox *>("FileRead");
            if(FileRead)
                FileRead->setChecked(!ui->OnlyWrite->isChecked());

            QCheckBox * FileWrite = ResourceWidget->GetTemplateWidgetByType(true,Type)->findChild<QCheckBox *>("FileWrite");
            if(FileWrite)
                FileWrite->setChecked(!ui->OnlyRead->isChecked());

            QCheckBox * FileMix = ResourceWidget->GetTemplateWidgetByType(true,Type)->findChild<QCheckBox *>("FileMix");
            if(FileMix)
                FileMix->setChecked(ui->MixLines->isChecked());


        }
        if(Type == "FilesFromDirectory")
        {
            QCheckBox * DirectoryClean = ResourceWidget->GetTemplateWidgetByType(true,Type)->findChild<QCheckBox *>("DirectoryClean");
            if(DirectoryClean)
                DirectoryClean->setChecked(!ui->OnlyRead->isChecked());

            QCheckBox * DirectoryMix = ResourceWidget->GetTemplateWidgetByType(true,Type)->findChild<QCheckBox *>("DirectoryMix");
            if(DirectoryMix)
                DirectoryMix->setChecked(ui->MixLines->isChecked());

        }

        if(Type == "Database")
        {
            QCheckBox * DatabaseClear = ResourceWidget->GetTemplateWidgetByType(true,Type)->findChild<QCheckBox *>("DatabaseClear");
            if(DatabaseClear)
                DatabaseClear->setChecked(!ui->OnlyRead->isChecked());

            QCheckBox * DatabaseMix = ResourceWidget->GetTemplateWidgetByType(true,Type)->findChild<QCheckBox *>("DatabaseMix");
            if(DatabaseMix)
                DatabaseMix->setChecked(ui->MixLines->isChecked());
        }
    }else if(CurrentPageId == 6)
    {
        int Success = 0;
        int Fails = 0;
        if(ui->EachLineOneTime->isChecked())
        {
            Success = 1;
            Fails = 1;
        }else if(ui->EachLineSeveralTimes->isChecked())
        {
            Success = 10;
            Fails = 10;
        }else if(ui->EachLineAnyNumberOfTimes->isChecked())
        {
            Success = 100000;
            Fails = 100000;
        }

        if(Type == "LinesFromFile")
        {
            QSpinBox * FileMaxSuccess = ResourceWidget->GetTemplateWidgetByType(true,Type)->findChild<QSpinBox *>("FileMaxSuccess");
            if(FileMaxSuccess)
                FileMaxSuccess->setValue(Success);

            QSpinBox * FileMaxFail = ResourceWidget->GetTemplateWidgetByType(true,Type)->findChild<QSpinBox *>("FileMaxFail");
            if(FileMaxFail)
                FileMaxFail->setValue(Fails);
        }

        if(Type == "FilesFromDirectory")
        {
            QSpinBox * DirectoryMaxSuccess = ResourceWidget->GetTemplateWidgetByType(true,Type)->findChild<QSpinBox *>("DirectoryMaxSuccess");
            if(DirectoryMaxSuccess)
                DirectoryMaxSuccess->setValue(Success);

            QSpinBox * DirectoryMaxFail = ResourceWidget->GetTemplateWidgetByType(true,Type)->findChild<QSpinBox *>("DirectoryMaxFail");
            if(DirectoryMaxFail)
                DirectoryMaxFail->setValue(Fails);

        }

        if(Type == "Database")
        {
            QSpinBox * DatabaseMaxSuccess = ResourceWidget->GetTemplateWidgetByType(true,Type)->findChild<QSpinBox *>("DatabaseMaxSuccess");
            if(DatabaseMaxSuccess)
                DatabaseMaxSuccess->setValue(Success);

            QSpinBox * DatabaseMaxFail = ResourceWidget->GetTemplateWidgetByType(true,Type)->findChild<QSpinBox *>("DatabaseMaxFail");
            if(DatabaseMaxFail)
                DatabaseMaxFail->setValue(Fails);
        }

        if(Type == "LinesFromUrl")
        {
            QSpinBox * UrlMaxSuccess = ResourceWidget->GetTemplateWidgetByType(true,Type)->findChild<QSpinBox *>("UrlMaxSuccess");
            if(UrlMaxSuccess)
                UrlMaxSuccess->setValue(Success);

            QSpinBox * UrlMaxFail = ResourceWidget->GetTemplateWidgetByType(true,Type)->findChild<QSpinBox *>("UrlMaxFail");
            if(UrlMaxFail)
                UrlMaxFail->setValue(Fails);
        }
    }

    if(PageId > CurrentPageId)
    {
        if(PageId == 2 && Type != "FixedString")
        {
            next();
            return;
        }
        if(PageId == 3 && Type != "RandomInteger")
        {
            next();
            return;
        }
        if(PageId == 4 && Type != "FixedInteger")
        {
            next();
            return;
        }
        if(PageId == 5 && Type != "LinesFromFile" && Type != "FilesFromDirectory" && Type != "Database")
        {
            next();
            return;
        }
        if(PageId == 6 && Type != "LinesFromFile" && Type != "FilesFromDirectory" && Type != "Database" && Type != "LinesFromUrl")
        {
            next();
            return;
        }
        if(PageId == 7 && Type != "RandomString")
        {
            next();
            return;
        }
        if(PageId == 8 && Type != "Select")
        {
            next();
            return;
        }
        if(PageId == 9 && !IsAdditionalIf)
        {
            next();
            return;
        }
        if(PageId == 10 && !IsAdditionalTab)
        {
            next();
            return;
        }
    }else
    {
        if(PageId == 2 && Type != "FixedString")
        {
            back();
            return;
        }
        if(PageId == 3 && Type != "RandomInteger")
        {
            back();
            return;
        }
        if(PageId == 4 && Type != "FixedInteger")
        {
            back();
            return;
        }
        if(PageId == 5 && Type != "LinesFromFile" && Type != "FilesFromDirectory" && Type != "Database")
        {
            back();
            return;
        }
        if(PageId == 6 && Type != "LinesFromFile" && Type != "FilesFromDirectory" && Type != "Database" && Type != "LinesFromUrl")
        {
            back();
            return;
        }
        if(PageId == 7 && Type != "RandomString")
        {
            back();
            return;
        }
        if(PageId == 8 && Type != "Select")
        {
            back();
            return;
        }
        if(PageId == 9 && !IsAdditionalIf)
        {
            back();
            return;
        }
        if(PageId == 10 && !IsAdditionalTab)
        {
            back();
            return;
        }
    }

    CurrentPageId = PageId;
}
ConfigurationDialog::ConfigurationDialog(QWidget *parent) : KPageDialog(parent)
{
	setCaption(i18nc("@title:window", "Configure Kaffeine"));

	QWidget *widget = new QWidget(this);
	QGridLayout *gridLayout = new QGridLayout(widget);

	startupDisplayModeBox = new KComboBox(widget);
	startupDisplayModeBox->addItem(i18nc("@item:inlistbox 'Startup display mode:'",
		"Normal Mode"));
	startupDisplayModeBox->addItem(i18nc("@item:inlistbox 'Startup display mode:'",
		"Minimal Mode"));
	startupDisplayModeBox->addItem(i18nc("@item:inlistbox 'Startup display mode:'",
		"Full Screen Mode"));
	startupDisplayModeBox->addItem(i18nc("@item:inlistbox 'Startup display mode:'",
		"Remember Last Setting"));
	startupDisplayModeBox->setCurrentIndex(Configuration::instance()->getStartupDisplayMode());
	gridLayout->addWidget(startupDisplayModeBox, 0, 1);

	QLabel *label = new QLabel(i18nc("@label:listbox", "Startup display mode:"), widget);
	label->setBuddy(startupDisplayModeBox);
	gridLayout->addWidget(label, 0, 0);

	shortSkipBox = new QSpinBox(widget);
	shortSkipBox->setRange(1, 600);
	shortSkipBox->setValue(Configuration::instance()->getShortSkipDuration());
	gridLayout->addWidget(shortSkipBox, 1, 1);

	label = new QLabel(i18nc("@label:spinbox", "Short skip duration:"), widget);
	label->setBuddy(shortSkipBox);
	gridLayout->addWidget(label, 1, 0);

	longSkipBox = new QSpinBox(widget);
	longSkipBox->setRange(1, 600);
	longSkipBox->setValue(Configuration::instance()->getLongSkipDuration());
	gridLayout->addWidget(longSkipBox, 2, 1);

	label = new QLabel(i18nc("@label:spinbox", "Long skip duration:"), widget);
	label->setBuddy(longSkipBox);
	gridLayout->addWidget(label, 2, 0);
	gridLayout->setRowStretch(3, 1);

	KPageWidgetItem *page = new KPageWidgetItem(widget, i18nc("@title:group", "General"));
	page->setIcon(KIcon(QLatin1String("configure")));
	addPage(page);

	widget = new QWidget(this);
	gridLayout = new QGridLayout(widget);

	label = new QLabel(i18nc("@label:textbox", "Log messages:"), widget);
	gridLayout->addWidget(label, 0, 0);

	QPushButton *pushButton = new QPushButton(i18nc("@action:button", "Show dmesg"));
	pushButton->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
	connect(pushButton, SIGNAL(clicked()), this, SLOT(showDmesg()));
	gridLayout->addWidget(pushButton, 0, 1);

	QPlainTextEdit *textEdit = new QPlainTextEdit(widget);
	textEdit->setPlainText(Log::getLog());
	textEdit->setReadOnly(true);
	gridLayout->addWidget(textEdit, 1, 0, 1, 2);
	gridLayout->setRowStretch(2, 1);

	page = new KPageWidgetItem(widget, i18nc("@title:group", "Diagnostics"));
	page->setIcon(KIcon(QLatin1String("page-zoom")));
	addPage(page);
}