The querytab now shows the elapsed time of the query using the new stopwatch class.

The old elapsedtime code from the mainwindow has been removed.
This commit is contained in:
Eelke Klein 2017-01-22 08:50:41 +01:00
parent 7f379f3b80
commit 6e852f466f
7 changed files with 232 additions and 163 deletions

View file

@ -14,23 +14,10 @@
#include <QCloseEvent>
#include <querytab.h>
#include "util.h"
//#include <thread>
namespace pg = Pgsql;
const char * test_query =
//"SELECT id, program, version, lic_bedrijf, lic_plaats, "
//"lic_number, callstack_crc_1, callstack_crc_2, callstack_crc_3, exception_class, "
//"exception_message \nFROM foutrapport"
"SELECT f1.id, f1.program, f1.version, f1.lic_number, f1.callstack_crc_1, f1.callstack_crc_2, array_agg(f2.id) \n"
"FROM foutrapport f1 JOIN foutrapport f2 USING (callstack_crc_2) \n"
"WHERE f1.actief \n"
"GROUP BY f1.id"
;
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
@ -38,37 +25,22 @@ MainWindow::MainWindow(QWidget *parent)
{
ui->setupUi(this);
m_timeElapsedLabel = new QLabel(this);
statusBar()->addPermanentWidget(m_timeElapsedLabel);
// {
// QVBoxLayout *layout = new QVBoxLayout;
// layout->addWidget(m_queryTab);
// layout->setMargin(4);
// ui->tab_2->setLayout(layout);
// }
ui->tabWidget->setDocumentMode(true);
ui->tabWidget->setTabsClosable(true);
}
MainWindow::~MainWindow()
{
// m_dbConnection.closeConnection();
// m_dbConnection.setStateCallback(nullptr);
delete ui;
}
void MainWindow::newSqlPage()
QueryTab* MainWindow::newSqlPage()
{
QueryTab *qt = new QueryTab(this);
qt->setConfig(m_config);
// QVBoxLayout *layout = new QVBoxLayout;
// layout->addWidget(qt);
// layout->setMargin(4);
ui->tabWidget->addTab(qt, "Tab");
ui->tabWidget->setCurrentWidget(qt);
return qt;
}
QueryTab *MainWindow::GetActiveQueryTab()
@ -106,52 +78,16 @@ void MainWindow::processCallableQueue()
}
}
void MainWindow::startTimer()
{
m_startTime = std::chrono::steady_clock::now();
m_timer = std::make_unique<QTimer>(nullptr);
m_timer->setTimerType(Qt::CoarseTimer);
connect(m_timer.get(), SIGNAL(timeout()), this, SLOT(updateTimer()));
m_timer->start(18);
}
void MainWindow::updateTimer()
{
auto nu = std::chrono::steady_clock::now();
std::chrono::duration<float, std::milli> diff = nu - m_startTime;
elapsedTime = diff;
m_timeElapsedLabel->setText(msfloatToHumanReadableString(diff.count()));
if (m_timer) {
int ms = diff.count();
int interval = 18;
if (ms >= 10000) {
int rem = ms % 1000;
interval = 1000 - rem;
}
else if (ms >= 1000) {
interval = 100;
}
m_timer->start(interval);
}
}
void MainWindow::endTimer()
{
if (m_timer) {
m_timer.reset();
updateTimer();
}
}
void MainWindow::on_actionLoad_SQL_triggered()
{
QueryTab *tab = GetActiveQueryTab();
if (tab) {
tab->open();
QString home_dir = QStandardPaths::locate(QStandardPaths::HomeLocation, "", QStandardPaths::LocateDirectory);
QString file_name = QFileDialog::getOpenFileName(this,
tr("Open sql query"), home_dir, tr("SQL files (*.sql *.txt)"));
if ( ! file_name.isEmpty()) {
QueryTab* qt = newSqlPage();
qt->load(file_name);
}
}
void MainWindow::on_actionSave_SQL_triggered()
@ -272,11 +208,16 @@ void MainWindow::showEvent(QShowEvent *event)
event->accept();
}
void MainWindow::on_actionNew_SQL_triggered()
{
newSqlPage();
newSqlPage()->newdoc();
}
void MainWindow::on_tabWidget_tabCloseRequested(int index)
{
QWidget *widget = ui->tabWidget->widget(index);
QueryTab *qt = dynamic_cast<QueryTab*>(widget);
if (qt->canClose()) {
ui->tabWidget->removeTab(index);
}
}