ft: Closing windows asks to save queries before closing the window.
fix: closetab did incorrectly close when cancel was choosen.
This commit is contained in:
parent
adb44fc157
commit
dea76e17c5
7 changed files with 59 additions and 10 deletions
|
|
@ -9,6 +9,7 @@
|
||||||
#include "TaskExecutor.h"
|
#include "TaskExecutor.h"
|
||||||
#include <QAction>
|
#include <QAction>
|
||||||
#include <QApplication>
|
#include <QApplication>
|
||||||
|
#include <QCloseEvent>
|
||||||
#include <QFileDialog>
|
#include <QFileDialog>
|
||||||
#include <QMenuBar>
|
#include <QMenuBar>
|
||||||
#include <QMessageBox>
|
#include <QMessageBox>
|
||||||
|
|
@ -24,6 +25,9 @@
|
||||||
namespace pg = Pgsql;
|
namespace pg = Pgsql;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
DatabaseWindow::DatabaseWindow(MasterController *master, QWidget *parent)
|
DatabaseWindow::DatabaseWindow(MasterController *master, QWidget *parent)
|
||||||
: QMainWindow(parent)
|
: QMainWindow(parent)
|
||||||
, m_masterController(master)
|
, m_masterController(master)
|
||||||
|
|
@ -84,6 +88,20 @@ CrudTab *DatabaseWindow::GetActiveCrud()
|
||||||
return ct;
|
return ct;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void DatabaseWindow::closeEvent(QCloseEvent *event)
|
||||||
|
{
|
||||||
|
for (int idx = 0; idx < m_tabWidget->count(); ++idx) {
|
||||||
|
auto widget = m_tabWidget->widget(idx);
|
||||||
|
auto mp = dynamic_cast<ManagedPage*>(widget);
|
||||||
|
if (mp) {
|
||||||
|
if (!mp->CanClose(true)) {
|
||||||
|
event->ignore();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void DatabaseWindow::setConfig(const ConnectionConfig &config)
|
void DatabaseWindow::setConfig(const ConnectionConfig &config)
|
||||||
{
|
{
|
||||||
m_config = config;
|
m_config = config;
|
||||||
|
|
@ -352,13 +370,15 @@ void DatabaseWindow::closeTab(int index)
|
||||||
{
|
{
|
||||||
QWidget *widget = m_tabWidget->widget(index);
|
QWidget *widget = m_tabWidget->widget(index);
|
||||||
|
|
||||||
auto qt = dynamic_cast<QueryTool*>(widget);
|
auto mp = dynamic_cast<ManagedPage*>(widget);
|
||||||
if (qt && qt->canClose()) {
|
if (mp) {
|
||||||
m_tabWidget->removeTab(index);
|
if (mp->CanClose(true)) {
|
||||||
|
m_tabWidget->removeTab(index);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else if (index >= 0) {
|
else if (index >= 0) {
|
||||||
m_tabWidget->removeTab(index);
|
m_tabWidget->removeTab(index);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void DatabaseWindow::catalogLoaded()
|
void DatabaseWindow::catalogLoaded()
|
||||||
|
|
|
||||||
|
|
@ -50,6 +50,10 @@ public:
|
||||||
|
|
||||||
QueryTool *GetActiveQueryTool();
|
QueryTool *GetActiveQueryTool();
|
||||||
CrudTab *GetActiveCrud();
|
CrudTab *GetActiveCrud();
|
||||||
|
|
||||||
|
protected:
|
||||||
|
virtual void closeEvent(QCloseEvent *event) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QTabWidget *m_tabWidget = nullptr;
|
QTabWidget *m_tabWidget = nullptr;
|
||||||
QToolBar *m_mainToolBar = nullptr;
|
QToolBar *m_mainToolBar = nullptr;
|
||||||
|
|
|
||||||
2
pglab/ManagedPage.cpp
Normal file
2
pglab/ManagedPage.cpp
Normal file
|
|
@ -0,0 +1,2 @@
|
||||||
|
#include "ManagedPage.h"
|
||||||
|
|
||||||
17
pglab/ManagedPage.h
Normal file
17
pglab/ManagedPage.h
Normal file
|
|
@ -0,0 +1,17 @@
|
||||||
|
#ifndef MANAGEDPAGE_H
|
||||||
|
#define MANAGEDPAGE_H
|
||||||
|
|
||||||
|
#include <QWidget>
|
||||||
|
|
||||||
|
class ManagedPage: public QWidget
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
using QWidget::QWidget;
|
||||||
|
|
||||||
|
virtual ~ManagedPage() {}
|
||||||
|
|
||||||
|
virtual bool CanClose(bool prompt_user) = 0;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // MANAGEDPAGE_H
|
||||||
|
|
@ -23,7 +23,7 @@
|
||||||
|
|
||||||
|
|
||||||
QueryTool::QueryTool(IDatabaseWindow *context, QWidget *parent)
|
QueryTool::QueryTool(IDatabaseWindow *context, QWidget *parent)
|
||||||
: QWidget(parent)
|
: ManagedPage(parent)
|
||||||
, m_context(context)
|
, m_context(context)
|
||||||
, ui(new Ui::QueryTab)
|
, ui(new Ui::QueryTab)
|
||||||
, m_dbConnection()
|
, m_dbConnection()
|
||||||
|
|
@ -61,11 +61,14 @@ QueryTool::~QueryTool()
|
||||||
delete ui;
|
delete ui;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool QueryTool::canClose()
|
bool QueryTool::CanClose(bool prompt_user)
|
||||||
{
|
{
|
||||||
bool can_close;
|
bool can_close;
|
||||||
if (m_queryTextChanged) {
|
if (m_queryTextChanged) {
|
||||||
can_close = continueWithoutSavingWarning();
|
if (prompt_user)
|
||||||
|
can_close = continueWithoutSavingWarning();
|
||||||
|
else
|
||||||
|
can_close = false;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
can_close = true;
|
can_close = true;
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
#ifndef QUERYTAB_H
|
#ifndef QUERYTAB_H
|
||||||
#define QUERYTAB_H
|
#define QUERYTAB_H
|
||||||
|
|
||||||
|
#include "ManagedPage.h"
|
||||||
#include "ASyncDBConnection.h"
|
#include "ASyncDBConnection.h"
|
||||||
#include "QueryResultModel.h"
|
#include "QueryResultModel.h"
|
||||||
#include "QueryExplainModel.h"
|
#include "QueryExplainModel.h"
|
||||||
|
|
@ -32,7 +33,7 @@ class OpenDatabase;
|
||||||
class QueryParamListController;
|
class QueryParamListController;
|
||||||
class PgDatabaseCatalog;
|
class PgDatabaseCatalog;
|
||||||
|
|
||||||
class QueryTool : public QWidget {
|
class QueryTool : public ManagedPage {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
QueryTool(IDatabaseWindow *context, QWidget *parent = nullptr);
|
QueryTool(IDatabaseWindow *context, QWidget *parent = nullptr);
|
||||||
|
|
@ -43,7 +44,7 @@ public:
|
||||||
|
|
||||||
void explain(bool analyze);
|
void explain(bool analyze);
|
||||||
|
|
||||||
bool canClose();
|
bool CanClose(bool prompt_user);
|
||||||
|
|
||||||
void generateCode();
|
void generateCode();
|
||||||
void exportDataToFilename(const QString &filename);
|
void exportDataToFilename(const QString &filename);
|
||||||
|
|
|
||||||
|
|
@ -25,6 +25,7 @@ SOURCES += main.cpp\
|
||||||
ConnectionController.cpp \
|
ConnectionController.cpp \
|
||||||
DependantsPage.cpp \
|
DependantsPage.cpp \
|
||||||
DependantsTableModel.cpp \
|
DependantsTableModel.cpp \
|
||||||
|
ManagedPage.cpp \
|
||||||
NotificationListWidget.cpp \
|
NotificationListWidget.cpp \
|
||||||
NotificationModel.cpp \
|
NotificationModel.cpp \
|
||||||
NotificationService.cpp \
|
NotificationService.cpp \
|
||||||
|
|
@ -94,6 +95,7 @@ HEADERS += \
|
||||||
DependantsPage.h \
|
DependantsPage.h \
|
||||||
DependantsTableModel.h \
|
DependantsTableModel.h \
|
||||||
IDatabaseWindow.h \
|
IDatabaseWindow.h \
|
||||||
|
ManagedPage.h \
|
||||||
NotificationListWidget.h \
|
NotificationListWidget.h \
|
||||||
NotificationModel.h \
|
NotificationModel.h \
|
||||||
NotificationService.h \
|
NotificationService.h \
|
||||||
|
|
@ -174,7 +176,7 @@ FORMS += \
|
||||||
RESOURCES += \
|
RESOURCES += \
|
||||||
resources.qrc
|
resources.qrc
|
||||||
|
|
||||||
QMAKE_LFLAGS_WINDOWS = /SUBSYSTEM:WINDOWS,5.01
|
#QMAKE_LFLAGS_WINDOWS = /SUBSYSTEM:WINDOWS,5.01
|
||||||
|
|
||||||
win32:CONFIG(release, debug|release): LIBS += -L$$OUT_PWD/../core/release/ -lcore
|
win32:CONFIG(release, debug|release): LIBS += -L$$OUT_PWD/../core/release/ -lcore
|
||||||
else:win32:CONFIG(debug, debug|release): LIBS += -L$$OUT_PWD/../core/debug/ -lcore
|
else:win32:CONFIG(debug, debug|release): LIBS += -L$$OUT_PWD/../core/debug/ -lcore
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue