Fix adding new keys

This commit is contained in:
Igor Malinovskiy
2018-01-26 18:18:42 +02:00
parent fa72a2482a
commit da0f6e9c59
12 changed files with 77 additions and 28 deletions
+16
View File
@@ -6,6 +6,8 @@
#include <QtCharts/QDateTimeAxis>
#include <QDateTime>
#include "value-editor/largetextmodel.h"
bool QmlUtils::isBinaryString(const QVariant &value)
{
if (!value.canConvert(QVariant::ByteArray)) {
@@ -149,3 +151,17 @@ void QmlUtils::addNewValueToDynamicChart(QtCharts::QXYSeries *series, double val
ax->setMax(QDateTime::currentDateTime());
}
}
QObject *QmlUtils::wrapLargeText(const QByteArray &text)
{
auto w = new ValueEditor::LargeTextWrappingModel(QString::fromUtf8(text));
w->setParent(this);
return w;
}
void QmlUtils::deleteTextWrapper(QObject *w)
{
if (w && w->parent() == this) {
w->deleteLater();
}
}
+2
View File
@@ -20,4 +20,6 @@ public:
Q_INVOKABLE QString getPathFromUrl(const QUrl &url);
Q_INVOKABLE void copyToClipboard(const QString &text);
Q_INVOKABLE void addNewValueToDynamicChart(QtCharts::QXYSeries* series, double value);
Q_INVOKABLE QObject* wrapLargeText(const QByteArray &text);
Q_INVOKABLE void deleteTextWrapper(QObject* w);
};
+16 -6
View File
@@ -1,15 +1,15 @@
#include "largetextmodel.h"
#include <QDebug>
ValueEditor::LargeTextWrappingModel::LargeTextWrappingModel(const QString &text, uint chunkSize)
: m_chunkSize(chunkSize)
{
m_textRows.reserve(text.size()/chunkSize);
setText(text);
}
for (uint chunkIndex=0; chunkIndex < text.size()/chunkSize + 1; chunkIndex++)
{
m_textRows.append(text.mid(chunkIndex * chunkSize, chunkSize));
}
ValueEditor::LargeTextWrappingModel::~LargeTextWrappingModel()
{
qDebug() << "{DELETE}: Largetext model";
}
QHash<int, QByteArray> ValueEditor::LargeTextWrappingModel::roleNames() const
@@ -36,6 +36,16 @@ QVariant ValueEditor::LargeTextWrappingModel::data(const QModelIndex &index, int
return QVariant();
}
void ValueEditor::LargeTextWrappingModel::setText(const QString &text)
{
m_textRows.reserve(text.size()/m_chunkSize);
for (uint chunkIndex=0; chunkIndex < text.size()/m_chunkSize + 1; chunkIndex++)
{
m_textRows.append(text.mid(chunkIndex * m_chunkSize, m_chunkSize));
}
}
void ValueEditor::LargeTextWrappingModel::cleanUp()
{
emit beginRemoveRows(QModelIndex(), 0, rowCount());
+3 -1
View File
@@ -14,7 +14,7 @@ class LargeTextWrappingModel : public QAbstractListModel
public:
LargeTextWrappingModel(const QString& text=QString(), uint chunkSize=10000);
~LargeTextWrappingModel() {}
~LargeTextWrappingModel();
QHash<int, QByteArray> roleNames() const;
@@ -22,6 +22,8 @@ public:
QVariant data(const QModelIndex &index, int role) const;
void setText(const QString& text);
public slots:
void cleanUp();
@@ -2,8 +2,6 @@
#include <QDebug>
#include <QSettings>
#include "largetextmodel.h"
ValueEditor::ValueViewModel::ValueViewModel(Model &model)
: QAbstractListModel((QObject*)model.getConnector().data()),
m_model(model),
@@ -55,13 +53,6 @@ QVariantList ValueEditor::ValueViewModel::getColumnNames()
return result;
}
QObject *ValueEditor::ValueViewModel::wrapLargeText(const QByteArray &text)
{
auto w = new LargeTextWrappingModel(QString::fromUtf8(text));
w->setParent(this);
return w;
}
bool ValueEditor::ValueViewModel::isMultiRow()
{
return m_model.isMultiRow();
+1 -3
View File
@@ -34,9 +34,7 @@ public:
Q_INVOKABLE int pageSize();
// general operations
Q_INVOKABLE QVariantList getColumnNames();
Q_INVOKABLE QObject* wrapLargeText(const QByteArray &text);
Q_INVOKABLE QVariantList getColumnNames();
signals:
void rowsLoaded(int start, int count);
+2 -3
View File
@@ -42,9 +42,6 @@ Dialog {
objectName: "rdm_add_key_type_field"
}
Text {
text: qsTr("Value:")
}
Loader {
id: valueAddEditor
Layout.fillWidth: true
@@ -55,6 +52,7 @@ Dialog {
onLoaded: {
item.state = "new"
item.initEmpty()
}
}
@@ -88,6 +86,7 @@ Dialog {
if (!err) {
newKeyName.text = ''
valueAddEditor.item.reset()
valueAddEditor.item.initEmpty()
root.close()
} else {
addError.text = err
@@ -14,6 +14,10 @@ ColumnLayout {
State { name: "edit"} // Editing existing key
]
function initEmpty() {
console.exception("Not implemented")
}
function validateValue(callback) {
console.exception("Not implemented")
}
@@ -34,6 +34,11 @@ AbstractEditor {
objectName: "rdm_key_hash_text_field"
}
function initEmpty() {
keyText.initEmpty()
textArea.initEmpty()
}
function validateValue(callback) {
return textArea.validate(function (textAreaValid) {
keyText.validate(function (keyTextValid) {
@@ -16,6 +16,14 @@ ColumnLayout
property string fieldLabel: qsTr("Value:")
property bool isEdited: false
property var value
property int valueSizeLimit: 150000
function initEmpty() {
// init editor with empty model
textView.model = qmlUtils.wrapLargeText("")
textView.readOnly = false
textView.textFormat = TextEdit.PlainText
}
function validate(callback) {
loadRawValue(function (error, raw) {
@@ -55,7 +63,7 @@ ColumnLayout
return;
}
if (binaryUtils.binaryStringLength(root.value) > 150000) {
if (binaryUtils.binaryStringLength(root.value) > valueSizeLimit) {
root.showFormatters = false
formatterSelector.currentIndex = 0
} else {
@@ -87,14 +95,14 @@ ColumnLayout
if (format === "json") {
// 1 is JSON
return formatterSelector.model[1].instance.getFormatted(formatted, function (formattedJson, r, f) {
textView.model = keyTab.keyModel.wrapLargeText(formattedJson)
textView.model = qmlUtils.wrapLargeText(formattedJson)
textView.readOnly = isReadOnly
textView.textFormat = TextEdit.PlainText
root.isEdited = false
uiBlocker.visible = false
})
} else {
textView.model = keyTab.keyModel.wrapLargeText(formatted)
textView.model = qmlUtils.wrapLargeText(formatted)
textView.readOnly = isReadOnly
root.isEdited = false
@@ -111,6 +119,11 @@ ColumnLayout
function reset() {
if (textView.model)
textView.model.cleanUp()
if (textView.model) {
qmlUtils.deleteTextWrapper(textView.model)
}
textView.model = null
root.value = ""
root.isEdited = false
@@ -152,10 +165,11 @@ ColumnLayout
}
}
Text { visible: !showFormatters; text: qsTr("Large value (>150kB). Formatters is not available."); color: "red"; }
Text { visible: !showFormatters && binaryUtils.binaryStringLength(root.value) > valueSizeLimit; text: qsTr("Large value (>150kB). Formatters is not available."); color: "red"; }
}
Rectangle {
id: texteditorWrapper
Layout.fillWidth: true
Layout.fillHeight: true
Layout.preferredHeight: 100
@@ -181,7 +195,7 @@ ColumnLayout
NewTextArea {
id: textAreaPart
width: textView.width
height: textAreaPart.contentHeight
height: textAreaPart.contentHeight < texteditorWrapper.height? texteditorWrapper.height - 5 : textAreaPart.contentHeight
enabled: root.enabled
text: value
@@ -216,5 +230,5 @@ ColumnLayout
}
MouseArea { anchors.fill: parent }
}
}
}
@@ -21,6 +21,10 @@ AbstractEditor {
showFormatters: root.state == "edit"
}
function initEmpty() {
textEditor.initEmpty()
}
function validateValue(callback) {
return textEditor.validate(callback);
}
@@ -54,6 +54,10 @@ AbstractEditor {
objectName: "rdm_key_zset_text_field"
}
function initEmpty() {
textArea.initEmpty()
}
function validateValue(callback) {
return textArea.validate(callback);
}