-
-
Notifications
You must be signed in to change notification settings - Fork 3k
/
qgsquickattributeformmodelbase.h
149 lines (118 loc) · 5.42 KB
/
qgsquickattributeformmodelbase.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
/***************************************************************************
qgsquickattributemodelbase.h
--------------------------------------
Date : 16.8.2016
Copyright : (C) 2016 by Matthias Kuhn
Email : matthias@opengis.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 QGSQUICKATTRIBUTEFORMMODELBASE_H
#define QGSQUICKATTRIBUTEFORMMODELBASE_H
/// @cond PRIVATE
//
// W A R N I N G
// -------------
//
// This file is not part of the QGIS API. It exists purely as an
// implementation detail. This header file may change from version to
// version without notice, or even be removed.
//
#include <QStandardItemModel>
#include <QStack>
#include "qgseditformconfig.h"
#include "qgsexpressioncontext.h"
#include "qgsattributeeditorcontainer.h"
#include "qgis_quick.h"
#include "qgsquickattributemodel.h"
class QVariant;
/**
* \ingroup quick
* This is an internal (implementation) class used as the source model for QgsQuickAttributeFormModel.
*
* \sa QgsQuickAttributeFormModel
*
* \since QGIS 3.4
*/
class QgsQuickAttributeFormModelBase : public QStandardItemModel
{
Q_OBJECT
//! Feature model with attributes
Q_PROPERTY( QgsQuickAttributeModel *attributeModel READ attributeModel WRITE setAttributeModel NOTIFY attributeModelChanged )
//! Whether use tabs layout
Q_PROPERTY( bool hasTabs READ hasTabs WRITE setHasTabs NOTIFY hasTabsChanged )
//! Returns TRUE if all hard constraints defined on fields are satisfied with the current attribute values
Q_PROPERTY( bool constraintsHardValid READ constraintsHardValid NOTIFY constraintsHardValidChanged )
//! Returns TRUE if all soft constraints defined on fields are satisfied with the current attribute values
Q_PROPERTY( bool constraintsSoftValid READ constraintsSoftValid NOTIFY constraintsSoftValidChanged )
public:
//! Constructor
explicit QgsQuickAttributeFormModelBase( QObject *parent = nullptr );
//! Destructor
~QgsQuickAttributeFormModelBase() = default;
QHash<int, QByteArray> roleNames() const override;
bool setData( const QModelIndex &index, const QVariant &value, int role = Qt::EditRole ) override;
//! \copydoc QgsQuickAttributeFormModelBase::attributeModel
QgsQuickAttributeModel *attributeModel() const;
//! \copydoc QgsQuickAttributeFormModelBase::attributeModel
void setAttributeModel( QgsQuickAttributeModel *attributeModel );
//! \copydoc QgsQuickAttributeFormModelBase::hasTabs
bool hasTabs() const;
//! \copydoc QgsQuickAttributeFormModelBase::hasTabs
void setHasTabs( bool hasTabs );
//! Saves changes
void save();
//! Creates a new feature
void create();
//! \copydoc QgsQuickAttributeFormModelBase::constraintsHardValid
bool constraintsHardValid() const;
//! \copydoc QgsQuickAttributeFormModelBase::constraintsSoftValid
bool constraintsSoftValid() const;
/**
* Gets the value of attribute of the feature in the model
*
* \param name QString name of the wanted attribute
*/
QVariant attribute( const QString &name ) const;
//! \copydoc QgsQuickAttributeFormModelBase::constraintsHardValid
void setConstraintsHardValid( bool constraintsHardValid );
//! \copydoc QgsQuickAttributeFormModelBase::constraintsSoftValid
void setConstraintsSoftValid( bool constraintsSoftValid );
//! Resets the model
Q_INVOKABLE void forceClean();
signals:
//! \copydoc QgsQuickAttributeFormModelBase::attributeModel
void attributeModelChanged();
//! \copydoc QgsQuickAttributeFormModelBase::hasTabs
void hasTabsChanged();
//! \copydoc QgsQuickAttributeFormModelBase::constraintsHardValid
void constraintsHardValidChanged();
//! \copydoc QgsQuickAttributeFormModelBase::constraintsSoftValid
void constraintsSoftValidChanged();
private slots:
void onFeatureChanged();
void onLayerChanged();
private:
QgsAttributeEditorContainer *generateRootContainer() const; //#spellok
QgsAttributeEditorContainer *invisibleRootContainer() const;
void updateAttributeValue( QStandardItem *item );
void flatten( QgsAttributeEditorContainer *container, QStandardItem *parent, const QString &parentVisibilityExpressions, QVector<QStandardItem *> &items );
void updateVisibility( int fieldIndex = -1 );
QgsQuickAttributeModel *mAttributeModel = nullptr; // not owned
QgsVectorLayer *mLayer = nullptr; // not owned
std::unique_ptr<QgsAttributeEditorContainer> mTemporaryContainer;
bool mHasTabs = false;
typedef QPair<QgsExpression, QVector<QStandardItem *> > VisibilityExpression;
QList<VisibilityExpression> mVisibilityExpressions;
QMap<QStandardItem *, QgsFieldConstraints> mConstraints;
QgsExpressionContext mExpressionContext;
bool mConstraintsHardValid = false;
bool mConstraintsSoftValid = false;
};
/// @endcond
#endif // QGSQUICKATTRIBUTEFORMMODELBASE_H