Commit aae03193 authored by Christoph Cullmann's avatar Christoph Cullmann

use more 'modern' worker object approach

parent 3cf52412
......@@ -9,7 +9,7 @@ if (NOT QJSON_FOUND)
return()
endif (NOT QJSON_FOUND)
set(kateprojectplugin_PART_SRCS plugin_kateproject.cpp kateproject.cpp kateprojectthread.cpp kateprojectitem.cpp kateprojectview.cpp kateprojectpluginview.cpp)
set(kateprojectplugin_PART_SRCS plugin_kateproject.cpp kateproject.cpp kateprojectworker.cpp kateprojectitem.cpp kateprojectview.cpp kateprojectpluginview.cpp)
kde4_add_plugin(kateprojectplugin ${kateprojectplugin_PART_SRCS})
......
......@@ -19,7 +19,7 @@
*/
#include "kateproject.h"
#include "kateprojectthread.h"
#include "kateprojectworker.h"
#include <QDir>
#include <QDirIterator>
......@@ -34,23 +34,28 @@
KateProject::KateProject ()
: QObject ()
, m_thread (new KateProjectThread (this))
, m_worker (new KateProjectWorker (this))
, m_model (new QStandardItemModel (this))
{
/**
* start our worker thread
* move worker object over and start our worker thread
*/
m_thread->start ();
m_worker->moveToThread (&m_thread);
m_thread.start ();
}
KateProject::~KateProject ()
{
/**
* quit the thread event loop, wait for completion and delete it
* quit the thread event loop and wait for completion
*/
m_thread->quit ();
m_thread->wait ();
delete m_thread;
m_thread.quit ();
m_thread.wait ();
/**
* delete worker, before thread is deleted
*/
delete m_worker;
}
bool KateProject::load (const QString &fileName)
......
......@@ -21,7 +21,7 @@
#ifndef KATE_PROJECT_H
#define KATE_PROJECT_H
#include <QObject>
#include <QThread>
#include <QStandardItemModel>
#include <QMap>
......@@ -135,7 +135,12 @@ class KateProject : public QObject
/**
* our internal thread to load stuff and do things in background
*/
class KateProjectThread *m_thread;
QThread m_thread;
/**
* the worker inside the background thread
*/
class KateProjectWorker *m_worker;
/**
* project file name
......
......@@ -18,24 +18,16 @@
* Boston, MA 02110-1301, USA.
*/
#include "kateprojectthread.h"
#include "kateprojectworker.h"
KateProjectThread::KateProjectThread (KateProject *project)
: QThread ()
KateProjectWorker::KateProjectWorker (KateProject *project)
: QObject ()
, m_project (project)
{
}
KateProjectThread::~KateProjectThread ()
KateProjectWorker::~KateProjectWorker ()
{
}
void KateProjectThread::run ()
{
/**
* execute event loop
*/
exec ();
}
// kate: space-indent on; indent-width 2; replace-tabs on;
......@@ -18,38 +18,32 @@
* Boston, MA 02110-1301, USA.
*/
#ifndef KATE_PROJECT_THREAD_H
#define KATE_PROJECT_THREAD_H
#ifndef KATE_PROJECT_WORKER_H
#define KATE_PROJECT_WORKER_H
#include <QThread>
#include <QObject>
#include "kateproject.h"
/**
* Class representing a project background thread.
* This thread will build up the model for the project on load and do other stuff in the background.
* Class representing a project background worker.
* This worker will build up the model for the project on load and do other stuff in the background.
*/
class KateProjectThread : public QThread
class KateProjectWorker : public QObject
{
Q_OBJECT
public:
/**
* construct project thread for given project
* construct project worker for given project
* @param project our project
*/
KateProjectThread (KateProject *project);
KateProjectWorker (KateProject *project);
/**
* deconstruct project
* deconstruct worker
*/
~KateProjectThread ();
protected:
/**
* Overwritten run method
*/
void run ();
~KateProjectWorker ();
private:
/**
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment