First tab at building a mechanism where tabpages can supply a list of actions that are added to the global main toolbar.
This commit is contained in:
parent
c2d725ec6d
commit
3d516e6006
10 changed files with 130 additions and 26 deletions
|
|
@ -7,7 +7,7 @@
|
||||||
|
|
||||||
|
|
||||||
CrudTab::CrudTab(MainWindow *parent)
|
CrudTab::CrudTab(MainWindow *parent)
|
||||||
: QWidget(parent)
|
: PlgPage(parent)
|
||||||
, ui(new Ui::CrudTab)
|
, ui(new Ui::CrudTab)
|
||||||
, m_window(parent)
|
, m_window(parent)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@
|
||||||
|
|
||||||
#include "PgClass.h"
|
#include "PgClass.h"
|
||||||
#include <QWidget>
|
#include <QWidget>
|
||||||
|
#include "PlgPage.h"
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
||||||
namespace Ui {
|
namespace Ui {
|
||||||
|
|
@ -13,7 +14,7 @@ class OpenDatabase;
|
||||||
class CrudModel;
|
class CrudModel;
|
||||||
class MainWindow;
|
class MainWindow;
|
||||||
|
|
||||||
class CrudTab : public QWidget
|
class CrudTab : public PlgPage
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -13,6 +13,7 @@
|
||||||
#include <QMetaMethod>
|
#include <QMetaMethod>
|
||||||
#include "QueryTab.h"
|
#include "QueryTab.h"
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
|
#include "PlgPage.h"
|
||||||
#include "MasterController.h"
|
#include "MasterController.h"
|
||||||
#include "CrudTab.h"
|
#include "CrudTab.h"
|
||||||
#include "WorkManager.h"
|
#include "WorkManager.h"
|
||||||
|
|
@ -40,8 +41,9 @@ QueryTab* MainWindow::newSqlPage()
|
||||||
{
|
{
|
||||||
QueryTab *qt = new QueryTab(this);
|
QueryTab *qt = new QueryTab(this);
|
||||||
qt->setConfig(m_config, m_database->catalogue());
|
qt->setConfig(m_config, m_database->catalogue());
|
||||||
ui->tabWidget->addTab(qt, "Tab");
|
// ui->tabWidget->addTab(qt, "Tab");
|
||||||
ui->tabWidget->setCurrentWidget(qt);
|
// ui->tabWidget->setCurrentWidget(qt);
|
||||||
|
addPage(qt, "Tab");
|
||||||
qt->newdoc();
|
qt->newdoc();
|
||||||
qt->focusEditor();
|
qt->focusEditor();
|
||||||
return qt;
|
return qt;
|
||||||
|
|
@ -51,8 +53,9 @@ void MainWindow::newCrudPage(const PgClass &table)
|
||||||
{
|
{
|
||||||
CrudTab *ct = new CrudTab(this);
|
CrudTab *ct = new CrudTab(this);
|
||||||
ct->setConfig(m_database, table);
|
ct->setConfig(m_database, table);
|
||||||
ui->tabWidget->addTab(ct, table.name);
|
// ui->tabWidget->addTab(ct, table.name);
|
||||||
ui->tabWidget->setCurrentWidget(ct);
|
// ui->tabWidget->setCurrentWidget(ct);
|
||||||
|
addPage(ct, table.name);
|
||||||
}
|
}
|
||||||
|
|
||||||
QueryTab *MainWindow::GetActiveQueryTab()
|
QueryTab *MainWindow::GetActiveQueryTab()
|
||||||
|
|
@ -262,9 +265,20 @@ void MainWindow::on_actionNew_SQL_triggered()
|
||||||
newSqlPage();
|
newSqlPage();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void MainWindow::on_tabWidget_tabCloseRequested(int index)
|
void MainWindow::on_tabWidget_tabCloseRequested(int index)
|
||||||
{
|
{
|
||||||
QWidget *widget = ui->tabWidget->widget(index);
|
QWidget *widget = ui->tabWidget->widget(index);
|
||||||
|
PlgPage *plg_page = dynamic_cast<PlgPage*>(widget);
|
||||||
|
if (plg_page) {
|
||||||
|
if (plg_page->canClose()) {
|
||||||
|
removePage(plg_page);
|
||||||
|
ui->tabWidget->removeTab(index);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
// old behaviour shouldn't be needed any more when all pages have been migrated
|
||||||
|
// to PlgPage
|
||||||
QueryTab *qt = dynamic_cast<QueryTab*>(widget);
|
QueryTab *qt = dynamic_cast<QueryTab*>(widget);
|
||||||
if (qt && qt->canClose()) {
|
if (qt && qt->canClose()) {
|
||||||
ui->tabWidget->removeTab(index);
|
ui->tabWidget->removeTab(index);
|
||||||
|
|
@ -272,6 +286,7 @@ void MainWindow::on_tabWidget_tabCloseRequested(int index)
|
||||||
else if (index > 0) {
|
else if (index > 0) {
|
||||||
ui->tabWidget->removeTab(index);
|
ui->tabWidget->removeTab(index);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -319,3 +334,54 @@ void MainWindow::on_actionCopy_as_raw_Cpp_string_triggered()
|
||||||
tab->copyQueryAsRawCppString();
|
tab->copyQueryAsRawCppString();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MainWindow::addToolBarButtonsForPage(PlgPage *page)
|
||||||
|
{
|
||||||
|
std::vector<QAction*> actions = page->getToolbarActions();
|
||||||
|
QList<QAction*> list;
|
||||||
|
for (auto act : actions) {
|
||||||
|
list.append(act);
|
||||||
|
}
|
||||||
|
ui->mainToolBar->addActions(list);
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainWindow::removeToolBarButtonsForPage(PlgPage *page)
|
||||||
|
{
|
||||||
|
std::vector<QAction*> actions = page->getToolbarActions();
|
||||||
|
for (auto act : actions) {
|
||||||
|
ui->mainToolBar->removeAction(act);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void MainWindow::addPage(PlgPage* page, QString caption)
|
||||||
|
{
|
||||||
|
ui->tabWidget->addTab(page, caption);
|
||||||
|
ui->tabWidget->setCurrentWidget(page);
|
||||||
|
|
||||||
|
//addToolBarButtonsForPage(page);
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainWindow::removePage(PlgPage *page)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainWindow::on_tabWidget_currentChanged(int index)
|
||||||
|
{
|
||||||
|
// remove buttons of old page
|
||||||
|
if (m_previousPage) {
|
||||||
|
removeToolBarButtonsForPage(m_previousPage);
|
||||||
|
}
|
||||||
|
|
||||||
|
// add buttons of new page
|
||||||
|
PlgPage * page = nullptr;
|
||||||
|
if (index >= 0) {
|
||||||
|
QWidget *widget = ui->tabWidget->widget(index);
|
||||||
|
page = dynamic_cast<PlgPage*>(widget);
|
||||||
|
if (page) {
|
||||||
|
addToolBarButtonsForPage(page);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
m_previousPage = page;
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -33,6 +33,7 @@ class MasterController;
|
||||||
class QCloseEvent;
|
class QCloseEvent;
|
||||||
class OpenDatabase;
|
class OpenDatabase;
|
||||||
class PgClass;
|
class PgClass;
|
||||||
|
class PlgPage;
|
||||||
|
|
||||||
class MainWindow : public ASyncWindow {
|
class MainWindow : public ASyncWindow {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
@ -53,6 +54,7 @@ private:
|
||||||
std::shared_ptr<OpenDatabase> m_database;
|
std::shared_ptr<OpenDatabase> m_database;
|
||||||
|
|
||||||
MasterController *m_masterController;
|
MasterController *m_masterController;
|
||||||
|
PlgPage *m_previousPage = nullptr; ///< tracks which pages buttons were previously being displayed
|
||||||
|
|
||||||
class QLoad : public QueuedBackgroundTask {
|
class QLoad : public QueuedBackgroundTask {
|
||||||
public:
|
public:
|
||||||
|
|
@ -90,6 +92,14 @@ private:
|
||||||
|
|
||||||
void catalogLoaded();
|
void catalogLoaded();
|
||||||
|
|
||||||
|
/// Called when a newly created page is added to the QTabWidget
|
||||||
|
void addPage(PlgPage* page, QString caption);
|
||||||
|
/// Called when a page is completely removed from the QTabWidget
|
||||||
|
void removePage(PlgPage *page);
|
||||||
|
|
||||||
|
void addToolBarButtonsForPage(PlgPage *page);
|
||||||
|
void removeToolBarButtonsForPage(PlgPage *page);
|
||||||
|
//class PageData
|
||||||
private slots:
|
private slots:
|
||||||
|
|
||||||
void on_actionLoad_SQL_triggered();
|
void on_actionLoad_SQL_triggered();
|
||||||
|
|
@ -109,6 +119,7 @@ private slots:
|
||||||
void on_actionCopy_triggered();
|
void on_actionCopy_triggered();
|
||||||
void on_actionCopy_as_C_string_triggered();
|
void on_actionCopy_as_C_string_triggered();
|
||||||
void on_actionCopy_as_raw_Cpp_string_triggered();
|
void on_actionCopy_as_raw_Cpp_string_triggered();
|
||||||
|
void on_tabWidget_currentChanged(int index);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // MAINWINDOW_H
|
#endif // MAINWINDOW_H
|
||||||
|
|
|
||||||
|
|
@ -1,6 +0,0 @@
|
||||||
#include "PglPage.h"
|
|
||||||
|
|
||||||
//PglPage::PglPage()
|
|
||||||
//{
|
|
||||||
|
|
||||||
//}
|
|
||||||
16
pglab/PlgPage.cpp
Normal file
16
pglab/PlgPage.cpp
Normal file
|
|
@ -0,0 +1,16 @@
|
||||||
|
#include "PlgPage.h"
|
||||||
|
|
||||||
|
//PglPage::PglPage()
|
||||||
|
//{
|
||||||
|
|
||||||
|
//}
|
||||||
|
|
||||||
|
std::vector<QAction*> PlgPage::getToolbarActions()
|
||||||
|
{
|
||||||
|
return std::vector<QAction*>();
|
||||||
|
}
|
||||||
|
|
||||||
|
bool PlgPage::canClose()
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
@ -2,6 +2,7 @@
|
||||||
#define PGLPAGE_H
|
#define PGLPAGE_H
|
||||||
|
|
||||||
#include <QWidget>
|
#include <QWidget>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
/// Provides a pluggable system for toolbar buttons and menu actions
|
/// Provides a pluggable system for toolbar buttons and menu actions
|
||||||
///
|
///
|
||||||
|
|
@ -14,11 +15,13 @@
|
||||||
/// Can we use same groupings for toolbars and menu's
|
/// Can we use same groupings for toolbars and menu's
|
||||||
/// How about additional toolbars?
|
/// How about additional toolbars?
|
||||||
///
|
///
|
||||||
class PglPage: public QWidget{
|
class PlgPage: public QWidget{
|
||||||
public:
|
public:
|
||||||
using QWidget::QWidget;
|
using QWidget::QWidget;
|
||||||
|
|
||||||
|
/// Returns the toolbar buttons for this page
|
||||||
|
virtual std::vector<QAction*> getToolbarActions();
|
||||||
|
virtual bool canClose();
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // PGLPAGE_H
|
#endif // PGLPAGE_H
|
||||||
|
|
@ -22,7 +22,7 @@
|
||||||
#include "GlobalIoService.h"
|
#include "GlobalIoService.h"
|
||||||
|
|
||||||
QueryTab::QueryTab(MainWindow *win, QWidget *parent) :
|
QueryTab::QueryTab(MainWindow *win, QWidget *parent) :
|
||||||
PglPage(parent),
|
PlgPage(parent),
|
||||||
ui(new Ui::QueryTab),
|
ui(new Ui::QueryTab),
|
||||||
m_win(win),
|
m_win(win),
|
||||||
m_dbConnection(*getGlobalAsioIoService())
|
m_dbConnection(*getGlobalAsioIoService())
|
||||||
|
|
@ -603,3 +603,13 @@ void QueryTab::focusEditor()
|
||||||
{
|
{
|
||||||
ui->queryEdit->setFocus();
|
ui->queryEdit->setFocus();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::vector<QAction*> QueryTab::getToolbarActions()
|
||||||
|
{
|
||||||
|
if (actions.empty()) {
|
||||||
|
QAction *action = new QAction(tr("Execute"), this);
|
||||||
|
connect(action, &QAction::triggered, this, &QueryTab::execute);
|
||||||
|
actions.push_back(action);
|
||||||
|
}
|
||||||
|
return actions;
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,7 @@
|
||||||
#include "tuplesresultwidget.h"
|
#include "tuplesresultwidget.h"
|
||||||
|
|
||||||
#include <QWidget>
|
#include <QWidget>
|
||||||
#include "PglPage.h"
|
#include "PlgPage.h"
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
||||||
namespace Ui {
|
namespace Ui {
|
||||||
|
|
@ -32,7 +32,7 @@ class OpenDatabase;
|
||||||
class QueryParamListController;
|
class QueryParamListController;
|
||||||
class PgDatabaseCatalog;
|
class PgDatabaseCatalog;
|
||||||
|
|
||||||
class QueryTab : public PglPage {
|
class QueryTab : public PlgPage {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
QueryTab(MainWindow *win, QWidget *parent = nullptr);
|
QueryTab(MainWindow *win, QWidget *parent = nullptr);
|
||||||
|
|
@ -61,6 +61,8 @@ public:
|
||||||
bool isChanged() const { return m_queryTextChanged; }
|
bool isChanged() const { return m_queryTextChanged; }
|
||||||
bool isNew() const { return m_new; }
|
bool isNew() const { return m_new; }
|
||||||
void focusEditor();
|
void focusEditor();
|
||||||
|
|
||||||
|
virtual std::vector<QAction*> getToolbarActions() override;
|
||||||
private:
|
private:
|
||||||
|
|
||||||
using ResultTabContainer = std::vector<TuplesResultWidget*>;
|
using ResultTabContainer = std::vector<TuplesResultWidget*>;
|
||||||
|
|
@ -70,6 +72,7 @@ private:
|
||||||
SqlSyntaxHighlighter* highlighter;
|
SqlSyntaxHighlighter* highlighter;
|
||||||
ConnectionConfig m_config;
|
ConnectionConfig m_config;
|
||||||
StopWatch m_stopwatch;
|
StopWatch m_stopwatch;
|
||||||
|
std::vector<QAction*> actions;
|
||||||
|
|
||||||
QueryParamListController *m_queryParamListController = nullptr;
|
QueryParamListController *m_queryParamListController = nullptr;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -71,9 +71,9 @@ SOURCES += main.cpp\
|
||||||
CrudModel.cpp \
|
CrudModel.cpp \
|
||||||
PgLabItemDelegate.cpp \
|
PgLabItemDelegate.cpp \
|
||||||
Module.cpp \
|
Module.cpp \
|
||||||
PglPage.cpp \
|
|
||||||
EditorGutter.cpp \
|
EditorGutter.cpp \
|
||||||
CodeEditor.cpp
|
CodeEditor.cpp \
|
||||||
|
PlgPage.cpp
|
||||||
|
|
||||||
HEADERS += \
|
HEADERS += \
|
||||||
QueryResultModel.h \
|
QueryResultModel.h \
|
||||||
|
|
@ -116,9 +116,9 @@ HEADERS += \
|
||||||
CrudModel.h \
|
CrudModel.h \
|
||||||
PgLabItemDelegate.h \
|
PgLabItemDelegate.h \
|
||||||
Module.h \
|
Module.h \
|
||||||
PglPage.h \
|
|
||||||
EditorGutter.h \
|
EditorGutter.h \
|
||||||
CodeEditor.h
|
CodeEditor.h \
|
||||||
|
PlgPage.h
|
||||||
|
|
||||||
FORMS += mainwindow.ui \
|
FORMS += mainwindow.ui \
|
||||||
ConnectionManagerWindow.ui \
|
ConnectionManagerWindow.ui \
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue