qbolt: fixes post-port

This commit is contained in:
mappu 2024-10-05 15:58:56 +13:00
parent a6cbc5a9ed
commit 2c5d1946ec
11 changed files with 88 additions and 407 deletions

4
.gitignore vendored
View File

@ -1,4 +1,2 @@
build-qbolt-*
qbolt
dummy-data/dummy-data*
*.pro.user$
build/

View File

@ -128,7 +128,7 @@ func Bolt_DeleteItem(db *bolt.DB, browse []string, key string) error {
}
func Bolt_DBStats(db *bolt.DB) (string, error) {
jBytes, err := json.Marshal(db.Stats())
jBytes, err := json.MarshalIndent(db.Stats(), "", " ")
if err != nil {
return "", err
}
@ -147,7 +147,7 @@ func Bolt_BucketStats(db *bolt.DB, browse []string) (string, error) {
return "", err
}
jBytes, err := json.Marshal(stats)
jBytes, err := json.MarshalIndent(stats, "", " ")
if err != nil {
return "", err
}

View File

@ -3,13 +3,19 @@
set -eu
MIQT_UIC=${MIQT_UIC:-miqt-uic}
MIQT_RCC=${MIQT_RCC:-miqt-rcc}
rm resources.rcc || true
rcc --binary -o resources.rcc resources.qrc
main() {
$MIQT_RCC resources.qrc
$MIQT_UIC -InFile mainwindow.ui -OutFile mainwindow_ui.go
$MIQT_UIC -InFile itemwindow.ui -OutFile itemwindow_ui.go
go build -ldflags "-s -w" -gcflags='-trimpath=$(pwd)' -asmflags='-trimpath=$(pwd)'
echo "Build OK"
$MIQT_UIC -InFile mainwindow.ui -OutFile mainwindow_ui.go
$MIQT_UIC -InFile itemwindow.ui -OutFile itemwindow_ui.go
}
go build -ldflags "-s -w"
echo "Build OK"
main "$@"

View File

@ -42,12 +42,6 @@
</item>
<item row="1" column="0">
<widget class="QFrame" name="frame">
<property name="frameShape">
<enum>QFrame::StyledPanel</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Raised</enum>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0">
<widget class="QDialogButtonBox" name="buttonBox">

View File

@ -44,8 +44,6 @@ func NewItemWindowUi() *ItemWindowUi {
ui.frame = qt.NewQFrame2(ui.ItemWindow.QWidget)
ui.frame.SetObjectName("frame")
ui.frame.SetFrameShape(qt.QFrame__StyledPanel)
ui.frame.SetFrameShadow(qt.QFrame__Raised)
ui.gridLayout = qt.NewQGridLayout(ui.frame.QWidget)
ui.gridLayout.SetObjectName("gridLayout")
@ -54,7 +52,9 @@ func NewItemWindowUi() *ItemWindowUi {
ui.buttonBox = qt.NewQDialogButtonBox5(ui.frame.QWidget)
ui.buttonBox.SetObjectName("buttonBox")
/* miqt-uic: no handler for buttonBox property 'standardButtons' */
ui.buttonBox.SetStandardButtons(qt.QDialogButtonBox__Cancel | qt.QDialogButtonBox__Save)
ui.buttonBox.OnAccepted(ui.ItemWindow.Accept)
ui.buttonBox.OnRejected(ui.ItemWindow.Reject)
ui.gridLayout.AddWidget2(ui.buttonBox.QWidget, 0, 0)

View File

@ -2,7 +2,9 @@ package main
import (
"fmt"
"path/filepath"
"strconv"
"strings"
bolt "github.com/boltdb/bolt"
"github.com/mappu/miqt/qt"
@ -121,7 +123,7 @@ func (this *MainWindow) openDatabase(file string, readOnly bool) {
}
top := qt.NewQTreeWidgetItem()
top.SetText(0, file)
top.SetText(0, filepath.Base(file))
top.SetIcon(0, qt.NewQIcon4(":/rsrc/database.png"))
SET_BDB(top, bdb)
this.ui.bucketTree.AddTopLevelItem(top)
@ -133,45 +135,36 @@ func (this *MainWindow) openDatabase(file string, readOnly bool) {
}
func getDisplayName(qba string) string {
if qba == "" {
return "<empty>"
}
ret := strconv.Quote(qba)
return ret[1 : len(ret)-2]
return ret[1 : len(ret)-1]
}
func (this *MainWindow) refreshBucketTree(itm *qt.QTreeWidgetItem) {
var top *qt.QTreeWidgetItem = itm
var browsePath []string
for {
browsePath = append(browsePath, top.Data(0, BinaryDataRole).ToString())
if top.Parent() == nil {
break
} else {
top = top.Parent()
}
}
ReverseSlice(browsePath)
ws := this.getSelection(itm)
// Remove existing children
i := itm.ChildCount()
for i > 0 {
itm.TakeChild(i).Delete()
itm.TakeChild(i - 1).Delete()
i -= 1
}
bdb := GET_BDB(top)
err := Bolt_ListBuckets(ws.bdb, ws.browse, func(qba string) {
err := Bolt_ListBuckets(bdb, browsePath, func(qba string) {
child := qt.NewQTreeWidgetItem()
child := qt.NewQTreeWidgetItem6(itm) // NewQTreeWidgetItem()
child.SetText(0, getDisplayName(qba))
child.SetData(0, BinaryDataRole, qt.NewQVariant14(qba))
child.SetData(0, BinaryDataRole, qt.NewQVariant15(MakeQByteArray(qba)))
child.SetIcon(0, qt.NewQIcon4(":/rsrc/table.png"))
itm.AddChild(child)
this.refreshBucketTree(child)
})
if err != nil {
this.alert(fmt.Sprintf("Error listing buckets: %s", err.Error()))
this.alert(fmt.Sprintf("Error listing buckets under %s: %s", strings.Join(ws.browse, `/`), err.Error()))
return
}
}
@ -222,11 +215,11 @@ func (this *MainWindow) on_bucketTree_customContextMenuRequested(pos *qt.QPoint)
if itm.Parent() != nil {
// Child item, show the bucket menu
this.bucketContext.Popup(this.ui.bucketTree.MapToGlobal(pos))
this.bucketContext.Popup(this.ui.bucketTree.Viewport().MapToGlobal(pos))
} else {
// Top-level item, show the database menu
this.databaseContext.Popup(this.ui.bucketTree.MapToGlobal(pos))
this.databaseContext.Popup(this.ui.bucketTree.Viewport().MapToGlobal(pos))
}
}
@ -266,28 +259,17 @@ func (this *MainWindow) on_bucketTree_currentItemChanged(current, previous *qt.Q
this.ui.stackedWidget.SetCurrentWidget(this.ui.bucketPage)
this.ui.bucketPropertiesArea.Clear()
top := current
var browse []string
for {
browse = append(browse, top.Data(0, BinaryDataRole).ToString())
if top.Parent() == nil {
break
} else {
top = top.Parent()
}
}
ReverseSlice(browse)
bdb := GET_BDB(top)
ws := this.getSelection(current)
stats, err := Bolt_BucketStats(bdb, browse)
stats, err := Bolt_BucketStats(ws.bdb, ws.browse)
if err != nil {
this.ui.databasePropertiesArea.SetPlainText(fmt.Sprintf("Error retrieving bucket statistics: %s", err.Error()))
this.ui.bucketPropertiesArea.SetPlainText(fmt.Sprintf("Error retrieving bucket statistics: %s", err.Error()))
} else {
this.ui.databasePropertiesArea.SetPlainText(stats)
this.ui.bucketPropertiesArea.SetPlainText(stats)
}
// Load the data tab
this.refreshData(bdb, browse)
this.refreshData(ws.bdb, ws.browse)
// Clean up foreign areas
this.ui.databasePropertiesArea.Clear()
@ -301,7 +283,7 @@ func (this *MainWindow) refreshData(bdb *bolt.DB, browse []string) {
err := Bolt_ListItems(bdb, browse, func(lii ListItemInfo) error {
itm := qt.NewQTreeWidgetItem()
itm.SetText(0, getDisplayName(lii.Name))
itm.SetData(0, BinaryDataRole, qt.NewQVariant14(lii.Name))
itm.SetData(0, BinaryDataRole, qt.NewQVariant15(MakeQByteArray(lii.Name)))
itm.SetText(1, fmt.Sprintf("%d", lii.DataLen))
this.ui.bucketData.AddTopLevelItem(itm)
return nil
@ -334,14 +316,19 @@ func (this *MainWindow) getWindowSelection() (windowSelection, bool) {
return windowSelection{}, false // No selection
}
return this.getSelection(itm), true
}
func (this *MainWindow) getSelection(itm *qt.QTreeWidgetItem) windowSelection {
top := itm
var browse []string
for {
browse = append(browse, top.Data(0, BinaryDataRole).ToString())
if top.Parent() == nil {
break
} else {
browse = append(browse, FromQByteArray(top.Data(0, BinaryDataRole).ToByteArray()))
top = top.Parent()
}
}
@ -350,7 +337,7 @@ func (this *MainWindow) getWindowSelection() (windowSelection, bool) {
bdb := GET_BDB(top)
return windowSelection{itm: itm, top: top, browse: browse, bdb: bdb}, true
return windowSelection{itm: itm, top: top, browse: browse, bdb: bdb}
}
func (this *MainWindow) openEditor(bdb *bolt.DB, saveAs []string, saveAsKey string, currentContent []byte) {
@ -384,7 +371,7 @@ func (this *MainWindow) on_bucketData_doubleClicked(index *qt.QModelIndex) {
// Get item key
model := index.Model()
key := model.Data2(model.Index(index.Row(), 0), BinaryDataRole).ToString()
key := FromQByteArray(model.Data2(model.Index(index.Row(), 0), BinaryDataRole).ToByteArray())
// DB lookup
content, err := Bolt_GetItem(ws.bdb, ws.browse, key)
@ -428,7 +415,7 @@ func (this *MainWindow) on_actionDelete_bucket_triggered() {
}
// Prompt for confirmation
bucketToDelete := ws.itm.Data(0, BinaryDataRole).ToString()
bucketToDelete := FromQByteArray(ws.itm.Data(0, BinaryDataRole).ToByteArray())
if qt.QMessageBox_Question4(
this.Widget(),
"Delete bucket",
@ -493,7 +480,7 @@ func (this *MainWindow) on_DeleteDataButton_clicked() {
var i int = len(selection)
for i > 0 {
err := Bolt_DeleteItem(ws.bdb, ws.browse, selection[i].Data(0, BinaryDataRole).ToString())
err := Bolt_DeleteItem(ws.bdb, ws.browse, FromQByteArray(selection[i-1].Data(0, BinaryDataRole).ToByteArray()))
if err != nil {
this.alert(fmt.Sprintf("Error removing item: %s", err.Error()))
return

View File

@ -269,12 +269,12 @@
<x>0</x>
<y>0</y>
<width>668</width>
<height>21</height>
<height>29</height>
</rect>
</property>
<widget class="QMenu" name="menuFile">
<property name="title">
<string>Fi&amp;le</string>
<string>&amp;File</string>
</property>
<addaction name="actionNew_database"/>
<addaction name="actionOpen_database"/>

View File

@ -1,336 +0,0 @@
/********************************************************************************
** Form generated from reading UI file 'mainwindow.ui'
**
** Created by: Qt User Interface Compiler version 5.15.8
**
** WARNING! All changes made in this file will be lost when recompiling UI file!
********************************************************************************/
#ifndef MAINWINDOW_UI_H
#define MAINWINDOW_UI_H
#include <QtCore/QVariant>
#include <QtGui/QIcon>
#include <QtWidgets/QAction>
#include <QtWidgets/QApplication>
#include <QtWidgets/QGridLayout>
#include <QtWidgets/QHeaderView>
#include <QtWidgets/QMainWindow>
#include <QtWidgets/QMenu>
#include <QtWidgets/QMenuBar>
#include <QtWidgets/QPlainTextEdit>
#include <QtWidgets/QPushButton>
#include <QtWidgets/QSpacerItem>
#include <QtWidgets/QSplitter>
#include <QtWidgets/QStackedWidget>
#include <QtWidgets/QStatusBar>
#include <QtWidgets/QTabWidget>
#include <QtWidgets/QToolBar>
#include <QtWidgets/QTreeWidget>
#include <QtWidgets/QWidget>
QT_BEGIN_NAMESPACE
class Ui_MainWindow
{
public:
QAction *actionAbout_qbolt;
QAction *actionAbout_Qt;
QAction *actionOpen_database;
QAction *actionExit;
QAction *actionDisconnect;
QAction *actionDelete_bucket;
QAction *actionRefresh_buckets;
QAction *actionClear_selection;
QAction *actionNew_database;
QAction *actionAdd_bucket;
QAction *actionOpen_database_as_read_only;
QWidget *centralWidget;
QGridLayout *gridLayout;
QSplitter *splitter;
QTreeWidget *bucketTree;
QStackedWidget *stackedWidget;
QWidget *databasePage;
QGridLayout *gridLayout_4;
QTabWidget *databaseTabWidget;
QWidget *databasePropertiesTab;
QGridLayout *gridLayout_2;
QPlainTextEdit *databasePropertiesArea;
QWidget *bucketPage;
QGridLayout *gridLayout_3;
QTabWidget *bucketTabWidget;
QWidget *bucketPropertiesTab;
QGridLayout *gridLayout_5;
QPlainTextEdit *bucketPropertiesArea;
QWidget *bucketDataTab;
QGridLayout *gridLayout_6;
QTreeWidget *bucketData;
QPushButton *AddDataButton;
QSpacerItem *horizontalSpacer;
QPushButton *DeleteDataButton;
QMenuBar *menuBar;
QMenu *menuFile;
QMenu *menuHelp;
QMenu *menuView;
QToolBar *mainToolBar;
QStatusBar *statusBar;
void setupUi(QMainWindow *MainWindow)
{
if (MainWindow->objectName().isEmpty())
MainWindow->setObjectName(QString::fromUtf8("MainWindow"));
MainWindow->resize(668, 405);
QIcon icon;
icon.addFile(QString::fromUtf8(":/rsrc/database_lightning.png"), QSize(), QIcon::Normal, QIcon::Off);
MainWindow->setWindowIcon(icon);
actionAbout_qbolt = new QAction(MainWindow);
actionAbout_qbolt->setObjectName(QString::fromUtf8("actionAbout_qbolt"));
QIcon icon1;
icon1.addFile(QString::fromUtf8(":/rsrc/information.png"), QSize(), QIcon::Normal, QIcon::Off);
actionAbout_qbolt->setIcon(icon1);
actionAbout_Qt = new QAction(MainWindow);
actionAbout_Qt->setObjectName(QString::fromUtf8("actionAbout_Qt"));
actionOpen_database = new QAction(MainWindow);
actionOpen_database->setObjectName(QString::fromUtf8("actionOpen_database"));
QIcon icon2;
icon2.addFile(QString::fromUtf8(":/rsrc/database.png"), QSize(), QIcon::Normal, QIcon::Off);
actionOpen_database->setIcon(icon2);
actionExit = new QAction(MainWindow);
actionExit->setObjectName(QString::fromUtf8("actionExit"));
QIcon icon3;
icon3.addFile(QString::fromUtf8(":/rsrc/door_out.png"), QSize(), QIcon::Normal, QIcon::Off);
actionExit->setIcon(icon3);
actionDisconnect = new QAction(MainWindow);
actionDisconnect->setObjectName(QString::fromUtf8("actionDisconnect"));
QIcon icon4;
icon4.addFile(QString::fromUtf8(":/rsrc/disconnect.png"), QSize(), QIcon::Normal, QIcon::Off);
actionDisconnect->setIcon(icon4);
actionDelete_bucket = new QAction(MainWindow);
actionDelete_bucket->setObjectName(QString::fromUtf8("actionDelete_bucket"));
QIcon icon5;
icon5.addFile(QString::fromUtf8(":/rsrc/table_delete.png"), QSize(), QIcon::Normal, QIcon::Off);
actionDelete_bucket->setIcon(icon5);
actionRefresh_buckets = new QAction(MainWindow);
actionRefresh_buckets->setObjectName(QString::fromUtf8("actionRefresh_buckets"));
QIcon icon6;
icon6.addFile(QString::fromUtf8(":/rsrc/arrow_refresh.png"), QSize(), QIcon::Normal, QIcon::Off);
actionRefresh_buckets->setIcon(icon6);
actionClear_selection = new QAction(MainWindow);
actionClear_selection->setObjectName(QString::fromUtf8("actionClear_selection"));
actionNew_database = new QAction(MainWindow);
actionNew_database->setObjectName(QString::fromUtf8("actionNew_database"));
QIcon icon7;
icon7.addFile(QString::fromUtf8(":/rsrc/database_add.png"), QSize(), QIcon::Normal, QIcon::Off);
actionNew_database->setIcon(icon7);
actionAdd_bucket = new QAction(MainWindow);
actionAdd_bucket->setObjectName(QString::fromUtf8("actionAdd_bucket"));
QIcon icon8;
icon8.addFile(QString::fromUtf8(":/rsrc/table_add.png"), QSize(), QIcon::Normal, QIcon::Off);
actionAdd_bucket->setIcon(icon8);
actionOpen_database_as_read_only = new QAction(MainWindow);
actionOpen_database_as_read_only->setObjectName(QString::fromUtf8("actionOpen_database_as_read_only"));
centralWidget = new QWidget(MainWindow);
centralWidget->setObjectName(QString::fromUtf8("centralWidget"));
gridLayout = new QGridLayout(centralWidget);
gridLayout->setSpacing(6);
gridLayout->setContentsMargins(11, 11, 11, 11);
gridLayout->setObjectName(QString::fromUtf8("gridLayout"));
gridLayout->setContentsMargins(0, 0, 0, 0);
splitter = new QSplitter(centralWidget);
splitter->setObjectName(QString::fromUtf8("splitter"));
splitter->setOrientation(Qt::Horizontal);
splitter->setChildrenCollapsible(false);
bucketTree = new QTreeWidget(splitter);
bucketTree->setObjectName(QString::fromUtf8("bucketTree"));
bucketTree->setContextMenuPolicy(Qt::CustomContextMenu);
bucketTree->setUniformRowHeights(true);
splitter->addWidget(bucketTree);
stackedWidget = new QStackedWidget(splitter);
stackedWidget->setObjectName(QString::fromUtf8("stackedWidget"));
databasePage = new QWidget();
databasePage->setObjectName(QString::fromUtf8("databasePage"));
gridLayout_4 = new QGridLayout(databasePage);
gridLayout_4->setSpacing(6);
gridLayout_4->setContentsMargins(11, 11, 11, 11);
gridLayout_4->setObjectName(QString::fromUtf8("gridLayout_4"));
gridLayout_4->setContentsMargins(0, 0, 0, 0);
databaseTabWidget = new QTabWidget(databasePage);
databaseTabWidget->setObjectName(QString::fromUtf8("databaseTabWidget"));
databasePropertiesTab = new QWidget();
databasePropertiesTab->setObjectName(QString::fromUtf8("databasePropertiesTab"));
gridLayout_2 = new QGridLayout(databasePropertiesTab);
gridLayout_2->setSpacing(6);
gridLayout_2->setContentsMargins(11, 11, 11, 11);
gridLayout_2->setObjectName(QString::fromUtf8("gridLayout_2"));
gridLayout_2->setContentsMargins(3, 3, 3, 3);
databasePropertiesArea = new QPlainTextEdit(databasePropertiesTab);
databasePropertiesArea->setObjectName(QString::fromUtf8("databasePropertiesArea"));
databasePropertiesArea->setFrameShape(QFrame::NoFrame);
databasePropertiesArea->setReadOnly(true);
gridLayout_2->addWidget(databasePropertiesArea, 0, 0, 1, 1);
QIcon icon9;
icon9.addFile(QString::fromUtf8(":/rsrc/chart_bar.png"), QSize(), QIcon::Normal, QIcon::Off);
databaseTabWidget->addTab(databasePropertiesTab, icon9, QString());
gridLayout_4->addWidget(databaseTabWidget, 0, 0, 1, 1);
stackedWidget->addWidget(databasePage);
bucketPage = new QWidget();
bucketPage->setObjectName(QString::fromUtf8("bucketPage"));
gridLayout_3 = new QGridLayout(bucketPage);
gridLayout_3->setSpacing(6);
gridLayout_3->setContentsMargins(11, 11, 11, 11);
gridLayout_3->setObjectName(QString::fromUtf8("gridLayout_3"));
gridLayout_3->setContentsMargins(0, 0, 0, 0);
bucketTabWidget = new QTabWidget(bucketPage);
bucketTabWidget->setObjectName(QString::fromUtf8("bucketTabWidget"));
bucketPropertiesTab = new QWidget();
bucketPropertiesTab->setObjectName(QString::fromUtf8("bucketPropertiesTab"));
gridLayout_5 = new QGridLayout(bucketPropertiesTab);
gridLayout_5->setSpacing(6);
gridLayout_5->setContentsMargins(11, 11, 11, 11);
gridLayout_5->setObjectName(QString::fromUtf8("gridLayout_5"));
gridLayout_5->setContentsMargins(3, 3, 3, 3);
bucketPropertiesArea = new QPlainTextEdit(bucketPropertiesTab);
bucketPropertiesArea->setObjectName(QString::fromUtf8("bucketPropertiesArea"));
bucketPropertiesArea->setFrameShape(QFrame::NoFrame);
bucketPropertiesArea->setReadOnly(true);
gridLayout_5->addWidget(bucketPropertiesArea, 0, 0, 1, 1);
bucketTabWidget->addTab(bucketPropertiesTab, icon9, QString());
bucketDataTab = new QWidget();
bucketDataTab->setObjectName(QString::fromUtf8("bucketDataTab"));
gridLayout_6 = new QGridLayout(bucketDataTab);
gridLayout_6->setSpacing(6);
gridLayout_6->setContentsMargins(11, 11, 11, 11);
gridLayout_6->setObjectName(QString::fromUtf8("gridLayout_6"));
gridLayout_6->setContentsMargins(3, 3, 3, 3);
bucketData = new QTreeWidget(bucketDataTab);
bucketData->setObjectName(QString::fromUtf8("bucketData"));
bucketData->setSelectionMode(QAbstractItemView::ExtendedSelection);
bucketData->setIndentation(0);
bucketData->setRootIsDecorated(false);
bucketData->setUniformRowHeights(true);
bucketData->setItemsExpandable(false);
gridLayout_6->addWidget(bucketData, 0, 0, 1, 3);
AddDataButton = new QPushButton(bucketDataTab);
AddDataButton->setObjectName(QString::fromUtf8("AddDataButton"));
QIcon icon10;
icon10.addFile(QString::fromUtf8(":/rsrc/add.png"), QSize(), QIcon::Normal, QIcon::Off);
AddDataButton->setIcon(icon10);
gridLayout_6->addWidget(AddDataButton, 1, 0, 1, 1);
horizontalSpacer = new QSpacerItem(40, 20, QSizePolicy::Expanding, QSizePolicy::Minimum);
gridLayout_6->addItem(horizontalSpacer, 1, 2, 1, 1);
DeleteDataButton = new QPushButton(bucketDataTab);
DeleteDataButton->setObjectName(QString::fromUtf8("DeleteDataButton"));
QIcon icon11;
icon11.addFile(QString::fromUtf8(":/rsrc/delete.png"), QSize(), QIcon::Normal, QIcon::Off);
DeleteDataButton->setIcon(icon11);
gridLayout_6->addWidget(DeleteDataButton, 1, 1, 1, 1);
QIcon icon12;
icon12.addFile(QString::fromUtf8(":/rsrc/table.png"), QSize(), QIcon::Normal, QIcon::Off);
bucketTabWidget->addTab(bucketDataTab, icon12, QString());
gridLayout_3->addWidget(bucketTabWidget, 0, 0, 1, 1);
stackedWidget->addWidget(bucketPage);
splitter->addWidget(stackedWidget);
gridLayout->addWidget(splitter, 0, 0, 1, 1);
MainWindow->setCentralWidget(centralWidget);
menuBar = new QMenuBar(MainWindow);
menuBar->setObjectName(QString::fromUtf8("menuBar"));
menuBar->setGeometry(QRect(0, 0, 668, 21));
menuFile = new QMenu(menuBar);
menuFile->setObjectName(QString::fromUtf8("menuFile"));
menuHelp = new QMenu(menuBar);
menuHelp->setObjectName(QString::fromUtf8("menuHelp"));
menuView = new QMenu(menuBar);
menuView->setObjectName(QString::fromUtf8("menuView"));
MainWindow->setMenuBar(menuBar);
mainToolBar = new QToolBar(MainWindow);
mainToolBar->setObjectName(QString::fromUtf8("mainToolBar"));
MainWindow->addToolBar(Qt::TopToolBarArea, mainToolBar);
statusBar = new QStatusBar(MainWindow);
statusBar->setObjectName(QString::fromUtf8("statusBar"));
MainWindow->setStatusBar(statusBar);
menuBar->addAction(menuFile->menuAction());
menuBar->addAction(menuView->menuAction());
menuBar->addAction(menuHelp->menuAction());
menuFile->addAction(actionNew_database);
menuFile->addAction(actionOpen_database);
menuFile->addAction(actionOpen_database_as_read_only);
menuFile->addSeparator();
menuFile->addAction(actionExit);
menuHelp->addAction(actionAbout_qbolt);
menuHelp->addAction(actionAbout_Qt);
menuView->addAction(actionClear_selection);
mainToolBar->addAction(actionNew_database);
mainToolBar->addAction(actionOpen_database);
mainToolBar->addSeparator();
retranslateUi(MainWindow);
stackedWidget->setCurrentIndex(0);
databaseTabWidget->setCurrentIndex(0);
bucketTabWidget->setCurrentIndex(0);
QMetaObject::connectSlotsByName(MainWindow);
} // setupUi
void retranslateUi(QMainWindow *MainWindow)
{
MainWindow->setWindowTitle(QCoreApplication::translate("MainWindow", "QBolt", nullptr));
actionAbout_qbolt->setText(QCoreApplication::translate("MainWindow", "&About QBolt", nullptr));
actionAbout_Qt->setText(QCoreApplication::translate("MainWindow", "About &Qt", nullptr));
actionOpen_database->setText(QCoreApplication::translate("MainWindow", "&Open database...", nullptr));
#if QT_CONFIG(shortcut)
actionOpen_database->setShortcut(QCoreApplication::translate("MainWindow", "Ctrl+O", nullptr));
#endif // QT_CONFIG(shortcut)
actionExit->setText(QCoreApplication::translate("MainWindow", "&Exit", nullptr));
actionDisconnect->setText(QCoreApplication::translate("MainWindow", "Disconnect", nullptr));
actionDelete_bucket->setText(QCoreApplication::translate("MainWindow", "Delete bucket", nullptr));
actionRefresh_buckets->setText(QCoreApplication::translate("MainWindow", "Refresh buckets", nullptr));
actionClear_selection->setText(QCoreApplication::translate("MainWindow", "&Clear selection", nullptr));
actionNew_database->setText(QCoreApplication::translate("MainWindow", "&New database...", nullptr));
actionAdd_bucket->setText(QCoreApplication::translate("MainWindow", "Add bucket...", nullptr));
actionOpen_database_as_read_only->setText(QCoreApplication::translate("MainWindow", "Open database as read-only...", nullptr));
QTreeWidgetItem *___qtreewidgetitem = bucketTree->headerItem();
___qtreewidgetitem->setText(0, QCoreApplication::translate("MainWindow", "Bucket", nullptr));
databasePropertiesArea->setPlainText(QCoreApplication::translate("MainWindow", "No selection", nullptr));
databaseTabWidget->setTabText(databaseTabWidget->indexOf(databasePropertiesTab), QCoreApplication::translate("MainWindow", "Database", nullptr));
bucketTabWidget->setTabText(bucketTabWidget->indexOf(bucketPropertiesTab), QCoreApplication::translate("MainWindow", "Bucket", nullptr));
QTreeWidgetItem *___qtreewidgetitem1 = bucketData->headerItem();
___qtreewidgetitem1->setText(1, QCoreApplication::translate("MainWindow", "Data length", nullptr));
___qtreewidgetitem1->setText(0, QCoreApplication::translate("MainWindow", "Key", nullptr));
AddDataButton->setText(QCoreApplication::translate("MainWindow", "Add...", nullptr));
DeleteDataButton->setText(QCoreApplication::translate("MainWindow", "Delete...", nullptr));
bucketTabWidget->setTabText(bucketTabWidget->indexOf(bucketDataTab), QCoreApplication::translate("MainWindow", "Data", nullptr));
menuFile->setTitle(QCoreApplication::translate("MainWindow", "Fi&le", nullptr));
menuHelp->setTitle(QCoreApplication::translate("MainWindow", "Help", nullptr));
menuView->setTitle(QCoreApplication::translate("MainWindow", "&View", nullptr));
} // retranslateUi
};
namespace Ui {
class MainWindow: public Ui_MainWindow {};
} // namespace Ui
QT_END_NAMESPACE
#endif // MAINWINDOW_UI_H

View File

@ -221,7 +221,7 @@ func NewMainWindowUi() *MainWindowUi {
ui.bucketData.SetUniformRowHeights(true)
ui.bucketData.SetItemsExpandable(false)
ui.gridLayout_6.AddWidget2(ui.bucketData.QWidget, 0, 0)
ui.gridLayout_6.AddWidget3(ui.bucketData.QWidget, 0, 0, 1, 3)
ui.AddDataButton = qt.NewQPushButton4(ui.bucketDataTab)
ui.AddDataButton.SetObjectName("AddDataButton")
@ -252,7 +252,7 @@ func NewMainWindowUi() *MainWindowUi {
ui.menuBar = qt.NewQMenuBar2(ui.MainWindow.QWidget)
ui.menuBar.SetObjectName("menuBar")
ui.menuBar.Resize(668, 21)
ui.menuBar.Resize(668, 29)
ui.menuFile = qt.NewQMenu3(ui.menuBar.QWidget)
ui.menuFile.SetObjectName("menuFile")
@ -319,7 +319,7 @@ func (ui *MainWindowUi) Retranslate() {
ui.bucketData.HeaderItem().SetText(1, qt.QTreeWidget_Tr("Data length"))
ui.AddDataButton.SetText(qt.QWidget_Tr("Add..."))
ui.DeleteDataButton.SetText(qt.QWidget_Tr("Delete..."))
ui.menuFile.SetTitle(qt.QMenuBar_Tr("Fi&le"))
ui.menuFile.SetTitle(qt.QMenuBar_Tr("&File"))
ui.menuHelp.SetTitle(qt.QMenuBar_Tr("Help"))
ui.menuView.SetTitle(qt.QMenuBar_Tr("&View"))
}

15
util.go
View File

@ -1,5 +1,11 @@
package main
import (
"unsafe"
"github.com/mappu/miqt/qt"
)
// ReverseSlice reverses a slice.
// @ref https://stackoverflow.com/a/28058324
func ReverseSlice[S ~[]E, E any](s S) {
@ -7,3 +13,12 @@ func ReverseSlice[S ~[]E, E any](s S) {
s[i], s[j] = s[j], s[i]
}
}
func MakeQByteArray(s string) *qt.QByteArray {
return qt.NewQByteArray7(s, len(s))
}
func FromQByteArray(qba *qt.QByteArray) string {
var rawData []byte = unsafe.Slice((*byte)(qba.Data()), qba.Length())
return string(rawData) // copy
}

17
util_test.go Normal file
View File

@ -0,0 +1,17 @@
package main
import (
"testing"
)
func TestQByteArray(t *testing.T) {
foo := "the \x00 quick \x01 brown \x02 fox \x03 jumps \x04 over \x05 the \x06 lazy \x07 dog"
qb := MakeQByteArray(foo)
out := FromQByteArray(qb)
if foo != out {
t.Errorf("Expected equal")
}
}