Skip to content

Commit f13f47a

Browse files
committed
Fix issues in New Key dialog
1 parent c121732 commit f13f47a

File tree

6 files changed

+29
-17
lines changed

6 files changed

+29
-17
lines changed

src/modules/value-editor/viewmodel.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -106,15 +106,17 @@ QHash<int, QByteArray> ValueEditor::ViewModel::roleNames() const
106106
return roles;
107107
}
108108

109-
void ValueEditor::ViewModel::addKey(QString keyName, QString keyType, const QVariantMap &row)
109+
void ValueEditor::ViewModel::addKey(QString keyName, QString keyType,
110+
const QVariantMap &row, QJSValue jsCallback)
110111
{
111112
try {
112113
m_keyFactory->addKey(m_newKeyRequest.first,
113114
keyName.toUtf8(), m_newKeyRequest.second,
114115
keyType, row);
115116
m_newKeyCallback();
116-
} catch (const Model::Exception& e) {
117-
emit keyError(-1, "Can't add new key: " + QString(e.what()));
117+
jsCallback.call(QJSValueList {});
118+
} catch (const Model::Exception& e) {
119+
jsCallback.call(QJSValueList { "Can't add new key: " + QString(e.what()) });
118120
}
119121
}
120122

src/modules/value-editor/viewmodel.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include <QPair>
66
#include <QByteArray>
77
#include <QSharedPointer>
8+
#include <QJSValue>
89
#include "abstractkeyfactory.h"
910
#include "keymodel.h"
1011

@@ -41,7 +42,8 @@ class ViewModel : public QAbstractListModel
4142

4243

4344
public: // methods exported to QML
44-
Q_INVOKABLE void addKey(QString keyName, QString keyType, const QVariantMap &row);
45+
Q_INVOKABLE void addKey(QString keyName, QString keyType,
46+
const QVariantMap &row, QJSValue jsCallback);
4547
Q_INVOKABLE void renameKey(int index, const QString& newKeyName);
4648
Q_INVOKABLE void removeKey(int i);
4749
Q_INVOKABLE void closeTab(int i);

src/resources/qml/AddKeyDialog.qml

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -77,13 +77,21 @@ Item {
7777
}
7878

7979
var row = valueAddEditor.item.getValue()
80-
viewModel.addKey(newKeyName.text,
81-
typeSelector.model[typeSelector.currentIndex],
82-
row)
83-
84-
newKeyName.text = ''
85-
valueAddEditor.item.reset()
86-
root.close()
80+
viewModel.addKey(
81+
newKeyName.text,
82+
typeSelector.model[typeSelector.currentIndex],
83+
row,
84+
function callback(err) {
85+
if (!err) {
86+
newKeyName.text = ''
87+
valueAddEditor.item.reset()
88+
root.close()
89+
} else {
90+
addError.text = err
91+
addError.open()
92+
}
93+
}
94+
)
8795
}
8896
}
8997

@@ -97,12 +105,12 @@ Item {
97105
}
98106

99107
MessageDialog {
100-
id: addConfirmation
101-
title: "Save value"
108+
id: addError
109+
title: "Error"
102110
text: ""
103111
visible: false
104112
modality: Qt.ApplicationModal
105-
icon: StandardIcon.Information
113+
icon: StandardIcon.Warning
106114
standardButtons: StandardButton.Ok
107115
}
108116
}

src/resources/qml/editors/HashItemEditor.qml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ AbstractEditor {
2020
value: ""
2121
enabled: originalValue != "" || root.state !== "edit"
2222
property var originalValue: ""
23+
showFormatters: root.state != "new"
2324

2425
style: TextAreaStyle {
2526
backgroundColor: (!keyText.value && keyText.enabled

src/resources/qml/editors/SingleItemEditor.qml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ AbstractEditor {
5252
}
5353

5454
function reset() {
55-
textArea.text = ''
55+
textArea.value = ''
5656
console.log("reset")
5757
}
5858
}

src/resources/qml/value-editor.qml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,8 +134,7 @@ Rectangle {
134134
tabs.removeTab(0)
135135
}
136136

137-
onNewKeyDialog: {
138-
console.log(dbIdentificationString, keyPrefix)
137+
onNewKeyDialog: {
139138
addNewKeyDialog.open()
140139
}
141140
}

0 commit comments

Comments
 (0)