28 #include <QHBoxLayout> 45 mToggleEditingButton->
setObjectName(
"mToggleEditingButton" );
47 mToggleEditingButton->
setText(
tr(
"Toggle editing" ) );
50 buttonLayout->
addWidget( mToggleEditingButton );
54 mSaveEditsButton->
setText(
tr(
"Save layer edits" ) );
56 buttonLayout->
addWidget( mSaveEditsButton );
60 mAddFeatureButton->
setText(
tr(
"Add feature" ) );
62 buttonLayout->
addWidget( mAddFeatureButton );
66 mDeleteFeatureButton->
setText(
tr(
"Delete feature" ) );
67 mDeleteFeatureButton->
setObjectName(
"mDeleteFeatureButton" );
68 buttonLayout->
addWidget( mDeleteFeatureButton );
72 mLinkFeatureButton->
setText(
tr(
"Link feature" ) );
74 buttonLayout->
addWidget( mLinkFeatureButton );
78 mUnlinkFeatureButton->
setText(
tr(
"Unlink feature" ) );
79 mUnlinkFeatureButton->
setObjectName(
"mUnlinkFeatureButton" );
80 buttonLayout->
addWidget( mUnlinkFeatureButton );
85 mFormViewButton->
setText(
tr(
"Form view" ) );
89 buttonLayout->
addWidget( mFormViewButton );
92 mTableViewButton->
setText(
tr(
"Table view" ) );
96 buttonLayout->
addWidget( mTableViewButton );
110 mDualView->
setView( mViewMode );
117 connect( mViewModeButtonGroup, SIGNAL( buttonClicked(
int ) ),
this, SLOT(
setViewMode(
int ) ) );
118 connect( mToggleEditingButton, SIGNAL(
clicked(
bool ) ),
this, SLOT( toggleEditing(
bool ) ) );
119 connect( mSaveEditsButton, SIGNAL(
clicked() ),
this, SLOT( saveEdits() ) );
120 connect( mAddFeatureButton, SIGNAL(
clicked() ),
this, SLOT( addFeature() ) );
121 connect( mDeleteFeatureButton, SIGNAL(
clicked() ),
this, SLOT( deleteFeature() ) );
122 connect( mLinkFeatureButton, SIGNAL(
clicked() ),
this, SLOT( linkFeature() ) );
123 connect( mUnlinkFeatureButton, SIGNAL(
clicked() ),
this, SLOT( unlinkFeature() ) );
138 mRelation = relation;
141 connect( mRelation.referencingLayer(), SIGNAL( editingStarted() ),
this, SLOT( updateButtons() ) );
142 connect( mRelation.referencingLayer(), SIGNAL( editingStopped() ),
this, SLOT( updateButtons() ) );
149 if ( canChangeAttributes && !lyr->isReadOnly() )
170 mDualView->
init( mRelation.referencingLayer(),
nullptr, myRequest, mEditorContext );
188 mRelation = relation;
189 mNmRelation = nmrelation;
191 if ( !mRelation.isValid() )
194 connect( mRelation.referencingLayer(), SIGNAL( editingStarted() ),
this, SLOT( updateButtons() ) );
195 connect( mRelation.referencingLayer(), SIGNAL( editingStopped() ),
this, SLOT( updateButtons() ) );
208 if ( canChangeAttributes && !lyr->isReadOnly() )
226 mEditorContext = context;
231 return mFeatureSelectionMgr;
248 void QgsRelationEditorWidget::updateButtons()
250 bool editable =
false;
251 bool linkable =
false;
267 mDeleteFeatureButton->
setEnabled( editable && selectionNotEmpty );
268 mUnlinkFeatureButton->
setEnabled( linkable && selectionNotEmpty );
273 void QgsRelationEditorWidget::addFeature()
309 void QgsRelationEditorWidget::linkFeature()
320 if ( selectionDlg.
exec() )
336 linkFeature.setAttribute( fieldPair.first, mFeature.
attribute( fieldPair.second ) );
343 linkFeature.setAttribute( fieldPair.first, relatedFeature.
attribute( fieldPair.second ) );
346 newFeatures << linkFeature;
376 void QgsRelationEditorWidget::deleteFeature()
390 void QgsRelationEditorWidget::unlinkFeature()
410 filters.
join(
" OR " ) );
414 .setFilterExpression( filter ) );
437 keyFields.
insert( idx, fld );
452 void QgsRelationEditorWidget::toggleEditing(
bool state )
468 void QgsRelationEditorWidget::saveEdits()
475 void QgsRelationEditorWidget::onCollapsedStateChanged(
bool collapsed )
485 void QgsRelationEditorWidget::updateUi()
QgsFeatureId id() const
Get the feature ID for this feature.
Wrapper for iterator of features from vector data provider or vector layer.
bool isValid() const
Returns the validity of this relation.
QString & append(QChar ch)
void setContentsMargins(int left, int top, int right, int bottom)
bool collapsed
The collapsed state of this group box.
QString referencedField() const
Get the name of the referenced field.
QMap< int, QVariant > QgsAttributeMap
void setFeatureSelectionManager(QgsIFeatureSelectionManager *featureSelectionManager)
A groupbox that collapses/expands when toggled and can save its collapsed and checked states...
virtual int selectedFeatureCount() override
The number of features that are selected in this layer.
void clicked(bool checked)
QgsFields fields() const
Returns the list of fields of this layer.
This class contains context information for attribute editor widgets.
QString & prepend(QChar ch)
QgsFeatureIterator getFeatures(const QgsFeatureRequest &request=QgsFeatureRequest())
Query the provider for features specified in request.
static QIcon getThemeIcon(const QString &theName)
Helper to get a theme icon.
const T & at(int i) const
ViewMode
The view modes, in which this widget can present information.
void collapsedStateChanged(bool collapsed)
Signal emitted when groupbox collapsed/expanded state is changed, and when first shown.
bool deleteFeatures(const QgsFeatureIds &fids)
Deletes a set of features from the layer (but does not commit it)
QgsVectorLayer * referencedLayer() const
Access the referenced (parent) layer.
Container of fields for a vector layer.
A geometry is the spatial representation of a feature.
bool setAttribute(int field, const QVariant &attr)
Set an attribute's value by field index.
bool addFeature(QgsFeature &f, bool alsoUpdateExtent=true)
Adds a feature.
QString join(const QString &separator) const
virtual const QgsFeatureIds & selectedFeaturesIds() const override
Return reference to identifiers of selected features.
QString name() const
Returns a human readable name for this relation.
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
QgsAttributeList referencedFields() const
Returns a list of attributes used to form the referenced fields (most likely primary key) on the refe...
QgsFeatureRequest getReferencedFeatureRequest(const QgsAttributes &attributes) const
Creates a request to return the feature on the referenced (parent) layer which is referenced by the p...
bool disconnect(const QObject *sender, const char *signal, const QObject *receiver, const char *method)
virtual bool isEditable() const override
Returns true if the provider is in editing mode.
QString tr(const char *sourceText, const char *disambiguation, int n)
void setView(ViewMode view)
Change the current view mode.
const QgsFeatureIds & selectedFeatures()
Get the selected features.
Show a list of the features, where one can be chosen and the according attribute dialog will be prese...
QgsFeatureRequest & setFilterExpression(const QString &expression)
Set the filter expression.
Defines a relation between matching fields of the two involved tables of a relation.
Shows the features and attributes in a table layout.
QString referencingField() const
Get the name of the referencing field.
virtual int capabilities() const
Returns a bitmask containing the supported capabilities Note, some capabilities may change depending ...
QgsVectorLayer * referencingLayer() const
Access the referencing (child) layer This is the layer which has the field(s) which point to another ...
virtual void addItem(QLayoutItem *item)
void setObjectName(const QString &name)
This class wraps a request for features to a vector layer (or directly its vector data provider)...
QList< int > QgsAttributeList
void init(QgsVectorLayer *layer, QgsMapCanvas *mapCanvas, const QgsFeatureRequest &request=QgsFeatureRequest(), const QgsAttributeEditorContext &context=QgsAttributeEditorContext())
Has to be called to initialize the dual view.
Encapsulate a field in an attribute table or data source.
QgsFeatureRequest getRelatedFeaturesRequest(const QgsFeature &feature) const
Creates a request to return all the features on the referencing (child) layer which have a foreign ke...
const QgsField & at(int i) const
Get field at particular index (must be in range 0..N-1)
bool addFeatures(QgsFeatureList features, bool makeSelected=true)
Insert a copy of the given features into the layer (but does not commit it)
Q_DECL_DEPRECATED bool changeAttributeValue(QgsFeatureId fid, int field, const QVariant &value, bool emitSignal)
Changes an attribute value (but does not commit it)
int indexFromName(const QString &name) const
Look up field's index from name. Returns -1 on error.
QgsAttributeList referencingFields() const
Returns a list of attributes used to form the referencing fields (foreign key) on the referencing lay...
This selection manager synchronizes a local set of selected features with an attribute table...
QgsAttributeTableModel * masterModel() const
Returns the model which has the information about all features (not only filtered) ...
QVariant attribute(const QString &name) const
Lookup attribute value from attribute name.
void setTitle(const QString &title)
QgsVectorLayer * layer() const
Returns the layer this model uses as backend.
const QgsVectorLayerTools * vectorLayerTools() const
void loadState()
Will load the collapsed and checked state.
QList< FieldPair > fieldPairs() const
Returns the field pairs which form this relation The first element of each pair are the field names f...
void setText(const QString &text)
QString expression() const
Return the original, unmodified expression string.
iterator insert(const Key &key, const T &value)
QgsVectorDataProvider * dataProvider()
Returns the data provider.
bool nextFeature(QgsFeature &f)
bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
Is an interface class to abstract feature selection handling.
Represents a vector layer which manages a vector based data sets.
int fieldNameIndex(const QString &fieldName) const
Returns the index of a field name or -1 if the field does not exist.
QString arg(qlonglong a, int fieldWidth, int base, const QChar &fillChar) const
Allows modification of attribute values.
This widget is used to show the attributes of a set of features of a QgsVectorLayer.
void addLayout(QLayout *layout, int stretch)
QgsExpression * filterExpression() const
Returns the filter expression if set.