From 5e5867c3b6187df703caa817c98786bcae2b7ae8 Mon Sep 17 00:00:00 2001 From: Just Wonder Date: Sat, 9 May 2020 23:14:38 -0700 Subject: [PATCH] Allowed updating bookmark name. --- src/Makefile.qt.include | 4 ++ src/qt/forms/kevaeditbookmarkdialog.ui | 60 ++++++++++++++++++++++++++ src/qt/kevabookmarksdialog.cpp | 33 +++++++++++++- src/qt/kevabookmarksdialog.h | 2 +- src/qt/kevaeditbookmarkdialog.cpp | 53 +++++++++++++++++++++++ src/qt/kevaeditbookmarkdialog.h | 41 ++++++++++++++++++ src/qt/kevatablemodel.cpp | 2 +- src/qt/locale/bitcoin_en.ts | 39 +++++++++++++---- src/qt/locale/bitcoin_zh_CN.ts | 4 ++ 9 files changed, 227 insertions(+), 11 deletions(-) create mode 100644 src/qt/forms/kevaeditbookmarkdialog.ui create mode 100644 src/qt/kevaeditbookmarkdialog.cpp create mode 100644 src/qt/kevaeditbookmarkdialog.h diff --git a/src/Makefile.qt.include b/src/Makefile.qt.include index 81181b98d..baa779ae4 100644 --- a/src/Makefile.qt.include +++ b/src/Makefile.qt.include @@ -140,6 +140,7 @@ QT_FORMS_UI = \ qt/forms/kevaaddkeydialog.ui \ qt/forms/kevabookmarksdialog.ui \ qt/forms/kevanewnamespacedialog.ui \ + qt/forms/kevaeditbookmarkdialog.ui \ qt/forms/kevamynamespacesdialog.ui \ qt/forms/debugwindow.ui \ qt/forms/sendcoinsdialog.ui \ @@ -186,6 +187,7 @@ QT_MOC_CPP = \ qt/moc_kevaaddkeydialog.cpp \ qt/moc_kevabookmarksdialog.cpp \ qt/moc_kevanewnamespacedialog.cpp \ + qt/moc_kevaeditbookmarkdialog.cpp \ qt/moc_kevamynamespacesdialog.cpp \ qt/moc_rpcconsole.cpp \ qt/moc_sendcoinsdialog.cpp \ @@ -281,6 +283,7 @@ BITCOIN_QT_H = \ qt/kevaaddkeydialog.h \ qt/kevabookmarksdialog.h \ qt/kevanewnamespacedialog.h \ + qt/kevaeditbookmarkdialog.h \ qt/kevamynamespacesdialog.h \ qt/utilitydialog.h \ qt/walletframe.h \ @@ -405,6 +408,7 @@ BITCOIN_QT_WALLET_CPP = \ qt/kevaaddkeydialog.cpp \ qt/kevabookmarksdialog.cpp \ qt/kevanewnamespacedialog.cpp \ + qt/kevaeditbookmarkdialog.cpp \ qt/kevamynamespacesdialog.cpp \ qt/walletframe.cpp \ qt/walletmodel.cpp \ diff --git a/src/qt/forms/kevaeditbookmarkdialog.ui b/src/qt/forms/kevaeditbookmarkdialog.ui new file mode 100644 index 000000000..8e8319c3a --- /dev/null +++ b/src/qt/forms/kevaeditbookmarkdialog.ui @@ -0,0 +1,60 @@ + + + KevaEditBookmarkDialog + + + + 0 + 0 + 400 + 100 + + + + Bookmark Name + + + + + + + + Bookmark name. + + + Name: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + bookmarkName + + + + + + + This pane allows change of bookmark name + + + false + + + + + + + + + Qt::Horizontal + + + QDialogButtonBox::Cancel|QDialogButtonBox::Save + + + + + + + diff --git a/src/qt/kevabookmarksdialog.cpp b/src/qt/kevabookmarksdialog.cpp index 4444a90df..1891274bf 100644 --- a/src/qt/kevabookmarksdialog.cpp +++ b/src/qt/kevabookmarksdialog.cpp @@ -4,6 +4,7 @@ #include #include +#include #include #include @@ -16,9 +17,10 @@ KevaBookmarksDialog::KevaBookmarksDialog(QWidget *parent) : ui(new Ui::KevaBookmarksDialog) { ui->setupUi(this); + ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(false); ui->buttonBox->button(QDialogButtonBox::Save)->setEnabled(false); - ui->buttonBox->button(QDialogButtonBox::Save)->setText(tr("Edit")); + ui->buttonBox->button(QDialogButtonBox::Save)->setText(tr("&Edit")); connect(ui->buttonBox->button(QDialogButtonBox::Cancel), SIGNAL(clicked()), this, SLOT(reject())); connect(ui->buttonBox->button(QDialogButtonBox::Ok), SIGNAL(clicked()), this, SLOT(apply())); connect(ui->buttonBox->button(QDialogButtonBox::Save), SIGNAL(clicked()), this, SLOT(rename())); @@ -78,6 +80,35 @@ void KevaBookmarksDialog::apply() void KevaBookmarksDialog::rename() { + QModelIndex idIdx = selectedIndex.sibling(selectedIndex.row(), KevaBookmarksModel::Id); + QString idStr = idIdx.data(Qt::DisplayRole).toString(); + QModelIndex nameIdx = selectedIndex.sibling(selectedIndex.row(), KevaBookmarksModel::Name); + QString nameStr = nameIdx.data(Qt::DisplayRole).toString(); + KevaEditBookmarkDialog *dialog = new KevaEditBookmarkDialog(this, idStr, nameStr); + dialog->setAttribute(Qt::WA_DeleteOnClose); + dialog->show(); +} + +void KevaBookmarksDialog::saveName(const QString& id, const QString& name) +{ + QJsonArray array; + KevaBookmarksModel* bookmarksModel = this->model->getKevaBookmarksModel(); + bookmarksModel->loadBookmarks(array); + + for (int i = 0; i < array.size(); ++i) { + QJsonObject obj = array[i].toObject(); + BookmarkEntry entry; + QString idStr = obj["id"].toString(); + if (idStr == id) { + QJsonObject entry; + entry["id"] = id; + entry["name"] = name; + array.replace(i, entry); + break; + } + } + bookmarksModel->saveBookmarks(array); + bookmarksModel->loadBookmarks(); } void KevaBookmarksDialog::reject() diff --git a/src/qt/kevabookmarksdialog.h b/src/qt/kevabookmarksdialog.h index cb23951a1..310a1af9f 100644 --- a/src/qt/kevabookmarksdialog.h +++ b/src/qt/kevabookmarksdialog.h @@ -18,7 +18,6 @@ namespace Ui { class KevaBookmarksDialog; } - /** Dialog showing namepsace creation. */ class KevaBookmarksDialog : public QDialog { @@ -39,6 +38,7 @@ public Q_SLOTS: void apply(); void reject(); void rename(); + void saveName(const QString& id, const QString& name); private Q_SLOTS: void namespaceView_selectionChanged(); diff --git a/src/qt/kevaeditbookmarkdialog.cpp b/src/qt/kevaeditbookmarkdialog.cpp new file mode 100644 index 000000000..c866c7ce5 --- /dev/null +++ b/src/qt/kevaeditbookmarkdialog.cpp @@ -0,0 +1,53 @@ +// Copyright (c) 2011-2017 The Bitcoin Core developers +// Distributed under the MIT software license, see the accompanying +// file COPYING or http://www.opensource.org/licenses/mit-license.php. + +#include +#include +#include + +#include +#include + +#include +#include + +KevaEditBookmarkDialog::KevaEditBookmarkDialog(QWidget *parent, const QString& id, const QString& name) : + QDialog(parent), id(id), name(name), + ui(new Ui::KevaEditBookmarkDialog) +{ + ui->setupUi(this); + ui->bookmarkName->setText(name); + this->parentDialog = (KevaBookmarksDialog*)parent; + + connect(ui->buttonBox->button(QDialogButtonBox::Cancel), SIGNAL(clicked()), this, SLOT(close())); + connect(ui->buttonBox->button(QDialogButtonBox::Save), SIGNAL(clicked()), this, SLOT(save())); + connect(ui->bookmarkName, SIGNAL(textChanged(const QString &)), this, SLOT(onNameChanged(const QString &))); + ui->buttonBox->button(QDialogButtonBox::Save)->setEnabled(false); +} + +void KevaEditBookmarkDialog::onNameChanged(const QString & name) +{ + int length = name.length(); + bool enabled = length > 0; + ui->buttonBox->button(QDialogButtonBox::Save)->setEnabled(enabled); + this->name = name; +} + +void KevaEditBookmarkDialog::save() +{ + KevaDialog* dialog = (KevaDialog*)this->parentWidget(); + QString bookmarkText = ui->bookmarkName->text(); + this->parentDialog->saveName(id, name); + QDialog::close(); +} + +void KevaEditBookmarkDialog::close() +{ + QDialog::close(); +} + +KevaEditBookmarkDialog::~KevaEditBookmarkDialog() +{ + delete ui; +} \ No newline at end of file diff --git a/src/qt/kevaeditbookmarkdialog.h b/src/qt/kevaeditbookmarkdialog.h new file mode 100644 index 000000000..5e9c443ff --- /dev/null +++ b/src/qt/kevaeditbookmarkdialog.h @@ -0,0 +1,41 @@ +// Copyright (c) 2011-2014 The Bitcoin Core developers +// Distributed under the MIT software license, see the accompanying +// file COPYING or http://www.opensource.org/licenses/mit-license.php. + +#ifndef BITCOIN_QT_KEVAEDITBOOKMARKDIALOG_H +#define BITCOIN_QT_KEVAEDITBOOKMARKDIALOG_H + +#include +#include + +#include + +namespace Ui { + class KevaEditBookmarkDialog; +} + +class KevaBookmarksDialog; + + +/** Dialog showing namepsace creation. */ +class KevaEditBookmarkDialog : public QDialog +{ + Q_OBJECT + +public: + explicit KevaEditBookmarkDialog(QWidget *parent, const QString& id, const QString& name); + ~KevaEditBookmarkDialog(); + +public Q_SLOTS: + void save(); + void close(); + void onNameChanged(const QString & ns); + +private: + Ui::KevaEditBookmarkDialog *ui; + QString id; + QString name; + KevaBookmarksDialog* parentDialog; +}; + +#endif // BITCOIN_QT_KEVAEDITBOOKMARKDIALOG_H diff --git a/src/qt/kevatablemodel.cpp b/src/qt/kevatablemodel.cpp index 63b83f34d..8fdcddcf0 100644 --- a/src/qt/kevatablemodel.cpp +++ b/src/qt/kevatablemodel.cpp @@ -76,7 +76,7 @@ QVariant KevaTableModel::data(const QModelIndex &index, int role) const if (index.column() == Block) return (int)(Qt::AlignRight|Qt::AlignVCenter); else if (index.column() == Value) { -#if (QT_VERSION <= QT_VERSION_CHECK(5, 9, 5)) +#if (QT_VERSION <= QT_VERSION_CHECK(5, 12, 0)) return (int)(Qt::AlignLeft|Qt::AlignVCenter); #else return (int)(Qt::AlignLeft|Qt::AlignTop); diff --git a/src/qt/locale/bitcoin_en.ts b/src/qt/locale/bitcoin_en.ts index 384cb904d..521956601 100644 --- a/src/qt/locale/bitcoin_en.ts +++ b/src/qt/locale/bitcoin_en.ts @@ -1181,8 +1181,8 @@ KevaBookmarksDialog - - Show + + &Edit @@ -1215,7 +1215,7 @@ KevaDialog - + Show the selected request (does the same as double clicking an entry) @@ -1226,13 +1226,18 @@ - - + + The namespace ID with a prefix "N". - + + Bookmark this namespace + + + + Use this form to perform Keva database operations. @@ -1322,7 +1327,7 @@ - + Warning Warning @@ -1376,6 +1381,24 @@ + + KevaEditBookmarkDialog + + + Bookmark name. + + + + + Name: + + + + + This pane allows change of bookmark name + + + KevaMyNamespacesDialog @@ -1438,7 +1461,7 @@ - + Requested diff --git a/src/qt/locale/bitcoin_zh_CN.ts b/src/qt/locale/bitcoin_zh_CN.ts index 8c5b70ce1..ba0bd8bcf 100644 --- a/src/qt/locale/bitcoin_zh_CN.ts +++ b/src/qt/locale/bitcoin_zh_CN.ts @@ -928,6 +928,10 @@ Show 显示 + + &Edit + 编辑 + KevaBookmarksModel