QScriptValue UniversalInputDialogScript::add(const QScriptValue& def, const QScriptValue& description, const QScriptValue& id){ QWidget* w = 0; if (def.isArray()) { QStringList options; QScriptValueIterator it(def); while (it.hasNext()) { it.next(); if (it.flags() & QScriptValue::SkipInEnumeration) continue; if (it.value().isString() || it.value().isNumber()) options << it.value().toString(); else engine->currentContext()->throwError("Invalid default value in array (must be string or number): "+it.value().toString()); } w = addComboBox(ManagedProperty::fromValue(options), description.toString()); } else if (def.isBool()) { w = addCheckBox(ManagedProperty::fromValue(def.toBool()), description.toString()); } else if (def.isNumber()) { w = addDoubleSpinBox(ManagedProperty::fromValue(def.toNumber()), description.toString()); } else if (def.isString()) { w = addLineEdit(ManagedProperty::fromValue(def.toString()), description.toString()); } else { engine->currentContext()->throwError(tr("Invalid default value: %1").arg(def.toString())); return QScriptValue(); } if (id.isValid()) properties.last().name = id.toString(); return engine->newQObject(w); }
ChecklistGuidePageCurves::ChecklistGuidePageCurves(const QString &title) : ChecklistGuidePage (title) { LOG4CPP_INFO_S ((*mainCat)) << "ChecklistGuidePageCurves::ChecklistGuidePageCurves"; const QString WHATS_THIS_CURVE (tr ("Curve name. Empty if unused.")); const QString WHATS_THIS_LINES (tr ("Draw lines between points in each curve.")); const QString WHATS_THIS_POINTS (tr ("Draw points in each curve, without lines between the points.")); addHtml (QString ("<p>%1</p>") .arg (tr ("What are the names of the curves that are to be digitized? At least one entry is required."))); m_edit = new ChecklistLineEdit* [NUM_CURVE_NAMES()]; for (int i = 0; i < NUM_CURVE_NAMES(); i++) { m_edit [i] = new ChecklistLineEdit; connect (m_edit [i], SIGNAL (signalKeyRelease()), this, SLOT (slotTableChanged())); addLineEdit (m_edit [i], WHATS_THIS_CURVE); } SettingsForGraph settingsForGraph; QString curveName = settingsForGraph.defaultCurveName (1, DEFAULT_GRAPH_CURVE_NAME); m_edit [0]->setText (curveName); addHtml ("<p> </p>"); addHtml (QString ("<p>%1</p>") .arg (tr ("How are those curves drawn?"))); m_btnLines = addLabelAndRadioButton (tr ("With lines (with or without points)"), WHATS_THIS_LINES); m_btnPoints = addLabelAndRadioButton (tr ("With points only (no lines between points)"), WHATS_THIS_POINTS); m_btnLines->setChecked (true); // Default encourages digitizing using the lines, since that is easier }
QgsGrassModuleOption::QgsGrassModuleOption( QgsGrassModule *module, QString key, QDomElement &qdesc, QDomElement &gdesc, QDomNode &gnode, bool direct, QWidget * parent ) : QgsGrassModuleGroupBoxItem( module, key, qdesc, gdesc, gnode, direct, parent ) , mControlType( NoControl ) , mValueType( String ) , mOutputType( None ) , mHaveLimits( false ) , mMin( INT_MAX ) , mMax( INT_MIN ) , mComboBox( 0 ) , mIsOutput( false ) , mValidator( 0 ) , mLayout( 0 ) , mUsesRegion( false ) { QgsDebugMsg( "entered" ); setSizePolicy( QSizePolicy::MinimumExpanding, QSizePolicy::Minimum ); if ( mHidden ) hide(); mLayout = new QVBoxLayout(); // Is it output? QDomNode promptNode = gnode.namedItem( "gisprompt" ); if ( !promptNode.isNull() ) { QDomElement promptElem = promptNode.toElement(); QString element = promptElem.attribute( "element" ); QString age = promptElem.attribute( "age" ); if ( age == "new" ) { mOutputElement = element; mIsOutput = true; if ( element == "vector" ) { mOutputType = Vector; } else if ( element == "cell" ) { mOutputType = Raster; } } } // String without options if ( !mHidden ) { QDomElement gelem = gnode.toElement(); // Output option may have missing gisprompt if output may be both vector and raster according to other options (e.g. v.kernel) // outputType qgm attribute allows forcing an output type // Predefined values ? QDomNode valuesNode = gnode.namedItem( "values" ); QDomElement valuesElem = valuesNode.toElement(); // null if valuesNode is null if ( !valuesNode.isNull() && valuesNode.childNodes().count() > 1 ) { setLayout( mLayout ); // predefined values -> ComboBox or CheckBox // one or many? if ( gelem.attribute( "multiple" ) == "yes" ) { mControlType = CheckBoxes; } else { mControlType = ComboBox; mComboBox = new QComboBox( this ); mLayout->addWidget( mComboBox ); } // List of values to be excluded QStringList exclude = qdesc.attribute( "exclude" ).split( ',', QString::SkipEmptyParts ); QDomNode valueNode = valuesElem.firstChild(); while ( !valueNode.isNull() ) { QDomElement valueElem = valueNode.toElement(); if ( !valueElem.isNull() && valueElem.tagName() == "value" ) { QDomNode n = valueNode.namedItem( "name" ); if ( !n.isNull() ) { QDomElement e = n.toElement(); QString val = e.text().trimmed(); if ( exclude.contains( val ) == 0 ) { n = valueNode.namedItem( "description" ); QString desc; if ( !n.isNull() ) { e = n.toElement(); desc = e.text().trimmed(); } else { desc = val; } desc.replace( 0, 1, desc.left( 1 ).toUpper() ); if ( mControlType == ComboBox ) { mComboBox->addItem( desc ); if ( mAnswer.length() > 0 && val == mAnswer ) { mComboBox->setCurrentIndex( mComboBox->count() - 1 ); } } else { QgsGrassModuleCheckBox *cb = new QgsGrassModuleCheckBox( desc, this ); mCheckBoxes.push_back( cb ); mLayout->addWidget( cb ); } mValues.push_back( val ); } } } valueNode = valueNode.nextSibling(); } } else // No values { // Line edit mControlType = LineEdit; // Output option may have missing gisprompt if output may be both vector and raster according to other options (e.g. v.kernel) // outputType qgm attribute allow forcing an output type QgsDebugMsg( "outputType = " + qdesc.attribute( "outputType" ) ); if ( qdesc.hasAttribute( "outputType" ) ) { QString outputType = qdesc.attribute( "outputType" ); mIsOutput = true; if ( outputType == "vector" ) { mOutputElement = "vector"; mOutputType = Vector; } else if ( outputType == "raster" ) { mOutputElement = "cell"; mOutputType = Raster; } else { mErrors << tr( "Unknown outputType" ) + " : " + outputType; } } if ( gelem.attribute( "type" ) == "integer" ) { mValueType = Integer; } else if ( gelem.attribute( "type" ) == "float" ) { mValueType = Double; } QStringList minMax; if ( valuesNode.childNodes().count() == 1 ) { QDomNode valueNode = valuesElem.firstChild(); QDomNode n = valueNode.namedItem( "name" ); if ( !n.isNull() ) { QDomElement e = n.toElement(); QString val = e.text().trimmed(); minMax = val.split( "-" ); if ( minMax.size() == 2 ) { mHaveLimits = true; mMin = minMax.at( 0 ).toDouble(); mMax = minMax.at( 1 ).toDouble(); } } } QDomNode keydescNode = gnode.namedItem( "keydesc" ); if ( !keydescNode.isNull() ) { // fixed number of line edits // Example: // <keydesc> // <item order="1">rows</item> // <item order="2">columns</item> // </keydesc> QDomNodeList keydescs = keydescNode.childNodes(); for ( int k = 0; k < keydescs.count(); k++ ) { QDomNode nodeItem = keydescs.at( k ); QString itemDesc = nodeItem.toElement().text().trimmed(); //QString itemDesc = nodeItem.firstChild().toText().data(); QgsDebugMsg( "keydesc item = " + itemDesc ); addLineEdit(); } setLayout( mLayout ); } else if ( gelem.attribute( "multiple" ) == "yes" ) { // variable number of line edits // add/delete buttons for multiple options QHBoxLayout *l = new QHBoxLayout( this ); QVBoxLayout *vl = new QVBoxLayout(); l->insertLayout( -1, mLayout ); l->insertLayout( -1, vl ); // TODO: how to keep both buttons on the top? QPushButton *b = new QPushButton( "+", this ); connect( b, SIGNAL( clicked() ), this, SLOT( addLineEdit() ) ); vl->addWidget( b, 0, Qt::AlignTop ); b = new QPushButton( "-", this ); connect( b, SIGNAL( clicked() ), this, SLOT( removeLineEdit() ) ); vl->addWidget( b, 0, Qt::AlignTop ); // Don't enable this, it makes the group box expanding // vl->addStretch(); } else { // only one line edit addLineEdit(); setLayout( mLayout ); } } } mUsesRegion = false; QString region = qdesc.attribute( "region" ); if ( region.length() > 0 ) { if ( region == "yes" ) mUsesRegion = true; } else { QgsDebugMsg( "\n\n\n\n**************************" ); QgsDebugMsg( QString( "isOutput = %1" ).arg( isOutput() ) ); QgsDebugMsg( QString( "mOutputType = %1" ).arg( mOutputType ) ); if ( isOutput() && mOutputType == Raster ) mUsesRegion = true; } QgsDebugMsg( QString( "mUsesRegion = %1" ).arg( mUsesRegion ) ); }