digiKam
Loading...
Searching...
No Matches
actionthreadbase.h
Go to the documentation of this file.
1/* ============================================================
2 *
3 * This file is a part of digiKam project
4 * https://www.digikam.org
5 *
6 * Date : 2011-12-28
7 * Description : Low level threads management for batch processing on multi-core
8 *
9 * SPDX-FileCopyrightText: 2011-2024 by Gilles Caulier <caulier dot gilles at gmail dot com>
10 * SPDX-FileCopyrightText: 2014 by Veaceslav Munteanu <veaceslav dot munteanu90 at gmail dot com>
11 * SPDX-FileCopyrightText: 2011-2012 by Janardhan Reddy <annapareddyjanardhanreddy at gmail dot com>
12 *
13 * SPDX-License-Identifier: GPL-2.0-or-later
14 *
15 * ============================================================ */
16
17#pragma once
18
19// Qt includes
20
21#include <QHash>
22#include <QObject>
23#include <QThread>
24#include <QRunnable>
25#include <QElapsedTimer>
26
27// Local includes
28
29#include "digikam_export.h"
30
31namespace Digikam
32{
33
34class DIGIKAM_EXPORT ActionJob : public QObject,
35 public QRunnable
36{
37 Q_OBJECT
38
39public:
40
44 explicit ActionJob(QObject* const parent = nullptr);
45
49 ~ActionJob() override;
50
51Q_SIGNALS:
52
57
61 void signalProgress(int);
62
66 void signalDone();
67
68public Q_SLOTS:
69
73 void cancel();
74
75public:
76
80 QElapsedTimer m_timer;
81
82protected:
83
87 bool m_cancel = false;
88};
89
95typedef QHash<ActionJob*, int> ActionJobCollection;
96
97// -------------------------------------------------------------------------------------------------------
98
99class DIGIKAM_EXPORT ActionThreadBase : public QThread
100{
101 Q_OBJECT
102
103public:
104
105 explicit ActionThreadBase(QObject* const parent = nullptr);
106 ~ActionThreadBase() override;
107
111 void setMaximumNumberOfThreads(int n);
112
116 int maximumNumberOfThreads() const;
117
122 void setDefaultMaximumNumberOfThreads();
123
127 void cancel(bool isCancel = true);
128
129protected:
130
134 void run() override;
135
140 void appendJobs(const ActionJobCollection& jobs);
141
145 bool isEmpty() const;
146
150 int pendingCount() const;
151
152protected Q_SLOTS:
153
154 void slotJobFinished();
155
156private:
157
158 class Private;
159 Private* const d = nullptr;
160};
161
162} // namespace Digikam
Definition actionthreadbase.h:36
void signalProgress(int)
QElapsedTimer m_timer
Definition actionthreadbase.h:80
Definition actionthreadbase.h:100
Definition datefolderview.cpp:34
QHash< ActionJob *, int > ActionJobCollection
Definition actionthreadbase.h:95