Skip to content

Commit

Permalink
[quick] [feature] Feature attribute panel
Browse files Browse the repository at this point in the history
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)
  • Loading branch information
PeterPetrik committed Jul 2, 2018
1 parent 5b655b3 commit 4ca91b2
Show file tree
Hide file tree
Showing 47 changed files with 3,411 additions and 228 deletions.
3 changes: 3 additions & 0 deletions doc/qgsquick.dox
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ QGIS Quick consists of a Qt plugin that provides the QML components and of a sha

\subsection qgsquick_overview_widgets QML Classes
\subsubsection qgsquick_overview_widgets_mapcanvas MapCanvas
\subsubsection qgsquick_overview_widgets_featureform FeatureForm
A form listing attributes of a given feature. It supports basic edit field widgets for types such as edit text, map value,
check box, date/time picker or external resource (photo capture).
\subsubsection qgsquick_overview_widgets_positionmarker PositionMarker
The element refers to current position according gps location device connected to it. It holds information about longitude, latitude, altitude,
direction of the movement and accuracy of the signal. See also QgsQuickPositionKit.
Expand Down
11 changes: 11 additions & 0 deletions src/quickgui/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
############################################################
# sources
SET(QGIS_QUICK_GUI_MOC_HDRS
attributes/qgsquickattributeformmodel.h
attributes/qgsquickattributeformmodelbase.h
attributes/qgsquickattributemodel.h
attributes/qgsquicksubmodel.h

qgsquickfeaturelayerpair.h
qgsquickcoordinatetransformer.h
qgsquickfeaturehighlight.h
Expand All @@ -20,6 +25,11 @@ SET(QGIS_QUICK_GUI_HDRS
)

SET(QGIS_QUICK_GUI_SRC
attributes/qgsquickattributeformmodel.cpp
attributes/qgsquickattributeformmodelbase.cpp
attributes/qgsquickattributemodel.cpp
attributes/qgsquicksubmodel.cpp

qgsquickfeaturelayerpair.cpp
qgsquickcoordinatetransformer.cpp
qgsquickfeaturehighlight.cpp
Expand All @@ -37,6 +47,7 @@ SET(QGIS_QUICK_GUI_SRC

INCLUDE_DIRECTORIES(
${CMAKE_CURRENT_SOURCE_DIR}
${CMAKE_CURRENT_SOURCE_DIR}/attributes
${CMAKE_CURRENT_BINARY_DIR}

${CMAKE_SOURCE_DIR}/src/core
Expand Down
72 changes: 72 additions & 0 deletions src/quickgui/attributes/qgsquickattributeformmodel.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
/***************************************************************************
qgsquickattributeformmodel.cpp
--------------------------------------
Date : 22.9.2016
Copyright : (C) 2016 by Matthias Kuhn
Email : [email protected]
***************************************************************************
* *
* 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. *
* *
***************************************************************************/

#include "qgsquickattributeformmodel.h"
#include "qgsquickattributeformmodelbase.h"

QgsQuickAttributeFormModel::QgsQuickAttributeFormModel( QObject *parent )
: QSortFilterProxyModel( parent )
, mSourceModel( new QgsQuickAttributeFormModelBase( this ) )
{
setSourceModel( mSourceModel );
connect( mSourceModel, &QgsQuickAttributeFormModelBase::hasTabsChanged, this, &QgsQuickAttributeFormModel::hasTabsChanged );
connect( mSourceModel, &QgsQuickAttributeFormModelBase::attributeModelChanged, this, &QgsQuickAttributeFormModel::attributeModelChanged );
connect( mSourceModel, &QgsQuickAttributeFormModelBase::constraintsValidChanged, this, &QgsQuickAttributeFormModel::constraintsValidChanged );
}

bool QgsQuickAttributeFormModel::hasTabs() const
{
return mSourceModel->hasTabs();
}

void QgsQuickAttributeFormModel::setHasTabs( bool hasTabs )
{
mSourceModel->setHasTabs( hasTabs );
}

QgsQuickAttributeModel *QgsQuickAttributeFormModel::attributeModel() const
{
return mSourceModel->attributeModel();
}

void QgsQuickAttributeFormModel::setAttributeModel( QgsQuickAttributeModel *attributeModel )
{
mSourceModel->setAttributeModel( attributeModel );
}

bool QgsQuickAttributeFormModel::constraintsValid() const
{
return mSourceModel->constraintsValid();
}

void QgsQuickAttributeFormModel::save()
{
mSourceModel->save();
}

void QgsQuickAttributeFormModel::create()
{
mSourceModel->create();
}

QVariant QgsQuickAttributeFormModel::attribute( const QString &name ) const
{
return mSourceModel->attribute( name );
}

bool QgsQuickAttributeFormModel::filterAcceptsRow( int source_row, const QModelIndex &source_parent ) const
{
return mSourceModel->data( mSourceModel->index( source_row, 0, source_parent ), CurrentlyVisible ).toBool();
}
122 changes: 122 additions & 0 deletions src/quickgui/attributes/qgsquickattributeformmodel.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
/***************************************************************************
qgsquickattributeformmodel.h
--------------------------------------
Date : 22.9.2016
Copyright : (C) 2016 by Matthias Kuhn
Email : [email protected]
***************************************************************************
* *
* 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 QGSQUICKATTRIBUTEFORMMODEL_H
#define QGSQUICKATTRIBUTEFORMMODEL_H

#include <QSortFilterProxyModel>

#include "qgis_quick.h"

class QgsQuickAttributeFormModelBase;
class QgsQuickAttributeModel;
class QVariant;

/**
* \ingroup quick
* This is a model implementation for attribute form of a feature from a vector layer.
*
* The model is based on vector layer's edit form config (QgsEditFormConfig). It supports
* auto-generated editor layouts and "tab" layout (layout defined with groups and tabs).
* The form layout gets flattened into a list, each row has a bunch of roles with values
* extracted from the edit form config.
*
* It also adds filtering of attribute (attributes may be visible or hidden based on expressions).
*
* \note QML Type: AttributeFormModel
*
* \since QGIS 3.4
*/
class QUICK_EXPORT QgsQuickAttributeFormModel : public QSortFilterProxyModel
{
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 constraints defined on fields are satisfied with the current attribute values
Q_PROPERTY( bool constraintsValid READ constraintsValid NOTIFY constraintsValidChanged )

public:

//! Feature fields's roles
enum FeatureRoles
{
ElementType = Qt::UserRole + 1, //!< User role used to identify either "field" or "container" type of item
Name, //!< Field Name
AttributeValue, //!< Field Value
AttributeEditable, //!< Whether is field editable
EditorWidget, //!< Widget type to represent the data (text field, value map, ...)
EditorWidgetConfig, //!< Widget configuration
RememberValue, //!< Remember value (default value for next feature)
Field, //!< Field
FieldIndex, //!< Index
Group, //!< Group
AttributeEditorElement, //!< Attribute editor element
CurrentlyVisible, //!< Field visible
ConstraintValid, //!< Contraint valid
ConstraintDescription //!< Contraint description
};

Q_ENUM( FeatureRoles )

//! Create new attribute form model
QgsQuickAttributeFormModel( QObject *parent = nullptr );

//! \copydoc QgsQuickAttributeFormModel::hasTabs
bool hasTabs() const;

//! \copydoc QgsQuickAttributeFormModel::hasTabs
void setHasTabs( bool hasTabs );

//! \copydoc QgsQuickAttributeFormModel::attributeModel
QgsQuickAttributeModel *attributeModel() const;

//! \copydoc QgsQuickAttributeFormModel::attributeModel
void setAttributeModel( QgsQuickAttributeModel *attributeModel );

//! \copydoc QgsQuickAttributeFormModel::constraintsValid
bool constraintsValid() const;

//! Updates QgsFeature based on changes
Q_INVOKABLE void save();

//! Creates new QgsFeature
Q_INVOKABLE void create();

//! Returns attribute value with name
Q_INVOKABLE QVariant attribute( const QString &name ) const;

signals:
//! \copydoc QgsQuickAttributeFormModel::attributeModel
void attributeModelChanged();

//! \copydoc QgsQuickAttributeFormModel::hasTabs
void hasTabsChanged();

//! \copydoc QgsQuickAttributeFormModel::constraintsValid
void constraintsValidChanged();

protected:
virtual bool filterAcceptsRow( int source_row, const QModelIndex &source_parent ) const override;

private:
QgsQuickAttributeFormModelBase *mSourceModel; //not owned
};

#endif // QGSQUICKATTRIBUTEFORMMODEL_H
Loading

0 comments on commit 4ca91b2

Please sign in to comment.