popup editor to view record content
This commit is contained in:
parent
5270dd00bc
commit
d2ec12798e
19
main.go
19
main.go
@ -238,6 +238,25 @@ func Bolt_ListItems(b ObjectReference, browse []string) ObjectReference {
|
||||
return pNC_Ref
|
||||
}
|
||||
|
||||
//export Bolt_GetItem
|
||||
func Bolt_GetItem(b ObjectReference, browse []string, key string) (int64, *C.char, int) {
|
||||
var ret *C.char = nil
|
||||
var ret_len = 0
|
||||
|
||||
err := withBrowse_ReadOnly(b, browse, func(db *bolt.DB, tx *bolt.Tx, bucket *bolt.Bucket) error {
|
||||
d := bucket.Get([]byte(key))
|
||||
ret = C.CString(string(d))
|
||||
ret_len = len(d)
|
||||
return nil
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
return ERROR_AND_STOP_CALLING, C.CString(err.Error()), len(err.Error())
|
||||
}
|
||||
|
||||
return REAL_MESSAGE, ret, ret_len
|
||||
}
|
||||
|
||||
//export GetNext
|
||||
func GetNext(oRef ObjectReference) (int64, *C.char, int) {
|
||||
pNC_Iface, ok := gms.Get(oRef)
|
||||
|
@ -59,6 +59,29 @@ bool BoltDB::listKeys(QStringList bucketPath, QString& errorOut, std::function<v
|
||||
});
|
||||
}
|
||||
|
||||
bool BoltDB::getData(QStringList bucketPath, QByteArray key, std::function<void(QByteArray)> onSuccess, std::function<void(QString)> onError)
|
||||
{
|
||||
GoSliceManagedWrapper browse(&bucketPath);
|
||||
GoString keyGS = Interop::toGoString_WeakRef(&key);
|
||||
auto resp = ::Bolt_GetItem(this->gmsDbRef, browse.slice, keyGS);
|
||||
|
||||
if (resp.r0 == ERROR_AND_STOP_CALLING) {
|
||||
onError(QString::fromUtf8(resp.r1, resp.r2));
|
||||
free(resp.r1);
|
||||
return false;
|
||||
|
||||
} else if (resp.r0 == REAL_MESSAGE) {
|
||||
onSuccess(QByteArray(resp.r1, resp.r2));
|
||||
free(resp.r1);
|
||||
return true;
|
||||
|
||||
} else {
|
||||
// ?? unreachable
|
||||
return false;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
bool BoltDB::pumpNext(GoInt64 jobRef, QString& errorOut, NameReciever cb)
|
||||
{
|
||||
errorOut.clear();
|
||||
@ -95,9 +118,8 @@ bool BoltDB::getStatsJSON(std::function<void(QByteArray)> onSuccess, std::functi
|
||||
auto statresp = Bolt_DBStats(this->gmsDbRef);
|
||||
|
||||
if (statresp.r0 == ERROR_AND_STOP_CALLING) {
|
||||
QString err = QString::fromUtf8(statresp.r1, statresp.r2);
|
||||
onError(QString::fromUtf8(statresp.r1, statresp.r2));
|
||||
free(statresp.r1);
|
||||
onError(err);
|
||||
return false;
|
||||
|
||||
} else if (statresp.r0 == REAL_MESSAGE) {
|
||||
|
@ -22,6 +22,8 @@ public:
|
||||
|
||||
bool listKeys(QStringList bucketPath, QString& errorOut, std::function<void(QByteArray, int64_t)> cb);
|
||||
|
||||
bool getData(QStringList bucketPath, QByteArray key, std::function<void(QByteArray)> onSuccess, std::function<void(QString)> onError);
|
||||
|
||||
bool getStatsJSON(std::function<void(QByteArray)> onSuccess, std::function<void(QString)> onError);
|
||||
|
||||
bool getBucketStatsJSON(QStringList bucketPath, std::function<void(QByteArray)> onSuccess, std::function<void(QString)> onError);
|
||||
|
18
qbolt/itemwindow.cpp
Normal file
18
qbolt/itemwindow.cpp
Normal file
@ -0,0 +1,18 @@
|
||||
#include "itemwindow.h"
|
||||
#include "ui_itemwindow.h"
|
||||
|
||||
ItemWindow::ItemWindow(QWidget *parent) :
|
||||
QDialog(parent),
|
||||
ui(new Ui::ItemWindow)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
}
|
||||
|
||||
ItemWindow::~ItemWindow()
|
||||
{
|
||||
delete ui;
|
||||
}
|
||||
|
||||
QPlainTextEdit* ItemWindow::ContentArea() const {
|
||||
return ui->contentArea;
|
||||
}
|
25
qbolt/itemwindow.h
Normal file
25
qbolt/itemwindow.h
Normal file
@ -0,0 +1,25 @@
|
||||
#ifndef ITEMWINDOW_H
|
||||
#define ITEMWINDOW_H
|
||||
|
||||
#include <QDialog>
|
||||
#include <QPlainTextEdit>
|
||||
|
||||
namespace Ui {
|
||||
class ItemWindow;
|
||||
}
|
||||
|
||||
class ItemWindow : public QDialog
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit ItemWindow(QWidget *parent = 0);
|
||||
~ItemWindow();
|
||||
|
||||
QPlainTextEdit* ContentArea() const;
|
||||
|
||||
private:
|
||||
Ui::ItemWindow *ui;
|
||||
};
|
||||
|
||||
#endif // ITEMWINDOW_H
|
46
qbolt/itemwindow.ui
Normal file
46
qbolt/itemwindow.ui
Normal file
@ -0,0 +1,46 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>ItemWindow</class>
|
||||
<widget class="QDialog" name="ItemWindow">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>370</width>
|
||||
<height>353</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string/>
|
||||
</property>
|
||||
<property name="windowIcon">
|
||||
<iconset resource="resources.qrc">
|
||||
<normaloff>:/rsrc/database_lightning.png</normaloff>:/rsrc/database_lightning.png</iconset>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout">
|
||||
<property name="leftMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="topMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="rightMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="bottomMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<item row="0" column="0">
|
||||
<widget class="QPlainTextEdit" name="contentArea">
|
||||
<property name="frameShape">
|
||||
<enum>QFrame::NoFrame</enum>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<resources>
|
||||
<include location="resources.qrc"/>
|
||||
</resources>
|
||||
<connections/>
|
||||
</ui>
|
@ -1,6 +1,6 @@
|
||||
#include "mainwindow.h"
|
||||
#include "ui_mainwindow.h"
|
||||
|
||||
#include "itemwindow.h"
|
||||
#include "boltdb.h"
|
||||
|
||||
#include <QFileDialog>
|
||||
@ -58,6 +58,8 @@ void MainWindow::on_actionOpen_database_triggered()
|
||||
|
||||
refreshBucketTree(top);
|
||||
ui->bucketTree->setCurrentItem(top);
|
||||
|
||||
ui->bucketTree->expandItem(top);
|
||||
}
|
||||
|
||||
void MainWindow::refreshBucketTree(QTreeWidgetItem* itm)
|
||||
@ -225,12 +227,15 @@ void MainWindow::on_bucketTree_currentItemChanged(QTreeWidgetItem *current, QTre
|
||||
itm->setText(1, QString("%1").arg(dataLen));
|
||||
ui->bucketData->addTopLevelItem(itm);
|
||||
});
|
||||
|
||||
if (! ok) {
|
||||
QMessageBox qmb;
|
||||
qmb.setText(tr("Error listing bucket content: %1").arg(err));
|
||||
qmb.exec();
|
||||
}
|
||||
|
||||
ui->bucketData->resizeColumnToContents(0);
|
||||
|
||||
// Clean up foreign areas
|
||||
ui->databasePropertiesArea->clear();
|
||||
}
|
||||
@ -240,3 +245,49 @@ void MainWindow::on_actionClear_selection_triggered()
|
||||
{
|
||||
ui->bucketTree->setCurrentItem(nullptr);
|
||||
}
|
||||
|
||||
void MainWindow::on_bucketData_doubleClicked(const QModelIndex &index)
|
||||
{
|
||||
auto *itm = ui->bucketTree->currentItem();
|
||||
if (itm == nullptr) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Get browse path
|
||||
|
||||
QTreeWidgetItem* top = itm;
|
||||
QStringList browse;
|
||||
while(top->parent() != nullptr) {
|
||||
browse.push_front(top->text(0));
|
||||
top = top->parent();
|
||||
}
|
||||
|
||||
// Get BDB
|
||||
|
||||
auto *bdb = GET_BDB(top);
|
||||
|
||||
// Get item key
|
||||
|
||||
auto model = index.model();
|
||||
QString key = model->data(model->index(index.row(), 0), 0).toString();
|
||||
|
||||
// DB lookup
|
||||
|
||||
bdb->getData(
|
||||
browse,
|
||||
key.toUtf8(),
|
||||
[=](QByteArray content) {
|
||||
auto iw = new ItemWindow();
|
||||
iw->ContentArea()->setPlainText(QString::fromUtf8(content));
|
||||
iw->setWindowTitle(key);
|
||||
connect(iw, &ItemWindow::finished, iw, &ItemWindow::deleteLater);
|
||||
iw->show();
|
||||
},
|
||||
[=](QString error) {
|
||||
QMessageBox qmb;
|
||||
qmb.setText(tr("Error loading item content: %1").arg(error));
|
||||
qmb.exec();
|
||||
}
|
||||
);
|
||||
|
||||
}
|
||||
|
@ -36,6 +36,8 @@ private slots:
|
||||
|
||||
void on_actionClear_selection_triggered();
|
||||
|
||||
void on_bucketData_doubleClicked(const QModelIndex &index);
|
||||
|
||||
protected:
|
||||
void refreshBucketTree(QTreeWidgetItem* top);
|
||||
|
||||
|
@ -29,14 +29,17 @@ linux: {
|
||||
SOURCES += main.cpp\
|
||||
mainwindow.cpp \
|
||||
interop.cpp \
|
||||
boltdb.cpp
|
||||
boltdb.cpp \
|
||||
itemwindow.cpp
|
||||
|
||||
HEADERS += mainwindow.h \
|
||||
interop.h \
|
||||
boltdb.h \
|
||||
qbolt_cgo.h
|
||||
qbolt_cgo.h \
|
||||
itemwindow.h
|
||||
|
||||
FORMS += mainwindow.ui
|
||||
FORMS += mainwindow.ui \
|
||||
itemwindow.ui
|
||||
|
||||
RESOURCES += \
|
||||
resources.qrc
|
||||
|
Loading…
Reference in New Issue
Block a user