• Skip to content
  • Skip to link menu
KDE 4.2 API Reference
  • KDE API Reference
  • API Reference
  • Sitemap
  • Contact Us
 

NepomukDaemons

query.cpp

Go to the documentation of this file.
00001 /*
00002    This file is part of the Nepomuk KDE project.
00003    Copyright (C) 2008 Sebastian Trueg <trueg@kde.org>
00004 
00005    This library is free software; you can redistribute it and/or
00006    modify it under the terms of the GNU Library General Public
00007    License version 2 as published by the Free Software Foundation.
00008 
00009    This library is distributed in the hope that it will be useful,
00010    but WITHOUT ANY WARRANTY; without even the implied warranty of
00011    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012    Library General Public License for more details.
00013 
00014    You should have received a copy of the GNU Library General Public License
00015    along with this library; see the file COPYING.LIB.  If not, write to
00016    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00017    Boston, MA 02110-1301, USA.
00018  */
00019 
00020 #include "query.h"
00021 #include "term.h"
00022 
00023 #include <QtCore/QSharedData>
00024 #include <QtCore/QDebug>
00025 
00026 
00027 class Nepomuk::Search::Query::Private : public QSharedData
00028 {
00029 public:
00030     Private()
00031         : type( InvalidQuery ),
00032           limit( 0 ) {
00033     }
00034 
00035     Type type;
00036     Term term;
00037     QString sparqlQuery;
00038     int limit;
00039 
00040     QList<RequestProperty> requestProperties;
00041 };
00042 
00043 
00044 Nepomuk::Search::Query::Query()
00045     : d( new Private() )
00046 {
00047 }
00048 
00049 
00050 Nepomuk::Search::Query::Query( const Query& other )
00051 {
00052     d = other.d;
00053 }
00054 
00055 
00056 Nepomuk::Search::Query::Query( const Term& term )
00057     : d ( new Private() )
00058 {
00059     d->type = PlainQuery;
00060     d->term = term;
00061 }
00062 
00063 
00064 Nepomuk::Search::Query::Query( const QString& sparqlQuery )
00065     : d ( new Private() )
00066 {
00067     d->type = SPARQLQuery;
00068     d->sparqlQuery = sparqlQuery;
00069 }
00070 
00071 
00072 Nepomuk::Search::Query::~Query()
00073 {
00074 }
00075 
00076 
00077 Nepomuk::Search::Query& Nepomuk::Search::Query::operator=( const Query& other )
00078 {
00079     d = other.d;
00080     return *this;
00081 }
00082 
00083 
00084 Nepomuk::Search::Query::Type Nepomuk::Search::Query::type() const
00085 {
00086     return d->type;
00087 }
00088 
00089 
00090 Nepomuk::Search::Term Nepomuk::Search::Query::term() const
00091 {
00092     return d->term;
00093 }
00094 
00095 
00096 int Nepomuk::Search::Query::limit() const
00097 {
00098     return d->limit;
00099 }
00100 
00101 
00102 QString Nepomuk::Search::Query::sparqlQuery() const
00103 {
00104     return d->sparqlQuery;
00105 }
00106 
00107 
00108 void Nepomuk::Search::Query::setTerm( const Term& term )
00109 {
00110     d->term = term;
00111     d->type = PlainQuery;
00112 }
00113 
00114 
00115 void Nepomuk::Search::Query::setLimit( int limit )
00116 {
00117     d->limit = limit;
00118 }
00119 
00120 
00121 void Nepomuk::Search::Query::setSparqlQuery( const QString& qs )
00122 {
00123     d->sparqlQuery = qs;
00124     d->term = Term();
00125     d->type = SPARQLQuery;
00126 }
00127 
00128 
00129 void Nepomuk::Search::Query::addRequestProperty( const QUrl& property, bool optional )
00130 {
00131     d->requestProperties.append( qMakePair( property, optional ) );
00132 }
00133 
00134 
00135 void Nepomuk::Search::Query::clearRequestProperties()
00136 {
00137     d->requestProperties.clear();
00138 }
00139 
00140 
00141 QList<Nepomuk::Search::Query::RequestProperty> Nepomuk::Search::Query::requestProperties() const
00142 {
00143     return d->requestProperties;
00144 }
00145 
00146 
00147 namespace {
00148     bool compareRequestProperties( const QList<Nepomuk::Search::Query::RequestProperty>& rp1, const QList<Nepomuk::Search::Query::RequestProperty>& rp2 ) {
00149         // brute force
00150         foreach( const Nepomuk::Search::Query::RequestProperty& rp, rp1 ) {
00151             if ( !rp2.contains( rp ) ) {
00152                 return false;
00153             }
00154         }
00155         foreach( const Nepomuk::Search::Query::RequestProperty& rp, rp2 ) {
00156             if ( !rp1.contains( rp ) ) {
00157                 return false;
00158             }
00159         }
00160         return true;
00161     }
00162 }
00163 
00164 bool Nepomuk::Search::Query::operator==( const Query& other ) const
00165 {
00166     if ( d->type == other.d->type &&
00167          d->limit == other.d->limit ) {
00168         if ( d->type == SPARQLQuery ) {
00169             return( d->sparqlQuery == other.d->sparqlQuery &&
00170                     compareRequestProperties( d->requestProperties, other.d->requestProperties ) );
00171         }
00172         else {
00173             return( d->term == other.d->term &&
00174                     compareRequestProperties( d->requestProperties, other.d->requestProperties ) );
00175         }
00176     }
00177 
00178     return false;
00179 }
00180 
00181 
00182 QDebug operator<<( QDebug dbg, const Nepomuk::Search::Query& query )
00183 {
00184     dbg << "(Query" << query.term() << query.limit() << ")";
00185     return dbg;
00186 }
00187 
00188 
00189 uint Nepomuk::Search::qHash( const Nepomuk::Search::Query& query )
00190 {
00191     if ( query.type() == Nepomuk::Search::Query::SPARQLQuery )
00192         return qHash( query.sparqlQuery() );
00193     else
00194         return qHash( query.term() );
00195 }

NepomukDaemons

Skip menu "NepomukDaemons"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members
  • Related Pages

API Reference

Skip menu "API Reference"
  • KCMShell
  • KNotify
  • KStyles
  • Nepomuk Daemons
Generated for API Reference by doxygen 1.5.7
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal