QGIS API Documentation 3.99.0-Master (26c88405ac0)
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:
94
111 Q_ENUM( Button )
112 Q_DECLARE_FLAGS( Buttons, Button )
113 Q_FLAG( Buttons )
114
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
188 public slots:
189 void parentFormValueChanged( const QString &attribute, const QVariant &newValue ) override;
190
191 protected:
192 void updateUi() override;
193 void beforeSetRelationFeature( const QgsRelation &newRelation, const QgsFeature &newFeature ) override;
194 void afterSetRelationFeature() override;
195 void beforeSetRelations( const QgsRelation &newRelation, const QgsRelation &newNmRelation ) override;
196 void afterSetRelations() override;
197
198 private slots:
199 void setViewMode( int mode ) { setViewMode( static_cast<QgsDualView::ViewMode>( mode ) ); }
200 void updateButtons();
201
202 void addFeature();
203 void addFeatureGeometry();
204
205 // TODO -- someone familiar with this widget needs to fix this:
206 void toggleEditing( bool state ); // cppcheck-suppress duplInheritedMember
207
208 void showContextMenu( QgsActionMenu *menu, QgsFeatureId fid );
209 void mapToolDeactivated();
210 void onDigitizingCompleted( const QgsFeature &feature );
211 void onDigitizingCanceled();
212 void multiEditItemSelectionChanged();
213 void linkFeature();
214
215 private:
216 void digitizingFinished();
217
218 enum class MultiEditFeatureType : int
219 {
220 Parent,
221 Child
222 };
223
224 enum class MultiEditTreeWidgetRole : int
225 {
226 FeatureType = Qt::UserRole + 1,
227 FeatureId = Qt::UserRole + 2
228 };
229
230 void initDualView( QgsVectorLayer *layer, const QgsFeatureRequest &request );
231 void setMapTool( QgsMapTool *mapTool );
232 void unsetMapTool();
233 QgsFeatureIds selectedChildFeatureIds() const;
234 void updateUiSingleEdit();
235 void updateUiMultiEdit();
236 QTreeWidgetItem *createMultiEditTreeWidgetItem( const QgsFeature &feature, QgsVectorLayer *layer, MultiEditFeatureType type );
237
238 QgsDualView *mDualView = nullptr;
239 QPointer<QgsMessageBarItem> mMessageBarItem;
241
242 QToolButton *mToggleEditingButton = nullptr;
243 QToolButton *mSaveEditsButton = nullptr;
244 QToolButton *mAddFeatureButton = nullptr;
245 QToolButton *mDuplicateFeatureButton = nullptr;
246 QToolButton *mDeleteFeatureButton = nullptr;
247 QToolButton *mLinkFeatureButton = nullptr;
248 QToolButton *mUnlinkFeatureButton = nullptr;
249 QToolButton *mZoomToFeatureButton = nullptr;
250 QToolButton *mFormViewButton = nullptr;
251 QToolButton *mTableViewButton = nullptr;
252 QToolButton *mAddFeatureGeometryButton = nullptr;
253 QLabel *mMultiEditInfoLabel = nullptr;
254 QStackedWidget *mStackedWidget = nullptr;
255 QWidget *mMultiEditStackedWidgetPage = nullptr;
256 QTreeWidget *mMultiEditTreeWidget = nullptr;
257 QObjectUniquePtr<QgsMapToolDigitizeFeature> mMapToolDigitize;
258 QButtonGroup *mViewModeButtonGroup = nullptr;
259 QgsVectorLayerSelectionManager *mFeatureSelectionMgr = nullptr;
260
261 Buttons mButtonsVisibility = Button::AllButtons;
262 bool mShowFirstFeature = true;
263 bool mAllowAddChildFeatureWithNoGeometry = true;
264 QString mFilterExpression;
265
266 QList<QTreeWidgetItem *> mMultiEditPreviousSelectedItems;
267 QgsFeatureIds mMultiEdit1NJustAddedIds;
268
270};
271
272
279class GUI_EXPORT QgsRelationEditorConfigWidget : public QgsAbstractRelationEditorConfigWidget, private Ui::QgsRelationEditorConfigWidgetBase
280{
281 Q_OBJECT
282
283 public:
284
291 explicit QgsRelationEditorConfigWidget( const QgsRelation &relation, QWidget *parent SIP_TRANSFERTHIS );
292
298 QVariantMap config() override;
299
305 void setConfig( const QVariantMap &config ) override;
306
311};
312
313
314#ifndef SIP_RUN
315
324{
325 public:
327
328 QString type() const override;
329
330 QString name() const override;
331
332 QgsAbstractRelationEditorWidget *create( const QVariantMap &config, QWidget *parent = nullptr ) const override;
333
334 QgsAbstractRelationEditorConfigWidget *configWidget( const QgsRelation &relation, QWidget *parent ) const override;
335};
336#endif
337
338
339#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:58
@ AttributeEditor
Show a list of the features, where one can be chosen and the according attribute dialog will be prese...
Definition qgsdualview.h:70
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