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
23 #include <board/side.h>
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
36 class LIB_EXPORT PgnGameFilter
39 /*! The type of the filter. */
42 /*! Filter all tags with a single fixed string. */
44 /*! Use invididual filtering terms for each tag. */
48 /*! The result of the game. */
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
62 * Creates a new empty filter.
64 * An empty filter will not filter out any games.
65 * The filter's type is \a Advanced.
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. */
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;
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;
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
);
151 QByteArray m_pattern
;
155 QByteArray m_opponent
;
156 Chess::Side m_playerSide
;
162 bool m_resultInverted
;
165 inline PgnGameFilter::Type
PgnGameFilter::type() const
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
190 inline const QDate
& PgnGameFilter::maxDate() const
195 inline int PgnGameFilter::minRound() const
200 inline int PgnGameFilter::maxRound() const
205 inline PgnGameFilter::Result
PgnGameFilter::result() const
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
230 #endif // PGNGAMEFILTER_H