pgLab/pglab/QueryToolModule.cpp
eelke f4f2474a81 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.
2019-01-05 19:58:23 +01:00

85 lines
2.6 KiB
C++

#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")