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:
eelke 2018-05-14 20:24:41 +02:00
parent c2d725ec6d
commit 3d516e6006
10 changed files with 130 additions and 26 deletions

View file

@ -13,6 +13,7 @@
#include <QMetaMethod>
#include "QueryTab.h"
#include "util.h"
#include "PlgPage.h"
#include "MasterController.h"
#include "CrudTab.h"
#include "WorkManager.h"
@ -40,8 +41,9 @@ QueryTab* MainWindow::newSqlPage()
{
QueryTab *qt = new QueryTab(this);
qt->setConfig(m_config, m_database->catalogue());
ui->tabWidget->addTab(qt, "Tab");
ui->tabWidget->setCurrentWidget(qt);
// ui->tabWidget->addTab(qt, "Tab");
// ui->tabWidget->setCurrentWidget(qt);
addPage(qt, "Tab");
qt->newdoc();
qt->focusEditor();
return qt;
@ -51,8 +53,9 @@ void MainWindow::newCrudPage(const PgClass &table)
{
CrudTab *ct = new CrudTab(this);
ct->setConfig(m_database, table);
ui->tabWidget->addTab(ct, table.name);
ui->tabWidget->setCurrentWidget(ct);
// ui->tabWidget->addTab(ct, table.name);
// ui->tabWidget->setCurrentWidget(ct);
addPage(ct, table.name);
}
QueryTab *MainWindow::GetActiveQueryTab()
@ -262,15 +265,27 @@ void MainWindow::on_actionNew_SQL_triggered()
newSqlPage();
}
void MainWindow::on_tabWidget_tabCloseRequested(int index)
{
QWidget *widget = ui->tabWidget->widget(index);
QueryTab *qt = dynamic_cast<QueryTab*>(widget);
if (qt && qt->canClose()) {
ui->tabWidget->removeTab(index);
PlgPage *plg_page = dynamic_cast<PlgPage*>(widget);
if (plg_page) {
if (plg_page->canClose()) {
removePage(plg_page);
ui->tabWidget->removeTab(index);
}
}
else if (index > 0) {
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);
if (qt && qt->canClose()) {
ui->tabWidget->removeTab(index);
}
else if (index > 0) {
ui->tabWidget->removeTab(index);
}
}
}
@ -319,3 +334,54 @@ void MainWindow::on_actionCopy_as_raw_Cpp_string_triggered()
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;
}