summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlbert Astals Cid <aacid@kde.org>2014-08-09 18:44:25 (GMT)
committerAlbert Astals Cid <aacid@kde.org>2014-08-09 18:44:25 (GMT)
commitefbde6600927ef41df5b7e139048202205d50404 (patch)
tree552abfca57415642a05733d8632fd74a54e83de0
parent20d687cac5d28b42afcb107bb5fe8e380b6a7dbf (diff)
Port to new threadweaver
Not sure it works at all, but at least it compiles ^_^
-rw-r--r--core/pagecontroller.cpp13
-rw-r--r--core/pagecontroller_p.h9
-rw-r--r--core/rotationjob.cpp52
-rw-r--r--core/rotationjob_p.h38
4 files changed, 67 insertions, 45 deletions
diff --git a/core/pagecontroller.cpp b/core/pagecontroller.cpp
index 44258a6..18848f2 100644
--- a/core/pagecontroller.cpp
+++ b/core/pagecontroller.cpp
@@ -11,12 +11,13 @@
// qt/kde includes
#include <kglobal.h>
-#include <threadweaver/threadweaver.h>
// local includes
#include "page_p.h"
#include "rotationjob_p.h"
+#include <threadweaver/queueing.h>
+
using namespace Okular;
PageController::PageController()
@@ -30,14 +31,14 @@ PageController::~PageController()
void PageController::addRotationJob(RotationJob *job)
{
- connect( job, SIGNAL(done(ThreadWeaver::Job*)),
- this, SLOT(imageRotationDone(ThreadWeaver::Job*)) );
- ThreadWeaver::Weaver::instance()->enqueue(job);
+ connect( job, SIGNAL(done(ThreadWeaver::JobPointer)),
+ this, SLOT(imageRotationDone(ThreadWeaver::JobPointer)) );
+ ThreadWeaver::enqueue(&m_weaver, job);
}
-void PageController::imageRotationDone(ThreadWeaver::Job *j)
+void PageController::imageRotationDone(const ThreadWeaver::JobPointer &j)
{
- RotationJob *job = static_cast< RotationJob * >( j );
+ RotationJob *job = static_cast< RotationJob * >( j.data() );
if ( job->page() )
{
diff --git a/core/pagecontroller_p.h b/core/pagecontroller_p.h
index 55fe7bf..56b63b2 100644
--- a/core/pagecontroller_p.h
+++ b/core/pagecontroller_p.h
@@ -12,9 +12,7 @@
#include <QtCore/QObject>
-namespace ThreadWeaver {
- class Job;
-}
+#include <threadweaver/queue.h>
namespace Okular {
@@ -37,7 +35,10 @@ class PageController : public QObject
void rotationFinished( int page, Okular::Page *okularPage );
private slots:
- void imageRotationDone(ThreadWeaver::Job*);
+ void imageRotationDone(const ThreadWeaver::JobPointer &job);
+
+ private:
+ ThreadWeaver::Queue m_weaver;
};
}
diff --git a/core/rotationjob.cpp b/core/rotationjob.cpp
index 898bc92..cf4cc09 100644
--- a/core/rotationjob.cpp
+++ b/core/rotationjob.cpp
@@ -14,7 +14,8 @@
using namespace Okular;
RotationJob::RotationJob( const QImage &image, Rotation oldRotation, Rotation newRotation, DocumentObserver *observer )
- : mImage( image ), mOldRotation( oldRotation ), mNewRotation( newRotation ), mObserver( observer ), m_pd( 0 )
+ : ThreadWeaver::QObjectDecorator( new RotationJobInternal( image, oldRotation, newRotation ) )
+ , mObserver( observer ), m_pd( 0 )
, mRect( NormalizedRect() )
{
}
@@ -29,16 +30,6 @@ void RotationJob::setRect( const NormalizedRect &rect )
mRect = rect;
}
-QImage RotationJob::image() const
-{
- return mRotatedImage;
-}
-
-Rotation RotationJob::rotation() const
-{
- return mNewRotation;
-}
-
DocumentObserver * RotationJob::observer() const
{
return mObserver;
@@ -54,18 +45,6 @@ NormalizedRect RotationJob::rect() const
return mRect;
}
-void RotationJob::run()
-{
- if ( mOldRotation == mNewRotation ) {
- mRotatedImage = mImage;
- return;
- }
-
- QTransform matrix = rotationMatrix( mOldRotation, mNewRotation );
-
- mRotatedImage = mImage.transformed( matrix );
-}
-
QTransform RotationJob::rotationMatrix( Rotation from, Rotation to )
{
QTransform matrix;
@@ -103,4 +82,31 @@ QTransform RotationJob::rotationMatrix( Rotation from, Rotation to )
return matrix;
}
+RotationJobInternal::RotationJobInternal( const QImage &image, Rotation oldRotation, Rotation newRotation )
+ : mImage( image ), mOldRotation( oldRotation ), mNewRotation( newRotation )
+{
+}
+
+QImage RotationJobInternal::image() const
+{
+ return mRotatedImage;
+}
+
+Rotation RotationJobInternal::rotation() const
+{
+ return mNewRotation;
+}
+
+void RotationJobInternal::run(ThreadWeaver::JobPointer self, ThreadWeaver::Thread *thread)
+{
+ if ( mOldRotation == mNewRotation ) {
+ mRotatedImage = mImage;
+ return;
+ }
+
+ const QTransform matrix = RotationJob::rotationMatrix( mOldRotation, mNewRotation );
+
+ mRotatedImage = mImage.transformed( matrix );
+}
+
#include "moc_rotationjob_p.cpp"
diff --git a/core/rotationjob_p.h b/core/rotationjob_p.h
index ee27793..dc1712b 100644
--- a/core/rotationjob_p.h
+++ b/core/rotationjob_p.h
@@ -13,7 +13,8 @@
#include <QtGui/QImage>
#include <QtGui/QTransform>
-#include <threadweaver/Job.h>
+#include <threadweaver/qobjectdecorator.h>
+#include <threadweaver/job.h>
#include "core/global.h"
#include "core/area.h"
@@ -23,33 +24,46 @@ namespace Okular {
class DocumentObserver;
class PagePrivate;
-class RotationJob : public ThreadWeaver::Job
+class RotationJobInternal : public ThreadWeaver::Job
{
- Q_OBJECT
+ friend class RotationJob;
+
+ public:
+ QImage image() const;
+ Rotation rotation() const;
+ NormalizedRect rect() const;
+
+ protected:
+ void run(ThreadWeaver::JobPointer self, ThreadWeaver::Thread *thread) Q_DECL_OVERRIDE;
+
+ private:
+ RotationJobInternal( const QImage &image, Rotation oldRotation, Rotation newRotation );
+
+ const QImage mImage;
+ Rotation mOldRotation;
+ Rotation mNewRotation;
+ QImage mRotatedImage;
+};
+class RotationJob : public ThreadWeaver::QObjectDecorator
+{
+ Q_OBJECT
public:
RotationJob( const QImage &image, Rotation oldRotation, Rotation newRotation, DocumentObserver *observer );
void setPage( PagePrivate * pd );
void setRect( const NormalizedRect &rect );
- QImage image() const;
- Rotation rotation() const;
+ QImage image() const { return static_cast<const RotationJobInternal*>(job())->image(); }
+ Rotation rotation() const { return static_cast<const RotationJobInternal*>(job())->rotation(); }
DocumentObserver *observer() const;
PagePrivate * page() const;
NormalizedRect rect() const;
static QTransform rotationMatrix( Rotation from, Rotation to );
- protected:
- virtual void run();
-
private:
- const QImage mImage;
- Rotation mOldRotation;
- Rotation mNewRotation;
DocumentObserver *mObserver;
- QImage mRotatedImage;
PagePrivate * m_pd;
NormalizedRect mRect;
};