From 1364120d319702b52f827d6ee1e5034f51eea3cb Mon Sep 17 00:00:00 2001 From: Michael Bohlender Date: Tue, 12 Sep 2017 11:20:44 +0200 Subject: remove file loading/saving related code from documenthandler --- framework/src/domain/documenthandler.cpp | 72 -------------------------------- framework/src/domain/documenthandler.h | 17 -------- 2 files changed, 89 deletions(-) (limited to 'framework') diff --git a/framework/src/domain/documenthandler.cpp b/framework/src/domain/documenthandler.cpp index 25a83592..1a323d9f 100644 --- a/framework/src/domain/documenthandler.cpp +++ b/framework/src/domain/documenthandler.cpp @@ -256,78 +256,6 @@ void DocumentHandler::setFontSize(int size) emit fontSizeChanged(); } -QString DocumentHandler::fileName() const -{ - const QString filePath = QQmlFile::urlToLocalFileOrQrc(m_fileUrl); - const QString fileName = QFileInfo(filePath).fileName(); - if (fileName.isEmpty()) - return QStringLiteral("untitled.txt"); - return fileName; -} - -QString DocumentHandler::fileType() const -{ - return QFileInfo(fileName()).suffix(); -} - -QUrl DocumentHandler::fileUrl() const -{ - return m_fileUrl; -} - -void DocumentHandler::load(const QUrl &fileUrl) -{ - if (fileUrl == m_fileUrl) - return; - - QQmlEngine *engine = qmlEngine(this); - if (!engine) { - qWarning() << "load() called before DocumentHandler has QQmlEngine"; - return; - } - - const QUrl path = QQmlFileSelector::get(engine)->selector()->select(fileUrl); - const QString fileName = QQmlFile::urlToLocalFileOrQrc(path); - if (QFile::exists(fileName)) { - QFile file(fileName); - if (file.open(QFile::ReadOnly)) { - QByteArray data = file.readAll(); - QTextCodec *codec = QTextCodec::codecForHtml(data); - if (QTextDocument *doc = textDocument()) - doc->setModified(false); - - emit loaded(codec->toUnicode(data)); - reset(); - } - } - - m_fileUrl = fileUrl; - emit fileUrlChanged(); -} - -void DocumentHandler::saveAs(const QUrl &fileUrl) -{ - QTextDocument *doc = textDocument(); - if (!doc) - return; - - const QString filePath = fileUrl.toLocalFile(); - const bool isHtml = QFileInfo(filePath).suffix().contains(QLatin1String("htm")); - QFile file(filePath); - if (!file.open(QFile::WriteOnly | QFile::Truncate | (isHtml ? QFile::NotOpen : QFile::Text))) { - emit error(tr("Cannot save: ") + file.errorString()); - return; - } - file.write((isHtml ? doc->toHtml() : doc->toPlainText()).toUtf8()); - file.close(); - - if (fileUrl == m_fileUrl) - return; - - m_fileUrl = fileUrl; - emit fileUrlChanged(); -} - void DocumentHandler::reset() { emit fontFamilyChanged(); diff --git a/framework/src/domain/documenthandler.h b/framework/src/domain/documenthandler.h index a6125bc3..74b7c4f9 100644 --- a/framework/src/domain/documenthandler.h +++ b/framework/src/domain/documenthandler.h @@ -80,10 +80,6 @@ class DocumentHandler : public QObject Q_PROPERTY(int fontSize READ fontSize WRITE setFontSize NOTIFY fontSizeChanged) - Q_PROPERTY(QString fileName READ fileName NOTIFY fileUrlChanged) - Q_PROPERTY(QString fileType READ fileType NOTIFY fileUrlChanged) - Q_PROPERTY(QUrl fileUrl READ fileUrl NOTIFY fileUrlChanged) - public: explicit DocumentHandler(QObject *parent = nullptr); @@ -120,14 +116,6 @@ public: int fontSize() const; void setFontSize(int size); - QString fileName() const; - QString fileType() const; - QUrl fileUrl() const; - -public Q_SLOTS: - void load(const QUrl &fileUrl); - void saveAs(const QUrl &fileUrl); - Q_SIGNALS: void documentChanged(); void cursorPositionChanged(); @@ -145,10 +133,6 @@ Q_SIGNALS: void fontSizeChanged(); void textChanged(); - void fileUrlChanged(); - - void loaded(const QString &text); - void error(const QString &message); private: void reset(); @@ -164,7 +148,6 @@ private: QFont m_font; int m_fontSize; - QUrl m_fileUrl; }; #endif // DOCUMENTHANDLER_H -- cgit v1.2.3