implement CRUD operations in the namespace browser

This commit is contained in:
kvazar-network 2024-05-10 06:04:55 +03:00
parent d77b85d89b
commit 9ce6743227
9 changed files with 211 additions and 95 deletions

View File

@ -11,7 +11,7 @@
</rect> </rect>
</property> </property>
<property name="windowTitle"> <property name="windowTitle">
<string notr="true">Add New Key-Value Pair</string> <string notr="true">Create new record</string>
</property> </property>
<layout class="QVBoxLayout" name="verticalLayout"> <layout class="QVBoxLayout" name="verticalLayout">
<item> <item>

View File

@ -15,13 +15,56 @@
</property> </property>
<layout class="QVBoxLayout" name="verticalLayout"> <layout class="QVBoxLayout" name="verticalLayout">
<item> <item>
<widget class="QTextEdit" name="detailText"> <!-- @TODO -->
<property name="toolTip"> <widget class="QLabel" name="detailKey">
<string>This pane shows the value associated with a give key</string> <property name="text">
</property> <string/>
<property name="readOnly"> </property>
<bool>false</bool> <property name="font">
<!--
<font>
<bold>true</bold>
</font>
-->
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
<property name="alignment">
<set>Qt::AlignLeft</set>
</property>
<property name="textInteractionFlags">
<set>Qt::LinksAccessibleByMouse|Qt::TextSelectableByKeyboard|Qt::TextSelectableByMouse</set>
</property>
<property name="textFormat">
<!-- exlude remote content loading -->
<enum>Qt::PlainText</enum>
</property>
</widget>
</item>
<item>
<widget class="QScrollArea" name="scrollArea">
<property name="widgetResizable">
<bool>true</bool>
</property> </property>
<widget class="QLabel" name="detailValue">
<property name="text">
<string/>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
<property name="alignment">
<set>Qt::AlignLeft</set>
</property>
<property name="textInteractionFlags">
<set>Qt::LinksAccessibleByMouse|Qt::TextSelectableByKeyboard|Qt::TextSelectableByMouse</set>
</property>
<property name="textFormat">
<!-- exlude remote content loading -->
<enum>Qt::PlainText</enum>
</property>
</widget>
</widget> </widget>
</item> </item>
<item> <item>
@ -30,7 +73,7 @@
<enum>Qt::Horizontal</enum> <enum>Qt::Horizontal</enum>
</property> </property>
<property name="standardButtons"> <property name="standardButtons">
<set>QDialogButtonBox::Close|QDialogButtonBox::Save</set> <set>QDialogButtonBox::Close</set>
</property> </property>
</widget> </widget>
</item> </item>

View File

