-
-
Notifications
You must be signed in to change notification settings - Fork 3k
/
qgsattributesformproperties.h
316 lines (245 loc) · 9.92 KB
/
qgsattributesformproperties.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
/***************************************************************************
qgsattributesformproperties.h
---------------------
begin : August 2017
copyright : (C) 2017 by David Signer
email : david at opengis dot ch
***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
#ifndef QGSATTRIBUTESFORMPROPERTIES_H
#define QGSATTRIBUTESFORMPROPERTIES_H
// We don't want to expose this in the public API
#define SIP_NO_FILE
#include <QMimeData>
#include <QPushButton>
#include <QTableWidget>
#include <QTreeWidget>
#include <QWidget>
#include <QSpinBox>
#include <QTreeWidgetItem>
#include <QDropEvent>
#include <QTableWidgetItem>
#include <QMessageBox>
#include <QFileDialog>
#include <QHBoxLayout>
#include <QFormLayout>
#include <QPlainTextEdit>
#include "ui_qgsattributesformproperties.h"
#include "qgis_gui.h"
#include "qgsaddattrdialog.h"
#include "qgslogger.h"
#include "qgsexpressionbuilderdialog.h"
#include "qgsfieldcalculator.h"
#include "qgsfieldexpressionwidget.h"
#include "qgsattributesforminitcode.h"
#include "qgsgui.h"
#include "qgseditorwidgetfactory.h"
#include "qgseditorwidgetregistry.h"
#include "qgsrelationmanager.h"
class QgsAttributesDnDTree;
class QgsAttributeFormContainerEdit;
class QgsAttributeTypeDialog;
class QgsAttributeWidgetEdit;
class GUI_EXPORT QgsAttributesFormProperties : public QWidget, public QgsExpressionContextGenerator, private Ui_QgsAttributesFormProperties
{
Q_OBJECT
public:
enum FieldPropertiesRoles
{
DnDTreeRole = Qt::UserRole,
FieldConfigRole,
FieldNameRole
};
struct RelationEditorConfiguration
{
QgsAttributeEditorRelation::Buttons buttons = QgsAttributeEditorRelation::Button::AllButtons;
QVariant nmRelationId;
bool forceSuppressFormPopup = false;
QString label;
};
struct QmlElementEditorConfiguration
{
QString qmlCode;
};
struct HtmlElementEditorConfiguration
{
QString htmlCode;
};
class DnDTreeItemData : public QTreeWidgetItem
{
public:
enum Type
{
Field,
Relation,
Container, //!< Container for the form
QmlWidget,
HtmlWidget,
WidgetType //!< In the widget tree, the type of widget
};
//do we need that
DnDTreeItemData() = default;
DnDTreeItemData( Type type, const QString &name, const QString &displayName, const QColor &backgroundColor = QColor() )
: mType( type )
, mName( name )
, mDisplayName( displayName )
, mBackgroundColor( backgroundColor )
{}
QString name() const { return mName; }
void setName( const QString &name ) { mName = name; }
QString displayName() const { return mDisplayName; }
void setDisplayName( const QString &displayName ) { mDisplayName = displayName; }
Type type() const { return mType; }
void setType( Type type ) { mType = type; }
operator QVariant() { return QVariant::fromValue<DnDTreeItemData>( *this ); }
int columnCount() const { return mColumnCount; }
void setColumnCount( int count ) { mColumnCount = count; }
bool showAsGroupBox() const;
void setShowAsGroupBox( bool showAsGroupBox );
bool showLabel() const;
void setShowLabel( bool showLabel );
QgsOptionalExpression visibilityExpression() const;
void setVisibilityExpression( const QgsOptionalExpression &visibilityExpression );
RelationEditorConfiguration relationEditorConfiguration() const;
void setRelationEditorConfiguration( RelationEditorConfiguration relationEditorConfiguration );
QmlElementEditorConfiguration qmlElementEditorConfiguration() const;
void setQmlElementEditorConfiguration( QmlElementEditorConfiguration qmlElementEditorConfiguration );
HtmlElementEditorConfiguration htmlElementEditorConfiguration() const;
void setHtmlElementEditorConfiguration( HtmlElementEditorConfiguration htmlElementEditorConfiguration );
QColor backgroundColor() const;
void setBackgroundColor( const QColor &backgroundColor );
private:
Type mType = Field;
QString mName;
QString mDisplayName;
int mColumnCount = 1;
bool mShowAsGroupBox = false;
bool mShowLabel = true;
QgsOptionalExpression mVisibilityExpression;
RelationEditorConfiguration mRelationEditorConfiguration;
QmlElementEditorConfiguration mQmlElementEditorConfiguration;
HtmlElementEditorConfiguration mHtmlElementEditorConfiguration;
QColor mBackgroundColor;
};
/**
* Holds the configuration for a field
*/
struct FieldConfig
{
FieldConfig() = default;
FieldConfig( QgsVectorLayer *layer, int idx );
bool mEditable = true ;
bool mEditableEnabled = true ;
bool mLabelOnTop = false ;
QgsFieldConstraints mFieldConstraints;
QPushButton *mButton = nullptr;
QString mEditorWidgetType;
QMap<QString, QVariant> mEditorWidgetConfig;
QString mAlias;
QgsPropertyCollection mDataDefinedProperties;
QString mComment;
operator QVariant();
};
public:
explicit QgsAttributesFormProperties( QgsVectorLayer *layer, QWidget *parent = nullptr );
QgsAttributeEditorElement *createAttributeEditorWidget( QTreeWidgetItem *item, QgsAttributeEditorElement *parent, bool forceGroup = true );
void init();
void apply();
void loadRelations();
void initAvailableWidgetsTree();
void initFormLayoutTree();
void initLayoutConfig();
void initInitPython();
void initSuppressCombo();
QgsExpressionContext createExpressionContext() const override;
protected:
void updateButtons();
//QList<QgsRelation> mRelations;
QgsVectorLayer *mLayer = nullptr;
QgsAttributesDnDTree *mAvailableWidgetsTree = nullptr;
QgsAttributesDnDTree *mFormLayoutTree = nullptr;
QgsAttributeWidgetEdit *mAttributeWidgetEdit = nullptr;
QgsAttributeTypeDialog *mAttributeTypeDialog = nullptr;
QgsAttributeFormContainerEdit *mAttributeContainerEdit = nullptr;
QLabel *mInfoTextWidget = nullptr;
private slots:
void onInvertSelectionButtonClicked( bool checked );
void loadAttributeSpecificEditor( QgsAttributesDnDTree *emitter, QgsAttributesDnDTree *receiver );
void onAttributeSelectionChanged();
void onFormLayoutSelectionChanged();
private:
//! this will clean the right panel
void clearAttributeTypeFrame();
void loadAttributeWidgetEdit();
void storeAttributeWidgetEdit();
void loadAttributeTypeDialog();
void storeAttributeTypeDialog( );
void storeAttributeContainerEdit();
void loadAttributeContainerEdit();
void loadInfoWidget( const QString &infoText );
QgsEditFormConfig::PythonInitCodeSource mInitCodeSource = QgsEditFormConfig::CodeSourceNone;
QString mInitFunction;
QString mInitFilePath;
QString mInitCode;
QTreeWidgetItem *loadAttributeEditorTreeItem( QgsAttributeEditorElement *widgetDef, QTreeWidgetItem *parent, QgsAttributesDnDTree *tree );
private slots:
void addTabOrGroupButton();
void removeTabOrGroupButton();
void mEditorLayoutComboBox_currentIndexChanged( int index );
void pbnSelectEditForm_clicked();
void mTbInitCode_clicked();
};
QDataStream &operator<< ( QDataStream &stream, const QgsAttributesFormProperties::DnDTreeItemData &data );
QDataStream &operator>> ( QDataStream &stream, QgsAttributesFormProperties::DnDTreeItemData &data );
/**
* This class overrides mime type handling to be able to work with
* the drag and drop attribute editor.
*
* The mime type is application/x-qgsattributetablefield
*
* Graphical representation for the attribute editor drag and drop editor
*/
class GUI_EXPORT QgsAttributesDnDTree : public QTreeWidget
{
Q_OBJECT
public:
explicit QgsAttributesDnDTree( QgsVectorLayer *layer, QWidget *parent = nullptr );
/**
* Adds a new item to a \a parent. If \a index is -1, the item is added to the end of the parent's existing children.
* Otherwise it is inserted at the specified \a index.
*/
QTreeWidgetItem *addItem( QTreeWidgetItem *parent, QgsAttributesFormProperties::DnDTreeItemData data, int index = -1 );
QTreeWidgetItem *addContainer( QTreeWidgetItem *parent, const QString &title, int columnCount );
enum Type
{
Drag,
Drop
};
Type type() const;
void setType( QgsAttributesDnDTree::Type value );
public slots:
void selectFirstMatchingItem( const QgsAttributesFormProperties::DnDTreeItemData &data );
protected:
void dragMoveEvent( QDragMoveEvent *event ) override;
void dropEvent( QDropEvent *event ) override;
bool dropMimeData( QTreeWidgetItem *parent, int index, const QMimeData *data, Qt::DropAction action ) override;
/* Qt::DropActions supportedDropActions() const;*/
// QTreeWidget interface
protected:
QStringList mimeTypes() const override;
QMimeData *mimeData( const QList<QTreeWidgetItem *> items ) const override;
private slots:
void onItemDoubleClicked( QTreeWidgetItem *item, int column );
private:
QgsVectorLayer *mLayer = nullptr;
Type mType = QgsAttributesDnDTree::Type::Drag;
};
Q_DECLARE_METATYPE( QgsAttributesFormProperties::FieldConfig )
Q_DECLARE_METATYPE( QgsAttributesFormProperties::DnDTreeItemData )
#endif // QGSATTRIBUTESFORMPROPERTIES_H