From a0581f28aaaa0b13df7513d2461954d1848c3076 Mon Sep 17 00:00:00 2001 From: Just Wonder Date: Sun, 12 Apr 2020 21:21:56 -0700 Subject: [PATCH] WIP: allow modification of value. --- src/qt/forms/kevadetaildialog.ui | 4 ++-- src/qt/kevadetaildialog.cpp | 34 +++++++++++++++++++++++++++++--- src/qt/kevadetaildialog.h | 8 +++++++- src/qt/kevadialog.cpp | 3 ++- 4 files changed, 42 insertions(+), 7 deletions(-) diff --git a/src/qt/forms/kevadetaildialog.ui b/src/qt/forms/kevadetaildialog.ui index 8788f55e6..6bb86bbd8 100644 --- a/src/qt/forms/kevadetaildialog.ui +++ b/src/qt/forms/kevadetaildialog.ui @@ -20,7 +20,7 @@ This pane shows the value associated with a give key - true + false @@ -30,7 +30,7 @@ Qt::Horizontal - QDialogButtonBox::Close + QDialogButtonBox::Close|QDialogButtonBox::Save diff --git a/src/qt/kevadetaildialog.cpp b/src/qt/kevadetaildialog.cpp index 0da1ea9b7..8e9376dd4 100644 --- a/src/qt/kevadetaildialog.cpp +++ b/src/qt/kevadetaildialog.cpp @@ -6,23 +6,51 @@ #include #include +#include #include +#include -KevaDetailDialog::KevaDetailDialog(const QModelIndex &idx, QWidget *parent) : + +KevaDetailDialog::KevaDetailDialog(const QModelIndex &idx, QWidget *parent, const QString &nameSpace) : QDialog(parent), ui(new Ui::KevaDetailDialog) { ui->setupUi(this); QModelIndex keyIdx = idx.sibling(idx.row(), KevaTableModel::Key); QModelIndex valueIdx = idx.sibling(idx.row(), KevaTableModel::Value); - setWindowTitle(tr("Value for %1").arg(keyIdx.data(Qt::DisplayRole).toString())); + this->nameSpace = nameSpace; + key = keyIdx.data(Qt::DisplayRole).toString(); + setWindowTitle(tr("Value for %1").arg(key)); QString desc = valueIdx.data(Qt::DisplayRole).toString(); + connect(ui->detailText, SIGNAL(textChanged()), this, SLOT(onValueChanged())); //ui->detailText->setHtml(desc); ui->detailText->setPlainText(desc); + ui->buttonBox->button(QDialogButtonBox::Save)->setEnabled(false); + connect(ui->buttonBox->button(QDialogButtonBox::Save), SIGNAL(clicked()), this, SLOT(onSave())); } KevaDetailDialog::~KevaDetailDialog() { delete ui; -} \ No newline at end of file +} + +void KevaDetailDialog::onValueChanged() +{ + bool enabled = ui->detailText->toPlainText().length() > 0; + ui->buttonBox->button(QDialogButtonBox::Save)->setEnabled(enabled); +} + +void KevaDetailDialog::onSave() +{ + KevaDialog* dialog = (KevaDialog*)this->parentWidget(); + std::string keyText = key.toStdString(); + std::string valueText = ui->detailText->toPlainText().toStdString(); + std::string ns = nameSpace.toStdString(); + if (!dialog->addKeyValue(ns, keyText, valueText)) { + QDialog::close(); + return; + } + dialog->showNamespace(nameSpace); + QDialog::close(); +} diff --git a/src/qt/kevadetaildialog.h b/src/qt/kevadetaildialog.h index a4a43e105..597eb1bc4 100644 --- a/src/qt/kevadetaildialog.h +++ b/src/qt/kevadetaildialog.h @@ -24,11 +24,17 @@ class KevaDetailDialog : public QDialog Q_OBJECT public: - explicit KevaDetailDialog(const QModelIndex &idx, QWidget *parent = 0); + explicit KevaDetailDialog(const QModelIndex &idx, QWidget *parent, const QString &nameSpace); ~KevaDetailDialog(); +public Q_SLOTS: + void onValueChanged(); + void onSave(); + private: Ui::KevaDetailDialog *ui; + QString nameSpace; + QString key; }; #endif // BITCOIN_QT_KEVADETAILDIALOG_H diff --git a/src/qt/kevadialog.cpp b/src/qt/kevadialog.cpp index f1e0add02..c9e5230ca 100644 --- a/src/qt/kevadialog.cpp +++ b/src/qt/kevadialog.cpp @@ -207,7 +207,8 @@ void KevaDialog::on_showContent_clicked() void KevaDialog::on_kevaView_doubleClicked(const QModelIndex &index) { - KevaDetailDialog *dialog = new KevaDetailDialog(index, this); + QString nameSpace = ui->nameSpace->text(); + KevaDetailDialog *dialog = new KevaDetailDialog(index, this, nameSpace); dialog->setAttribute(Qt::WA_DeleteOnClose); dialog->show(); }