Skip to content

Commit 4ca91b2

Browse files
committed
[quick] [feature] Feature attribute panel
Allow to show feature attribute form and edit/save the modification of the attributes. Support most frequent QGIS edit widgets such as text edit, value map or external resource (photo capture)
1 parent 5b655b3 commit 4ca91b2

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+3411
-228
lines changed

doc/qgsquick.dox

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ QGIS Quick consists of a Qt plugin that provides the QML components and of a sha
1313

1414
\subsection qgsquick_overview_widgets QML Classes
1515
\subsubsection qgsquick_overview_widgets_mapcanvas MapCanvas
16+
\subsubsection qgsquick_overview_widgets_featureform FeatureForm
17+
A form listing attributes of a given feature. It supports basic edit field widgets for types such as edit text, map value,
18+
check box, date/time picker or external resource (photo capture).
1619
\subsubsection qgsquick_overview_widgets_positionmarker PositionMarker
1720
The element refers to current position according gps location device connected to it. It holds information about longitude, latitude, altitude,
1821
direction of the movement and accuracy of the signal. See also QgsQuickPositionKit.

src/quickgui/CMakeLists.txt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
############################################################
22
# sources
33
SET(QGIS_QUICK_GUI_MOC_HDRS
4+
attributes/qgsquickattributeformmodel.h
5+
attributes/qgsquickattributeformmodelbase.h
6+
attributes/qgsquickattributemodel.h
7+
attributes/qgsquicksubmodel.h
8+
49
qgsquickfeaturelayerpair.h
510
qgsquickcoordinatetransformer.h
611
qgsquickfeaturehighlight.h
@@ -20,6 +25,11 @@ SET(QGIS_QUICK_GUI_HDRS
2025
)
2126

2227
SET(QGIS_QUICK_GUI_SRC
28+
attributes/qgsquickattributeformmodel.cpp
29+
attributes/qgsquickattributeformmodelbase.cpp
30+
attributes/qgsquickattributemodel.cpp
31+
attributes/qgsquicksubmodel.cpp
32+
2333
qgsquickfeaturelayerpair.cpp
2434
qgsquickcoordinatetransformer.cpp
2535
qgsquickfeaturehighlight.cpp
@@ -37,6 +47,7 @@ SET(QGIS_QUICK_GUI_SRC
3747

3848
INCLUDE_DIRECTORIES(
3949
${CMAKE_CURRENT_SOURCE_DIR}
50+
${CMAKE_CURRENT_SOURCE_DIR}/attributes
4051
${CMAKE_CURRENT_BINARY_DIR}
4152

4253
${CMAKE_SOURCE_DIR}/src/core
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
/***************************************************************************
2+
qgsquickattributeformmodel.cpp
3+
--------------------------------------
4+
Date : 22.9.2016
5+
Copyright : (C) 2016 by Matthias Kuhn
6+
Email : matthias@opengis.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+
#include "qgsquickattributeformmodel.h"
17+
#include "qgsquickattributeformmodelbase.h"
18+
19+
QgsQuickAttributeFormModel::QgsQuickAttributeFormModel( QObject *parent )
20+
: QSortFilterProxyModel( parent )
21+
, mSourceModel( new QgsQuickAttributeFormModelBase( this ) )
22+
{
23+
setSourceModel( mSourceModel );
24+
connect( mSourceModel, &QgsQuickAttributeFormModelBase::hasTabsChanged, this, &QgsQuickAttributeFormModel::hasTabsChanged );
25+
connect( mSourceModel, &QgsQuickAttributeFormModelBase::attributeModelChanged, this, &QgsQuickAttributeFormModel::attributeModelChanged );
26+
connect( mSourceModel, &QgsQuickAttributeFormModelBase::constraintsValidChanged, this, &QgsQuickAttributeFormModel::constraintsValidChanged );
27+
}
28+
29+
bool QgsQuickAttributeFormModel::hasTabs() const
30+
{
31+
return mSourceModel->hasTabs();
32+
}
33+
34+
void QgsQuickAttributeFormModel::setHasTabs( bool hasTabs )
35+
{
36+
mSourceModel->setHasTabs( hasTabs );
37+
}
38+
39+
QgsQuickAttributeModel *QgsQuickAttributeFormModel::attributeModel() const
40+
{
41+
return mSourceModel->attributeModel();
42+
}
43+
44+
void QgsQuickAttributeFormModel::setAttributeModel( QgsQuickAttributeModel *attributeModel )
45+
{
46+
mSourceModel->setAttributeModel( attributeModel );
47+
}
48+
49+
bool QgsQuickAttributeFormModel::constraintsValid() const
50+
{
51+
return mSourceModel->constraintsValid();
52+
}
53+
54+
void QgsQuickAttributeFormModel::save()
55+
{
56+
mSourceModel->save();
57+
}
58+
59+
void QgsQuickAttributeFormModel::create()
60+
{
61+
mSourceModel->create();
62+
}
63+
64+
QVariant QgsQuickAttributeFormModel::attribute( const QString &name ) const
65+
{
66+
return mSourceModel->attribute( name );
67+
}
68+
69+
bool QgsQuickAttributeFormModel::filterAcceptsRow( int source_row, const QModelIndex &source_parent ) const
70+
{
71+
return mSourceModel->data( mSourceModel->index( source_row, 0, source_parent ), CurrentlyVisible ).toBool();
72+
}
Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
/***************************************************************************
2+
qgsquickattributeformmodel.h
3+
--------------------------------------
4+
Date : 22.9.2016
5+
Copyright : (C) 2016 by Matthias Kuhn
6+
Email : matthias@opengis.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 QGSQUICKATTRIBUTEFORMMODEL_H
17+
#define QGSQUICKATTRIBUTEFORMMODEL_H
18+
19+
#include <QSortFilterProxyModel>
20+
21+
#include "qgis_quick.h"
22+
23+
class QgsQuickAttributeFormModelBase;
24+
class QgsQuickAttributeModel;
25+
class QVariant;
26+
27+
/**
28+
* \ingroup quick
29+
* This is a model implementation for attribute form of a feature from a vector layer.
30+
*
31+
* The model is based on vector layer's edit form config (QgsEditFormConfig). It supports
32+
* auto-generated editor layouts and "tab" layout (layout defined with groups and tabs).
33+
* The form layout gets flattened into a list, each row has a bunch of roles with values
34+
* extracted from the edit form config.
35+
*
36+
* It also adds filtering of attribute (attributes may be visible or hidden based on expressions).
37+
*
38+
* \note QML Type: AttributeFormModel
39+
*
40+
* \since QGIS 3.4
41+
*/
42+
class QUICK_EXPORT QgsQuickAttributeFormModel : public QSortFilterProxyModel
43+
{
44+
Q_OBJECT
45+
46+
//! Feature model with attributes
47+
Q_PROPERTY( QgsQuickAttributeModel *attributeModel READ attributeModel WRITE setAttributeModel NOTIFY attributeModelChanged )
48+
49+
//! Whether use tabs layout
50+
Q_PROPERTY( bool hasTabs READ hasTabs WRITE setHasTabs NOTIFY hasTabsChanged )
51+
52+
//! Returns true if all constraints defined on fields are satisfied with the current attribute values
53+
Q_PROPERTY( bool constraintsValid READ constraintsValid NOTIFY constraintsValidChanged )
54+
55+
public:
56+
57+
//! Feature fields's roles
58+
enum FeatureRoles
59+
{
60+
ElementType = Qt::UserRole + 1, //!< User role used to identify either "field" or "container" type of item
61+
Name, //!< Field Name
62+
AttributeValue, //!< Field Value
63+
AttributeEditable, //!< Whether is field editable
64+
EditorWidget, //!< Widget type to represent the data (text field, value map, ...)
65+
EditorWidgetConfig, //!< Widget configuration
66+
RememberValue, //!< Remember value (default value for next feature)
67+
Field, //!< Field
68+
FieldIndex, //!< Index
69+
Group, //!< Group
70+
AttributeEditorElement, //!< Attribute editor element
71+
CurrentlyVisible, //!< Field visible
72+
ConstraintValid, //!< Contraint valid
73+
ConstraintDescription //!< Contraint description
74+
};
75+
76+
Q_ENUM( FeatureRoles )
77+
78+
//! Create new attribute form model
79+
QgsQuickAttributeFormModel( QObject *parent = nullptr );
80+
81+
//! \copydoc QgsQuickAttributeFormModel::hasTabs
82+
bool hasTabs() const;
83+
84+
//! \copydoc QgsQuickAttributeFormModel::hasTabs
85+
void setHasTabs( bool hasTabs );
86+
87+
//! \copydoc QgsQuickAttributeFormModel::attributeModel
88+
QgsQuickAttributeModel *attributeModel() const;
89+
90+
//! \copydoc QgsQuickAttributeFormModel::attributeModel
91+
void setAttributeModel( QgsQuickAttributeModel *attributeModel );
92+
93+
//! \copydoc QgsQuickAttributeFormModel::constraintsValid
94+
bool constraintsValid() const;
95+
96+
//! Updates QgsFeature based on changes
97+
Q_INVOKABLE void save();
98+
99+
//! Creates new QgsFeature
100+
Q_INVOKABLE void create();
101+
102+
//! Returns attribute value with name
103+
Q_INVOKABLE QVariant attribute( const QString &name ) const;
104+
105+
signals:
106+
//! \copydoc QgsQuickAttributeFormModel::attributeModel
107+
void attributeModelChanged();
108+
109+
//! \copydoc QgsQuickAttributeFormModel::hasTabs
110+
void hasTabsChanged();
111+
112+
//! \copydoc QgsQuickAttributeFormModel::constraintsValid
113+
void constraintsValidChanged();
114+
115+
protected:
116+
virtual bool filterAcceptsRow( int source_row, const QModelIndex &source_parent ) const override;
117+
118+
private:
119+
QgsQuickAttributeFormModelBase *mSourceModel; //not owned
120+
};
121+
122+
#endif // QGSQUICKATTRIBUTEFORMMODEL_H

0 commit comments

Comments
 (0)