mirror of
https://github.com/kvazar-network/kevacoin.git
synced 2025-01-31 01:04:20 +00:00
implement CRUD operations in the namespace browser
This commit is contained in:
parent
d77b85d89b
commit
9ce6743227
@ -11,7 +11,7 @@
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string notr="true">Add New Key-Value Pair</string>
|
||||
<string notr="true">Create new record</string>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<item>
|
||||
|
@ -15,13 +15,56 @@
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<item>
|
||||
<widget class="QTextEdit" name="detailText">
|
||||
<property name="toolTip">
|
||||
<string>This pane shows the value associated with a give key</string>
|
||||
</property>
|
||||
<property name="readOnly">
|
||||
<bool>false</bool>
|
||||
<!-- @TODO -->
|
||||
<widget class="QLabel" name="detailKey">
|
||||
<property name="text">
|
||||
<string/>
|
||||
</property>
|
||||
<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>
|
||||
<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>
|
||||
</item>
|
||||
<item>
|
||||
@ -30,7 +73,7 @@
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="standardButtons">
|
||||
<set>QDialogButtonBox::Close|QDialogButtonBox::Save</set>
|
||||
<set>QDialogButtonBox::Close</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
|
@ -263,15 +263,55 @@
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_2">
|
||||
<item>
|
||||
<widget class="QPushButton" name="showValueButton">
|
||||
<widget class="QPushButton" name="createButton">
|
||||
<property name="enabled">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="toolTip">
|
||||
<string>Show the selected request (does the same as double clicking an entry)</string>
|
||||
<string>Create new record</string>
|
||||
</property>
|
||||
<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 name="icon">
|
||||
<iconset resource="../bitcoin.qrc">
|
||||
@ -283,15 +323,15 @@
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="removeButton">
|
||||
<widget class="QPushButton" name="deleteButton">
|
||||
<property name="enabled">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="toolTip">
|
||||
<string>Remove the selected entries from the list</string>
|
||||
<string>Delete the selected entries from the list</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Remove</string>
|
||||
<string>Delete</string>
|
||||
</property>
|
||||
<property name="icon">
|
||||
<iconset resource="../bitcoin.qrc">
|
||||
@ -302,26 +342,6 @@
|
||||
</property>
|
||||
</widget>
|
||||
</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>
|
||||
<spacer name="horizontalSpacer_2">
|
||||
<property name="orientation">
|
||||
@ -355,8 +375,8 @@
|
||||
<tabstop>receiveButton</tabstop>
|
||||
<tabstop>clearButton</tabstop>
|
||||
<tabstop>recentRequestsView</tabstop>
|
||||
<tabstop>showValueButton</tabstop>
|
||||
<tabstop>removeButton</tabstop>
|
||||
<tabstop>readButton</tabstop>
|
||||
<tabstop>deleteButton</tabstop>
|
||||
</tabstops>
|
||||
<resources>
|
||||
<include location="../bitcoin.qrc"/>
|
||||
|
@ -28,6 +28,20 @@ KevaAddKeyDialog::~KevaAddKeyDialog()
|
||||
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()
|
||||
{
|
||||
KevaDialog* dialog = (KevaDialog*)this->parentWidget();
|
||||
|
@ -34,6 +34,8 @@ private:
|
||||
public Q_SLOTS:
|
||||
void create();
|
||||
void cancel();
|
||||
void setKey(const QString& value);
|
||||
void setValue(const QString& value);
|
||||
void onKeyChanged(const QString& key);
|
||||
void onValueChanged();
|
||||
};
|
||||
|
@ -17,40 +17,40 @@ KevaDetailDialog::KevaDetailDialog(const QModelIndex &idx, QWidget *parent, cons
|
||||
ui(new Ui::KevaDetailDialog)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
QModelIndex keyIdx = idx.sibling(idx.row(), KevaTableModel::Key);
|
||||
QModelIndex valueIdx = idx.sibling(idx.row(), KevaTableModel::Value);
|
||||
|
||||
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()));
|
||||
|
||||
setWindowTitle(
|
||||
idx.sibling(
|
||||
idx.row(),
|
||||
KevaTableModel::Key
|
||||
).data(
|
||||
Qt::DisplayRole
|
||||
).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()
|
||||
{
|
||||
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();
|
||||
}
|
||||
|
@ -7,7 +7,6 @@
|
||||
|
||||
#include <QObject>
|
||||
#include <QString>
|
||||
|
||||
#include <QDialog>
|
||||
|
||||
namespace Ui {
|
||||
@ -27,10 +26,6 @@ public:
|
||||
explicit KevaDetailDialog(const QModelIndex &idx, QWidget *parent, const QString &nameSpace);
|
||||
~KevaDetailDialog();
|
||||
|
||||
public Q_SLOTS:
|
||||
void onValueChanged();
|
||||
void onSave();
|
||||
|
||||
private:
|
||||
Ui::KevaDetailDialog *ui;
|
||||
QString nameSpace;
|
||||
|
@ -40,13 +40,16 @@ KevaDialog::KevaDialog(const PlatformStyle *_platformStyle, QWidget *parent) :
|
||||
|
||||
if (!_platformStyle->getImagesOnButtons()) {
|
||||
ui->bookmarksButton->setIcon(QIcon());
|
||||
ui->showValueButton->setIcon(QIcon());
|
||||
ui->removeButton->setIcon(QIcon());
|
||||
ui->createButton->setIcon(QIcon());
|
||||
ui->readButton->setIcon(QIcon());
|
||||
ui->updateButton->setIcon(QIcon());
|
||||
ui->deleteButton->setIcon(QIcon());
|
||||
} else {
|
||||
ui->bookmarksButton->setIcon(_platformStyle->SingleColorIcon(":/icons/address-book"));
|
||||
ui->showValueButton->setIcon(_platformStyle->SingleColorIcon(":/icons/edit"));
|
||||
ui->removeButton->setIcon(_platformStyle->SingleColorIcon(":/icons/remove"));
|
||||
ui->addKVButton->setIcon(_platformStyle->SingleColorIcon(":/icons/add"));
|
||||
ui->createButton->setIcon(_platformStyle->SingleColorIcon(":/icons/add"));
|
||||
ui->readButton->setIcon(_platformStyle->SingleColorIcon(":/icons/eye"));
|
||||
ui->updateButton->setIcon(_platformStyle->SingleColorIcon(":/icons/edit"));
|
||||
ui->deleteButton->setIcon(_platformStyle->SingleColorIcon(":/icons/remove"));
|
||||
}
|
||||
|
||||
// context menu actions
|
||||
@ -158,10 +161,10 @@ void KevaDialog::onNamespaceChanged(const QString& nameSpace)
|
||||
valtype nameSpaceVal;
|
||||
bool isValidNamespace = false;
|
||||
if (DecodeKevaNamespace(namespaceStr, Params(), nameSpaceVal)) {
|
||||
ui->addKVButton->setEnabled(true);
|
||||
ui->createButton->setEnabled(true);
|
||||
isValidNamespace = true;
|
||||
} else {
|
||||
ui->addKVButton->setEnabled(false);
|
||||
ui->createButton->setEnabled(false);
|
||||
ui->bookmarkNamespace->setIcon(QIcon(":/icons/star_empty"));
|
||||
}
|
||||
|
||||
@ -285,13 +288,22 @@ void KevaDialog::on_bookmarkNamespace_clicked()
|
||||
|
||||
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();
|
||||
ui->showValueButton->setEnabled(enable);
|
||||
ui->removeButton->setEnabled(enable);
|
||||
ui->readButton->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())
|
||||
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())
|
||||
return;
|
||||
@ -351,14 +400,6 @@ void KevaDialog::on_removeButton_clicked()
|
||||
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
|
||||
// sizes as the tables width is proportional to the dialogs width.
|
||||
void KevaDialog::resizeEvent(QResizeEvent *event)
|
||||
|
@ -73,9 +73,10 @@ private Q_SLOTS:
|
||||
void on_showContent_clicked();
|
||||
void on_createNamespace_clicked();
|
||||
void on_listNamespaces_clicked();
|
||||
void on_showValueButton_clicked();
|
||||
void on_removeButton_clicked();
|
||||
void on_addKVButton_clicked();
|
||||
void on_createButton_clicked();
|
||||
void on_readButton_clicked();
|
||||
void on_updateButton_clicked();
|
||||
void on_deleteButton_clicked();
|
||||
void on_kevaView_doubleClicked(const QModelIndex &index);
|
||||
void kevaView_selectionChanged();
|
||||
void on_bookmarksButton_clicked();
|
||||
|
Loading…
x
Reference in New Issue
Block a user