QGIS API Documentation 3.41.0-Master (45a0abf3bec)
Loading...
Searching...
No Matches
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
35class QTreeWidget;
36class QTreeWidgetItem;
37class QgsFeature;
38class QgsVectorLayer;
40class QgsMapTool;
42
43#ifdef SIP_RUN
44% ModuleHeaderCode
45// fix to allow compilation with sip that for some reason
46// doesn't add this include to the file where the code from
47// ConvertToSubClassCode goes.
49% End
50#endif
51
52
54#ifndef SIP_RUN
55
60class QgsFilteredSelectionManager : public QgsVectorLayerSelectionManager
61{
62 Q_OBJECT
63
64 public:
65 QgsFilteredSelectionManager( QgsVectorLayer *layer, const QgsFeatureRequest &request, QObject *parent = nullptr );
66
67 const QgsFeatureIds &selectedFeatureIds() const override;
68 int selectedFeatureCount() override;
69
70 private slots:
71
72 void onSelectionChanged( const QgsFeatureIds &selected, const QgsFeatureIds &deselected, bool clearAndSelect ) override;
73
74 private:
75
76 QgsFeatureRequest mRequest;
77 QgsFeatureIds mSelectedFeatureIds;
78};
79#endif
81
82
90{
91
92 Q_OBJECT
93 Q_PROPERTY( QgsDualView::ViewMode viewMode READ viewMode WRITE setViewMode )
94 Q_PROPERTY( Buttons visibleButtons READ visibleButtons WRITE setVisibleButtons )
95
96 public:
97
102 enum Button SIP_ENUM_BASETYPE( IntFlag )
103 {
104 NoButton = 0,
105 Link = 1 << 1,
106 Unlink = 1 << 2,
107 SaveChildEdits = 1 << 3,
108 AddChildFeature = 1 << 4,
109 DuplicateChildFeature = 1 << 5,
110 DeleteChildFeature = 1 << 6,
111 ZoomToChildFeature = 1 << 7,
112 AllButtons = Link | Unlink | SaveChildEdits | AddChildFeature | DuplicateChildFeature | DeleteChildFeature | ZoomToChildFeature
113 };
114 Q_ENUM( Button )
115 Q_DECLARE_FLAGS( Buttons, Button )
116 Q_FLAG( Buttons )
117
123 QgsRelationEditorWidget( const QVariantMap &config, QWidget *parent SIP_TRANSFERTHIS = nullptr );
124
126 void setViewMode( QgsDualView::ViewMode mode );
127
129 QgsDualView::ViewMode viewMode() {return mViewMode;}
130
135 QgsIFeatureSelectionManager *featureSelectionManager();
136
142 void setEditorContext( const QgsAttributeEditorContext &context ) override;
143
147 void setVisibleButtons( const Buttons &buttons );
148
152 Buttons visibleButtons() const;
153
158 Q_DECL_DEPRECATED void duplicateFeature() SIP_DEPRECATED;
159
164 void duplicateSelectedFeatures();
165
169 void unlinkSelectedFeatures();
170
174 void deleteSelectedFeatures();
175
179 void zoomToSelectedFeatures();
180
184 QVariantMap config() const override;
185
189 void setConfig( const QVariantMap &config ) override;
190
191 public slots:
192 void parentFormValueChanged( const QString &attribute, const QVariant &newValue ) override;
193
194 protected:
195 virtual void updateUi() override;
196 void beforeSetRelationFeature( const QgsRelation &newRelation, const QgsFeature &newFeature ) override;
197 void afterSetRelationFeature() override;
198 void beforeSetRelations( const QgsRelation &newRelation, const QgsRelation &newNmRelation ) override;
199 void afterSetRelations() override;
200
201 private slots:
202 void setViewMode( int mode ) {setViewMode( static_cast<QgsDualView::ViewMode>( mode ) );}
203 void updateButtons();
204
205 void addFeature();
206 void addFeatureGeometry();
207
208 // TODO -- someone familiar with this widget needs to fix this:
209 void toggleEditing( bool state ); // cppcheck-suppress duplInheritedMember
210
211 void showContextMenu( QgsActionMenu *menu, QgsFeatureId fid );
212 void mapToolDeactivated();
213 void onDigitizingCompleted( const QgsFeature &feature );
214 void onDigitizingCanceled( );
215 void multiEditItemSelectionChanged();
216 void linkFeature();
217
218 private:
219
220 void digitizingFinished( );
221
222 enum class MultiEditFeatureType : int
223 {
224 Parent,
225 Child
226 };
227
228 enum class MultiEditTreeWidgetRole : int
229 {
230 FeatureType = Qt::UserRole + 1,
231 FeatureId = Qt::UserRole + 2
232 };
233
234 void initDualView( QgsVectorLayer *layer, const QgsFeatureRequest &request );
235 void setMapTool( QgsMapTool *mapTool );
236 void unsetMapTool();
237 QgsFeatureIds selectedChildFeatureIds() const;
238 void updateUiSingleEdit();
239 void updateUiMultiEdit();
240 QTreeWidgetItem *createMultiEditTreeWidgetItem( const QgsFeature &feature, QgsVectorLayer *layer, MultiEditFeatureType type );
241
242 QgsDualView *mDualView = nullptr;
243 QPointer<QgsMessageBarItem> mMessageBarItem;
245
246 QToolButton *mToggleEditingButton = nullptr;
247 QToolButton *mSaveEditsButton = nullptr;
248 QToolButton *mAddFeatureButton = nullptr;
249 QToolButton *mDuplicateFeatureButton = nullptr;
250 QToolButton *mDeleteFeatureButton = nullptr;
251 QToolButton *mLinkFeatureButton = nullptr;
252 QToolButton *mUnlinkFeatureButton = nullptr;
253 QToolButton *mZoomToFeatureButton = nullptr;
254 QToolButton *mFormViewButton = nullptr;
255 QToolButton *mTableViewButton = nullptr;
256 QToolButton *mAddFeatureGeometryButton = nullptr;
257 QLabel *mMultiEditInfoLabel = nullptr;
258 QStackedWidget *mStackedWidget = nullptr;
259 QWidget *mMultiEditStackedWidgetPage = nullptr;
260 QTreeWidget *mMultiEditTreeWidget = nullptr;
262 QButtonGroup *mViewModeButtonGroup = nullptr;
263 QgsVectorLayerSelectionManager *mFeatureSelectionMgr = nullptr;
264
265 Buttons mButtonsVisibility = Button::AllButtons;
266 bool mShowFirstFeature = true;
267 bool mAllowAddChildFeatureWithNoGeometry = true;
268 QString mFilterExpression;
269
270 QList<QTreeWidgetItem *> mMultiEditPreviousSelectedItems;
271 QgsFeatureIds mMultiEdit1NJustAddedIds;
272
273 friend class TestQgsRelationEditorWidget;
274};
275
276
283class GUI_EXPORT QgsRelationEditorConfigWidget : public QgsAbstractRelationEditorConfigWidget, private Ui::QgsRelationEditorConfigWidgetBase
284{
285 Q_OBJECT
286
287 public:
288
295 explicit QgsRelationEditorConfigWidget( const QgsRelation &relation, QWidget *parent SIP_TRANSFERTHIS );
296
302 QVariantMap config() override;
303
309 void setConfig( const QVariantMap &config ) override;
310
314 void mEditExpression_clicked();
315};
316
317
318#ifndef SIP_RUN
319
328{
329 public:
331
332 QString type() const override;
333
334 QString name() const override;
335
336 QgsAbstractRelationEditorWidget *create( const QVariantMap &config, QWidget *parent = nullptr ) const override;
337
338 QgsAbstractRelationEditorConfigWidget *configWidget( const QgsRelation &relation, QWidget *parent ) const override;
339
340};
341#endif
342
343
344#endif // QGSRELATIONEDITORWIDGET_H
Keeps a pointer to a QObject and deletes it whenever this object is deleted.
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.
QgsFeatureIds addFeature(const QgsGeometry &geometry=QgsGeometry())
Adds new features with given geometry Returns the Id of added features.
virtual void setConfig(const QVariantMap &config)=0
Defines the widget configuration.
virtual void setEditorContext(const QgsAttributeEditorContext &context)
Sets the editor context.
void linkFeature(const QString &filterExpression=QString())
Links a new feature to the relation.
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.
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:58
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.
Represents a relationship between two vector layers.
Definition qgsrelation.h:44
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
#define SIP_ENUM_BASETYPE(type)
Definition qgis_sip.h:278
QSet< QgsFeatureId > QgsFeatureIds
qint64 QgsFeatureId
64 bit feature ids negative numbers are used for uncommitted/newly added features