QGIS API Documentation 3.31.0-Master (d2b117a3c8)
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
96 {
97 QString text;
98 };
99
101 {
102 bool drawLine = false;
103 };
104
109 class DnDTreeItemData : public QTreeWidgetItem
110 {
111 public:
112 enum Type
113 {
123 };
124
125 //do we need that
126 DnDTreeItemData() = default;
127
128 DnDTreeItemData( Type type, const QString &name, const QString &displayName, const QColor &backgroundColor = QColor() )
129 : mType( type )
130 , mName( name )
131 , mDisplayName( displayName )
132 , mBackgroundColor( backgroundColor )
133 {}
134
135 QString name() const { return mName; }
136 void setName( const QString &name ) { mName = name; }
137
138 QString displayName() const { return mDisplayName; }
139 void setDisplayName( const QString &displayName ) { mDisplayName = displayName; }
140
141 Type type() const { return mType; }
142 void setType( Type type ) { mType = type; }
143
144 operator QVariant() { return QVariant::fromValue<DnDTreeItemData>( *this ); }
145
146 int columnCount() const { return mColumnCount; }
147 void setColumnCount( int count ) { mColumnCount = count; }
148
149 bool showAsGroupBox() const;
150 void setShowAsGroupBox( bool showAsGroupBox );
151
160 bool collapsed() const { return mCollapsed; };
161
169 void setCollapsed( bool collapsed ) { mCollapsed = collapsed; };
170
176 const QgsAttributeEditorElement::LabelStyle labelStyle() const;
177
183 void setLabelStyle( const QgsAttributeEditorElement::LabelStyle &labelStyle );
184
185 bool showLabel() const;
186 void setShowLabel( bool showLabel );
187
188 QgsOptionalExpression visibilityExpression() const;
189
196 void setVisibilityExpression( const QgsOptionalExpression &visibilityExpression );
197
206 QgsOptionalExpression collapsedExpression() const;
207
216 void setCollapsedExpression( const QgsOptionalExpression &collapsedExpression );
217
218 RelationEditorConfiguration relationEditorConfiguration() const;
219 void setRelationEditorConfiguration( RelationEditorConfiguration relationEditorConfiguration );
220
221 QmlElementEditorConfiguration qmlElementEditorConfiguration() const;
222 void setQmlElementEditorConfiguration( QmlElementEditorConfiguration qmlElementEditorConfiguration );
223
224 HtmlElementEditorConfiguration htmlElementEditorConfiguration() const;
225 void setHtmlElementEditorConfiguration( HtmlElementEditorConfiguration htmlElementEditorConfiguration );
226
231 SpacerElementEditorConfiguration spacerElementEditorConfiguration() const;
232
237 void setSpacerElementEditorConfiguration( SpacerElementEditorConfiguration spacerElementEditorConfiguration );
238
239 QColor backgroundColor() const;
240 void setBackgroundColor( const QColor &backgroundColor );
241
246 TextElementEditorConfiguration textElementEditorConfiguration() const;
247
252 void setTextElementEditorConfiguration( const TextElementEditorConfiguration &textElementEditorConfiguration );
253
254 private:
255 Type mType = Field;
256 QString mName;
257 QString mDisplayName;
258 int mColumnCount = 1;
259 bool mShowAsGroupBox = false;
260 bool mShowLabel = true;
261 QgsOptionalExpression mVisibilityExpression;
262 RelationEditorConfiguration mRelationEditorConfiguration;
263 QmlElementEditorConfiguration mQmlElementEditorConfiguration;
264 HtmlElementEditorConfiguration mHtmlElementEditorConfiguration;
265 TextElementEditorConfiguration mTextElementEditorConfiguration;
266 SpacerElementEditorConfiguration mSpacerElementEditorConfiguration;
267 QColor mBackgroundColor;
268 bool mCollapsed = false;
269 QgsOptionalExpression mCollapsedExpression;
271 };
272
273
278 {
279 FieldConfig() = default;
280 FieldConfig( QgsVectorLayer *layer, int idx );
281
282 bool mEditable = true;
283 bool mEditableEnabled = true;
284 bool mLabelOnTop = false;
285 bool mReuseLastValues = false;
287 QPushButton *mButton = nullptr;
289 QMap<QString, QVariant> mEditorWidgetConfig;
290 QString mAlias;
292 QString mComment;
294
295 operator QVariant();
296 };
297
298 public:
299 explicit QgsAttributesFormProperties( QgsVectorLayer *layer, QWidget *parent = nullptr );
300
301 QgsAttributeEditorElement *createAttributeEditorWidget( QTreeWidgetItem *item, QgsAttributeEditorElement *parent, bool forceGroup = true );
302
303 void init();
304 void apply();
305
306
308
309 void initAvailableWidgetsTree();
310 void initFormLayoutTree();
311 void initLayoutConfig();
312 void initInitPython();
313 void initSuppressCombo();
314
316
317 protected:
319
320 //QList<QgsRelation> mRelations;
321 QgsVectorLayer *mLayer = nullptr;
322
323 QgsAttributesDnDTree *mAvailableWidgetsTree = nullptr;
324 QgsAttributesDnDTree *mFormLayoutTree = nullptr;
325
326 QgsAttributeWidgetEdit *mAttributeWidgetEdit = nullptr;
327 QgsAttributeTypeDialog *mAttributeTypeDialog = nullptr;
328 QgsAttributeFormContainerEdit *mAttributeContainerEdit = nullptr;
329 QLabel *mInfoTextWidget = nullptr;
330
331 private slots:
332
333 void onInvertSelectionButtonClicked( bool checked );
334 void loadAttributeSpecificEditor( QgsAttributesDnDTree *emitter, QgsAttributesDnDTree *receiver );
335 void onAttributeSelectionChanged();
336 void onFormLayoutSelectionChanged();
337
338 private:
340 void clearAttributeTypeFrame();
341
342 void loadAttributeWidgetEdit();
343 void storeAttributeWidgetEdit();
344
345 void loadAttributeTypeDialog();
346 void storeAttributeTypeDialog( );
347
348 void storeAttributeContainerEdit();
349 void loadAttributeContainerEdit();
350
351 void loadInfoWidget( const QString &infoText );
352
353 QTreeWidgetItem *loadAttributeEditorTreeItem( QgsAttributeEditorElement *widgetDef, QTreeWidgetItem *parent, QgsAttributesDnDTree *tree );
354
356 QString mInitFunction;
357 QString mInitFilePath;
358 QString mInitCode;
359
360 private slots:
361 void addTabOrGroupButton();
362 void removeTabOrGroupButton();
363 void mEditorLayoutComboBox_currentIndexChanged( int index );
364 void pbnSelectEditForm_clicked();
365 void mTbInitCode_clicked();
366};
367
368
369QDataStream &operator<< ( QDataStream &stream, const QgsAttributesFormProperties::DnDTreeItemData &data );
370QDataStream &operator>> ( QDataStream &stream, QgsAttributesFormProperties::DnDTreeItemData &data );
371
372
384class GUI_EXPORT QgsAttributesDnDTree : public QTreeWidget, private QgsExpressionContextGenerator
385{
386 Q_OBJECT
387
388 public:
389 explicit QgsAttributesDnDTree( QgsVectorLayer *layer, QWidget *parent = nullptr );
390
395 QTreeWidgetItem *addItem( QTreeWidgetItem *parent, QgsAttributesFormProperties::DnDTreeItemData data, int index = -1, const QIcon &icon = QIcon() );
396 QTreeWidgetItem *addContainer( QTreeWidgetItem *parent, const QString &title, int columnCount );
397
398 enum Type
399 {
401 Drop
402 };
403
404
405 Type type() const;
406 void setType( QgsAttributesDnDTree::Type value );
407
408 public slots:
409 void selectFirstMatchingItem( const QgsAttributesFormProperties::DnDTreeItemData &data );
410
411 protected:
412 void dragMoveEvent( QDragMoveEvent *event ) override;
413 void dropEvent( QDropEvent *event ) override;
414 bool dropMimeData( QTreeWidgetItem *parent, int index, const QMimeData *data, Qt::DropAction action ) override;
415 /* Qt::DropActions supportedDropActions() const;*/
416
417 // QTreeWidget interface
418 protected:
419 QStringList mimeTypes() const override;
420
421#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
422 QMimeData *mimeData( const QList<QTreeWidgetItem *> items ) const override;
423#else
424 QMimeData *mimeData( const QList<QTreeWidgetItem *> &items ) const override;
425#endif
426
427 private slots:
428 void onItemDoubleClicked( QTreeWidgetItem *item, int column );
429
430 private:
431 QgsVectorLayer *mLayer = nullptr;
432 Type mType = QgsAttributesDnDTree::Type::Drag;
433
434 // QgsExpressionContextGenerator interface
435 public:
437};
438
439
443
444#endif // QGSATTRIBUTESFORMPROPERTIES_H
FieldDomainSplitPolicy
Split policy for field domains.
Definition: qgis.h:2286
@ Duplicate
Duplicate original value.
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.