WIP moving actions for toolbar to module system.
This commit is contained in:
parent
f5e9c4b74e
commit
78a6666839
8 changed files with 225 additions and 114 deletions
16
pglab/AbstractCommand.h
Normal file
16
pglab/AbstractCommand.h
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
#ifndef ABSTRACTCOMMAND_H
|
||||
#define ABSTRACTCOMMAND_H
|
||||
|
||||
#include <QString>
|
||||
|
||||
class QAction;
|
||||
|
||||
class AbstractCommand {
|
||||
public:
|
||||
virtual QAction* getAction() const = 0;
|
||||
virtual QString getToolbar() const = 0;
|
||||
virtual QString getMenuPath() const = 0;
|
||||
};
|
||||
|
||||
|
||||
#endif // ABSTRACTCOMMAND_H
|
||||
|
|
@ -179,47 +179,6 @@ void MainWindow::on_actionAbout_triggered()
|
|||
|
||||
}
|
||||
|
||||
void MainWindow::on_actionExecute_SQL_triggered()
|
||||
{
|
||||
QueryTab *tab = GetActiveQueryTab();
|
||||
if (tab) {
|
||||
tab->execute();
|
||||
}
|
||||
else {
|
||||
QWidget *widget = ui->tabWidget->currentWidget();
|
||||
CrudTab *ct = dynamic_cast<CrudTab*>(widget);
|
||||
if (ct) {
|
||||
ct->refresh();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::on_actionExplain_triggered()
|
||||
{
|
||||
QueryTab *tab = GetActiveQueryTab();
|
||||
if (tab) {
|
||||
tab->explain(false);
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::on_actionExplain_Analyze_triggered()
|
||||
{
|
||||
QueryTab *tab = GetActiveQueryTab();
|
||||
if (tab) {
|
||||
tab->explain(true);
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::on_actionCancel_triggered()
|
||||
{
|
||||
QueryTab *tab = GetActiveQueryTab();
|
||||
if (tab) {
|
||||
tab->cancel();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void MainWindow::closeEvent(QCloseEvent* /*event*/)
|
||||
{
|
||||
// TODO collect which files need saving
|
||||
|
|
|
|||
|
|
@ -107,14 +107,10 @@ private slots:
|
|||
void on_actionExport_data_triggered();
|
||||
void on_actionClose_triggered();
|
||||
void on_actionAbout_triggered();
|
||||
void on_actionExecute_SQL_triggered();
|
||||
void on_actionExplain_Analyze_triggered();
|
||||
void on_actionCancel_triggered();
|
||||
void on_actionSave_SQL_as_triggered();
|
||||
void on_actionSave_copy_of_SQL_as_triggered();
|
||||
void on_actionNew_SQL_triggered();
|
||||
void on_tabWidget_tabCloseRequested(int index);
|
||||
void on_actionExplain_triggered();
|
||||
void on_actionShow_connection_manager_triggered();
|
||||
void on_actionCopy_triggered();
|
||||
void on_actionCopy_as_C_string_triggered();
|
||||
|
|
|
|||
|
|
@ -45,7 +45,7 @@
|
|||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>993</width>
|
||||
<height>25</height>
|
||||
<height>20</height>
|
||||
</rect>
|
||||
</property>
|
||||
<widget class="QMenu" name="menuTest">
|
||||
|
|
@ -71,11 +71,7 @@
|
|||
<property name="title">
|
||||
<string>&Query</string>
|
||||
</property>
|
||||
<addaction name="actionExecute_SQL"/>
|
||||
<addaction name="actionExplain"/>
|
||||
<addaction name="actionExplain_Analyze"/>
|
||||
<addaction name="separator"/>
|
||||
<addaction name="actionCancel"/>
|
||||
</widget>
|
||||
<widget class="QMenu" name="menuView">
|
||||
<property name="title">
|
||||
|
|
@ -113,10 +109,6 @@
|
|||
<addaction name="actionCopy"/>
|
||||
<addaction name="actionCopy_as_C_string"/>
|
||||
<addaction name="separator"/>
|
||||
<addaction name="actionExecute_SQL"/>
|
||||
<addaction name="actionExplain"/>
|
||||
<addaction name="actionExplain_Analyze"/>
|
||||
<addaction name="actionCancel"/>
|
||||
<addaction name="separator"/>
|
||||
<addaction name="actionAbout"/>
|
||||
</widget>
|
||||
|
|
@ -177,47 +169,6 @@
|
|||
<string>&About</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="actionExecute_SQL">
|
||||
<property name="icon">
|
||||
<iconset>
|
||||
<normalon>:/icons/script_go.png</normalon>
|
||||
</iconset>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>&Execute queries</string>
|
||||
</property>
|
||||
<property name="toolTip">
|
||||
<string>Execute the (selected) queries</string>
|
||||
</property>
|
||||
<property name="shortcut">
|
||||
<string>F5</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="actionCancel">
|
||||
<property name="icon">
|
||||
<iconset>
|
||||
<normalon>:/icons/script_delete.png</normalon>
|
||||
</iconset>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>&Cancel</string>
|
||||
</property>
|
||||
<property name="shortcut">
|
||||
<string>Alt+Pause</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="actionExplain_Analyze">
|
||||
<property name="icon">
|
||||
<iconset resource="resources.qrc">
|
||||
<normaloff>:/icons/lightbulb.png</normaloff>:/icons/lightbulb.png</iconset>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Ex&plain Analyze</string>
|
||||
</property>
|
||||
<property name="shortcut">
|
||||
<string>Shift+F7</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="actionSave_SQL_as">
|
||||
<property name="text">
|
||||
<string>Sa&ve SQL as</string>
|
||||
|
|
@ -241,22 +192,6 @@
|
|||
<string>Ctrl+N</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="actionExplain">
|
||||
<property name="icon">
|
||||
<iconset>
|
||||
<normalon>:/icons/lightbulb_off.png</normalon>
|
||||
</iconset>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>E&xplain</string>
|
||||
</property>
|
||||
<property name="toolTip">
|
||||
<string>Explain the (selected) query</string>
|
||||
</property>
|
||||
<property name="shortcut">
|
||||
<string>F7</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="actionShow_connection_manager">
|
||||
<property name="text">
|
||||
<string>&Show connection manager</string>
|
||||
|
|
|
|||
|
|
@ -1,8 +1,66 @@
|
|||
#include "Module.h"
|
||||
#include <set>
|
||||
|
||||
using namespace Leon;
|
||||
|
||||
|
||||
void ModuleRegistry::registerModule(Module *module)
|
||||
{
|
||||
modules.insert(module);
|
||||
}
|
||||
|
||||
|
||||
|
||||
ModuleRegistry& Leon::GetModuleRegistry()
|
||||
{
|
||||
static ModuleRegistry registry;
|
||||
return registry;
|
||||
}
|
||||
|
||||
Module::Module()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
ModuleInstance::ModuleInstance()
|
||||
{
|
||||
GetModuleRegistry().registerModule(this);
|
||||
}
|
||||
|
||||
|
||||
//class QueryModule: public ModuleInstance {
|
||||
//public:
|
||||
// QueryModule();
|
||||
|
||||
// virtual QString getName() const override;
|
||||
|
||||
// virtual CommandContainer getCommands() const override;
|
||||
//private:
|
||||
//// CommandContainer commands;
|
||||
|
||||
// void createNewQueryTab();
|
||||
//};
|
||||
|
||||
//QueryModule::QueryModule()
|
||||
//{
|
||||
//// commands = {
|
||||
//// std::make_shared<Command<>>("New SQL file", "", createNewQueryTab)
|
||||
//// ->setHint("")
|
||||
//// ->setDescription("")
|
||||
//// ->setShortCut(Qt::CTRL + Qt::Key_N)
|
||||
//// ->addOnToolbar("standard", "")
|
||||
//// ->setMenuPath("file")
|
||||
//// };
|
||||
//}
|
||||
|
||||
//QString QueryModule::getName() const
|
||||
//{
|
||||
// return "Query Module";
|
||||
//}
|
||||
|
||||
////QueryModule::CommandContainer QueryModule::getCommands() const
|
||||
////{
|
||||
//// return commands;
|
||||
////}
|
||||
|
||||
////QueryModule theQueryModuleInstance;
|
||||
|
|
|
|||
105
pglab/Module.h
105
pglab/Module.h
|
|
@ -1,15 +1,120 @@
|
|||
#ifndef MODULE_H
|
||||
#define MODULE_H
|
||||
|
||||
#include "AbstractCommand.h"
|
||||
#include <QKeySequence>
|
||||
#include <QString>
|
||||
#include <boost/container/small_vector.hpp>
|
||||
#include <memory>
|
||||
#include <unordered_set>
|
||||
#include <vector>
|
||||
|
||||
class QAction;
|
||||
|
||||
namespace Leon {
|
||||
|
||||
class Module;
|
||||
|
||||
class ModuleRegistry {
|
||||
public:
|
||||
using ModuleContainer = std::unordered_set<Module*>;
|
||||
using Iterator = ModuleContainer::iterator;
|
||||
|
||||
Iterator begin() { return modules.begin(); }
|
||||
Iterator end() { return modules.end(); }
|
||||
|
||||
void registerModule(Module *module);
|
||||
|
||||
private:
|
||||
|
||||
ModuleContainer modules;
|
||||
};
|
||||
|
||||
ModuleRegistry& GetModuleRegistry();
|
||||
|
||||
template <typename Func>
|
||||
class Command: public AbstractCommand {
|
||||
public:
|
||||
Command(QString caption, QString iconpath, Func f);
|
||||
Command& setHint(QString hint);
|
||||
Command& setDescription(QString description);
|
||||
Command& setShortCut(QKeySequence shortcut);
|
||||
Command& addOnToolbar(QString toolbar, QString group);
|
||||
Command& setMenuPath(QString menu);
|
||||
|
||||
|
||||
// action = new QAction(QIcon(":/icons/script_save.png"), tr("Save SQL"), this);
|
||||
// action->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_S));
|
||||
// connect(action, &QAction::triggered, this, &QueryTab::save);
|
||||
// actions.push_back(action);
|
||||
private:
|
||||
mutable QAction *action = nullptr;
|
||||
};
|
||||
|
||||
|
||||
/// Abstract interface for retrieving information about a subsystem
|
||||
///
|
||||
/// Each module should derive a class From ModuleInstance and implement
|
||||
/// the abstract methods declared in this interface. Don't do to much in your constructor
|
||||
/// as it might be called very early in the startup of the program
|
||||
class Module
|
||||
{
|
||||
public:
|
||||
using AbstractCommandSptr = std::shared_ptr<AbstractCommand>;
|
||||
using CommandContainer = std::vector<AbstractCommand>;
|
||||
|
||||
Module();
|
||||
|
||||
// getGlobalActions
|
||||
virtual QString getName() const = 0;
|
||||
|
||||
virtual CommandContainer getCommands() const = 0;
|
||||
};
|
||||
|
||||
/// Adds auto registration to Module so not each
|
||||
/// module has to implement registration
|
||||
class ModuleInstance: public Module {
|
||||
protected:
|
||||
ModuleInstance();
|
||||
};
|
||||
|
||||
|
||||
class Path {
|
||||
public:
|
||||
explicit Path(QString p)
|
||||
{
|
||||
int ofs = 0;
|
||||
if (p.isEmpty())
|
||||
return;
|
||||
|
||||
if (p[0] == '/')
|
||||
++ofs;
|
||||
|
||||
while (true) {
|
||||
int i = p.indexOf('/', ofs);
|
||||
if (i >= ofs) {
|
||||
path.push_back(p.mid(ofs, i - ofs));
|
||||
ofs = i+1;
|
||||
}
|
||||
else {
|
||||
path.push_back(p.right(ofs));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int getDepth() const { return path.size(); }
|
||||
QString getElem(int i) const { return path.at(i); }
|
||||
private:
|
||||
using PathContainer = boost::container::small_vector<QString, 3>;
|
||||
|
||||
PathContainer path;
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
#endif // MODULE_H
|
||||
|
|
|
|||
|
|
@ -1,9 +1,11 @@
|
|||
#include "QueryTab.h"
|
||||
|
||||
#include "QueryTab.h"
|
||||
#include "ui_QueryTab.h"
|
||||
#include "SqlSyntaxHighlighter.h"
|
||||
#include <QStandardPaths>
|
||||
#include <QPushButton>
|
||||
|
||||
#include <QAction>
|
||||
#include <QFileDialog>
|
||||
#include <QStatusBar>
|
||||
#include <QMessageBox>
|
||||
|
|
@ -604,13 +606,52 @@ void QueryTab::focusEditor()
|
|||
ui->queryEdit->setFocus();
|
||||
}
|
||||
|
||||
|
||||
std::vector<QAction*> QueryTab::getToolbarActions()
|
||||
{
|
||||
if (actions.empty()) {
|
||||
QAction *action = new QAction(QIcon(":/icons/script_go.png"), tr("Execute"), this);
|
||||
QAction *action;
|
||||
// New
|
||||
// action = new QAction(QIcon(":/icons/new_query_tab.png"), tr("New"), this);
|
||||
// action->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_N));
|
||||
// connect(action, &QAction::triggered, this, &QueryTab::);
|
||||
// actions.push_back(action);
|
||||
// Load
|
||||
|
||||
// Save
|
||||
action = new QAction(QIcon(":/icons/script_save.png"), tr("Save SQL"), this);
|
||||
action->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_S));
|
||||
connect(action, &QAction::triggered, this, &QueryTab::save);
|
||||
actions.push_back(action);
|
||||
// Save as
|
||||
action = new QAction(QIcon(":/icons/script_go.png"), tr("Save SQL as"), this);
|
||||
//action->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_S));
|
||||
connect(action, &QAction::triggered, this, &QueryTab::saveAs);
|
||||
actions.push_back(action);
|
||||
// Save copy as
|
||||
// Copy
|
||||
// Copy as C-string
|
||||
// Copy as raw cpp string
|
||||
// Execute SQL
|
||||
action = new QAction(QIcon(":/icons/script_go.png"), tr("Execute"), this);
|
||||
action->setShortcut(QKeySequence(Qt::Key_F5));
|
||||
connect(action, &QAction::triggered, this, &QueryTab::execute);
|
||||
actions.push_back(action);
|
||||
// Explain
|
||||
action = new QAction(QIcon(":/icons/lightbulb_off.png"), tr("Explain"), this);
|
||||
action->setShortcut(QKeySequence(Qt::Key_F7));
|
||||
connect(action, &QAction::triggered, this, [this] () { explain(false); });
|
||||
actions.push_back(action);
|
||||
// Explain Anaylze
|
||||
action = new QAction(QIcon(":/icons/lightbulb.png"), tr("Analyze"), this);
|
||||
action->setShortcut(QKeySequence(Qt::SHIFT + Qt::Key_F7));
|
||||
connect(action, &QAction::triggered, this, [this] () { explain(true); });
|
||||
actions.push_back(action);
|
||||
// Cancel
|
||||
action = new QAction(QIcon(":/icons/script_delete.png"), tr("Cancel"), this);
|
||||
action->setShortcut(QKeySequence(Qt::ALT + Qt::Key_Pause));
|
||||
connect(action, &QAction::triggered, this, &QueryTab::cancel);
|
||||
actions.push_back(action);
|
||||
}
|
||||
return actions;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -118,7 +118,8 @@ HEADERS += \
|
|||
Module.h \
|
||||
EditorGutter.h \
|
||||
CodeEditor.h \
|
||||
PlgPage.h
|
||||
PlgPage.h \
|
||||
AbstractCommand.h
|
||||
|
||||
FORMS += mainwindow.ui \
|
||||
ConnectionManagerWindow.ui \
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue