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->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()
|
||||
@ -18,6 +27,10 @@ MainWindow::~MainWindow()
|
||||
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()
|
||||
{
|
||||
@ -37,10 +50,26 @@ void MainWindow::on_actionOpen_database_triggered()
|
||||
}
|
||||
|
||||
QTreeWidgetItem *top = new QTreeWidgetItem();
|
||||
top->setText(0, QFileInfo(file).completeBaseName());
|
||||
top->setText(0, QFileInfo(file).fileName());
|
||||
top->setIcon(0, QIcon(":/rsrc/database.png"));
|
||||
SET_BDB(top, bdb);
|
||||
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){
|
||||
QTreeWidgetItem *child = new QTreeWidgetItem();
|
||||
child->setText(0, QString::fromUtf8(qba));
|
||||
@ -54,9 +83,6 @@ void MainWindow::on_actionOpen_database_triggered()
|
||||
qmb.exec();
|
||||
// (continue)
|
||||
}
|
||||
|
||||
// Free
|
||||
delete bdb;
|
||||
}
|
||||
|
||||
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
|
||||
|
||||
#include <QMainWindow>
|
||||
#include <QMenu>
|
||||
#include <QTreeWidgetItem>
|
||||
|
||||
namespace Ui {
|
||||
class MainWindow;
|
||||
@ -24,8 +26,25 @@ private slots:
|
||||
|
||||
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:
|
||||
Ui::MainWindow *ui;
|
||||
|
||||
QMenu *databaseContext;
|
||||
QMenu *bucketContext;
|
||||
QTreeWidgetItem* lastContextSelection;
|
||||
};
|
||||
|
||||
#endif // MAINWINDOW_H
|
||||
|
@ -40,6 +40,9 @@
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<widget class="QTreeWidget" name="bucketTree">
|
||||
<property name="contextMenuPolicy">
|
||||
<enum>Qt::CustomContextMenu</enum>
|
||||
</property>
|
||||
<property name="uniformRowHeights">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
@ -157,7 +160,14 @@
|
||||
<addaction name="actionAbout_qbolt"/>
|
||||
<addaction name="actionAbout_Qt"/>
|
||||
</widget>
|
||||
<widget class="QMenu" name="menuView">
|
||||
<property name="title">
|
||||
<string>&View</string>
|
||||
</property>
|
||||
<addaction name="actionClear_selection"/>
|
||||
</widget>
|
||||
<addaction name="menuFile"/>
|
||||
<addaction name="menuView"/>
|
||||
<addaction name="menuHelp"/>
|
||||
</widget>
|
||||
<widget class="QToolBar" name="mainToolBar">
|
||||
@ -192,12 +202,38 @@
|
||||
<property name="text">
|
||||
<string>&Open database...</string>
|
||||
</property>
|
||||
<property name="shortcut">
|
||||
<string>Ctrl+O</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="actionExit">
|
||||
<property name="text">
|
||||
<string>&Exit</string>
|
||||
</property>
|
||||
</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>
|
||||
<layoutdefault spacing="6" margin="11"/>
|
||||
<resources>
|
||||
|
Loading…
Reference in New Issue
Block a user