QGIS API Documentation  3.22.4-Białowieża (ce8e65e95e)
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 QGSRELATIONEDITORWIDGET_H
17 #define QGSRELATIONEDITORWIDGET_H
18 
19 #include <QWidget>
20 #include <QToolButton>
21 #include <QButtonGroup>
22 #include <QGridLayout>
23 #include "qobjectuniqueptr.h"
24 
25 #include "ui_qgsrelationeditorconfigwidgetbase.h"
26 
28 #include "qobjectuniqueptr.h"
30 #include "qgsdualview.h"
31 #include "qgsrelation.h"
33 #include "qgis_gui.h"
34 
35 class QgsFeature;
36 class QgsVectorLayer;
38 class QgsMapTool;
40 
41 #ifdef SIP_RUN
42 % ModuleHeaderCode
43 // fix to allow compilation with sip that for some reason
44 // doesn't add this include to the file where the code from
45 // ConvertToSubClassCode goes.
47 % End
48 #endif
49 
50 
52 #ifndef SIP_RUN
53 
58 class QgsFilteredSelectionManager : public QgsVectorLayerSelectionManager
59 {
60  Q_OBJECT
61 
62  public:
63  QgsFilteredSelectionManager( QgsVectorLayer *layer, const QgsFeatureRequest &request, QObject *parent = nullptr );
64 
65  const QgsFeatureIds &selectedFeatureIds() const override;
66  int selectedFeatureCount() override;
67 
68  private slots:
69 
70  void onSelectionChanged( const QgsFeatureIds &selected, const QgsFeatureIds &deselected, bool clearAndSelect ) override;
71 
72  private:
73 
74  QgsFeatureRequest mRequest;
75  QgsFeatureIds mSelectedFeatureIds;
76 };
77 #endif
79 
80 
88 {
89 
90  Q_OBJECT
91  Q_PROPERTY( QgsDualView::ViewMode viewMode READ viewMode WRITE setViewMode )
92  Q_PROPERTY( Buttons visibleButtons READ visibleButtons WRITE setVisibleButtons )
93 
94  public:
95 
100  enum Button
101  {
102  NoButton = 0,
103  Link = 1 << 1,
104  Unlink = 1 << 2,
105  SaveChildEdits = 1 << 3,
106  AddChildFeature = 1 << 4,
107  DuplicateChildFeature = 1 << 5,
108  DeleteChildFeature = 1 << 6,
109  ZoomToChildFeature = 1 << 7,
110  AllButtons = Link | Unlink | SaveChildEdits | AddChildFeature | DuplicateChildFeature | DeleteChildFeature | ZoomToChildFeature
111  };
112  Q_ENUM( Button )
113  Q_DECLARE_FLAGS( Buttons, Button )
114  Q_FLAG( Buttons )
115 
116 
121  QgsRelationEditorWidget( const QVariantMap &config, QWidget *parent SIP_TRANSFERTHIS = nullptr );
122 
124  void setViewMode( QgsDualView::ViewMode mode );
125 
127  QgsDualView::ViewMode viewMode() {return mViewMode;}
128 
133  QgsIFeatureSelectionManager *featureSelectionManager();
134 
140  void setEditorContext( const QgsAttributeEditorContext &context ) override;
141 
145  void setVisibleButtons( const Buttons &buttons );
146 
150  Buttons visibleButtons() const;
151 
156  Q_DECL_DEPRECATED void duplicateFeature() SIP_DEPRECATED;
157 
162  void duplicateSelectedFeatures();
163 
167  void unlinkSelectedFeatures();
168 
172  void deleteSelectedFeatures();
173 
177  void zoomToSelectedFeatures();
178 
182  QVariantMap config() const override;
183 
187  void setConfig( const QVariantMap &config ) override;
188 
189  public slots:
190  void parentFormValueChanged( const QString &attribute, const QVariant &newValue ) override;
191 
192  protected:
193  virtual void updateUi() override;
194  void beforeSetRelationFeature( const QgsRelation &newRelation, const QgsFeature &newFeature ) override;
195  void afterSetRelationFeature() override;
196  void beforeSetRelations( const QgsRelation &newRelation, const QgsRelation &newNmRelation ) override;
197  void afterSetRelations() override;
198 
199  private slots:
200  void setViewMode( int mode ) {setViewMode( static_cast<QgsDualView::ViewMode>( mode ) );}
201  void updateButtons();
202 
203  void addFeatureGeometry();
204  void toggleEditing( bool state );
205  void showContextMenu( QgsActionMenu *menu, QgsFeatureId fid );
206  void mapToolDeactivated();
207  void onKeyPressed( QKeyEvent *e );
208  void onDigitizingCompleted( const QgsFeature &feature );
209 
210  private:
211  void initDualView( QgsVectorLayer *layer, const QgsFeatureRequest &request );
212  void setMapTool( QgsMapTool *mapTool );
213  void unsetMapTool();
214 
215  QgsDualView *mDualView = nullptr;
216  QPointer<QgsMessageBarItem> mMessageBarItem;
218 
219  QToolButton *mToggleEditingButton = nullptr;
220  QToolButton *mSaveEditsButton = nullptr;
221  QToolButton *mAddFeatureButton = nullptr;
222  QToolButton *mDuplicateFeatureButton = nullptr;
223  QToolButton *mDeleteFeatureButton = nullptr;
224  QToolButton *mLinkFeatureButton = nullptr;
225  QToolButton *mUnlinkFeatureButton = nullptr;
226  QToolButton *mZoomToFeatureButton = nullptr;
227  QToolButton *mFormViewButton = nullptr;
228  QToolButton *mTableViewButton = nullptr;
229  QToolButton *mAddFeatureGeometryButton = nullptr;
231  QButtonGroup *mViewModeButtonGroup = nullptr;
232  QgsVectorLayerSelectionManager *mFeatureSelectionMgr = nullptr;
233 
234  Buttons mButtonsVisibility = Button::AllButtons;
235  bool mShowFirstFeature = true;
236 };
237 
238 
245 class GUI_EXPORT QgsRelationEditorConfigWidget : public QgsAbstractRelationEditorConfigWidget, private Ui::QgsRelationEditorConfigWidgetBase
246 {
247  Q_OBJECT
248 
249  public:
250 
257  explicit QgsRelationEditorConfigWidget( const QgsRelation &relation, QWidget *parent SIP_TRANSFERTHIS );
258 
264  QVariantMap config();
265 
271  void setConfig( const QVariantMap &config );
272 
273 };
274 
275 
276 #ifndef SIP_RUN
277 
286 {
287  public:
289 
290  QString type() const override;
291 
292  QString name() const override;
293 
294  QgsAbstractRelationEditorWidget *create( const QVariantMap &config, QWidget *parent = nullptr ) const override;
295 
296  QgsAbstractRelationEditorConfigWidget *configWidget( const QgsRelation &relation, QWidget *parent ) const override;
297 
298 };
299 #endif
300 
301 
302 #endif // QGSRELATIONEDITORWIDGET_H
This class should be subclassed for every configurable relation widget type.
Factory class for creating relation widgets and their corresponding config widgets.
Base class to build new relation widgets.
void toggleEditing(bool state)
Toggles editing state of the widget.
virtual void setConfig(const QVariantMap &config)=0
Defines the widget configuration.
virtual void setEditorContext(const QgsAttributeEditorContext &context)
Sets the editor context.
virtual QVariantMap config() const =0
Returns the widget configuration.
void duplicateFeature(const QgsFeatureId &fid)
Duplicates a feature.
This class is a menu that is populated automatically with the actions defined for a given layer.
Definition: qgsactionmenu.h:38
This class contains context information for attribute editor widgets.
This widget is used to show the attributes of a set of features of a QgsVectorLayer.
Definition: qgsdualview.h:45
ViewMode
The view modes, in which this widget can present information.
Definition: qgsdualview.h:56
@ AttributeEditor
Show a list of the features, where one can be chosen and the according attribute dialog will be prese...
Definition: qgsdualview.h:68
This class wraps a request for features to a vector layer (or directly its vector data provider).
The feature class encapsulates a single feature including its unique ID, geometry and a list of field...
Definition: qgsfeature.h:56
Is an interface class to abstract feature selection handling.
This tool digitizes geometry of new point/line/polygon features on already existing vector layers Onc...
Abstract base class for all map tools.
Definition: qgsmaptool.h:71
Creates a new configuration widget for the relation editor widget.
Factory class for creating a relation editor widget and the respective config widget.
The default relation widget in QGIS.
Button
Possible buttons shown in the relation editor.
QgsDualView::ViewMode viewMode()
Gets the view mode for the dual view.
int selectedFeatureCount() override
Returns the number of features that are selected in this layer.
const QgsFeatureIds & selectedFeatureIds() const override
Returns reference to identifiers of selected features.
Methods in this class are used to handle basic operations on vector layers.
Represents a vector layer which manages a vector based data sets.
#define SIP_DEPRECATED
Definition: qgis_sip.h:106
#define SIP_TRANSFERTHIS
Definition: qgis_sip.h:53
QSet< QgsFeatureId > QgsFeatureIds
Definition: qgsfeatureid.h:37
qint64 QgsFeatureId
64 bit feature ids negative numbers are used for uncommitted/newly added features
Definition: qgsfeatureid.h:28