@ -263,15 +263,55 @@
<item> <item>
<layout class="QHBoxLayout" name="horizontalLayout_2"> <layout class="QHBoxLayout" name="horizontalLayout_2">
<item> <item>
<widget class="QPushButton" name="showValueButton"> <widget class="QPushButton" name="createButton">
<property name="enabled"> <property name="enabled">
<bool>false</bool> <bool>false</bool>
</property> </property>
<property name="toolTip"> <property name="toolTip">
<string>Show the selected request (does the same as double clicking an entry)</string> <string>Create new record</string>
</property> </property>
<property name="text"> <property name="text">
<string>Show</string> <string>Create</string>
</property>
<property name="icon">
<iconset resource="../bitcoin.qrc">
<normaloff>:/icons/add</normaloff>:/icons/add</iconset>
</property>
<property name="autoDefault">
<bool>false</bool>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="readButton">
<property name="enabled">
<bool>false</bool>
</property>
<property name="toolTip">
<string>Read selected record</string>
</property>
<property name="text">
<string>Read</string>
</property>
<property name="icon">
<iconset resource="../bitcoin.qrc">
<normaloff>:/icons/eye</normaloff>:/icons/eye</iconset>
</property>
<property name="autoDefault">
<bool>false</bool>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="updateButton">
<property name="enabled">
<bool>false</bool>
</property>
<property name="toolTip">
<string>Update selected record</string>
</property>
<property name="text">
<string>Update</string>
</property> </property>
<property name="icon"> <property name="icon">
<iconset resource="../bitcoin.qrc"> <iconset resource="../bitcoin.qrc">
@ -283,15 +323,15 @@
</widget> </widget>
</item> </item>
<item> <item>
<widget class="QPushButton" name="removeButton"> <widget class="QPushButton" name="deleteButton">
<property name="enabled"> <property name="enabled">
<bool>false</bool> <bool>false</bool>
</property> </property>
<property name="toolTip"> <property name="toolTip">
<string>Remove the selected entries from the list</string> <string>Delete the selected entries from the list</string>
</property> </property>
<property name="text"> <property name="text">
<string>Remove</string> <string>Delete</string>
</property> </property>
<property name="icon"> <property name="icon">
<iconset resource="../bitcoin.qrc"> <iconset resource="../bitcoin.qrc">
@ -302,26 +342,6 @@
</property> </property>
</widget> </widget>
</item> </item>
<item>
<widget class="QPushButton" name="addKVButton">
<property name="enabled">
<bool>false</bool>
</property>
<property name="toolTip">
<string>Add new key-value pair</string>
</property>
<property name="text">
<string>Add key-value</string>
</property>
<property name="icon">
<iconset resource="../bitcoin.qrc">
<normaloff>:/icons/add</normaloff>:/icons/add</iconset>
</property>
<property name="autoDefault">
<bool>false</bool>
</property>
</widget>
</item>
<item> <item>
<spacer name="horizontalSpacer_2"> <spacer name="horizontalSpacer_2">
<property name="orientation"> <property name="orientation">
@ -355,8 +375,8 @@
<tabstop>receiveButton</tabstop> <tabstop>receiveButton</tabstop>
<tabstop>clearButton</tabstop> <tabstop>clearButton</tabstop>
<tabstop>recentRequestsView</tabstop> <tabstop>recentRequestsView</tabstop>
<tabstop>showValueButton</tabstop> <tabstop>readButton</tabstop>
<tabstop>removeButton</tabstop> <tabstop>deleteButton</tabstop>
</tabstops> </tabstops>
<resources> <resources>
<include location="../bitcoin.qrc"/> <include location="../bitcoin.qrc"/>

View File

@ -28,6 +28,20 @@ KevaAddKeyDialog::~KevaAddKeyDialog()
delete ui; delete ui;
} }
void KevaAddKeyDialog::setKey(const QString &value)
{
ui->keyText->setText(
value
);
}
void KevaAddKeyDialog::setValue(const QString &value)
{
ui->valueText->setPlainText(
value
);
}
void KevaAddKeyDialog::create() void KevaAddKeyDialog::create()
{ {
KevaDialog* dialog = (KevaDialog*)this->parentWidget(); KevaDialog* dialog = (KevaDialog*)this->parentWidget();

View File

@ -34,6 +34,8 @@ private:
public Q_SLOTS: public Q_SLOTS:
void create(); void create();
void cancel(); void cancel();
void setKey(const QString& value);
void setValue(const QString& value);
void onKeyChanged(const QString& key); void onKeyChanged(const QString& key);
void onValueChanged(); void onValueChanged();
}; };

View File

@ -17,40 +17,40 @@ KevaDetailDialog::KevaDetailDialog(const QModelIndex &idx, QWidget *parent, cons
ui(new Ui::KevaDetailDialog) ui(new Ui::KevaDetailDialog)
{ {
ui->setupUi(this); ui->setupUi(this);
QModelIndex keyIdx = idx.sibling(idx.row(), KevaTableModel::Key);
QModelIndex valueIdx = idx.sibling(idx.row(), KevaTableModel::Value);
this->nameSpace = nameSpace; this->nameSpace = nameSpace;
key = keyIdx.data(Qt::DisplayRole).toString();
setWindowTitle(tr("Value for %1").arg(key)); setWindowTitle(
QString desc = valueIdx.data(Qt::DisplayRole).toString(); idx.sibling(
connect(ui->detailText, SIGNAL(textChanged()), this, SLOT(onValueChanged())); idx.row(),
//ui->detailText->setHtml(desc); KevaTableModel::Key
ui->detailText->setPlainText(desc); ).data(
ui->buttonBox->button(QDialogButtonBox::Save)->setEnabled(false); Qt::DisplayRole
connect(ui->buttonBox->button(QDialogButtonBox::Save), SIGNAL(clicked()), this, SLOT(onSave())); ).toString()
);
/* @TODO multi-tab data/meta browser
ui->detailKey->setText(
idx.sibling(
idx.row(),
KevaTableModel::Key
).data(
Qt::DisplayRole
).toString()
);
*/
ui->detailValue->setText(
idx.sibling(
idx.row(),
KevaTableModel::Value
).data(
Qt::DisplayRole
).toString()
);
} }
KevaDetailDialog::~KevaDetailDialog() KevaDetailDialog::~KevaDetailDialog()
{ {
delete ui; delete ui;
} }
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();
}

