QGIS API Documentation  3.13.0-Master (788156190c)
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  QgsIFeatureSelectionManager *featureSelectionManager();
147 
153  bool showLabel() const;
154 
160  void setShowLabel( bool showLabel );
161 
167  bool showLinkButton() const;
168 
174  void setShowLinkButton( bool showLinkButton );
175 
181  bool showUnlinkButton() const;
182 
188  void setShowUnlinkButton( bool showUnlinkButton );
189 
195  void setShowSaveChildEditsButton( bool showChildEdits );
196 
202  bool showSaveChildEditsButton() const;
203 
209  QgsFeature feature() const;
210 
211  public slots:
212 
218  void parentFormValueChanged( const QString &attribute, const QVariant &newValue );
219 
220  private slots:
221  void setViewMode( int mode ) {setViewMode( static_cast<QgsDualView::ViewMode>( mode ) );}
222  void updateButtons();
223 
224  void addFeature( const QgsGeometry &geometry = QgsGeometry() );
225  void addFeatureGeometry();
226  void duplicateFeature();
227  void linkFeature();
228  void deleteFeature( QgsFeatureId featureid = QgsFeatureId() );
229  void deleteSelectedFeatures();
230  void unlinkFeature( QgsFeatureId featureid = QgsFeatureId() );
231  void unlinkSelectedFeatures();
232  void zoomToSelectedFeatures();
233  void saveEdits();
234  void toggleEditing( bool state );
235  void onCollapsedStateChanged( bool collapsed );
236  void showContextMenu( QgsActionMenu *menu, QgsFeatureId fid );
237  void mapToolDeactivated();
238  void onKeyPressed( QKeyEvent *e );
239  void onDigitizingCompleted( const QgsFeature &feature );
240  void onLinkFeatureDlgAccepted();
241 
242  private:
243  void updateUi();
244  void initDualView( QgsVectorLayer *layer, const QgsFeatureRequest &request );
245  void setMapTool( QgsMapTool *mapTool );
246  void unsetMapTool();
247 
248  QgsDualView *mDualView = nullptr;
249  QPointer<QgsMessageBarItem> mMessageBarItem;
251  QgsVectorLayerSelectionManager *mFeatureSelectionMgr = nullptr;
252  QgsAttributeEditorContext mEditorContext;
253  QgsRelation mRelation;
254  QgsRelation mNmRelation;
255  QgsFeature mFeature;
256 
257  QToolButton *mToggleEditingButton = nullptr;
258  QToolButton *mSaveEditsButton = nullptr;
259  QToolButton *mAddFeatureButton = nullptr;
260  QToolButton *mDuplicateFeatureButton = nullptr;
261  QToolButton *mDeleteFeatureButton = nullptr;
262  QToolButton *mLinkFeatureButton = nullptr;
263  QToolButton *mUnlinkFeatureButton = nullptr;
264  QToolButton *mZoomToFeatureButton = nullptr;
265  QToolButton *mFormViewButton = nullptr;
266  QToolButton *mTableViewButton = nullptr;
267  QToolButton *mAddFeatureGeometryButton = nullptr;
268  QGridLayout *mRelationLayout = nullptr;
270  QButtonGroup *mViewModeButtonGroup = nullptr;
271 
272  bool mShowLabel = true;
273  bool mVisible = false;
274 
280  void deleteFeatures( const QgsFeatureIds &featureids );
281 
287  void unlinkFeatures( const QgsFeatureIds &featureids );
288 };
289 
290 #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:62
SIP_CONVERT_TO_SUBCLASS_CODE
#define SIP_CONVERT_TO_SUBCLASS_CODE(code)
Definition: qgis_sip.h:172
QgsFeatureRequest
Definition: qgsfeaturerequest.h:72
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:386
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