60 lines
1.7 KiB
C++
60 lines
1.7 KiB
C++
#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
|