View File

@ -7,7 +7,6 @@
#include <QObject> #include <QObject>
#include <QString> #include <QString>
#include <QDialog> #include <QDialog>
namespace Ui { namespace Ui {
@ -27,10 +26,6 @@ public:
explicit KevaDetailDialog(const QModelIndex &idx, QWidget *parent, const QString &nameSpace); explicit KevaDetailDialog(const QModelIndex &idx, QWidget *parent, const QString &nameSpace);
~KevaDetailDialog(); ~KevaDetailDialog();
public Q_SLOTS:
void onValueChanged();
void onSave();
private: private:
Ui::KevaDetailDialog *ui; Ui::KevaDetailDialog *ui;
QString nameSpace; QString nameSpace;

View File

@ -40,13 +40,16 @@ KevaDialog::KevaDialog(const PlatformStyle *_platformStyle, QWidget *parent) :
if (!_platformStyle->getImagesOnButtons()) { if (!_platformStyle->getImagesOnButtons()) {
ui->bookmarksButton->setIcon(QIcon()); ui->bookmarksButton->setIcon(QIcon());
ui->showValueButton->setIcon(QIcon()); ui->createButton->setIcon(QIcon());
ui->removeButton->setIcon(QIcon()); ui->readButton->setIcon(QIcon());
ui->updateButton->setIcon(QIcon());
ui->deleteButton->setIcon(QIcon());
} else { } else {
ui->bookmarksButton->setIcon(_platformStyle->SingleColorIcon(":/icons/address-book")); ui->bookmarksButton->setIcon(_platformStyle->SingleColorIcon(":/icons/address-book"));
ui->showValueButton->setIcon(_platformStyle->SingleColorIcon(":/icons/edit")); ui->createButton->setIcon(_platformStyle->SingleColorIcon(":/icons/add"));
ui->removeButton->setIcon(_platformStyle->SingleColorIcon(":/icons/remove")); ui->readButton->setIcon(_platformStyle->SingleColorIcon(":/icons/eye"));
ui->addKVButton->setIcon(_platformStyle->SingleColorIcon(":/icons/add")); ui->updateButton->setIcon(_platformStyle->SingleColorIcon(":/icons/edit"));
ui->deleteButton->setIcon(_platformStyle->SingleColorIcon(":/icons/remove"));
} }
// context menu actions // context menu actions
@ -158,10 +161,10 @@ void KevaDialog::onNamespaceChanged(const QString& nameSpace)
valtype nameSpaceVal; valtype nameSpaceVal;
bool isValidNamespace = false; bool isValidNamespace = false;
if (DecodeKevaNamespace(namespaceStr, Params(), nameSpaceVal)) { if (DecodeKevaNamespace(namespaceStr, Params(), nameSpaceVal)) {
ui->addKVButton->setEnabled(true); ui->createButton->setEnabled(true);
isValidNamespace = true; isValidNamespace = true;
} else { } else {
ui->addKVButton->setEnabled(false); ui->createButton->setEnabled(false);
ui->bookmarkNamespace->setIcon(QIcon(":/icons/star_empty")); ui->bookmarkNamespace->setIcon(QIcon(":/icons/star_empty"));
} }
@ -285,13 +288,22 @@ void KevaDialog::on_bookmarkNamespace_clicked()
void KevaDialog::kevaView_selectionChanged() void KevaDialog::kevaView_selectionChanged()
{ {
// Enable Show/Remove buttons only if anything is selected. // Enable Read/Delete buttons only if anything is selected.
bool enable = !ui->kevaView->selectionModel()->selectedRows().isEmpty(); bool enable = !ui->kevaView->selectionModel()->selectedRows().isEmpty();
ui->showValueButton->setEnabled(enable); ui->readButton->setEnabled(enable);
ui->removeButton->setEnabled(enable); ui->updateButton->setEnabled(enable);
ui->deleteButton->setEnabled(enable);
} }
void KevaDialog::on_showValueButton_clicked() void KevaDialog::on_createButton_clicked()
{
QString ns = ui->nameSpace->text();
KevaAddKeyDialog *dialog = new KevaAddKeyDialog(this, ns);
dialog->setAttribute(Qt::WA_DeleteOnClose);
dialog->show();
}
void KevaDialog::on_readButton_clicked()
{ {
if(!model || !model->getKevaTableModel() || !ui->kevaView->selectionModel()) if(!model || !model->getKevaTableModel() || !ui->kevaView->selectionModel())
return; return;
@ -302,7 +314,44 @@ void KevaDialog::on_showValueButton_clicked()
} }
} }
void KevaDialog::on_removeButton_clicked() void KevaDialog::on_updateButton_clicked()
{
QString ns = ui->nameSpace->text();
KevaAddKeyDialog *dialog = new KevaAddKeyDialog(this, ns);
if(!model || !model->getKevaTableModel() || !ui->kevaView->selectionModel())
return;
for (const QModelIndex& index : ui->kevaView->selectionModel()->selectedRows())
{
dialog->setKey(
index.sibling(
index.row(),
KevaTableModel::Key
).data(
Qt::DisplayRole
).toString()
);
dialog->setValue(
index.sibling(
index.row(),
KevaTableModel::Value
).data(
Qt::DisplayRole
).toString()
);
}
dialog->setAttribute(
Qt::WA_DeleteOnClose
);
dialog->show();
}
void KevaDialog::on_deleteButton_clicked()
{ {
if(!model || !model->getKevaTableModel() || !ui->kevaView->selectionModel()) if(!model || !model->getKevaTableModel() || !ui->kevaView->selectionModel())
return; return;
@ -351,14 +400,6 @@ void KevaDialog::on_removeButton_clicked()
model->getKevaTableModel()->removeRows(firstIndex.row(), selection.length(), firstIndex.parent()); model->getKevaTableModel()->removeRows(firstIndex.row(), selection.length(), firstIndex.parent());
} }
void KevaDialog::on_addKVButton_clicked()
{
QString ns = ui->nameSpace->text();
KevaAddKeyDialog *dialog = new KevaAddKeyDialog(this, ns);
dialog->setAttribute(Qt::WA_DeleteOnClose);
dialog->show();
}
// We override the virtual resizeEvent of the QWidget to adjust tables column // We override the virtual resizeEvent of the QWidget to adjust tables column
// sizes as the tables width is proportional to the dialogs width. // sizes as the tables width is proportional to the dialogs width.
void KevaDialog::resizeEvent(QResizeEvent *event) void KevaDialog::resizeEvent(QResizeEvent *event)

View File

@ -73,9 +73,10 @@ private Q_SLOTS:
void on_showContent_clicked(); void on_showContent_clicked();
void on_createNamespace_clicked(); void on_createNamespace_clicked();
void on_listNamespaces_clicked(); void on_listNamespaces_clicked();
void on_showValueButton_clicked(); void on_createButton_clicked();
void on_removeButton_clicked(); void on_readButton_clicked();
void on_addKVButton_clicked(); void on_updateButton_clicked();
void on_deleteButton_clicked();
void on_kevaView_doubleClicked(const QModelIndex &index); void on_kevaView_doubleClicked(const QModelIndex &index);
void kevaView_selectionChanged(); void kevaView_selectionChanged();
void on_bookmarksButton_clicked(); void on_bookmarksButton_clicked();