28 #include <QHBoxLayout> 45 mToggleEditingButton->
setObjectName(
"mToggleEditingButton" );
47 mToggleEditingButton->
setText(
tr(
"Toggle editing" ) );
50 mToggleEditingButton->
setToolTip(
tr(
"Toggle editing mode for child layer" ) );
51 buttonLayout->
addWidget( mToggleEditingButton );
55 mSaveEditsButton->
setText(
tr(
"Save layer edits" ) );
56 mSaveEditsButton->
setToolTip(
tr(
"Save child layer edits" ) );
58 buttonLayout->
addWidget( mSaveEditsButton );
62 mAddFeatureButton->
setText(
tr(
"Add feature" ) );
63 mAddFeatureButton->
setToolTip(
tr(
"Add child feature" ) );
65 buttonLayout->
addWidget( mAddFeatureButton );
69 mDeleteFeatureButton->
setText(
tr(
"Delete feature" ) );
70 mDeleteFeatureButton->
setToolTip(
tr(
"Delete child feature" ) );
71 mDeleteFeatureButton->
setObjectName(
"mDeleteFeatureButton" );
72 buttonLayout->
addWidget( mDeleteFeatureButton );
76 mLinkFeatureButton->
setText(
tr(
"Link feature" ) );
77 mLinkFeatureButton->
setToolTip(
tr(
"Link existing child features" ) );
79 buttonLayout->
addWidget( mLinkFeatureButton );
83 mUnlinkFeatureButton->
setText(
tr(
"Unlink feature" ) );
84 mUnlinkFeatureButton->
setToolTip(
tr(
"Unlink child feature" ) );
85 mUnlinkFeatureButton->
setObjectName(
"mUnlinkFeatureButton" );
86 buttonLayout->
addWidget( mUnlinkFeatureButton );
91 mFormViewButton->
setText(
tr(
"Form view" ) );
92 mFormViewButton->
setToolTip(
tr(
"Switch to form view" ) );
96 buttonLayout->
addWidget( mFormViewButton );
99 mTableViewButton->
setText(
tr(
"Table view" ) );
100 mTableViewButton->
setToolTip(
tr(
"Switch to table view" ) );
104 buttonLayout->
addWidget( mTableViewButton );
118 mDualView->
setView( mViewMode );
125 connect( mViewModeButtonGroup, SIGNAL( buttonClicked(
int ) ),
this, SLOT(
setViewMode(
int ) ) );
126 connect( mToggleEditingButton, SIGNAL(
clicked(
bool ) ),
this, SLOT( toggleEditing(
bool ) ) );
127 connect( mSaveEditsButton, SIGNAL(
clicked() ),
this, SLOT( saveEdits() ) );
128 connect( mAddFeatureButton, SIGNAL(
clicked() ),
this, SLOT( addFeature() ) );
129 connect( mDeleteFeatureButton, SIGNAL(
clicked() ),
this, SLOT( deleteFeature() ) );
130 connect( mLinkFeatureButton, SIGNAL(
clicked() ),
this, SLOT( linkFeature() ) );
131 connect( mUnlinkFeatureButton, SIGNAL(
clicked() ),
this, SLOT( unlinkFeature() ) );
146 mRelation = relation;
149 connect( mRelation.referencingLayer(), SIGNAL( editingStarted() ),
this, SLOT( updateButtons() ) );
150 connect( mRelation.referencingLayer(), SIGNAL( editingStopped() ),
this, SLOT( updateButtons() ) );
157 if ( canChangeAttributes && !lyr->isReadOnly() )
178 mDualView->
init( mRelation.referencingLayer(),
nullptr, myRequest, mEditorContext );
196 mRelation = relation;
197 mNmRelation = nmrelation;
199 if ( !mRelation.isValid() )
202 connect( mRelation.referencingLayer(), SIGNAL( editingStarted() ),
this, SLOT( updateButtons() ) );
203 connect( mRelation.referencingLayer(), SIGNAL( editingStopped() ),
this, SLOT( updateButtons() ) );
216 if ( canChangeAttributes && !lyr->isReadOnly() )
234 mEditorContext = context;
239 return mFeatureSelectionMgr;
256 void QgsRelationEditorWidget::updateButtons()
258 bool editable =
false;
259 bool linkable =
false;
275 mDeleteFeatureButton->
setEnabled( editable && selectionNotEmpty );
276 mUnlinkFeatureButton->
setEnabled( linkable && selectionNotEmpty );
281 void QgsRelationEditorWidget::addFeature()
317 void QgsRelationEditorWidget::linkFeature()
328 if ( selectionDlg.
exec() )
344 linkFeature.setAttribute( fieldPair.first, mFeature.
attribute( fieldPair.second ) );
351 linkFeature.setAttribute( fieldPair.first, relatedFeature.
attribute( fieldPair.second ) );
354 newFeatures << linkFeature;
384 void QgsRelationEditorWidget::deleteFeature()
398 void QgsRelationEditorWidget::unlinkFeature()
418 filters.
join(
" OR " ) );
422 .setFilterExpression( filter ) );
445 keyFields.
insert( idx, fld );
460 void QgsRelationEditorWidget::toggleEditing(
bool state )
476 void QgsRelationEditorWidget::saveEdits()
483 void QgsRelationEditorWidget::onCollapsedStateChanged(
bool collapsed )
493 void QgsRelationEditorWidget::updateUi()
const QgsVectorLayerTools * vectorLayerTools() const
Wrapper for iterator of features from vector data provider or vector layer.
QgsVectorLayer * layer() const
Returns the layer this model uses as backend.
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.
QgsAttributeList referencingFields() const
Returns a list of attributes used to form the referencing fields (foreign key) on the referencing lay...
QgsAttributeTableModel * masterModel() const
Returns the model which has the information about all features (not only filtered) ...
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)
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)
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.
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
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 QgsField & at(int i) const
Get field at particular index (must be in range 0..N-1)
const QgsFeatureIds & selectedFeatures()
Get the selected features.
QgsFields fields() const
Returns the list of fields of this layer.
QgsExpression * filterExpression() const
Returns the filter expression if set.
Show a list of the features, where one can be chosen and the according attribute dialog will be prese...
QgsAttributeList referencedFields() const
Returns a list of attributes used to form the referenced fields (most likely primary key) on the refe...
QgsFeatureRequest & setFilterExpression(const QString &expression)
Set the filter expression.
QgsFeatureRequest getReferencedFeatureRequest(const QgsAttributes &attributes) const
Creates a request to return the feature on the referenced (parent) layer which is referenced by the p...
Defines a relation between matching fields of the two involved tables of a relation.
Shows the features and attributes in a table layout.
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...
virtual int capabilities() const
Returns a bitmask containing the supported capabilities Note, some capabilities may change depending ...
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)
QgsFeatureId id() const
Get the feature ID for this feature.
QList< FieldPair > fieldPairs() const
Returns the field pairs which form this relation The first element of each pair are the field names f...
QgsVectorLayer * referencedLayer() const
Access the referenced (parent) layer.
QString expression() const
Return the original, unmodified expression string.
This selection manager synchronizes a local set of selected features with an attribute table...
QgsVectorLayer * referencingLayer() const
Access the referencing (child) layer This is the layer which has the field(s) which point to another ...
int indexFromName(const QString &name) const
Look up field's index from name. Returns -1 on error.
void setTitle(const QString &title)
QString referencedField() const
Get the name of the referenced field.
void loadState()
Will load the collapsed and checked state.
void setText(const QString &text)
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.
QVariant attribute(const QString &name) const
Lookup attribute value from attribute name.
QString referencingField() const
Get the name of the referencing field.
QString arg(qlonglong a, int fieldWidth, int base, const QChar &fillChar) const
Allows modification of attribute values.
int fieldNameIndex(const QString &fieldName) const
Returns the index of a field name or -1 if the field does not exist.
QString name() const
Returns a human readable name for this relation.
This widget is used to show the attributes of a set of features of a QgsVectorLayer.
void addLayout(QLayout *layout, int stretch)