not quite so much needs to be delayed to the init() function
[personal-kdebase.git] / workspace / libs / nepomukquery / result.cpp
bloba3b5bf183b8219d1ba815e99efdbdb77aa7502e3
1 /*
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.
20 #include "result.h"
21 #include "qurlhash.h"
23 #include <QtCore/QSharedData>
24 #include <QtCore/QHash>
27 class Nepomuk::Search::Result::Private : public QSharedData
29 public:
30 QUrl resource;
31 double score;
32 QHash<QUrl, Soprano::Node> requestProperties;
36 Nepomuk::Search::Result::Result()
37 : d( new Private() )
42 Nepomuk::Search::Result::Result( const QUrl& uri, double score )
43 : d( new Private() )
45 d->resource = uri;
46 d->score = score;
50 Nepomuk::Search::Result::Result( const Result& other )
52 d = other.d;
56 Nepomuk::Search::Result::~Result()
61 Nepomuk::Search::Result& Nepomuk::Search::Result::operator=( const Result& other )
63 d = other.d;
64 return *this;
68 double Nepomuk::Search::Result::score() const
70 return d->score;
74 QUrl Nepomuk::Search::Result::resourceUri() const
76 return d->resource;
80 void Nepomuk::Search::Result::setScore( double score )
82 d->score = score;
86 void Nepomuk::Search::Result::addRequestProperty( const QUrl& property, const Soprano::Node& value )
88 d->requestProperties[property] = value;
92 Soprano::Node Nepomuk::Search::Result::operator[]( const QUrl& property ) const
94 return requestProperty( property );
98 Soprano::Node Nepomuk::Search::Result::requestProperty( const QUrl& property ) const
100 QHash<QUrl, Soprano::Node>::const_iterator it = d->requestProperties.find( property );
101 if ( it != d->requestProperties.end() ) {
102 return *it;
104 else {
105 return Soprano::Node();
110 QHash<QUrl, Soprano::Node> Nepomuk::Search::Result::requestProperties() const
112 return d->requestProperties;
116 bool Nepomuk::Search::Result::operator==( const Result& other ) const
118 if ( d->resource != other.d->resource ||
119 d->score != other.d->score ) {
120 return false;
122 for ( QHash<QUrl, Soprano::Node>::const_iterator it = d->requestProperties.constBegin();
123 it != d->requestProperties.constEnd(); ++it ) {
124 QHash<QUrl, Soprano::Node>::const_iterator it2 = other.d->requestProperties.constFind( it.key() );
125 if ( it2 == other.d->requestProperties.constEnd() ||
126 it2.value() != it.value() ) {
127 return false;
130 for ( QHash<QUrl, Soprano::Node>::const_iterator it = other.d->requestProperties.constBegin();
131 it != other.d->requestProperties.constEnd(); ++it ) {
132 QHash<QUrl, Soprano::Node>::const_iterator it2 = d->requestProperties.constFind( it.key() );
133 if ( it2 == d->requestProperties.constEnd() ||
134 it2.value() != it.value() ) {
135 return false;
138 return true;