From 50cd865b1a0f97368414a526219212dea2461184 Mon Sep 17 00:00:00 2001 From: eelke Date: Sat, 10 Apr 2021 09:49:54 +0200 Subject: [PATCH] Add unsaved changes indication to SQL tabs --- pglab/QueryTool.cpp | 32 +++++++++++++++++++++++++------- pglab/QueryTool.h | 7 +++++-- 2 files changed, 30 insertions(+), 9 deletions(-) diff --git a/pglab/QueryTool.cpp b/pglab/QueryTool.cpp index 2dbd502..0bd1cd7 100644 --- a/pglab/QueryTool.cpp +++ b/pglab/QueryTool.cpp @@ -80,7 +80,7 @@ void QueryTool::newdoc() { ui->queryEdit->clear(); setFileName(tr("new")); - m_queryTextChanged = false; + setQueryTextChanged(false); m_new = true; } @@ -99,7 +99,7 @@ bool QueryTool::load(const QString &filename) } ui->queryEdit->setPlainText(text); - m_queryTextChanged = false; + setQueryTextChanged(false); setFileName(filename); m_new = false; result = true; @@ -244,9 +244,19 @@ QString QueryTool::title() const void QueryTool::setFileName(const QString &filename) { m_fileName = filename; - QFileInfo fileInfo(filename); - QString fn(fileInfo.fileName()); - m_context->setTitleForWidget(this, fn, m_fileName); + updateTitle(); +} + +void QueryTool::updateTitle() +{ + QFileInfo fileInfo(m_fileName); + QString title = fileInfo.fileName(); + + if (m_queryTextChanged) { + title = "*" + title; + } + + m_context->setTitleForWidget(this, title, m_fileName); } bool QueryTool::continueWithoutSavingWarning() @@ -284,7 +294,7 @@ bool QueryTool::saveSqlTo(const QString &filename) stream.flush(); if (stream.status() == QTextStream::Ok) { - m_queryTextChanged = false; + setQueryTextChanged(false); result = true; } } @@ -300,7 +310,7 @@ QString QueryTool::promptUserForSaveSqlFilename() void QueryTool::queryTextChanged() { - m_queryTextChanged = true; + setQueryTextChanged(true); } void QueryTool::connectionStateChanged(ASyncDBConnection::State state) @@ -622,3 +632,11 @@ void QueryTool::exportData() tr("Export data"), home_dir, tr("CSV file (*.csv)")); exportDataToFilename(file_name); } + +void QueryTool::setQueryTextChanged(bool queryTextChanged) +{ + if (m_queryTextChanged != queryTextChanged) { + m_queryTextChanged = queryTextChanged; + updateTitle(); + } +} diff --git a/pglab/QueryTool.h b/pglab/QueryTool.h index 0c6c4ff..f254991 100644 --- a/pglab/QueryTool.h +++ b/pglab/QueryTool.h @@ -56,9 +56,10 @@ public: QString title() const; + public slots: - void execute(); - /// Save the document under its current name, a file save dialog will be shown if this is a new document + void execute(); + /// Save the document under its current name, a file save dialog will be shown if this is a new document bool save(); /// Saves the document under a new name and continue editing the document under this new name. bool saveAs(); @@ -103,6 +104,8 @@ private: void clearResult(); void markError(const Pgsql::ErrorDetails &details); + void updateTitle(); + void setQueryTextChanged(bool queryTextChanged); private slots: