Moved definition of widget instance actions to the module so other parts of the system can no about them.
The plugin system will create the Action objects and bind them to the specified slots of the specific widget instances.
This commit is contained in:
parent
d0c4dabe8b
commit
f4f2474a81
21 changed files with 418 additions and 204 deletions
85
pglab/QueryToolModule.cpp
Normal file
85
pglab/QueryToolModule.cpp
Normal file
|
|
@ -0,0 +1,85 @@
|
|||
#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());
|
||||
{
|
||||
MenuAction ma("New SQL", [this] (IPluginContentWidgetContext* context)
|
||||
{ menuAction_new(context); });
|
||||
ma.setMenuLocation(MenuPath("File/New"));
|
||||
ma.setIcon(QIcon(":/icons/new_query_tab.png"));
|
||||
ma.setShortcut(QKeySequence(Qt::CTRL + Qt::Key_N));
|
||||
registerMenuAction(ma);
|
||||
}
|
||||
{
|
||||
MenuAction ma("Open SQL", [this] (IPluginContentWidgetContext* context)
|
||||
{ menuAction_open(context); });
|
||||
ma.setMenuLocation(MenuPath("File/Open"));
|
||||
ma.setIcon(QIcon(":/icons/folder.png"));
|
||||
registerMenuAction(ma);
|
||||
}
|
||||
{
|
||||
LWidgetAction wa("Save SQL", SLOT(save()));
|
||||
wa.setMenuLocation(MenuPath("File/Save"));
|
||||
wa.setIcon(QIcon(":/icons/script_save.png"));
|
||||
wa.setShortcut(QKeySequence(Qt::CTRL + Qt::Key_S));
|
||||
registerWidgetAction(wa);
|
||||
}
|
||||
{
|
||||
LWidgetAction wa("Save SQL as", SLOT(saveAs()));
|
||||
wa.setMenuLocation(MenuPath("File/Save"));
|
||||
wa.setIcon(QIcon(":/icons/script_save.png"));
|
||||
registerWidgetAction(wa);
|
||||
}
|
||||
{
|
||||
LWidgetAction wa("Execute", SLOT(execute()));
|
||||
wa.setMenuLocation(MenuPath("Query/1"));
|
||||
wa.setIcon(QIcon(":/icons/script_go.png"));
|
||||
registerWidgetAction(wa);
|
||||
}
|
||||
{
|
||||
LWidgetAction wa("Explain", SLOT(explain()));
|
||||
wa.setMenuLocation(MenuPath("Query/2"));
|
||||
wa.setIcon(QIcon(":/icons/lightbulb_off.png"));
|
||||
registerWidgetAction(wa);
|
||||
}
|
||||
{
|
||||
LWidgetAction wa("Analyze", SLOT(analyze()));
|
||||
wa.setMenuLocation(MenuPath("Query/1"));
|
||||
wa.setIcon(QIcon(":/icons/lightbulb.png"));
|
||||
registerWidgetAction(wa);
|
||||
}
|
||||
{
|
||||
LWidgetAction wa("Cancel", SLOT(cancel()));
|
||||
wa.setMenuLocation(MenuPath("Query/1"));
|
||||
wa.setIcon(QIcon(":/icons/script_delete.png"));
|
||||
registerWidgetAction(wa);
|
||||
}
|
||||
}
|
||||
|
||||
void QueryToolModule::menuAction_new(IPluginContentWidgetContext* context)
|
||||
{
|
||||
auto *ct = new QueryTool(context, nullptr);
|
||||
context->addContentWidget(this, ct);
|
||||
ct->newdoc();
|
||||
}
|
||||
|
||||
void QueryToolModule::menuAction_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, nullptr);
|
||||
context->addContentWidget(this, ct);
|
||||
ct->load(file_name);
|
||||
}
|
||||
}
|
||||
|
||||
REGISTER_PLUGIN_MODULE(QueryToolModule, "Query tool", "pglab.querytool")
|
||||
Loading…
Add table
Add a link
Reference in a new issue