context menus, disconnection, re-refresh, selection behaviour, ^O shortcut
This commit is contained in:
parent
d32ab82d73
commit
8597f270f6
@ -11,6 +11,15 @@ MainWindow::MainWindow(QWidget *parent) :
|
|||||||
ui(new Ui::MainWindow)
|
ui(new Ui::MainWindow)
|
||||||
{
|
{
|
||||||
ui->setupUi(this);
|
ui->setupUi(this);
|
||||||
|
|
||||||
|
on_bucketTree_currentItemChanged(nullptr, nullptr);
|
||||||
|
|
||||||
|
databaseContext = new QMenu();
|
||||||
|
databaseContext->addAction(ui->actionRefresh_buckets);
|
||||||
|
databaseContext->addAction(ui->actionDisconnect);
|
||||||
|
|
||||||
|
bucketContext = new QMenu();
|
||||||
|
bucketContext->addAction(ui->actionDelete_bucket);
|
||||||
}
|
}
|
||||||
|
|
||||||
MainWindow::~MainWindow()
|
MainWindow::~MainWindow()
|
||||||
@ -18,6 +27,10 @@ MainWindow::~MainWindow()
|
|||||||
delete ui;
|
delete ui;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static const int BdbPointerRole = Qt::UserRole + 1;
|
||||||
|
#define SET_BDB(top, bdb) top->setData(0, BdbPointerRole, QVariant::fromValue<void*>(static_cast<void*>(bdb)))
|
||||||
|
#define GET_BDB(top) static_cast<BoltDB*>( top->data(0, BdbPointerRole).value<void*>() )
|
||||||
|
|
||||||
|
|
||||||
void MainWindow::on_actionOpen_database_triggered()
|
void MainWindow::on_actionOpen_database_triggered()
|
||||||
{
|
{
|
||||||
@ -37,10 +50,26 @@ void MainWindow::on_actionOpen_database_triggered()
|
|||||||
}
|
}
|
||||||
|
|
||||||
QTreeWidgetItem *top = new QTreeWidgetItem();
|
QTreeWidgetItem *top = new QTreeWidgetItem();
|
||||||
top->setText(0, QFileInfo(file).completeBaseName());
|
top->setText(0, QFileInfo(file).fileName());
|
||||||
top->setIcon(0, QIcon(":/rsrc/database.png"));
|
top->setIcon(0, QIcon(":/rsrc/database.png"));
|
||||||
|
SET_BDB(top, bdb);
|
||||||
ui->bucketTree->addTopLevelItem(top);
|
ui->bucketTree->addTopLevelItem(top);
|
||||||
|
|
||||||
|
refreshBucketTree(top);
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainWindow::refreshBucketTree(QTreeWidgetItem* top)
|
||||||
|
{
|
||||||
|
ui->bucketTree->clearSelection();
|
||||||
|
//top->setSelected(true);
|
||||||
|
ui->bucketTree->setCurrentItem(top);
|
||||||
|
|
||||||
|
auto *bdb = GET_BDB(top);
|
||||||
|
for (int i = top->childCount(); i --> 0;) {
|
||||||
|
delete top->takeChild(i);
|
||||||
|
}
|
||||||
|
|
||||||
|
QString error;
|
||||||
bool ok = bdb->listBucketsAtRoot(error, [=](QByteArray qba){
|
bool ok = bdb->listBucketsAtRoot(error, [=](QByteArray qba){
|
||||||
QTreeWidgetItem *child = new QTreeWidgetItem();
|
QTreeWidgetItem *child = new QTreeWidgetItem();
|
||||||
child->setText(0, QString::fromUtf8(qba));
|
child->setText(0, QString::fromUtf8(qba));
|
||||||
@ -54,9 +83,6 @@ void MainWindow::on_actionOpen_database_triggered()
|
|||||||
qmb.exec();
|
qmb.exec();
|
||||||
// (continue)
|
// (continue)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Free
|
|
||||||
delete bdb;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::on_actionExit_triggered()
|
void MainWindow::on_actionExit_triggered()
|
||||||
@ -81,3 +107,60 @@ void MainWindow::on_actionAbout_qbolt_triggered()
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MainWindow::on_actionDisconnect_triggered()
|
||||||
|
{
|
||||||
|
QTreeWidgetItem *top = lastContextSelection;
|
||||||
|
if (top->parent()) {
|
||||||
|
return; // somehow we didn't select a top-level item
|
||||||
|
}
|
||||||
|
|
||||||
|
auto *bdb = GET_BDB(top);
|
||||||
|
|
||||||
|
// Remove UI
|
||||||
|
ui->bucketTree->clearSelection();
|
||||||
|
delete top;
|
||||||
|
|
||||||
|
// Disconnect from DB
|
||||||
|
delete bdb;
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainWindow::on_bucketTree_customContextMenuRequested(const QPoint &pos)
|
||||||
|
{
|
||||||
|
auto *itm = ui->bucketTree->itemAt(pos);
|
||||||
|
if (itm == nullptr) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
lastContextSelection = itm;
|
||||||
|
|
||||||
|
if (itm->parent() != nullptr) {
|
||||||
|
// Child item, show the bucket menu
|
||||||
|
bucketContext->popup(ui->bucketTree->mapToGlobal(pos));
|
||||||
|
|
||||||
|
} else {
|
||||||
|
// Top-level item, show the database menu
|
||||||
|
databaseContext->popup(ui->bucketTree->mapToGlobal(pos));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainWindow::on_actionRefresh_buckets_triggered()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainWindow::on_bucketTree_currentItemChanged(QTreeWidgetItem *current, QTreeWidgetItem *previous)
|
||||||
|
{
|
||||||
|
Q_UNUSED(previous);
|
||||||
|
if (current == nullptr) {
|
||||||
|
ui->tabWidget->setVisible(false);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
ui->tabWidget->setVisible(true);
|
||||||
|
// refresh properties for the currently selected tree item...
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainWindow::on_actionClear_selection_triggered()
|
||||||
|
{
|
||||||
|
ui->bucketTree->setCurrentItem(nullptr);
|
||||||
|
}
|
||||||
|
@ -2,6 +2,8 @@
|
|||||||
#define MAINWINDOW_H
|
#define MAINWINDOW_H
|
||||||
|
|
||||||
#include <QMainWindow>
|
#include <QMainWindow>
|
||||||
|
#include <QMenu>
|
||||||
|
#include <QTreeWidgetItem>
|
||||||
|
|
||||||
namespace Ui {
|
namespace Ui {
|
||||||
class MainWindow;
|
class MainWindow;
|
||||||
@ -24,8 +26,25 @@ private slots:
|
|||||||
|
|
||||||
void on_actionAbout_qbolt_triggered();
|
void on_actionAbout_qbolt_triggered();
|
||||||
|
|
||||||
|
void on_actionDisconnect_triggered();
|
||||||
|
|
||||||
|
void on_bucketTree_customContextMenuRequested(const QPoint &pos);
|
||||||
|
|
||||||
|
void on_actionRefresh_buckets_triggered();
|
||||||
|
|
||||||
|
void on_bucketTree_currentItemChanged(QTreeWidgetItem *current, QTreeWidgetItem *previous);
|
||||||
|
|
||||||
|
void on_actionClear_selection_triggered();
|
||||||
|
|
||||||
|
protected:
|
||||||
|
void refreshBucketTree(QTreeWidgetItem* top);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Ui::MainWindow *ui;
|
Ui::MainWindow *ui;
|
||||||
|
|
||||||
|
QMenu *databaseContext;
|
||||||
|
QMenu *bucketContext;
|
||||||
|
QTreeWidgetItem* lastContextSelection;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // MAINWINDOW_H
|
#endif // MAINWINDOW_H
|
||||||
|
@ -40,6 +40,9 @@
|
|||||||
<bool>false</bool>
|
<bool>false</bool>
|
||||||
</property>
|
</property>
|
||||||
<widget class="QTreeWidget" name="bucketTree">
|
<widget class="QTreeWidget" name="bucketTree">
|
||||||
|
<property name="contextMenuPolicy">
|
||||||
|
<enum>Qt::CustomContextMenu</enum>
|
||||||
|
</property>
|
||||||
<property name="uniformRowHeights">
|
<property name="uniformRowHeights">
|
||||||
<bool>true</bool>
|
<bool>true</bool>
|
||||||
</property>
|
</property>
|
||||||
@ -157,7 +160,14 @@
|
|||||||
<addaction name="actionAbout_qbolt"/>
|
<addaction name="actionAbout_qbolt"/>
|
||||||
<addaction name="actionAbout_Qt"/>
|
<addaction name="actionAbout_Qt"/>
|
||||||
</widget>
|
</widget>
|
||||||
|
<widget class="QMenu" name="menuView">
|
||||||
|
<property name="title">
|
||||||
|
<string>&View</string>
|
||||||
|
</property>
|
||||||
|
<addaction name="actionClear_selection"/>
|
||||||
|
</widget>
|
||||||
<addaction name="menuFile"/>
|
<addaction name="menuFile"/>
|
||||||
|
<addaction name="menuView"/>
|
||||||
<addaction name="menuHelp"/>
|
<addaction name="menuHelp"/>
|
||||||
</widget>
|
</widget>
|
||||||
<widget class="QToolBar" name="mainToolBar">
|
<widget class="QToolBar" name="mainToolBar">
|
||||||
@ -192,12 +202,38 @@
|
|||||||
<property name="text">
|
<property name="text">
|
||||||
<string>&Open database...</string>
|
<string>&Open database...</string>
|
||||||
</property>
|
</property>
|
||||||
|
<property name="shortcut">
|
||||||
|
<string>Ctrl+O</string>
|
||||||
|
</property>
|
||||||
</action>
|
</action>
|
||||||
<action name="actionExit">
|
<action name="actionExit">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>&Exit</string>
|
<string>&Exit</string>
|
||||||
</property>
|
</property>
|
||||||
</action>
|
</action>
|
||||||
|
<action name="actionDisconnect">
|
||||||
|
<property name="text">
|
||||||
|
<string>Disconnect</string>
|
||||||
|
</property>
|
||||||
|
</action>
|
||||||
|
<action name="actionDelete_bucket">
|
||||||
|
<property name="enabled">
|
||||||
|
<bool>false</bool>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string>Delete bucket</string>
|
||||||
|
</property>
|
||||||
|
</action>
|
||||||
|
<action name="actionRefresh_buckets">
|
||||||
|
<property name="text">
|
||||||
|
<string>Refresh buckets</string>
|
||||||
|
</property>
|
||||||
|
</action>
|
||||||
|
<action name="actionClear_selection">
|
||||||
|
<property name="text">
|
||||||
|
<string>Clear selection</string>
|
||||||
|
</property>
|
||||||
|
</action>
|
||||||
</widget>
|
</widget>
|
||||||
<layoutdefault spacing="6" margin="11"/>
|
<layoutdefault spacing="6" margin="11"/>
|
||||||
<resources>
|
<resources>
|
||||||
|
Loading…
Reference in New Issue
Block a user