diff --git a/src/core/attributeformmodel.cpp b/src/core/attributeformmodel.cpp index df4cfde2df..6106e74330 100644 --- a/src/core/attributeformmodel.cpp +++ b/src/core/attributeformmodel.cpp @@ -95,6 +95,16 @@ void AttributeFormModel::applyRelationshipDefaultValues() return mSourceModel->applyRelationshipDefaultValues(); } +void AttributeFormModel::activateAllRememberValues() +{ + return mSourceModel->activateAllRememberValues(); +} + +void AttributeFormModel::deactivateAllRememberValues() +{ + return mSourceModel->deactivateAllRememberValues(); +} + bool AttributeFormModel::filterAcceptsRow( int source_row, const QModelIndex &source_parent ) const { return mSourceModel->data( mSourceModel->index( source_row, 0, source_parent ), CurrentlyVisible ).toBool(); diff --git a/src/core/attributeformmodel.h b/src/core/attributeformmodel.h index 9627f4845c..c1693e5743 100644 --- a/src/core/attributeformmodel.h +++ b/src/core/attributeformmodel.h @@ -45,6 +45,7 @@ class AttributeFormModel : public QSortFilterProxyModel EditorWidgetConfig, RelationEditorWidget, RelationEditorWidgetConfig, + CanRememberValue, RememberValue, Field, RelationId, @@ -112,6 +113,12 @@ class AttributeFormModel : public QSortFilterProxyModel //! Applies default values linked to relationships Q_INVOKABLE void applyRelationshipDefaultValues(); + //! Activate all available value that can be remembered and reused. + Q_INVOKABLE void activateAllRememberValues(); + + //! Deactivate all available value that can be remembered and reused. + Q_INVOKABLE void deactivateAllRememberValues(); + signals: void featureModelChanged(); void hasTabsChanged(); diff --git a/src/core/attributeformmodelbase.cpp b/src/core/attributeformmodelbase.cpp index d91c2af3b9..14d2e8c1fd 100644 --- a/src/core/attributeformmodelbase.cpp +++ b/src/core/attributeformmodelbase.cpp @@ -80,6 +80,7 @@ QHash AttributeFormModelBase::roleNames() const roles[AttributeFormModel::EditorWidgetConfig] = "EditorWidgetConfig"; roles[AttributeFormModel::RelationEditorWidget] = "RelationEditorWidget"; roles[AttributeFormModel::RelationEditorWidgetConfig] = "RelationEditorWidgetConfig"; + roles[AttributeFormModel::CanRememberValue] = "CanRememberValue"; roles[AttributeFormModel::RememberValue] = "RememberValue"; roles[AttributeFormModel::Field] = "Field"; roles[AttributeFormModel::RelationId] = "RelationId"; @@ -348,6 +349,24 @@ void AttributeFormModelBase::applyRelationshipDefaultValues() } } +void AttributeFormModelBase::activateAllRememberValues() +{ + QMap::ConstIterator fieldIterator( mFields.constBegin() ); + for ( ; fieldIterator != mFields.constEnd(); ++fieldIterator ) + { + setData( fieldIterator.key()->index(), true, AttributeFormModel::RememberValue ); + } +} + +void AttributeFormModelBase::deactivateAllRememberValues() +{ + QMap::ConstIterator fieldIterator( mFields.constBegin() ); + for ( ; fieldIterator != mFields.constEnd(); ++fieldIterator ) + { + setData( fieldIterator.key()->index(), false, AttributeFormModel::RememberValue ); + } +} + QgsAttributeEditorContainer *AttributeFormModelBase::generateRootContainer() const { QgsAttributeEditorContainer *root = new QgsAttributeEditorContainer( QString(), nullptr ); @@ -479,6 +498,7 @@ void AttributeFormModelBase::buildForm( QgsAttributeEditorContainer *container, item->setData( QModelIndex(), AttributeFormModel::GroupIndex ); item->setData( true, AttributeFormModel::ConstraintHardValid ); item->setData( true, AttributeFormModel::ConstraintSoftValid ); + item->setData( false, AttributeFormModel::CanRememberValue ); QgsAttributeEditorElement::LabelStyle labelStyle = element->labelStyle(); item->setData( labelStyle.overrideColor, AttributeFormModel::LabelOverrideColor ); @@ -545,6 +565,11 @@ void AttributeFormModelBase::buildForm( QgsAttributeEditorContainer *container, item->setData( !mLayer->editFormConfig().readOnly( fieldIndex ) && setup.type() != QStringLiteral( "Binary" ), AttributeFormModel::AttributeEditable ); item->setData( setup.type(), AttributeFormModel::EditorWidget ); item->setData( setup.config(), AttributeFormModel::EditorWidgetConfig ); +#if _QGIS_VERSION_INT >= 39900 + item->setData( mLayer->editFormConfig().reuseLastValue( fieldIndex ), AttributeFormModel::CanRememberValue ); +#else + item->setData( true, AttributeFormModel::CanRememberValue ); +#endif item->setData( mFeatureModel->rememberedAttributes().at( fieldIndex ) ? Qt::Checked : Qt::Unchecked, AttributeFormModel::RememberValue ); item->setData( QgsField( field ), AttributeFormModel::Field ); item->setData( "field", AttributeFormModel::ElementType ); diff --git a/src/core/attributeformmodelbase.h b/src/core/attributeformmodelbase.h index 0bcd9462f7..0e49b4947a 100644 --- a/src/core/attributeformmodelbase.h +++ b/src/core/attributeformmodelbase.h @@ -69,6 +69,12 @@ class AttributeFormModelBase : public QStandardItemModel //! \copydoc AttributeFormModel::applyRelationshipDefaultValues void applyRelationshipDefaultValues(); + //! \copydoc AttributeFormModel::activateAllRememberValues + void activateAllRememberValues(); + + //! \copydoc AttributeFormModel::deactivateAllRememberValues + void deactivateAllRememberValues(); + signals: void featureModelChanged(); void hasTabsChanged(); diff --git a/src/core/featuremodel.cpp b/src/core/featuremodel.cpp index 1c6363a9bf..63d55f75bd 100644 --- a/src/core/featuremodel.cpp +++ b/src/core/featuremodel.cpp @@ -143,7 +143,11 @@ void FeatureModel::setCurrentLayer( QgsVectorLayer *layer ) const QgsEditFormConfig config = mLayer->editFormConfig(); for ( int i = 0; i < layer->fields().size(); i++ ) { +#if _QGIS_VERSION_INT >= 39900 + ( *sRememberings )[mLayer].rememberedAttributes << ( config.reuseLastValue( i ) && config.rememberLastValueByDefault( i ) ); +#else ( *sRememberings )[mLayer].rememberedAttributes << config.reuseLastValue( i ); +#endif } } @@ -450,7 +454,11 @@ bool FeatureModel::setData( const QModelIndex &index, const QVariant &value, int ( *sRememberings )[mLayer].rememberedAttributes[index.row()] = value.toBool(); QgsEditFormConfig config = mLayer->editFormConfig(); +#if _QGIS_VERSION_INT >= 39900 + config.setRememberLastValueByDefault( index.row(), value.toBool() ); +#else config.setReuseLastValue( index.row(), value.toBool() ); +#endif mLayer->setEditFormConfig( config ); emit dataChanged( index, index, QVector() << role ); diff --git a/src/core/projectinfo.cpp b/src/core/projectinfo.cpp index 152e767b0d..86a08b452d 100644 --- a/src/core/projectinfo.cpp +++ b/src/core/projectinfo.cpp @@ -376,7 +376,11 @@ void ProjectInfo::saveLayerRememberedFields( QgsMapLayer *layer ) const QgsFields fields = vlayer->fields(); for ( int i = 0; i < fields.size(); i++ ) { +#if _QGIS_VERSION_INT >= 39900 + rememberedFields.insert( fields.at( i ).name(), config.reuseLastValue( i ) && config.rememberLastValueByDefault( i ) ); +#else rememberedFields.insert( fields.at( i ).name(), config.reuseLastValue( i ) ); +#endif } const bool isDataset = QgsProject::instance()->readBoolEntry( QStringLiteral( "QField" ), QStringLiteral( "isDataset" ), false ); @@ -553,7 +557,11 @@ void ProjectInfo::restoreSettings( QString &projectFilePath, QgsProject *project const QStringList fieldNames = rememberedFields.keys(); for ( const QString fieldName : fieldNames ) { +#if _QGIS_VERSION_INT >= 39900 + config.setRememberLastValueByDefault( vlayer->fields().indexFromName( fieldName ), rememberedFields[fieldName].toBool() ); +#else config.setReuseLastValue( vlayer->fields().indexFromName( fieldName ), rememberedFields[fieldName].toBool() ); +#endif } vlayer->setEditFormConfig( config ); } diff --git a/src/qml/FeatureForm.qml b/src/qml/FeatureForm.qml index 90bab637d4..9bba31961f 100644 --- a/src/qml/FeatureForm.qml +++ b/src/qml/FeatureForm.qml @@ -662,7 +662,7 @@ Page { QfToolButton { id: rememberButton - visible: form.state === "Add" && EditorWidget !== "Hidden" && EditorWidget !== 'RelationEditor' + visible: CanRememberValue && form.state === "Add" && EditorWidget !== "Hidden" && EditorWidget !== 'RelationEditor' width: visible ? 48 : 0 iconSource: Theme.getThemeVectorIcon("ic_pin_black_24dp") @@ -827,6 +827,7 @@ Page { id: titleLabel Layout.fillWidth: true Layout.preferredHeight: parent.height + Layout.leftMargin: 48 objectName: "titleLabel" font: Theme.strongFont @@ -836,7 +837,7 @@ Page { const featureModel = model.featureModel; var currentLayer = featureModel ? featureModel.currentLayer : null; var layerName = 'N/A'; - if (currentLayer != null) + if (currentLayer !== null) layerName = currentLayer.name; if (form.state === 'Add') qsTr('Add feature on %1').arg(layerName); @@ -924,6 +925,52 @@ Page { } } } + + QfToolButton { + id: menuButton + + Layout.alignment: Qt.AlignTop | Qt.AlignRight + + width: 49 + height: 48 + clip: true + visible: !setupOnly + + iconSource: Theme.getThemeVectorIcon("ic_dot_menu_black_24dp") + iconColor: Theme.mainOverlayColor + + onClicked: { + featureFormMenu.popup(menuButton.x + menuButton.width - featureFormMenu.width, menuButton.y); + } + } + } + } + + QfMenu { + id: featureFormMenu + title: qsTr("Feature Form Menu") + + topMargin: mainWindow.sceneTopMargin + bottomMargin: mainWindow.sceneBottomMargin + + MenuItem { + text: qsTr('Remember all reusable values') + + font: Theme.defaultFont + height: 48 + leftPadding: Theme.menuItemCheckLeftPadding + + onTriggered: form.model.activateAllRememberValues() + } + + MenuItem { + text: qsTr('Forget all reusable values') + + font: Theme.defaultFont + height: 48 + leftPadding: Theme.menuItemCheckLeftPadding + + onTriggered: form.model.deactivateAllRememberValues() } }