Add JSON RFC to the See Also section
[sloppygui.git] / projects / lib / src / pgngamefilter.h
blob55a2ef9dec6aa33ced1336d07e5645911c5853cd
1 /*
2 This file is part of Cute Chess.
4 Cute Chess is free software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation, either version 3 of the License, or
7 (at your option) any later version.
9 Cute Chess is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with Cute Chess. If not, see <http://www.gnu.org/licenses/>.
18 #ifndef PGNGAMEFILTER_H
19 #define PGNGAMEFILTER_H
21 #include <QByteArray>
22 #include <QDate>
23 #include <board/side.h>
24 class QString;
25 class PgnGameEntry;
27 /*!
28 * \brief A filter for chess games in a PGN database.
30 * A PgnGameFilter object can be used to filter games in a PGN
31 * database by matching the filtering terms to the games' PGN
32 * tags.
34 * \sa PgnGameEntry
36 class LIB_EXPORT PgnGameFilter
38 public:
39 /*! The type of the filter. */
40 enum Type
42 /*! Filter all tags with a single fixed string. */
43 FixedString,
44 /*! Use invididual filtering terms for each tag. */
45 Advanced
48 /*! The result of the game. */
49 enum Result
51 AnyResult, //!< Any result (no filtering)
52 EitherPlayerWins, //!< Either player wins
53 WhiteWins, //!< The white player wins
54 BlackWins, //!< The black player wins
55 FirstPlayerWins, //!< The first player wins
56 FirstPlayerLoses, //!< The first player loses
57 Draw, //!< The game is a draw
58 Unfinished //!< The game wasn't completed
61 /*!
62 * Creates a new empty filter.
64 * An empty filter will not filter out any games.
65 * The filter's type is \a Advanced.
67 PgnGameFilter();
68 /*!
69 * Creates a new filter based on a fixed string.
71 * Games that have tags matching \a pattern will be filtered in.
72 * The filter's type is \a FixedString.
74 PgnGameFilter(const QString& pattern);
76 /*! Returns the type of the filter. */
77 Type type() const;
79 /*! Returns the pattern for \a FixedString mode. */
80 const char* pattern() const;
82 /*! Returns the filter for the \a Event tag. */
83 const char* event() const;
84 /*! Returns the filter for the \a Site tag. */
85 const char* site() const;
86 /*!
87 * Returns the filter for the first player.
89 * The first player's side/color is determined by the
90 * playerSide() member function.
92 const char* player() const;
93 /*! Returns the filter for the opponent of the first player. */
94 const char* opponent() const;
95 /*! Returns the filter for the side/color of the first player. */
96 Chess::Side playerSide() const;
97 /*!
98 * Returns the filter for the game's minimum starting date.
100 * \note A null QDate won't filter out any games.
102 const QDate& minDate() const;
104 * Returns the filter for the game's maximum starting date.
106 * \note A null QDate won't filter out any games.
108 const QDate& maxDate() const;
109 /*! Returns the filter for the minimum round ordinal. */
110 int minRound() const;
111 /*! Returns the filter for the maximum round ordinal. */
112 int maxRound() const;
113 /*! Returns the filter for the \a Result tag. */
114 Result result() const;
116 * Returns true if the filter is looking for the inverse
117 * of \a result(); otherwise returns false.
119 bool isResultInverted() const;
122 * Sets the \a FixedString pattern to \a pattern.
124 * This function will change the filter type to \a FixedString.
126 void setPattern(const QString& pattern);
128 /*! Sets the \a Event tag filter to \a event. */
129 void setEvent(const QString& event);
130 /*! Sets the \a Site tag filter to \a site. */
131 void setSite(const QString& site);
132 /*! Sets the minimum starting date filter to \a date. */
133 void setMinDate(const QDate& date);
134 /*! Sets the maximum starting date filter to \a date. */
135 void setMaxDate(const QDate& date);
136 /*! Sets the minimum round ordinal filter to \a round. */
137 void setMinRound(int round);
138 /*! Sets the maximum round ordinal filter to \a round. */
139 void setMaxRound(int round);
140 /*! Sets the \a side player's filter to \a name. */
141 void setPlayer(const QString& name, Chess::Side side);
142 /*! Sets the first player's opponent filter to \a name. */
143 void setOpponent(const QString& name);
144 /*! Sets the \a Result tag filter to \a result. */
145 void setResult(Result result);
146 /*! Sets the \a resultInverted value to \a invert. */
147 void setResultInverted(bool invert);
149 private:
150 Type m_type;
151 QByteArray m_pattern;
152 QByteArray m_event;
153 QByteArray m_site;
154 QByteArray m_player;
155 QByteArray m_opponent;
156 Chess::Side m_playerSide;
157 QDate m_minDate;
158 QDate m_maxDate;
159 int m_minRound;
160 int m_maxRound;
161 Result m_result;
162 bool m_resultInverted;
165 inline PgnGameFilter::Type PgnGameFilter::type() const
167 return m_type;
170 inline const char* PgnGameFilter::pattern() const
172 return m_pattern.constData();
175 inline const char* PgnGameFilter::event() const
177 return m_event.constData();
180 inline const char* PgnGameFilter::site() const
182 return m_site.constData();
185 inline const QDate& PgnGameFilter::minDate() const
187 return m_minDate;
190 inline const QDate& PgnGameFilter::maxDate() const
192 return m_maxDate;
195 inline int PgnGameFilter::minRound() const
197 return m_minRound;
200 inline int PgnGameFilter::maxRound() const
202 return m_maxRound;
205 inline PgnGameFilter::Result PgnGameFilter::result() const
207 return m_result;
210 inline bool PgnGameFilter::isResultInverted() const
212 return m_resultInverted;
215 inline const char* PgnGameFilter::player() const
217 return m_player.constData();
220 inline const char* PgnGameFilter::opponent() const
222 return m_opponent.constData();
225 inline Chess::Side PgnGameFilter::playerSide() const
227 return m_playerSide;
230 #endif // PGNGAMEFILTER_H