QGIS API Documentation  3.26.3-Buenos Aires (65e4edfdad)
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"
39 #include "qgsaddattrdialog.h"
40 #include "qgslogger.h"
42 #include "qgsfieldcalculator.h"
45 #include "qgsgui.h"
46 #include "qgseditorwidgetfactory.h"
48 #include "qgsrelationmanager.h"
50 
51 
53 class QgsAttributeFormContainerEdit;
54 class QgsAttributeTypeDialog;
55 class QgsAttributeWidgetEdit;
56 
61 class GUI_EXPORT QgsAttributesFormProperties : public QWidget, public QgsExpressionContextGenerator, private Ui_QgsAttributesFormProperties
62 {
63  Q_OBJECT
64 
65  public:
66 
68  {
69  DnDTreeRole = Qt::UserRole,
72  };
73 
75  {
76  operator QVariant();
77 
79  QVariantMap mRelationWidgetConfig;
80  QVariant nmRelationId;
81  bool forceSuppressFormPopup = false;
82  QString label;
83  };
84 
86  {
87  QString qmlCode;
88  };
89 
91  {
92  QString htmlCode;
93  };
94 
99  class DnDTreeItemData : public QTreeWidgetItem
100  {
101  public:
102  enum Type
103  {
110  Action
111  };
112 
113  //do we need that
114  DnDTreeItemData() = default;
115 
116  DnDTreeItemData( Type type, const QString &name, const QString &displayName, const QColor &backgroundColor = QColor() )
117  : mType( type )
118  , mName( name )
119  , mDisplayName( displayName )
120  , mBackgroundColor( backgroundColor )
121  {}
122 
123  QString name() const { return mName; }
124  void setName( const QString &name ) { mName = name; }
125 
126  QString displayName() const { return mDisplayName; }
127  void setDisplayName( const QString &displayName ) { mDisplayName = displayName; }
128 
129  Type type() const { return mType; }
130  void setType( Type type ) { mType = type; }
131 
132  operator QVariant() { return QVariant::fromValue<DnDTreeItemData>( *this ); }
133 
134  int columnCount() const { return mColumnCount; }
135  void setColumnCount( int count ) { mColumnCount = count; }
136 
137  bool showAsGroupBox() const;
138  void setShowAsGroupBox( bool showAsGroupBox );
139 
148  bool collapsed() const { return mCollapsed; };
149 
157  void setCollapsed( bool collapsed ) { mCollapsed = collapsed; };
158 
164  const QgsAttributeEditorElement::LabelStyle labelStyle() const;
165 
171  void setLabelStyle( const QgsAttributeEditorElement::LabelStyle &labelStyle );
172 
173  bool showLabel() const;
174  void setShowLabel( bool showLabel );
175 
176  QgsOptionalExpression visibilityExpression() const;
177 
184  void setVisibilityExpression( const QgsOptionalExpression &visibilityExpression );
185 
194  QgsOptionalExpression collapsedExpression() const;
195 
204  void setCollapsedExpression( const QgsOptionalExpression &collapsedExpression );
205 
206  RelationEditorConfiguration relationEditorConfiguration() const;
207  void setRelationEditorConfiguration( RelationEditorConfiguration relationEditorConfiguration );
208 
209  QmlElementEditorConfiguration qmlElementEditorConfiguration() const;
210  void setQmlElementEditorConfiguration( QmlElementEditorConfiguration qmlElementEditorConfiguration );
211 
212  HtmlElementEditorConfiguration htmlElementEditorConfiguration() const;
213  void setHtmlElementEditorConfiguration( HtmlElementEditorConfiguration htmlElementEditorConfiguration );
214 
215  QColor backgroundColor() const;
216  void setBackgroundColor( const QColor &backgroundColor );
217 
218  private:
219  Type mType = Field;
220  QString mName;
221  QString mDisplayName;
222  int mColumnCount = 1;
223  bool mShowAsGroupBox = false;
224  bool mShowLabel = true;
225  QgsOptionalExpression mVisibilityExpression;
226  RelationEditorConfiguration mRelationEditorConfiguration;
227  QmlElementEditorConfiguration mQmlElementEditorConfiguration;
228  HtmlElementEditorConfiguration mHtmlElementEditorConfiguration;
229  QColor mBackgroundColor;
230  bool mCollapsed = false;
231  QgsOptionalExpression mCollapsedExpression;
233  };
234 
235 
239  struct FieldConfig
240  {
241  FieldConfig() = default;
242  FieldConfig( QgsVectorLayer *layer, int idx );
243 
244  bool mEditable = true;
245  bool mEditableEnabled = true;
246  bool mLabelOnTop = false;
247  bool mReuseLastValues = false;
249  QPushButton *mButton = nullptr;
251  QMap<QString, QVariant> mEditorWidgetConfig;
252  QString mAlias;
254  QString mComment;
255 
256  operator QVariant();
257  };
258 
259  public:
260  explicit QgsAttributesFormProperties( QgsVectorLayer *layer, QWidget *parent = nullptr );
261 
262  QgsAttributeEditorElement *createAttributeEditorWidget( QTreeWidgetItem *item, QgsAttributeEditorElement *parent, bool forceGroup = true );
263 
264  void init();
265  void apply();
266 
267 
268  void loadRelations();
269 
270  void initAvailableWidgetsTree();
271  void initFormLayoutTree();
272  void initLayoutConfig();
273  void initInitPython();
274  void initSuppressCombo();
275 
277 
278  protected:
279  void updateButtons();
280 
281  //QList<QgsRelation> mRelations;
282  QgsVectorLayer *mLayer = nullptr;
283 
284  QgsAttributesDnDTree *mAvailableWidgetsTree = nullptr;
285  QgsAttributesDnDTree *mFormLayoutTree = nullptr;
286 
287  QgsAttributeWidgetEdit *mAttributeWidgetEdit = nullptr;
288  QgsAttributeTypeDialog *mAttributeTypeDialog = nullptr;
289  QgsAttributeFormContainerEdit *mAttributeContainerEdit = nullptr;
290  QLabel *mInfoTextWidget = nullptr;
291 
292  private slots:
293 
294  void onInvertSelectionButtonClicked( bool checked );
295  void loadAttributeSpecificEditor( QgsAttributesDnDTree *emitter, QgsAttributesDnDTree *receiver );
296  void onAttributeSelectionChanged();
297  void onFormLayoutSelectionChanged();
298 
299  private:
301  void clearAttributeTypeFrame();
302 
303  void loadAttributeWidgetEdit();
304  void storeAttributeWidgetEdit();
305 
306  void loadAttributeTypeDialog();
307  void storeAttributeTypeDialog( );
308 
309  void storeAttributeContainerEdit();
310  void loadAttributeContainerEdit();
311 
312  void loadInfoWidget( const QString &infoText );
313 
314  QTreeWidgetItem *loadAttributeEditorTreeItem( QgsAttributeEditorElement *widgetDef, QTreeWidgetItem *parent, QgsAttributesDnDTree *tree );
315 
317  QString mInitFunction;
318  QString mInitFilePath;
319  QString mInitCode;
320 
321  private slots:
322  void addTabOrGroupButton();
323  void removeTabOrGroupButton();
324  void mEditorLayoutComboBox_currentIndexChanged( int index );
325  void pbnSelectEditForm_clicked();
326  void mTbInitCode_clicked();
327 };
328 
329 
330 QDataStream &operator<< ( QDataStream &stream, const QgsAttributesFormProperties::DnDTreeItemData &data );
331 QDataStream &operator>> ( QDataStream &stream, QgsAttributesFormProperties::DnDTreeItemData &data );
332 
333 
345 class GUI_EXPORT QgsAttributesDnDTree : public QTreeWidget
346 {
347  Q_OBJECT
348 
349  public:
350  explicit QgsAttributesDnDTree( QgsVectorLayer *layer, QWidget *parent = nullptr );
351 
356  QTreeWidgetItem *addItem( QTreeWidgetItem *parent, QgsAttributesFormProperties::DnDTreeItemData data, int index = -1, const QIcon &icon = QIcon() );
357  QTreeWidgetItem *addContainer( QTreeWidgetItem *parent, const QString &title, int columnCount );
358 
359  enum Type
360  {
362  Drop
363  };
364 
365 
366  Type type() const;
367  void setType( QgsAttributesDnDTree::Type value );
368 
369  public slots:
370  void selectFirstMatchingItem( const QgsAttributesFormProperties::DnDTreeItemData &data );
371 
372  protected:
373  void dragMoveEvent( QDragMoveEvent *event ) override;
374  void dropEvent( QDropEvent *event ) override;
375  bool dropMimeData( QTreeWidgetItem *parent, int index, const QMimeData *data, Qt::DropAction action ) override;
376  /* Qt::DropActions supportedDropActions() const;*/
377 
378  // QTreeWidget interface
379  protected:
380  QStringList mimeTypes() const override;
381 
382 #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
383  QMimeData *mimeData( const QList<QTreeWidgetItem *> items ) const override;
384 #else
385  QMimeData *mimeData( const QList<QTreeWidgetItem *> &items ) const override;
386 #endif
387 
388  private slots:
389  void onItemDoubleClicked( QTreeWidgetItem *item, int column );
390 
391  private:
392  QgsVectorLayer *mLayer = nullptr;
393  Type mType = QgsAttributesDnDTree::Type::Drag;
394 };
395 
396 
400 
401 #endif // QGSATTRIBUTESFORMPROPERTIES_H
QgsAttributeEditorElement
This is an abstract base class for any elements of a drag and drop form.
Definition: qgsattributeeditorelement.h:37
QgsExpressionContext
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
Definition: qgsexpressioncontext.h:406
QgsAttributesFormProperties::DnDTreeItemData::DnDTreeItemData
DnDTreeItemData(Type type, const QString &name, const QString &displayName, const QColor &backgroundColor=QColor())
Definition: qgsattributesformproperties.h:116
qgsattributesforminitcode.h
qgsfieldcalculator.h
QgsAttributesFormProperties::FieldConfig
Holds the configuration for a field.
Definition: qgsattributesformproperties.h:239
QgsAttributesFormProperties::DnDTreeItemData::WidgetType
@ WidgetType
In the widget tree, the type of widget.
Definition: qgsattributesformproperties.h:109
QgsAttributeEditorElement::LabelStyle
The TabStyle struct defines color and font overrides for form fields, tabs and groups labels.
Definition: qgsattributeeditorelement.h:82
QgsEditFormConfig::PythonInitCodeSource
PythonInitCodeSource
The Python init code source options.
Definition: qgseditformconfig.h:95
QgsAttributesFormProperties::DnDTreeItemData::setName
void setName(const QString &name)
Definition: qgsattributesformproperties.h:124
QgsAttributesFormProperties
Definition: qgsattributesformproperties.h:61
QgsFieldConstraints
Stores information about constraints which may be present on a field.
Definition: qgsfieldconstraints.h:32
qgsattributeeditorrelation.h
qgsgui.h
QgsAttributesFormProperties::DnDTreeItemData::QmlWidget
@ QmlWidget
Definition: qgsattributesformproperties.h:107
QgsAttributesFormProperties::DnDTreeItemData::HtmlWidget
@ HtmlWidget
Definition: qgsattributesformproperties.h:108
QgsAttributesFormProperties::FieldNameRole
@ FieldNameRole
Definition: qgsattributesformproperties.h:71
QgsAttributesFormProperties::DnDTreeItemData::displayName
QString displayName() const
Definition: qgsattributesformproperties.h:126
QgsAttributesFormProperties::QmlElementEditorConfiguration
Definition: qgsattributesformproperties.h:85
QgsEditFormConfig::CodeSourceNone
@ CodeSourceNone
Do not use Python code at all.
Definition: qgseditformconfig.h:97
QgsAttributesDnDTree::Type
Type
Definition: qgsattributesformproperties.h:359
operator>>
QDataStream & operator>>(QDataStream &stream, QgsAttributesFormProperties::DnDTreeItemData &data)
Definition: qgsattributesformproperties.cpp:1514
QgsAttributesFormProperties::FieldPropertiesRoles
FieldPropertiesRoles
Definition: qgsattributesformproperties.h:67
QgsAttributesFormProperties::FieldConfig::mDataDefinedProperties
QgsPropertyCollection mDataDefinedProperties
Definition: qgsattributesformproperties.h:253
QgsAttributesDnDTree::Drag
@ Drag
Definition: qgsattributesformproperties.h:361
QgsAttributesFormProperties::DnDTreeItemData
Definition: qgsattributesformproperties.h:99
QgsAttributesFormProperties::FieldConfig::mEditorWidgetType
QString mEditorWidgetType
Definition: qgsattributesformproperties.h:250
QgsAttributesFormProperties::HtmlElementEditorConfiguration
Definition: qgsattributesformproperties.h:90
QgsAttributesFormProperties::DnDTreeItemData::setCollapsed
void setCollapsed(bool collapsed)
For group box containers sets if this group box is collapsed.
Definition: qgsattributesformproperties.h:157
QgsAttributesFormProperties::DnDTreeItemData::name
QString name() const
Definition: qgsattributesformproperties.h:123
qgsaddattrdialog.h
QgsAttributesFormProperties::RelationEditorConfiguration::nmRelationId
QVariant nmRelationId
Definition: qgsattributesformproperties.h:80
QgsAttributesFormProperties::QmlElementEditorConfiguration::qmlCode
QString qmlCode
Definition: qgsattributesformproperties.h:87
QgsAttributesFormProperties::FieldConfig::mFieldConstraints
QgsFieldConstraints mFieldConstraints
Definition: qgsattributesformproperties.h:248
operator<<
QDataStream & operator<<(QDataStream &stream, const QgsAttributesFormProperties::DnDTreeItemData &data)
Definition: qgsattributesformproperties.cpp:1508
QgsExpressionContextGenerator::createExpressionContext
virtual QgsExpressionContext createExpressionContext() const =0
This method needs to be reimplemented in all classes which implement this interface and return an exp...
QgsAttributesFormProperties::HtmlElementEditorConfiguration::htmlCode
QString htmlCode
Definition: qgsattributesformproperties.h:92
QgsOptionalExpression
An expression with an additional enabled flag.
Definition: qgsoptionalexpression.h:39
qgsrelationmanager.h
QgsAttributesFormProperties::FieldConfigRole
@ FieldConfigRole
Definition: qgsattributesformproperties.h:70
QgsAttributesFormProperties::DnDTreeItemData::type
Type type() const
Definition: qgsattributesformproperties.h:129
QgsAttributesFormProperties::DnDTreeItemData::collapsed
bool collapsed() const
For group box containers returns if this group box is collapsed.
Definition: qgsattributesformproperties.h:148
QgsPropertyCollection
A grouped map of multiple QgsProperty objects, each referenced by a integer key value.
Definition: qgspropertycollection.h:318
QgsAttributesDnDTree
This class overrides mime type handling to be able to work with the drag and drop attribute editor.
Definition: qgsattributesformproperties.h:345
QgsAttributesFormProperties::DnDTreeItemData::setType
void setType(Type type)
Definition: qgsattributesformproperties.h:130
qgseditorwidgetregistry.h
QgsAttributesFormProperties::DnDTreeItemData::Relation
@ Relation
Definition: qgsattributesformproperties.h:105
QgsAttributesFormProperties::DnDTreeItemData::Container
@ Container
Container for the form.
Definition: qgsattributesformproperties.h:106
QgsVectorLayer
Represents a vector layer which manages a vector based data sets.
Definition: qgsvectorlayer.h:391
qgseditorwidgetfactory.h
QgsAttributesFormProperties::FieldConfig::mAlias
QString mAlias
Definition: qgsattributesformproperties.h:252
QgsAttributesFormProperties::RelationEditorConfiguration
Definition: qgsattributesformproperties.h:74
QgsAttributesFormProperties::RelationEditorConfiguration::mRelationWidgetConfig
QVariantMap mRelationWidgetConfig
Definition: qgsattributesformproperties.h:79
QgsAttributesFormProperties::DnDTreeItemData::Type
Type
Definition: qgsattributesformproperties.h:102
QgsAttributesFormProperties::DnDTreeItemData::columnCount
int columnCount() const
Definition: qgsattributesformproperties.h:134
Q_DECLARE_METATYPE
Q_DECLARE_METATYPE(QgsDatabaseQueryLogEntry)
QgsAttributesFormProperties::RelationEditorConfiguration::mRelationWidgetType
QString mRelationWidgetType
Definition: qgsattributesformproperties.h:78
QgsAttributesFormProperties::RelationEditorConfiguration::label
QString label
Definition: qgsattributesformproperties.h:82
qgsfieldexpressionwidget.h
QgsAttributesFormProperties::DnDTreeItemData::setDisplayName
void setDisplayName(const QString &displayName)
Definition: qgsattributesformproperties.h:127
qgslogger.h
QgsAttributesFormProperties::FieldConfig::mComment
QString mComment
Definition: qgsattributesformproperties.h:254
QgsExpressionContextGenerator
Abstract interface for generating an expression context.
Definition: qgsexpressioncontextgenerator.h:36
QgsAttributesFormProperties::DnDTreeItemData::setColumnCount
void setColumnCount(int count)
Definition: qgsattributesformproperties.h:135
QgsAttributesFormProperties::FieldConfig::mEditorWidgetConfig
QMap< QString, QVariant > mEditorWidgetConfig
Definition: qgsattributesformproperties.h:251
qgsexpressionbuilderdialog.h
QgsAttributesFormProperties::DnDTreeItemData::Field
@ Field
Definition: qgsattributesformproperties.h:104