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 
DImgFilterGenerator()46     DImgFilterGenerator()          {};
~DImgFilterGenerator()47     virtual ~DImgFilterGenerator() {};
48 
49     /// Returns a list with identifiers of supported filters
50     virtual QStringList supportedFilters()                                  = 0;
51 
52     /// Returns a list with the supported versions for the given identifier
53     virtual QList<int>  supportedVersions(const QString& filterIdentifier)  = 0;
54 
55     /// Returns a QString with filter name for displaying in views
56     virtual QString displayableName(const QString& filterIdentifier)        = 0;
57 
58     /// Convenience methods
59     virtual bool isSupported(const QString& filterIdentifier);
60     virtual bool isSupported(const QString& filterIdentifier, int version);
61 
62     /// Create the filter for the given combination of identifier and version
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>
73 class BasicDImgFilterGenerator : public DImgFilterGenerator
74 {
75 public:
76 
77     /**
78      * A sample implementation for one DImgThreadedFilter class.
79      * The class must provide two static methods, FilterIdentifier() and SupportedVersions().
80      */
81 
BasicDImgFilterGenerator()82     BasicDImgFilterGenerator()
83     {
84     }
85 
supportedFilters()86     QStringList supportedFilters() override
87     {
88         return QList<QString>() << T::FilterIdentifier();
89     }
90 
supportedVersions(const QString & filterIdentifier)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 
createFilter(const QString & filterIdentifier,int version)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 
displayableName(const QString & filterIdentifier)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
129