QGIS API Documentation 3.30.0-'s-Hertogenbosch (f186b8efe0)
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"
48#include "qgsrelationmanager.h"
50
51
53class QgsAttributeFormContainerEdit;
54class QgsAttributeTypeDialog;
55class QgsAttributeWidgetEdit;
56
61class 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
80 QVariant nmRelationId;
81 bool forceSuppressFormPopup = false;
82 QString label;
83 };
84
86 {
87 QString qmlCode;
88 };
89
91 {
92 QString htmlCode;
93 };
94
96 {
97 QString text;
98 };
99
101 {
102 bool drawLine = false;
103 };
104
109 class DnDTreeItemData : public QTreeWidgetItem
110 {
111 public:
112 enum Type
113 {
123 };
124
125 //do we need that
126 DnDTreeItemData() = default;
127
128 DnDTreeItemData( Type type, const QString &name, const QString &displayName, const QColor &backgroundColor = QColor() )
129 : mType( type )
130 , mName( name )
131 , mDisplayName( displayName )
132 , mBackgroundColor( backgroundColor )
133 {}
134
135 QString name() const { return mName; }
136 void setName( const QString &name ) { mName = name; }
137
138 QString displayName() const { return mDisplayName; }
139 void setDisplayName( const QString &displayName ) { mDisplayName = displayName; }
140
141 Type type() const { return mType; }
142 void setType( Type type ) { mType = type; }
143
144 operator QVariant() { return QVariant::fromValue<DnDTreeItemData>( *this ); }
145
146 int columnCount() const { return mColumnCount; }
147 void setColumnCount( int count ) { mColumnCount = count; }
148
149 bool showAsGroupBox() const;
150 void setShowAsGroupBox( bool showAsGroupBox );
151
160 bool collapsed() const { return mCollapsed; };
161
169 void setCollapsed( bool collapsed ) { mCollapsed = collapsed; };
170
176 const QgsAttributeEditorElement::LabelStyle labelStyle() const;
177
183 void setLabelStyle( const QgsAttributeEditorElement::LabelStyle &labelStyle );
184
185 bool showLabel() const;
186 void setShowLabel( bool showLabel );
187
188 QgsOptionalExpression visibilityExpression() const;
189
196 void setVisibilityExpression( const QgsOptionalExpression &visibilityExpression );
197
206 QgsOptionalExpression collapsedExpression() const;
207
216 void setCollapsedExpression( const QgsOptionalExpression &collapsedExpression );
217
218 RelationEditorConfiguration relationEditorConfiguration() const;
219 void setRelationEditorConfiguration( RelationEditorConfiguration relationEditorConfiguration );
220
221 QmlElementEditorConfiguration qmlElementEditorConfiguration() const;
222 void setQmlElementEditorConfiguration( QmlElementEditorConfiguration qmlElementEditorConfiguration );
223
224 HtmlElementEditorConfiguration htmlElementEditorConfiguration() const;
225 void setHtmlElementEditorConfiguration( HtmlElementEditorConfiguration htmlElementEditorConfiguration );
226
231 SpacerElementEditorConfiguration spacerElementEditorConfiguration() const;
232
237 void setSpacerElementEditorConfiguration( SpacerElementEditorConfiguration spacerElementEditorConfiguration );
238
239 QColor backgroundColor() const;
240 void setBackgroundColor( const QColor &backgroundColor );
241
246 TextElementEditorConfiguration textElementEditorConfiguration() const;
247
252 void setTextElementEditorConfiguration( const TextElementEditorConfiguration &textElementEditorConfiguration );
253
254 private:
255 Type mType = Field;
256 QString mName;
257 QString mDisplayName;
258 int mColumnCount = 1;
259 bool mShowAsGroupBox = false;
260 bool mShowLabel = true;
261 QgsOptionalExpression mVisibilityExpression;
262 RelationEditorConfiguration mRelationEditorConfiguration;
263 QmlElementEditorConfiguration mQmlElementEditorConfiguration;
264 HtmlElementEditorConfiguration mHtmlElementEditorConfiguration;
265 TextElementEditorConfiguration mTextElementEditorConfiguration;
266 SpacerElementEditorConfiguration mSpacerElementEditorConfiguration;
267 QColor mBackgroundColor;
268 bool mCollapsed = false;
269 QgsOptionalExpression mCollapsedExpression;
271 };
272
273
278 {
279 FieldConfig() = default;
280 FieldConfig( QgsVectorLayer *layer, int idx );
281
282 bool mEditable = true;
283 bool mEditableEnabled = true;
284 bool mLabelOnTop = false;
285 bool mReuseLastValues = false;
287 QPushButton *mButton = nullptr;
289 QMap<QString, QVariant> mEditorWidgetConfig;
290 QString mAlias;
292 QString mComment;
293
294 operator QVariant();
295 };
296
297 public:
298 explicit QgsAttributesFormProperties( QgsVectorLayer *layer, QWidget *parent = nullptr );
299
300 QgsAttributeEditorElement *createAttributeEditorWidget( QTreeWidgetItem *item, QgsAttributeEditorElement *parent, bool forceGroup = true );
301
302 void init();
303 void apply();
304
305
307
308 void initAvailableWidgetsTree();
309 void initFormLayoutTree();
310 void initLayoutConfig();
311 void initInitPython();
312 void initSuppressCombo();
313
315
316 protected:
318
319 //QList<QgsRelation> mRelations;
320 QgsVectorLayer *mLayer = nullptr;
321
322 QgsAttributesDnDTree *mAvailableWidgetsTree = nullptr;
323 QgsAttributesDnDTree *mFormLayoutTree = nullptr;
324
325 QgsAttributeWidgetEdit *mAttributeWidgetEdit = nullptr;
326 QgsAttributeTypeDialog *mAttributeTypeDialog = nullptr;
327 QgsAttributeFormContainerEdit *mAttributeContainerEdit = nullptr;
328 QLabel *mInfoTextWidget = nullptr;
329
330 private slots:
331
332 void onInvertSelectionButtonClicked( bool checked );
333 void loadAttributeSpecificEditor( QgsAttributesDnDTree *emitter, QgsAttributesDnDTree *receiver );
334 void onAttributeSelectionChanged();
335 void onFormLayoutSelectionChanged();
336
337 private:
339 void clearAttributeTypeFrame();
340
341 void loadAttributeWidgetEdit();
342 void storeAttributeWidgetEdit();
343
344 void loadAttributeTypeDialog();
345 void storeAttributeTypeDialog( );
346
347 void storeAttributeContainerEdit();
348 void loadAttributeContainerEdit();
349
350 void loadInfoWidget( const QString &infoText );
351
352 QTreeWidgetItem *loadAttributeEditorTreeItem( QgsAttributeEditorElement *widgetDef, QTreeWidgetItem *parent, QgsAttributesDnDTree *tree );
353
355 QString mInitFunction;
356 QString mInitFilePath;
357 QString mInitCode;
358
359 private slots:
360 void addTabOrGroupButton();
361 void removeTabOrGroupButton();
362 void mEditorLayoutComboBox_currentIndexChanged( int index );
363 void pbnSelectEditForm_clicked();
364 void mTbInitCode_clicked();
365};
366
367
368QDataStream &operator<< ( QDataStream &stream, const QgsAttributesFormProperties::DnDTreeItemData &data );
369QDataStream &operator>> ( QDataStream &stream, QgsAttributesFormProperties::DnDTreeItemData &data );
370
371
383class GUI_EXPORT QgsAttributesDnDTree : public QTreeWidget, private QgsExpressionContextGenerator
384{
385 Q_OBJECT
386
387 public:
388 explicit QgsAttributesDnDTree( QgsVectorLayer *layer, QWidget *parent = nullptr );
389
394 QTreeWidgetItem *addItem( QTreeWidgetItem *parent, QgsAttributesFormProperties::DnDTreeItemData data, int index = -1, const QIcon &icon = QIcon() );
395 QTreeWidgetItem *addContainer( QTreeWidgetItem *parent, const QString &title, int columnCount );
396
397 enum Type
398 {
400 Drop
401 };
402
403
404 Type type() const;
405 void setType( QgsAttributesDnDTree::Type value );
406
407 public slots:
408 void selectFirstMatchingItem( const QgsAttributesFormProperties::DnDTreeItemData &data );
409
410 protected:
411 void dragMoveEvent( QDragMoveEvent *event ) override;
412 void dropEvent( QDropEvent *event ) override;
413 bool dropMimeData( QTreeWidgetItem *parent, int index, const QMimeData *data, Qt::DropAction action ) override;
414 /* Qt::DropActions supportedDropActions() const;*/
415
416 // QTreeWidget interface
417 protected:
418 QStringList mimeTypes() const override;
419
420#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
421 QMimeData *mimeData( const QList<QTreeWidgetItem *> items ) const override;
422#else
423 QMimeData *mimeData( const QList<QTreeWidgetItem *> &items ) const override;
424#endif
425
426 private slots:
427 void onItemDoubleClicked( QTreeWidgetItem *item, int column );
428
429 private:
430 QgsVectorLayer *mLayer = nullptr;
431 Type mType = QgsAttributesDnDTree::Type::Drag;
432
433 // QgsExpressionContextGenerator interface
434 public:
436};
437
438
442
443#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.
void setCollapsed(bool collapsed)
For group box containers sets if this group box is collapsed.
bool collapsed() const
For group box containers returns if this group box is collapsed.
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, 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.