digiKam
dimgfiltergenerator.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 : 2010-06-24
7  * Description : class for creating a particular filter
8  *
9  * Copyright (C) 2010-2011 by Marcel Wiesweg <marcel dot wiesweg at gmx dot de>
10  *
11  * This program is free software; you can redistribute it
12  * and/or modify it under the terms of the GNU General
13  * Public License as published by the Free Software Foundation;
14  * either version 2, or (at your option)
15  * any later version.
16  *
17  * This program is distributed in the hope that it will be useful,
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20  * GNU General Public License for more details.
21  *
22  * ============================================================ */
23 
24 #ifndef DIGIKAM_DIMG_FILTER_GENERATOR_H
25 #define DIGIKAM_DIMG_FILTER_GENERATOR_H
26 
27 // Qt includes
28 
29 #include <QList>
30 #include <QString>
31 #include <QStringList>
32 
33 // Local includes
34 
35 #include "digikam_export.h"
36 
37 namespace Digikam
38 {
39 
40 class DImgThreadedFilter;
41 
42 class DIGIKAM_EXPORT DImgFilterGenerator
43 {
44 public:
45 
47  virtual ~DImgFilterGenerator() {};
48 
50  virtual QStringList supportedFilters() = 0;
51 
53  virtual QList<int> supportedVersions(const QString& filterIdentifier) = 0;
54 
56  virtual QString displayableName(const QString& filterIdentifier) = 0;
57 
59  virtual bool isSupported(const QString& filterIdentifier);
60  virtual bool isSupported(const QString& filterIdentifier, int version);
61 
63  virtual DImgThreadedFilter* createFilter(const QString& filterIdentifier,
64  int version) = 0;
65 private:
66 
67  Q_DISABLE_COPY(DImgFilterGenerator)
68 };
69 
70 // -----------------------------------------------------------------------------------
71 
72 template <class T>
74 {
75 public:
76 
83  {
84  }
85 
86  QStringList supportedFilters() override
87  {
88  return QList<QString>() << T::FilterIdentifier();
89  }
90 
91  QList<int> supportedVersions(const QString& filterIdentifier) override
92  {
93  if (filterIdentifier == T::FilterIdentifier())
94  {
95  return T::SupportedVersions();
96  }
97 
98  return QList<int>();
99  }
100 
101  DImgThreadedFilter* createFilter(const QString& filterIdentifier, int version) override
102  {
103  if ((filterIdentifier == T::FilterIdentifier()) &&
104  T::SupportedVersions().contains(version))
105  {
106  T* const t = new T;
107  t->setFilterVersion(version);
108 
109  return t;
110  }
111 
112  return nullptr;
113  }
114 
115  QString displayableName(const QString& filterIdentifier) override
116  {
117  if (filterIdentifier == T::FilterIdentifier())
118  {
119  return T::DisplayableName();
120  }
121 
122  return QString();
123  }
124 };
125 
126 } // namespace Digikam
127 
128 #endif // DIGIKAM_DIMG_FILTER_GENERATOR_H
Definition: dimgfiltergenerator.h:74
DImgThreadedFilter * createFilter(const QString &filterIdentifier, int version) override
Create the filter for the given combination of identifier and version.
Definition: dimgfiltergenerator.h:101
QList< int > supportedVersions(const QString &filterIdentifier) override
Returns a list with the supported versions for the given identifier.
Definition: dimgfiltergenerator.h:91
BasicDImgFilterGenerator()
Definition: dimgfiltergenerator.h:82
QStringList supportedFilters() override
Returns a list with identifiers of supported filters.
Definition: dimgfiltergenerator.h:86
QString displayableName(const QString &filterIdentifier) override
Returns a QString with filter name for displaying in views.
Definition: dimgfiltergenerator.h:115
Definition: dimgfiltergenerator.h:43
virtual ~DImgFilterGenerator()
Definition: dimgfiltergenerator.h:47
virtual QString displayableName(const QString &filterIdentifier)=0
Returns a QString with filter name for displaying in views.
virtual QList< int > supportedVersions(const QString &filterIdentifier)=0
Returns a list with the supported versions for the given identifier.
virtual QStringList supportedFilters()=0
Returns a list with identifiers of supported filters.
virtual DImgThreadedFilter * createFilter(const QString &filterIdentifier, int version)=0
Create the filter for the given combination of identifier and version.
DImgFilterGenerator()
Definition: dimgfiltergenerator.h:46
Definition: dimgthreadedfilter.h:41
#define T
Definition: datefolderview.cpp:43