2 This file is part of the Nepomuk KDE project.
3 Copyright (C) 2008 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.
23 #include <QtCore/QSharedData>
24 #include <QtCore/QDebug>
27 class Nepomuk::Search::Query::Private
: public QSharedData
31 : type( InvalidQuery
),
40 QList
<RequestProperty
> requestProperties
;
44 Nepomuk::Search::Query::Query()
50 Nepomuk::Search::Query::Query( const Query
& other
)
56 Nepomuk::Search::Query::Query( const Term
& term
)
64 Nepomuk::Search::Query::Query( const QString
& sparqlQuery
)
67 d
->type
= SPARQLQuery
;
68 d
->sparqlQuery
= sparqlQuery
;
72 Nepomuk::Search::Query::~Query()
77 Nepomuk::Search::Query
& Nepomuk::Search::Query::operator=( const Query
& other
)
84 Nepomuk::Search::Query::Type
Nepomuk::Search::Query::type() const
90 Nepomuk::Search::Term
Nepomuk::Search::Query::term() const
96 int Nepomuk::Search::Query::limit() const
102 QString
Nepomuk::Search::Query::sparqlQuery() const
104 return d
->sparqlQuery
;
108 void Nepomuk::Search::Query::setTerm( const Term
& term
)
111 d
->type
= PlainQuery
;
115 void Nepomuk::Search::Query::setLimit( int limit
)
121 void Nepomuk::Search::Query::setSparqlQuery( const QString
& qs
)
125 d
->type
= SPARQLQuery
;
129 void Nepomuk::Search::Query::addRequestProperty( const QUrl
& property
, bool optional
)
131 d
->requestProperties
.append( qMakePair( property
, optional
) );
135 void Nepomuk::Search::Query::clearRequestProperties()
137 d
->requestProperties
.clear();
141 QList
<Nepomuk::Search::Query::RequestProperty
> Nepomuk::Search::Query::requestProperties() const
143 return d
->requestProperties
;
148 bool compareRequestProperties( const QList
<Nepomuk::Search::Query::RequestProperty
>& rp1
, const QList
<Nepomuk::Search::Query::RequestProperty
>& rp2
) {
150 foreach( const Nepomuk::Search::Query::RequestProperty
& rp
, rp1
) {
151 if ( !rp2
.contains( rp
) ) {
155 foreach( const Nepomuk::Search::Query::RequestProperty
& rp
, rp2
) {
156 if ( !rp1
.contains( rp
) ) {
164 bool Nepomuk::Search::Query::operator==( const Query
& other
) const
166 if ( d
->type
== other
.d
->type
&&
167 d
->limit
== other
.d
->limit
) {
168 if ( d
->type
== SPARQLQuery
) {
169 return( d
->sparqlQuery
== other
.d
->sparqlQuery
&&
170 compareRequestProperties( d
->requestProperties
, other
.d
->requestProperties
) );
173 return( d
->term
== other
.d
->term
&&
174 compareRequestProperties( d
->requestProperties
, other
.d
->requestProperties
) );
182 QDebug
operator<<( QDebug dbg
, const Nepomuk::Search::Query
& query
)
184 dbg
<< "(Query" << query
.term() << query
.limit() << ")";
189 uint
Nepomuk::Search::qHash( const Nepomuk::Search::Query
& query
)
191 if ( query
.type() == Nepomuk::Search::Query::SPARQLQuery
)
192 return qHash( query
.sparqlQuery() );
194 return qHash( query
.term() );