QGIS API Documentation 3.29.0-Master (006c3c0232)
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 <QMimeData>
23#include <QPushButton>
24#include <QTableWidget>
25#include <QTreeWidget>
26#include <QWidget>
27#include <QSpinBox>
28#include <QTreeWidgetItem>
29#include <QDropEvent>
30#include <QTableWidgetItem>
31#include <QMessageBox>
32#include <QFileDialog>
33#include <QHBoxLayout>
34#include <QFormLayout>
35#include <QPlainTextEdit>
36
37#include "ui_qgsattributesformproperties.h"
38#include "qgis_gui.h"
39#include "qgsaddattrdialog.h"
40#include "qgslogger.h"
42#include "qgsfieldcalculator.h"
45#include "qgsgui.h"
48#include "qgsrelationmanager.h"
50
51
53class QgsAttributeFormContainerEdit;
54class QgsAttributeTypeDialog;
55class QgsAttributeWidgetEdit;
56
61class GUI_EXPORT QgsAttributesFormProperties : public QWidget, public QgsExpressionContextGenerator, private Ui_QgsAttributesFormProperties
62{
63 Q_OBJECT
64
65 public:
66
68 {
69 DnDTreeRole = Qt::UserRole,
72 };
73
75 {
76 operator QVariant();
77
80 QVariant nmRelationId;
81 bool forceSuppressFormPopup = false;
82 QString label;
83 };
84
86 {
87 QString qmlCode;
88 };
89
91 {
92 QString htmlCode;
93 };
94
99 class DnDTreeItemData : public QTreeWidgetItem
100 {
101 public:
102 enum Type
103 {
110 Action
111 };
112
113 //do we need that
114 DnDTreeItemData() = default;
115
116 DnDTreeItemData( Type type, const QString &name, const QString &displayName, const QColor &backgroundColor = QColor() )
117 : mType( type )
118 , mName( name )
119 , mDisplayName( displayName )
120 , mBackgroundColor( backgroundColor )
121 {}
122
123 QString name() const { return mName; }
124 void setName( const QString &name ) { mName = name; }
125
126 QString displayName() const { return mDisplayName; }
127 void setDisplayName( const QString &displayName ) { mDisplayName = displayName; }
128
129 Type type() const { return mType; }
130 void setType( Type type ) { mType = type; }
131
132 operator QVariant() { return QVariant::fromValue<DnDTreeItemData>( *this ); }
133
134 int columnCount() const { return mColumnCount; }
135 void setColumnCount( int count ) { mColumnCount = count; }
136
137 bool showAsGroupBox() const;
138 void setShowAsGroupBox( bool showAsGroupBox );
139
148 bool collapsed() const { return mCollapsed; };
149
157 void setCollapsed( bool collapsed ) { mCollapsed = collapsed; };
158
164 const QgsAttributeEditorElement::LabelStyle labelStyle() const;
165
171 void setLabelStyle( const QgsAttributeEditorElement::LabelStyle &labelStyle );
172
173 bool showLabel() const;
174 void setShowLabel( bool showLabel );
175
176 QgsOptionalExpression visibilityExpression() const;
177
184 void setVisibilityExpression( const QgsOptionalExpression &visibilityExpression );
185
194 QgsOptionalExpression collapsedExpression() const;
195
204 void setCollapsedExpression( const QgsOptionalExpression &collapsedExpression );
205
206 RelationEditorConfiguration relationEditorConfiguration() const;
207 void setRelationEditorConfiguration( RelationEditorConfiguration relationEditorConfiguration );
208
209 QmlElementEditorConfiguration qmlElementEditorConfiguration() const;
210 void setQmlElementEditorConfiguration( QmlElementEditorConfiguration qmlElementEditorConfiguration );
211
212 HtmlElementEditorConfiguration htmlElementEditorConfiguration() const;
213 void setHtmlElementEditorConfiguration( HtmlElementEditorConfiguration htmlElementEditorConfiguration );
214
215 QColor backgroundColor() const;
216 void setBackgroundColor( const QColor &backgroundColor );
217
218 private:
219 Type mType = Field;
220 QString mName;
221 QString mDisplayName;
222 int mColumnCount = 1;
223 bool mShowAsGroupBox = false;
224 bool mShowLabel = true;
225 QgsOptionalExpression mVisibilityExpression;
226 RelationEditorConfiguration mRelationEditorConfiguration;
227 QmlElementEditorConfiguration mQmlElementEditorConfiguration;
228 HtmlElementEditorConfiguration mHtmlElementEditorConfiguration;
229 QColor mBackgroundColor;
230 bool mCollapsed = false;
231 QgsOptionalExpression mCollapsedExpression;
233 };
234
235
240 {
241 FieldConfig() = default;
242 FieldConfig( QgsVectorLayer *layer, int idx );
243
244 bool mEditable = true;
245 bool mEditableEnabled = true;
246 bool mLabelOnTop = false;
247 bool mReuseLastValues = false;
249 QPushButton *mButton = nullptr;
251 QMap<QString, QVariant> mEditorWidgetConfig;
252 QString mAlias;
254 QString mComment;
255
256 operator QVariant();
257 };
258
259 public:
260 explicit QgsAttributesFormProperties( QgsVectorLayer *layer, QWidget *parent = nullptr );
261
262 QgsAttributeEditorElement *createAttributeEditorWidget( QTreeWidgetItem *item, QgsAttributeEditorElement *parent, bool forceGroup = true );
263
264 void init();
265 void apply();
266
267
269
270 void initAvailableWidgetsTree();
271 void initFormLayoutTree();
272 void initLayoutConfig();
273 void initInitPython();
274 void initSuppressCombo();
275
277
278 protected:
280
281 //QList<QgsRelation> mRelations;
282 QgsVectorLayer *mLayer = nullptr;
283
284 QgsAttributesDnDTree *mAvailableWidgetsTree = nullptr;
285 QgsAttributesDnDTree *mFormLayoutTree = nullptr;
286
287 QgsAttributeWidgetEdit *mAttributeWidgetEdit = nullptr;
288 QgsAttributeTypeDialog *mAttributeTypeDialog = nullptr;
289 QgsAttributeFormContainerEdit *mAttributeContainerEdit = nullptr;
290 QLabel *mInfoTextWidget = nullptr;
291
292 private slots:
293
294 void onInvertSelectionButtonClicked( bool checked );
295 void loadAttributeSpecificEditor( QgsAttributesDnDTree *emitter, QgsAttributesDnDTree *receiver );
296 void onAttributeSelectionChanged();
297 void onFormLayoutSelectionChanged();
298
299 private:
301 void clearAttributeTypeFrame();
302
303 void loadAttributeWidgetEdit();
304 void storeAttributeWidgetEdit();
305
306 void loadAttributeTypeDialog();
307 void storeAttributeTypeDialog( );
308
309 void storeAttributeContainerEdit();
310 void loadAttributeContainerEdit();
311
312 void loadInfoWidget( const QString &infoText );
313
314 QTreeWidgetItem *loadAttributeEditorTreeItem( QgsAttributeEditorElement *widgetDef, QTreeWidgetItem *parent, QgsAttributesDnDTree *tree );
315
317 QString mInitFunction;
318 QString mInitFilePath;
319 QString mInitCode;
320
321 private slots:
322 void addTabOrGroupButton();
323 void removeTabOrGroupButton();
324 void mEditorLayoutComboBox_currentIndexChanged( int index );
325 void pbnSelectEditForm_clicked();
326 void mTbInitCode_clicked();
327};
328
329
330QDataStream &operator<< ( QDataStream &stream, const QgsAttributesFormProperties::DnDTreeItemData &data );
331QDataStream &operator>> ( QDataStream &stream, QgsAttributesFormProperties::DnDTreeItemData &data );
332
333
345class GUI_EXPORT QgsAttributesDnDTree : public QTreeWidget
346{
347 Q_OBJECT
348
349 public:
350 explicit QgsAttributesDnDTree( QgsVectorLayer *layer, QWidget *parent = nullptr );
351
356 QTreeWidgetItem *addItem( QTreeWidgetItem *parent, QgsAttributesFormProperties::DnDTreeItemData data, int index = -1, const QIcon &icon = QIcon() );
357 QTreeWidgetItem *addContainer( QTreeWidgetItem *parent, const QString &title, int columnCount );
358
359 enum Type
360 {
362 Drop
363 };
364
365
366 Type type() const;
367 void setType( QgsAttributesDnDTree::Type value );
368
369 public slots:
370 void selectFirstMatchingItem( const QgsAttributesFormProperties::DnDTreeItemData &data );
371
372 protected:
373 void dragMoveEvent( QDragMoveEvent *event ) override;
374 void dropEvent( QDropEvent *event ) override;
375 bool dropMimeData( QTreeWidgetItem *parent, int index, const QMimeData *data, Qt::DropAction action ) override;
376 /* Qt::DropActions supportedDropActions() const;*/
377
378 // QTreeWidget interface
379 protected:
380 QStringList mimeTypes() const override;
381
382#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
383 QMimeData *mimeData( const QList<QTreeWidgetItem *> items ) const override;
384#else
385 QMimeData *mimeData( const QList<QTreeWidgetItem *> &items ) const override;
386#endif
387
388 private slots:
389 void onItemDoubleClicked( QTreeWidgetItem *item, int column );
390
391 private:
392 QgsVectorLayer *mLayer = nullptr;
393 Type mType = QgsAttributesDnDTree::Type::Drag;
394};
395
396
400
401#endif // QGSATTRIBUTESFORMPROPERTIES_H
This is an abstract base class for any elements of a drag and drop form.
This class overrides mime type handling to be able to work with the drag and drop attribute editor.
DnDTreeItemData(Type type, const QString &name, const QString &displayName, const QColor &backgroundColor=QColor())
@ WidgetType
In the widget tree, the type of widget.
void setCollapsed(bool collapsed)
For group box containers sets if this group box is collapsed.
bool collapsed() const
For group box containers returns if this group box is collapsed.
PythonInitCodeSource
The Python init code source options.
@ CodeSourceNone
Do not use Python code at all.
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...
Stores information about constraints which may be present on a field.
An expression with an additional enabled flag.
A grouped map of multiple QgsProperty objects, each referenced by a integer key value.
Represents a vector layer which manages a vector based data sets.
QDataStream & operator>>(QDataStream &stream, QgsAttributesFormProperties::DnDTreeItemData &data)
QDataStream & operator<<(QDataStream &stream, const QgsAttributesFormProperties::DnDTreeItemData &data)
Q_DECLARE_METATYPE(QgsDatabaseQueryLogEntry)
The TabStyle struct defines color and font overrides for form fields, tabs and groups labels.