From c9b1f48d13f325e11ecb8c6a0c77aca45ad4c9ac Mon Sep 17 00:00:00 2001 From: Mohsen Date: Sun, 18 Aug 2024 21:21:54 +0330 Subject: [PATCH 1/8] Remove old TODO (use itemAtIndex). --- src/qml/VariableEditor.qml | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/qml/VariableEditor.qml b/src/qml/VariableEditor.qml index fdaab91d18..65614da102 100644 --- a/src/qml/VariableEditor.qml +++ b/src/qml/VariableEditor.qml @@ -47,6 +47,10 @@ ColumnLayout { property var itemRow: index property bool canDelete: table.model.isEditable(index) + function forceFocusOnVariableName() { + variableNameText.forceActiveFocus(); + } + Row { id: line spacing: 5 @@ -153,8 +157,7 @@ ColumnLayout { onClicked: { table.model.addCustomVariable("new_variable", ""); table.positionViewAtIndex(table.count - 1, ListView.visible); - // TODO: Use Qt 5.13 itemAtIndex( index ) - table.children[0].children[table.count].children[0].children[0].forceActiveFocus(); + table.itemAtIndex(table.count - 1).forceFocusOnVariableName(); } } } From 98daecf3c452841a1defa021cc9651b099620711 Mon Sep 17 00:00:00 2001 From: Mohsen Date: Mon, 19 Aug 2024 20:40:08 +0330 Subject: [PATCH 2/8] Show app variables only. --- src/core/expressionvariablemodel.cpp | 31 +++++++++++++++++++++++++++- src/core/expressionvariablemodel.h | 12 +++++++++++ src/qml/QFieldSettings.qml | 4 ++++ src/qml/VariableEditor.qml | 1 + src/qml/qgismobileapp.qml | 1 + 5 files changed, 48 insertions(+), 1 deletion(-) diff --git a/src/core/expressionvariablemodel.cpp b/src/core/expressionvariablemodel.cpp index 7eef0263bf..ba4229ae29 100644 --- a/src/core/expressionvariablemodel.cpp +++ b/src/core/expressionvariablemodel.cpp @@ -15,6 +15,7 @@ ***************************************************************************/ #include "expressionvariablemodel.h" +#include "utils/expressioncontextutils.h" #include #include @@ -72,7 +73,7 @@ void ExpressionVariableModel::reloadVariables() QStringList variableNames = scope->variableNames(); variableNames.sort(); - // First add readonly variables + // First add readonly app variables for ( const QString &varName : variableNames ) { if ( scope->isReadOnly( varName ) ) @@ -90,6 +91,21 @@ void ExpressionVariableModel::reloadVariables() } } + // Second add readonly project variables + QVariantMap projectVariables = ExpressionContextUtils::projectVariables( mCurrentProject ); + for ( const QString &varName : projectVariables.keys() ) + { + QStandardItem *nameItem = new QStandardItem( varName ); + QVariant varValue = projectVariables.value( varName ).toString(); + + nameItem->setData( varName, VariableName ); + nameItem->setData( varValue, VariableValue ); + nameItem->setEditable( false ); + + insertRow( rowCount(), QList() << nameItem ); + } + + // Then add custom variables for ( const QString &varName : variableNames ) { @@ -147,3 +163,16 @@ void ExpressionVariableModel::onDataChanged( const QModelIndex &topLeft, const Q Q_UNUSED( bottomRight ) Q_UNUSED( roles ) } + +QgsProject *ExpressionVariableModel::currentProject() const +{ + return mCurrentProject; +} + +void ExpressionVariableModel::setCurrentProject( QgsProject *newCurrentProject ) +{ + if ( mCurrentProject == newCurrentProject ) + return; + mCurrentProject = newCurrentProject; + emit currentProjectChanged(); +} diff --git a/src/core/expressionvariablemodel.h b/src/core/expressionvariablemodel.h index 615538daae..be32f7befb 100644 --- a/src/core/expressionvariablemodel.h +++ b/src/core/expressionvariablemodel.h @@ -17,11 +17,14 @@ #define EXPRESSIONVARIABLEMODEL_H #include +#include class ExpressionVariableModel : public QStandardItemModel { Q_OBJECT + Q_PROPERTY( QgsProject *currentProject READ currentProject WRITE setCurrentProject NOTIFY currentProjectChanged ) + public: enum Roles { @@ -49,8 +52,17 @@ class ExpressionVariableModel : public QStandardItemModel QHash roleNames() const override; + QgsProject *currentProject() const; + void setCurrentProject( QgsProject *newCurrentProject ); + + signals: + void currentProjectChanged(); + private slots: void onDataChanged( const QModelIndex &topLeft, const QModelIndex &bottomRight, const QVector &roles ); + + private: + QgsProject *mCurrentProject = nullptr; }; #endif // EXPRESSIONVARIABLEMODEL_H diff --git a/src/qml/QFieldSettings.qml b/src/qml/QFieldSettings.qml index cecdb2aa61..a72e43e2b3 100644 --- a/src/qml/QFieldSettings.qml +++ b/src/qml/QFieldSettings.qml @@ -31,6 +31,10 @@ Page { } } + function reset() { + variableEditor.reset(); + } + Settings { id: registry property bool showScaleBar: true diff --git a/src/qml/VariableEditor.qml b/src/qml/VariableEditor.qml index 65614da102..c869af79f5 100644 --- a/src/qml/VariableEditor.qml +++ b/src/qml/VariableEditor.qml @@ -29,6 +29,7 @@ ColumnLayout { ListView { id: table model: ExpressionVariableModel { + currentProject: qgisProject } flickableDirection: Flickable.VerticalFlick boundsBehavior: Flickable.StopAtBounds diff --git a/src/qml/qgismobileapp.qml b/src/qml/qgismobileapp.qml index 600aee5525..2b05c18870 100644 --- a/src/qml/qgismobileapp.qml +++ b/src/qml/qgismobileapp.qml @@ -2333,6 +2333,7 @@ ApplicationWindow { onTriggered: { dashBoard.close(); + qfieldSettings.reset(); qfieldSettings.visible = true; highlighted = false; } From 92dd70ede2f9244d89201bb5b216a0684801bd30 Mon Sep 17 00:00:00 2001 From: Mohsen Date: Wed, 21 Aug 2024 16:00:21 +0330 Subject: [PATCH 3/8] Add VariableScopeRole. --- src/core/expressionvariablemodel.cpp | 4 ++++ src/core/expressionvariablemodel.h | 9 ++++++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/core/expressionvariablemodel.cpp b/src/core/expressionvariablemodel.cpp index ba4229ae29..d481aa5e65 100644 --- a/src/core/expressionvariablemodel.cpp +++ b/src/core/expressionvariablemodel.cpp @@ -40,6 +40,7 @@ void ExpressionVariableModel::addCustomVariable( const QString &varName, const Q QStandardItem *nameItem = new QStandardItem( varName ); nameItem->setData( varName, VariableName ); nameItem->setData( varVal, VariableValue ); + nameItem->setData( QVariant::fromValue( VariableScope::ApplicationScope ), VariableScopeRole ); nameItem->setEditable( true ); insertRow( rowCount(), QList() << nameItem ); @@ -86,6 +87,7 @@ void ExpressionVariableModel::reloadVariables() nameItem->setData( varName, VariableName ); nameItem->setData( varValue, VariableValue ); nameItem->setEditable( false ); + nameItem->setData( QVariant::fromValue( VariableScope::ApplicationScope ), VariableScopeRole ); insertRow( rowCount(), QList() << nameItem ); } @@ -101,6 +103,7 @@ void ExpressionVariableModel::reloadVariables() nameItem->setData( varName, VariableName ); nameItem->setData( varValue, VariableValue ); nameItem->setEditable( false ); + nameItem->setData( QVariant::fromValue( VariableScope::ProjectScope ), VariableScopeRole ); insertRow( rowCount(), QList() << nameItem ); } @@ -155,6 +158,7 @@ QHash ExpressionVariableModel::roleNames() const QHash names = QStandardItemModel::roleNames(); names[VariableName] = "VariableName"; names[VariableValue] = "VariableValue"; + names[VariableScopeRole] = "VariableScope"; return names; } diff --git a/src/core/expressionvariablemodel.h b/src/core/expressionvariablemodel.h index be32f7befb..6e40f349bc 100644 --- a/src/core/expressionvariablemodel.h +++ b/src/core/expressionvariablemodel.h @@ -29,7 +29,14 @@ class ExpressionVariableModel : public QStandardItemModel enum Roles { VariableName = Qt::UserRole, - VariableValue + VariableValue, + VariableScopeRole + }; + + enum class VariableScope + { + ApplicationScope, + ProjectScope }; explicit ExpressionVariableModel( QObject *parent = nullptr ); From 2dd663cc958cb4de2589edfe6606027b1dd35db1 Mon Sep 17 00:00:00 2001 From: Mohsen Date: Wed, 21 Aug 2024 17:06:03 +0330 Subject: [PATCH 4/8] add a VeriableEditable role. --- src/core/expressionvariablemodel.cpp | 15 ++++----------- src/core/expressionvariablemodel.h | 5 ++--- src/qml/VariableEditor.qml | 6 +++--- 3 files changed, 9 insertions(+), 17 deletions(-) diff --git a/src/core/expressionvariablemodel.cpp b/src/core/expressionvariablemodel.cpp index d481aa5e65..60ba3f7c74 100644 --- a/src/core/expressionvariablemodel.cpp +++ b/src/core/expressionvariablemodel.cpp @@ -41,7 +41,7 @@ void ExpressionVariableModel::addCustomVariable( const QString &varName, const Q nameItem->setData( varName, VariableName ); nameItem->setData( varVal, VariableValue ); nameItem->setData( QVariant::fromValue( VariableScope::ApplicationScope ), VariableScopeRole ); - nameItem->setEditable( true ); + nameItem->setData( true, VariableEditable ); insertRow( rowCount(), QList() << nameItem ); } @@ -86,8 +86,8 @@ void ExpressionVariableModel::reloadVariables() nameItem->setData( varName, VariableName ); nameItem->setData( varValue, VariableValue ); - nameItem->setEditable( false ); nameItem->setData( QVariant::fromValue( VariableScope::ApplicationScope ), VariableScopeRole ); + nameItem->setData( false, VariableEditable ); insertRow( rowCount(), QList() << nameItem ); } @@ -102,8 +102,8 @@ void ExpressionVariableModel::reloadVariables() nameItem->setData( varName, VariableName ); nameItem->setData( varValue, VariableValue ); - nameItem->setEditable( false ); nameItem->setData( QVariant::fromValue( VariableScope::ProjectScope ), VariableScopeRole ); + nameItem->setData( false, VariableEditable ); insertRow( rowCount(), QList() << nameItem ); } @@ -119,14 +119,6 @@ void ExpressionVariableModel::reloadVariables() } } -bool ExpressionVariableModel::isEditable( int row ) -{ - QStandardItem *rowItem = item( row ); - if ( rowItem ) - return rowItem->isEditable(); - return false; -} - void ExpressionVariableModel::setName( int row, const QString &name ) { QStandardItem *rowItem = item( row ); @@ -159,6 +151,7 @@ QHash ExpressionVariableModel::roleNames() const names[VariableName] = "VariableName"; names[VariableValue] = "VariableValue"; names[VariableScopeRole] = "VariableScope"; + names[VariableEditable] = "VariableEditable"; return names; } diff --git a/src/core/expressionvariablemodel.h b/src/core/expressionvariablemodel.h index 6e40f349bc..7e365d4890 100644 --- a/src/core/expressionvariablemodel.h +++ b/src/core/expressionvariablemodel.h @@ -30,7 +30,8 @@ class ExpressionVariableModel : public QStandardItemModel { VariableName = Qt::UserRole, VariableValue, - VariableScopeRole + VariableScopeRole, + VariableEditable = Qt::EditRole }; enum class VariableScope @@ -51,8 +52,6 @@ class ExpressionVariableModel : public QStandardItemModel Q_INVOKABLE void reloadVariables(); - Q_INVOKABLE bool isEditable( int row ); - Q_INVOKABLE void setName( int row, const QString &name ); Q_INVOKABLE void setValue( int row, const QString &value ); diff --git a/src/qml/VariableEditor.qml b/src/qml/VariableEditor.qml index c869af79f5..fc48df4afe 100644 --- a/src/qml/VariableEditor.qml +++ b/src/qml/VariableEditor.qml @@ -46,7 +46,7 @@ ColumnLayout { color: "transparent" property var itemRow: index - property bool canDelete: table.model.isEditable(index) + property bool canDelete: VariableEditable function forceFocusOnVariableName() { variableNameText.forceActiveFocus(); @@ -72,7 +72,7 @@ ColumnLayout { leftPadding: 1 rightPadding: 1 text: VariableName - enabled: table.model.isEditable(index) + enabled: VariableEditable font: Theme.tipFont horizontalAlignment: TextInput.AlignLeft placeholderText: displayText === '' ? qsTr("Enter name") : '' @@ -109,7 +109,7 @@ ColumnLayout { leftPadding: 1 rightPadding: 1 text: VariableValue - enabled: table.model.isEditable(index) + enabled: VariableEditable font: Theme.tipFont horizontalAlignment: TextInput.AlignLeft placeholderText: displayText === '' ? qsTr("Enter value") : '' From c722f202463ed789ba22e5189a2e561a545d06fc Mon Sep 17 00:00:00 2001 From: Mohsen Date: Wed, 21 Aug 2024 17:48:15 +0330 Subject: [PATCH 5/8] reloadVariables in ExpressionVariableModel::setCurrentProject. --- src/core/expressionvariablemodel.cpp | 7 ++++--- src/core/expressionvariablemodel.h | 2 +- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/core/expressionvariablemodel.cpp b/src/core/expressionvariablemodel.cpp index 60ba3f7c74..5e9f4d5170 100644 --- a/src/core/expressionvariablemodel.cpp +++ b/src/core/expressionvariablemodel.cpp @@ -166,10 +166,11 @@ QgsProject *ExpressionVariableModel::currentProject() const return mCurrentProject; } -void ExpressionVariableModel::setCurrentProject( QgsProject *newCurrentProject ) +void ExpressionVariableModel::setCurrentProject( QgsProject *project ) { - if ( mCurrentProject == newCurrentProject ) + if ( mCurrentProject == project ) return; - mCurrentProject = newCurrentProject; + mCurrentProject = project; + reloadVariables(); emit currentProjectChanged(); } diff --git a/src/core/expressionvariablemodel.h b/src/core/expressionvariablemodel.h index 7e365d4890..3d4a5c5dbb 100644 --- a/src/core/expressionvariablemodel.h +++ b/src/core/expressionvariablemodel.h @@ -59,7 +59,7 @@ class ExpressionVariableModel : public QStandardItemModel QHash roleNames() const override; QgsProject *currentProject() const; - void setCurrentProject( QgsProject *newCurrentProject ); + void setCurrentProject( QgsProject *project ); signals: void currentProjectChanged(); From 4f31c9332bc1aa6a294b68bd0cd8f408cf72d128 Mon Sep 17 00:00:00 2001 From: Mohsen Date: Thu, 22 Aug 2024 11:49:31 +0330 Subject: [PATCH 6/8] Add documentation as mentioned in PR. --- src/core/expressionvariablemodel.h | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/core/expressionvariablemodel.h b/src/core/expressionvariablemodel.h index 3d4a5c5dbb..b8daf1f662 100644 --- a/src/core/expressionvariablemodel.h +++ b/src/core/expressionvariablemodel.h @@ -58,7 +58,14 @@ class ExpressionVariableModel : public QStandardItemModel QHash roleNames() const override; + /** + * Returns the current project used to retrieve variables from. + */ QgsProject *currentProject() const; + + /** + * Sets the project used to retrieve variables from. + */ void setCurrentProject( QgsProject *project ); signals: From 2bdadca70b28ed10fcfb4d9d56fceeedfa1e3167 Mon Sep 17 00:00:00 2001 From: Mohsen Date: Fri, 23 Aug 2024 13:26:35 +0330 Subject: [PATCH 7/8] Insertion to the end of app variable list. merge issue remains. --- src/core/expressionvariablemodel.cpp | 27 +++++++++++++-------------- src/core/expressionvariablemodel.h | 2 +- src/qml/VariableEditor.qml | 13 ++++++++++--- 3 files changed, 24 insertions(+), 18 deletions(-) diff --git a/src/core/expressionvariablemodel.cpp b/src/core/expressionvariablemodel.cpp index 5e9f4d5170..244b6e52ca 100644 --- a/src/core/expressionvariablemodel.cpp +++ b/src/core/expressionvariablemodel.cpp @@ -35,7 +35,7 @@ bool ExpressionVariableModel::setData( const QModelIndex &index, const QVariant return QStandardItemModel::setData( index, value, role ); } -void ExpressionVariableModel::addCustomVariable( const QString &varName, const QString &varVal ) +void ExpressionVariableModel::addCustomVariable( const QString &varName, const QString &varVal, const int &rowIndex ) { QStandardItem *nameItem = new QStandardItem( varName ); nameItem->setData( varName, VariableName ); @@ -43,7 +43,7 @@ void ExpressionVariableModel::addCustomVariable( const QString &varName, const Q nameItem->setData( QVariant::fromValue( VariableScope::ApplicationScope ), VariableScopeRole ); nameItem->setData( true, VariableEditable ); - insertRow( rowCount(), QList() << nameItem ); + insertRow( rowIndex == -1 ? rowCount() : rowIndex, QList() << nameItem ); } void ExpressionVariableModel::removeCustomVariable( int row ) @@ -88,12 +88,20 @@ void ExpressionVariableModel::reloadVariables() nameItem->setData( varValue, VariableValue ); nameItem->setData( QVariant::fromValue( VariableScope::ApplicationScope ), VariableScopeRole ); nameItem->setData( false, VariableEditable ); + nameItem->setEditable( false ); insertRow( rowCount(), QList() << nameItem ); } } - - // Second add readonly project variables + // Second add custom variables + for ( const QString &varName : variableNames ) + { + if ( !scope->isReadOnly( varName ) ) + { + addCustomVariable( varName, scope->variable( varName ).toString() ); + } + } + // Finally add readonly project variables QVariantMap projectVariables = ExpressionContextUtils::projectVariables( mCurrentProject ); for ( const QString &varName : projectVariables.keys() ) { @@ -104,19 +112,10 @@ void ExpressionVariableModel::reloadVariables() nameItem->setData( varValue, VariableValue ); nameItem->setData( QVariant::fromValue( VariableScope::ProjectScope ), VariableScopeRole ); nameItem->setData( false, VariableEditable ); + nameItem->setEditable( false ); insertRow( rowCount(), QList() << nameItem ); } - - - // Then add custom variables - for ( const QString &varName : variableNames ) - { - if ( !scope->isReadOnly( varName ) ) - { - addCustomVariable( varName, scope->variable( varName ).toString() ); - } - } } void ExpressionVariableModel::setName( int row, const QString &name ) diff --git a/src/core/expressionvariablemodel.h b/src/core/expressionvariablemodel.h index b8daf1f662..56be49dd26 100644 --- a/src/core/expressionvariablemodel.h +++ b/src/core/expressionvariablemodel.h @@ -44,7 +44,7 @@ class ExpressionVariableModel : public QStandardItemModel bool setData( const QModelIndex &index, const QVariant &value, int role ) override; - Q_INVOKABLE void addCustomVariable( const QString &varName, const QString &varVal ); + Q_INVOKABLE void addCustomVariable( const QString &varName, const QString &varVal, const int &rowIndex = -1 ); Q_INVOKABLE void removeCustomVariable( int row ); diff --git a/src/qml/VariableEditor.qml b/src/qml/VariableEditor.qml index fc48df4afe..73564e6577 100644 --- a/src/qml/VariableEditor.qml +++ b/src/qml/VariableEditor.qml @@ -47,6 +47,7 @@ ColumnLayout { property var itemRow: index property bool canDelete: VariableEditable + property var variableType: VariableScope function forceFocusOnVariableName() { variableNameText.forceActiveFocus(); @@ -156,9 +157,15 @@ ColumnLayout { text: qsTr("Add a new variable") onClicked: { - table.model.addCustomVariable("new_variable", ""); - table.positionViewAtIndex(table.count - 1, ListView.visible); - table.itemAtIndex(table.count - 1).forceFocusOnVariableName(); + let lastAppVariableIndex = 0; + for (let i = 0; i < table.count; ++i) { + if (table.itemAtIndex(i) && table.itemAtIndex(i).variableType === 0) { + lastAppVariableIndex = i; + } + } + table.model.addCustomVariable("new_variable", "", lastAppVariableIndex + 1); + table.positionViewAtIndex(lastAppVariableIndex + 1, ListView.Contain); + table.itemAtIndex(lastAppVariableIndex + 1).forceFocusOnVariableName(); } } } From facb371503434a45ee764482104f77884484fd9b Mon Sep 17 00:00:00 2001 From: Mohsen Date: Sat, 24 Aug 2024 12:21:36 +0330 Subject: [PATCH 8/8] Refactore addCustomVariable and removeCustomVariable. --- src/core/expressionvariablemodel.cpp | 42 +++++++++++++++++++++------- src/core/expressionvariablemodel.h | 4 +-- src/qml/VariableEditor.qml | 16 ++++------- 3 files changed, 39 insertions(+), 23 deletions(-) diff --git a/src/core/expressionvariablemodel.cpp b/src/core/expressionvariablemodel.cpp index 244b6e52ca..450b78ba61 100644 --- a/src/core/expressionvariablemodel.cpp +++ b/src/core/expressionvariablemodel.cpp @@ -35,20 +35,42 @@ bool ExpressionVariableModel::setData( const QModelIndex &index, const QVariant return QStandardItemModel::setData( index, value, role ); } -void ExpressionVariableModel::addCustomVariable( const QString &varName, const QString &varVal, const int &rowIndex ) +int ExpressionVariableModel::addVariable( VariableScope scope, const QString &name, const QString &value ) { - QStandardItem *nameItem = new QStandardItem( varName ); - nameItem->setData( varName, VariableName ); - nameItem->setData( varVal, VariableValue ); - nameItem->setData( QVariant::fromValue( VariableScope::ApplicationScope ), VariableScopeRole ); - nameItem->setData( true, VariableEditable ); + int lastVariableInScope = rowCount(); + for ( int i = 0; i < rowCount(); ++i ) + { + if ( item( i )->data( VariableScopeRole ).value() == scope ) + { + lastVariableInScope = i; + } + } + + QStandardItem *nameItem = new QStandardItem( name ); + nameItem->setData( name, VariableName ); + nameItem->setData( value, VariableValue ); + nameItem->setData( QVariant::fromValue( scope ), VariableScopeRole ); + nameItem->setData( scope == VariableScope::ApplicationScope, VariableEditable ); + + insertRow( lastVariableInScope + 1, QList() << nameItem ); - insertRow( rowIndex == -1 ? rowCount() : rowIndex, QList() << nameItem ); + return lastVariableInScope + 1; } -void ExpressionVariableModel::removeCustomVariable( int row ) +void ExpressionVariableModel::removeVariable( VariableScope scope, const QString &name ) { - removeRow( row ); + for ( int i = 0; i < rowCount(); ++i ) + { + QStandardItem *rowItem = item( i ); + QString variableName = rowItem->data( VariableName ).toString(); + VariableScope variableScope = rowItem->data( VariableScopeRole ).value(); + + if ( variableName == name && variableScope == scope ) + { + removeRow( i ); + return; + } + } } void ExpressionVariableModel::save() @@ -98,7 +120,7 @@ void ExpressionVariableModel::reloadVariables() { if ( !scope->isReadOnly( varName ) ) { - addCustomVariable( varName, scope->variable( varName ).toString() ); + addVariable( VariableScope::ApplicationScope, varName, scope->variable( varName ).toString() ); } } // Finally add readonly project variables diff --git a/src/core/expressionvariablemodel.h b/src/core/expressionvariablemodel.h index 56be49dd26..6fc4b52b9b 100644 --- a/src/core/expressionvariablemodel.h +++ b/src/core/expressionvariablemodel.h @@ -44,9 +44,9 @@ class ExpressionVariableModel : public QStandardItemModel bool setData( const QModelIndex &index, const QVariant &value, int role ) override; - Q_INVOKABLE void addCustomVariable( const QString &varName, const QString &varVal, const int &rowIndex = -1 ); + Q_INVOKABLE int addVariable( VariableScope scope, const QString &name, const QString &value ); - Q_INVOKABLE void removeCustomVariable( int row ); + Q_INVOKABLE void removeVariable( VariableScope scope, const QString &name ); Q_INVOKABLE void save(); diff --git a/src/qml/VariableEditor.qml b/src/qml/VariableEditor.qml index 73564e6577..f4f78ac55b 100644 --- a/src/qml/VariableEditor.qml +++ b/src/qml/VariableEditor.qml @@ -47,7 +47,6 @@ ColumnLayout { property var itemRow: index property bool canDelete: VariableEditable - property var variableType: VariableScope function forceFocusOnVariableName() { variableNameText.forceActiveFocus(); @@ -143,7 +142,7 @@ ColumnLayout { bgcolor: "transparent" onClicked: { - table.model.removeCustomVariable(index); + table.model.removeVariable(VariableScope, variableNameText.text); } } } @@ -157,15 +156,10 @@ ColumnLayout { text: qsTr("Add a new variable") onClicked: { - let lastAppVariableIndex = 0; - for (let i = 0; i < table.count; ++i) { - if (table.itemAtIndex(i) && table.itemAtIndex(i).variableType === 0) { - lastAppVariableIndex = i; - } - } - table.model.addCustomVariable("new_variable", "", lastAppVariableIndex + 1); - table.positionViewAtIndex(lastAppVariableIndex + 1, ListView.Contain); - table.itemAtIndex(lastAppVariableIndex + 1).forceFocusOnVariableName(); + let applicationScope = 0; + let insertionPosition = table.model.addVariable(applicationScope, "new_variable", ""); + table.positionViewAtIndex(insertionPosition, ListView.Contain); + table.itemAtIndex(insertionPosition).forceFocusOnVariableName(); } } }