Basic concept of MenuAction is working
Module can register action Window adds this action to its menu Clicking the menu item for the action has the expected result But menu structure still needs work (everything is now put into one dropdown menu)
This commit is contained in:
parent
f130c426a1
commit
dc8a052544
12 changed files with 220 additions and 28 deletions
|
|
@ -65,17 +65,64 @@ namespace DatabaseWindow_details {
|
||||||
using namespace DatabaseWindow_details;
|
using namespace DatabaseWindow_details;
|
||||||
|
|
||||||
|
|
||||||
DatabaseWindow::DatabaseWindow(MasterController *master, QWidget *parent)
|
LMainWindow::LMainWindow(QWidget *parent)
|
||||||
: QMainWindow(parent)
|
: QMainWindow(parent)
|
||||||
|
{
|
||||||
|
m_fileMenu = new QMenu("File T", this);
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
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->menuActions();
|
||||||
|
for (auto && item : items) {
|
||||||
|
addMenuAction(item);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void LMainWindow::addMenuAction(const MenuAction &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->
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
DatabaseWindow::DatabaseWindow(MasterController *master, QWidget *parent)
|
||||||
|
: LMainWindow(parent)
|
||||||
, ui(new Ui::DatabaseWindow)
|
, ui(new Ui::DatabaseWindow)
|
||||||
, m_context(new DatabaseWindowContentContext(this))
|
|
||||||
, m_masterController(master)
|
, m_masterController(master)
|
||||||
{
|
{
|
||||||
ui->setupUi(this);
|
ui->setupUi(this);
|
||||||
ui->tabWidget->setDocumentMode(true);
|
ui->tabWidget->setDocumentMode(true);
|
||||||
|
|
||||||
|
m_context = new DatabaseWindowContentContext(this);
|
||||||
|
|
||||||
connect(&loadWatcher, &QFutureWatcher<LoadCatalog::Result>::finished,
|
connect(&loadWatcher, &QFutureWatcher<LoadCatalog::Result>::finished,
|
||||||
this, &DatabaseWindow::catalogLoaded);
|
this, &DatabaseWindow::catalogLoaded);
|
||||||
|
|
||||||
|
initModuleMenus();
|
||||||
}
|
}
|
||||||
|
|
||||||
DatabaseWindow::~DatabaseWindow()
|
DatabaseWindow::~DatabaseWindow()
|
||||||
|
|
|
||||||
|
|
@ -30,6 +30,7 @@ namespace Pgsql {
|
||||||
class Connection;
|
class Connection;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class MenuAction;
|
||||||
class QueryTab;
|
class QueryTab;
|
||||||
class MasterController;
|
class MasterController;
|
||||||
class QCloseEvent;
|
class QCloseEvent;
|
||||||
|
|
@ -41,13 +42,33 @@ namespace DatabaseWindow_details {
|
||||||
class DatabaseWindowContentContext;
|
class DatabaseWindowContentContext;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class LMainWindow : public QMainWindow {
|
||||||
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
|
||||||
|
LMainWindow(QWidget *parent = nullptr);
|
||||||
|
|
||||||
|
void initModuleMenus();
|
||||||
|
protected:
|
||||||
|
|
||||||
|
DatabaseWindow_details::DatabaseWindowContentContext *m_context;
|
||||||
|
|
||||||
|
void addModuleMenuActions();
|
||||||
|
|
||||||
|
private:
|
||||||
|
QMenu *m_fileMenu = nullptr;
|
||||||
|
|
||||||
|
void addMenuAction(const MenuAction &ma);
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
/** This is the class for windows that handle tasks for a specific database/catalog
|
/** This is the class for windows that handle tasks for a specific database/catalog
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
class DatabaseWindow : public QMainWindow {
|
class DatabaseWindow : public LMainWindow {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
explicit DatabaseWindow(MasterController *master, QWidget *parent);
|
DatabaseWindow(MasterController *master, QWidget *parent);
|
||||||
~DatabaseWindow();
|
~DatabaseWindow();
|
||||||
|
|
||||||
void setConfig(const ConnectionConfig &config);
|
void setConfig(const ConnectionConfig &config);
|
||||||
|
|
@ -64,7 +85,6 @@ public:
|
||||||
private:
|
private:
|
||||||
|
|
||||||
Ui::DatabaseWindow *ui;
|
Ui::DatabaseWindow *ui;
|
||||||
DatabaseWindow_details::DatabaseWindowContentContext *m_context;
|
|
||||||
|
|
||||||
ConnectionConfig m_config;
|
ConnectionConfig m_config;
|
||||||
std::shared_ptr<OpenDatabase> m_database;
|
std::shared_ptr<OpenDatabase> m_database;
|
||||||
|
|
|
||||||
|
|
@ -674,14 +674,18 @@ std::vector<QAction*> QueryTab::getToolbarActions()
|
||||||
|
|
||||||
void QueryToolModule::init()
|
void QueryToolModule::init()
|
||||||
{
|
{
|
||||||
auto action_new = new QAction(QIcon(":/icons/new_query_tab.png"), tr("New"), this);
|
MenuAction ma_new("New", [this] (IPluginContentWidgetContext* context)
|
||||||
connect(action_new, &QAction::triggered, this, &QueryToolModule::new_triggered);
|
{ menuAction_new(context); });
|
||||||
|
ma_new.setMenuLocation(MenuPath("File/New"));
|
||||||
registerAction(action_new, MenuLocation({"File/New"}), ToolbarLocation("File", ""));
|
ma_new.setIcon(QIcon(":/icons/new_query_tab.png"));
|
||||||
|
registerMenuAction(ma_new);
|
||||||
}
|
}
|
||||||
|
|
||||||
void QueryToolModule::new_triggered()
|
void QueryToolModule::menuAction_new(IPluginContentWidgetContext* context)
|
||||||
{
|
{
|
||||||
|
auto *ct = new QueryTab(context, nullptr);
|
||||||
|
context->addContentWidget(ct);
|
||||||
|
ct->newdoc();
|
||||||
}
|
}
|
||||||
|
|
||||||
REGISTER_PLUGIN_MODULE(QueryToolModule, "Query tool", "pglab.querytool")
|
REGISTER_PLUGIN_MODULE(QueryToolModule, "Query tool", "pglab.querytool")
|
||||||
|
|
|
||||||
|
|
@ -117,9 +117,9 @@ class QueryToolModule: public PluginModule {
|
||||||
public:
|
public:
|
||||||
using PluginModule::PluginModule;
|
using PluginModule::PluginModule;
|
||||||
|
|
||||||
void init();
|
void init() override;
|
||||||
|
void menuAction_new(IPluginContentWidgetContext* context);
|
||||||
private slots:
|
private slots:
|
||||||
void new_triggered();
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // QUERYTAB_H
|
#endif // QUERYTAB_H
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,7 @@
|
||||||
#endif
|
#endif
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include "GlobalIoService.h"
|
#include "GlobalIoService.h"
|
||||||
|
#include "plugin_support/PluginRegister.h"
|
||||||
|
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
|
|
@ -29,6 +30,8 @@ int main(int argc, char *argv[])
|
||||||
QCoreApplication::setOrganizationDomain("eelkeklein.nl");
|
QCoreApplication::setOrganizationDomain("eelkeklein.nl");
|
||||||
QCoreApplication::setApplicationName("pglab");
|
QCoreApplication::setApplicationName("pglab");
|
||||||
|
|
||||||
|
PluginRegister::getInstance()->initModules();
|
||||||
|
|
||||||
std::thread asio_service_thread;
|
std::thread asio_service_thread;
|
||||||
int result = -1;
|
int result = -1;
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -87,7 +87,8 @@ PropertyProxyModel.cpp \
|
||||||
plugin_support/ToolbarLocation.cpp \
|
plugin_support/ToolbarLocation.cpp \
|
||||||
plugin_support/PluginRegister.cpp \
|
plugin_support/PluginRegister.cpp \
|
||||||
plugin_support/PluginContentWidget.cpp \
|
plugin_support/PluginContentWidget.cpp \
|
||||||
plugin_support/PluginContentWidgetContextBase.cpp
|
plugin_support/PluginContentWidgetContextBase.cpp \
|
||||||
|
plugin_support/MenuAction.cpp
|
||||||
|
|
||||||
HEADERS += \
|
HEADERS += \
|
||||||
QueryResultModel.h \
|
QueryResultModel.h \
|
||||||
|
|
@ -154,7 +155,8 @@ CustomDataRole.h \
|
||||||
plugin_support/PluginContentWidget.h \
|
plugin_support/PluginContentWidget.h \
|
||||||
plugin_support/ModuleActionParameters.h \
|
plugin_support/ModuleActionParameters.h \
|
||||||
plugin_support/IPluginContentWidgetContext.h \
|
plugin_support/IPluginContentWidgetContext.h \
|
||||||
plugin_support/PluginContentWidgetContextBase.h
|
plugin_support/PluginContentWidgetContextBase.h \
|
||||||
|
plugin_support/MenuAction.h
|
||||||
|
|
||||||
FORMS += \
|
FORMS += \
|
||||||
ConnectionManagerWindow.ui \
|
ConnectionManagerWindow.ui \
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,62 @@
|
||||||
#include "MenuAction.h"
|
#include "MenuAction.h"
|
||||||
|
|
||||||
MenuAction::MenuAction()
|
MenuAction::MenuAction(QString text, Func func)
|
||||||
|
: m_text(std::move(text))
|
||||||
|
, m_func(std::move(func))
|
||||||
|
{}
|
||||||
|
|
||||||
|
const QIcon& MenuAction::icon() const
|
||||||
{
|
{
|
||||||
|
return m_icon;
|
||||||
|
}
|
||||||
|
|
||||||
|
const MenuLocation& MenuAction::menuLocation() const
|
||||||
|
{
|
||||||
|
return m_menuLocation;
|
||||||
|
}
|
||||||
|
|
||||||
|
void MenuAction::setIcon(QIcon icon)
|
||||||
|
{
|
||||||
|
m_icon = std::move(icon);
|
||||||
|
}
|
||||||
|
|
||||||
|
void MenuAction::setMenuLocation(MenuLocation menu_location)
|
||||||
|
{
|
||||||
|
m_menuLocation = std::move(menu_location);
|
||||||
|
}
|
||||||
|
|
||||||
|
void MenuAction::setShortCut(QKeySequence shortcut)
|
||||||
|
{
|
||||||
|
m_shortCut = std::move(shortcut);
|
||||||
|
}
|
||||||
|
|
||||||
|
void MenuAction::setText(QString text)
|
||||||
|
{
|
||||||
|
m_text = std::move(text);
|
||||||
|
}
|
||||||
|
|
||||||
|
void MenuAction::setToolTip(QString tooltip)
|
||||||
|
{
|
||||||
|
m_toolTip = std::move(tooltip);
|
||||||
|
}
|
||||||
|
|
||||||
|
const QKeySequence& MenuAction::shortCut() const
|
||||||
|
{
|
||||||
|
return m_shortCut;
|
||||||
|
}
|
||||||
|
|
||||||
|
const QString& MenuAction::text() const
|
||||||
|
{
|
||||||
|
return m_text;
|
||||||
|
}
|
||||||
|
|
||||||
|
const QString& MenuAction::toolTip() const
|
||||||
|
{
|
||||||
|
return m_toolTip;
|
||||||
|
}
|
||||||
|
|
||||||
|
void MenuAction::perform(IPluginContentWidgetContext *context) const
|
||||||
|
{
|
||||||
|
if (m_func)
|
||||||
|
m_func(context);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,11 +1,49 @@
|
||||||
#ifndef MENUACTION_H
|
#ifndef MENUACTION_H
|
||||||
#define MENUACTION_H
|
#define MENUACTION_H
|
||||||
|
|
||||||
|
#include "MenuLocation.h"
|
||||||
|
#include "ToolbarLocation.h"
|
||||||
|
|
||||||
class MenuAction
|
#include <QIcon>
|
||||||
{
|
#include <QKeySequence>
|
||||||
|
#include <QString>
|
||||||
|
#include <functional>
|
||||||
|
|
||||||
|
class QAction;
|
||||||
|
class IPluginContentWidgetContext;
|
||||||
|
|
||||||
|
/** An action for in a menu or toolbar that does not pertain to a specific
|
||||||
|
* widget. It often will create a widget for instance a New or Open action.
|
||||||
|
* It does need a context.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
class MenuAction {
|
||||||
public:
|
public:
|
||||||
MenuAction();
|
using Func = std::function<void(IPluginContentWidgetContext *context)>;
|
||||||
|
|
||||||
|
MenuAction(QString text, Func func);
|
||||||
|
|
||||||
|
const QIcon& icon() const;
|
||||||
|
const MenuLocation& menuLocation() const;
|
||||||
|
void setIcon(QIcon icon);
|
||||||
|
void setMenuLocation(MenuLocation menu_location);
|
||||||
|
void setShortCut(QKeySequence shortcut);
|
||||||
|
void setText(QString text);
|
||||||
|
void setToolTip(QString tooltip);
|
||||||
|
const QKeySequence& shortCut() const;
|
||||||
|
const QString& text() const;
|
||||||
|
const QString& toolTip() const;
|
||||||
|
|
||||||
|
void perform(IPluginContentWidgetContext *context) const;
|
||||||
|
private:
|
||||||
|
QString m_text;
|
||||||
|
QString m_toolTip;
|
||||||
|
QIcon m_icon;
|
||||||
|
QKeySequence m_shortCut;
|
||||||
|
MenuLocation m_menuLocation;
|
||||||
|
|
||||||
|
Func m_func;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
#endif // MENUACTION_H
|
#endif // MENUACTION_H
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
#include "plugin_support/PluginModule.h"
|
#include "plugin_support/PluginModule.h"
|
||||||
|
#include <QDebug>
|
||||||
|
|
||||||
PluginModule::PluginModule(QString name, QString ident)
|
PluginModule::PluginModule(QString name, QString ident)
|
||||||
: m_name(std::move(name))
|
: m_name(std::move(name))
|
||||||
|
|
@ -11,9 +12,15 @@ void PluginModule::setDisplayCategory(QString category)
|
||||||
m_displayCategory = std::move(category);
|
m_displayCategory = std::move(category);
|
||||||
}
|
}
|
||||||
|
|
||||||
void PluginModule::registerAction(QAction *action, MenuLocation menu_location, ToolbarLocation toolbar_location)
|
void PluginModule::registerMenuAction(MenuAction action)
|
||||||
{
|
{
|
||||||
|
qDebug() << "registerMenuAction " << action.text();
|
||||||
|
m_menuActions.emplace_back(std::move(action));
|
||||||
|
}
|
||||||
|
|
||||||
|
const PluginModule::MenuActionList& PluginModule::menuActions() const
|
||||||
|
{
|
||||||
|
return m_menuActions;
|
||||||
}
|
}
|
||||||
|
|
||||||
void PluginModule::registerModuleAction(QString module_action, ModuleAction action)
|
void PluginModule::registerModuleAction(QString module_action, ModuleAction action)
|
||||||
|
|
|
||||||
|
|
@ -1,13 +1,13 @@
|
||||||
#ifndef PLUGIN_SUPPORTPLUGINMODULE_H
|
#ifndef PLUGIN_SUPPORTPLUGINMODULE_H
|
||||||
#define PLUGIN_SUPPORTPLUGINMODULE_H
|
#define PLUGIN_SUPPORTPLUGINMODULE_H
|
||||||
|
|
||||||
#include "MenuLocation.h"
|
|
||||||
#include "ToolbarLocation.h"
|
|
||||||
#include "ModuleActionParameters.h"
|
#include "ModuleActionParameters.h"
|
||||||
|
#include "MenuAction.h"
|
||||||
#include "PluginRegister.h"
|
#include "PluginRegister.h"
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
#include <functional>
|
#include <functional>
|
||||||
#include <map>
|
#include <map>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
class QAction;
|
class QAction;
|
||||||
class IPluginContentWidgetContext;
|
class IPluginContentWidgetContext;
|
||||||
|
|
@ -15,17 +15,23 @@ class IPluginContentWidgetContext;
|
||||||
class PluginModule: public QObject {
|
class PluginModule: public QObject {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
|
using MenuActionList = std::vector<MenuAction>;
|
||||||
using ModuleAction = std::function<void(IPluginContentWidgetContext*, const ModuleActionParameters &)>;
|
using ModuleAction = std::function<void(IPluginContentWidgetContext*, const ModuleActionParameters &)>;
|
||||||
using ModuleActionMap = std::map<QString, ModuleAction>;
|
using ModuleActionMap = std::map<QString, ModuleAction>;
|
||||||
|
|
||||||
PluginModule(QString name, QString ident);
|
PluginModule(QString name, QString ident);
|
||||||
|
|
||||||
|
virtual void init() {};
|
||||||
|
|
||||||
const QString& name() const { return m_name; }
|
const QString& name() const { return m_name; }
|
||||||
const QString& identifier() const { return m_ident; }
|
const QString& identifier() const { return m_ident; }
|
||||||
const QString& displayCategory() const { return m_displayCategory; }
|
const QString& displayCategory() const { return m_displayCategory; }
|
||||||
|
|
||||||
void setDisplayCategory(QString category);
|
void setDisplayCategory(QString category);
|
||||||
void registerAction(QAction *action, MenuLocation menu_location, ToolbarLocation toolbar_location);
|
|
||||||
|
/// registers an action that should always be accessible from the menu
|
||||||
|
void registerMenuAction(MenuAction action);
|
||||||
|
const MenuActionList& menuActions() const;
|
||||||
|
|
||||||
void registerModuleAction(QString module_action, ModuleAction action);
|
void registerModuleAction(QString module_action, ModuleAction action);
|
||||||
|
|
||||||
|
|
@ -39,6 +45,7 @@ private:
|
||||||
QString m_ident;
|
QString m_ident;
|
||||||
QString m_displayCategory;
|
QString m_displayCategory;
|
||||||
|
|
||||||
|
MenuActionList m_menuActions;
|
||||||
ModuleActionMap m_moduleActions;
|
ModuleActionMap m_moduleActions;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -47,7 +54,6 @@ template <typename T>
|
||||||
std::shared_ptr<PluginModule> createPluginModule(QString name, QString ident)
|
std::shared_ptr<PluginModule> createPluginModule(QString name, QString ident)
|
||||||
{
|
{
|
||||||
auto module = std::make_shared<T>(std::move(name), std::move(ident));
|
auto module = std::make_shared<T>(std::move(name), std::move(ident));
|
||||||
module->init();
|
|
||||||
|
|
||||||
PluginRegister::getInstance()->registerModule(module);
|
PluginRegister::getInstance()->registerModule(module);
|
||||||
return std::move(module);
|
return std::move(module);
|
||||||
|
|
|
||||||
|
|
@ -23,6 +23,13 @@ PluginRegister* PluginRegister::getInstance()
|
||||||
|
|
||||||
PluginRegister::PluginRegister() = default;
|
PluginRegister::PluginRegister() = default;
|
||||||
|
|
||||||
|
void PluginRegister::initModules()
|
||||||
|
{
|
||||||
|
for (auto && mod : m_moduleMap) {
|
||||||
|
mod.second->init();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void PluginRegister::registerModule(PluginModuleSPtr module)
|
void PluginRegister::registerModule(PluginModuleSPtr module)
|
||||||
{
|
{
|
||||||
m_moduleMap.emplace(module->identifier(), module);
|
m_moduleMap.emplace(module->identifier(), module);
|
||||||
|
|
|
||||||
|
|
@ -18,6 +18,8 @@ public:
|
||||||
|
|
||||||
PluginRegister();
|
PluginRegister();
|
||||||
void registerModule(PluginModuleSPtr module);
|
void registerModule(PluginModuleSPtr module);
|
||||||
|
|
||||||
|
void initModules();
|
||||||
const ModuleMap& modules() const{ return m_moduleMap; }
|
const ModuleMap& modules() const{ return m_moduleMap; }
|
||||||
|
|
||||||
const PluginModule* findModule(const QString &module_ident) const;
|
const PluginModule* findModule(const QString &module_ident) const;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue