1 /***************************************************************************
2     Copyright (C) 2007-2009 Robby Stephenson <robby@periapsis.org>
3  ***************************************************************************/
4 
5 /***************************************************************************
6  *                                                                         *
7  *   This program is free software; you can redistribute it and/or         *
8  *   modify it under the terms of the GNU General Public License as        *
9  *   published by the Free Software Foundation; either version 2 of        *
10  *   the License or (at your option) version 3 or any later version        *
11  *   accepted by the membership of KDE e.V. (or its successor approved     *
12  *   by the membership of KDE e.V.), which shall act as a proxy            *
13  *   defined in Section 14 of version 3 of the license.                    *
14  *                                                                         *
15  *   This program is distributed in the hope that it will be useful,       *
16  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
17  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
18  *   GNU General Public License for more details.                          *
19  *                                                                         *
20  *   You should have received a copy of the GNU General Public License     *
21  *   along with this program.  If not, see <http://www.gnu.org/licenses/>. *
22  *                                                                         *
23  ***************************************************************************/
24 
25 #ifndef TELLICO_FIELDCOMPARISON_H
26 #define TELLICO_FIELDCOMPARISON_H
27 
28 #include "../datavectors.h"
29 
30 #include <QStringList>
31 
32 namespace Tellico {
33 
34 class StringComparison;
35 
36 class FieldComparison {
37 public:
38   FieldComparison(Data::FieldPtr field);
~FieldComparison()39   virtual ~FieldComparison() {}
40 
field()41   Data::FieldPtr field() const { return m_field; }
42 
43   virtual int compare(Data::EntryPtr entry1, Data::EntryPtr entry2);
44 
45   static FieldComparison* create(Data::FieldPtr field);
46 
47 protected:
48   virtual int compare(const QString& str1, const QString& str2) = 0;
49 
50 private:
51   Q_DISABLE_COPY(FieldComparison)
52   Data::FieldPtr m_field;
53 };
54 
55 class ValueComparison : public FieldComparison {
56 public:
57   ValueComparison(Data::FieldPtr field, StringComparison* comp);
58   ~ValueComparison();
59 
60   using FieldComparison::compare;
61 
62 protected:
63   virtual int compare(const QString& str1, const QString& str2) Q_DECL_OVERRIDE;
64 
65 private:
66   StringComparison* m_stringComparison;
67 };
68 
69 class ImageComparison : public FieldComparison {
70 public:
71   ImageComparison(Data::FieldPtr field);
72 
73   using FieldComparison::compare;
74 
75 protected:
76   virtual int compare(const QString& str1, const QString& str2) Q_DECL_OVERRIDE;
77 };
78 
79 class ChoiceComparison : public FieldComparison {
80 public:
81   ChoiceComparison(Data::FieldPtr field);
82 
83   using FieldComparison::compare;
84 
85 protected:
86   virtual int compare(const QString& str1, const QString& str2) Q_DECL_OVERRIDE;
87 
88 private:
89   QStringList m_values;
90 };
91 
92 }
93 #endif
94