QGIS API Documentation 3.43.0-Master (b60ef06885e)
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#include <QAction>
37#include <QMenu>
38#include <QClipboard>
39
40#include "ui_qgsattributesformproperties.h"
41#include "qgis_gui.h"
46#include "qgsmessagebar.h"
47
49class QgsAttributeFormContainerEdit;
50class QgsAttributeTypeDialog;
51class QgsAttributeWidgetEdit;
52
58class GUI_EXPORT QgsAttributesFormProperties : public QWidget, public QgsExpressionContextGenerator, private Ui_QgsAttributesFormProperties
59{
60 Q_OBJECT
61
62 public:
64 {
65 DnDTreeRole = Qt::UserRole,
68 };
69
71 {
72 operator QVariant();
73
76 QVariant nmRelationId;
77 bool forceSuppressFormPopup = false;
78 QString label;
79 };
80
82 {
83 QString qmlCode;
84 };
85
87 {
88 QString htmlCode;
89 };
90
92 {
93 QString text;
94 };
95
97 {
98 bool drawLine = false;
99 };
100
106 class DnDTreeItemData : public QTreeWidgetItem
107 {
108 public:
121
122 //do we need that
123 DnDTreeItemData() = default;
124
125 DnDTreeItemData( Type type, const QString &name, const QString &displayName, const QColor &backgroundColor = QColor() )
126 : mType( type )
127 , mName( name )
128 , mDisplayName( displayName )
129 , mBackgroundColor( backgroundColor )
130 {}
131
132 QString name() const { return mName; }
133 void setName( const QString &name ) { mName = name; }
134
135 QString displayName() const { return mDisplayName; }
136 void setDisplayName( const QString &displayName ) { mDisplayName = displayName; }
137
138 Type type() const { return mType; }
139 void setType( Type type ) { mType = type; }
140
141 operator QVariant() { return QVariant::fromValue<DnDTreeItemData>( *this ); }
142
143 int columnCount() const { return mColumnCount; }
144 void setColumnCount( int count ) { mColumnCount = count; }
145
152 Qgis::AttributeEditorContainerType containerType() const;
153
160 void setContainerType( Qgis::AttributeEditorContainerType type );
161
170 bool collapsed() const { return mCollapsed; };
171
179 void setCollapsed( bool collapsed ) { mCollapsed = collapsed; };
180
186 const QgsAttributeEditorElement::LabelStyle labelStyle() const;
187
193 void setLabelStyle( const QgsAttributeEditorElement::LabelStyle &labelStyle );
194
195 bool showLabel() const;
196 void setShowLabel( bool showLabel );
197
206 int horizontalStretch() const { return mHorizontalStretch; }
207
216 void setHorizontalStretch( int stretch ) { mHorizontalStretch = stretch; }
217
226 int verticalStretch() const { return mVerticalStretch; }
227
236 void setVerticalStretch( int stretch ) { mVerticalStretch = stretch; }
237
238 QgsOptionalExpression visibilityExpression() const;
239
246 void setVisibilityExpression( const QgsOptionalExpression &visibilityExpression );
247
256 QgsOptionalExpression collapsedExpression() const;
257
266 void setCollapsedExpression( const QgsOptionalExpression &collapsedExpression );
267
273 RelationEditorConfiguration relationEditorConfiguration() const;
274
280 void setRelationEditorConfiguration( const RelationEditorConfiguration &relationEditorConfiguration );
281
287 QmlElementEditorConfiguration qmlElementEditorConfiguration() const;
288
294 void setQmlElementEditorConfiguration( const QmlElementEditorConfiguration &qmlElementEditorConfiguration );
295
301 HtmlElementEditorConfiguration htmlElementEditorConfiguration() const;
302
308 void setHtmlElementEditorConfiguration( const HtmlElementEditorConfiguration &htmlElementEditorConfiguration );
309
314 SpacerElementEditorConfiguration spacerElementEditorConfiguration() const;
315
320 void setSpacerElementEditorConfiguration( SpacerElementEditorConfiguration spacerElementEditorConfiguration );
321
322 QColor backgroundColor() const;
323 void setBackgroundColor( const QColor &backgroundColor );
324
329 TextElementEditorConfiguration textElementEditorConfiguration() const;
330
335 void setTextElementEditorConfiguration( const TextElementEditorConfiguration &textElementEditorConfiguration );
336
337 private:
338 Type mType = Field;
339 QString mName;
340 QString mDisplayName;
341 int mColumnCount = 1;
343 bool mShowLabel = true;
344 int mHorizontalStretch = 0;
345 int mVerticalStretch = 0;
346 QgsOptionalExpression mVisibilityExpression;
347 RelationEditorConfiguration mRelationEditorConfiguration;
348 QmlElementEditorConfiguration mQmlElementEditorConfiguration;
349 HtmlElementEditorConfiguration mHtmlElementEditorConfiguration;
350 TextElementEditorConfiguration mTextElementEditorConfiguration;
351 SpacerElementEditorConfiguration mSpacerElementEditorConfiguration;
352 QColor mBackgroundColor;
353 bool mCollapsed = false;
354 QgsOptionalExpression mCollapsedExpression;
356 };
357
358
363 {
364 FieldConfig() = default;
365 FieldConfig( QgsVectorLayer *layer, int idx );
366
367 bool mEditable = true;
368 bool mLabelOnTop = false;
369 bool mReuseLastValues = false;
371 QPushButton *mButton = nullptr;
373 QMap<QString, QVariant> mEditorWidgetConfig;
374 QString mAlias;
376 QString mComment;
380
381 operator QVariant();
382 };
383
384 public:
385 explicit QgsAttributesFormProperties( QgsVectorLayer *layer, QWidget *parent = nullptr );
386
390 QgsAttributeEditorElement *createAttributeEditorWidget( QTreeWidgetItem *item, QgsAttributeEditorElement *parent, bool isTopLevel = false );
391
392 void init();
393
397 void apply();
398
403 void store();
404
406
407 void initAvailableWidgetsTree();
408 void initFormLayoutTree();
409 void initLayoutConfig();
410 void initInitPython();
411 void initSuppressCombo();
412
414
415 protected:
417
418 //QList<QgsRelation> mRelations;
419 QgsVectorLayer *mLayer = nullptr;
420
421 QgsAttributesDnDTree *mAvailableWidgetsTree = nullptr;
422 QgsAttributesDnDTree *mFormLayoutTree = nullptr;
423
424 QgsAttributeWidgetEdit *mAttributeWidgetEdit = nullptr;
425 QgsAttributeTypeDialog *mAttributeTypeDialog = nullptr;
426 QgsAttributeFormContainerEdit *mAttributeContainerEdit = nullptr;
427 QLabel *mInfoTextWidget = nullptr;
428
429 private slots:
430 void addContainer();
431 void removeTabOrGroupButton();
432 void mEditorLayoutComboBox_currentIndexChanged( int index );
433 void pbnSelectEditForm_clicked();
434 void mTbInitCode_clicked();
435
436 void onInvertSelectionButtonClicked( bool checked );
437 void loadAttributeSpecificEditor( QgsAttributesDnDTree *emitter, QgsAttributesDnDTree *receiver );
438 void onAttributeSelectionChanged();
439 void onFormLayoutSelectionChanged();
440
442 void onContextMenuRequested( QPoint );
443
444 void updatedFields();
445
446 private:
448 void clearAttributeTypeFrame();
449
450 void loadAttributeWidgetEdit();
451 void storeAttributeWidgetEdit();
452
453 void loadAttributeTypeDialog();
454 void loadAttributeTypeDialogFromConfiguration( const FieldConfig &cfg );
455 void storeAttributeTypeDialog();
456
457 void storeAttributeContainerEdit();
458 void loadAttributeContainerEdit();
459
460 void loadInfoWidget( const QString &infoText );
461
462 void copyWidgetConfiguration();
463 void pasteWidgetConfiguration();
464
465 QTreeWidgetItem *loadAttributeEditorTreeItem( QgsAttributeEditorElement *widgetDef, QTreeWidgetItem *parent, QgsAttributesDnDTree *tree );
466
467 QgsMessageBar *mMessageBar = nullptr;
468
470 QString mInitFunction;
471 QString mInitFilePath;
472 QString mInitCode;
473 int mBlockUpdates = 0;
474
476 QMenu *mAvailableWidgetsTreeContextMenu = nullptr;
477 QAction *mActionCopyWidgetConfiguration = nullptr;
478 QAction *mActionPasteWidgetConfiguration = nullptr;
479
480 friend class TestQgsAttributesFormProperties;
481};
482
483
484QDataStream &operator<<( QDataStream &stream, const QgsAttributesFormProperties::DnDTreeItemData &data );
485QDataStream &operator>>( QDataStream &stream, QgsAttributesFormProperties::DnDTreeItemData &data );
486
487
499class GUI_EXPORT QgsAttributesDnDTree : public QTreeWidget, private QgsExpressionContextGenerator
500{
501 Q_OBJECT
502
503 public:
504 explicit QgsAttributesDnDTree( QgsVectorLayer *layer, QWidget *parent = nullptr );
505
510 QTreeWidgetItem *addItem( QTreeWidgetItem *parent, const QgsAttributesFormProperties::DnDTreeItemData &data, int index = -1, const QIcon &icon = QIcon() );
511
517 QTreeWidgetItem *addContainer( QTreeWidgetItem *parent, const QString &title, int columnCount, Qgis::AttributeEditorContainerType type );
518
519 enum Type
520 {
522 Drop
523 };
524
525
526 Type type() const;
527 void setType( QgsAttributesDnDTree::Type value );
528
529 public slots:
530 void selectFirstMatchingItem( const QgsAttributesFormProperties::DnDTreeItemData &data );
531
532 protected:
533 void dragMoveEvent( QDragMoveEvent *event ) override;
534 void dropEvent( QDropEvent *event ) override;
535 bool dropMimeData( QTreeWidgetItem *parent, int index, const QMimeData *data, Qt::DropAction action ) override;
536 /* Qt::DropActions supportedDropActions() const;*/
537
538 // QTreeWidget interface
539 protected:
540 QStringList mimeTypes() const override;
541
542#if QT_VERSION < QT_VERSION_CHECK( 6, 0, 0 )
543 QMimeData *mimeData( const QList<QTreeWidgetItem *> items ) const override;
544#else
545 QMimeData *mimeData( const QList<QTreeWidgetItem *> &items ) const override;
546#endif
547
548 private slots:
549 void onItemDoubleClicked( QTreeWidgetItem *item, int column );
550
551 private:
552 QgsVectorLayer *mLayer = nullptr;
554
555 // QgsExpressionContextGenerator interface
556 public:
558};
559
560
564
565#endif // QGSATTRIBUTESFORMPROPERTIES_H
AttributeEditorContainerType
Attribute editor container types.
Definition qgis.h:5263
AttributeFormPythonInitCodeSource
The Python init code source for attribute forms.
Definition qgis.h:5308
@ NoSource
Do not use Python code at all.
FieldDomainMergePolicy
Merge policy for field domains.
Definition qgis.h:3774
@ DefaultValue
Use default field value.
FieldDomainSplitPolicy
Split policy for field domains.
Definition qgis.h:3757
@ Duplicate
Duplicate original value.
FieldDuplicatePolicy
Duplicate policy for fields.
Definition qgis.h:3794
@ Duplicate
Duplicate original value.
An abstract base class for any elements of a drag and drop form.
Overrides mime type handling to be able to work with the drag and drop attribute editor.
A tree widget item containing drag-and-drop form designer elements.
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.
A widget for configuring attribute forms.
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.
A bar for displaying non-blocking messages to the user.
An expression with an additional enabled flag.
A grouped map of multiple QgsProperty objects, each referenced by an integer key value.
Represents a vector layer which manages a vector based dataset.
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.