add more spacing
[personal-kdebase.git] / workspace / libs / nepomukquery / term.h
blob272eed7838d8847f24166e7278e0c0f5885c4af7
1 /*
2 This file is part of the Nepomuk KDE project.
3 Copyright (C) 2007 Sebastian Trueg <trueg@kde.org>
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public
7 License version 2 as published by the Free Software Foundation.
9 This library 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 GNU
12 Library General Public License for more details.
14 You should have received a copy of the GNU Library General Public License
15 along with this library; see the file COPYING.LIB. If not, write to
16 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 Boston, MA 02110-1301, USA.
20 #ifndef _NEPOMUK_SEARCH_TERM_H_
21 #define _NEPOMUK_SEARCH_TERM_H_
23 #include <QtCore/QList>
24 #include <QtCore/QUrl>
25 #include <QtCore/QSharedDataPointer>
27 #include <Soprano/LiteralValue>
29 #include "nepomukquery_export.h"
32 namespace Nepomuk {
33 namespace Search {
34 /**
35 * \class Term term.h nepomuk/term.h
37 * \brief A Query constist of Terms.
39 * Queries are build from Term instances. A Term can have one of multiple
40 * types and subterms. See Term::Type for details on the different Term types.
42 * \author Sebastian Trueg <trueg@kde.org>
44 class NEPOMUKQUERY_EXPORT Term
46 public:
47 /**
48 * Each search term has a type.
50 enum Type {
51 InvalidTerm, /**< An invalid term does not do anything */
52 /**
53 * A literal term is the simplest form of Term. It matches all resource
54 * that contain the value.
56 * It is also used to specify literal values in comparison Terms such
57 * as ContainsTerm or EqualityTerm.
59 LiteralTerm,
61 /**
62 * A resource term matches one resource by URI.
64 * It is also used to specify a resource in EqualityTerm Terms.
66 ResourceTerm,
68 /**
69 * Match all resources that match all sub terms.
71 AndTerm,
73 /**
74 * Match all resources that match one of the sub terms.
76 OrTerm,
78 /**
79 * A comparison. The comparison operator needs to be specified in addition.
80 * For specifying the %property the same applies as for ContainsTerm.
82 * A single subterm specifies the resource or value to match (resource terms
83 * can only be matched via Equal or Contains.
85 ComparisonTerm
88 enum Comparator {
89 Contains,
90 Equal,
91 Greater,
92 Smaller,
93 GreaterOrEqual,
94 SmallerOrEqual
97 /**
98 * Constructs an invalid term.
100 Term();
103 * Copy constructor.
105 Term( const Term& other );
108 * Construct a literal term.
110 Term( const Soprano::LiteralValue& value );
113 * Construct a resource term.
115 Term( const QUrl& resource );
118 * Construct a Contains ComparisonTerm term.
119 * \param field A string that will be matched against a field label
120 * \param value A value that will be matched against the field value. Unsupported
121 * types are converted to string.
122 * \param comparator The Comparator to use
124 Term( const QString& field, const Soprano::LiteralValue& value, Comparator c = Contains );
127 * Construct a Contains ComparisonTerm term.
128 * \param field The exact field to match
129 * \param value A value that will be matched against the field value. Unsupported
130 * types are converted to string.
131 * \param comparator The Comparator to use
133 Term( const QUrl& field, const Soprano::LiteralValue& value, Comparator c = Contains );
136 * Construct an EqualityTerm term.
137 * \param field The exact field to match
138 * \param value The resource that should be matched.
140 Term( const QUrl& field, const QUrl& resource );
143 * Destructor
145 ~Term();
148 * Assign another term to this one.
150 Term& operator=( const Term& other );
153 * Make the term a literal term.
155 Term& operator=( const Soprano::LiteralValue& other );
158 * \return \p true if the Term is valid.
160 bool isValid() const;
163 * \return the Term type.
165 * \sa setType
167 Type type() const;
170 * The literal value of a LiteralTerm.
172 * \sa setValue
174 Soprano::LiteralValue value() const;
177 * The resource of a ResourceTerm
179 * \sa setResource
181 QUrl resource() const;
184 * The Comparator used by ComparisonTerm Terms.
186 * \sa setComparator
188 Comparator comparator() const;
191 * A property name used for ComparisonTerm Terms. Will be matched against
192 * the rdfs:label to find the corresponding property.
194 * \sa setField, property, setProperty
196 QString field() const;
199 * A property used for ComparisonTerm Terms.
201 * \sa setProperty, field, setField
203 QUrl property() const;
206 * The sub terms used by AndTerm, OrTerm, and ComparisonTerm.
208 * \sa setSubTerms, addSubTerm
210 QList<Term> subTerms() const;
213 * Set the type of the Term
215 void setType( Type );
218 * Set the value of a LiteralTerm
220 void setValue( const Soprano::LiteralValue& );
223 * Set the resource of a ResourceTerm
225 void setResource( const QUrl& );
228 * Defaults to Equal
230 void setComparator( Comparator );
233 * Set the property label in case the exact
234 * property is not known. Will be mached against
235 * the property's rdfs:label.
237 * \sa field, setProperty, property
239 void setField( const QString& );
242 * Set the property for ComparisonTerm
243 * Terms.
245 * If the exact property is not known use setField.
247 * \sa property
249 void setProperty( const QUrl& );
252 * Set the subterms used by AndTerm, OrTerm, and ComparisonTerm.
254 * \sa addSubTerm
256 void setSubTerms( const QList<Term>& );
259 * Add a subterm used by AndTerm, OrTerm, and ComparisonTerm.
261 * \sa setSubTerm
263 void addSubTerm( const Term& );
266 * Comparison operator.
268 bool operator==( const Term& ) const;
270 private:
271 class Private;
272 QSharedDataPointer<Private> d;
275 NEPOMUKQUERY_EXPORT uint qHash( const Nepomuk::Search::Term& );
279 NEPOMUKQUERY_EXPORT QDebug operator<<( QDebug, const Nepomuk::Search::Term& );
281 #endif