|
| 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