QGIS API Documentation  3.24.2-Tisler (13c1a02865)
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 
140  bool showLabel() const;
141  void setShowLabel( bool showLabel );
142 
143  QgsOptionalExpression visibilityExpression() const;
144  void setVisibilityExpression( const QgsOptionalExpression &visibilityExpression );
145 
146  RelationEditorConfiguration relationEditorConfiguration() const;
147  void setRelationEditorConfiguration( RelationEditorConfiguration relationEditorConfiguration );
148 
149  QmlElementEditorConfiguration qmlElementEditorConfiguration() const;
150  void setQmlElementEditorConfiguration( QmlElementEditorConfiguration qmlElementEditorConfiguration );
151 
152  HtmlElementEditorConfiguration htmlElementEditorConfiguration() const;
153  void setHtmlElementEditorConfiguration( HtmlElementEditorConfiguration htmlElementEditorConfiguration );
154 
155  QColor backgroundColor() const;
156  void setBackgroundColor( const QColor &backgroundColor );
157 
158  private:
159  Type mType = Field;
160  QString mName;
161  QString mDisplayName;
162  int mColumnCount = 1;
163  bool mShowAsGroupBox = false;
164  bool mShowLabel = true;
165  QgsOptionalExpression mVisibilityExpression;
166  RelationEditorConfiguration mRelationEditorConfiguration;
167  QmlElementEditorConfiguration mQmlElementEditorConfiguration;
168  HtmlElementEditorConfiguration mHtmlElementEditorConfiguration;
169  QColor mBackgroundColor;
170  };
171 
172 
176  struct FieldConfig
177  {
178  FieldConfig() = default;
179  FieldConfig( QgsVectorLayer *layer, int idx );
180 
181  bool mEditable = true;
182  bool mEditableEnabled = true;
183  bool mLabelOnTop = false;
184  bool mReuseLastValues = false;
186  QPushButton *mButton = nullptr;
188  QMap<QString, QVariant> mEditorWidgetConfig;
189  QString mAlias;
191  QString mComment;
192 
193  operator QVariant();
194  };
195 
196  public:
197  explicit QgsAttributesFormProperties( QgsVectorLayer *layer, QWidget *parent = nullptr );
198 
199  QgsAttributeEditorElement *createAttributeEditorWidget( QTreeWidgetItem *item, QgsAttributeEditorElement *parent, bool forceGroup = true );
200 
201  void init();
202  void apply();
203 
204 
206 
207  void initAvailableWidgetsTree();
208  void initFormLayoutTree();
209  void initLayoutConfig();
210  void initInitPython();
211  void initSuppressCombo();
212 
214 
215  protected:
217 
218  //QList<QgsRelation> mRelations;
219  QgsVectorLayer *mLayer = nullptr;
220 
221  QgsAttributesDnDTree *mAvailableWidgetsTree = nullptr;
222  QgsAttributesDnDTree *mFormLayoutTree = nullptr;
223 
224  QgsAttributeWidgetEdit *mAttributeWidgetEdit = nullptr;
225  QgsAttributeTypeDialog *mAttributeTypeDialog = nullptr;
226  QgsAttributeFormContainerEdit *mAttributeContainerEdit = nullptr;
227  QLabel *mInfoTextWidget = nullptr;
228 
229  private slots:
230 
231  void onInvertSelectionButtonClicked( bool checked );
232  void loadAttributeSpecificEditor( QgsAttributesDnDTree *emitter, QgsAttributesDnDTree *receiver );
233  void onAttributeSelectionChanged();
234  void onFormLayoutSelectionChanged();
235 
236  private:
238  void clearAttributeTypeFrame();
239 
240  void loadAttributeWidgetEdit();
241  void storeAttributeWidgetEdit();
242 
243  void loadAttributeTypeDialog();
244  void storeAttributeTypeDialog( );
245 
246  void storeAttributeContainerEdit();
247  void loadAttributeContainerEdit();
248 
249  void loadInfoWidget( const QString &infoText );
250 
252  QString mInitFunction;
253  QString mInitFilePath;
254  QString mInitCode;
255 
256  QTreeWidgetItem *loadAttributeEditorTreeItem( QgsAttributeEditorElement *widgetDef, QTreeWidgetItem *parent, QgsAttributesDnDTree *tree );
257 
258  private slots:
259  void addTabOrGroupButton();
260  void removeTabOrGroupButton();
261  void mEditorLayoutComboBox_currentIndexChanged( int index );
262  void pbnSelectEditForm_clicked();
263  void mTbInitCode_clicked();
264 };
265 
266 
267 QDataStream &operator<< ( QDataStream &stream, const QgsAttributesFormProperties::DnDTreeItemData &data );
268 QDataStream &operator>> ( QDataStream &stream, QgsAttributesFormProperties::DnDTreeItemData &data );
269 
270 
282 class GUI_EXPORT QgsAttributesDnDTree : public QTreeWidget
283 {
284  Q_OBJECT
285 
286  public:
287  explicit QgsAttributesDnDTree( QgsVectorLayer *layer, QWidget *parent = nullptr );
288 
293  QTreeWidgetItem *addItem( QTreeWidgetItem *parent, QgsAttributesFormProperties::DnDTreeItemData data, int index = -1, const QIcon &icon = QIcon() );
294  QTreeWidgetItem *addContainer( QTreeWidgetItem *parent, const QString &title, int columnCount );
295 
296  enum Type
297  {
299  Drop
300  };
301 
302 
303  Type type() const;
304  void setType( QgsAttributesDnDTree::Type value );
305 
306  public slots:
307  void selectFirstMatchingItem( const QgsAttributesFormProperties::DnDTreeItemData &data );
308 
309  protected:
310  void dragMoveEvent( QDragMoveEvent *event ) override;
311  void dropEvent( QDropEvent *event ) override;
312  bool dropMimeData( QTreeWidgetItem *parent, int index, const QMimeData *data, Qt::DropAction action ) override;
313  /* Qt::DropActions supportedDropActions() const;*/
314 
315  // QTreeWidget interface
316  protected:
317  QStringList mimeTypes() const override;
318 
319 #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
320  QMimeData *mimeData( const QList<QTreeWidgetItem *> items ) const override;
321 #else
322  QMimeData *mimeData( const QList<QTreeWidgetItem *> &items ) const override;
323 #endif
324 
325  private slots:
326  void onItemDoubleClicked( QTreeWidgetItem *item, int column );
327 
328  private:
329  QgsVectorLayer *mLayer = nullptr;
330  Type mType = QgsAttributesDnDTree::Type::Drag;
331 };
332 
333 
337 
338 #endif // QGSATTRIBUTESFORMPROPERTIES_H
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.
DnDTreeItemData(Type type, const QString &name, const QString &displayName, const QColor &backgroundColor=QColor())
@ WidgetType
In the widget tree, the type of widget.
PythonInitCodeSource
The Python init code source options.
@ CodeSourceNone
Do not use Python code at all.
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, const QgsAttributesFormProperties::DnDTreeItemData &data)
QDataStream & operator>>(QDataStream &stream, QgsAttributesFormProperties::DnDTreeItemData &data)
Q_DECLARE_METATYPE(QgsMeshTimeSettings)