QGIS API Documentation  3.14.0-Pi (9f7028fd23)
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 
101  public:
102 
106  QgsRelationEditorWidget( QWidget *parent SIP_TRANSFERTHIS = nullptr );
107 
109  void setViewMode( QgsDualView::ViewMode mode );
110 
112  QgsDualView::ViewMode viewMode() {return mViewMode;}
113 
117  void setRelationFeature( const QgsRelation &relation, const QgsFeature &feature );
118 
128  void setRelations( const QgsRelation &relation, const QgsRelation &nmrelation );
129 
133  void setFeature( const QgsFeature &feature, bool update = true );
134 
140  void setEditorContext( const QgsAttributeEditorContext &context );
141 
146  QgsAttributeEditorContext editorContext( ) const;
147 
152  QgsIFeatureSelectionManager *featureSelectionManager();
153 
159  bool showLabel() const;
160 
166  void setShowLabel( bool showLabel );
167 
173  bool showLinkButton() const;
174 
180  void setShowLinkButton( bool showLinkButton );
181 
187  bool showUnlinkButton() const;
188 
194  void setShowUnlinkButton( bool showUnlinkButton );
195 
201  void setShowSaveChildEditsButton( bool showChildEdits );
202 
208  bool showSaveChildEditsButton() const;
209 
215  QgsFeature feature() const;
216 
217  public slots:
218 
224  void parentFormValueChanged( const QString &attribute, const QVariant &newValue );
225 
226  private slots:
227  void setViewMode( int mode ) {setViewMode( static_cast<QgsDualView::ViewMode>( mode ) );}
228  void updateButtons();
229 
230  void addFeature( const QgsGeometry &geometry = QgsGeometry() );
231  void addFeatureGeometry();
232  void duplicateFeature();
233  void linkFeature();
234  void deleteFeature( QgsFeatureId featureid = QgsFeatureId() );
235  void deleteSelectedFeatures();
236  void unlinkFeature( QgsFeatureId featureid = QgsFeatureId() );
237  void unlinkSelectedFeatures();
238  void zoomToSelectedFeatures();
239  void saveEdits();
240  void toggleEditing( bool state );
241  void onCollapsedStateChanged( bool collapsed );
242  void showContextMenu( QgsActionMenu *menu, QgsFeatureId fid );
243  void mapToolDeactivated();
244  void onKeyPressed( QKeyEvent *e );
245  void onDigitizingCompleted( const QgsFeature &feature );
246  void onLinkFeatureDlgAccepted();
247 
248  private:
249  void updateUi();
250  void initDualView( QgsVectorLayer *layer, const QgsFeatureRequest &request );
251  void setMapTool( QgsMapTool *mapTool );
252  void unsetMapTool();
253  void updateTitle();
254 
255  QgsDualView *mDualView = nullptr;
256  QPointer<QgsMessageBarItem> mMessageBarItem;
258  QgsVectorLayerSelectionManager *mFeatureSelectionMgr = nullptr;
259  QgsAttributeEditorContext mEditorContext;
260  QgsRelation mRelation;
261  QgsRelation mNmRelation;
262  QgsFeature mFeature;
263 
264  QToolButton *mToggleEditingButton = nullptr;
265  QToolButton *mSaveEditsButton = nullptr;
266  QToolButton *mAddFeatureButton = nullptr;
267  QToolButton *mDuplicateFeatureButton = nullptr;
268  QToolButton *mDeleteFeatureButton = nullptr;
269  QToolButton *mLinkFeatureButton = nullptr;
270  QToolButton *mUnlinkFeatureButton = nullptr;
271  QToolButton *mZoomToFeatureButton = nullptr;
272  QToolButton *mFormViewButton = nullptr;
273  QToolButton *mTableViewButton = nullptr;
274  QToolButton *mAddFeatureGeometryButton = nullptr;
275  QGridLayout *mRelationLayout = nullptr;
277  QButtonGroup *mViewModeButtonGroup = nullptr;
278 
279  bool mShowLabel = true;
280  bool mVisible = false;
281 
287  void deleteFeatures( const QgsFeatureIds &featureids );
288 
294  void unlinkFeatures( const QgsFeatureIds &featureids );
295 };
296 
297 #endif // QGSRELATIONEDITOR_H
qgscollapsiblegroupbox.h
QgsRelationEditorWidget
Definition: qgsrelationeditorwidget.h:83
QgsVectorLayerTools
Definition: qgsvectorlayertools.h:39
qgsdualview.h
QgsDualView
Definition: qgsdualview.h:41
QgsCollapsibleGroupBox
Definition: qgscollapsiblegroupbox.h:178
qgsrelationeditorwidget.h
QgsMapTool
Definition: qgsmaptool.h:63
SIP_CONVERT_TO_SUBCLASS_CODE
#define SIP_CONVERT_TO_SUBCLASS_CODE(code)
Definition: qgis_sip.h:172
QgsFeatureRequest
Definition: qgsfeaturerequest.h:75
qgsvectorlayerselectionmanager.h
QObjectUniquePtr< QgsMapToolDigitizeFeature >
qobjectuniqueptr.h
QgsDualView::AttributeEditor
@ AttributeEditor
Show a list of the features, where one can be chosen and the according attribute dialog will be prese...
Definition: qgsdualview.h:65
QgsActionMenu
Definition: qgsactionmenu.h:37
QgsMapToolDigitizeFeature
This tool digitizes geometry of new point/line/polygon features on already existing vector layers Onc...
Definition: qgsmaptooldigitizefeature.h:31
qgsattributeeditorcontext.h
QgsVectorLayerSelectionManager
Definition: qgsvectorlayerselectionmanager.h:32
qgsrelation.h
QgsFeatureIds
QSet< QgsFeatureId > QgsFeatureIds
Definition: qgsfeatureid.h:34
QgsDualView::ViewMode
ViewMode
The view modes, in which this widget can present information.
Definition: qgsdualview.h:52
QgsVectorLayerSelectionManager::selectedFeatureCount
int selectedFeatureCount() override
Returns the number of features that are selected in this layer.
Definition: qgsvectorlayerselectionmanager.cpp:27
QgsGeometry
Definition: qgsgeometry.h:122
QgsVectorLayer
Definition: qgsvectorlayer.h:385
QgsRelation
Definition: qgsrelation.h:41
QgsFeature
Definition: qgsfeature.h:55
QgsIFeatureSelectionManager
Definition: qgsifeatureselectionmanager.h:31
QgsAttributeEditorContext
Definition: qgsattributeeditorcontext.h:40
SIP_END
#define SIP_END
Definition: qgis_sip.h:189
SIP_TRANSFERTHIS
#define SIP_TRANSFERTHIS
Definition: qgis_sip.h:53
QgsVectorLayerSelectionManager::selectedFeatureIds
const QgsFeatureIds & selectedFeatureIds() const override
Returns reference to identifiers of selected features.
Definition: qgsvectorlayerselectionmanager.cpp:47
QgsFeatureId
qint64 QgsFeatureId
Definition: qgsfeatureid.h:25