Removing plugin system is holding back development to much.

This commit is contained in:
eelke 2019-08-15 16:18:47 +02:00
parent 048843a1d4
commit edb789ca4a
22 changed files with 198 additions and 562 deletions

View file

@ -1,35 +1,62 @@
#include "DatabaseWindow.h"
#include "plugin_support/IPluginContentWidgetContext.h"
#include "util.h"
#include "OpenDatabase.h"
#include "MasterController.h"
#include "TaskExecutor.h"
#include <QAction>
#include <QApplication>
#include <QFileDialog>
#include <QMenuBar>
#include <QMessageBox>
#include <QMetaMethod>
#include <QStandardPaths>
#include <QTableView>
// Pages that should become modules
#include "EditTableWidget.h"
#include "CodeGenerator.h"
#include "QueryTool.h"
namespace pg = Pgsql;
DatabaseWindow::DatabaseWindow(MasterController *master, QWidget *parent)
: LMainWindow(parent)
: QMainWindow(parent)
, m_masterController(master)
{
connect(&loadWatcher, &QFutureWatcher<LoadCatalog::Result>::finished,
this, &DatabaseWindow::catalogLoaded);
initModuleMenus();
m_tabWidget = new QTabWidget(this);
setCentralWidget(m_tabWidget);
createActions();
initMenus();
QMetaObject::connectSlotsByName(this);
}
DatabaseWindow::~DatabaseWindow() = default;
void DatabaseWindow::addPage(QWidget* page, QString caption)
{
m_tabWidget->addTab(page, caption);
m_tabWidget->setCurrentWidget(page);
}
void DatabaseWindow::setTabCaptionForWidget(QWidget *widget, const QString &caption, const QString &hint)
{
auto index = m_tabWidget->indexOf(widget);
m_tabWidget->setTabText(index, caption);
m_tabWidget->setTabToolTip(index, hint);
}
void DatabaseWindow::setTabIcon(QWidget *widget, const QString &iconname)
{
auto index = m_tabWidget->indexOf(widget);
auto n = ":/icons/16x16/" + iconname;
m_tabWidget->setTabIcon(index, QIcon(n));
}
void DatabaseWindow::newCreateTablePage()
{
auto w = new EditTableWidget(m_database, this);
@ -65,27 +92,130 @@ void DatabaseWindow::setConfig(const ConnectionConfig &config)
}
}
void DatabaseWindow::createActions()
{
{
QIcon icon;
icon.addFile(QString::fromUtf8(":/icons/about.png"), QSize(), QIcon::Normal, QIcon::On);
actionAbout = new QAction(icon, tr("About"), this);
}
{
QIcon icon;
icon.addFile(QString::fromUtf8(":/icons/page_white_delete.png"), QSize(), QIcon::Normal, QIcon::On);
auto action = actionClose = new QAction(icon, tr("Close"), this);
action->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_W));
}
{
QIcon icon;
icon.addFile(QString::fromUtf8(":/icons/new_query_tab.png"), QSize(), QIcon::Normal, QIcon::On);
auto action = actionNewSql = new QAction(icon, tr("New Query"), this);
action->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_N));
}
{
QIcon icon;
icon.addFile(QString::fromUtf8(":/icons/folder.png"), QSize(), QIcon::Normal, QIcon::On);
auto action = actionOpenSql = new QAction(icon, tr("Open Query"), this);
action->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_O));
}
// {
// auto ca = makeContextAction<QueryTool>(tr("Save SQL"), &QueryTool::save);
// ca->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_S));
// ca->setMenuLocation(MenuPath("File/Save"));
// ca->setToolbarLocation(ToolbarLocation("main", "save"));
// // how we tell the system we want this to become a menu button with this as it's default action
// registerContextAction(ca);
// }
// {
// auto ca = makeContextAction<QueryTool>(tr("Save SQL as"), &QueryTool::saveAs);
// ca->setMenuLocation(MenuPath("File/Save"));
// ca->setToolbarLocation(ToolbarLocation("main", "save"));
// // how we tell the system we want this to become a secondary action for the previous button?
// registerContextAction(ca);
// }
// {
// auto ca = makeContextAction<QueryTool>(tr("Save copy of SQL as"), &QueryTool::saveCopyAs);
// ca->setMenuLocation(MenuPath("File/Save"));
// ca->setToolbarLocation(ToolbarLocation("main", "save"));
// // how we tell the system we want this to become a secondary action for the previous button?
// registerContextAction(ca);
// }
}
void DatabaseWindow::initMenus()
{
// TODO construct menubar
auto seperator = new QAction(this);
seperator->setSeparator(true);
auto mb = new QMenuBar(this);
menuFile = mb->addMenu(tr("File"));
menuFile->addActions({
actionNewSql,
actionOpenSql,
seperator,
seperator,
actionClose
});
menuHelp = mb->addMenu(tr("Help"));
menuHelp->addActions({
seperator,
actionAbout
});
setMenuBar(mb);
}
void DatabaseWindow::on_actionClose_triggered()
{
m_tabWidget->tabCloseRequested(m_tabWidget->currentIndex());
}
void DatabaseWindow::on_actionNewSql_triggered()
{
auto *ct = new QueryTool(m_database, this);
addPage(ct, "");
ct->newdoc();
}
void DatabaseWindow::on_actionOpenSql_triggered()
{
QString home_dir = QStandardPaths::locate(QStandardPaths::HomeLocation, "", QStandardPaths::LocateDirectory);
QString file_name = QFileDialog::getOpenFileName(this,
tr("Open sql query"), home_dir, tr("SQL files (*.sql *.txt)"));
if ( ! file_name.isEmpty()) {
auto *ct = new QueryTool(m_database, this);
addPage(ct, "");
if (!ct->load(file_name)) {
// TODO load has failed remove widget or never add it?
}
}
}
void DatabaseWindow::catalogLoaded()
{
try {
m_database = loadWatcher.future().result();
auto ctx = context();
ctx->registerObject(m_database);
for (auto f : { "user", "pg_catalog", "information_schema" })
ctx->moduleAction("pglab.catalog-inspector", "open", {
{ "namespace-filter", f }
});
for (auto f : { "user", "pg_catalog", "information_schema" }) {
// TODO open inspector windows
}
newCreateTablePage();
} catch (const OpenDatabaseException &ex) {
QMessageBox::critical(this, "Error reading database", ex.text());
close();
}
}
void DatabaseWindow::on_actionAbout_triggered()
{
QMessageBox::about(this, "pgLab 0.1", tr(
@ -128,4 +258,3 @@ void DatabaseWindow::on_actionCopy_triggered()
}
}

View file

@ -1,12 +1,12 @@
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include "plugin_support/LMainWindow.h"
#include "ConnectionConfig.h"
#include "OpenDatabase.h"
#include "Pgsql_Connection.h"
#include "ControllableTask.h"
#include <QFutureWatcher>
#include <QMainWindow>
#include <memory>
namespace Pgsql {
@ -18,13 +18,16 @@ class QCloseEvent;
class OpenDatabase;
class PgClass;
class QAction;
class QMenu;
class QTabWidget;
class QToolBar;
/** This is the class for windows that handle tasks for a specific database/catalog
*
*/
class DatabaseWindow : public LMainWindow {
class DatabaseWindow : public QMainWindow {
Q_OBJECT
public:
DatabaseWindow(MasterController *master, QWidget *parent);
@ -34,15 +37,36 @@ public:
std::shared_ptr<OpenDatabase> getDatabase() { return m_database; }
void newCodeGenPage(QString query, std::shared_ptr<const Pgsql::Result> dbres);
void setTabCaptionForWidget(QWidget *widget, const QString &caption, const QString &hint);
void setTabIcon(QWidget *widget, const QString &iconname);
/// Called when a newly created page is added to the QTabWidget
void addPage(QWidget* page, QString caption);
void newCodeGenPage(QString query, std::shared_ptr<const Pgsql::Result> dbres);
private:
QTabWidget *m_tabWidget = nullptr;
QToolBar *m_mainToolBar = nullptr;
ConnectionConfig m_config;
std::shared_ptr<OpenDatabase> m_database;
MasterController *m_masterController;
// Standard menu's
QMenu *m_fileMenu = nullptr;
// Standard actions
QAction *actionAbout = nullptr;
QAction *actionClose = nullptr;
QAction *actionNewSql = nullptr;
QAction *actionOpenSql = nullptr;
QMenu *menuFile = nullptr;
QMenu *menuHelp = nullptr;
class LoadCatalog: public ControllableTask<OpenDatabase::OpenDatabaseSPtr> {
public:
LoadCatalog(ConnectionConfig config)
@ -62,10 +86,17 @@ private:
void newCreateTablePage();
void createActions();
void initMenus();
private slots:
void catalogLoaded();
// void tabWidget_tabCloseRequested(int index);
// void tabWidget_currentChanged(int index);
void on_actionClose_triggered();
void on_actionNewSql_triggered();
void on_actionOpenSql_triggered();
void on_actionAbout_triggered();
void on_actionShow_connection_manager_triggered();
void on_actionCopy_triggered();

View file

@ -18,8 +18,10 @@ int NotificationModel::columnCount(const QModelIndex &) const
QVariant NotificationModel::data(const QModelIndex &index, int role) const
{
return {};
}
QVariant NotificationModel::headerData(int section, Qt::Orientation orientation, int role) const
{
return {};
}

View file

@ -44,7 +44,7 @@ void NotificationService::addError(const QString &msg, const QString &detail)
void NotificationService::add(NotificationSeverity severity, const QString &msg, const QString &detail)
{
m_notifications.push_back({ severity, msg, detail });
// m_notifications.push_back({ severity, msg, detail });
}
int NotificationService::count() const

View file

@ -14,9 +14,9 @@ enum NotificationSeverity {
Critical ///< Don't think you should ever need this in a correct program....
};
class Notification: public QObject {
Q_OBJECT
class Notification {
public:
Notification() = default;
Notification(int64_t id, NotificationSeverity severity, const QString &msg, const QString &detail = {});
int64_t id() const { return m_id; }
@ -25,14 +25,15 @@ public:
QString detailMessage() const { return m_detailMessage; }
private:
int64_t m_id;
NotificationSeverity m_severity;
int64_t m_id = 0;
NotificationSeverity m_severity = NotificationSeverity::Informational;
QString m_shortMessage;
QString m_detailMessage;
};
class NotificationService {
class NotificationService: public QObject {
Q_OBJECT
public:
static std::shared_ptr<NotificationService> instance();

View file

@ -22,16 +22,15 @@
#include "plugin_support/IPluginContentWidgetContext.h"
QueryTool::QueryTool(IPluginContentWidgetContext *context_, PluginModule *module, QWidget *parent)
: PluginContentWidget(context_, module, parent)
QueryTool::QueryTool(std::shared_ptr<OpenDatabase> open_database, QWidget *parent)
: QWidget(parent)
, ui(new Ui::QueryTab)
, m_dbConnection(*getGlobalAsioIoService())
{
ui->setupUi(this);
auto db = context()->getObject<OpenDatabase>();
m_config = db->config();
m_catalog = db->catalog();
m_config = open_database->config();
m_catalog = open_database->catalog();
connect(&m_dbConnection, &ASyncDBConnection::onStateChanged, this, &QueryTool::connectionStateChanged);
connect(&m_dbConnection, &ASyncDBConnection::onNotice, this, &QueryTool::receiveNotice);
@ -39,11 +38,7 @@ QueryTool::QueryTool(IPluginContentWidgetContext *context_, PluginModule *module
ui->queryEdit->setFont(UserConfiguration::instance()->codeFont());
highlighter = new SqlSyntaxHighlighter(ui->queryEdit->document());
auto open_database = context()->getObject<OpenDatabase>();
if (open_database) {
auto cat = open_database->catalog();
highlighter->setTypes(*cat->types());
}
highlighter->setTypes(*m_catalog->types());
initActions();
@ -232,7 +227,7 @@ void QueryTool::setFileName(const QString &filename)
m_fileName = filename;
QFileInfo fileInfo(filename);
QString fn(fileInfo.fileName());
context()->setCaption(this, fn, m_fileName);
// context()->setCaption(this, fn, m_fileName);
}
bool QueryTool::continueWithoutSavingWarning()
@ -307,7 +302,7 @@ void QueryTool::connectionStateChanged(ASyncDBConnection::State state)
case ASyncDBConnection::State::Terminating:
break;
}
context()->setIcon(this, iconname);
// context()->setIcon(this, iconname);
}
@ -396,7 +391,7 @@ void QueryTool::explain_ready(ExplainRoot::SPtr explain)
ui->explainTreeView->setColumnWidth(6, 600);
ui->tabWidget->setCurrentWidget(ui->explainTab);
context()->showStatusMessage(tr("Explain ready."));
// context()->showStatusMessage(tr("Explain ready."));
}
else {
addLog("Explain no result");

View file

@ -8,7 +8,6 @@
#include "tuplesresultwidget.h"
#include <QWidget>
#include "plugin_support/PluginContentWidget.h"
#include <memory>
namespace Ui {
@ -31,10 +30,10 @@ class OpenDatabase;
class QueryParamListController;
class PgDatabaseCatalog;
class QueryTool : public PluginContentWidget {
class QueryTool : public QWidget {
Q_OBJECT
public:
QueryTool(IPluginContentWidgetContext *context, PluginModule *module, QWidget *parent = nullptr);
QueryTool(std::shared_ptr<OpenDatabase> open_database, QWidget *parent = nullptr);
~QueryTool() override;
void newdoc();
@ -42,7 +41,7 @@ public:
void explain(bool analyze);
bool canClose() override;
bool canClose();
void generateCode();
void exportDataToFilename(const QString &filename);

View file

@ -1,83 +0,0 @@
#include "QueryToolModule.h"
#include "QueryTool.h"
#include "plugin_support/IPluginContentWidgetContext.h"
#include "plugin_support/PluginRegister.h"
#include <QStandardPaths>
#include <QFileDialog>
void QueryToolModule::init()
{
std::string slot_name = SLOT(QueryTool::execute());
{
StaticAction ma("New SQL", [this] (IPluginContentWidgetContext* context)
{ staticAction_new(context); });
ma.setMenuLocation(MenuPath("File/New"));
ma.setToolbarLocation(ToolbarLocation("main", "new"));
ma.setIcon(QIcon(":/icons/new_query_tab.png"));
ma.setShortcut(QKeySequence(Qt::CTRL + Qt::Key_N));
registerStaticAction(ma);
}
{
StaticAction ma("Open SQL", [this] (IPluginContentWidgetContext* context)
{ staticAction_open(context); });
ma.setMenuLocation(MenuPath("File/Open"));
ma.setToolbarLocation(ToolbarLocation("main", "open"));
ma.setIcon(QIcon(":/icons/folder.png"));
registerStaticAction(ma);
}
{
auto ca = makeContextAction<QueryTool>(tr("Save SQL"), &QueryTool::save);
ca->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_S));
ca->setMenuLocation(MenuPath("File/Save"));
ca->setToolbarLocation(ToolbarLocation("main", "save"));
// how we tell the system we want this to become a menu button with this as it's default action
registerContextAction(ca);
}
{
auto ca = makeContextAction<QueryTool>(tr("Save SQL as"), &QueryTool::saveAs);
ca->setMenuLocation(MenuPath("File/Save"));
ca->setToolbarLocation(ToolbarLocation("main", "save"));
// how we tell the system we want this to become a secondary action for the previous button?
registerContextAction(ca);
}
{
auto ca = makeContextAction<QueryTool>(tr("Save copy of SQL as"), &QueryTool::saveCopyAs);
ca->setMenuLocation(MenuPath("File/Save"));
ca->setToolbarLocation(ToolbarLocation("main", "save"));
// how we tell the system we want this to become a secondary action for the previous button?
registerContextAction(ca);
}
}
void QueryToolModule::staticAction_new(IPluginContentWidgetContext* context)
{
auto *ct = new QueryTool(context, this);
// Should we let constructor of PluginContentWidget do this?
// Saves a line but what if we don't want it.
context->addContentWidget(ct);
// should content widget now to which module it belongs?
// That way the context would not need to keep track of this.
ct->newdoc();
}
void QueryToolModule::staticAction_open(IPluginContentWidgetContext* context)
{
QString home_dir = QStandardPaths::locate(QStandardPaths::HomeLocation, "", QStandardPaths::LocateDirectory);
QString file_name = QFileDialog::getOpenFileName(context->container(),
tr("Open sql query"), home_dir, tr("SQL files (*.sql *.txt)"));
if ( ! file_name.isEmpty()) {
auto *ct = new QueryTool(context, this);
context->addContentWidget(ct);
if (!ct->load(file_name)) {
// TODO load has failed remove widget or never add it?
}
}
}
REGISTER_PLUGIN_MODULE_CAT(QueryToolModule, "Query tool", "pglab.querytool", "database")

View file

@ -1,18 +0,0 @@
#ifndef QUERYTOOLMODULE_H
#define QUERYTOOLMODULE_H
#include "plugin_support/PluginModule.h"
class QueryToolModule: public PluginModule {
Q_OBJECT
public:
using PluginModule::PluginModule;
void init() override;
void staticAction_new(IPluginContentWidgetContext* context);
void staticAction_open(IPluginContentWidgetContext* context);
private slots:
};
#endif // QUERYTOOLMODULE_H

View file

@ -30,10 +30,6 @@ SOURCES += main.cpp\
ConnectionManagerWindow.cpp \
ConnectionListModel.cpp \
BackupRestore.cpp \
plugin_support/LMenu.cpp \
plugin_support/LMenuBar.cpp \
plugin_support/LMenuItem.cpp \
plugin_support/LMenuSection.cpp \
stopwatch.cpp \
TuplesResultWidget.cpp \
BackupDialog.cpp \
@ -86,12 +82,9 @@ PropertyProxyModel.cpp \
plugin_support/PluginRegister.cpp \
plugin_support/PluginContentWidget.cpp \
plugin_support/PluginContentWidgetContextBase.cpp \
plugin_support/LMainWindow.cpp \
QueryTool.cpp \
QueryToolModule.cpp \
CatalogInspector.cpp \
plugin_support/StaticAction.cpp \
plugin_support/LMainMenu.cpp \
widgets/CatalogIndexPage.cpp \
widgets/CatalogPageBase.cpp \
widgets/CatalogConstraintPage.cpp \
@ -108,10 +101,6 @@ HEADERS += \
CreateDatabaseDialog.h \
ConnectionManagerWindow.h \
ConnectionListModel.h \
plugin_support/LMenu.h \
plugin_support/LMenuBar.h \
plugin_support/LMenuItem.h \
plugin_support/LMenuSection.h \
stopwatch.h \
TuplesResultWidget.h \
BackupDialog.h \
@ -168,12 +157,9 @@ CustomDataRole.h \
plugin_support/ModuleActionParameters.h \
plugin_support/IPluginContentWidgetContext.h \
plugin_support/PluginContentWidgetContextBase.h \
plugin_support/LMainWindow.h \
QueryTool.h \
QueryToolModule.h \
CatalogInspector.h \
plugin_support/StaticAction.h \
plugin_support/LMainMenu.h \
widgets/CatalogIndexPage.h \
widgets/CatalogPageBase.h \
widgets/CatalogConstraintPage.h \

View file

@ -1,6 +0,0 @@
#include "LMainMenu.h"
LMainMenu::LMainMenu()
{
}

View file

@ -1,56 +0,0 @@
#ifndef LMAINMENU_H
#define LMAINMENU_H
#include <QString>
#include <vector>
class QAction;
class LMenuGroupItem {
public:
LMenuGroupItem(QAction *action, int position)
: m_menuAction(action)
, m_position(position)
{}
int position() const { return m_position; }
private:
QAction *m_menuAction;
int m_position;
};
// Menu's are divided into logical groups,
// these groups form only a single level they are NOT submenu's
class LMenuGroup {
public:
explicit LMenuGroup(QString group_id);
QString groupId() const;
private:
QString m_groupId;
};
class LMenu {
public:
QString menuId() const;
void addGroup(const LMenuGroup &group)
{
m_groups.push_back(group);
}
private:
using Groups = std::vector<LMenuGroup>;
QString m_caption;
Groups m_groups;
};
class LMainMenu: public LMenu {
public:
LMainMenu();
};
#endif // LMAINMENU_H

View file

@ -1,217 +0,0 @@
#include "LMainWindow.h"
#include "PluginContentWidget.h"
#include "PluginContentWidgetContextBase.h"
#include "PluginModule.h"
#include "PluginRegister.h"
#include <QDebug>
#include <QMenuBar>
#include <QStatusBar>
#include <QToolBar>
namespace LMainWindow_details {
class LMainWindowContentContext: public PluginContentWidgetContextBase {
public:
explicit LMainWindowContentContext(LMainWindow *window)
: m_window(window)
{}
void setCaption(PluginContentWidget *content, const QString &caption, const QString &hint = {}) override
{
m_window->setTabCaptionForWidget(content, caption, hint);
}
void setIcon(PluginContentWidget *content, const QString &iconname) override
{
m_window->setTabIcon(content, iconname);
}
void showStatusMessage(const QString &msg) override
{
m_window->statusBar()->showMessage(msg);
}
void addContentWidget(PluginContentWidget *widget) override
{
PluginContentWidgetContextBase::addContentWidget(widget);
m_window->addPage(widget, "");
}
QWidget* container() override
{
return m_window;
}
private:
LMainWindow *m_window;
};
}
using namespace LMainWindow_details;
LMainWindow::LMainWindow(QWidget *parent)
: QMainWindow(parent)
{
m_context = new LMainWindowContentContext(this);
m_tabWidget = new QTabWidget(this);
m_tabWidget->setObjectName(QString::fromUtf8("tabWidget"));
m_tabWidget->setDocumentMode(true);
setCentralWidget(m_tabWidget);
// menu
auto menuBar = new QMenuBar(this);
setMenuBar(menuBar);
// tooolbar
m_mainToolBar = new QToolBar(this);
addToolBar(Qt::TopToolBarArea, m_mainToolBar);
// statusbar
auto statusBar = new QStatusBar(this);
setStatusBar(statusBar);
m_fileMenu = new QMenu(tr("File"), this);
createActions();
m_mainToolBar->addAction(m_closeAction);
connect(m_tabWidget, &QTabWidget::tabCloseRequested, this, &LMainWindow::tabWidget_tabCloseRequested);
connect(m_tabWidget, &QTabWidget::currentChanged, this, &LMainWindow::tabWidget_currentChanged);
}
LMainWindow::~LMainWindow()
{
delete m_context;
}
void LMainWindow::initModuleMenus()
{
menuBar()->addMenu(m_fileMenu);
addModuleMenuActions();
}
void LMainWindow::addModuleMenuActions()
{
auto reg = PluginRegister::getInstance();
auto mods = reg->modules();
for (auto && mod : mods) {
auto items = mod.second->staticActions();
for (auto && item : items) {
addMenuAction(item);
}
}
}
void LMainWindow::createActions()
{
{
auto action = m_closeAction = new QAction(this);
QIcon icon;
icon.addFile(QString::fromUtf8(":/icons/page_white_delete.png"), QSize(), QIcon::Normal, QIcon::On);
action->setIcon(icon);
connect(m_closeAction, &QAction::triggered, this, &LMainWindow::actionClose_triggered);
}
}
void LMainWindow::addMenuAction(const StaticAction &ma)
{
qDebug() << "add action " << ma.text();
//auto ac =
m_fileMenu->addAction(ma.icon(), ma.text(),
[ma, this] ()
{
ma.perform(m_context);
},
ma.shortcut());
// auto ac = new QAction(this);
// ac->
}
void LMainWindow::actionClose_triggered()
{
m_tabWidget->tabCloseRequested(m_tabWidget->currentIndex());
}
void LMainWindow::addPage(PluginContentWidget* page, QString caption)
{
m_tabWidget->addTab(page, caption);
m_tabWidget->setCurrentWidget(page);
}
void LMainWindow::setTabCaptionForWidget(QWidget *widget, const QString &caption, const QString &hint)
{
auto index = m_tabWidget->indexOf(widget);
m_tabWidget->setTabText(index, caption);
m_tabWidget->setTabToolTip(index, hint);
}
void LMainWindow::setTabIcon(QWidget *widget, const QString &iconname)
{
auto index = m_tabWidget->indexOf(widget);
auto n = ":/icons/16x16/" + iconname;
m_tabWidget->setTabIcon(index, QIcon(n));
}
IPluginContentWidgetContext* LMainWindow::context()
{
return m_context;
}
void LMainWindow::tabWidget_tabCloseRequested(int index)
{
QWidget *widget = m_tabWidget->widget(index);
PluginContentWidget *plg_page = dynamic_cast<PluginContentWidget*>(widget);
if (plg_page) {
if (plg_page->canClose()) {
m_tabWidget->removeTab(index);
m_context->removeContentWidget(plg_page);
delete plg_page;
}
}
else {
// old behaviour shouldn't be needed any more when all pages have been migrated
// to PlgPage
m_tabWidget->removeTab(index);
delete widget;
}
}
void LMainWindow::tabWidget_currentChanged(int index)
{
// remove buttons of old page
if (m_previousPage) {
removeModuleWidgetActionsForPage(m_previousPage);
}
// add buttons of new page
PluginContentWidget * page = nullptr;
if (index >= 0) {
QWidget *widget = m_tabWidget->widget(index);
page = dynamic_cast<PluginContentWidget*>(widget);
if (page) {
addModuleWidgetActionsForPage(page);
}
}
m_previousPage = page;
}
void LMainWindow::addModuleWidgetActionsForPage(PluginContentWidget *page)
{
m_context->addWidgetActionsToToolbar(page, m_mainToolBar);
m_context->addContextActionsToMenu(page, menuBar());
}
void LMainWindow::removeModuleWidgetActionsForPage(PluginContentWidget *page)
{
m_context->removeContextActionsFromMenu(page, menuBar());
m_context->removeWidgetActionsFromToolbar(page, m_mainToolBar);
}

View file

@ -1,58 +0,0 @@
#ifndef LMAINWINDOW_H
#define LMAINWINDOW_H
#include <QMainWindow>
class IPluginContentWidgetContext;
class StaticAction;
class PluginContentWidget;
namespace LMainWindow_details {
class LMainWindowContentContext;
}
class LMainWindow : public QMainWindow {
Q_OBJECT
public:
LMainWindow(QWidget *parent = nullptr);
~LMainWindow();
void initModuleMenus();
void setTabCaptionForWidget(QWidget *widget, const QString &caption, const QString &hint);
void setTabIcon(QWidget *widget, const QString &iconname);
/// Called when a newly created page is added to the QTabWidget
void addPage(PluginContentWidget* page, QString caption);
IPluginContentWidgetContext* context();
protected:
QTabWidget *m_tabWidget = nullptr;
QToolBar *m_mainToolBar = nullptr;
// Standard menu's
QMenu *m_fileMenu = nullptr;
// Standard actions
QAction *m_closeAction = nullptr;
void addModuleMenuActions();
void addModuleWidgetActionsForPage(PluginContentWidget *page);
void removeModuleWidgetActionsForPage(PluginContentWidget *page);
private:
LMainWindow_details::LMainWindowContentContext *m_context;
PluginContentWidget *m_previousPage = nullptr; ///< tracks which pages buttons were previously being displayed
void createActions();
void addMenuAction(const StaticAction &ma);
private slots:
void actionClose_triggered();
void tabWidget_tabCloseRequested(int index);
void tabWidget_currentChanged(int index);
};
#endif // LMAINWINDOW_H

View file

@ -1,6 +0,0 @@
#include "LMenu.h"
LMenu::LMenu()
{
}

View file

@ -1,13 +0,0 @@
#ifndef LMENU_H
#define LMENU_H
/** Represents a menu wraps QMenu to give it more dynamic functionality
*
*/
class LMenu
{
public:
LMenu();
};
#endif // LMENU_H

View file

@ -1,6 +0,0 @@
#include "LMenuBar.h"
LMenuBar::LMenuBar()
{
}

View file

@ -1,11 +0,0 @@
#ifndef LMENUBAR_H
#define LMENUBAR_H
/** Represents the main menubar. Linked to a QMenuBar
*/
class LMenuBar {
public:
LMenuBar();
};
#endif // LMENUBAR_H

View file

@ -1,6 +0,0 @@
#include "LMenuItem.h"
LMenuItem::LMenuItem()
{
}

View file

@ -1,10 +0,0 @@
#ifndef LMENUITEM_H
#define LMENUITEM_H
class LMenuItem {
public:
LMenuItem();
};
#endif // LMENUITEM_H

View file

@ -1,6 +0,0 @@
#include "LMenuSection.h"
LMenuSection::LMenuSection()
{
}

View file

@ -1,11 +0,0 @@
#ifndef LMENUSECTION_H
#define LMENUSECTION_H
/** Logical grouping within a menu
*/
class LMenuSection {
public:
LMenuSection();
};
#endif // LMENUSECTION_H