Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Utilities
Kate
Commits
a9e4fa4e
Commit
a9e4fa4e
authored
Jan 21, 2021
by
Christoph Cullmann
🐮
Browse files
simplify threading of project's plugin
QRunnable is enough, we use no advanced ThreadWeaver feature
parent
879e3b9a
Changes
7
Hide whitespace changes
Inline
Side-by-side
addons/project/CMakeLists.txt
View file @
a9e4fa4e
...
...
@@ -4,12 +4,10 @@ find_package(
COMPONENTS
GuiAddons
NewStuff
ThreadWeaver
)
set_package_properties
(
KFGuiAddons PROPERTIES PURPOSE
"Required to build the project addon"
)
set_package_properties
(
KF5NewStuff PROPERTIES PURPOSE
"Required to build the project addon"
)
set_package_properties
(
KF5ThreadWeaver PROPERTIES PURPOSE
"Required to build the project addon"
)
if
(
NOT KF5_FOUND
)
return
()
...
...
@@ -19,12 +17,11 @@ add_library(kateprojectplugin MODULE "")
target_compile_definitions
(
kateprojectplugin PRIVATE TRANSLATION_DOMAIN=
"kateproject"
)
target_link_libraries
(
kateprojectplugin
kateprojectplugin
PRIVATE
KF5::GuiAddons
KF5::NewStuff
KF5::TextEditor
KF5::ThreadWeaver
)
target_include_directories
(
...
...
@@ -41,7 +38,7 @@ if(HAVE_CTERMID)
endif
()
target_sources
(
kateprojectplugin
kateprojectplugin
PRIVATE
fileutil.cpp
kateprojectplugin.cpp
...
...
addons/project/kateproject.cpp
View file @
a9e4fa4e
...
...
@@ -13,8 +13,6 @@
#include <ktexteditor/document.h>
#include <ThreadWeaver/Queue>
#include <QDir>
#include <QFile>
#include <QFileInfo>
...
...
@@ -25,10 +23,10 @@
#include <QPlainTextDocumentLayout>
#include <utility>
KateProject
::
KateProject
(
Thread
Weaver
::
Queue
*
weaver
,
KateProjectPlugin
*
plugin
)
KateProject
::
KateProject
(
Q
Thread
Pool
&
threadPool
,
KateProjectPlugin
*
plugin
)
:
m_notesDocument
(
nullptr
)
,
m_untrackedDocumentsRoot
(
nullptr
)
,
m_
weaver
(
weaver
)
,
m_
threadPool
(
threadPool
)
,
m_plugin
(
plugin
)
{
}
...
...
@@ -170,10 +168,12 @@ bool KateProject::load(const QVariantMap &globalProject, bool force)
indexDir
=
QDir
::
tempPath
();
}
}
// let's run the stuff in our own thread pool
auto
w
=
new
KateProjectWorker
(
m_baseDir
,
indexDir
,
m_projectMap
,
force
);
connect
(
w
,
&
KateProjectWorker
::
loadDone
,
this
,
&
KateProject
::
loadProjectDone
);
connect
(
w
,
&
KateProjectWorker
::
loadIndexDone
,
this
,
&
KateProject
::
loadIndexDone
);
m_
weaver
->
stream
()
<<
w
;
m_
threadPool
.
start
(
w
)
;
// we are done here
return
true
;
...
...
addons/project/kateproject.h
View file @
a9e4fa4e
...
...
@@ -29,12 +29,8 @@ Q_DECLARE_METATYPE(KateProjectSharedQMapStringItem)
typedef
QSharedPointer
<
KateProjectIndex
>
KateProjectSharedProjectIndex
;
Q_DECLARE_METATYPE
(
KateProjectSharedProjectIndex
)
namespace
ThreadWeaver
{
class
Queue
;
}
class
KateProjectPlugin
;
class
QThreadPool
;
/**
* Class representing a project.
...
...
@@ -48,7 +44,7 @@ public:
/**
* construct empty project
*/
KateProject
(
Thread
Weaver
::
Queue
*
weaver
,
KateProjectPlugin
*
plugin
);
KateProject
(
Q
Thread
Pool
&
threadPool
,
KateProjectPlugin
*
plugin
);
/**
* deconstruct project
...
...
@@ -290,7 +286,10 @@ private:
*/
QStandardItem
*
m_untrackedDocumentsRoot
;
ThreadWeaver
::
Queue
*
m_weaver
;
/**
* thread pool used for project worker
*/
QThreadPool
&
m_threadPool
;
/**
* project configuration (read from file or injected)
...
...
addons/project/kateprojectplugin.cpp
View file @
a9e4fa4e
...
...
@@ -17,7 +17,6 @@
#include <KConfigGroup>
#include <KLocalizedString>
#include <KSharedConfig>
#include <ThreadWeaver/Queue>
#include <QFileInfo>
#include <QTime>
...
...
@@ -55,7 +54,6 @@ KateProjectPlugin::KateProjectPlugin(QObject *parent, const QList<QVariant> &)
,
m_indexEnabled
(
false
)
,
m_multiProjectCompletion
(
false
)
,
m_multiProjectGoto
(
false
)
,
m_weaver
(
new
ThreadWeaver
::
Queue
(
this
))
{
qRegisterMetaType
<
KateProjectSharedQStandardItem
>
(
"KateProjectSharedQStandardItem"
);
qRegisterMetaType
<
KateProjectSharedQMapStringItem
>
(
"KateProjectSharedQMapStringItem"
);
...
...
@@ -98,9 +96,6 @@ KateProjectPlugin::~KateProjectPlugin()
delete
project
;
}
m_projects
.
clear
();
m_weaver
->
shutDown
();
delete
m_weaver
;
}
QObject
*
KateProjectPlugin
::
createView
(
KTextEditor
::
MainWindow
*
mainWindow
)
...
...
@@ -123,7 +118,7 @@ KTextEditor::ConfigPage *KateProjectPlugin::configPage(int number, QWidget *pare
KateProject
*
KateProjectPlugin
::
createProjectForFileName
(
const
QString
&
fileName
)
{
KateProject
*
project
=
new
KateProject
(
m_
weaver
,
this
);
KateProject
*
project
=
new
KateProject
(
m_
threadPool
,
this
);
if
(
!
project
->
loadFromFile
(
fileName
))
{
delete
project
;
return
nullptr
;
...
...
@@ -282,7 +277,7 @@ KateProject *KateProjectPlugin::createProjectForRepository(const QString &type,
cnf
[
QStringLiteral
(
"name"
)]
=
dir
.
dirName
();
cnf
[
QStringLiteral
(
"files"
)]
=
(
QVariantList
()
<<
files
);
KateProject
*
project
=
new
KateProject
(
m_
weaver
,
this
);
KateProject
*
project
=
new
KateProject
(
m_
threadPool
,
this
);
project
->
loadFromData
(
cnf
,
dir
.
canonicalPath
());
m_projects
.
append
(
project
);
...
...
addons/project/kateprojectplugin.h
View file @
a9e4fa4e
...
...
@@ -10,6 +10,7 @@
#include <QDir>
#include <QFileSystemWatcher>
#include <QThreadPool>
#include <KTextEditor/Plugin>
#include <ktexteditor/document.h>
...
...
@@ -20,11 +21,6 @@
#include "kateproject.h"
#include "kateprojectcompletion.h"
namespace
ThreadWeaver
{
class
Queue
;
}
class
KateProjectPlugin
:
public
KTextEditor
::
Plugin
{
Q_OBJECT
...
...
@@ -184,7 +180,11 @@ private:
bool
m_multiProjectGoto
:
1
;
QUrl
m_indexDirectory
;
ThreadWeaver
::
Queue
*
m_weaver
;
/**
* thread pool for our workers
*/
QThreadPool
m_threadPool
;
};
#endif
addons/project/kateprojectworker.cpp
View file @
a9e4fa4e
...
...
@@ -16,6 +16,7 @@
#include <QSet>
#include <QSettings>
#include <QTime>
#include <QThread>
KateProjectWorker
::
KateProjectWorker
(
const
QString
&
baseDir
,
const
QString
&
indexDir
,
const
QVariantMap
&
projectMap
,
bool
force
)
:
m_baseDir
(
baseDir
)
...
...
@@ -26,7 +27,7 @@ KateProjectWorker::KateProjectWorker(const QString &baseDir, const QString &inde
Q_ASSERT
(
!
m_baseDir
.
isEmpty
());
}
void
KateProjectWorker
::
run
(
ThreadWeaver
::
JobPointer
,
ThreadWeaver
::
Thread
*
)
void
KateProjectWorker
::
run
()
{
/**
* Create dummy top level parent item and empty map inside shared pointers
...
...
addons/project/kateprojectworker.h
View file @
a9e4fa4e
...
...
@@ -11,9 +11,8 @@
#include "kateproject.h"
#include "kateprojectitem.h"
#include <ThreadWeaver/Job>
#include <QMap>
#include <QRunnable>
#include <QStandardItemModel>
class
QDir
;
...
...
@@ -22,7 +21,7 @@ class QDir;
* 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
KateProjectWorker
:
public
QObject
,
public
ThreadWeaver
::
Job
class
KateProjectWorker
:
public
QObject
,
public
QRunnable
{
Q_OBJECT
...
...
@@ -34,7 +33,7 @@ public:
explicit
KateProjectWorker
(
const
QString
&
baseDir
,
const
QString
&
indexDir
,
const
QVariantMap
&
projectMap
,
bool
force
);
void
run
(
ThreadWeaver
::
JobPointer
self
,
ThreadWeaver
::
Thread
*
thread
)
override
;
void
run
()
override
;
Q_SIGNALS:
void
loadDone
(
KateProjectSharedQStandardItem
topLevel
,
KateProjectSharedQMapStringItem
file2Item
);
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment