DatabaseWindow now provides some functionality to its child components through the IDatabaseWindow interface.
This way children do not need to include the full header to get access to some utility functions for changing the titles and icons of tabpages (and in fact do not need to know that there are tabs, could be something else)
This commit is contained in:
parent
6d4df99100
commit
1a2ec6a224
6 changed files with 84 additions and 135 deletions
|
|
@ -6,6 +6,7 @@
|
|||
#include <QAction>
|
||||
#include <QFileDialog>
|
||||
#include <QMessageBox>
|
||||
#include <QStatusBar>
|
||||
#include <QTabWidget>
|
||||
#include <QTextCodec>
|
||||
#include <QTextDocumentFragment>
|
||||
|
|
@ -19,17 +20,20 @@
|
|||
#include "util.h"
|
||||
#include "GlobalIoService.h"
|
||||
#include "UserConfiguration.h"
|
||||
#include "IDatabaseWindow.h"
|
||||
|
||||
|
||||
QueryTool::QueryTool(std::shared_ptr<OpenDatabase> open_database, QWidget *parent)
|
||||
QueryTool::QueryTool(IDatabaseWindow *context, QWidget *parent)
|
||||
: QWidget(parent)
|
||||
, m_context(context)
|
||||
, ui(new Ui::QueryTab)
|
||||
, m_dbConnection(*getGlobalAsioIoService())
|
||||
{
|
||||
ui->setupUi(this);
|
||||
|
||||
m_config = open_database->config();
|
||||
m_catalog = open_database->catalog();
|
||||
auto db = context->openDatabase();
|
||||
m_config = db->config();
|
||||
m_catalog = db->catalog();
|
||||
|
||||
connect(&m_dbConnection, &ASyncDBConnection::onStateChanged, this, &QueryTool::connectionStateChanged);
|
||||
connect(&m_dbConnection, &ASyncDBConnection::onNotice, this, &QueryTool::receiveNotice);
|
||||
|
|
@ -39,11 +43,9 @@ QueryTool::QueryTool(std::shared_ptr<OpenDatabase> open_database, QWidget *paren
|
|||
highlighter = new SqlSyntaxHighlighter(ui->queryEdit->document());
|
||||
highlighter->setTypes(*m_catalog->types());
|
||||
|
||||
initActions();
|
||||
|
||||
connect(ui->queryEdit, &QPlainTextEdit::textChanged, this, &QueryTool::queryTextChanged);
|
||||
|
||||
m_queryParamListController = new QueryParamListController(ui->paramTableView, open_database, this);
|
||||
m_queryParamListController = new QueryParamListController(ui->paramTableView, m_context->openDatabase(), this);
|
||||
connect(ui->addButton, &QPushButton::clicked, m_queryParamListController,
|
||||
&QueryParamListController::on_addParam);
|
||||
connect(ui->removeButton, &QPushButton::clicked, m_queryParamListController,
|
||||
|
|
@ -226,7 +228,7 @@ void QueryTool::setFileName(const QString &filename)
|
|||
m_fileName = filename;
|
||||
QFileInfo fileInfo(filename);
|
||||
QString fn(fileInfo.fileName());
|
||||
// context()->setCaption(this, fn, m_fileName);
|
||||
m_context->setTitleForWidget(this, fn, m_fileName);
|
||||
}
|
||||
|
||||
bool QueryTool::continueWithoutSavingWarning()
|
||||
|
|
@ -282,29 +284,27 @@ void QueryTool::queryTextChanged()
|
|||
m_queryTextChanged = true;
|
||||
}
|
||||
|
||||
|
||||
void QueryTool::connectionStateChanged(ASyncDBConnection::State state)
|
||||
{
|
||||
QString iconname;
|
||||
switch (state) {
|
||||
case ASyncDBConnection::State::NotConnected:
|
||||
case ASyncDBConnection::State::Connecting:
|
||||
iconname = "document_red.png";
|
||||
iconname = "red.png";
|
||||
break;
|
||||
case ASyncDBConnection::State::Connected:
|
||||
iconname = "document_green.png";
|
||||
iconname = "green.png";
|
||||
break;
|
||||
case ASyncDBConnection::State::QuerySend:
|
||||
case ASyncDBConnection::State::CancelSend:
|
||||
iconname = "document_yellow.png";
|
||||
iconname = "yellow.png";
|
||||
break;
|
||||
case ASyncDBConnection::State::Terminating:
|
||||
break;
|
||||
}
|
||||
// context()->setIcon(this, iconname);
|
||||
m_context->setIconForWidget(this, QIcon(":/icons/16x16/document_" + iconname));
|
||||
}
|
||||
|
||||
|
||||
void QueryTool::addLog(QString s)
|
||||
{
|
||||
QTextCursor text_cursor = QTextCursor(ui->edtLog->document());
|
||||
|
|
@ -390,12 +390,13 @@ void QueryTool::explain_ready(ExplainRoot::SPtr explain)
|
|||
ui->explainTreeView->setColumnWidth(6, 600);
|
||||
ui->tabWidget->setCurrentWidget(ui->explainTab);
|
||||
|
||||
// context()->showStatusMessage(tr("Explain ready."));
|
||||
m_context->showStatusBarMessage(tr("Explain ready."));
|
||||
|
||||
}
|
||||
else {
|
||||
addLog("Explain no result");
|
||||
addLog(tr("Explain no result"));
|
||||
ui->tabWidget->setCurrentWidget(ui->messageTab);
|
||||
// statusBar()->showMessage(tr("Explain failed."));
|
||||
m_context->showStatusBarMessage(tr("Explain no result"));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -417,27 +418,6 @@ std::string QueryTool::getCommandUtf8() const
|
|||
return getCommand().toUtf8().data();
|
||||
}
|
||||
|
||||
//QTabWidget *QueryTab::getTabWidget()
|
||||
//{
|
||||
// QWidget * w = parentWidget();
|
||||
// QWidget * p = w->parentWidget();
|
||||
// QTabWidget *tw = dynamic_cast<QTabWidget*>(p);
|
||||
// return tw;
|
||||
//}
|
||||
|
||||
//void QueryTab::setTabCaption(const QString &caption, const QString &tooltip)
|
||||
//{
|
||||
// QTabWidget *tabwidget = getTabWidget();
|
||||
// if (tabwidget) {
|
||||
// int i = tabwidget->indexOf(this);
|
||||
// if (i >= 0) {
|
||||
// tabwidget->setTabText(i, caption);
|
||||
// tabwidget->setTabToolTip(i, tooltip);
|
||||
// }
|
||||
// }
|
||||
|
||||
//}
|
||||
|
||||
void QueryTool::query_ready(std::shared_ptr<Pgsql::Result> dbres, qint64 elapsedms)
|
||||
{
|
||||
if (dbres) {
|
||||
|
|
@ -564,14 +544,6 @@ void QueryTool::clearResult()
|
|||
|
||||
void QueryTool::copyQueryAsCString()
|
||||
{
|
||||
// QString command;
|
||||
// QTextCursor cursor = ui->queryEdit->textCursor();
|
||||
// if (cursor.hasSelection()) {
|
||||
// command = cursor.selection().toPlainText();
|
||||
// }
|
||||
// else {
|
||||
// command = ui->queryEdit->toPlainText();
|
||||
// }
|
||||
QString command = getCommand();
|
||||
QString cs = ConvertToMultiLineCString(command);
|
||||
QApplication::clipboard()->setText(cs);
|
||||
|
|
@ -583,7 +555,6 @@ void QueryTool::copyQueryAsCString()
|
|||
void QueryTool::copyQueryAsRawCppString()
|
||||
{
|
||||
QString command = getCommand();
|
||||
//auto sql = getAllOrSelectedSql();
|
||||
QString cs = ConvertToMultiLineRawCppString(command);
|
||||
QApplication::clipboard()->setText(cs);
|
||||
}
|
||||
|
|
@ -623,69 +594,3 @@ void QueryTool::exportData()
|
|||
tr("Export data"), home_dir, tr("CSV file (*.csv)"));
|
||||
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 };
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue