File indexing completed on 2024-05-12 16:35:15

0001 /* This file is part of the KDE project
0002    Copyright 2007 Stefan Nikolaus <stefan.nikolaus@kdemail.net>
0003 
0004    This library is free software; you can redistribute it and/or
0005    modify it under the terms of the GNU Library General Public
0006    License as published by the Free Software Foundation; either
0007    version 2 of the License, or (at your option) any later version.
0008 
0009    This library is distributed in the hope that it will be useful,
0010    but WITHOUT ANY WARRANTY; without even the implied warranty of
0011    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0012    Library General Public License for more details.
0013 
0014    You should have received a copy of the GNU Library General Public License
0015    along with this library; see the file COPYING.LIB.  If not, write to
0016    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
0017    Boston, MA 02110-1301, USA.
0018 */
0019 
0020 #ifndef CALLIGRA_SHEETS_FILTER
0021 #define CALLIGRA_SHEETS_FILTER
0022 
0023 #include <QHash>
0024 #include <QString>
0025 
0026 #include <KoXmlReader.h>
0027 
0028 #include "sheets_odf_export.h"
0029 
0030 class KoXmlWriter;
0031 
0032 namespace Calligra
0033 {
0034 namespace Sheets
0035 {
0036 class Database;
0037 class Map;
0038 class AbstractCondition;
0039 
0040 /**
0041  * OpenDocument, 8.7.1 Table Filter
0042  */
0043 class CALLIGRA_SHEETS_ODF_EXPORT Filter
0044 {
0045 public:
0046     enum Comparison {
0047         Match,
0048         NotMatch,
0049         Equal,
0050         NotEqual,
0051         Less,
0052         Greater,
0053         LessOrEqual,
0054         GreaterOrEqual,
0055         Empty,
0056         NotEmpty,
0057         TopValues,
0058         BottomValues,
0059         TopPercent,
0060         BottomPercent
0061     };
0062 
0063     enum Composition {
0064         AndComposition,
0065         OrComposition
0066     };
0067 
0068     enum Mode {
0069         Text,
0070         Number
0071     };
0072 
0073     /**
0074      * Constructor.
0075      */
0076     Filter();
0077 
0078     /**
0079      * Constructor.
0080      */
0081     Filter(const Filter& other);
0082 
0083     /**
0084      * Destructor.
0085      */
0086     virtual ~Filter();
0087 
0088     void addCondition(Composition composition,
0089                       int fieldNumber, Comparison comparison, const QString& value,
0090                       Qt::CaseSensitivity caseSensitivity = Qt::CaseInsensitive, Mode mode = Text);
0091     void addSubFilter(Composition composition, const Filter& filter);
0092 
0093     QHash<QString, Comparison> conditions(int fieldNumber) const;
0094     void removeConditions(int fieldNumber = -1);
0095 
0096     bool isEmpty() const;
0097 
0098     /**
0099      * \return \c true if the column/row with \p index fulfills all conditions, i.e. it should not
0100      * be filtered.
0101      */
0102     bool evaluate(const Database& database, int index) const;
0103 
0104     bool loadOdf(const KoXmlElement& element, const Map* map);
0105     void saveOdf(KoXmlWriter& xmlWriter) const;
0106 
0107     bool operator==(const Filter& other) const;
0108     inline bool operator!=(const Filter& other) const {
0109         return !operator==(other);
0110     }
0111 
0112     void dump() const;
0113 
0114 private:
0115     class And;
0116     class Or;
0117     class Condition;
0118     friend class AbstractCondition;
0119 
0120     void operator=(const Filter&);
0121     static QList<AbstractCondition*> copyList(const QList<AbstractCondition*>& list);
0122     static bool conditionsEquals(AbstractCondition* a, AbstractCondition* b);
0123 
0124     class Private;
0125     Private * const d;
0126 };
0127 
0128 } // namespace Sheets
0129 } // namespace Calligra
0130 
0131 #endif // CALLIGRA_SHEETS_FILTER