QGIS API Documentation 3.99.0-Master (e69e8341d6a)
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 void updateFilteredItems( const QString &filterText );
143
144 private:
146 void clearAttributeTypeFrame();
147
148 void loadAttributeWidgetEdit();
149
153 void storeAttributeWidgetEdit();
154
158 void storeAttributeContainerEdit();
159
161 void storeAttributeWidgetEdit( const QModelIndex &index );
162 void storeAttributeContainerEdit( const QModelIndex &index );
163
164 void loadAttributeTypeDialog();
165 void loadAttributeTypeDialogFromConfiguration( const QgsAttributesFormData::FieldConfig &cfg );
166 void storeAttributeTypeDialog();
167
168 void loadAttributeContainerEdit();
169
170 void loadInfoWidget( const QString &infoText );
171
172 void copyWidgetConfiguration();
173 void pasteWidgetConfiguration();
174
175 QgsAttributesAvailableWidgetsModel *mAvailableWidgetsModel;
176 QgsAttributesFormLayoutModel *mFormLayoutModel;
177 QgsAttributesFormProxyModel *mAvailableWidgetsProxyModel;
178 QgsAttributesFormProxyModel *mFormLayoutProxyModel;
179
180 QgsMessageBar *mMessageBar = nullptr;
181
183 QString mInitFunction;
184 QString mInitFilePath;
185 QString mInitCode;
186 int mBlockUpdates = 0;
187
189 QMenu *mAvailableWidgetsContextMenu = nullptr;
190 QAction *mActionCopyWidgetConfiguration = nullptr;
191 QAction *mActionPasteWidgetConfiguration = nullptr;
192
193 friend class TestQgsAttributesFormProperties;
194};
195
196
204class GUI_EXPORT QgsAttributesFormBaseView : public QTreeView, protected QgsExpressionContextGenerator
205{
206 Q_OBJECT
207
208 public:
214 explicit QgsAttributesFormBaseView( QgsVectorLayer *layer, QWidget *parent = nullptr );
215
221 QModelIndex firstSelectedIndex() const;
222
223 // QgsExpressionContextGenerator interface
225
226 public slots:
232 void selectFirstMatchingItem( const QgsAttributesFormData::AttributesFormItemType &itemType, const QString &itemId );
233
239 void setFilterText( const QString &text );
240
241 protected:
242 QgsVectorLayer *mLayer = nullptr;
244};
245
246
255{
256 Q_OBJECT
257
258 public:
264 explicit QgsAttributesAvailableWidgetsView( QgsVectorLayer *layer, QWidget *parent = nullptr );
265
267 void setModel( QAbstractItemModel *model ) override;
268
270 QgsAttributesAvailableWidgetsModel *availableWidgetsModel() const;
271};
272
273
282{
283 Q_OBJECT
284
285 public:
291 explicit QgsAttributesFormLayoutView( QgsVectorLayer *layer, QWidget *parent = nullptr );
292
294 void setModel( QAbstractItemModel *model ) override;
295
296 protected:
297 // Drag and drop support (to handle internal moves)
298 void dragEnterEvent( QDragEnterEvent *event ) override;
299 void dragMoveEvent( QDragMoveEvent *event ) override;
300 void dropEvent( QDropEvent *event ) override;
301
302 private slots:
303 void onItemDoubleClicked( const QModelIndex &index );
304 void handleExternalDroppedItem( QModelIndex &index );
305 void handleInternalDroppedItem( QModelIndex &index );
306};
307
308#endif // QGSATTRIBUTESFORMPROPERTIES_H
AttributeFormPythonInitCodeSource
The Python init code source for attribute forms.
Definition qgis.h:5393
@ 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
Proxy model to filter items in the tree views of the drag and drop designer.
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.