← Back to team overview

ubuntu-touch-coreapps-reviewers team mailing list archive

[Merge] lp:~mrqtros/ubuntu-docviewer-app/ubuntu-docviewer-app-thread-opt into lp:ubuntu-docviewer-app

 

Roman Shchekin has proposed merging lp:~mrqtros/ubuntu-docviewer-app/ubuntu-docviewer-app-thread-opt into lp:ubuntu-docviewer-app.

Commit message:
Multithreading improved.

Requested reviews:
  Ubuntu Document Viewer Developers (ubuntu-docviewer-dev)

For more details, see:
https://code.launchpad.net/~mrqtros/ubuntu-docviewer-app/ubuntu-docviewer-app-thread-opt/+merge/264076

Multithreading improved.
-- 
Your team Ubuntu Document Viewer Developers is requested to review the proposed merge of lp:~mrqtros/ubuntu-docviewer-app/ubuntu-docviewer-app-thread-opt into lp:ubuntu-docviewer-app.
=== modified file 'src/plugin/poppler-qml-plugin/CMakeLists.txt'
--- src/plugin/poppler-qml-plugin/CMakeLists.txt	2015-04-15 14:47:28 +0000
+++ src/plugin/poppler-qml-plugin/CMakeLists.txt	2015-07-07 21:33:49 +0000
@@ -11,7 +11,6 @@
     plugin.cpp
     pdfdocument.cpp
     pdfimageprovider.cpp
-    pdfthread.cpp
     pdfitem.cpp
     verticalview.cpp
     pdftocmodel.cpp
@@ -23,7 +22,7 @@
 
 target_link_libraries(popplerqmlplugin poppler-qt5)
 
-qt5_use_modules(popplerqmlplugin Gui Qml Quick Xml)
+qt5_use_modules(popplerqmlplugin Gui Qml Quick Xml Concurrent)
 
 # Copy the plugin, the qmldir file and other assets to the build dir for running in QtCreator
 if(NOT "${CMAKE_CURRENT_SOURCE_DIR}" STREQUAL "${CMAKE_CURRENT_BINARY_DIR}")

=== modified file 'src/plugin/poppler-qml-plugin/pdfdocument.cpp'
--- src/plugin/poppler-qml-plugin/pdfdocument.cpp	2015-03-25 16:51:53 +0000
+++ src/plugin/poppler-qml-plugin/pdfdocument.cpp	2015-07-07 21:33:49 +0000
@@ -19,13 +19,13 @@
 
 #include "pdfdocument.h"
 #include "pdfimageprovider.h"
-#include "pdfthread.h"
 
 #include <poppler/qt5/poppler-qt5.h>
 #include <QDebug>
 #include <QQmlEngine>
 #include <QQmlContext>
-#include <QThread>
+
+#include <QtConcurrent/QtConcurrent>
 
 PdfDocument::PdfDocument(QAbstractListModel *parent):
     QAbstractListModel(parent)
@@ -145,12 +145,15 @@
     if (!m_document)
         return false;
 
-    PdfThread *pdfThread = new PdfThread();
-    pdfThread->setDocument(m_document);
-
-    connect(pdfThread, SIGNAL(resultReady(PdfPagesList)), this, SLOT(_q_populate(PdfPagesList)));
-    connect(pdfThread, SIGNAL(finished()), pdfThread, SLOT(deleteLater()));
-    pdfThread->start();
+    Poppler::Document* document = m_document;
+    QtConcurrent::run( [=] {
+        PdfPagesList pages;
+
+        for( int i = 0; i < document->numPages(); ++i )
+            pages.append(document->page(i));
+
+        QMetaObject::invokeMethod(this, "_q_populate", Qt::QueuedConnection, Q_ARG(PdfPagesList, pages));
+    });
 
     return true;
 }

=== removed file 'src/plugin/poppler-qml-plugin/pdfthread.cpp'
--- src/plugin/poppler-qml-plugin/pdfthread.cpp	2015-01-30 18:42:00 +0000
+++ src/plugin/poppler-qml-plugin/pdfthread.cpp	1970-01-01 00:00:00 +0000
@@ -1,35 +0,0 @@
-/*
- * Copyright (C) 2014 Canonical, Ltd.
- *
- * This program is free software: you can redistribute it and/or modify it
- * under the terms of the GNU General Public License version 3, as published
- * by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranties of
- * MERCHANTABILITY, SATISFACTORY QUALITY, 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/>.
- *
- * Author: Stefano Verzegnassi <stefano92.100@xxxxxxxxx>
- */
-
-#include "pdfthread.h"
-#include <QDebug>
-
-void PdfThread::run()
-{
-    PdfPagesList pages;
-
-    for( int i=0; i<m_document->numPages(); i++ )
-        pages.append(m_document->page(i));
-
-    Q_EMIT resultReady(pages);
-}
-
-void PdfThread::setDocument(Poppler::Document *document)
-{
-    m_document = document;
-}

=== removed file 'src/plugin/poppler-qml-plugin/pdfthread.h'
--- src/plugin/poppler-qml-plugin/pdfthread.h	2015-01-30 18:42:00 +0000
+++ src/plugin/poppler-qml-plugin/pdfthread.h	1970-01-01 00:00:00 +0000
@@ -1,42 +0,0 @@
-/*
- * Copyright (C) 2014-2015 Canonical, Ltd.
- *
- * This program is free software: you can redistribute it and/or modify it
- * under the terms of the GNU General Public License version 3, as published
- * by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranties of
- * MERCHANTABILITY, SATISFACTORY QUALITY, 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/>.
- *
- * Author: Stefano Verzegnassi <stefano92.100@xxxxxxxxx>
- */
-
-#ifndef PDFTHREAD_H
-#define PDFTHREAD_H
-
-#include <QThread>
-#include <poppler/qt5/poppler-qt5.h>
-
-typedef QList<Poppler::Page*> PdfPagesList;
-
-class PdfThread : public QThread
-{
-    Q_OBJECT
-
-public:
-    void run();
-    void setDocument(Poppler::Document *document);
-
-Q_SIGNALS:
-    void resultReady(PdfPagesList pages);
-
-private:
-    Poppler::Document *m_document;
-};
-
-#endif // PDFTHREAD_H


Follow ups