Work on plugin mechanism

Context actions have become normal actions in the pluginwidget so the widget knows abot them and
can easily do things like enable/disable.
This commit is contained in:
eelke 2019-02-08 10:10:11 +01:00
parent eca8841427
commit a704332342
24 changed files with 239 additions and 267 deletions

View file

@ -45,6 +45,8 @@ QueryTool::QueryTool(IPluginContentWidgetContext *context_, QWidget *parent)
highlighter->setTypes(*cat->types());
}
initActions();
connect(ui->queryEdit, &QPlainTextEdit::textChanged, this, &QueryTool::queryTextChanged);
m_queryParamListController = new QueryParamListController(ui->paramTableView, open_database, this);
@ -173,16 +175,6 @@ void QueryTool::execute()
}
}
void QueryTool::explain()
{
explain(false);
}
void QueryTool::analyze()
{
explain(true);
}
void QueryTool::explain(bool analyze)
{
ui->explainTreeView->setModel(nullptr);
@ -615,7 +607,7 @@ void QueryTool::generateCode()
}
}
void QueryTool::exportData(const QString &file_name)
void QueryTool::exportDataToFilename(const QString &file_name)
{
auto widget = ui->tabWidget->currentWidget();
auto fi = std::find(resultList.begin(), resultList.end(), widget);
@ -635,5 +627,73 @@ void QueryTool::exportData()
QString home_dir = QStandardPaths::locate(QStandardPaths::HomeLocation, "", QStandardPaths::LocateDirectory);
QString file_name = QFileDialog::getSaveFileName(this,
tr("Export data"), home_dir, tr("CSV file (*.csv)"));
exportData(file_name);
exportDataToFilename(file_name);
}
void QueryTool::initActions()
{
{
auto ac = new QAction(QIcon(":/icons/script_save.png"), tr("Save SQL"), this);
ac->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_S));
connect(ac, &QAction::triggered, this, &QueryTool::save);
m_saveSqlAction = ac;
}
{
auto ac = new QAction(QIcon(":/icons/script_save.png"), tr("Save SQL as"), this);
connect(ac, &QAction::triggered, this, &QueryTool::saveAs);
m_saveSqlAsAction = ac;
}
{
auto ac = new QAction(QIcon(":/icons/script_save.png"), tr("Save copy of SQL as"), this);
connect(ac, &QAction::triggered, this, &QueryTool::saveCopyAs);
m_saveCopyOfSqlAsAction = ac;
}
{
auto ac = new QAction(QIcon(":/icons/table_save.png"), tr("&Export data"), this);
connect(ac, &QAction::triggered, this, &QueryTool::exportData);
m_exportDataAction = ac;
}
{
auto ac = new QAction(QIcon(":/icons/token_shortland_character.png"), tr("Copy as C string"), this);
connect(ac, &QAction::triggered, this, &QueryTool::copyQueryAsCString);
m_copyQueryAsCStringAction = ac;
}
{
auto ac = new QAction(QIcon(":/icons/token_shortland_character.png"), tr("Copy as raw C++ string"), this);
connect(ac, &QAction::triggered, this, &QueryTool::copyQueryAsRawCppString);
m_copyQueryAsRawCppStringAction = ac;
}
{
auto ac = new QAction(QIcon(":/icons/script_go.png"), tr("Execute"), this);
connect(ac, &QAction::triggered, this, &QueryTool::execute);
ac->setShortcut(QKeySequence(Qt::Key_F5));
m_executeAction = ac;
}
{
auto ac = new QAction(QIcon(":/icons/lightbulb_off.png"), tr("Explain"), this);
connect(ac, &QAction::triggered, [this] { explain(false); });
ac->setShortcut(QKeySequence(Qt::Key_F7));
m_explainAction = ac;
}
{
auto ac = new QAction(QIcon(":/icons/lightbulb.png"), tr("Analyze"), this);
connect(ac, &QAction::triggered, [this] { explain(true); });
ac->setShortcut(QKeySequence(Qt::SHIFT + Qt::Key_F7));
m_analyzeAction = ac;
}
{
auto ac = new QAction(QIcon(":/icons/script_delete.png"), tr("Cancel"), this);
connect(ac, &QAction::triggered, this, &QueryTool::cancel);
m_analyzeAction = ac;
}
}
QList<QAction *> QueryTool::actions()
{
return { m_saveSqlAction, m_saveSqlAsAction, m_saveCopyOfSqlAsAction,
m_exportDataAction,
m_copyQueryAsCStringAction, m_copyQueryAsRawCppStringAction,
m_executeAction, m_explainAction, m_analyzeAction };
}