digiKam
dimgthreadedfilter.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 : 2005-05-25
7  * Description : threaded image filter class.
8  *
9  * Copyright (C) 2005-2022 by Gilles Caulier <caulier dot gilles at gmail dot com>
10  * Copyright (C) 2007-2012 by Marcel Wiesweg <marcel dot wiesweg at gmx dot de>
11  *
12  * This program is free software; you can redistribute it
13  * and/or modify it under the terms of the GNU General
14  * Public License as published by the Free Software Foundation;
15  * either version 2, or (at your option)
16  * any later version.
17  *
18  * This program is distributed in the hope that it will be useful,
19  * but WITHOUT ANY WARRANTY; without even the implied warranty of
20  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21  * GNU General Public License for more details.
22  *
23  * ============================================================ */
24 
25 #ifndef DIGIKAM_DIMG_THREADED_FILTER_H
26 #define DIGIKAM_DIMG_THREADED_FILTER_H
27 
28 // Local includes
29 
30 #include "digikam_export.h"
31 #include "dimg.h"
32 #include "dynamicthread.h"
33 #include "filteraction.h"
34 
35 class QObject;
36 
37 namespace Digikam
38 {
39 
40 class DIGIKAM_EXPORT DImgThreadedFilter : public DynamicThread
41 {
42  Q_OBJECT
43 
44 public:
45 
52  explicit DImgThreadedFilter(QObject* const parent = nullptr, const QString& name = QString());
53 
60  DImgThreadedFilter(DImg* const orgImage,
61  QObject* const parent,
62  const QString& name = QString());
63 
64  ~DImgThreadedFilter() override;
65 
71  void setupFilter(const DImg& orgImage);
72 
76  void setupAndStartDirectly(const DImg& orgImage,
77  DImgThreadedFilter* const master,
78  int progressBegin = 0,
79  int progressEnd = 100);
80 
81  void setOriginalImage(const DImg& orgImage);
82  void setFilterName(const QString& name);
83 
85  {
86  return m_destImage;
87  };
88 
89  const QString& filterName()
90  {
91  return m_name;
92  };
93 
103  QList<int> multithreadedSteps(int stop, int start = 0) const;
104 
108  virtual void startFilter();
109 
113  virtual void cancelFilter();
114 
118  virtual void startFilterDirectly();
119 
123  virtual FilterAction filterAction() = 0;
124 
125  virtual void readParameters(const FilterAction&) = 0;
126 
130  virtual QString filterIdentifier() const = 0;
131 
132  virtual QList<int> supportedVersions() const;
133 
142  void setFilterVersion(int version);
143  int filterVersion() const;
144 
156  virtual bool parametersSuccessfullyRead() const;
157  virtual QString readParametersError(const FilterAction& actionThatFailed) const;
158 
159 Q_SIGNALS:
160 
164  void started();
165 
169  void progress(int progress);
170 
176  void finished(bool success);
177 
178 protected:
179 
183  virtual void initFilter();
184 
188  void run() override;
189 
193  virtual void filterImage() = 0;
194 
199  virtual void cleanupFilter() {};
200 
204  void postProgress(int progress);
205 
206 protected:
207 
226  const DImg& orgImage,
227  const DImg& destImage,
228  int progressBegin = 0,
229  int progressEnd = 100,
230  const QString& name = QString());
231 
236  void initSlave(DImgThreadedFilter* const master,
237  int progressBegin = 0,
238  int progressEnd = 100);
239 
243  void setSlave(DImgThreadedFilter* const slave);
244 
249  virtual int modulateProgress(int progress);
250 
251  void initMaster();
252  virtual void prepareDestImage();
253 
257  template <class Filter>
258 
260  {
261  public:
262 
264  : FilterAction(Filter::FilterIdentifier(), Filter::CurrentVersion(), category)
265  {
266  setDisplayableName(Filter::DisplayableName());
267  }
268 
269  explicit DefaultFilterAction(bool isReproducible)
270  : FilterAction(Filter::FilterIdentifier(), Filter::CurrentVersion(),
271  isReproducible ? FilterAction::ReproducibleFilter : FilterAction::ComplexFilter)
272  {
273  setDisplayableName(Filter::DisplayableName());
274  }
275 
281  void supportOlderVersionIf(int version, bool condition)
282  {
283  if (condition && (version <= m_version))
284  {
285  m_version = version;
286  }
287  }
288 
289  };
290 
291 protected:
292 
294 
296 
303 
307  QString m_name;
308 
313 
318 
323 
328 };
329 
330 } // namespace Digikam
331 
332 #endif // DIGIKAM_DIMG_THREADED_FILTER_H
Definition: dimgthreadedfilter.h:260
void supportOlderVersionIf(int version, bool condition)
Definition: dimgthreadedfilter.h:281
DefaultFilterAction(bool isReproducible)
Definition: dimgthreadedfilter.h:269
DefaultFilterAction(FilterAction::Category category=FilterAction::ReproducibleFilter)
Definition: dimgthreadedfilter.h:263
Definition: dimgthreadedfilter.h:41
virtual void filterImage()=0
virtual QString filterIdentifier() const =0
DImg getTargetImage()
Definition: dimgthreadedfilter.h:84
virtual void cleanupFilter()
Definition: dimgthreadedfilter.h:199
bool m_wasCancelled
Definition: dimgthreadedfilter.h:295
DImg m_orgImage
Definition: dimgthreadedfilter.h:312
virtual FilterAction filterAction()=0
int m_version
Definition: dimgthreadedfilter.h:293
void progress(int progress)
QString m_name
Definition: dimgthreadedfilter.h:307
DImgThreadedFilter * m_master
Definition: dimgthreadedfilter.h:327
int m_progressBegin
Definition: dimgthreadedfilter.h:300
int m_progressCurrent
To prevent signals bombarding with progress indicator value in postProgress().
Definition: dimgthreadedfilter.h:302
virtual void readParameters(const FilterAction &)=0
void finished(bool success)
const QString & filterName()
Definition: dimgthreadedfilter.h:89
int m_progressSpan
Definition: dimgthreadedfilter.h:301
DImg m_destImage
Definition: dimgthreadedfilter.h:317
DImgThreadedFilter * m_slave
Definition: dimgthreadedfilter.h:322
Definition: dimg.h:62
Definition: dynamicthread.h:43
Definition: filteraction.h:43
Category
Definition: filteraction.h:47
@ ReproducibleFilter
Definition: filteraction.h:56
Definition: filter.h:44
Definition: datefolderview.cpp:43