QGIS API Documentation  3.18.1-Zürich (202f1bf7e5)
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 "qgscollapsiblegroupbox.h"
31 #include "qgsdualview.h"
32 #include "qgsrelation.h"
34 #include "qgis_gui.h"
35 
36 class QgsFeature;
37 class QgsVectorLayer;
39 class QgsMapTool;
41 
42 #ifdef SIP_RUN
43 % ModuleHeaderCode
44 // fix to allow compilation with sip that for some reason
45 // doesn't add this include to the file where the code from
46 // ConvertToSubClassCode goes.
48 % End
49 #endif
50 
51 
53 #ifndef SIP_RUN
54 
59 class QgsFilteredSelectionManager : public QgsVectorLayerSelectionManager
60 {
61  Q_OBJECT
62 
63  public:
64  QgsFilteredSelectionManager( QgsVectorLayer *layer, const QgsFeatureRequest &request, QObject *parent = nullptr );
65 
66  const QgsFeatureIds &selectedFeatureIds() const override;
67  int selectedFeatureCount() override;
68 
69  private slots:
70 
71  void onSelectionChanged( const QgsFeatureIds &selected, const QgsFeatureIds &deselected, bool clearAndSelect ) override;
72 
73  private:
74 
75  QgsFeatureRequest mRequest;
76  QgsFeatureIds mSelectedFeatureIds;
77 };
78 #endif
80 
81 
89 {
90 
91  Q_OBJECT
92  Q_PROPERTY( QgsDualView::ViewMode viewMode READ viewMode WRITE setViewMode )
93  Q_PROPERTY( Buttons visibleButtons READ visibleButtons WRITE setVisibleButtons )
94 
95  public:
96 
100  enum Button
101  {
102  Link = 1 << 1,
103  Unlink = 1 << 2,
104  SaveChildEdits = 1 << 3,
105  AddChildFeature = 1 << 4,
106  DuplicateChildFeature = 1 << 5,
107  DeleteChildFeature = 1 << 6,
108  ZoomToChildFeature = 1 << 7,
109  AllButtons = Link | Unlink | SaveChildEdits | AddChildFeature | DuplicateChildFeature | DeleteChildFeature | ZoomToChildFeature
110  };
111  Q_ENUM( Button )
112  Q_DECLARE_FLAGS( Buttons, Button )
113  Q_FLAG( Buttons )
114 
115 
120  QgsRelationEditorWidget( const QVariantMap &config, QWidget *parent SIP_TRANSFERTHIS = nullptr );
121 
123  void setViewMode( QgsDualView::ViewMode mode );
124 
126  QgsDualView::ViewMode viewMode() {return mViewMode;}
127 
132  QgsIFeatureSelectionManager *featureSelectionManager();
133 
139  void setEditorContext( const QgsAttributeEditorContext &context ) override;
140 
144  void setVisibleButtons( const Buttons &buttons );
145 
149  Buttons visibleButtons() const;
150 
155  Q_DECL_DEPRECATED void duplicateFeature() SIP_DEPRECATED;
156 
161  void duplicateSelectedFeatures();
162 
166  void unlinkSelectedFeatures();
167 
171  void deleteSelectedFeatures();
172 
176  void zoomToSelectedFeatures();
177 
181  QVariantMap config() const override;
182 
186  void setConfig( const QVariantMap &config ) override;
187 
191  void setTitle( const QString &title ) override;
192 
193  public slots:
194  void parentFormValueChanged( const QString &attribute, const QVariant &newValue ) override;
195 
196  protected:
197  virtual void updateUi() override;
198  void beforeSetRelationFeature( const QgsRelation &newRelation, const QgsFeature &newFeature ) override;
199  void afterSetRelationFeature() override;
200  void beforeSetRelations( const QgsRelation &newRelation, const QgsRelation &newNmRelation ) override;
201  void afterSetRelations() override;
202 
203  private slots:
204  void setViewMode( int mode ) {setViewMode( static_cast<QgsDualView::ViewMode>( mode ) );}
205  void updateButtons();
206 
207  void addFeatureGeometry();
208  void toggleEditing( bool state );
209  void onCollapsedStateChanged( bool collapsed );
210  void showContextMenu( QgsActionMenu *menu, QgsFeatureId fid );
211  void mapToolDeactivated();
212  void onKeyPressed( QKeyEvent *e );
213  void onDigitizingCompleted( const QgsFeature &feature );
214 
215  private:
216  void initDualView( QgsVectorLayer *layer, const QgsFeatureRequest &request );
217  void setMapTool( QgsMapTool *mapTool );
218  void unsetMapTool();
219 
220  QgsCollapsibleGroupBox *mRootCollapsibleGroupBox = nullptr;
221  QgsDualView *mDualView = nullptr;
222  QPointer<QgsMessageBarItem> mMessageBarItem;
224 
225  QToolButton *mToggleEditingButton = nullptr;
226  QToolButton *mSaveEditsButton = nullptr;
227  QToolButton *mAddFeatureButton = nullptr;
228  QToolButton *mDuplicateFeatureButton = nullptr;
229  QToolButton *mDeleteFeatureButton = nullptr;
230  QToolButton *mLinkFeatureButton = nullptr;
231  QToolButton *mUnlinkFeatureButton = nullptr;
232  QToolButton *mZoomToFeatureButton = nullptr;
233  QToolButton *mFormViewButton = nullptr;
234  QToolButton *mTableViewButton = nullptr;
235  QToolButton *mAddFeatureGeometryButton = nullptr;
236  QGridLayout *mRelationLayout = nullptr;
238  QButtonGroup *mViewModeButtonGroup = nullptr;
239  QgsVectorLayerSelectionManager *mFeatureSelectionMgr = nullptr;
240 
241  Buttons mButtonsVisibility = Button::AllButtons;
242  bool mVisible = true;
243 };
244 
245 
252 class GUI_EXPORT QgsRelationEditorConfigWidget : public QgsAbstractRelationEditorConfigWidget, private Ui::QgsRelationEditorConfigWidgetBase
253 {
254  Q_OBJECT
255 
256  public:
257 
264  explicit QgsRelationEditorConfigWidget( const QgsRelation &relation, QWidget *parent SIP_TRANSFERTHIS );
265 
271  QVariantMap config();
272 
278  void setConfig( const QVariantMap &config );
279 
280 };
281 
282 
283 #ifndef SIP_RUN
284 
293 {
294  public:
296 
297  QString type() const override;
298 
299  QString name() const override;
300 
301  QgsAbstractRelationEditorWidget *create( const QVariantMap &config, QWidget *parent = nullptr ) const override;
302 
303  QgsAbstractRelationEditorConfigWidget *configWidget( const QgsRelation &relation, QWidget *parent ) const override;
304 
305 };
306 #endif
307 
308 
309 #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.
A groupbox that collapses/expands when toggled and can save its collapsed and checked states.
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 id, geometry and a list of field/values...
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:66
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