Skip to content

Commit da0f6e9

Browse files
committed
Fix adding new keys
1 parent fa72a24 commit da0f6e9

File tree

12 files changed

+77
-28
lines changed

12 files changed

+77
-28
lines changed

src/app/qmlutils.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
#include <QtCharts/QDateTimeAxis>
77
#include <QDateTime>
88

9+
#include "value-editor/largetextmodel.h"
10+
911
bool QmlUtils::isBinaryString(const QVariant &value)
1012
{
1113
if (!value.canConvert(QVariant::ByteArray)) {
@@ -149,3 +151,17 @@ void QmlUtils::addNewValueToDynamicChart(QtCharts::QXYSeries *series, double val
149151
ax->setMax(QDateTime::currentDateTime());
150152
}
151153
}
154+
155+
QObject *QmlUtils::wrapLargeText(const QByteArray &text)
156+
{
157+
auto w = new ValueEditor::LargeTextWrappingModel(QString::fromUtf8(text));
158+
w->setParent(this);
159+
return w;
160+
}
161+
162+
void QmlUtils::deleteTextWrapper(QObject *w)
163+
{
164+
if (w && w->parent() == this) {
165+
w->deleteLater();
166+
}
167+
}

src/app/qmlutils.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,6 @@ class QmlUtils : public QObject
2020
Q_INVOKABLE QString getPathFromUrl(const QUrl &url);
2121
Q_INVOKABLE void copyToClipboard(const QString &text);
2222
Q_INVOKABLE void addNewValueToDynamicChart(QtCharts::QXYSeries* series, double value);
23+
Q_INVOKABLE QObject* wrapLargeText(const QByteArray &text);
24+
Q_INVOKABLE void deleteTextWrapper(QObject* w);
2325
};

src/modules/value-editor/largetextmodel.cpp

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
#include "largetextmodel.h"
2-
2+
#include <QDebug>
33

44
ValueEditor::LargeTextWrappingModel::LargeTextWrappingModel(const QString &text, uint chunkSize)
55
: m_chunkSize(chunkSize)
66
{
7-
m_textRows.reserve(text.size()/chunkSize);
7+
setText(text);
8+
}
89

9-
for (uint chunkIndex=0; chunkIndex < text.size()/chunkSize + 1; chunkIndex++)
10-
{
11-
m_textRows.append(text.mid(chunkIndex * chunkSize, chunkSize));
12-
}
10+
ValueEditor::LargeTextWrappingModel::~LargeTextWrappingModel()
11+
{
12+
qDebug() << "{DELETE}: Largetext model";
1313
}
1414

1515
QHash<int, QByteArray> ValueEditor::LargeTextWrappingModel::roleNames() const
@@ -36,6 +36,16 @@ QVariant ValueEditor::LargeTextWrappingModel::data(const QModelIndex &index, int
3636
return QVariant();
3737
}
3838

39+
void ValueEditor::LargeTextWrappingModel::setText(const QString &text)
40+
{
41+
m_textRows.reserve(text.size()/m_chunkSize);
42+
43+
for (uint chunkIndex=0; chunkIndex < text.size()/m_chunkSize + 1; chunkIndex++)
44+
{
45+
m_textRows.append(text.mid(chunkIndex * m_chunkSize, m_chunkSize));
46+
}
47+
}
48+
3949
void ValueEditor::LargeTextWrappingModel::cleanUp()
4050
{
4151
emit beginRemoveRows(QModelIndex(), 0, rowCount());

src/modules/value-editor/largetextmodel.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,16 @@ class LargeTextWrappingModel : public QAbstractListModel
1414
public:
1515
LargeTextWrappingModel(const QString& text=QString(), uint chunkSize=10000);
1616

17-
~LargeTextWrappingModel() {}
17+
~LargeTextWrappingModel();
1818

1919
QHash<int, QByteArray> roleNames() const;
2020

2121
int rowCount(const QModelIndex &parent = QModelIndex()) const override;
2222

2323
QVariant data(const QModelIndex &index, int role) const;
2424

25+
void setText(const QString& text);
26+
2527
public slots:
2628
void cleanUp();
2729

src/modules/value-editor/valueviewmodel.cpp

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
#include <QDebug>
33
#include <QSettings>
44

5-
#include "largetextmodel.h"
6-
75
ValueEditor::ValueViewModel::ValueViewModel(Model &model)
86
: QAbstractListModel((QObject*)model.getConnector().data()),
97
m_model(model),
@@ -55,13 +53,6 @@ QVariantList ValueEditor::ValueViewModel::getColumnNames()
5553
return result;
5654
}
5755

