void MicroSelectWidget::updateFromAllowed() { QString oldFamily = m_pMicroFamily->currentText(); m_pMicroFamily->clear(); #define CHECK_ADD(family) \ if ( (m_allowedAsmSet & AsmInfo::family) \ && !MicroLibrary::self()->microIDs( AsmInfo::family, \ m_allowedGpsimSupport, m_allowedFlowCodeSupport, m_allowedMicrobeSupport ).isEmpty() ) { \ m_pMicroFamily->insertItem( m_pMicroFamily->count(), AsmInfo::setToString(AsmInfo::family) ); \ } CHECK_ADD(PIC12) CHECK_ADD(PIC14) CHECK_ADD(PIC16); #undef CHECK_ADD if ( m_pMicroFamily->contains(oldFamily) ) { //m_pMicroFamily->setCurrentText(oldFamily); // 2018.12.07 { QComboBox *c = m_pMicroFamily; QString text = oldFamily; int i = c->findText(text); if (i != -1) c->setCurrentIndex(i); else if (c->isEditable()) c->setEditText(text); else c->setItemText(c->currentIndex(), text); } } microFamilyChanged(oldFamily); }
void MicroSelectWidget::setMicro( const QString & id ) { MicroInfo * info = MicroLibrary::self()->microInfoWithID(id); if (!info) return; m_pMicro->clear(); m_pMicro->insertItems( m_pMicro->count(), MicroLibrary::self()->microIDs( info->instructionSet()->set() ) ); //m_pMicro->setCurrentText(id); // 2018.12.07 { QComboBox *c = m_pMicro; QString text = id; int i = c->findText(text); if (i != -1) c->setCurrentIndex(i); else if (c->isEditable()) c->setEditText(text); else c->setItemText(c->currentIndex(), text); } //m_pMicroFamily->setCurrentText( AsmInfo::setToString( info->instructionSet()->set() ) ); // 2018.12.07 { QComboBox *c = m_pMicroFamily; QString text = AsmInfo::setToString( info->instructionSet()->set() ); int i = c->findText(text); if (i != -1) c->setCurrentIndex(i); else if (c->isEditable()) c->setEditText(text); else c->setItemText(c->currentIndex(), text); } }
void ComboBoxDelegate::setEditorData(QWidget *editor, const QModelIndex &index) const { if (QString(editor->metaObject()->className())==tr("QComboBox")){ QString text = index.model()->data(index, Qt::EditRole).toString(); QComboBox *cb = static_cast<QComboBox*>(editor); int i = 0; for(int j=1; j<=n_element; j++) { if( text.toStdString() == element_data[j-1].symbol ) { i = j-1; } } if (i != -1) cb->setCurrentIndex(i); else if (cb->isEditable()) cb->setEditText(text); else cb->setCurrentIndex(0); } else QItemDelegate::setEditorData(editor,index); }
void ComPortPicker::populate(QComboBox &box, const QString &settingsKey) { const QList<QextPortInfo> ports = QextSerialEnumerator::getPorts(); const QString defaultPortName = SettingsManager::value(settingsKey).toString(); box.clear(); for (const QextPortInfo &info : ports) { const QRegExp portNameRegexp("COM\\d+", Qt::CaseInsensitive); if (portNameRegexp.indexIn(info.portName) != -1) { const QString portName = portNameRegexp.cap(); box.addItem(portName); } } const int defaultIndex = box.findText(defaultPortName); if (defaultIndex != -1) { box.setCurrentIndex(defaultIndex); } else if (box.isEditable()) { box.setCurrentText(defaultPortName); } }
QWidget *QgsAttributeEditor::createAttributeEditor( QWidget *parent, QWidget *editor, QgsVectorLayer *vl, int idx, const QVariant &value, QMap<int, QWidget*> &proxyWidgets ) { if ( !vl ) return 0; QWidget *myWidget = 0; QgsVectorLayer::EditType editType = vl->editType( idx ); const QgsField &field = vl->pendingFields()[idx]; QVariant::Type myFieldType = field.type(); bool synchronized = false; switch ( editType ) { case QgsVectorLayer::UniqueValues: { QList<QVariant> values; vl->dataProvider()->uniqueValues( idx, values ); QComboBox *cb = comboBox( editor, parent ); if ( cb ) { cb->setEditable( false ); for ( QList<QVariant>::iterator it = values.begin(); it != values.end(); it++ ) cb->addItem( it->toString(), it->toString() ); myWidget = cb; } } break; case QgsVectorLayer::Enumeration: { QStringList enumValues; vl->dataProvider()->enumValues( idx, enumValues ); QComboBox *cb = comboBox( editor, parent ); if ( cb ) { QStringList::const_iterator s_it = enumValues.constBegin(); for ( ; s_it != enumValues.constEnd(); ++s_it ) { cb->addItem( *s_it, *s_it ); } myWidget = cb; } } break; case QgsVectorLayer::ValueMap: { const QMap<QString, QVariant> &map = vl->valueMap( idx ); QComboBox *cb = comboBox( editor, parent ); if ( cb ) { for ( QMap<QString, QVariant>::const_iterator it = map.begin(); it != map.end(); it++ ) { cb->addItem( it.key(), it.value() ); } myWidget = cb; } } break; case QgsVectorLayer::ValueRelation: { const QgsVectorLayer::ValueRelationData &data = vl->valueRelation( idx ); QgsVectorLayer *layer = qobject_cast<QgsVectorLayer*>( QgsMapLayerRegistry::instance()->mapLayer( data.mLayer ) ); QMap< QString, QString > map; int fi = -1; if ( layer ) { int ki = layer->fieldNameIndex( data.mOrderByValue ? data.mValue : data.mKey ); int vi = layer->fieldNameIndex( data.mOrderByValue ? data.mKey : data.mValue ); if ( !data.mFilterAttributeColumn.isNull() ) fi = layer->fieldNameIndex( data.mFilterAttributeColumn ); if ( ki >= 0 && vi >= 0 ) { QgsAttributeList attributes; attributes << ki; attributes << vi; if ( fi >= 0 ) attributes << fi; layer->select( attributes, QgsRectangle(), false ); QgsFeature f; while ( layer->nextFeature( f ) ) { if ( fi >= 0 && f.attributeMap()[ fi ].toString() != data.mFilterAttributeValue ) continue; map.insert( f.attributeMap()[ ki ].toString(), f.attributeMap()[ vi ].toString() ); } } } if ( !data.mAllowMulti ) { QComboBox *cb = comboBox( editor, parent ); if ( cb ) { if ( data.mAllowNull ) { QSettings settings; cb->addItem( tr( "(no selection)" ), settings.value( "qgis/nullValue", "NULL" ).toString() ); } for ( QMap< QString, QString >::const_iterator it = map.begin(); it != map.end(); it++ ) { if ( data.mOrderByValue ) cb->addItem( it.key(), it.value() ); else cb->addItem( it.value(), it.key() ); } myWidget = cb; } } else { QListWidget *lw = listWidget( editor, parent ); if ( lw ) { QStringList checkList = value.toString().remove( QChar( '{' ) ).remove( QChar( '}' ) ).split( "," ); for ( QMap< QString, QString >::const_iterator it = map.begin(); it != map.end(); it++ ) { QListWidgetItem *item; if ( data.mOrderByValue ) { item = new QListWidgetItem( it.key() ); item->setData( Qt::UserRole, it.value() ); item->setCheckState( checkList.contains( it.value() ) ? Qt::Checked : Qt::Unchecked ); } else { item = new QListWidgetItem( it.value() ); item->setData( Qt::UserRole, it.key() ); item->setCheckState( checkList.contains( it.key() ) ? Qt::Checked : Qt::Unchecked ); } lw->addItem( item ); } myWidget = lw; } } } break; case QgsVectorLayer::Classification: { QMap<QString, QString> classes; const QgsUniqueValueRenderer *uvr = dynamic_cast<const QgsUniqueValueRenderer *>( vl->renderer() ); if ( uvr ) { const QList<QgsSymbol *> symbols = uvr->symbols(); for ( int i = 0; i < symbols.size(); i++ ) { QString label = symbols[i]->label(); QString name = symbols[i]->lowerValue(); if ( label == "" ) label = name; classes.insert( name, label ); } } const QgsCategorizedSymbolRendererV2 *csr = dynamic_cast<const QgsCategorizedSymbolRendererV2 *>( vl->rendererV2() ); if ( csr ) { const QgsCategoryList &categories = (( QgsCategorizedSymbolRendererV2 * )csr )->categories(); // FIXME: QgsCategorizedSymbolRendererV2::categories() should be const for ( int i = 0; i < categories.size(); i++ ) { QString label = categories[i].label(); QString value = categories[i].value().toString(); if ( label.isEmpty() ) label = value; classes.insert( value, label ); } } QComboBox *cb = comboBox( editor, parent ); if ( cb ) { for ( QMap<QString, QString>::const_iterator it = classes.begin(); it != classes.end(); it++ ) { cb->addItem( it.value(), it.key() ); } myWidget = cb; } } break; case QgsVectorLayer::DialRange: case QgsVectorLayer::SliderRange: case QgsVectorLayer::EditRange: { if ( myFieldType == QVariant::Int ) { int min = vl->range( idx ).mMin.toInt(); int max = vl->range( idx ).mMax.toInt(); int step = vl->range( idx ).mStep.toInt(); if ( editType == QgsVectorLayer::EditRange ) { QSpinBox *sb = 0; if ( editor ) sb = qobject_cast<QSpinBox *>( editor ); else sb = new QSpinBox( parent ); if ( sb ) { sb->setRange( min, max ); sb->setSingleStep( step ); myWidget = sb; } } else { QAbstractSlider *sl = 0; if ( editor ) { sl = qobject_cast<QAbstractSlider*>( editor ); } else if ( editType == QgsVectorLayer::DialRange ) { sl = new QDial( parent ); } else { sl = new QSlider( Qt::Horizontal, parent ); } if ( sl ) { sl->setRange( min, max ); sl->setSingleStep( step ); myWidget = sl; } } break; } else if ( myFieldType == QVariant::Double ) { QDoubleSpinBox *dsb = 0; if ( editor ) dsb = qobject_cast<QDoubleSpinBox*>( editor ); else dsb = new QDoubleSpinBox( parent ); if ( dsb ) { double min = vl->range( idx ).mMin.toDouble(); double max = vl->range( idx ).mMax.toDouble(); double step = vl->range( idx ).mStep.toDouble(); dsb->setRange( min, max ); dsb->setSingleStep( step ); myWidget = dsb; } break; } } case QgsVectorLayer::CheckBox: { QCheckBox *cb = 0; if ( editor ) cb = qobject_cast<QCheckBox*>( editor ); else cb = new QCheckBox( parent ); if ( cb ) { myWidget = cb; break; } } // fall-through case QgsVectorLayer::LineEdit: case QgsVectorLayer::TextEdit: case QgsVectorLayer::UuidGenerator: case QgsVectorLayer::UniqueValuesEditable: case QgsVectorLayer::Immutable: { QLineEdit *le = 0; QTextEdit *te = 0; QPlainTextEdit *pte = 0; QComboBox * cb = 0; if ( editor ) { le = qobject_cast<QLineEdit *>( editor ); te = qobject_cast<QTextEdit *>( editor ); pte = qobject_cast<QPlainTextEdit *>( editor ); cb = qobject_cast<QComboBox *>( editor ); } else if ( editType == QgsVectorLayer::TextEdit ) { pte = new QPlainTextEdit( parent ); } else { le = new QLineEdit( parent ); } if ( le ) { if ( editType == QgsVectorLayer::UniqueValuesEditable ) { QList<QVariant> values; vl->dataProvider()->uniqueValues( idx, values ); QStringList svalues; for ( QList<QVariant>::const_iterator it = values.begin(); it != values.end(); it++ ) svalues << it->toString(); QCompleter *c = new QCompleter( svalues ); c->setCompletionMode( QCompleter::PopupCompletion ); le->setCompleter( c ); } if ( editType == QgsVectorLayer::UuidGenerator ) { le->setReadOnly( true ); } le->setValidator( new QgsFieldValidator( le, field ) ); myWidget = le; } if ( te ) { te->setAcceptRichText( true ); myWidget = te; } if ( pte ) { myWidget = pte; } if ( cb ) { myWidget = cb; } if ( myWidget ) { myWidget->setDisabled( editType == QgsVectorLayer::Immutable ); QgsStringRelay* relay = NULL; QMap<int, QWidget*>::const_iterator it = proxyWidgets.find( idx ); if ( it != proxyWidgets.end() ) { QObject* obj = qvariant_cast<QObject*>( (*it)->property( "QgisAttrEditProxy" ) ); relay = qobject_cast<QgsStringRelay*>( obj ); } else { relay = new QgsStringRelay( myWidget ); } if ( cb && cb->isEditable() ) { synchronized = connect( relay, SIGNAL( textChanged( QString ) ), myWidget, SLOT( setEditText( QString ) ) ); synchronized &= connect( myWidget, SIGNAL( editTextChanged( QString ) ), relay, SLOT( changeText( QString ) ) ); } else { synchronized = connect( relay, SIGNAL( textChanged( QString ) ), myWidget, SLOT( setText( QString ) ) ); synchronized &= connect( myWidget, SIGNAL( textChanged( QString ) ), relay, SLOT( changeText( QString ) ) ); } if ( !cb || cb->isEditable() ) { myWidget->setProperty( "QgisAttrEditProxy", QVariant( QMetaType::QObjectStar, &relay ) ); } } } break; case QgsVectorLayer::Hidden: myWidget = 0; break; case QgsVectorLayer::FileName: case QgsVectorLayer::Calendar: { QPushButton *pb = 0; QLineEdit *le = qobject_cast<QLineEdit *>( editor ); if ( le ) { if ( le ) myWidget = le; if ( editor->parent() ) { pb = editor->parent()->findChild<QPushButton *>(); } } else { le = new QLineEdit(); pb = new QPushButton( tr( "..." ) ); QHBoxLayout *hbl = new QHBoxLayout(); hbl->addWidget( le ); hbl->addWidget( pb ); myWidget = new QWidget( parent ); myWidget->setBackgroundRole( QPalette::Window ); myWidget->setAutoFillBackground( true ); myWidget->setLayout( hbl ); } if ( pb ) { if ( editType == QgsVectorLayer::FileName ) connect( pb, SIGNAL( clicked() ), new QgsAttributeEditor( pb ), SLOT( selectFileName() ) ); if ( editType == QgsVectorLayer::Calendar ) connect( pb, SIGNAL( clicked() ), new QgsAttributeEditor( pb ), SLOT( selectDate() ) ); } } break; } QMap<int, QWidget*>::const_iterator it = proxyWidgets.find( idx ); if ( it != proxyWidgets.end() ) { if ( !synchronized ) { myWidget->setEnabled( false ); } } else { proxyWidgets.insert( idx, myWidget ); } setValue( myWidget, vl, idx, value ); return myWidget; }
void WidgetIOProperties::createIOProperties() { ui->mainLayout->setColumnMinimumWidth(0, 150); ui->optionLayout->setColumnMinimumWidth(0, 150); QString lang = Utils::GetLocale(); QString rsc = QString(":/doc/%1/io_doc.json").arg(lang); QFile f(rsc); if (!f.open(QIODevice::ReadOnly | QIODevice::Text)) { QMessageBox::warning(this, tr("Error"), tr("Failed to load IO documentation from %1").arg(rsc)); return; } QJsonParseError jerr; QJsonDocument jdoc = QJsonDocument::fromJson(f.readAll(), &jerr); if (jerr.error != QJsonParseError::NoError || !jdoc.isObject()) { QMessageBox::warning(this, tr("Error"), tr("Failed to parse JSON IO documentation from %1").arg(rsc)); return; } QString iotype = QString::fromUtf8(params["type"].c_str()); QJsonObject jobj = jdoc.object(); for (auto it = jobj.begin();it != jobj.end();it++) jobj.insert(it.key().toLower(), it.value()); QJsonObject jobjAlias; if (!jobj.contains(iotype)) { //Search in aliases bool aliasfound = false; for (auto it = jobj.constBegin();it != jobj.constEnd();it++) { QJsonObject o = it.value().toObject(); QJsonArray jalias = o["alias"].toArray(); for (int i = 0;i < jalias.size();i++) { if (jalias.at(i).toString() == iotype) { aliasfound = true; jobjAlias = o; } } } if (!aliasfound) { QMessageBox::warning(this, tr("Error"), tr("IO type %1 is not found in %2").arg(iotype).arg(rsc)); return; } } QJsonObject jioobj; if (jobjAlias.isEmpty()) jioobj = jobj[iotype].toObject(); else jioobj = jobjAlias; ui->labelTitle->setText(iotype); ui->labelDesc->setText(jioobj["description"].toString()); int rowMain = 0, rowOption = 0; QJsonArray jparams = jioobj["parameters"].toArray(); for (int i = 0;i < jparams.size();i++) { QJsonObject jparam = jparams[i].toObject(); QGridLayout *layout = jparam["mandatory"].toString() == "true"?ui->mainLayout:ui->optionLayout; int row = jparam["mandatory"].toBool()?rowMain:rowOption; QLabel *title = new QLabel(jparam["name"].toString()); layout->addWidget(title, row, 0); QPushButton *revert = new QPushButton(); revert->setIcon(QIcon(":/img/document-revert.png")); revert->setToolTip(tr("Revert modification")); layout->addWidget(revert, row, 1); hider.hide(revert); QString pvalue; string prop = jparam["name"].toString().toUtf8().constData(); if (params.Exists(prop)) pvalue = QString::fromUtf8(params[prop].c_str()); else pvalue = jparam["default"].toString(); if (jparam["type"].toString() == "string") { QLineEdit *w = new QLineEdit(); w->setEnabled(jparam["readonly"].toString() != "true" && editable); w->setText(pvalue); layout->addWidget(w, row, 2); UiObject uiObject; uiObject.type = UiObjectType::LineEdit; uiObject.lineEdit = w; uiObjectMap[prop] = uiObject; connect(w, &QLineEdit::textChanged, [=]() { updateChangedParam(prop, w->text(), pvalue, title, revert); }); connect(revert, &QPushButton::clicked, [=]() { w->setText(pvalue); }); } else if (jparam["type"].toString() == "bool") { QCheckBox *w = new QCheckBox(); w->setEnabled(jparam["readonly"].toString() != "true" && editable); w->setChecked(pvalue == "true"); layout->addWidget(w, row, 2); UiObject uiObject; uiObject.type = UiObjectType::CheckBox; uiObject.checkBox = w; uiObjectMap[prop] = uiObject; connect(w, &QCheckBox::stateChanged, [=]() { updateChangedParam(prop, w->isChecked()?"true":"false", pvalue, title, revert); }); connect(revert, &QPushButton::clicked, [=]() { w->setChecked(pvalue == "true"); }); } else if (jparam["type"].toString() == "int") { QSpinBox *w = new QSpinBox(); w->setEnabled(jparam["readonly"].toString() != "true" && editable); if (!jparam["min"].toString().isEmpty()) w->setMinimum(jparam["min"].toString().toInt()); else w->setMinimum(-999999999); if (!jparam["max"].toString().isEmpty()) w->setMaximum(jparam["max"].toString().toInt()); else w->setMaximum(999999999); w->setValue(pvalue.toInt()); layout->addWidget(w, row, 2); UiObject uiObject; uiObject.type = UiObjectType::SpinBox; uiObject.spinBox = w; uiObjectMap[prop] = uiObject; connect(w, static_cast<void (QSpinBox::*)(int)>(&QSpinBox::valueChanged), [=]() { updateChangedParam(prop, QString("%1").arg(w->value()), pvalue.isEmpty()?"0":pvalue, title, revert); }); connect(revert, &QPushButton::clicked, [=]() { w->setValue(pvalue.toInt()); }); } else if (jparam["type"].toString() == "float") { QDoubleSpinBox *w = new QDoubleSpinBox(); w->setEnabled(jparam["readonly"].toString() != "true" && editable); if (!jparam["min"].toString().isEmpty()) w->setMinimum(jparam["min"].toString().toDouble()); else w->setMinimum(-999999999.0); if (!jparam["max"].toString().isEmpty()) w->setMaximum(jparam["max"].toString().toDouble()); else w->setMaximum(999999999.0); w->setValue(pvalue.toDouble()); layout->addWidget(w, row, 2); w->setDecimals(3); UiObject uiObject; uiObject.type = UiObjectType::DoubleSpinBox; uiObject.doubleSpinBox = w; uiObjectMap[prop] = uiObject; connect(w, static_cast<void (QDoubleSpinBox::*)(double)>(&QDoubleSpinBox::valueChanged), [=]() { updateChangedParam(prop, QString("%1").arg(w->value()), pvalue.isEmpty()?"0":pvalue, title, revert); }); connect(revert, &QPushButton::clicked, [=]() { w->setValue(pvalue.toDouble()); }); } else if (jparam["type"].toString() == "list") { QComboBox *w = new QComboBox(); int defIndex = 0; w->setEnabled(jparam["readonly"].toString() != "true" && editable); //fill combobox with values, if no value, set editable to true QJsonObject jvalues = jparam["list_value"].toObject(); if (jvalues.empty()) w->setEditable(true); else { w->setEditable(false); for (auto it = jvalues.begin();it != jvalues.end();it++) { w->addItem(it.value().toString(), it.key()); if (it.key() == pvalue) { defIndex = w->count() - 1; w->setCurrentIndex(defIndex); } } } layout->addWidget(w, row, 2); UiObject uiObject; uiObject.type = UiObjectType::ComboBox; uiObject.comboBox = w; uiObjectMap[prop] = uiObject; if (w->isEditable()) { connect(w, &QComboBox::currentTextChanged, [=]() { updateChangedParam(prop, w->currentText(), pvalue, title, revert); }); } else { connect(w, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged), [=]() { updateChangedParam(prop, w->currentData().toString(), pvalue, title, revert); }); } connect(revert, &QPushButton::clicked, [=]() { if (w->isEditable()) w->setEditText(pvalue); else w->setCurrentIndex(defIndex); }); } QPushButton *help = new QPushButton(); help->setIcon(QIcon(":/img/icon_unkown.png")); help->setFlat(true); layout->addWidget(help, row, 3); if((i==0)&&(entryHelper != nullptr)) { QPushButton *entryHelperButton = new QPushButton(); entryHelperButton->setIcon(QIcon(":/img/icon_entry_helper.png")); entryHelperButton->setFlat(true); layout->addWidget(entryHelperButton, row, 4); connect(entryHelperButton, &QPushButton::clicked, [=]() { if (entryHelper->exec() == QDialog::Accepted) setValues(entryHelper->getParams()); }); } //avoid copy the QJsonObject in the lambda QString helpInfo = jparam["description"].toString(); connect(help, &QPushButton::clicked, [=]() { if (balloonTip) delete balloonTip; balloonTip = new BalloonTip(QPixmap(":/img/icon_unkown.png"), title->text(), helpInfo, 800, help); balloonTip->setArrowPosition(BalloonTip::TopLeft); balloonTip->move(QCursor::pos()); balloonTip->show(); }); if (jparam["mandatory"].toBool()) rowMain++; else rowOption++; } }
int drv_combobox(int drvid, void *a0, void* a1, void* a2, void* a3, void* a4, void* a5, void* a6, void* a7, void* a8, void* a9) { handle_head* head = (handle_head*)a0; QComboBox *self = (QComboBox*)head->native; switch (drvid) { case COMBOBOX_INIT: { drvNewObj(a0,new QComboBox); break; } case COMBOBOX_COUNT: { drvSetInt(a1,self->count()); break; } case COMBOBOX_SETCURRENTINDEX: { self->setCurrentIndex(drvGetInt(a1)); break; } case COMBOBOX_CURRENTINDEX: { drvSetInt(a1,self->currentIndex()); break; } case COMBOBOX_CURRENTTEXT: { drvSetString(a1,self->currentText()); break; } case COMBOBOX_SETEDITABLE: { self->setEditable(drvGetBool(a1)); break; } case COMBOBOX_ISEDITABLE: { drvSetBool(a1,self->isEditable()); break; } case COMBOBOX_SETMAXCOUNT: { self->setMaxCount(drvGetInt(a1)); break; } case COMBOBOX_MAXCOUNT: { drvSetInt(a1,self->maxCount()); break; } case COMBOBOX_SETMAXVISIBLEITEMS: { self->setMaxVisibleItems(drvGetInt(a1)); break; } case COMBOBOX_MAXVISIBLEITEMS: { drvSetInt(a1,self->maxVisibleItems()); break; } case COMBOBOX_SETMINIMUMCONTENTSLENGTH: { self->setMinimumContentsLength(drvGetInt(a1)); break; } case COMBOBOX_MINIMUNCONTENTSLENGHT: { drvSetInt(a1,self->minimumContentsLength()); break; } case COMBOBOX_ADDITEM: { self->addItem(drvGetString(a1)); break; } case COMBOBOX_INSERTITEM: { self->insertItem(drvGetInt(a1),drvGetString(a2)); break; } case COMBOBOX_REMOVEITEM: { self->removeItem(drvGetInt(a1)); break; } case COMBOBOX_ITEMTEXT: { drvSetString(a2,self->itemText(drvGetInt(a1))); break; } case COMBOBOX_ONCURRENTINDEXCHANGED: { QObject::connect(self,SIGNAL(currentIndexChanged(int)),drvNewSignal(self,a1,a2),SLOT(call(int))); break; } default: return 0; } return 1; }
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: { QGroupBox *gb = qobject_cast<QGroupBox *>( editor ); if ( gb ) { QPair<QString, QString> states = vl->checkedState( idx ); gb->setChecked( value == states.first ); break; } 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 ); QComboBox *cb = qobject_cast<QComboBox *>( editor ); QTextEdit *te = qobject_cast<QTextEdit *>( editor ); QPlainTextEdit *pte = qobject_cast<QPlainTextEdit *>( editor ); if ( !le && ! cb && !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 ( cb && cb->isEditable() ) cb->setEditText( text ); if ( te ) te->setHtml( text ); if ( pte ) pte->setPlainText( text ); } break; case QgsVectorLayer::FileName: case QgsVectorLayer::Calendar: { QCalendarWidget *cw = qobject_cast<QCalendarWidget *>( editor ); if ( cw ) { cw->setSelectedDate( value.toDate() ); break; } QLineEdit* le = qobject_cast<QLineEdit*>( editor ); if ( !le ) { le = editor->findChild<QLineEdit *>(); } if ( !le ) { return false; } le->setText( value.toString() ); } break; } return true; }