QGIS API Documentation  3.17.0-Master (8af46bc54f)
qgsrelationeditorwidget.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgsrelationeditorwidget.h
3  --------------------------------------
4  Date : 17.5.2013
5  Copyright : (C) 2013 Matthias Kuhn
6  Email : matthias at opengis dot ch
7  ***************************************************************************
8  * *
9  * This program is free software; you can redistribute it and/or modify *
10  * it under the terms of the GNU General Public License as published by *
11  * the Free Software Foundation; either version 2 of the License, or *
12  * (at your option) any later version. *
13  * *
14  ***************************************************************************/
15 
16 #ifndef QGSRELATIONEDITOR_H
17 #define QGSRELATIONEDITOR_H
18 
19 #include <QWidget>
20 #include <QToolButton>
21 #include <QButtonGroup>
22 #include <QGridLayout>
23 #include "qobjectuniqueptr.h"
24 
25 #include "qobjectuniqueptr.h"
27 #include "qgscollapsiblegroupbox.h"
28 #include "qgsdualview.h"
29 #include "qgsrelation.h"
31 #include "qgis_gui.h"
32 
33 class QgsFeature;
34 class QgsVectorLayer;
36 class QgsMapTool;
38 
39 #ifdef SIP_RUN
40 % ModuleHeaderCode
41 // fix to allow compilation with sip that for some reason
42 // doesn't add this include to the file where the code from
43 // ConvertToSubClassCode goes.
45 % End
46 #endif
47 
48 
50 #ifndef SIP_RUN
51 
56 class QgsFilteredSelectionManager : public QgsVectorLayerSelectionManager
57 {
58  Q_OBJECT
59 
60  public:
61  QgsFilteredSelectionManager( QgsVectorLayer *layer, const QgsFeatureRequest &request, QObject *parent = nullptr );
62 
63  const QgsFeatureIds &selectedFeatureIds() const override;
64  int selectedFeatureCount() override;
65 
66  private slots:
67 
68  void onSelectionChanged( const QgsFeatureIds &selected, const QgsFeatureIds &deselected, bool clearAndSelect ) override;
69 
70  private:
71 
72  QgsFeatureRequest mRequest;
73  QgsFeatureIds mSelectedFeatureIds;
74 };
75 #endif
76 
78 
84 {
85 
86 #ifdef SIP_RUN
88  if ( qobject_cast<QgsRelationEditorWidget *>( sipCpp ) )
89  sipType = sipType_QgsRelationEditorWidget;
90  else
91  sipType = NULL;
92  SIP_END
93 #endif
94 
95 
96 
97  Q_OBJECT
98  Q_PROPERTY( QgsDualView::ViewMode viewMode READ viewMode WRITE setViewMode )
99  Q_PROPERTY( bool showLabel READ showLabel WRITE setShowLabel )
100  Q_PROPERTY( QgsAttributeEditorRelation::Buttons visibleButtons READ visibleButtons WRITE setVisibleButtons )
101 
102  public:
103 
104 
108  QgsRelationEditorWidget( QWidget *parent SIP_TRANSFERTHIS = nullptr );
109 
111  void setViewMode( QgsDualView::ViewMode mode );
112 
114  QgsDualView::ViewMode viewMode() {return mViewMode;}
115 
119  void setRelationFeature( const QgsRelation &relation, const QgsFeature &feature );
120 
130  void setRelations( const QgsRelation &relation, const QgsRelation &nmrelation );
131 
135  void setFeature( const QgsFeature &feature, bool update = true );
136 
142  void setEditorContext( const QgsAttributeEditorContext &context );
143 
148  QgsAttributeEditorContext editorContext( ) const;
149 
154  QgsIFeatureSelectionManager *featureSelectionManager();
155 
161  bool showLabel() const;
162 
168  void setShowLabel( bool showLabel );
169 
175  Q_DECL_DEPRECATED bool showLinkButton() const SIP_DEPRECATED;
176 
182  Q_DECL_DEPRECATED void setShowLinkButton( bool showLinkButton ) SIP_DEPRECATED;
183 
189  Q_DECL_DEPRECATED bool showUnlinkButton() const SIP_DEPRECATED;
190 
196  Q_DECL_DEPRECATED void setShowUnlinkButton( bool showUnlinkButton ) SIP_DEPRECATED;
197 
203  Q_DECL_DEPRECATED void setShowSaveChildEditsButton( bool showChildEdits ) SIP_DEPRECATED;
204 
210  Q_DECL_DEPRECATED bool showSaveChildEditsButton() const SIP_DEPRECATED;
211 
216  void setVisibleButtons( const QgsAttributeEditorRelation::Buttons &buttons );
217 
222  QgsAttributeEditorRelation::Buttons visibleButtons() const;
223 
228  bool forceSuppressFormPopup() const;
229 
235  void setForceSuppressFormPopup( bool forceSuppressFormPopup );
236 
241  QVariant nmRelationId() const;
242 
248  void setNmRelationId( const QVariant &nmRelationId = QVariant() );
249 
254  QString label() const;
255 
261  void setLabel( const QString &label = QString() );
262 
268  QgsFeature feature() const;
269 
270  public slots:
271 
277  void parentFormValueChanged( const QString &attribute, const QVariant &newValue );
278 
279  private slots:
280  void setViewMode( int mode ) {setViewMode( static_cast<QgsDualView::ViewMode>( mode ) );}
281  void updateButtons();
282 
283  void addFeature( const QgsGeometry &geometry = QgsGeometry() );
284  void addFeatureGeometry();
285  void duplicateFeature();
286  void linkFeature();
287  void deleteFeature( QgsFeatureId featureid = QgsFeatureId() );
288  void deleteSelectedFeatures();
289  void unlinkFeature( QgsFeatureId featureid = QgsFeatureId() );
290  void unlinkSelectedFeatures();
291  void zoomToSelectedFeatures();
292  void saveEdits();
293  void toggleEditing( bool state );
294  void onCollapsedStateChanged( bool collapsed );
295  void showContextMenu( QgsActionMenu *menu, QgsFeatureId fid );
296  void mapToolDeactivated();
297  void onKeyPressed( QKeyEvent *e );
298  void onDigitizingCompleted( const QgsFeature &feature );
299  void onLinkFeatureDlgAccepted();
300 
301  private:
302  void updateUi();
303  void initDualView( QgsVectorLayer *layer, const QgsFeatureRequest &request );
304  void setMapTool( QgsMapTool *mapTool );
305  void unsetMapTool();
306  void updateTitle();
307 
308  QgsDualView *mDualView = nullptr;
309  QPointer<QgsMessageBarItem> mMessageBarItem;
311  QgsVectorLayerSelectionManager *mFeatureSelectionMgr = nullptr;
312  QgsAttributeEditorContext mEditorContext;
313  QgsRelation mRelation;
314  QgsRelation mNmRelation;
315  QgsFeature mFeature;
316 
317  QToolButton *mToggleEditingButton = nullptr;
318  QToolButton *mSaveEditsButton = nullptr;
319  QToolButton *mAddFeatureButton = nullptr;
320  QToolButton *mDuplicateFeatureButton = nullptr;
321  QToolButton *mDeleteFeatureButton = nullptr;
322  QToolButton *mLinkFeatureButton = nullptr;
323  QToolButton *mUnlinkFeatureButton = nullptr;
324  QToolButton *mZoomToFeatureButton = nullptr;
325  QToolButton *mFormViewButton = nullptr;
326  QToolButton *mTableViewButton = nullptr;
327  QToolButton *mAddFeatureGeometryButton = nullptr;
328  QGridLayout *mRelationLayout = nullptr;
330  QButtonGroup *mViewModeButtonGroup = nullptr;
331 
332  QgsAttributeEditorRelation::Buttons mButtonsVisibility = QgsAttributeEditorRelation::Button::AllButtons;
333  bool mShowLabel = true;
334  bool mVisible = false;
335  bool mLayerInSameTransactionGroup = false;
336 
337  bool mForceSuppressFormPopup = false;
338  QVariant mNmRelationId;
339  QString mLabel;
340 
346  void deleteFeatures( const QgsFeatureIds &featureids );
347 
353  void unlinkFeatures( const QgsFeatureIds &featureids );
354 };
355 
356 
357 #endif // QGSRELATIONEDITOR_H
Methods in this class are used to handle basic operations on vector layers.
QSet< QgsFeatureId > QgsFeatureIds
Definition: qgsfeatureid.h:37
#define SIP_TRANSFERTHIS
Definition: qgis_sip.h:53
A groupbox that collapses/expands when toggled and can save its collapsed and checked states...
This class contains context information for attribute editor widgets.
ViewMode
The view modes, in which this widget can present information.
Definition: qgsdualview.h:52
qint64 QgsFeatureId
64 bit feature ids negative numbers are used for uncommitted/newly added features ...
Definition: qgsfeatureid.h:28
A geometry is the spatial representation of a feature.
Definition: qgsgeometry.h:123
This element will load a relation editor onto the form.
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
Definition: qgsfeature.h:55
const QgsFeatureIds & selectedFeatureIds() const override
Returns reference to identifiers of selected features.
Show a list of the features, where one can be chosen and the according attribute dialog will be prese...
Definition: qgsdualview.h:65
This class is a menu that is populated automatically with the actions defined for a given layer...
Definition: qgsactionmenu.h:37
This class wraps a request for features to a vector layer (or directly its vector data provider)...
#define SIP_END
Definition: qgis_sip.h:194
#define SIP_DEPRECATED
Definition: qgis_sip.h:106
Abstract base class for all map tools.
Definition: qgsmaptool.h:63
int selectedFeatureCount() override
Returns the number of features that are selected in this layer.
#define SIP_CONVERT_TO_SUBCLASS_CODE(code)
Definition: qgis_sip.h:177
This tool digitizes geometry of new point/line/polygon features on already existing vector layers Onc...
Is an interface class to abstract feature selection handling.
Represents a vector layer which manages a vector based data sets.
This widget is used to show the attributes of a set of features of a QgsVectorLayer.
Definition: qgsdualview.h:41