58-
QObject *ValueEditor::ValueViewModel::wrapLargeText(const QByteArray &text)
59-
{
60-
auto w = new LargeTextWrappingModel(QString::fromUtf8(text));
61-
w->setParent(this);
62-
return w;
63-
}
64-
6556
bool ValueEditor::ValueViewModel::isMultiRow()
6657
{
6758
return m_model.isMultiRow();

src/modules/value-editor/valueviewmodel.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,7 @@ class ValueViewModel : public QAbstractListModel
3434
Q_INVOKABLE int pageSize();
3535

3636
// general operations
37-
Q_INVOKABLE QVariantList getColumnNames();
38-
39-
Q_INVOKABLE QObject* wrapLargeText(const QByteArray &text);
37+
Q_INVOKABLE QVariantList getColumnNames();
4038

4139
signals:
4240
void rowsLoaded(int start, int count);

src/qml/value-editor/AddKeyDialog.qml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,6 @@ Dialog {
4242
objectName: "rdm_add_key_type_field"
4343
}
4444

45-
Text {
46-
text: qsTr("Value:")
47-
}
4845
Loader {
4946
id: valueAddEditor
5047
Layout.fillWidth: true
@@ -55,6 +52,7 @@ Dialog {
5552

5653
onLoaded: {
5754
item.state = "new"
55+
item.initEmpty()
5856
}
5957
}
6058

@@ -88,6 +86,7 @@ Dialog {
8886
if (!err) {
8987
newKeyName.text = ''
9088
valueAddEditor.item.reset()
89+
valueAddEditor.item.initEmpty()
9190
root.close()
9291
} else {
9392
addError.text = err

src/qml/value-editor/editors/AbstractEditor.qml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ ColumnLayout {
1414
State { name: "edit"} // Editing existing key
1515
]
1616

17+
function initEmpty() {
18+
console.exception("Not implemented")
19+
}
20+
1721
function validateValue(callback) {
1822
console.exception("Not implemented")
1923
}

src/qml/value-editor/editors/HashItemEditor.qml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,11 @@ AbstractEditor {
3434
objectName: "rdm_key_hash_text_field"
3535
}
3636

37+
function initEmpty() {
38+
keyText.initEmpty()
39+
textArea.initEmpty()
40+
}
41+
3742
function validateValue(callback) {
3843
return textArea.validate(function (textAreaValid) {
3944
keyText.validate(function (keyTextValid) {

src/qml/value-editor/editors/MultilineEditor.qml

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,14 @@ ColumnLayout
1616
property string fieldLabel: qsTr("Value:")
1717
property bool isEdited: false
1818
property var value
19+
property int valueSizeLimit: 150000
20+
21+
function initEmpty() {
22+
// init editor with empty model
23+
textView.model = qmlUtils.wrapLargeText("")
24+
textView.readOnly = false
25+
textView.textFormat = TextEdit.PlainText
26+
}
1927

2028
function validate(callback) {
2129
loadRawValue(function (error, raw) {
@@ -55,7 +63,7 @@ ColumnLayout
5563
return;
5664
}
5765

58-
if (binaryUtils.binaryStringLength(root.value) > 150000) {
66+
if (binaryUtils.binaryStringLength(root.value) > valueSizeLimit) {
5967
root.showFormatters = false
6068
formatterSelector.currentIndex = 0
6169
} else {
@@ -87,14 +95,14 @@ ColumnLayout
8795
if (format === "json") {
8896
// 1 is JSON
8997
return formatterSelector.model[1].instance.getFormatted(formatted, function (formattedJson, r, f) {
90-
textView.model = keyTab.keyModel.wrapLargeText(formattedJson)
98+
textView.model = qmlUtils.wrapLargeText(formattedJson)
9199
textView.readOnly = isReadOnly
92100
textView.textFormat = TextEdit.PlainText
93101
root.isEdited = false
94102
uiBlocker.visible = false
95103
})
96104
} else {
97-
textView.model = keyTab.keyModel.wrapLargeText(formatted)
105+
textView.model = qmlUtils.wrapLargeText(formatted)
98106
textView.readOnly = isReadOnly
99107
root.isEdited = false
100108

@@ -111,6 +119,11 @@ ColumnLayout
111119
function reset() {
112120
if (textView.model)
113121
textView.model.cleanUp()
122+
123+
if (textView.model) {
124+
qmlUtils.deleteTextWrapper(textView.model)
125+
}
126+
114127
textView.model = null
115128
root.value = ""
116129
root.isEdited = false
@@ -152,10 +165,11 @@ ColumnLayout
152165
}
153166
}
154167

155-
Text { visible: !showFormatters; text: qsTr("Large value (>150kB). Formatters is not available."); color: "red"; }
168+
Text { visible: !showFormatters && binaryUtils.binaryStringLength(root.value) > valueSizeLimit; text: qsTr("Large value (>150kB). Formatters is not available."); color: "red"; }
156169
}
157170

158171
Rectangle {
172+
id: texteditorWrapper
159173
Layout.fillWidth: true
160174
Layout.fillHeight: true
161175
Layout.preferredHeight: 100
@@ -181,7 +195,7 @@ ColumnLayout
181195
NewTextArea {
182196
id: textAreaPart
183197
width: textView.width
184-
height: textAreaPart.contentHeight
198+
height: textAreaPart.contentHeight < texteditorWrapper.height? texteditorWrapper.height - 5 : textAreaPart.contentHeight
185199

186200
enabled: root.enabled
187201
text: value
@@ -216,5 +230,5 @@ ColumnLayout
216230
}
217231

218232
MouseArea { anchors.fill: parent }
219-
}
233+
}
220234
}

0 commit comments

Comments
 (0)