void QgsComposerColumnSourceDelegate::setModelData( QWidget* editor, QAbstractItemModel* model, const QModelIndex& index ) const { QgsFieldExpressionWidget *fieldExpression = static_cast<QgsFieldExpressionWidget*>( editor ); QString field = fieldExpression->currentField(); model->setData( index, field, Qt::EditRole ); }
QMap< QString, QString > QgsDataDefinedSymbolDialog::dataDefinedProperties() const { QMap< QString, QString > propertyMap; int rowCount = mTreeWidget->topLevelItemCount(); for ( int i = 0; i < rowCount; ++i ) { QTreeWidgetItem* item = mTreeWidget->topLevelItem( i ); //property QString propertyKey = item->data( 0, Qt::UserRole ).toString(); //checked? bool checked = false; QCheckBox* cb = qobject_cast<QCheckBox*>( mTreeWidget->itemWidget( item, 0 ) ); if ( cb ) { checked = cb->isChecked(); } QString expressionString; if ( checked ) { QgsFieldExpressionWidget* few = qobject_cast<QgsFieldExpressionWidget*>( mTreeWidget->itemWidget( item, 1 ) ); expressionString = few->currentField(); } propertyMap.insert( propertyKey, expressionString ); } return propertyMap; }
void QgsComposerColumnSourceDelegate::setEditorData( QWidget* editor, const QModelIndex& index ) const { QString field = index.model()->data( index, Qt::EditRole ).toString(); //set the value for the field combobox QgsFieldExpressionWidget *fieldExpression = static_cast<QgsFieldExpressionWidget*>( editor ); fieldExpression->setField( field ); }
QWidget* QgsComposerColumnSourceDelegate::createEditor( QWidget* parent, const QStyleOptionViewItem& option, const QModelIndex& index ) const { Q_UNUSED( option ); Q_UNUSED( index ); QgsFieldExpressionWidget *fieldExpression = new QgsFieldExpressionWidget( parent ); fieldExpression->setLayer( mVectorLayer ); //listen out for field changes connect( fieldExpression, SIGNAL( fieldChanged( QString ) ), this, SLOT( commitAndCloseEditor() ) ); return fieldExpression; }
QWidget *QgsComposerColumnSourceDelegate::createEditor( QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index ) const { Q_UNUSED( option ); Q_UNUSED( index ); QgsFieldExpressionWidget *fieldExpression = new QgsFieldExpressionWidget( parent ); fieldExpression->setLayer( mVectorLayer ); fieldExpression->registerExpressionContextGenerator( this ); //listen out for field changes connect( fieldExpression, static_cast < void ( QgsFieldExpressionWidget::* )( const QString & ) >( &QgsFieldExpressionWidget::fieldChanged ), this, [ = ] { const_cast< QgsComposerColumnSourceDelegate * >( this )->commitAndCloseEditor(); } ); return fieldExpression; }
QgsDataDefinedSymbolDialog::QgsDataDefinedSymbolDialog( const QList< DataDefinedSymbolEntry >& entries, const QgsVectorLayer* vl, QWidget * parent, Qt::WindowFlags f ) : QDialog( parent, f ) , mVectorLayer( vl ) { setupUi( this ); QgsFields attributeFields; if ( mVectorLayer ) { attributeFields = mVectorLayer->pendingFields(); } int i = 0; QList< DataDefinedSymbolEntry >::const_iterator entryIt = entries.constBegin(); for ( ; entryIt != entries.constEnd(); ++entryIt ) { QTreeWidgetItem* item = new QTreeWidgetItem( mTreeWidget ); //check box QCheckBox* cb = new QCheckBox( entryIt->title, this ); cb->setChecked( !entryIt->initialValue.isEmpty() ); item->setData( 0, Qt::UserRole, entryIt->property ); mTreeWidget->setItemWidget( item, 0, cb ); // expression QgsFieldExpressionWidget* few = new QgsFieldExpressionWidget( this ); few->setMaximumWidth( 350 ); few->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Maximum ); few->setLayer( const_cast<QgsVectorLayer*>( vl ) ); few->setField( entryIt->initialValue ); mTreeWidget->setItemWidget( item, 1, few ); //help text item->setText( 2, entryIt->helpText ); mTreeWidget->addTopLevelItem( item ); ++i; } for ( int c = 0; c != mTreeWidget->columnCount() - 1; c++ ) mTreeWidget->resizeColumnToContents( c ); QSettings settings; restoreGeometry( settings.value( "/Windows/QgsDataDefinedSymbolDialog/geometry" ).toByteArray() ); }