40 , mReferencedLayer( nullptr )
46 connect( mComboRelation, SIGNAL( currentIndexChanged(
int ) ),
this, SLOT( relationChanged(
int ) ) );
61 connect( mCbxAllowNull, SIGNAL( toggled(
bool ) ),
this, SIGNAL(
changed() ) );
62 connect( mCbxOrderByValue, SIGNAL( toggled(
bool ) ),
this, SIGNAL(
changed() ) );
63 connect( mCbxShowForm, SIGNAL( toggled(
bool ) ),
this, SIGNAL(
changed() ) );
64 connect( mCbxMapIdentification, SIGNAL( toggled(
bool ) ),
this, SIGNAL(
changed() ) );
65 connect( mCbxReadOnly, SIGNAL( toggled(
bool ) ),
this, SIGNAL(
changed() ) );
66 connect( mComboRelation, SIGNAL( currentIndexChanged(
int ) ),
this, SIGNAL(
changed() ) );
67 connect( mCbxAllowAddFeatures, SIGNAL( toggled(
bool ) ),
this, SIGNAL(
changed() ) );
68 connect( mFilterGroupBox, SIGNAL( toggled(
bool ) ),
this, SIGNAL(
changed() ) );
70 connect( mCbxChainFilters, SIGNAL( toggled(
bool ) ),
this, SIGNAL(
changed() ) );
76 if ( config.contains(
"AllowNULL" ) )
78 mCbxAllowNull->setChecked( config.value(
"AllowNULL" ).toBool() );
81 if ( config.contains(
"OrderByValue" ) )
83 mCbxOrderByValue->setChecked( config.value(
"OrderByValue" ).toBool() );
86 if ( config.contains(
"ShowForm" ) )
88 mCbxShowForm->setChecked( config.value(
"ShowForm" ).toBool() );
91 if ( config.contains(
"Relation" ) )
93 mComboRelation->setCurrentIndex( mComboRelation->findData( config.value(
"Relation" ).toString() ) );
94 relationChanged( mComboRelation->currentIndex() );
97 if ( config.contains(
"MapIdentification" ) )
99 mCbxMapIdentification->setChecked( config.value(
"MapIdentification" ).toBool() );
102 if ( config.contains(
"AllowAddFeatures" ) )
103 mCbxAllowAddFeatures->setChecked( config.value(
"AllowAddFeatures" ).toBool() );
105 if ( config.contains(
"ReadOnly" ) )
107 mCbxReadOnly->setChecked( config.value(
"ReadOnly" ).toBool() );
110 if ( config.contains(
"FilterFields" ) )
112 mFilterGroupBox->setChecked(
true );
113 Q_FOREACH (
const QString& fld, config.value(
"FilterFields" ).toStringList() )
115 addFilterField( fld );
118 mCbxChainFilters->setChecked( config.value(
"ChainFilters" ).toBool() );
122 void QgsRelationReferenceConfigDlg::relationChanged(
int idx )
124 QString relName = mComboRelation->itemData( idx ).toString();
128 mExpressionWidget->setLayer( mReferencedLayer );
129 if ( mReferencedLayer )
132 mCbxMapIdentification->setEnabled( mReferencedLayer->
hasGeometryType() );
138 void QgsRelationReferenceConfigDlg::on_mAddFilterButton_clicked()
140 Q_FOREACH (
QListWidgetItem* item, mAvailableFieldsList->selectedItems() )
142 addFilterField( item );
146 void QgsRelationReferenceConfigDlg::on_mRemoveFilterButton_clicked()
148 Q_FOREACH (
QListWidgetItem* item , mFilterFieldsList->selectedItems() )
150 mFilterFieldsList->takeItem( indexFromListWidgetItem( item ) );
151 mAvailableFieldsList->addItem( item );
158 myConfig.insert(
"AllowNULL", mCbxAllowNull->isChecked() );
159 myConfig.insert(
"OrderByValue", mCbxOrderByValue->isChecked() );
160 myConfig.insert(
"ShowForm", mCbxShowForm->isChecked() );
161 myConfig.insert(
"MapIdentification", mCbxMapIdentification->isEnabled() && mCbxMapIdentification->isChecked() );
162 myConfig.insert(
"ReadOnly", mCbxReadOnly->isChecked() );
163 myConfig.insert(
"Relation", mComboRelation->itemData( mComboRelation->currentIndex() ) );
164 myConfig.insert(
"AllowAddFeatures", mCbxAllowAddFeatures->isChecked() );
166 if ( mFilterGroupBox->isChecked() )
169 filterFields.
reserve( mFilterFieldsList->count() );
170 for (
int i = 0; i < mFilterFieldsList->count(); i++ )
172 filterFields << mFilterFieldsList->item( i )->data( Qt::UserRole ).toString();
174 myConfig.
insert(
"FilterFields", filterFields );
176 myConfig.insert(
"ChainFilters", mCbxChainFilters->isChecked() );
179 if ( mReferencedLayer )
187 void QgsRelationReferenceConfigDlg::loadFields()
189 mAvailableFieldsList->clear();
190 mFilterFieldsList->clear();
192 if ( mReferencedLayer )
196 for (
int i = 0; i < flds.
count(); i++ )
199 mAvailableFieldsList->item( mAvailableFieldsList->count() - 1 )->setData( Qt::UserRole, flds.
at( i ).
name() );
204 void QgsRelationReferenceConfigDlg::addFilterField(
const QString&
field )
206 for (
int i = 0; i < mAvailableFieldsList->count(); i++ )
208 if ( mAvailableFieldsList->item( i )->data( Qt::UserRole ).toString() ==
field )
210 addFilterField( mAvailableFieldsList->item( i ) );
216 void QgsRelationReferenceConfigDlg::addFilterField(
QListWidgetItem* item )
218 mAvailableFieldsList->takeItem( indexFromListWidgetItem( item ) );
219 mFilterFieldsList->addItem( item );
222 int QgsRelationReferenceConfigDlg::indexFromListWidgetItem(
QListWidgetItem* item )
226 for (
int i = 0; i < lw->
count(); i++ )
228 if ( lw->
item( i ) == item )
virtual QgsEditorWidgetConfig config() override
Create a configuration from the current GUI state.
Container of fields for a vector layer.
void setDisplayExpression(const QString &displayExpression)
Set the preview expression, used to create a human readable preview string.
QList< QgsRelation > referencingRelations(int idx)
Get relations, where the foreign key is on this layer.
QgsRelationManager * relationManager() const
int count() const
Return number of items.
QString id() const
A (project-wide) unique id for this relation.
const QgsField & at(int i) const
Get field at particular index (must be in range 0..N-1)
QgsFields fields() const
Returns the list of fields of this layer.
bool hasGeometryType() const
Returns true if this is a geometry layer and false in case of NoGeometry (table only) or UnknownGeome...
virtual void setConfig(const QgsEditorWidgetConfig &config) override
Update the configuration widget to represent the given configuration.
QVariantMap QgsEditorWidgetConfig
Holds a set of configuration parameters for a editor widget wrapper.
static QgsExpressionContextScope * globalScope()
Creates a new scope which contains variables and functions relating to the global QGIS context...
QString displayName() const
Returns the name to use when displaying this field.
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
QgsVectorLayer * referencedLayer() const
Access the referenced (parent) layer.
void insert(int i, const T &value)
static QgsProject * instance()
Returns the QgsProject singleton instance.
static QgsExpressionContext _getExpressionContext(const void *context)
static QgsExpressionContextScope * projectScope()
Creates a new scope which contains variables and functions relating to the current QGIS project...
static QgsExpressionContextScope * layerScope(const QgsMapLayer *layer)
Creates a new scope which contains variables and functions relating to a QgsMapLayer.
QgsRelation relation(const QString &id) const
Get access to a relation by its id.
bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
QString displayExpression() const
Get the preview expression, used to create a human readable preview string.
Represents a vector layer which manages a vector based data sets.
QString referencedLayerId() const
Access the referenced (parent) layer's id.
QgsRelationReferenceConfigDlg(QgsVectorLayer *vl, int fieldIdx, QWidget *parent)
QString name() const
Returns a human readable name for this relation.