From edb789ca4a5f668c49f5c3d8eb8fee56e874f37a Mon Sep 17 00:00:00 2001 From: eelke Date: Thu, 15 Aug 2019 16:18:47 +0200 Subject: [PATCH] Removing plugin system is holding back development to much. --- pglab/DatabaseWindow.cpp | 157 +++++++++++++++++-- pglab/DatabaseWindow.h | 39 ++++- pglab/NotificationModel.cpp | 2 + pglab/NotificationService.cpp | 2 +- pglab/NotificationService.h | 11 +- pglab/QueryTool.cpp | 21 +-- pglab/QueryTool.h | 7 +- pglab/QueryToolModule.cpp | 83 ---------- pglab/QueryToolModule.h | 18 --- pglab/pglab.pro | 14 -- pglab/plugin_support/LMainMenu.cpp | 6 - pglab/plugin_support/LMainMenu.h | 56 ------- pglab/plugin_support/LMainWindow.cpp | 217 -------------------------- pglab/plugin_support/LMainWindow.h | 58 ------- pglab/plugin_support/LMenu.cpp | 6 - pglab/plugin_support/LMenu.h | 13 -- pglab/plugin_support/LMenuBar.cpp | 6 - pglab/plugin_support/LMenuBar.h | 11 -- pglab/plugin_support/LMenuItem.cpp | 6 - pglab/plugin_support/LMenuItem.h | 10 -- pglab/plugin_support/LMenuSection.cpp | 6 - pglab/plugin_support/LMenuSection.h | 11 -- 22 files changed, 198 insertions(+), 562 deletions(-) delete mode 100644 pglab/QueryToolModule.cpp delete mode 100644 pglab/QueryToolModule.h delete mode 100644 pglab/plugin_support/LMainMenu.cpp delete mode 100644 pglab/plugin_support/LMainMenu.h delete mode 100644 pglab/plugin_support/LMainWindow.cpp delete mode 100644 pglab/plugin_support/LMainWindow.h delete mode 100644 pglab/plugin_support/LMenu.cpp delete mode 100644 pglab/plugin_support/LMenu.h delete mode 100644 pglab/plugin_support/LMenuBar.cpp delete mode 100644 pglab/plugin_support/LMenuBar.h delete mode 100644 pglab/plugin_support/LMenuItem.cpp delete mode 100644 pglab/plugin_support/LMenuItem.h delete mode 100644 pglab/plugin_support/LMenuSection.cpp delete mode 100644 pglab/plugin_support/LMenuSection.h diff --git a/pglab/DatabaseWindow.cpp b/pglab/DatabaseWindow.cpp index e4b730d..5860711 100644 --- a/pglab/DatabaseWindow.cpp +++ b/pglab/DatabaseWindow.cpp @@ -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 #include +#include +#include #include #include +#include #include -// 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::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(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(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(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() } } - diff --git a/pglab/DatabaseWindow.h b/pglab/DatabaseWindow.h index cd14cf4..c01165a 100644 --- a/pglab/DatabaseWindow.h +++ b/pglab/DatabaseWindow.h @@ -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 +#include #include 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 getDatabase() { return m_database; } - void newCodeGenPage(QString query, std::shared_ptr 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 dbres); private: + QTabWidget *m_tabWidget = nullptr; + QToolBar *m_mainToolBar = nullptr; ConnectionConfig m_config; std::shared_ptr 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 { 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(); diff --git a/pglab/NotificationModel.cpp b/pglab/NotificationModel.cpp index f912d2a..9c0958e 100644 --- a/pglab/NotificationModel.cpp +++ b/pglab/NotificationModel.cpp @@ -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 {}; } diff --git a/pglab/NotificationService.cpp b/pglab/NotificationService.cpp index 975c910..54611f9 100644 --- a/pglab/NotificationService.cpp +++ b/pglab/NotificationService.cpp @@ -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 diff --git a/pglab/NotificationService.h b/pglab/NotificationService.h index 9101f8e..43d2fd4 100644 --- a/pglab/NotificationService.h +++ b/pglab/NotificationService.h @@ -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 instance(); diff --git a/pglab/QueryTool.cpp b/pglab/QueryTool.cpp index 17bc833..e93a89f 100644 --- a/pglab/QueryTool.cpp +++ b/pglab/QueryTool.cpp @@ -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 open_database, QWidget *parent) + : QWidget(parent) , ui(new Ui::QueryTab) , m_dbConnection(*getGlobalAsioIoService()) { ui->setupUi(this); - auto db = context()->getObject(); - 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(); - 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"); diff --git a/pglab/QueryTool.h b/pglab/QueryTool.h index edfee19..7b63eac 100644 --- a/pglab/QueryTool.h +++ b/pglab/QueryTool.h @@ -8,7 +8,6 @@ #include "tuplesresultwidget.h" #include -#include "plugin_support/PluginContentWidget.h" #include 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 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); diff --git a/pglab/QueryToolModule.cpp b/pglab/QueryToolModule.cpp deleted file mode 100644 index 98b826d..0000000 --- a/pglab/QueryToolModule.cpp +++ /dev/null @@ -1,83 +0,0 @@ -#include "QueryToolModule.h" -#include "QueryTool.h" -#include "plugin_support/IPluginContentWidgetContext.h" -#include "plugin_support/PluginRegister.h" - -#include -#include - -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(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(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(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") diff --git a/pglab/QueryToolModule.h b/pglab/QueryToolModule.h deleted file mode 100644 index 01aa591..0000000 --- a/pglab/QueryToolModule.h +++ /dev/null @@ -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 diff --git a/pglab/pglab.pro b/pglab/pglab.pro index 06a247a..8a485cc 100644 --- a/pglab/pglab.pro +++ b/pglab/pglab.pro @@ -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 \ diff --git a/pglab/plugin_support/LMainMenu.cpp b/pglab/plugin_support/LMainMenu.cpp deleted file mode 100644 index 17a40b8..0000000 --- a/pglab/plugin_support/LMainMenu.cpp +++ /dev/null @@ -1,6 +0,0 @@ -#include "LMainMenu.h" - -LMainMenu::LMainMenu() -{ - -} diff --git a/pglab/plugin_support/LMainMenu.h b/pglab/plugin_support/LMainMenu.h deleted file mode 100644 index c99a31c..0000000 --- a/pglab/plugin_support/LMainMenu.h +++ /dev/null @@ -1,56 +0,0 @@ -#ifndef LMAINMENU_H -#define LMAINMENU_H - -#include -#include - -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; - - QString m_caption; - Groups m_groups; -}; - - -class LMainMenu: public LMenu { -public: - LMainMenu(); -}; - -#endif // LMAINMENU_H diff --git a/pglab/plugin_support/LMainWindow.cpp b/pglab/plugin_support/LMainWindow.cpp deleted file mode 100644 index 2a21feb..0000000 --- a/pglab/plugin_support/LMainWindow.cpp +++ /dev/null @@ -1,217 +0,0 @@ -#include "LMainWindow.h" -#include "PluginContentWidget.h" -#include "PluginContentWidgetContextBase.h" -#include "PluginModule.h" -#include "PluginRegister.h" - -#include -#include -#include -#include - -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(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(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); -} diff --git a/pglab/plugin_support/LMainWindow.h b/pglab/plugin_support/LMainWindow.h deleted file mode 100644 index 228d5cc..0000000 --- a/pglab/plugin_support/LMainWindow.h +++ /dev/null @@ -1,58 +0,0 @@ -#ifndef LMAINWINDOW_H -#define LMAINWINDOW_H - -#include - -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 diff --git a/pglab/plugin_support/LMenu.cpp b/pglab/plugin_support/LMenu.cpp deleted file mode 100644 index 24b138a..0000000 --- a/pglab/plugin_support/LMenu.cpp +++ /dev/null @@ -1,6 +0,0 @@ -#include "LMenu.h" - -LMenu::LMenu() -{ - -} diff --git a/pglab/plugin_support/LMenu.h b/pglab/plugin_support/LMenu.h deleted file mode 100644 index 936df23..0000000 --- a/pglab/plugin_support/LMenu.h +++ /dev/null @@ -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 diff --git a/pglab/plugin_support/LMenuBar.cpp b/pglab/plugin_support/LMenuBar.cpp deleted file mode 100644 index f5d9342..0000000 --- a/pglab/plugin_support/LMenuBar.cpp +++ /dev/null @@ -1,6 +0,0 @@ -#include "LMenuBar.h" - -LMenuBar::LMenuBar() -{ - -} diff --git a/pglab/plugin_support/LMenuBar.h b/pglab/plugin_support/LMenuBar.h deleted file mode 100644 index 6699dc9..0000000 --- a/pglab/plugin_support/LMenuBar.h +++ /dev/null @@ -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 diff --git a/pglab/plugin_support/LMenuItem.cpp b/pglab/plugin_support/LMenuItem.cpp deleted file mode 100644 index 601b7e0..0000000 --- a/pglab/plugin_support/LMenuItem.cpp +++ /dev/null @@ -1,6 +0,0 @@ -#include "LMenuItem.h" - -LMenuItem::LMenuItem() -{ - -} diff --git a/pglab/plugin_support/LMenuItem.h b/pglab/plugin_support/LMenuItem.h deleted file mode 100644 index f4f566f..0000000 --- a/pglab/plugin_support/LMenuItem.h +++ /dev/null @@ -1,10 +0,0 @@ -#ifndef LMENUITEM_H -#define LMENUITEM_H - - -class LMenuItem { -public: - LMenuItem(); -}; - -#endif // LMENUITEM_H diff --git a/pglab/plugin_support/LMenuSection.cpp b/pglab/plugin_support/LMenuSection.cpp deleted file mode 100644 index c5de547..0000000 --- a/pglab/plugin_support/LMenuSection.cpp +++ /dev/null @@ -1,6 +0,0 @@ -#include "LMenuSection.h" - -LMenuSection::LMenuSection() -{ - -} diff --git a/pglab/plugin_support/LMenuSection.h b/pglab/plugin_support/LMenuSection.h deleted file mode 100644 index e8906b7..0000000 --- a/pglab/plugin_support/LMenuSection.h +++ /dev/null @@ -1,11 +0,0 @@ -#ifndef LMENUSECTION_H -#define LMENUSECTION_H - -/** Logical grouping within a menu - */ -class LMenuSection { -public: - LMenuSection(); -}; - -#endif // LMENUSECTION_H