[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: KDE/kdelibs/nepomuk/core
From: Sebastian Trueg <sebastian () trueg ! de>
Date: 2009-08-05 13:10:34
Message-ID: 1249477834.368764.16661.nullmailer () svn ! kde ! org
[Download RAW message or body]
SVN commit 1007293 by trueg:
* Handle Resource::resourceUri in toUrlList. This allows to convert QUrl, \
QList<QUrl>, Resource, and QList<Resource> into a QList<QUrl>
* Handle lists in all toFooBar methods by returning the first value in the list. This \
is only for convenience.
M +75 -5 variant.cpp
--- trunk/KDE/kdelibs/nepomuk/core/variant.cpp #1007292:1007293
@@ -750,36 +750,72 @@
int Nepomuk::Variant::toInt() const
{
+ if(isList()) {
+ QList<int> l = toIntList();
+ if(!l.isEmpty())
+ return l.first();
+ }
+
return d->value.toInt();
}
qlonglong Nepomuk::Variant::toInt64() const
{
+ if(isList()) {
+ QList<qlonglong> l = toInt64List();
+ if(!l.isEmpty())
+ return l.first();
+ }
+
return d->value.toLongLong();
}
uint Nepomuk::Variant::toUnsignedInt() const
{
+ if(isList()) {
+ QList<uint> l = toUnsignedIntList();
+ if(!l.isEmpty())
+ return l.first();
+ }
+
return d->value.toUInt();
}
qulonglong Nepomuk::Variant::toUnsignedInt64() const
{
+ if(isList()) {
+ QList<qulonglong> l = toUnsignedInt64List();
+ if(!l.isEmpty())
+ return l.first();
+ }
+
return d->value.toULongLong();
}
bool Nepomuk::Variant::toBool() const
{
+ if(isList()) {
+ QList<bool> l = toBoolList();
+ if(!l.isEmpty())
+ return l.first();
+ }
+
return d->value.toBool();
}
double Nepomuk::Variant::toDouble() const
{
+ if(isList()) {
+ QList<double> l = toDoubleList();
+ if(!l.isEmpty())
+ return l.first();
+ }
+
return d->value.toDouble();
}
@@ -826,33 +862,59 @@
QDate Nepomuk::Variant::toDate() const
{
+ if(isList()) {
+ QList<QDate> l = toDateList();
+ if(!l.isEmpty())
+ return l.first();
+ }
return d->value.toDate();
}
QTime Nepomuk::Variant::toTime() const
{
+ if(isList()) {
+ QList<QTime> l = toTimeList();
+ if(!l.isEmpty())
+ return l.first();
+ }
return d->value.toTime();
}
QDateTime Nepomuk::Variant::toDateTime() const
{
+ if(isList()) {
+ QList<QDateTime> l = toDateTimeList();
+ if(!l.isEmpty())
+ return l.first();
+ }
return d->value.toDateTime();
}
QUrl Nepomuk::Variant::toUrl() const
{
- if( isResource() )
+ if(isList()) {
+ QList<QUrl> l = toUrlList();
+ if(!l.isEmpty())
+ return l.first();
+ }
+ else if(isResource()) {
return toResource().resourceUri();
- else
- return d->value.toUrl();
+ }
+
+ return d->value.toUrl();
}
Nepomuk::Resource Nepomuk::Variant::toResource() const
{
+ if(isResourceList()) {
+ QList<Resource> l = toResourceList();
+ if(!l.isEmpty())
+ return l.first();
+ }
return d->value.value<Resource>();
}
@@ -1067,13 +1129,21 @@
QList<QUrl> Nepomuk::Variant::toUrlList() const
{
- if( isUrl() ) {
+ if( isUrl() || isResource() ) {
QList<QUrl> l;
l.append( toUrl() );
return l;
}
- else
+ else if( isResourceList() ) {
+ QList<QUrl> l;
+ QList<Resource> rl = toResourceList();
+ foreach(const Resource& r, rl)
+ l << r.resourceUri();
+ return l;
+ }
+ else {
return d->value.value<QList<QUrl> >();
+ }
}
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic