QGIS API Documentation 3.41.0-Master (57ec4277f5e)
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:
59 {
60 DnDTreeRole = Qt::UserRole,
63 };
64
66 {
67 operator QVariant();
68
71 QVariant nmRelationId;
72 bool forceSuppressFormPopup = false;
73 QString label;
74 };
75
77 {
78 QString qmlCode;
79 };
80
82 {
83 QString htmlCode;
84 };
85
87 {
88 QString text;
89 };
90
92 {
93 bool drawLine = false;
94 };
95
100 class DnDTreeItemData : public QTreeWidgetItem
101 {
102 public:
115
116 //do we need that
117 DnDTreeItemData() = default;
118
119 DnDTreeItemData( Type type, const QString &name, const QString &displayName, const QColor &backgroundColor = QColor() )
120 : mType( type )
121 , mName( name )
122 , mDisplayName( displayName )
123 , mBackgroundColor( backgroundColor )
124 {}
125
126 QString name() const { return mName; }
127 void setName( const QString &name ) { mName = name; }
128
129 QString displayName() const { return mDisplayName; }
130 void setDisplayName( const QString &displayName ) { mDisplayName = displayName; }
131
132 Type type() const { return mType; }
133 void setType( Type type ) { mType = type; }
134
135 operator QVariant() { return QVariant::fromValue<DnDTreeItemData>( *this ); }
136
137 int columnCount() const { return mColumnCount; }
138 void setColumnCount( int count ) { mColumnCount = count; }
139
146 Qgis::AttributeEditorContainerType containerType() const;
147
154 void setContainerType( Qgis::AttributeEditorContainerType type );
155
164 bool collapsed() const { return mCollapsed; };
165
173 void setCollapsed( bool collapsed ) { mCollapsed = collapsed; };
174
180 const QgsAttributeEditorElement::LabelStyle labelStyle() const;
181
187 void setLabelStyle( const QgsAttributeEditorElement::LabelStyle &labelStyle );
188
189 bool showLabel() const;
190 void setShowLabel( bool showLabel );
191
200 int horizontalStretch() const { return mHorizontalStretch; }
201
210 void setHorizontalStretch( int stretch ) { mHorizontalStretch = stretch; }
211
220 int verticalStretch() const { return mVerticalStretch; }
221
230 void setVerticalStretch( int stretch ) { mVerticalStretch = stretch; }
231
232 QgsOptionalExpression visibilityExpression() const;
233
240 void setVisibilityExpression( const QgsOptionalExpression &visibilityExpression );
241
250 QgsOptionalExpression collapsedExpression() const;
251
260 void setCollapsedExpression( const QgsOptionalExpression &collapsedExpression );
261
267 RelationEditorConfiguration relationEditorConfiguration() const;
268
274 void setRelationEditorConfiguration( const RelationEditorConfiguration &relationEditorConfiguration );
275
281 QmlElementEditorConfiguration qmlElementEditorConfiguration() const;
282
288 void setQmlElementEditorConfiguration( const QmlElementEditorConfiguration &qmlElementEditorConfiguration );
289
295 HtmlElementEditorConfiguration htmlElementEditorConfiguration() const;
296
302 void setHtmlElementEditorConfiguration( const HtmlElementEditorConfiguration &htmlElementEditorConfiguration );
303
308 SpacerElementEditorConfiguration spacerElementEditorConfiguration() const;
309
314 void setSpacerElementEditorConfiguration( SpacerElementEditorConfiguration spacerElementEditorConfiguration );
315
316 QColor backgroundColor() const;
317 void setBackgroundColor( const QColor &backgroundColor );
318
323 TextElementEditorConfiguration textElementEditorConfiguration() const;
324
329 void setTextElementEditorConfiguration( const TextElementEditorConfiguration &textElementEditorConfiguration );
330
331 private:
332 Type mType = Field;
333 QString mName;
334 QString mDisplayName;
335 int mColumnCount = 1;
337 bool mShowLabel = true;
338 int mHorizontalStretch = 0;
339 int mVerticalStretch = 0;
340 QgsOptionalExpression mVisibilityExpression;
341 RelationEditorConfiguration mRelationEditorConfiguration;
342 QmlElementEditorConfiguration mQmlElementEditorConfiguration;
343 HtmlElementEditorConfiguration mHtmlElementEditorConfiguration;
344 TextElementEditorConfiguration mTextElementEditorConfiguration;
345 SpacerElementEditorConfiguration mSpacerElementEditorConfiguration;
346 QColor mBackgroundColor;
347 bool mCollapsed = false;
348 QgsOptionalExpression mCollapsedExpression;
350 };
351
352
357 {
358 FieldConfig() = default;
359 FieldConfig( QgsVectorLayer *layer, int idx );
360
361 bool mEditable = true;
362 bool mLabelOnTop = false;
363 bool mReuseLastValues = false;
365 QPushButton *mButton = nullptr;
367 QMap<QString, QVariant> mEditorWidgetConfig;
368 QString mAlias;
370 QString mComment;
373
374 operator QVariant();
375 };
376
377 public:
378 explicit QgsAttributesFormProperties( QgsVectorLayer *layer, QWidget *parent = nullptr );
379
383 QgsAttributeEditorElement *createAttributeEditorWidget( QTreeWidgetItem *item, QgsAttributeEditorElement *parent, bool isTopLevel = false );
384
385 void init();
386
390 void apply();
391
396 void store();
397
399
400 void initAvailableWidgetsTree();
401 void initFormLayoutTree();
402 void initLayoutConfig();
403 void initInitPython();
404 void initSuppressCombo();
405
407
408 protected:
410
411 //QList<QgsRelation> mRelations;
412 QgsVectorLayer *mLayer = nullptr;
413
414 QgsAttributesDnDTree *mAvailableWidgetsTree = nullptr;
415 QgsAttributesDnDTree *mFormLayoutTree = nullptr;
416
417 QgsAttributeWidgetEdit *mAttributeWidgetEdit = nullptr;
418 QgsAttributeTypeDialog *mAttributeTypeDialog = nullptr;
419 QgsAttributeFormContainerEdit *mAttributeContainerEdit = nullptr;
420 QLabel *mInfoTextWidget = nullptr;
421
422 private slots:
423 void addContainer();
424 void removeTabOrGroupButton();
425 void mEditorLayoutComboBox_currentIndexChanged( int index );
426 void pbnSelectEditForm_clicked();
427 void mTbInitCode_clicked();
428
429 void onInvertSelectionButtonClicked( bool checked );
430 void loadAttributeSpecificEditor( QgsAttributesDnDTree *emitter, QgsAttributesDnDTree *receiver );
431 void onAttributeSelectionChanged();
432 void onFormLayoutSelectionChanged();
433
434 void updatedFields();
435
436 private:
438 void clearAttributeTypeFrame();
439
440 void loadAttributeWidgetEdit();
441 void storeAttributeWidgetEdit();
442
443 void loadAttributeTypeDialog();
444 void storeAttributeTypeDialog();
445
446 void storeAttributeContainerEdit();
447 void loadAttributeContainerEdit();
448
449 void loadInfoWidget( const QString &infoText );
450
451 QTreeWidgetItem *loadAttributeEditorTreeItem( QgsAttributeEditorElement *widgetDef, QTreeWidgetItem *parent, QgsAttributesDnDTree *tree );
452
454 QString mInitFunction;
455 QString mInitFilePath;
456 QString mInitCode;
457 int mBlockUpdates = 0;
458};
459
460
461QDataStream &operator<<( QDataStream &stream, const QgsAttributesFormProperties::DnDTreeItemData &data );
462QDataStream &operator>>( QDataStream &stream, QgsAttributesFormProperties::DnDTreeItemData &data );
463
464
476class GUI_EXPORT QgsAttributesDnDTree : public QTreeWidget, private QgsExpressionContextGenerator
477{
478 Q_OBJECT
479
480 public:
481 explicit QgsAttributesDnDTree( QgsVectorLayer *layer, QWidget *parent = nullptr );
482
487 QTreeWidgetItem *addItem( QTreeWidgetItem *parent, const QgsAttributesFormProperties::DnDTreeItemData &data, int index = -1, const QIcon &icon = QIcon() );
488
494 QTreeWidgetItem *addContainer( QTreeWidgetItem *parent, const QString &title, int columnCount, Qgis::AttributeEditorContainerType type );
495
496 enum Type
497 {
499 Drop
500 };
501
502
503 Type type() const;
504 void setType( QgsAttributesDnDTree::Type value );
505
506 public slots:
507 void selectFirstMatchingItem( const QgsAttributesFormProperties::DnDTreeItemData &data );
508
509 protected:
510 void dragMoveEvent( QDragMoveEvent *event ) override;
511 void dropEvent( QDropEvent *event ) override;
512 bool dropMimeData( QTreeWidgetItem *parent, int index, const QMimeData *data, Qt::DropAction action ) override;
513 /* Qt::DropActions supportedDropActions() const;*/
514
515 // QTreeWidget interface
516 protected:
517 QStringList mimeTypes() const override;
518
519#if QT_VERSION < QT_VERSION_CHECK( 6, 0, 0 )
520 QMimeData *mimeData( const QList<QTreeWidgetItem *> items ) const override;
521#else
522 QMimeData *mimeData( const QList<QTreeWidgetItem *> &items ) const override;
523#endif
524
525 private slots:
526 void onItemDoubleClicked( QTreeWidgetItem *item, int column );
527
528 private:
529 QgsVectorLayer *mLayer = nullptr;
531
532 // QgsExpressionContextGenerator interface
533 public:
535};
536
537
541
542#endif // QGSATTRIBUTESFORMPROPERTIES_H
AttributeEditorContainerType
Attribute editor container types.
Definition qgis.h:5144
AttributeFormPythonInitCodeSource
The Python init code source for attribute forms.
Definition qgis.h:5189
@ NoSource
Do not use Python code at all.
FieldDomainSplitPolicy
Split policy for field domains.
Definition qgis.h:3691
@ Duplicate
Duplicate original value.
FieldDuplicatePolicy
Duplicate policy for fields.
Definition qgis.h:3723
@ 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.