-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdocumenthandler.cpp
More file actions
43 lines (38 loc) · 896 Bytes
/
documenthandler.cpp
File metadata and controls
43 lines (38 loc) · 896 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#include "documenthandler.h"
#include <QFileDialog>
#include <QFile>
#include <QTextStream>
#include <QQmlEngine>
#include <QUrl>
//#include "highlighter.h"
DocumentHandler::DocumentHandler(QObject *parent)
: QObject(parent)
{
}
void DocumentHandler::openFile(const QString& path)
{
QUrl url(path);
QFile file(url.toLocalFile());
if (!file.open(QIODevice::ReadOnly | QIODevice::Text))
return;
QTextStream stream(&file);
auto text = stream.readAll();
setText(text);
file.close();
}
// void DocumentHandler::setDocument(QQuickTextDocument* document)
// {
// auto highlighter = new Highlighter(document->textDocument());
// Q_UNUSED(highlighter)
// }
QString DocumentHandler::text() const
{
return m_text;
}
void DocumentHandler::setText(QString text)
{
if (m_text != text) {
m_text = text;
emit textChanged(text);
}
}