QGIS API Documentation 3.41.0-Master (02257426e5a)
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#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
57class GUI_EXPORT QgsAttributesFormProperties : public QWidget, public QgsExpressionContextGenerator, private Ui_QgsAttributesFormProperties
58{
59 Q_OBJECT
60
61 public:
63 {
64 DnDTreeRole = Qt::UserRole,
67 };
68
70 {
71 operator QVariant();
72
75 QVariant nmRelationId;
76 bool forceSuppressFormPopup = false;
77 QString label;
78 };
79
81 {
82 QString qmlCode;
83 };
84
86 {
87 QString htmlCode;
88 };
89
91 {
92 QString text;
93 };
94
96 {
97 bool drawLine = false;
98 };
99
104 class DnDTreeItemData : public QTreeWidgetItem
105 {
106 public:
119
120 //do we need that
121 DnDTreeItemData() = default;
122
123 DnDTreeItemData( Type type, const QString &name, const QString &displayName, const QColor &backgroundColor = QColor() )
124 : mType( type )
125 , mName( name )
126 , mDisplayName( displayName )
127 , mBackgroundColor( backgroundColor )
128 {}
129
130 QString name() const { return mName; }
131 void setName( const QString &name ) { mName = name; }
132
133 QString displayName() const { return mDisplayName; }
134 void setDisplayName( const QString &displayName ) { mDisplayName = displayName; }
135
136 Type type() const { return mType; }
137 void setType( Type type ) { mType = type; }
138
139 operator QVariant() { return QVariant::fromValue<DnDTreeItemData>( *this ); }
140
141 int columnCount() const { return mColumnCount; }
142 void setColumnCount( int count ) { mColumnCount = count; }
143
150 Qgis::AttributeEditorContainerType containerType() const;
151
158 void setContainerType( Qgis::AttributeEditorContainerType type );
159
168 bool collapsed() const { return mCollapsed; };
169
177 void setCollapsed( bool collapsed ) { mCollapsed = collapsed; };
178
184 const QgsAttributeEditorElement::LabelStyle labelStyle() const;
185
191 void setLabelStyle( const QgsAttributeEditorElement::LabelStyle &labelStyle );
192
193 bool showLabel() const;
194 void setShowLabel( bool showLabel );
195
204 int horizontalStretch() const { return mHorizontalStretch; }
205
214 void setHorizontalStretch( int stretch ) { mHorizontalStretch = stretch; }
215
224 int verticalStretch() const { return mVerticalStretch; }
225
234 void setVerticalStretch( int stretch ) { mVerticalStretch = stretch; }
235
236 QgsOptionalExpression visibilityExpression() const;
237
244 void setVisibilityExpression( const QgsOptionalExpression &visibilityExpression );
245
254 QgsOptionalExpression collapsedExpression() const;
255
264 void setCollapsedExpression( const QgsOptionalExpression &collapsedExpression );
265
271 RelationEditorConfiguration relationEditorConfiguration() const;
272
278 void setRelationEditorConfiguration( const RelationEditorConfiguration &relationEditorConfiguration );
279
285 QmlElementEditorConfiguration qmlElementEditorConfiguration() const;
286
292 void setQmlElementEditorConfiguration( const QmlElementEditorConfiguration &qmlElementEditorConfiguration );
293
299 HtmlElementEditorConfiguration htmlElementEditorConfiguration() const;
300
306 void setHtmlElementEditorConfiguration( const HtmlElementEditorConfiguration &htmlElementEditorConfiguration );
307
312 SpacerElementEditorConfiguration spacerElementEditorConfiguration() const;
313
318 void setSpacerElementEditorConfiguration( SpacerElementEditorConfiguration spacerElementEditorConfiguration );
319
320 QColor backgroundColor() const;
321 void setBackgroundColor( const QColor &backgroundColor );
322
327 TextElementEditorConfiguration textElementEditorConfiguration() const;
328
333 void setTextElementEditorConfiguration( const TextElementEditorConfiguration &textElementEditorConfiguration );
334
335 private:
336 Type mType = Field;
337 QString mName;
338 QString mDisplayName;
339 int mColumnCount = 1;
341 bool mShowLabel = true;
342 int mHorizontalStretch = 0;
343 int mVerticalStretch = 0;
344 QgsOptionalExpression mVisibilityExpression;
345 RelationEditorConfiguration mRelationEditorConfiguration;
346 QmlElementEditorConfiguration mQmlElementEditorConfiguration;
347 HtmlElementEditorConfiguration mHtmlElementEditorConfiguration;
348 TextElementEditorConfiguration mTextElementEditorConfiguration;
349 SpacerElementEditorConfiguration mSpacerElementEditorConfiguration;
350 QColor mBackgroundColor;
351 bool mCollapsed = false;
352 QgsOptionalExpression mCollapsedExpression;
354 };
355
356
361 {
362 FieldConfig() = default;
363 FieldConfig( QgsVectorLayer *layer, int idx );
364
365 bool mEditable = true;
366 bool mLabelOnTop = false;
367 bool mReuseLastValues = false;
369 QPushButton *mButton = nullptr;
371 QMap<QString, QVariant> mEditorWidgetConfig;
372 QString mAlias;
374 QString mComment;
377
378 operator QVariant();
379 };
380
381 public:
382 explicit QgsAttributesFormProperties( QgsVectorLayer *layer, QWidget *parent = nullptr );
383
387 QgsAttributeEditorElement *createAttributeEditorWidget( QTreeWidgetItem *item, QgsAttributeEditorElement *parent, bool isTopLevel = false );
388
389 void init();
390
394 void apply();
395
400 void store();
401
403
404 void initAvailableWidgetsTree();
405 void initFormLayoutTree();
406 void initLayoutConfig();
407 void initInitPython();
408 void initSuppressCombo();
409
411
412 protected:
414
415 //QList<QgsRelation> mRelations;
416 QgsVectorLayer *mLayer = nullptr;
417
418 QgsAttributesDnDTree *mAvailableWidgetsTree = nullptr;
419 QgsAttributesDnDTree *mFormLayoutTree = nullptr;
420
421 QgsAttributeWidgetEdit *mAttributeWidgetEdit = nullptr;
422 QgsAttributeTypeDialog *mAttributeTypeDialog = nullptr;
423 QgsAttributeFormContainerEdit *mAttributeContainerEdit = nullptr;
424 QLabel *mInfoTextWidget = nullptr;
425
426 private slots:
427 void addContainer();
428 void removeTabOrGroupButton();
429 void mEditorLayoutComboBox_currentIndexChanged( int index );
430 void pbnSelectEditForm_clicked();
431 void mTbInitCode_clicked();
432
433 void onInvertSelectionButtonClicked( bool checked );
434 void loadAttributeSpecificEditor( QgsAttributesDnDTree *emitter, QgsAttributesDnDTree *receiver );
435 void onAttributeSelectionChanged();
436 void onFormLayoutSelectionChanged();
437
439 void onContextMenuRequested( QPoint );
440
441 void updatedFields();
442
443 private:
445 void clearAttributeTypeFrame();
446
447 void loadAttributeWidgetEdit();
448 void storeAttributeWidgetEdit();
449
450 void loadAttributeTypeDialog();
451 void loadAttributeTypeDialogFromConfiguration( const FieldConfig &cfg );
452 void storeAttributeTypeDialog();
453
454 void storeAttributeContainerEdit();
455 void loadAttributeContainerEdit();
456
457 void loadInfoWidget( const QString &infoText );
458
459 void copyWidgetConfiguration();
460 void pasteWidgetConfiguration();
461
462 QTreeWidgetItem *loadAttributeEditorTreeItem( QgsAttributeEditorElement *widgetDef, QTreeWidgetItem *parent, QgsAttributesDnDTree *tree );
463
464 QgsMessageBar *mMessageBar = nullptr;
465
467 QString mInitFunction;
468 QString mInitFilePath;
469 QString mInitCode;
470 int mBlockUpdates = 0;
471
473 QMenu *mAvailableWidgetsTreeContextMenu = nullptr;
474 QAction *mActionCopyWidgetConfiguration = nullptr;
475 QAction *mActionPasteWidgetConfiguration = nullptr;
476
477 friend class TestQgsAttributesFormProperties;
478};
479
480
481QDataStream &operator<<( QDataStream &stream, const QgsAttributesFormProperties::DnDTreeItemData &data );
482QDataStream &operator>>( QDataStream &stream, QgsAttributesFormProperties::DnDTreeItemData &data );
483
484
496class GUI_EXPORT QgsAttributesDnDTree : public QTreeWidget, private QgsExpressionContextGenerator
497{
498 Q_OBJECT
499
500 public:
501 explicit QgsAttributesDnDTree( QgsVectorLayer *layer, QWidget *parent = nullptr );
502
507 QTreeWidgetItem *addItem( QTreeWidgetItem *parent, const QgsAttributesFormProperties::DnDTreeItemData &data, int index = -1, const QIcon &icon = QIcon() );
508
514 QTreeWidgetItem *addContainer( QTreeWidgetItem *parent, const QString &title, int columnCount, Qgis::AttributeEditorContainerType type );
515
516 enum Type
517 {
519 Drop
520 };
521
522
523 Type type() const;
524 void setType( QgsAttributesDnDTree::Type value );
525
526 public slots:
527 void selectFirstMatchingItem( const QgsAttributesFormProperties::DnDTreeItemData &data );
528
529 protected:
530 void dragMoveEvent( QDragMoveEvent *event ) override;
531 void dropEvent( QDropEvent *event ) override;
532 bool dropMimeData( QTreeWidgetItem *parent, int index, const QMimeData *data, Qt::DropAction action ) override;
533 /* Qt::DropActions supportedDropActions() const;*/
534
535 // QTreeWidget interface
536 protected:
537 QStringList mimeTypes() const override;
538
539#if QT_VERSION < QT_VERSION_CHECK( 6, 0, 0 )
540 QMimeData *mimeData( const QList<QTreeWidgetItem *> items ) const override;
541#else
542 QMimeData *mimeData( const QList<QTreeWidgetItem *> &items ) const override;
543#endif
544
545 private slots:
546 void onItemDoubleClicked( QTreeWidgetItem *item, int column );
547
548 private:
549 QgsVectorLayer *mLayer = nullptr;
551
552 // QgsExpressionContextGenerator interface
553 public:
555};
556
557
561
562#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.
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 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.