30 #include <QHBoxLayout> 48 mToggleEditingButton->
setObjectName(
"mToggleEditingButton" );
50 mToggleEditingButton->
setText(
tr(
"Toggle editing" ) );
53 mToggleEditingButton->
setToolTip(
tr(
"Toggle editing mode for child layer" ) );
54 buttonLayout->
addWidget( mToggleEditingButton );
58 mSaveEditsButton->
setText(
tr(
"Save child layer edits" ) );
59 mSaveEditsButton->
setToolTip(
tr(
"Save child layer edits" ) );
61 buttonLayout->
addWidget( mSaveEditsButton );
65 mAddFeatureButton->
setText(
tr(
"Add child feature" ) );
66 mAddFeatureButton->
setToolTip(
tr(
"Add child feature" ) );
68 buttonLayout->
addWidget( mAddFeatureButton );
72 mDeleteFeatureButton->
setText(
tr(
"Delete child feature" ) );
73 mDeleteFeatureButton->
setToolTip(
tr(
"Delete child feature" ) );
74 mDeleteFeatureButton->
setObjectName(
"mDeleteFeatureButton" );
75 buttonLayout->
addWidget( mDeleteFeatureButton );
79 mLinkFeatureButton->
setText(
tr(
"Link existing features" ) );
80 mLinkFeatureButton->
setToolTip(
tr(
"Link existing child features" ) );
82 buttonLayout->
addWidget( mLinkFeatureButton );
86 mUnlinkFeatureButton->
setText(
tr(
"Unlink feature" ) );
87 mUnlinkFeatureButton->
setToolTip(
tr(
"Unlink child feature" ) );
88 mUnlinkFeatureButton->
setObjectName(
"mUnlinkFeatureButton" );
89 buttonLayout->
addWidget( mUnlinkFeatureButton );
94 mFormViewButton->
setText(
tr(
"Form view" ) );
95 mFormViewButton->
setToolTip(
tr(
"Switch to form view" ) );
99 buttonLayout->
addWidget( mFormViewButton );
102 mTableViewButton->
setText(
tr(
"Table view" ) );
103 mTableViewButton->
setToolTip(
tr(
"Switch to table view" ) );
107 buttonLayout->
addWidget( mTableViewButton );
121 mDualView->
setView( mViewMode );
128 connect( mViewModeButtonGroup, SIGNAL( buttonClicked(
int ) ),
this, SLOT(
setViewMode(
int ) ) );
129 connect( mToggleEditingButton, SIGNAL(
clicked(
bool ) ),
this, SLOT( toggleEditing(
bool ) ) );
130 connect( mSaveEditsButton, SIGNAL(
clicked() ),
this, SLOT( saveEdits() ) );
131 connect( mAddFeatureButton, SIGNAL(
clicked() ),
this, SLOT( addFeature() ) );
132 connect( mDeleteFeatureButton, SIGNAL(
clicked() ),
this, SLOT( deleteFeature() ) );
133 connect( mLinkFeatureButton, SIGNAL(
clicked() ),
this, SLOT( linkFeature() ) );
134 connect( mUnlinkFeatureButton, SIGNAL(
clicked() ),
this, SLOT( unlinkFeature() ) );
149 mRelation = relation;
152 connect( mRelation.referencingLayer(), SIGNAL( editingStarted() ),
this, SLOT( updateButtons() ) );
153 connect( mRelation.referencingLayer(), SIGNAL( editingStopped() ),
this, SLOT( updateButtons() ) );
161 if ( canChangeAttributes && !lyr->readOnly() )
182 mDualView->
init( mRelation.referencingLayer(),
nullptr, myRequest, mEditorContext );
200 mRelation = relation;
201 mNmRelation = nmrelation;
203 if ( !mRelation.isValid() )
206 connect( mRelation.referencingLayer(), SIGNAL( editingStarted() ),
this, SLOT( updateButtons() ) );
207 connect( mRelation.referencingLayer(), SIGNAL( editingStopped() ),
this, SLOT( updateButtons() ) );
220 if ( canChangeAttributes && !lyr->readOnly() )
238 mEditorContext = context;
243 return mFeatureSelectionMgr;
260 void QgsRelationEditorWidget::updateButtons()
262 bool editable =
false;
263 bool linkable =
false;
279 mDeleteFeatureButton->
setEnabled( editable && selectionNotEmpty );
280 mUnlinkFeatureButton->
setEnabled( linkable && selectionNotEmpty );
285 void QgsRelationEditorWidget::addFeature()
300 int attrCount = fields.
size();
305 for (
int i = 0; i < attrCount; ++i )
309 else if ( i == secondIdx )
333 void QgsRelationEditorWidget::linkFeature()
344 if ( selectionDlg.
exec() )
354 int attrCount = fields.
size();
369 for (
int i = 0; i < attrCount; ++i )
373 else if ( i == secondIdx )
379 newFeatures << linkFeature;
410 void QgsRelationEditorWidget::deleteFeature()
424 void QgsRelationEditorWidget::unlinkFeature()
444 filters.
join(
" OR " ) );
448 .setFilterExpression( filter ) );
471 keyFields.
insert( idx, fld );
486 void QgsRelationEditorWidget::toggleEditing(
bool state )
502 void QgsRelationEditorWidget::saveEdits()
509 void QgsRelationEditorWidget::onCollapsedStateChanged(
bool collapsed )
519 void QgsRelationEditorWidget::updateUi()
574 mLinkFeatureButton->
setVisible( showLinkButton );
579 return mUnlinkFeatureButton->
isVisible();
584 mUnlinkFeatureButton->
setVisible( showUnlinkButton );
596 if ( mShowLabel && mRelation.
isValid() )
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)
int size() const
Return number of items.
void init(QgsVectorLayer *layer, QgsMapCanvas *mapCanvas, const QgsFeatureRequest &request=QgsFeatureRequest(), const QgsAttributeEditorContext &context=QgsAttributeEditorContext(), bool loadFeatures=true)
Has to be called to initialize the dual view.
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 (ch...
QgsAttributeTableModel * masterModel() const
Returns the model which has the information about all features (not only filtered) ...
QMap< int, QVariant > QgsAttributeMap
void setFeatureSelectionManager(QgsIFeatureSelectionManager *featureSelectionManager)
Set the feature selection model.
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.
QSet< QgsVectorLayer * > layers() const
Get the set of layers currently managed by this transaction group.
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.
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 addFeature(QgsFeature &feature, bool alsoUpdateExtent=true)
Adds a feature.
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
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 o...
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...
bool contains(const T &value) const
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)
static QgsProject * instance()
Returns the QgsProject singleton instance.
QString referencedField() const
Get the name of the referenced (parent) 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 (child) 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)
QVariant defaultValue(int index, const QgsFeature &feature=QgsFeature(), QgsExpressionContext *context=nullptr) const
Returns the calculated default value for the specified field index.