-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathqgsfieldsproperties.h
314 lines (251 loc) · 9.17 KB
/
qgsfieldsproperties.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
/***************************************************************************
qgsfieldsproperties.h
---------------------
begin : September 2012
copyright : (C) 2012 by Matthias Kuhn
email : matthias 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 QGSFIELDSPROPERTIES_H
#define QGSFIELDSPROPERTIES_H
#include <QMimeData>
#include <QPushButton>
#include <QTableWidget>
#include <QTreeWidget>
#include <QWidget>
#include <QSpinBox>
#include "qgsvectorlayer.h"
#include "ui_qgsfieldspropertiesbase.h"
#include "qgis_app.h"
class DesignerTree;
class DragList;
class APP_EXPORT QgsFieldsProperties : public QWidget, private Ui_QgsFieldsPropertiesBase
{
Q_OBJECT
public:
enum FieldPropertiesRoles
{
DesignerTreeRole = Qt::UserRole,
FieldConfigRole
};
struct RelationEditorConfiguration
{
RelationEditorConfiguration()
: showLinkButton( true )
, showUnlinkButton( true )
{}
bool showLinkButton;
bool showUnlinkButton;
};
class DesignerTreeItemData
{
public:
enum Type
{
Field,
Relation,
Container
};
DesignerTreeItemData()
: mType( Field )
, mColumnCount( 1 )
, mShowAsGroupBox( false )
, mShowLabel( true )
{}
DesignerTreeItemData( 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; }
QVariant asQVariant() { return QVariant::fromValue<DesignerTreeItemData>( *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;
QString mName;
int mColumnCount;
bool mShowAsGroupBox;
bool mShowLabel;
QgsOptionalExpression mVisibilityExpression;
RelationEditorConfiguration mRelationEditorConfiguration;
};
/**
* Holds the configuration for a field
*/
class FieldConfig
{
public:
FieldConfig();
FieldConfig( QgsVectorLayer *layer, int idx );
bool mEditable;
bool mEditableEnabled;
bool mLabelOnTop;
QgsFieldConstraints::Constraints mConstraints;
QHash< QgsFieldConstraints::Constraint, QgsFieldConstraints::ConstraintStrength > mConstraintStrength;
QString mConstraint;
QString mConstraintDescription;
QPushButton *mButton = nullptr;
QString mEditorWidgetType;
QMap<QString, QVariant> mEditorWidgetConfig;
};
public:
QgsFieldsProperties( QgsVectorLayer *layer, QWidget *parent = nullptr );
~QgsFieldsProperties();
/** Adds an attribute to the table (but does not commit it yet)
@param field the field to add
@return false in case of a name conflict, true in case of success */
bool addAttribute( const QgsField &field );
/** Creates the a proper item to save from the tree
* @return A widget definition. Containing another container or the final field
*/
QgsAttributeEditorElement *createAttributeEditorWidget( QTreeWidgetItem *item, QgsAttributeEditorElement *parent, bool forceGroup = true );
void init();
void apply();
void loadRows();
void setRow( int row, int idx, const QgsField &field );
void loadRelations();
void loadAttributeEditorTree();
QTreeWidgetItem *loadAttributeEditorTreeItem( QgsAttributeEditorElement *const widgetDef, QTreeWidgetItem *parent );
/**
* @brief setEditFormInit set the private ui fields
* @param editForm
* @param initFunction
* @param initCode
* @param initFilePath
* @param codeSource
*/
void setEditFormInit( const QString &editForm,
const QString &initFunction,
const QString &initCode,
const QString &initFilePath,
QgsEditFormConfig::PythonInitCodeSource codeSource );
signals:
void toggleEditing();
private slots:
void on_mAddAttributeButton_clicked();
void on_mDeleteAttributeButton_clicked();
void on_mCalculateFieldButton_clicked();
void onAttributeSelectionChanged();
void on_pbtnSelectInitFilePath_clicked();
void on_pbnSelectEditForm_clicked();
void on_mEditorLayoutComboBox_currentIndexChanged( int index );
void on_mInitCodeSourceComboBox_currentIndexChanged( int codeSource );
void attributeAdded( int idx );
void attributeDeleted( int idx );
void attributeTypeDialog();
void on_mAddTabOrGroupButton_clicked();
void on_mAddItemButton_clicked();
void on_mRemoveTabGroupItemButton_clicked();
void on_mMoveDownItem_clicked();
void on_mMoveUpItem_clicked();
void attributesListCellChanged( int row, int column );
void updateExpression();
//! Editing of layer was toggled
void editingToggled();
protected:
void updateButtons();
FieldConfig configForRow( int row );
void setConfigForRow( int row, const FieldConfig &cfg );
QList<QgsRelation> mRelations;
QgsVectorLayer *mLayer = nullptr;
DesignerTree *mDesignerTree = nullptr;
DragList *mFieldsList = nullptr;
DragList *mRelationsList = nullptr;
// Holds all the first column items (header: id) of the table.
// The index in the list is the fieldIdx, and therefore acts as a mapping
// between fieldIdx and QTableWidgetItem->row()
QList<QTableWidgetItem *> mIndexedWidgets;
enum AttrColumns
{
AttrIdCol = 0,
AttrNameCol,
AttrEditTypeCol,
AttrAliasCol,
AttrTypeCol,
AttrTypeNameCol,
AttrLengthCol,
AttrPrecCol,
AttrCommentCol,
AttrWMSCol,
AttrWFSCol,
AttrColCount,
};
enum RelationColumns
{
RelNameCol = 0,
RelLayerCol,
RelFieldCol,
RelIdCol,
RelNmCol,
RelColCount
};
private:
void updateFieldRenamingStatus();
};
QDataStream &operator<< ( QDataStream &stream, const QgsFieldsProperties::DesignerTreeItemData &data );
QDataStream &operator>> ( QDataStream &stream, QgsFieldsProperties::DesignerTreeItemData &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
*/
class DragList : public QTableWidget
{
Q_OBJECT
public:
explicit DragList( QWidget *parent = nullptr )
: QTableWidget( parent )
{}
// QTreeWidget interface
protected:
virtual QStringList mimeTypes() const override;
virtual QMimeData *mimeData( const QList<QTableWidgetItem *> items ) const override;
};
/**
* Graphical representation for the attribute editor drag and drop editor
*/
class DesignerTree : public QTreeWidget
{
Q_OBJECT
public:
explicit DesignerTree( QgsVectorLayer *layer, QWidget *parent = nullptr );
QTreeWidgetItem *addItem( QTreeWidgetItem *parent, QgsFieldsProperties::DesignerTreeItemData data );
QTreeWidgetItem *addContainer( QTreeWidgetItem *parent, const QString &title, int columnCount );
protected:
virtual void dragMoveEvent( QDragMoveEvent *event ) override;
virtual void dropEvent( QDropEvent *event ) override;
virtual bool dropMimeData( QTreeWidgetItem *parent, int index, const QMimeData *data, Qt::DropAction action ) override;
/* Qt::DropActions supportedDropActions() const;*/
// QTreeWidget interface
protected:
virtual QStringList mimeTypes() const override;
virtual QMimeData *mimeData( const QList<QTreeWidgetItem *> items ) const override;
private slots:
void onItemDoubleClicked( QTreeWidgetItem *item, int column );
private:
QgsVectorLayer *mLayer = nullptr;
};
Q_DECLARE_METATYPE( QgsFieldsProperties::FieldConfig )
Q_DECLARE_METATYPE( QgsFieldsProperties::DesignerTreeItemData )
#endif // QGSFIELDSPROPERTIES_H