QGIS API Documentation 3.32.0-Lima (311a8cb8a6)
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"
43
45class QgsAttributeFormContainerEdit;
46class QgsAttributeTypeDialog;
47class QgsAttributeWidgetEdit;
48
53class GUI_EXPORT QgsAttributesFormProperties : public QWidget, public QgsExpressionContextGenerator, private Ui_QgsAttributesFormProperties
54{
55 Q_OBJECT
56
57 public:
58
60 {
61 DnDTreeRole = Qt::UserRole,
64 };
65
67 {
68 operator QVariant();
69
72 QVariant nmRelationId;
73 bool forceSuppressFormPopup = false;
74 QString label;
75 };
76
78 {
79 QString qmlCode;
80 };
81
83 {
84 QString htmlCode;
85 };
86
88 {
89 QString text;
90 };
91
93 {
94 bool drawLine = false;
95 };
96
101 class DnDTreeItemData : public QTreeWidgetItem
102 {
103 public:
104 enum Type
105 {
115 };
116
117 //do we need that
118 DnDTreeItemData() = default;
119
120 DnDTreeItemData( Type type, const QString &name, const QString &displayName, const QColor &backgroundColor = QColor() )
121 : mType( type )
122 , mName( name )
123 , mDisplayName( displayName )
124 , mBackgroundColor( backgroundColor )
125 {}
126
127 QString name() const { return mName; }
128 void setName( const QString &name ) { mName = name; }
129
130 QString displayName() const { return mDisplayName; }
131 void setDisplayName( const QString &displayName ) { mDisplayName = displayName; }
132
133 Type type() const { return mType; }
134 void setType( Type type ) { mType = type; }
135
136 operator QVariant() { return QVariant::fromValue<DnDTreeItemData>( *this ); }
137
138 int columnCount() const { return mColumnCount; }
139 void setColumnCount( int count ) { mColumnCount = count; }
140
147 Qgis::AttributeEditorContainerType containerType() const;
148
155 void setContainerType( Qgis::AttributeEditorContainerType type );
156
165 bool collapsed() const { return mCollapsed; };
166
174 void setCollapsed( bool collapsed ) { mCollapsed = collapsed; };
175
181 const QgsAttributeEditorElement::LabelStyle labelStyle() const;
182
188 void setLabelStyle( const QgsAttributeEditorElement::LabelStyle &labelStyle );
189
190 bool showLabel() const;
191 void setShowLabel( bool showLabel );
192
201 int horizontalStretch() const { return mHorizontalStretch; }
202
211 void setHorizontalStretch( int stretch ) { mHorizontalStretch = stretch; }
212
221 int verticalStretch() const { return mVerticalStretch; }
222
231 void setVerticalStretch( int stretch ) { mVerticalStretch = stretch; }
232
233 QgsOptionalExpression visibilityExpression() const;
234
241 void setVisibilityExpression( const QgsOptionalExpression &visibilityExpression );
242
251 QgsOptionalExpression collapsedExpression() const;
252
261 void setCollapsedExpression( const QgsOptionalExpression &collapsedExpression );
262
263 RelationEditorConfiguration relationEditorConfiguration() const;
264 void setRelationEditorConfiguration( RelationEditorConfiguration relationEditorConfiguration );
265
266 QmlElementEditorConfiguration qmlElementEditorConfiguration() const;
267 void setQmlElementEditorConfiguration( QmlElementEditorConfiguration qmlElementEditorConfiguration );
268
269 HtmlElementEditorConfiguration htmlElementEditorConfiguration() const;
270 void setHtmlElementEditorConfiguration( HtmlElementEditorConfiguration htmlElementEditorConfiguration );
271
276 SpacerElementEditorConfiguration spacerElementEditorConfiguration() const;
277
282 void setSpacerElementEditorConfiguration( SpacerElementEditorConfiguration spacerElementEditorConfiguration );
283
284 QColor backgroundColor() const;
285 void setBackgroundColor( const QColor &backgroundColor );
286
291 TextElementEditorConfiguration textElementEditorConfiguration() const;
292
297 void setTextElementEditorConfiguration( const TextElementEditorConfiguration &textElementEditorConfiguration );
298
299 private:
300 Type mType = Field;
301 QString mName;
302 QString mDisplayName;
303 int mColumnCount = 1;
305 bool mShowLabel = true;
306 int mHorizontalStretch = 0;
307 int mVerticalStretch = 0;
308 QgsOptionalExpression mVisibilityExpression;
309 RelationEditorConfiguration mRelationEditorConfiguration;
310 QmlElementEditorConfiguration mQmlElementEditorConfiguration;
311 HtmlElementEditorConfiguration mHtmlElementEditorConfiguration;
312 TextElementEditorConfiguration mTextElementEditorConfiguration;
313 SpacerElementEditorConfiguration mSpacerElementEditorConfiguration;
314 QColor mBackgroundColor;
315 bool mCollapsed = false;
316 QgsOptionalExpression mCollapsedExpression;
318 };
319
320
325 {
326 FieldConfig() = default;
327 FieldConfig( QgsVectorLayer *layer, int idx );
328
329 bool mEditable = true;
330 bool mEditableEnabled = true;
331 bool mLabelOnTop = false;
332 bool mReuseLastValues = false;
334 QPushButton *mButton = nullptr;
336 QMap<QString, QVariant> mEditorWidgetConfig;
337 QString mAlias;
339 QString mComment;
341
342 operator QVariant();
343 };
344
345 public:
346 explicit QgsAttributesFormProperties( QgsVectorLayer *layer, QWidget *parent = nullptr );
347
351 QgsAttributeEditorElement *createAttributeEditorWidget( QTreeWidgetItem *item, QgsAttributeEditorElement *parent, bool isTopLevel = false );
352
353 void init();
354 void apply();
355
356
358
359 void initAvailableWidgetsTree();
360 void initFormLayoutTree();
361 void initLayoutConfig();
362 void initInitPython();
363 void initSuppressCombo();
364
366
367 protected:
369
370 //QList<QgsRelation> mRelations;
371 QgsVectorLayer *mLayer = nullptr;
372
373 QgsAttributesDnDTree *mAvailableWidgetsTree = nullptr;
374 QgsAttributesDnDTree *mFormLayoutTree = nullptr;
375
376 QgsAttributeWidgetEdit *mAttributeWidgetEdit = nullptr;
377 QgsAttributeTypeDialog *mAttributeTypeDialog = nullptr;
378 QgsAttributeFormContainerEdit *mAttributeContainerEdit = nullptr;
379 QLabel *mInfoTextWidget = nullptr;
380
381 private slots:
382
383 void onInvertSelectionButtonClicked( bool checked );
384 void loadAttributeSpecificEditor( QgsAttributesDnDTree *emitter, QgsAttributesDnDTree *receiver );
385 void onAttributeSelectionChanged();
386 void onFormLayoutSelectionChanged();
387
388 private:
390 void clearAttributeTypeFrame();
391
392 void loadAttributeWidgetEdit();
393 void storeAttributeWidgetEdit();
394
395 void loadAttributeTypeDialog();
396 void storeAttributeTypeDialog( );
397
398 void storeAttributeContainerEdit();
399 void loadAttributeContainerEdit();
400
401 void loadInfoWidget( const QString &infoText );
402
403 QTreeWidgetItem *loadAttributeEditorTreeItem( QgsAttributeEditorElement *widgetDef, QTreeWidgetItem *parent, QgsAttributesDnDTree *tree );
404
405 Qgis::AttributeFormPythonInitCodeSource mInitCodeSource = Qgis::AttributeFormPythonInitCodeSource::NoSource;
406 QString mInitFunction;
407 QString mInitFilePath;
408 QString mInitCode;
409
410 private slots:
411 void addContainer();
412 void removeTabOrGroupButton();
413 void mEditorLayoutComboBox_currentIndexChanged( int index );
414 void pbnSelectEditForm_clicked();
415 void mTbInitCode_clicked();
416};
417
418
419QDataStream &operator<< ( QDataStream &stream, const QgsAttributesFormProperties::DnDTreeItemData &data );
420QDataStream &operator>> ( QDataStream &stream, QgsAttributesFormProperties::DnDTreeItemData &data );
421
422
434class GUI_EXPORT QgsAttributesDnDTree : public QTreeWidget, private QgsExpressionContextGenerator
435{
436 Q_OBJECT
437
438 public:
439 explicit QgsAttributesDnDTree( QgsVectorLayer *layer, QWidget *parent = nullptr );
440
445 QTreeWidgetItem *addItem( QTreeWidgetItem *parent, QgsAttributesFormProperties::DnDTreeItemData data, int index = -1, const QIcon &icon = QIcon() );
446
452 QTreeWidgetItem *addContainer( QTreeWidgetItem *parent, const QString &title, int columnCount, Qgis::AttributeEditorContainerType type );
453
454 enum Type
455 {
457 Drop
458 };
459
460
461 Type type() const;
462 void setType( QgsAttributesDnDTree::Type value );
463
464 public slots:
465 void selectFirstMatchingItem( const QgsAttributesFormProperties::DnDTreeItemData &data );
466
467 protected:
468 void dragMoveEvent( QDragMoveEvent *event ) override;
469 void dropEvent( QDropEvent *event ) override;
470 bool dropMimeData( QTreeWidgetItem *parent, int index, const QMimeData *data, Qt::DropAction action ) override;
471 /* Qt::DropActions supportedDropActions() const;*/
472
473 // QTreeWidget interface
474 protected:
475 QStringList mimeTypes() const override;
476
477#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
478 QMimeData *mimeData( const QList<QTreeWidgetItem *> items ) const override;
479#else
480 QMimeData *mimeData( const QList<QTreeWidgetItem *> &items ) const override;
481#endif
482
483 private slots:
484 void onItemDoubleClicked( QTreeWidgetItem *item, int column );
485
486 private:
487 QgsVectorLayer *mLayer = nullptr;
488 Type mType = QgsAttributesDnDTree::Type::Drag;
489
490 // QgsExpressionContextGenerator interface
491 public:
493};
494
495
499
500#endif // QGSATTRIBUTESFORMPROPERTIES_H
AttributeEditorContainerType
Attribute editor container types.
Definition: qgis.h:3562
AttributeFormPythonInitCodeSource
The Python init code source for attribute forms.
Definition: qgis.h:3607
FieldDomainSplitPolicy
Split policy for field domains.
Definition: qgis.h:2446
@ 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.
int verticalStretch() const
Returns the vertical stretch factor for the element.
DnDTreeItemData(Type type, const QString &name, const QString &displayName, const QColor &backgroundColor=QColor())
@ WidgetType
In the widget tree, the type of widget.
int horizontalStretch() const
Returns the horizontal stretch factor for the element.
void setCollapsed(bool collapsed)
For group box containers sets if this group box is collapsed.
void setVerticalStretch(int stretch)
Sets the vertical stretch factor for the element.
void setHorizontalStretch(int stretch)
Sets the horizontal stretch factor for the element.
bool collapsed() const
For group box containers returns if this group box is collapsed.
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.