Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/core/attributeformmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
7 changes: 7 additions & 0 deletions src/core/attributeformmodel.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ class AttributeFormModel : public QSortFilterProxyModel
EditorWidgetConfig,
RelationEditorWidget,
RelationEditorWidgetConfig,
CanRememberValue,
RememberValue,
Field,
RelationId,
Expand Down Expand Up @@ -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();
Expand Down
25 changes: 25 additions & 0 deletions src/core/attributeformmodelbase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ QHash<int, QByteArray> 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";
Expand Down Expand Up @@ -348,6 +349,24 @@ void AttributeFormModelBase::applyRelationshipDefaultValues()
}
}

void AttributeFormModelBase::activateAllRememberValues()
{
QMap<QStandardItem *, int>::ConstIterator fieldIterator( mFields.constBegin() );
for ( ; fieldIterator != mFields.constEnd(); ++fieldIterator )
{
setData( fieldIterator.key()->index(), true, AttributeFormModel::RememberValue );
}
}

void AttributeFormModelBase::deactivateAllRememberValues()
{
QMap<QStandardItem *, int>::ConstIterator fieldIterator( mFields.constBegin() );
for ( ; fieldIterator != mFields.constEnd(); ++fieldIterator )
{
setData( fieldIterator.key()->index(), false, AttributeFormModel::RememberValue );
}
}

Comment on lines +352 to +369
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The implementation of activateAllRememberValues and deactivateAllRememberValues is clear and consistent with the codebase;

However, currently, these functions apply to all fields, regardless of whether CanRememberValue is true.

for added robustness, you might check CanRememberValue before setting RememberValue, otherwise everything looks good.

QgsAttributeEditorContainer *AttributeFormModelBase::generateRootContainer() const
{
QgsAttributeEditorContainer *root = new QgsAttributeEditorContainer( QString(), nullptr );
Expand Down Expand Up @@ -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 );
Expand Down Expand Up @@ -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 );
Expand Down
6 changes: 6 additions & 0 deletions src/core/attributeformmodelbase.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
8 changes: 8 additions & 0 deletions src/core/featuremodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}

Expand Down Expand Up @@ -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<int>() << role );
Expand Down
8 changes: 8 additions & 0 deletions src/core/projectinfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand Down Expand Up @@ -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 );
}
Expand Down
51 changes: 49 additions & 2 deletions src/qml/FeatureForm.qml
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -827,6 +827,7 @@ Page {
id: titleLabel
Layout.fillWidth: true
Layout.preferredHeight: parent.height
Layout.leftMargin: 48
objectName: "titleLabel"

font: Theme.strongFont
Expand All @@ -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);
Expand Down Expand Up @@ -924,6 +925,52 @@ Page {
}
}
}

QfToolButton {
id: menuButton

Layout.alignment: Qt.AlignTop | Qt.AlignRight

width: 49
height: 48
Comment on lines +934 to +935
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why 49 - 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()
}
}

Expand Down
Loading