kspread

Filter.h

Go to the documentation of this file.
00001 /* This file is part of the KDE project
00002    Copyright 2007 Stefan Nikolaus <stefan.nikolaus@kdemail.net>
00003 
00004    This library is free software; you can redistribute it and/or
00005    modify it under the terms of the GNU Library General Public
00006    License as published by the Free Software Foundation; either
00007    version 2 of the License, or (at your option) any later version.
00008 
00009    This library is distributed in the hope that it will be useful,
00010    but WITHOUT ANY WARRANTY; without even the implied warranty of
00011    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012    Library General Public License for more details.
00013 
00014    You should have received a copy of the GNU Library General Public License
00015    along with this library; see the file COPYING.LIB.  If not, write to
00016    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00017    Boston, MA 02110-1301, USA.
00018 */
00019 
00020 #ifndef KSPREAD_FILTER
00021 #define KSPREAD_FILTER
00022 
00023 #include <QHash>
00024 #include <QString>
00025 
00026 #include <KoXmlReader.h>
00027 
00028 class KoXmlWriter;
00029 
00030 namespace KSpread
00031 {
00032 class Database;
00033 class Map;
00034 
00038 class Filter
00039 {
00040 public:
00041     enum Comparison {
00042         Match,
00043         NotMatch,
00044         Equal,
00045         NotEqual,
00046         Less,
00047         Greater,
00048         LessOrEqual,
00049         GreaterOrEqual,
00050         Empty,
00051         NotEmpty,
00052         TopValues,
00053         BottomValues,
00054         TopPercent,
00055         BottomPercent
00056     };
00057 
00058     enum Composition {
00059         AndComposition,
00060         OrComposition
00061     };
00062 
00063     enum Mode {
00064         Text,
00065         Number
00066     };
00067 
00071     Filter();
00072 
00076     Filter(const Filter& other);
00077 
00081     virtual ~Filter();
00082 
00083     void addCondition(Composition composition,
00084                       int fieldNumber, Comparison comparison, const QString& value,
00085                       Qt::CaseSensitivity caseSensitivity = Qt::CaseInsensitive, Mode mode = Text);
00086     void addSubFilter(Composition composition, const Filter& filter);
00087 
00088     QHash<QString, Comparison> conditions(int fieldNumber) const;
00089     void removeConditions(int fieldNumber = -1);
00090 
00091     bool isEmpty() const;
00092 
00097     bool evaluate(const Database& database, int index) const;
00098 
00099     bool loadOdf(const KoXmlElement& element, const Map* map);
00100     void saveOdf(KoXmlWriter& xmlWriter) const;
00101 
00102     bool operator==(const Filter& other) const;
00103     inline bool operator!=(const Filter& other) const {
00104         return !operator==(other);
00105     }
00106 
00107     void dump() const;
00108 
00109 private:
00110     class And;
00111     class Or;
00112     class Condition;
00113 
00114     void operator=(const Filter&);
00115 
00116     class Private;
00117     Private * const d;
00118 };
00119 
00120 } // namespace KSpread
00121 
00122 #endif // KSPREAD_FILTER