-
-
Notifications
You must be signed in to change notification settings - Fork 3k
/
qgsattributesformproperties.h
284 lines (222 loc) · 8.34 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
/***************************************************************************
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
#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 "qgsvectorlayer.h"
#include "ui_qgsattributesformproperties.h"
#include "qgis_app.h"
#include "qgsaddattrdialog.h"
#include "qgslogger.h"
#include "qgsproject.h"
#include "qgsexpressionbuilderdialog.h"
#include "qgsfieldcalculator.h"
#include "qgsfieldexpressionwidget.h"
#include "qgsaddtaborgroup.h"
#include "qgsattributetypedialog.h"
#include "qgsattributerelationedit.h"
#include "qgsattributesforminitcode.h"
#include "qgsgui.h"
#include "qgseditorwidgetfactory.h"
#include "qgseditorwidgetregistry.h"
#include "qgsrelationmanager.h"
class DnDTree;
class APP_EXPORT QgsAttributesFormProperties : public QWidget, private Ui_QgsAttributesFormProperties
{
Q_OBJECT
public:
enum FieldPropertiesRoles
{
DnDTreeRole = Qt::UserRole,
FieldConfigRole,
RelationConfigRole,
FieldNameRole
};
struct RelationEditorConfiguration
{
bool showLinkButton = true;
bool showUnlinkButton = true;
};
class DnDTreeItemData : public QTreeWidgetItem
{
public:
enum Type
{
Field,
Relation,
Container
};
//do we need that
DnDTreeItemData() = default;
DnDTreeItemData( Type type, const QString &name )
: mType( type )
, mName( name )
, mColumnCount( 1 )
, mShowAsGroupBox( false )
, mShowLabel( true )
{}
QString name() const { return mName; }
void setName( const QString &name ) { mName = name; }
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 );
private:
Type mType = Field;
QString mName;
int mColumnCount = 1;
bool mShowAsGroupBox = false;
bool mShowLabel = true;
QgsOptionalExpression mVisibilityExpression;
RelationEditorConfiguration mRelationEditorConfiguration;
};
/**
* 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;
QgsFieldConstraints::Constraints mConstraints = nullptr;
QHash< QgsFieldConstraints::Constraint, QgsFieldConstraints::ConstraintStrength > mConstraintStrength;
QString mConstraint;
QString mConstraintDescription;
QPushButton *mButton = nullptr;
QString mEditorWidgetType;
QMap<QString, QVariant> mEditorWidgetConfig;
QString mAlias;
QString mComment;
operator QVariant();
};
/**
* Holds the configuration for a relation
*/
struct RelationConfig
{
RelationConfig();
RelationConfig( QgsVectorLayer *layer, const QString &relationId );
QVariant mCardinality;
operator QVariant();
};
public:
explicit QgsAttributesFormProperties( QgsVectorLayer *layer, QWidget *parent = nullptr );
QgsAttributeEditorElement *createAttributeEditorWidget( QTreeWidgetItem *item, QgsAttributeEditorElement *parent, bool forceGroup = true );
void init();
void apply();
void onAttributeSelectionChanged();
void loadRelations();
void initAvailableWidgetsTree();
void initFormLayoutTree();
void initLayoutConfig();
void initInitPython();
void initSuppressCombo();
protected:
void updateButtons();
RelationConfig configForRelation( const QString &relationName );
//QList<QgsRelation> mRelations;
QgsVectorLayer *mLayer = nullptr;
DnDTree *mAvailableWidgetsTree = nullptr;
DnDTree *mFormLayoutTree = nullptr;
QgsAttributeTypeDialog *mAttributeTypeDialog = nullptr;
QgsAttributeRelationEdit *mAttributeRelationEdit = nullptr;
private:
void loadAttributeTypeDialog();
void storeAttributeTypeDialog( );
void loadAttributeRelationEdit();
void storeAttributeRelationEdit( );
QgsEditFormConfig::PythonInitCodeSource mInitCodeSource = QgsEditFormConfig::CodeSourceNone;
QString mInitFunction;
QString mInitFilePath;
QString mInitCode;
QTreeWidgetItem *loadAttributeEditorTreeItem( QgsAttributeEditorElement *const widgetDef, QTreeWidgetItem *parent, DnDTree *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 DnDTree : public QTreeWidget
{
Q_OBJECT
public:
explicit DnDTree( 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( const Type &value );
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 = DnDTree::Type::Drag;
};
Q_DECLARE_METATYPE( QgsAttributesFormProperties::FieldConfig )
Q_DECLARE_METATYPE( QgsAttributesFormProperties::RelationConfig )
Q_DECLARE_METATYPE( QgsAttributesFormProperties::DnDTreeItemData )
#endif // QGSATTRIBUTESFORMPROPERTIES_H