-
Notifications
You must be signed in to change notification settings - Fork 68
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: support multi-thraded read fiels.
Change-Id: I50e15a805a1ba2e8f211d591f0ef5b51be21880e
- Loading branch information
rekols
committed
Aug 28, 2018
1 parent
456230b
commit d4de743
Showing
8 changed files
with
140 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
/* | ||
* Copyright (C) 2017 ~ 2018 Deepin Technology Co., Ltd. | ||
* | ||
* Author: rekols <rekols@foxmail.com> | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
#include "fileloadthread.h" | ||
#include "utils.h" | ||
|
||
#include <QCoreApplication> | ||
#include <QPlainTextEdit> | ||
#include <QTextDocument> | ||
#include <QTextStream> | ||
#include <QFile> | ||
|
||
FileLoadThread::FileLoadThread(const QString &filepath, QObject *parent) | ||
: QThread(parent), | ||
m_filePath(filepath) | ||
{ | ||
|
||
} | ||
|
||
FileLoadThread::~FileLoadThread() | ||
{ | ||
} | ||
|
||
void FileLoadThread::run() | ||
{ | ||
QFile file(m_filePath); | ||
|
||
if (file.open(QIODevice::ReadOnly)) { | ||
// reads all remaining data from the file. | ||
QByteArray content = file.readAll(); | ||
|
||
// read the encode. | ||
QByteArray encode = Utils::getFileEncode(content, m_filePath); | ||
|
||
QTextStream stream(&content); | ||
stream.setCodec(encode); | ||
|
||
QTextDocument *doc = new QTextDocument; | ||
doc->moveToThread(QCoreApplication::instance()->thread()); | ||
doc->setPlainText(content); | ||
|
||
emit loadFinished(encode, doc); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/* | ||
* Copyright (C) 2017 ~ 2018 Deepin Technology Co., Ltd. | ||
* | ||
* Author: rekols <rekols@foxmail.com> | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
#ifndef FILELOADTHREAD_H | ||
#define FILELOADTHREAD_H | ||
|
||
#include <QThread> | ||
|
||
class QTextDocument; | ||
class FileLoadThread : public QThread | ||
{ | ||
Q_OBJECT | ||
|
||
public: | ||
FileLoadThread(const QString &filepath, QObject *QObject = nullptr); | ||
~FileLoadThread(); | ||
|
||
void run(); | ||
|
||
signals: | ||
void loadFinished(const QString &encode, QTextDocument *doc); | ||
|
||
private: | ||
QString m_filePath; | ||
}; | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters