QGIS API Documentation 3.99.0-Master (2fe06baccd8)
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 "ui_qgsrelationeditorconfigwidgetbase.h"
20
21#include "qgis_gui.h"
24#include "qgsdualview.h"
25#include "qgsrelation.h"
27#include "qobjectuniqueptr.h"
28
29#include <QButtonGroup>
30#include <QGridLayout>
31#include <QToolButton>
32#include <QWidget>
33
34class QTreeWidget;
35class QTreeWidgetItem;
36class QgsFeature;
37class QgsVectorLayer;
39class 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
59class 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 QgsFeatureRequest mRequest;
75 QgsFeatureIds mSelectedFeatureIds;
76};
77#endif
79
80
88{
89 Q_OBJECT
92
93 public:
110 Q_ENUM( Button )
111 Q_DECLARE_FLAGS( Buttons, Button )
112 Q_FLAG( Buttons )
113
119 QgsRelationEditorWidget( const QVariantMap &config, QWidget *parent SIP_TRANSFERTHIS = nullptr );
120
122 void setViewMode( QgsDualView::ViewMode mode );
123
125 QgsDualView::ViewMode viewMode() { return mViewMode; }
126
131 QgsIFeatureSelectionManager *featureSelectionManager();
132
138 void setEditorContext( const QgsAttributeEditorContext &context ) override;
139
143 void setVisibleButtons( const Buttons &buttons );
144
148 Buttons visibleButtons() const;
149
154 Q_DECL_DEPRECATED void duplicateFeature() SIP_DEPRECATED;
155
160 void duplicateSelectedFeatures();
161
165 void unlinkSelectedFeatures();
166
170 void deleteSelectedFeatures();
171
175 void zoomToSelectedFeatures();
176
180 QVariantMap config() const override;
181
185 void setConfig( const QVariantMap &config ) override;
186
187 public slots:
188 void parentFormValueChanged( const QString &attribute, const QVariant &newValue ) override;
189
190 protected:
191 void updateUi() override;
192 void beforeSetRelationFeature( const QgsRelation &newRelation, const QgsFeature &newFeature ) override;
193 void afterSetRelationFeature() override;
194 void beforeSetRelations( const QgsRelation &newRelation, const QgsRelation &newNmRelation ) override;
195 void afterSetRelations() override;
196
197 private slots:
198 void setViewMode( int mode ) { setViewMode( static_cast<QgsDualView::ViewMode>( mode ) ); }
199 void updateButtons();
200
201 void addFeature();
202 void addFeatureGeometry();
203
204 // TODO -- someone familiar with this widget needs to fix this:
205 void toggleEditing( bool state ); // cppcheck-suppress duplInheritedMember
206
207 void showContextMenu( QgsActionMenu *menu, QgsFeatureId fid );
208 void mapToolDeactivated();
209 void onDigitizingCompleted( const QgsFeature &feature );
210 void onDigitizingCanceled();
211 void multiEditItemSelectionChanged();
212 void linkFeature();
213
214 private:
215 void digitizingFinished();
216
217 enum class MultiEditFeatureType : int
218 {
219 Parent,
220 Child
221 };
222
223 enum class MultiEditTreeWidgetRole : int
224 {
225 FeatureType = Qt::UserRole + 1,
226 FeatureId = Qt::UserRole + 2
227 };
228
229 void initDualView( QgsVectorLayer *layer, const QgsFeatureRequest &request );
230 void setMapTool( QgsMapTool *mapTool );
231 void unsetMapTool();
232 QgsFeatureIds selectedChildFeatureIds() const;
233 void updateUiSingleEdit();
234 void updateUiMultiEdit();
235 QTreeWidgetItem *createMultiEditTreeWidgetItem( const QgsFeature &feature, QgsVectorLayer *layer, MultiEditFeatureType type );
236
237 QgsDualView *mDualView = nullptr;
238 QPointer<QgsMessageBarItem> mMessageBarItem;
240
241 QToolButton *mToggleEditingButton = nullptr;
242 QToolButton *mSaveEditsButton = nullptr;
243 QToolButton *mAddFeatureButton = nullptr;
244 QToolButton *mDuplicateFeatureButton = nullptr;
245 QToolButton *mDeleteFeatureButton = nullptr;
246 QToolButton *mLinkFeatureButton = nullptr;
247 QToolButton *mUnlinkFeatureButton = nullptr;
248 QToolButton *mZoomToFeatureButton = nullptr;
249 QToolButton *mFormViewButton = nullptr;
250 QToolButton *mTableViewButton = nullptr;
251 QToolButton *mAddFeatureGeometryButton = nullptr;
252 QLabel *mMultiEditInfoLabel = nullptr;
253 QStackedWidget *mStackedWidget = nullptr;
254 QWidget *mMultiEditStackedWidgetPage = nullptr;
255 QTreeWidget *mMultiEditTreeWidget = nullptr;
256 QObjectUniquePtr<QgsMapToolDigitizeFeature> mMapToolDigitize;
257 QButtonGroup *mViewModeButtonGroup = nullptr;
258 QgsVectorLayerSelectionManager *mFeatureSelectionMgr = nullptr;
259
260 Buttons mButtonsVisibility = Button::AllButtons;
261 bool mShowFirstFeature = true;
262 bool mAllowAddChildFeatureWithNoGeometry = true;
263 QString mFilterExpression;
264
265 QList<QTreeWidgetItem *> mMultiEditPreviousSelectedItems;
266 QgsFeatureIds mMultiEdit1NJustAddedIds;
267
269};
270
271
278class GUI_EXPORT QgsRelationEditorConfigWidget : public QgsAbstractRelationEditorConfigWidget, private Ui::QgsRelationEditorConfigWidgetBase
279{
280 Q_OBJECT
281
282 public:
289 explicit QgsRelationEditorConfigWidget( const QgsRelation &relation, QWidget *parent SIP_TRANSFERTHIS );
290
296 QVariantMap config() override;
297
303 void setConfig( const QVariantMap &config ) override;
304
309};
310
311
312#ifndef SIP_RUN
313
322{
323 public:
325
326 QString type() const override;
327
328 QString name() const override;
329
330 QgsAbstractRelationEditorWidget *create( const QVariantMap &config, QWidget *parent = nullptr ) const override;
331
332 QgsAbstractRelationEditorConfigWidget *configWidget( const QgsRelation &relation, QWidget *parent ) const override;
333};
334#endif
335
336
337#endif // QGSRELATIONEDITORWIDGET_H
Abstract base class for configurable relation widget types.
QgsRelation relation() const
Returns the relation for which this configuration widget applies.
QgsAbstractRelationEditorConfigWidget(const QgsRelation &relation, QWidget *parent)
Create a new configuration widget.
QgsAbstractRelationEditorWidgetFactory()
Creates a new relation widget factory with given name.
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.
QgsAbstractRelationEditorWidget(const QVariantMap &config, QWidget *parent=nullptr)
Constructor.
virtual QVariantMap config() const =0
Returns the widget configuration.
void duplicateFeature(const QgsFeatureId &fid)
Duplicates a feature.
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:47
ViewMode
The view modes, in which this widget can present information.
Definition qgsdualview.h:57
@ AttributeEditor
Show a list of the features, where one can be chosen and the according attribute dialog will be prese...
Definition qgsdualview.h:69
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.
Abstract base class for all map tools.
Definition qgsmaptool.h:72
QVariantMap config() override
Create a configuration from the current GUI state.
QgsRelationEditorConfigWidget(const QgsRelation &relation, QWidget *parent)
Create a new configuration widget.
void mEditExpression_clicked()
Opens an expression dialog and sets its value as filter expression for the linking dialog.
QString type() const override
Returns the machine readable identifier name of this widget type.
QString name() const override
Returns the human readable identifier name of this widget type.
QgsAbstractRelationEditorConfigWidget * configWidget(const QgsRelation &relation, QWidget *parent) const override
Override this in your implementation.
QgsAbstractRelationEditorWidget * create(const QVariantMap &config, QWidget *parent=nullptr) const override
Override this in your implementation.
Button
Possible buttons shown in the relation editor.
@ ZoomToChildFeature
Zoom to child feature.
@ DeleteChildFeature
Delete child feature button.
@ DuplicateChildFeature
Duplicate child feature.
@ SaveChildEdits
Save child edits button.
@ AddChildFeature
Add child feature (as in some projects we only want to allow linking/unlinking existing features).
QgsDualView::ViewMode viewMode
void setViewMode(QgsDualView::ViewMode mode)
Define the view mode for the dual view.
void setVisibleButtons(const Buttons &buttons)
Defines the buttons which are shown.
QgsRelationEditorWidget(const QVariantMap &config, QWidget *parent=nullptr)
Constructor.
QVariantMap config() const override
Returns the current configuration.
Represents a relationship between two vector layers.
Definition qgsrelation.h:42
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.
Used to handle basic editing operations on vector layers.
Represents a vector layer which manages a vector based dataset.
#define SIP_DEPRECATED
Definition qgis_sip.h:114
#define SIP_TRANSFERTHIS
Definition qgis_sip.h:53
#define SIP_ENUM_BASETYPE(type)
Definition qgis_sip.h:275
QSet< QgsFeatureId > QgsFeatureIds
qint64 QgsFeatureId
64 bit feature ids negative numbers are used for uncommitted/newly added features