109 lines
3.2 KiB
C++
109 lines
3.2 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("File/Save");
|
|
wa.setIcon(":/icons/script_save.png");
|
|
wa.setShortcut(QKeySequence(Qt::CTRL + Qt::Key_S));
|
|
registerWidgetAction(wa);
|
|
}
|
|
{
|
|
LWidgetAction wa("Save SQL as", SLOT(saveAs()));
|
|
wa.setMenuLocation("File/Save");
|
|
wa.setIcon(":/icons/script_save.png");
|
|
registerWidgetAction(wa);
|
|
}
|
|
{
|
|
LWidgetAction wa("Save copy of SQL as", SLOT(saveCopyAs()));
|
|
wa.setMenuLocation("File/Save");
|
|
//wa.setIcon(":/icons/script_save.png");
|
|
registerWidgetAction(wa);
|
|
}
|
|
{
|
|
LWidgetAction wa("&Export data", SLOT(exportData()));
|
|
wa.setMenuLocation("File/Export");
|
|
wa.setIcon(":/icons/table_save.png");
|
|
registerWidgetAction(wa);
|
|
}
|
|
{
|
|
LWidgetAction wa("Copy as C string", SLOT(copyQueryAsCString()));
|
|
wa.setMenuLocation("Edit/Copy");
|
|
wa.setIcon(":/icons/token_shortland_character.png");
|
|
registerWidgetAction(wa);
|
|
}
|
|
{
|
|
LWidgetAction wa("Copy as raw C++ string", SLOT(copyQueryAsRawCppString()));
|
|
wa.setMenuLocation("Edit/Copy");
|
|
wa.setIcon(":/icons/token_shortland_character.png");
|
|
registerWidgetAction(wa);
|
|
}
|
|
{
|
|
LWidgetAction wa("Execute", SLOT(execute()));
|
|
wa.setMenuLocation("Query/1");
|
|
wa.setIcon(":/icons/script_go.png");
|
|
registerWidgetAction(wa);
|
|
}
|
|
{
|
|
LWidgetAction wa("Explain", SLOT(explain()));
|
|
wa.setMenuLocation("Query/2");
|
|
wa.setIcon(":/icons/lightbulb_off.png");
|
|
registerWidgetAction(wa);
|
|
}
|
|
{
|
|
LWidgetAction wa("Analyze", SLOT(analyze()));
|
|
wa.setMenuLocation("Query/1");
|
|
wa.setIcon(":/icons/lightbulb.png");
|
|
registerWidgetAction(wa);
|
|
}
|
|
{
|
|
LWidgetAction wa("Cancel", SLOT(cancel()));
|
|
wa.setMenuLocation("Query/1");
|
|
wa.setIcon(":/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_CAT(QueryToolModule, "Query tool", "pglab.querytool", "database")
|