QGIS API Documentation  3.12.1-BucureČ™ti (121cc00ff0)
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 
114  void setRelationFeature( const QgsRelation &relation, const QgsFeature &feature );
115 
125  void setRelations( const QgsRelation &relation, const QgsRelation &nmrelation );
126 
127  void setFeature( const QgsFeature &feature );
128 
134  void setEditorContext( const QgsAttributeEditorContext &context );
135 
140  QgsIFeatureSelectionManager *featureSelectionManager();
141 
147  bool showLabel() const;
148 
154  void setShowLabel( bool showLabel );
155 
161  bool showLinkButton() const;
162 
168  void setShowLinkButton( bool showLinkButton );
169 
175  bool showUnlinkButton() const;
176 
182  void setShowUnlinkButton( bool showUnlinkButton );
183 
184  private slots:
185  void setViewMode( int mode ) {setViewMode( static_cast<QgsDualView::ViewMode>( mode ) );}
186  void updateButtons();
187 
188  void addFeature( const QgsGeometry &geometry = QgsGeometry() );
189  void addFeatureGeometry();
190  void duplicateFeature();
191  void linkFeature();
192  void deleteFeature( QgsFeatureId featureid = QgsFeatureId() );
193  void deleteSelectedFeatures();
194  void unlinkFeature( QgsFeatureId featureid = QgsFeatureId() );
195  void unlinkSelectedFeatures();
196  void zoomToSelectedFeatures();
197  void saveEdits();
198  void toggleEditing( bool state );
199  void onCollapsedStateChanged( bool collapsed );
200  void showContextMenu( QgsActionMenu *menu, QgsFeatureId fid );
201  void mapToolDeactivated();
202  void onKeyPressed( QKeyEvent *e );
203  void onDigitizingCompleted( const QgsFeature &feature );
204  void onLinkFeatureDlgAccepted();
205 
206  private:
207  void updateUi();
208  void initDualView( QgsVectorLayer *layer, const QgsFeatureRequest &request );
209  void setMapTool( QgsMapTool *mapTool );
210  void unsetMapTool();
211 
212  QgsDualView *mDualView = nullptr;
213  QPointer<QgsMessageBarItem> mMessageBarItem;
215  QgsVectorLayerSelectionManager *mFeatureSelectionMgr = nullptr;
216  QgsAttributeEditorContext mEditorContext;
217  QgsRelation mRelation;
218  QgsRelation mNmRelation;
219  QgsFeature mFeature;
220 
221  QToolButton *mToggleEditingButton = nullptr;
222  QToolButton *mSaveEditsButton = nullptr;
223  QToolButton *mAddFeatureButton = nullptr;
224  QToolButton *mDuplicateFeatureButton = nullptr;
225  QToolButton *mDeleteFeatureButton = nullptr;
226  QToolButton *mLinkFeatureButton = nullptr;
227  QToolButton *mUnlinkFeatureButton = nullptr;
228  QToolButton *mZoomToFeatureButton = nullptr;
229  QToolButton *mFormViewButton = nullptr;
230  QToolButton *mTableViewButton = nullptr;
231  QToolButton *mAddFeatureGeometryButton = nullptr;
232  QGridLayout *mRelationLayout = nullptr;
234  QButtonGroup *mViewModeButtonGroup = nullptr;
235 
236  bool mShowLabel = true;
237  bool mVisible = false;
238 
244  void deleteFeatures( const QgsFeatureIds &featureids );
245 
251  void unlinkFeatures( const QgsFeatureIds &featureids );
252 };
253 
254 #endif // QGSRELATIONEDITOR_H
Methods in this class are used to handle basic operations on vector layers.
QSet< QgsFeatureId > QgsFeatureIds
Definition: qgsfeatureid.h:34
#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
Definition: qgsfeatureid.h:25
A geometry is the spatial representation of a feature.
Definition: qgsgeometry.h:122
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:189
Abstract base class for all map tools.
Definition: qgsmaptool.h:62
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:172
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