QWidget* QgsRangeWidgetWrapper::createWidget( QWidget* parent ) { QWidget* editor = 0; if ( config( "Style" ).toString() == "Dial" ) { editor = new QgsDial( parent ); } else if ( config( "Style" ).toString() == "Slider" ) { editor = new QgsSlider( Qt::Horizontal, parent ); } else { QgsDebugMsg( QString( "%1" ).arg(( int )layer()->fields()[fieldIdx()].type() ) ); switch ( layer()->fields()[fieldIdx()].type() ) { case QVariant::Double: { editor = new QgsDoubleSpinBox( parent ); break; } case QVariant::Int: case QVariant::LongLong: default: editor = new QgsSpinBox( parent ); break; } } return editor; }
QWidget *QgsAttributeTableDelegate::createEditor( QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index ) const { QgsVectorLayer *vl = layer( index.model() ); if ( !vl ) return NULL; QWidget *w = QgsAttributeEditor::createAttributeEditor( parent, 0, vl, fieldIdx( index ), index.model()->data( index, Qt::EditRole ) ); if ( parent ) { QgsAttributeTableView *tv = dynamic_cast<QgsAttributeTableView *>( parent->parentWidget() ); w->setMinimumWidth( tv->columnWidth( index.column() ) ); if ( vl->editType( fieldIdx( index ) ) == QgsVectorLayer::FileName || vl->editType( fieldIdx( index ) ) == QgsVectorLayer::Calendar ) { QLineEdit *le = w->findChild<QLineEdit*>(); le->adjustSize(); w->setMinimumHeight( le->height()*2 ); // FIXME: there must be a better way to do this } } return w; }
void QgsRelationReferenceWidgetWrapper::initWidget( QWidget *editor ) { QgsRelationReferenceWidget *w = dynamic_cast<QgsRelationReferenceWidget *>( editor ); if ( !w ) { w = new QgsRelationReferenceWidget( editor ); } mWidget = w; mWidget->setEditorContext( context(), mCanvas, mMessageBar ); bool showForm = config( QStringLiteral( "ShowForm" ), false ).toBool(); bool mapIdent = config( QStringLiteral( "MapIdentification" ), false ).toBool(); bool readOnlyWidget = config( QStringLiteral( "ReadOnly" ), false ).toBool(); bool orderByValue = config( QStringLiteral( "OrderByValue" ), false ).toBool(); bool showOpenFormButton = config( QStringLiteral( "ShowOpenFormButton" ), true ).toBool(); mWidget->setEmbedForm( showForm ); mWidget->setReadOnlySelector( readOnlyWidget ); mWidget->setAllowMapIdentification( mapIdent ); mWidget->setOrderByValue( orderByValue ); mWidget->setOpenFormButtonVisible( showOpenFormButton ); if ( config( QStringLiteral( "FilterFields" ), QVariant() ).isValid() ) { mWidget->setFilterFields( config( QStringLiteral( "FilterFields" ) ).toStringList() ); mWidget->setChainFilters( config( QStringLiteral( "ChainFilters" ) ).toBool() ); } mWidget->setAllowAddFeatures( config( QStringLiteral( "AllowAddFeatures" ), false ).toBool() ); const QVariant relationName = config( QStringLiteral( "Relation" ) ); QgsRelation relation; // invalid relation by default if ( relationName.isValid() ) relation = QgsProject::instance()->relationManager()->relation( relationName.toString() ); else if ( ! layer()->referencingRelations( fieldIdx() ).isEmpty() ) relation = layer()->referencingRelations( fieldIdx() )[0]; // If this widget is already embedded by the same relation, reduce functionality const QgsAttributeEditorContext *ctx = &context(); do { if ( ctx->relation().name() == relation.name() ) { mWidget->setEmbedForm( false ); mWidget->setReadOnlySelector( false ); mWidget->setAllowMapIdentification( false ); break; } ctx = ctx->parentContext(); } while ( ctx ); mWidget->setRelation( relation, config( QStringLiteral( "AllowNULL" ) ).toBool() ); connect( mWidget, &QgsRelationReferenceWidget::foreignKeyChanged, this, &QgsRelationReferenceWidgetWrapper::foreignKeyChanged ); }
void QgsRangeWidgetWrapper::initWidget( QWidget* editor ) { mDoubleSpinBox = qobject_cast<QDoubleSpinBox*>( editor ); mIntSpinBox = qobject_cast<QSpinBox*>( editor ); mDial = qobject_cast<QDial*>( editor ); mSlider = qobject_cast<QSlider*>( editor ); mQgsDial = qobject_cast<QgsDial*>( editor ); mQgsSlider = qobject_cast<QgsSlider*>( editor ); bool allowNull = config( QStringLiteral( "AllowNull" ), true ).toBool(); QVariant min( config( QStringLiteral( "Min" ) ) ); QVariant max( config( QStringLiteral( "Max" ) ) ); QVariant step( config( QStringLiteral( "Step" ) ) ); if ( mDoubleSpinBox ) { // set the precision if field is integer int precision = layer()->fields().at( fieldIdx() ).precision(); if ( precision > 0 ) { mDoubleSpinBox->setDecimals( layer()->fields().at( fieldIdx() ).precision() ); } double minval = min.toDouble(); double stepval = step.toDouble(); QgsDoubleSpinBox* qgsWidget = dynamic_cast<QgsDoubleSpinBox*>( mDoubleSpinBox ); if ( qgsWidget ) qgsWidget->setShowClearButton( allowNull ); if ( allowNull ) { if ( precision > 0 ) { minval -= 10 ^ -precision; } else { minval -= stepval; } mDoubleSpinBox->setValue( minval ); mDoubleSpinBox->setSpecialValueText( QSettings().value( QStringLiteral( "qgis/nullValue" ), "NULL" ).toString() ); } mDoubleSpinBox->setMinimum( min.isValid() ? min.toDouble() : std::numeric_limits<double>::min() ); mDoubleSpinBox->setMaximum( max.isValid() ? max.toDouble() : std::numeric_limits<double>::max() ); mDoubleSpinBox->setSingleStep( step.isValid() ? step.toDouble() : 1.0 ); if ( config( QStringLiteral( "Suffix" ) ).isValid() ) mDoubleSpinBox->setSuffix( config( QStringLiteral( "Suffix" ) ).toString() ); connect( mDoubleSpinBox, SIGNAL( valueChanged( double ) ), this, SLOT( valueChanged( double ) ) ); } else if ( mIntSpinBox )
QWidget *QgsRangeWidgetWrapper::createWidget( QWidget *parent ) { QWidget *editor = nullptr; if ( config( QStringLiteral( "Style" ) ).toString() == QLatin1String( "Dial" ) ) { editor = new QgsDial( parent ); } else if ( config( QStringLiteral( "Style" ) ).toString() == QLatin1String( "Slider" ) ) { editor = new QgsSlider( Qt::Horizontal, parent ); } else { switch ( layer()->fields().at( fieldIdx() ).type() ) { case QVariant::Double: { editor = new QgsDoubleSpinBox( parent ); break; } case QVariant::Int: case QVariant::LongLong: default: editor = new QgsSpinBox( parent ); break; } } return editor; }
void QgsUniqueValuesWidget::initWidget( QWidget* editor ) { mComboBox = qobject_cast<QComboBox*>( editor ); mLineEdit = qobject_cast<QLineEdit*>( editor ); QStringList sValues; QList<QVariant> values; layer()->uniqueValues( fieldIdx(), values ); Q_FOREACH( QVariant v, values ) { if ( mComboBox ) { mComboBox->addItem( v.toString(), v ); } sValues << v.toString(); } if ( mLineEdit ) { QCompleter* c = new QCompleter( sValues ); c->setCompletionMode( QCompleter::PopupCompletion ); mLineEdit->setCompleter( c ); connect( mLineEdit, SIGNAL( textChanged( QString ) ), this, SLOT( valueChanged( QString ) ) ); } if ( mComboBox ) { connect( mComboBox, SIGNAL( currentIndexChanged( int ) ), this, SLOT( valueChanged() ) ); } }
void QgsAttributeTableDelegate::setEditorData( QWidget *editor, const QModelIndex &index ) const { QgsVectorLayer *vl = layer( index.model() ); if ( vl == NULL ) return; QgsAttributeEditor::setValue( editor, vl, fieldIdx( index ), index.model()->data( index, Qt::EditRole ) ); }
QWidget* QgsRangeWidgetWrapper::createWidget( QWidget* parent ) { QWidget* editor = 0; if ( config( "Style" ).toString() == "Dial" ) { editor = new QgsDial( parent ); } else if ( config( "Style" ).toString() == "Slider" ) { editor = new QgsSlider( Qt::Horizontal, parent ); } else { switch ( layer()->pendingFields()[fieldIdx()].type() ) { case QVariant::Double: { QDoubleSpinBox* spin = new QDoubleSpinBox( parent ); int precision = layer()->pendingFields()[fieldIdx()].precision(); if ( precision > 0 ) { spin->setDecimals( layer()->pendingFields()[fieldIdx()].precision() ); } editor = spin; break; } case QVariant::Int: case QVariant::LongLong: default: editor = new QSpinBox( parent ); break; } } return editor; }
void QgsEnumerationWidgetWrapper::initWidget( QWidget* editor ) { mComboBox = qobject_cast<QComboBox*>( editor ); if ( mComboBox ) { QStringList enumValues; layer()->dataProvider()->enumValues( fieldIdx(), enumValues ); Q_FOREACH ( const QString& s, enumValues ) { mComboBox->addItem( s, s ); } connect( mComboBox, SIGNAL( currentIndexChanged( int ) ), this, SLOT( valueChanged() ) ); }
void QgsAttributeTableDelegate::setModelData( QWidget *editor, QAbstractItemModel *model, const QModelIndex &index ) const { QgsVectorLayer *vl = layer( model ); if ( vl == NULL ) return; int idx = fieldIdx( index ); int fid = featureId( index ); QVariant value; if ( !QgsAttributeEditor::retrieveValue( editor, vl, idx, value ) ) return; vl->beginEditCommand( tr( "Attribute changed" ) ); vl->changeAttributeValue( fid, idx, value, true ); vl->endEditCommand(); }
void QgsUniqueValuesWidgetWrapper::initWidget( QWidget* editor ) { mComboBox = qobject_cast<QComboBox*>( editor ); mLineEdit = qobject_cast<QLineEdit*>( editor ); QStringList sValues; QList<QVariant> values; layer()->uniqueValues( fieldIdx(), values ); Q_FOREACH ( const QVariant& v, values ) { if ( mComboBox ) { mComboBox->addItem( v.toString(), v ); } if ( mLineEdit ) { sValues << v.toString(); } } if ( mLineEdit ) { QgsFilterLineEdit* fle = qobject_cast<QgsFilterLineEdit*>( editor ); if ( fle && !( field().type() == QVariant::Int || field().type() == QVariant::Double || field().type() == QVariant::LongLong || field().type() == QVariant::Date ) ) { fle->setNullValue( QSettings().value( "qgis/nullValue", "NULL" ).toString() ); } QCompleter* c = new QCompleter( sValues ); c->setCaseSensitivity( Qt::CaseInsensitive ); c->setCompletionMode( QCompleter::PopupCompletion ); mLineEdit->setCompleter( c ); connect( mLineEdit, SIGNAL( textChanged( QString ) ), this, SLOT( valueChanged( QString ) ) ); } if ( mComboBox ) { connect( mComboBox, SIGNAL( currentIndexChanged( int ) ), this, SLOT( valueChanged() ) ); } }
void QgsValueRelationWidgetWrapper::setValue( const QVariant &value ) { if ( mTableWidget ) { QStringList checkList; if ( layer()->fields().at( fieldIdx() ).type() == QVariant::Map ) { //because of json it's stored as QVariantList checkList = value.toStringList(); } else { checkList = QgsValueRelationFieldFormatter::valueToStringList( value ); } QTableWidgetItem *lastChangedItem = nullptr; const int nofColumns = columnCount(); // This block is needed because item->setCheckState triggers dataChanged gets back to value() // and iterate over all items again! This can be extremely slow on large items sets. for ( int j = 0; j < mTableWidget->rowCount(); j++ ) { auto signalBlockedTableWidget = whileBlocking( mTableWidget ); Q_UNUSED( signalBlockedTableWidget ) for ( int i = 0; i < nofColumns; ++i ) { QTableWidgetItem *item = mTableWidget->item( j, i ); if ( item ) { item->setCheckState( checkList.contains( item->data( Qt::UserRole ).toString() ) ? Qt::Checked : Qt::Unchecked ); //re-set enabled state because it's lost after reloading items item->setFlags( mEnabled ? item->flags() | Qt::ItemIsEnabled : item->flags() & ~Qt::ItemIsEnabled ); lastChangedItem = item; } } } // let's trigger the signal now, once and for all if ( lastChangedItem ) lastChangedItem->setCheckState( checkList.contains( lastChangedItem->data( Qt::UserRole ).toString() ) ? Qt::Checked : Qt::Unchecked ); } else if ( mComboBox )
void QgsRangeWidgetWrapper::initWidget( QWidget* editor ) { mDoubleSpinBox = qobject_cast<QDoubleSpinBox*>( editor ); mIntSpinBox = qobject_cast<QSpinBox*>( editor ); mDial = qobject_cast<QDial*>( editor ); mSlider = qobject_cast<QSlider*>( editor ); mQgsDial = qobject_cast<QgsDial*>( editor ); mQgsSlider = qobject_cast<QgsSlider*>( editor ); bool allowNull = config( "AllowNull" ).toBool(); QVariant min( config( "Min" ) ); QVariant max( config( "Max" ) ); QVariant step( config( "Step" ) ); if ( mDoubleSpinBox ) { // set the precision if field is integer int precision = layer()->fields()[fieldIdx()].precision(); if ( precision > 0 ) { mDoubleSpinBox->setDecimals( layer()->fields()[fieldIdx()].precision() ); } double minval = min.toDouble(); double stepval = step.toDouble(); QgsDoubleSpinBox* qgsWidget = dynamic_cast<QgsDoubleSpinBox*>( mDoubleSpinBox ); if ( qgsWidget ) qgsWidget->setShowClearButton( allowNull ); if ( allowNull ) { if ( precision > 0 ) { minval -= 10 ^ -precision; } else { minval -= stepval; } mDoubleSpinBox->setValue( minval ); mDoubleSpinBox->setSpecialValueText( QSettings().value( "qgis/nullValue", "NULL" ).toString() ); } if ( min.isValid() ) mDoubleSpinBox->setMinimum( min.toDouble() ); if ( max.isValid() ) mDoubleSpinBox->setMaximum( max.toDouble() ); if ( step.isValid() ) mDoubleSpinBox->setSingleStep( step.toDouble() ); if ( config( "Suffix" ).isValid() ) mDoubleSpinBox->setSuffix( config( "Suffix" ).toString() ); connect( mDoubleSpinBox, SIGNAL( valueChanged( double ) ), this, SLOT( valueChanged( double ) ) ); } if ( mIntSpinBox ) { int minval = min.toInt(); int stepval = step.toInt(); QgsSpinBox* qgsWidget = dynamic_cast<QgsSpinBox*>( mIntSpinBox ); if ( qgsWidget ) qgsWidget->setShowClearButton( allowNull ); if ( allowNull ) { minval -= stepval; mIntSpinBox->setValue( minval ); mIntSpinBox->setSpecialValueText( QSettings().value( "qgis/nullValue", "NULL" ).toString() ); } if ( min.isValid() ) mIntSpinBox->setMinimum( min.toInt() ); if ( max.isValid() ) mIntSpinBox->setMaximum( max.toInt() ); if ( step.isValid() ) mIntSpinBox->setSingleStep( step.toInt() ); if ( config( "Suffix" ).isValid() ) mIntSpinBox->setSuffix( config( "Suffix" ).toString() ); connect( mIntSpinBox, SIGNAL( valueChanged( int ) ), this, SLOT( valueChanged( int ) ) ); } if ( mQgsDial || mQgsSlider ) { field().convertCompatible( min ); field().convertCompatible( max ); field().convertCompatible( step ); if ( mQgsSlider ) { if ( min.isValid() ) mQgsSlider->setMinimum( min ); if ( max.isValid() ) mQgsSlider->setMaximum( max ); if ( step.isValid() ) mQgsSlider->setSingleStep( step ); } if ( mQgsDial ) { if ( min.isValid() ) mQgsDial->setMinimum( min ); if ( max.isValid() ) mQgsDial->setMaximum( max ); if ( step.isValid() ) mQgsDial->setSingleStep( step ); } connect( editor, SIGNAL( valueChanged( QVariant ) ), this, SLOT( valueChanged( QVariant ) ) ); } else if ( mDial ) { if ( min.isValid() ) mDial->setMinimum( min.toInt() ); if ( max.isValid() ) mDial->setMaximum( max.toInt() ); if ( step.isValid() ) mDial->setSingleStep( step.toInt() ); connect( mDial, SIGNAL( valueChanged( int ) ), this, SLOT( valueChanged( int ) ) ); } else if ( mSlider )
void QgsRangeWidgetWrapper::initWidget( QWidget *editor ) { mDoubleSpinBox = qobject_cast<QDoubleSpinBox *>( editor ); mIntSpinBox = qobject_cast<QSpinBox *>( editor ); mDial = qobject_cast<QDial *>( editor ); mSlider = qobject_cast<QSlider *>( editor ); mQgsDial = qobject_cast<QgsDial *>( editor ); mQgsSlider = qobject_cast<QgsSlider *>( editor ); bool allowNull = config( QStringLiteral( "AllowNull" ), true ).toBool(); QVariant min( config( QStringLiteral( "Min" ) ) ); QVariant max( config( QStringLiteral( "Max" ) ) ); QVariant step( config( QStringLiteral( "Step" ) ) ); if ( mDoubleSpinBox ) { // set the precision if field is integer int precision = layer()->fields().at( fieldIdx() ).precision(); if ( precision > 0 ) { mDoubleSpinBox->setDecimals( layer()->fields().at( fieldIdx() ).precision() ); } double minval = min.toDouble(); double stepval = step.toDouble(); QgsDoubleSpinBox *qgsWidget = dynamic_cast<QgsDoubleSpinBox *>( mDoubleSpinBox ); if ( qgsWidget ) qgsWidget->setShowClearButton( allowNull ); if ( allowNull ) { if ( precision > 0 ) { minval -= 10 ^ -precision; } else { minval -= stepval; } mDoubleSpinBox->setValue( minval ); mDoubleSpinBox->setSpecialValueText( QgsApplication::nullRepresentation() ); } mDoubleSpinBox->setMinimum( min.isValid() ? min.toDouble() : std::numeric_limits<double>::min() ); mDoubleSpinBox->setMaximum( max.isValid() ? max.toDouble() : std::numeric_limits<double>::max() ); mDoubleSpinBox->setSingleStep( step.isValid() ? step.toDouble() : 1.0 ); if ( config( QStringLiteral( "Suffix" ) ).isValid() ) mDoubleSpinBox->setSuffix( config( QStringLiteral( "Suffix" ) ).toString() ); connect( mDoubleSpinBox, static_cast < void ( QDoubleSpinBox::* )( double ) > ( &QDoubleSpinBox::valueChanged ), this, static_cast < void ( QgsEditorWidgetWrapper::* )( double ) > ( &QgsEditorWidgetWrapper::valueChanged ) ); } else if ( mIntSpinBox ) { QgsSpinBox *qgsWidget = dynamic_cast<QgsSpinBox *>( mIntSpinBox ); if ( qgsWidget ) qgsWidget->setShowClearButton( allowNull ); if ( allowNull ) { int minval = min.toInt(); int stepval = step.toInt(); minval -= stepval; mIntSpinBox->setValue( minval ); mIntSpinBox->setSpecialValueText( QgsApplication::nullRepresentation() ); } setupIntEditor( min, max, step, mIntSpinBox, this ); if ( config( QStringLiteral( "Suffix" ) ).isValid() ) mIntSpinBox->setSuffix( config( QStringLiteral( "Suffix" ) ).toString() ); } else { field().convertCompatible( min ); field().convertCompatible( max ); field().convertCompatible( step ); if ( mQgsDial ) setupIntEditor( min, max, step, mQgsDial, this ); else if ( mQgsSlider ) setupIntEditor( min, max, step, mQgsSlider, this ); else if ( mDial ) setupIntEditor( min, max, step, mDial, this ); else if ( mSlider ) setupIntEditor( min, max, step, mSlider, this ); } }
void QgsRangeWidgetWrapper::initWidget( QWidget *editor ) { mDoubleSpinBox = qobject_cast<QDoubleSpinBox *>( editor ); mIntSpinBox = qobject_cast<QSpinBox *>( editor ); mDial = qobject_cast<QDial *>( editor ); mSlider = qobject_cast<QSlider *>( editor ); mQgsDial = qobject_cast<QgsDial *>( editor ); mQgsSlider = qobject_cast<QgsSlider *>( editor ); bool allowNull = config( QStringLiteral( "AllowNull" ), true ).toBool(); QVariant min( config( QStringLiteral( "Min" ) ) ); QVariant max( config( QStringLiteral( "Max" ) ) ); QVariant step( config( QStringLiteral( "Step" ) ) ); QVariant precision( config( QStringLiteral( "Precision" ) ) ); if ( mDoubleSpinBox ) { double stepval = step.isValid() ? step.toDouble() : 1.0; double minval = min.isValid() ? min.toDouble() : std::numeric_limits<double>::lowest(); double maxval = max.isValid() ? max.toDouble() : std::numeric_limits<double>::max(); int precisionval = precision.isValid() ? precision.toInt() : layer()->fields().at( fieldIdx() ).precision(); mDoubleSpinBox->setDecimals( precisionval ); QgsDoubleSpinBox *qgsWidget = qobject_cast<QgsDoubleSpinBox *>( mDoubleSpinBox ); if ( qgsWidget ) qgsWidget->setShowClearButton( allowNull ); // Make room for null value: lower the minimum to allow for NULL special values if ( allowNull ) { double decr; if ( precisionval > 0 ) { decr = std::pow( 10, -precisionval ); } else { decr = stepval; } minval -= decr; // Note: call setMinimum here or setValue won't work mDoubleSpinBox->setMinimum( minval ); mDoubleSpinBox->setValue( minval ); QgsDoubleSpinBox *doubleSpinBox( qobject_cast<QgsDoubleSpinBox *>( mDoubleSpinBox ) ); if ( doubleSpinBox ) doubleSpinBox->setSpecialValueText( QgsApplication::nullRepresentation() ); else mDoubleSpinBox->setSpecialValueText( QgsApplication::nullRepresentation() ); } mDoubleSpinBox->setMinimum( minval ); mDoubleSpinBox->setMaximum( maxval ); mDoubleSpinBox->setSingleStep( stepval ); if ( config( QStringLiteral( "Suffix" ) ).isValid() ) mDoubleSpinBox->setSuffix( config( QStringLiteral( "Suffix" ) ).toString() ); connect( mDoubleSpinBox, static_cast < void ( QDoubleSpinBox::* )( double ) > ( &QDoubleSpinBox::valueChanged ), this, [ = ]( double ) { emitValueChanged(); } ); } else if ( mIntSpinBox ) { QgsSpinBox *qgsWidget = qobject_cast<QgsSpinBox *>( mIntSpinBox ); if ( qgsWidget ) qgsWidget->setShowClearButton( allowNull ); int minval = min.toInt(); if ( allowNull ) { int stepval = step.isValid() ? step.toInt() : 1; minval -= stepval; mIntSpinBox->setValue( minval ); QgsSpinBox *intSpinBox( qobject_cast<QgsSpinBox *>( mIntSpinBox ) ); if ( intSpinBox ) intSpinBox->setSpecialValueText( QgsApplication::nullRepresentation() ); else mIntSpinBox->setSpecialValueText( QgsApplication::nullRepresentation() ); } setupIntEditor( minval, max, step, mIntSpinBox, this ); if ( config( QStringLiteral( "Suffix" ) ).isValid() ) mIntSpinBox->setSuffix( config( QStringLiteral( "Suffix" ) ).toString() ); } else { ( void )field().convertCompatible( min ); ( void )field().convertCompatible( max ); ( void )field().convertCompatible( step ); if ( mQgsDial ) setupIntEditor( min, max, step, mQgsDial, this ); else if ( mQgsSlider ) setupIntEditor( min, max, step, mQgsSlider, this ); else if ( mDial ) setupIntEditor( min, max, step, mDial, this ); else if ( mSlider ) setupIntEditor( min, max, step, mSlider, this ); } }
QVariant QgsValueRelationWidgetWrapper::value() const { QVariant v; if ( mComboBox ) { int cbxIdx = mComboBox->currentIndex(); if ( cbxIdx > -1 ) { v = mComboBox->currentData(); } } const int nofColumns = columnCount(); if ( mTableWidget ) { QStringList selection; for ( int j = 0; j < mTableWidget->rowCount(); j++ ) { for ( int i = 0; i < nofColumns; ++i ) { QTableWidgetItem *item = mTableWidget->item( j, i ); if ( item ) { if ( item->checkState() == Qt::Checked ) selection << item->data( Qt::UserRole ).toString(); } } } if ( layer()->fields().at( fieldIdx() ).type() == QVariant::Map ) { QVariantList vl; //store as QVariantList because it's json for ( const QString &s : qgis::as_const( selection ) ) { vl << s; } v = vl; } else { //store as hstore string v = selection.join( ',' ).prepend( '{' ).append( '}' ); } } if ( mLineEdit ) { for ( const QgsValueRelationFieldFormatter::ValueRelationItem &item : qgis::as_const( mCache ) ) { if ( item.value == mLineEdit->text() ) { v = item.key; break; } } } return v; }