28 #include <QHBoxLayout> 37 , mInitialized( false )
39 QVBoxLayout* topLayout =
new QVBoxLayout(
this );
40 topLayout->setContentsMargins( 0, 9, 0, 0 );
41 setLayout( topLayout );
44 QHBoxLayout* buttonLayout =
new QHBoxLayout();
45 buttonLayout->setContentsMargins( 0, 0, 0, 0 );
47 mToggleEditingButton =
new QToolButton(
this );
49 mToggleEditingButton->setText(
tr(
"Toggle editing" ) );
50 mToggleEditingButton->setEnabled(
false );
51 mToggleEditingButton->setCheckable(
true );
52 buttonLayout->addWidget( mToggleEditingButton );
54 mSaveEditsButton =
new QToolButton(
this );
56 mSaveEditsButton->setText(
tr(
"Save layer edits" ) );
57 mSaveEditsButton->setEnabled(
true );
58 buttonLayout->addWidget( mSaveEditsButton );
60 mAddFeatureButton =
new QToolButton(
this );
62 mAddFeatureButton->setText(
tr(
"Add feature" ) );
63 buttonLayout->addWidget( mAddFeatureButton );
65 mDeleteFeatureButton =
new QToolButton(
this );
67 mDeleteFeatureButton->setText(
tr(
"Delete feature" ) );
68 buttonLayout->addWidget( mDeleteFeatureButton );
70 mLinkFeatureButton =
new QToolButton(
this );
72 mLinkFeatureButton->setText(
tr(
"Link feature" ) );
73 buttonLayout->addWidget( mLinkFeatureButton );
75 mUnlinkFeatureButton =
new QToolButton(
this );
77 mUnlinkFeatureButton->setText(
tr(
"Unlink feature" ) );
78 buttonLayout->addWidget( mUnlinkFeatureButton );
80 buttonLayout->addItem(
new QSpacerItem( 0, 0, QSizePolicy::Expanding ) );
82 mFormViewButton =
new QToolButton(
this );
83 mFormViewButton->setText(
tr(
"Form view" ) );
85 mFormViewButton->setCheckable(
true );
87 buttonLayout->addWidget( mFormViewButton );
89 mTableViewButton =
new QToolButton(
this );
90 mTableViewButton->setText(
tr(
"Table view" ) );
92 mTableViewButton->setCheckable(
true );
94 buttonLayout->addWidget( mTableViewButton );
96 mViewModeButtonGroup =
new QButtonGroup(
this );
101 topLayout->addLayout( buttonLayout );
104 referencingLayerEditingToggled();
106 mRelationLayout =
new QGridLayout();
107 mRelationLayout->setContentsMargins( 0, 0, 0, 0 );
108 topLayout->addLayout( mRelationLayout );
111 mDualView->
setView( mViewMode );
115 mRelationLayout->addWidget( mDualView );
117 connect(
this, SIGNAL(
collapsedStateChanged(
bool ) ),
this, SLOT( onCollapsedStateChanged(
bool ) ) );
118 connect( mViewModeButtonGroup, SIGNAL( buttonClicked(
int ) ),
this, SLOT(
setViewMode(
int ) ) );
119 connect( mToggleEditingButton, SIGNAL( clicked(
bool ) ),
this, SLOT( toggleEditing(
bool ) ) );
120 connect( mSaveEditsButton, SIGNAL( clicked() ),
this, SLOT( saveEdits() ) );
121 connect( mAddFeatureButton, SIGNAL( clicked() ),
this, SLOT( addFeature() ) );
122 connect( mDeleteFeatureButton, SIGNAL( clicked() ),
this, SLOT( deleteFeature() ) );
123 connect( mLinkFeatureButton, SIGNAL( clicked() ),
this, SLOT( linkFeature() ) );
124 connect( mUnlinkFeatureButton, SIGNAL( clicked() ),
this, SLOT( unlinkFeature() ) );
131 disconnect( mRelation.
referencingLayer(), SIGNAL( editingStarted() ),
this, SLOT( referencingLayerEditingToggled() ) );
132 disconnect( mRelation.
referencingLayer(), SIGNAL( editingStopped() ),
this, SLOT( referencingLayerEditingToggled() ) );
135 mRelation = relation;
138 connect( mRelation.referencingLayer(), SIGNAL( editingStarted() ),
this, SLOT( referencingLayerEditingToggled() ) );
139 connect( mRelation.referencingLayer(), SIGNAL( editingStopped() ),
this, SLOT( referencingLayerEditingToggled() ) );
141 setTitle( relation.
name() );
146 if ( canChangeAttributes && !lyr->isReadOnly() )
148 mToggleEditingButton->setEnabled(
true );
149 referencingLayerEditingToggled();
153 mToggleEditingButton->setEnabled(
false );
164 mDualView->
init( mRelation.referencingLayer(), 0, myRequest, mEditorContext );
170 mEditorContext = context;
179 void QgsRelationEditorWidget::referencingLayerEditingToggled()
181 bool editable =
false;
187 mAddFeatureButton->setEnabled( editable );
188 mLinkFeatureButton->setEnabled( editable );
189 mDeleteFeatureButton->setEnabled( editable );
190 mUnlinkFeatureButton->setEnabled( editable );
191 mToggleEditingButton->setChecked( editable );
192 mSaveEditsButton->setEnabled( editable );
195 void QgsRelationEditorWidget::addFeature()
209 void QgsRelationEditorWidget::linkFeature()
213 if ( selectionDlg.exec() )
215 QMap<int, QVariant> keys;
220 keys.insert( idx, val );
223 Q_FOREACH (
QgsFeatureId fid, selectionDlg.selectedFeatures() )
225 QMapIterator<int, QVariant> it( keys );
226 while ( it.hasNext() )
235 void QgsRelationEditorWidget::deleteFeature()
243 void QgsRelationEditorWidget::unlinkFeature()
245 QMap<int, QgsField> keyFields;
255 keyFields.insert( idx, fld );
260 QMapIterator<int, QgsField> it( keyFields );
261 while ( it.hasNext() )
269 void QgsRelationEditorWidget::toggleEditing(
bool state )
281 void QgsRelationEditorWidget::saveEdits()
286 void QgsRelationEditorWidget::onCollapsedStateChanged(
bool collapsed )
288 if ( !mInitialized && !collapsed && mRelation.
isValid() )
bool isValid() const
Returns the validity of this relation.
const QString name() const
QMap< int, QVariant > QgsAttributeMap
void setFeatureSelectionManager(QgsIFeatureSelectionManager *featureSelectionManager)
A groupbox that collapses/expands when toggled and can save its collapsed and checked states...
bool deleteFeature(QgsFeatureId fid)
delete a feature from the layer (but does not commit it)
This class contains context information for attribute editor widgets.
static QIcon getThemeIcon(const QString &theName)
Helper to get a theme icon.
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.
Container of fields for a vector layer.
const QgsField & at(int i) const
Get field at particular index (must be in range 0..N-1)
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...
virtual bool isEditable() const override
Returns true if the provider is in editing mode.
void setView(ViewMode view)
Change the current view mode.
Show a list of the features, where one can be chosen and the according attribute dialog will be prese...
Defines a relation between matchin fields of the two involved tables of a relation.
Shows the features and attributes in a table layout.
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 ...
This class wraps a request for features to a vector layer (or directly its vector data provider)...
void init(QgsVectorLayer *layer, QgsMapCanvas *mapCanvas, const QgsFeatureRequest &request=QgsFeatureRequest(), const QgsAttributeEditorContext &context=QgsAttributeEditorContext())
Has to be called to initialize the dual view.
Q_DECL_DEPRECATED bool changeAttributeValue(QgsFeatureId fid, int field, QVariant value, bool emitSignal)
Changes an attribute value (but does not commit it)
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...
int indexFromName(const QString &name) const
Look up field's index from name. Returns -1 on error.
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) ...
const QString & referencingField() const
Get the name of the referencing field.
QVariant attribute(const QString &name) const
Lookup attribute value from attribute name.
QgsVectorLayer * layer() const
Returns the layer this model uses as backend.
const QgsVectorLayerTools * vectorLayerTools() const
QList< FieldPair > fieldPairs() const
Returns the field pairs which form this relation The first element of each pair are the field names f...
const QgsFields & pendingFields() const
returns field list in the to-be-committed state
QgsVectorDataProvider * dataProvider()
Returns the data provider.
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.
allows modification of attribute values
This widget is used to show the attributes of a set of features of a QgsVectorLayer.
const QString & referencedField() const
Get the name of the referenced field.