Show UnsavedDocumentsDialog when closing window or quitting application
so user can save and or discard docs more efficiently.
This commit is contained in:
parent
b97adced4c
commit
784ad68758
16 changed files with 544 additions and 164 deletions
60
pglab/querytool/SqlDocument.h
Normal file
60
pglab/querytool/SqlDocument.h
Normal file
|
|
@ -0,0 +1,60 @@
|
|||
#ifndef SQLDOCUMENT_H
|
||||
#define SQLDOCUMENT_H
|
||||
|
||||
#include <QList>
|
||||
#include <QObject>
|
||||
#include <QString>
|
||||
|
||||
class QTextDocument;
|
||||
class QWidget;
|
||||
class SqlSyntaxHighlighter;
|
||||
|
||||
/** Owns the text of a SQL script together with its file state.
|
||||
* Several query tools (editors) can show the same document, they all
|
||||
* use the same QTextDocument.
|
||||
*/
|
||||
class SqlDocument : public QObject {
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit SqlDocument(QObject *parent = nullptr);
|
||||
~SqlDocument() override;
|
||||
|
||||
QTextDocument *textDocument() const { return m_document; }
|
||||
SqlSyntaxHighlighter *highlighter() const { return m_highlighter; }
|
||||
|
||||
QString fileName() const { return m_fileName; }
|
||||
bool isNew() const { return m_new; }
|
||||
bool isModified() const;
|
||||
void setModified(bool modified);
|
||||
|
||||
/// Empties the document and makes it a new unnamed document.
|
||||
void clear();
|
||||
bool load(const QString &filename);
|
||||
/// Save the document under its current name, a file save dialog will be shown if this is a new document
|
||||
bool save(QWidget *parent);
|
||||
/// Saves the document under a new name and continue editing the document under this new name.
|
||||
bool saveAs(QWidget *parent);
|
||||
/// Save the document under a new name but continue editing the document under its old name.
|
||||
bool saveCopyAs(QWidget *parent);
|
||||
|
||||
void addEditor(QWidget *editor);
|
||||
void removeEditor(QWidget *editor);
|
||||
const QList<QWidget*> &editors() const { return m_editors; }
|
||||
|
||||
signals:
|
||||
void modifiedChanged(bool modified);
|
||||
void fileNameChanged();
|
||||
|
||||
private:
|
||||
QTextDocument *m_document;
|
||||
SqlSyntaxHighlighter *m_highlighter;
|
||||
QString m_fileName;
|
||||
bool m_new = true;
|
||||
QList<QWidget*> m_editors;
|
||||
|
||||
void setFileName(const QString &filename);
|
||||
bool saveSqlTo(const QString &filename);
|
||||
QString promptUserForSaveSqlFilename(QWidget *parent);
|
||||
};
|
||||
|
||||
#endif // SQLDOCUMENT_H
|
||||
Loading…
Add table
Add a link
Reference in a new issue