digiKam
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  * Copyright (C) 2011-2022 by Gilles Caulier <caulier dot gilles at gmail dot com>
10  * Copyright (C) 2014 by Veaceslav Munteanu <veaceslav dot munteanu90 at gmail dot com>
11  * Copyright (C) 2011-2012 by Janardhan Reddy <annapareddyjanardhanreddy at gmail dot com>
12  *
13  * This program is free software; you can redistribute it
14  * and/or modify it under the terms of the GNU General
15  * Public License as published by the Free Software Foundation;
16  * either version 2, or (at your option)
17  * any later version.
18  *
19  * This program is distributed in the hope that it will be useful,
20  * but WITHOUT ANY WARRANTY; without even the implied warranty of
21  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22  * GNU General Public License for more details.
23  *
24  * ============================================================ */
25 
26 #ifndef DIGIKAM_ACTION_THREAD_BASE_H
27 #define DIGIKAM_ACTION_THREAD_BASE_H
28 
29 // Qt includes
30 
31 #include <QHash>
32 #include <QObject>
33 #include <QThread>
34 #include <QRunnable>
35 
36 // Local includes
37 
38 #include "digikam_export.h"
39 
40 namespace Digikam
41 {
42 
43 class DIGIKAM_EXPORT ActionJob : public QObject,
44  public QRunnable
45 {
46  Q_OBJECT
47 
48 public:
49 
53  explicit ActionJob(QObject* const parent = nullptr);
54 
58  ~ActionJob() override;
59 
60 Q_SIGNALS:
61 
65  void signalStarted();
66 
70  void signalProgress(int);
71 
75  void signalDone();
76 
77 public Q_SLOTS:
78 
82  void cancel();
83 
84 protected:
85 
89  bool m_cancel;
90 };
91 
97 typedef QHash<ActionJob*, int> ActionJobCollection;
98 
99 // -------------------------------------------------------------------------------------------------------
100 
101 class DIGIKAM_EXPORT ActionThreadBase : public QThread
102 {
103  Q_OBJECT
104 
105 public:
106 
107  explicit ActionThreadBase(QObject* const parent = nullptr);
108  ~ActionThreadBase() override;
109 
113  void setMaximumNumberOfThreads(int n);
114 
118  int maximumNumberOfThreads() const;
119 
124  void setDefaultMaximumNumberOfThreads();
125 
129  void cancel();
130 
131 protected:
132 
136  void run() override;
137 
142  void appendJobs(const ActionJobCollection& jobs);
143 
147  bool isEmpty() const;
148 
152  int pendingCount() const;
153 
154 protected Q_SLOTS:
155 
156  void slotJobFinished();
157 
158 private:
159 
160  class Private;
161  Private* const d;
162 };
163 
164 } // namespace Digikam
165 
166 #endif // DIGIKAM_ACTION_THREAD_BASE_H
Definition: actionthreadbase.h:45
void signalProgress(int)
bool m_cancel
Definition: actionthreadbase.h:89
Definition: actionthreadbase.h:102
Definition: datefolderview.cpp:43
QHash< ActionJob *, int > ActionJobCollection
Definition: actionthreadbase.h:97