QGIS API Documentation 3.41.0-Master (3440c17df1d)
Loading...
Searching...
No Matches
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:
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 mLabelOnTop = false;
331 bool mReuseLastValues = false;
333 QPushButton *mButton = nullptr;
335 QMap<QString, QVariant> mEditorWidgetConfig;
336 QString mAlias;
338 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
358 void apply();
359
364 void store();
365
367
368 void initAvailableWidgetsTree();
369 void initFormLayoutTree();
370 void initLayoutConfig();
371 void initInitPython();
372 void initSuppressCombo();
373
375
376 protected:
378
379 //QList<QgsRelation> mRelations;
380 QgsVectorLayer *mLayer = nullptr;
381
382 QgsAttributesDnDTree *mAvailableWidgetsTree = nullptr;
383 QgsAttributesDnDTree *mFormLayoutTree = nullptr;
384
385 QgsAttributeWidgetEdit *mAttributeWidgetEdit = nullptr;
386 QgsAttributeTypeDialog *mAttributeTypeDialog = nullptr;
387 QgsAttributeFormContainerEdit *mAttributeContainerEdit = nullptr;
388 QLabel *mInfoTextWidget = nullptr;
389
390 private slots:
391 void addContainer();
392 void removeTabOrGroupButton();
393 void mEditorLayoutComboBox_currentIndexChanged( int index );
394 void pbnSelectEditForm_clicked();
395 void mTbInitCode_clicked();
396
397 void onInvertSelectionButtonClicked( bool checked );
398 void loadAttributeSpecificEditor( QgsAttributesDnDTree *emitter, QgsAttributesDnDTree *receiver );
399 void onAttributeSelectionChanged();
400 void onFormLayoutSelectionChanged();
401
402 void updatedFields();
403
404 private:
406 void clearAttributeTypeFrame();
407
408 void loadAttributeWidgetEdit();
409 void storeAttributeWidgetEdit();
410
411 void loadAttributeTypeDialog();
412 void storeAttributeTypeDialog( );
413
414 void storeAttributeContainerEdit();
415 void loadAttributeContainerEdit();
416
417 void loadInfoWidget( const QString &infoText );
418
419 QTreeWidgetItem *loadAttributeEditorTreeItem( QgsAttributeEditorElement *widgetDef, QTreeWidgetItem *parent, QgsAttributesDnDTree *tree );
420
422 QString mInitFunction;
423 QString mInitFilePath;
424 QString mInitCode;
425 int mBlockUpdates = 0;
426
427};
428
429
430QDataStream &operator<< ( QDataStream &stream, const QgsAttributesFormProperties::DnDTreeItemData &data );
431QDataStream &operator>> ( QDataStream &stream, QgsAttributesFormProperties::DnDTreeItemData &data );
432
433
445class GUI_EXPORT QgsAttributesDnDTree : public QTreeWidget, private QgsExpressionContextGenerator
446{
447 Q_OBJECT
448
449 public:
450 explicit QgsAttributesDnDTree( QgsVectorLayer *layer, QWidget *parent = nullptr );
451
456 QTreeWidgetItem *addItem( QTreeWidgetItem *parent, const QgsAttributesFormProperties::DnDTreeItemData &data, int index = -1, const QIcon &icon = QIcon() );
457
463 QTreeWidgetItem *addContainer( QTreeWidgetItem *parent, const QString &title, int columnCount, Qgis::AttributeEditorContainerType type );
464
465 enum Type
466 {
468 Drop
469 };
470
471
472 Type type() const;
473 void setType( QgsAttributesDnDTree::Type value );
474
475 public slots:
476 void selectFirstMatchingItem( const QgsAttributesFormProperties::DnDTreeItemData &data );
477
478 protected:
479 void dragMoveEvent( QDragMoveEvent *event ) override;
480 void dropEvent( QDropEvent *event ) override;
481 bool dropMimeData( QTreeWidgetItem *parent, int index, const QMimeData *data, Qt::DropAction action ) override;
482 /* Qt::DropActions supportedDropActions() const;*/
483
484 // QTreeWidget interface
485 protected:
486 QStringList mimeTypes() const override;
487
488#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
489 QMimeData *mimeData( const QList<QTreeWidgetItem *> items ) const override;
490#else
491 QMimeData *mimeData( const QList<QTreeWidgetItem *> &items ) const override;
492#endif
493
494 private slots:
495 void onItemDoubleClicked( QTreeWidgetItem *item, int column );
496
497 private:
498 QgsVectorLayer *mLayer = nullptr;
500
501 // QgsExpressionContextGenerator interface
502 public:
504};
505
506
510
511#endif // QGSATTRIBUTESFORMPROPERTIES_H
AttributeEditorContainerType
Attribute editor container types.
Definition qgis.h:5081
AttributeFormPythonInitCodeSource
The Python init code source for attribute forms.
Definition qgis.h:5126
@ NoSource
Do not use Python code at all.
FieldDomainSplitPolicy
Split policy for field domains.
Definition qgis.h:3628
@ Duplicate
Duplicate original value.
FieldDuplicatePolicy
Duplicate policy for fields.
Definition qgis.h:3660
@ 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.