QGIS API Documentation 3.43.0-Master (69d1901085b)
qgsattributesformproperties.h
Go to the documentation of this file.
1/***************************************************************************
2 qgsattributesformproperties.h
3 ---------------------
4 begin : August 2017
5 copyright : (C) 2017 by David Signer
6 email : david 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 QGSATTRIBUTESFORMPROPERTIES_H
17#define QGSATTRIBUTESFORMPROPERTIES_H
18
19// We don't want to expose this in the public API
20#define SIP_NO_FILE
21
22#include "ui_qgsattributesformproperties.h"
23#include "qgis_gui.h"
24#include "qgsaction.h"
28#include "qgssettingstree.h"
29#include "qgssettingstreenode.h"
30#include "qgsmessagebar.h"
31
32#include <QMimeData>
33#include <QPushButton>
34#include <QWidget>
35#include <QTreeView>
36#include <QSpinBox>
37#include <QDropEvent>
38#include <QMessageBox>
39#include <QFileDialog>
40#include <QHBoxLayout>
41#include <QFormLayout>
42#include <QPlainTextEdit>
43#include <QAction>
44#include <QMenu>
45#include <QClipboard>
46
47class QgsAttributeFormContainerEdit;
48class QgsAttributeTypeDialog;
49class QgsAttributeWidgetEdit;
51
59class GUI_EXPORT QgsAttributesFormProperties : public QWidget, public QgsExpressionContextGenerator, private Ui_QgsAttributesFormProperties
60{
61 Q_OBJECT
62
63 public:
64 static inline QgsSettingsTreeNode *sTreeAttributesForm = QgsSettingsTree::sTreeApp->createChildNode( QStringLiteral( "attributes-form" ) );
66
67 explicit QgsAttributesFormProperties( QgsVectorLayer *layer, QWidget *parent = nullptr );
68
69 void init();
70
74 void apply();
75
80 void store();
81
83
87 void initAvailableWidgetsView();
88
92 void initFormLayoutView();
93
94 void initLayoutConfig();
95 void initInitPython();
96 void initSuppressCombo();
97
103 void initAvailableWidgetsActions( const QList< QgsAction > actions );
104
106
107 protected:
109
110 QgsVectorLayer *mLayer = nullptr;
111
112 QgsAttributesFormBaseView *mAvailableWidgetsView = nullptr;
113 QgsAttributesFormBaseView *mFormLayoutView = nullptr;
114
115 QgsAttributeWidgetEdit *mAttributeWidgetEdit = nullptr;
116 QgsAttributeTypeDialog *mAttributeTypeDialog = nullptr;
117 QgsAttributeFormContainerEdit *mAttributeContainerEdit = nullptr;
118 QLabel *mInfoTextWidget = nullptr;
119
120 private slots:
121 void addContainer();
122 void removeTabOrGroupButton();
123 void mEditorLayoutComboBox_currentIndexChanged( int index );
124 void pbnSelectEditForm_clicked();
125 void mTbInitCode_clicked();
126 void toggleShowAliases( bool checked );
127
131 void onInvertSelectionButtonClicked( bool checked );
132
133 void loadAttributeSpecificEditor( QgsAttributesFormBaseView *emitter, QgsAttributesFormBaseView *receiver, QModelIndex &deselectedFormLayoutIndex );
134 void onAttributeSelectionChanged( const QItemSelection &selected, const QItemSelection &deselected );
135 void onFormLayoutSelectionChanged( const QItemSelection &selected, const QItemSelection &deselected );
136
138 void onContextMenuRequested( QPoint );
139
140 void updatedFields();
141
142 private:
144 void clearAttributeTypeFrame();
145
146 void loadAttributeWidgetEdit();
147
151 void storeAttributeWidgetEdit();
152
156 void storeAttributeContainerEdit();
157
159 void storeAttributeWidgetEdit( const QModelIndex &index );
160 void storeAttributeContainerEdit( const QModelIndex &index );
161
162 void loadAttributeTypeDialog();
163 void loadAttributeTypeDialogFromConfiguration( const QgsAttributesFormData::FieldConfig &cfg );
164 void storeAttributeTypeDialog();
165
166 void loadAttributeContainerEdit();
167
168 void loadInfoWidget( const QString &infoText );
169
170 void copyWidgetConfiguration();
171 void pasteWidgetConfiguration();
172
173 QgsAttributesAvailableWidgetsModel *mAvailableWidgetsModel;
174 QgsAttributesFormLayoutModel *mFormLayoutModel;
175
176 QgsMessageBar *mMessageBar = nullptr;
177
179 QString mInitFunction;
180 QString mInitFilePath;
181 QString mInitCode;
182 int mBlockUpdates = 0;
183
185 QMenu *mAvailableWidgetsContextMenu = nullptr;
186 QAction *mActionCopyWidgetConfiguration = nullptr;
187 QAction *mActionPasteWidgetConfiguration = nullptr;
188
189 friend class TestQgsAttributesFormProperties;
190};
191
192
200class GUI_EXPORT QgsAttributesFormBaseView : public QTreeView, protected QgsExpressionContextGenerator
201{
202 Q_OBJECT
203
204 public:
210 explicit QgsAttributesFormBaseView( QgsVectorLayer *layer, QWidget *parent = nullptr );
211
212 // QgsExpressionContextGenerator interface
214
215 public slots:
221 void selectFirstMatchingItem( const QgsAttributesFormData::AttributesFormItemType &itemType, const QString &itemId );
222
223 protected:
224 QgsVectorLayer *mLayer = nullptr;
225};
226
227
236{
237 Q_OBJECT
238
239 public:
245 explicit QgsAttributesAvailableWidgetsView( QgsVectorLayer *layer, QWidget *parent = nullptr );
246
248 void setModel( QAbstractItemModel *model ) override;
249
251 QgsAttributesAvailableWidgetsModel *availableWidgetsModel() const;
252
253 private:
254 QgsAttributesAvailableWidgetsModel *mModel = nullptr;
255};
256
257
266{
267 Q_OBJECT
268
269 public:
275 explicit QgsAttributesFormLayoutView( QgsVectorLayer *layer, QWidget *parent = nullptr );
276
278 void setModel( QAbstractItemModel *model ) override;
279
281 QgsAttributesFormLayoutModel *formLayoutModel() const;
282
283 protected:
284 // Drag and drop support (to handle internal moves)
285 void dragEnterEvent( QDragEnterEvent *event ) override;
286 void dragMoveEvent( QDragMoveEvent *event ) override;
287 void dropEvent( QDropEvent *event ) override;
288
289 private slots:
290 void onItemDoubleClicked( const QModelIndex &index );
291 void handleExternalDroppedItem( QModelIndex &index );
292 void handleInternalDroppedItem( QModelIndex &index );
293
294 private:
295 QgsAttributesFormLayoutModel *mModel = nullptr;
296};
297
298#endif // QGSATTRIBUTESFORMPROPERTIES_H
AttributeFormPythonInitCodeSource
The Python init code source for attribute forms.
Definition qgis.h:5324
@ NoSource
Do not use Python code at all.
Manages available widgets when configuring attributes forms.
Graphical representation for the available widgets while configuring attributes forms.
Graphical representation for the attribute drag and drop editor.
AttributesFormItemType
Custom item types.
Manages form layouts when configuring attributes forms via drag and drop designer.
Graphical representation for the form layout while configuring attributes forms.
Creates panels to configure attributes forms.
static const QgsSettingsEntryBool * settingShowAliases
Abstract interface for generating an expression context.
virtual QgsExpressionContext createExpressionContext() const =0
This method needs to be reimplemented in all classes which implement this interface and return an exp...
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
A bar for displaying non-blocking messages to the user.
A boolean settings entry.
A tree node for the settings tree to help organizing and introspecting the tree.
QgsSettingsTreeNode * createChildNode(const QString &key)
Creates a normal tree node It will return the existing child node if it exists at the given key.
static QgsSettingsTreeNode * sTreeApp
Represents a vector layer which manages a vector based dataset.
Holds the configuration for a field.