Connection manager can now open a query window for selected connection.
Query window has now buttons with icons made in the designer for better looks. Depending on received responses from the database the tabcontrol with the message, data and explain tab now switches to the appropriate tab.
This commit is contained in:
parent
88fcc0338d
commit
d19741f111
26 changed files with 408 additions and 116 deletions
|
|
@ -93,21 +93,18 @@ MainWindow::MainWindow(QWidget *parent)
|
|||
font.setPointSize(10);
|
||||
ui->queryEdit->setFont(font);
|
||||
highlighter.reset(new SqlHighlighter(ui->queryEdit->document()));
|
||||
ui->queryEdit->setPlainText(test_query);
|
||||
ui->connectionStringEdit->setText("user=postgres dbname=foutrapport password=admin");
|
||||
// ui->queryEdit->setPlainText(test_query);
|
||||
// ui->connectionStringEdit->setText("user=postgres dbname=foutrapport password=admin");
|
||||
|
||||
QAction *action;
|
||||
action = ui->mainToolBar->addAction("connect");
|
||||
connect(action, &QAction::triggered, this, &MainWindow::startConnect);
|
||||
// QAction *action;
|
||||
// action = ui->mainToolBar->addAction("connect");
|
||||
// connect(action, &QAction::triggered, this, &MainWindow::startConnect);
|
||||
|
||||
action = ui->mainToolBar->addAction("execute");
|
||||
connect(action, &QAction::triggered, this, &MainWindow::performQuery);
|
||||
// action = ui->mainToolBar->addAction("explain");
|
||||
// connect(action, &QAction::triggered, this, &MainWindow::performExplain);
|
||||
|
||||
action = ui->mainToolBar->addAction("explain");
|
||||
connect(action, &QAction::triggered, this, &MainWindow::performExplain);
|
||||
|
||||
action = ui->mainToolBar->addAction("cancel");
|
||||
connect(action, &QAction::triggered, this, &MainWindow::cancel_query);
|
||||
// action = ui->mainToolBar->addAction("cancel");
|
||||
// connect(action, &QAction::triggered, this, &MainWindow::cancel_query);
|
||||
|
||||
m_dbConnection.setStateCallback([this](ASyncDBConnection::State st)
|
||||
{
|
||||
|
|
@ -130,6 +127,15 @@ MainWindow::~MainWindow()
|
|||
delete ui;
|
||||
}
|
||||
|
||||
void MainWindow::setConfig(const ConnectionConfig &config)
|
||||
{
|
||||
m_config = config;
|
||||
QString title = "pglab - ";
|
||||
title += m_config.name().c_str();
|
||||
setWindowTitle(title);
|
||||
QueueTask([this]() { startConnect(); });
|
||||
}
|
||||
|
||||
void MainWindow::QueueTask(TSQueue::t_Callable c)
|
||||
{
|
||||
m_taskQueue.add(c);
|
||||
|
|
@ -175,8 +181,9 @@ void MainWindow::connectionStateChanged(ASyncDBConnection::State state)
|
|||
|
||||
void MainWindow::startConnect()
|
||||
{
|
||||
std::string connstr = ui->connectionStringEdit->text().toUtf8().data();
|
||||
m_dbConnection.setupConnection(connstr);
|
||||
// std::string connstr = ui->connectionStringEdit->text().toUtf8().data();
|
||||
// m_dbConnection.setupConnection(connstr);
|
||||
m_dbConnection.setupConnection(m_config);
|
||||
}
|
||||
|
||||
void MainWindow::performQuery()
|
||||
|
|
@ -206,6 +213,7 @@ void MainWindow::query_ready(std::shared_ptr<Pgsql::Result> dbres)
|
|||
if (st == PGRES_TUPLES_OK) {
|
||||
resultModel.reset(new QueryResultModel(nullptr , dbres));
|
||||
ui->ResultView->setModel(resultModel.get());
|
||||
ui->tabWidget->setCurrentWidget(ui->dataTab);
|
||||
statusBar()->showMessage(tr("Query ready."));
|
||||
}
|
||||
else {
|
||||
|
|
@ -239,6 +247,7 @@ void MainWindow::query_ready(std::shared_ptr<Pgsql::Result> dbres)
|
|||
else {
|
||||
statusBar()->showMessage(tr("No tuples returned, possibly an error..."));
|
||||
}
|
||||
ui->tabWidget->setCurrentWidget(ui->messageTab);
|
||||
receiveNotice(dbres->diagDetails());
|
||||
}
|
||||
}
|
||||
|
|
@ -303,10 +312,12 @@ void MainWindow::explain_ready(ExplainRoot::SPtr explain)
|
|||
ui->explainTreeView->setColumnWidth(4, 80);
|
||||
ui->explainTreeView->setColumnWidth(5, 80);
|
||||
ui->explainTreeView->setColumnWidth(6, 600);
|
||||
ui->tabWidget->setCurrentWidget(ui->explainTab);
|
||||
statusBar()->showMessage(tr("Explain ready."));
|
||||
}
|
||||
else {
|
||||
addLog("Explain no result");
|
||||
ui->tabWidget->setCurrentWidget(ui->messageTab);
|
||||
statusBar()->showMessage(tr("Explain failed."));
|
||||
}
|
||||
}
|
||||
|
|
@ -321,10 +332,6 @@ void MainWindow::receiveNotice(Pgsql::ErrorDetails notice)
|
|||
QTextCursor cursor = ui->messagesEdit->textCursor();
|
||||
cursor.movePosition(QTextCursor::End, QTextCursor::MoveAnchor);
|
||||
|
||||
|
||||
// QString msg;
|
||||
// cursor.insertText("TEST\r\n");
|
||||
|
||||
QTextTable *table = cursor.insertTable(4, 2);
|
||||
if (table) {
|
||||
table->cellAt(1, 0).firstCursorPosition().insertText("State");
|
||||
|
|
@ -466,3 +473,18 @@ void Copy( )
|
|||
QApplication.clipboard().setText(selected_text);
|
||||
}
|
||||
#endif
|
||||
|
||||
void MainWindow::on_actionExecute_SQL_triggered()
|
||||
{
|
||||
performQuery();
|
||||
}
|
||||
|
||||
void MainWindow::on_actionExplain_Analyze_triggered()
|
||||
{
|
||||
performExplain();
|
||||
}
|
||||
|
||||
void MainWindow::on_actionCancel_triggered()
|
||||
{
|
||||
cancel_query();
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue