25 #include <soprano/literalvalue.h> 
   26 #include <soprano/node.h> 
   30 #include <QtCore/QVariant> 
   34     template<
typename T1, 
typename T2> QList<T2> convertList( 
const QList<T1>& l ) {
 
   36         for( 
int i = 0; i < l.count(); ++i ) {
 
   37             il.append( static_cast<T2>( l[i] ) );
 
   44 class Nepomuk2::Variant::Private
 
   73     if ( other.userType() == QVariant::Int ||
 
   74          other.userType() == QVariant::LongLong ||
 
   75          other.userType() == QVariant::UInt ||
 
   76          other.userType() == QVariant::ULongLong ||
 
   77          other.userType() == QVariant::Bool ||
 
   78          other.userType() == QVariant::Double ||
 
   79          other.userType() == QVariant::String ||
 
   80          other.userType() == QVariant::Date ||
 
   81          other.userType() == QVariant::Time ||
 
   82          other.userType() == QVariant::DateTime ||
 
   83          other.userType() == QVariant::Url ||
 
   84          other.userType() == qMetaTypeId<Resource>() ||
 
   85          other.userType() == qMetaTypeId<QList<int> >() ||
 
   86          other.userType() == qMetaTypeId<QList<qlonglong> >() ||
 
   87          other.userType() == qMetaTypeId<QList<uint> >() ||
 
   88          other.userType() == qMetaTypeId<QList<qulonglong> >() ||
 
   89          other.userType() == qMetaTypeId<QList<bool> >() ||
 
   90          other.userType() == qMetaTypeId<QList<double> >() ||
 
   91          other.userType() == QVariant::StringList ||
 
   92          other.userType() == qMetaTypeId<QList<QDate> >() ||
 
   93          other.userType() == qMetaTypeId<QList<QTime> >() ||
 
   94          other.userType() == qMetaTypeId<QList<QDateTime> >() ||
 
   95          other.userType() == qMetaTypeId<QList<QUrl> >() ||
 
   96          other.userType() == qMetaTypeId<QList<Resource> >() ) {
 
  105     d->value.setValue( i );
 
  112     d->value.setValue( i );
 
  119     d->value.setValue( i );
 
  126     d->value.setValue( i );
 
  133     d->value.setValue( b );
 
  140     d->value.setValue( v );
 
  147     d->value.setValue( QString::fromLatin1(
string) );
 
  154     d->value.setValue( 
string );
 
  161     d->value.setValue( date );
 
  168     d->value.setValue( time );
 
  175     d->value.setValue( datetime );
 
  182     d->value.setValue( url );
 
  189     d->value.setValue( r );
 
  196     d->value.setValue( i );
 
  203     d->value.setValue( i );
 
  210     d->value.setValue( i );
 
  217     d->value.setValue( i );
 
  224     d->value.setValue( b );
 
  231     d->value.setValue( v );
 
  238     d->value.setValue( stringlist );
 
  245     d->value.setValue( date );
 
  252     d->value.setValue( time );
 
  259     d->value.setValue( datetime );
 
  266     d->value.setValue( url );
 
  274     d->value.setValue( r );
 
  281     foreach( 
const Variant& v, vl ) {
 
  289     d->value = v.d->value;
 
  296     d->value.setValue( i );
 
  303     d->value.setValue( i );
 
  310     d->value.setValue( i );
 
  317     d->value.setValue( i );
 
  324     d->value.setValue( b );
 
  331     d->value.setValue( v );
 
  338     d->value.setValue( 
string );
 
  345     d->value.setValue( date );
 
  352     d->value.setValue( time );
 
  359     d->value.setValue( datetime );
 
  366     d->value.setValue( url );
 
  373     d->value.setValue( r );
 
  380     d->value.setValue( i );
 
  387     d->value.setValue( i );
 
  394     d->value.setValue( i );
 
  401     d->value.setValue( i );
 
  408     d->value.setValue( b );
 
  415     d->value.setValue( v );
 
  422     d->value.setValue( stringlist );
 
  429     d->value.setValue( date );
 
  436     d->value.setValue( time );
 
  443     d->value.setValue( datetime );
 
  450     d->value.setValue( url );
 
  457     d->value.setValue( r );
 
  464     QList<int> l = toIntList();
 
  472     QList<qlonglong> l = toInt64List();
 
  480     QList<uint> l = toUnsignedIntList();
 
  488     QList<qulonglong> l = toUnsignedInt64List();
 
  496     QList<bool> l = toBoolList();
 
  504     QList<double> l = toDoubleList();
 
  512     QStringList l = toStringList();
 
  520     QList<QDate> l = toDateList();
 
  528     QList<QTime> l = toTimeList();
 
  536     QList<QDateTime> l = toDateTimeList();
 
  537     l.append( datetime );
 
  544     QList<QUrl> l = toUrlList();
 
  552     QList<Resource> l = toResourceList();
 
  553     if ( !l.contains( r ) ) {
 
  567             operator=( toIntList() += v.
toIntList() );
 
  572         else if( v.
simpleType() == QVariant::LongLong ) {
 
  575         else if( v.
simpleType() == QVariant::ULongLong ) {
 
  581         else if( v.
simpleType() == QVariant::Double ) {
 
  584         else if( v.
simpleType() == QVariant::String ) {
 
  593         else if( v.
simpleType() == QVariant::DateTime ) {
 
  597             operator=( toUrlList() += v.
toUrlList() );
 
  599         else if( v.
simpleType() == qMetaTypeId<Resource>() ) {
 
  603             kDebug() << 
"(Variant::append) unknown type: " << v.
simpleType();
 
  610     return( type() == QVariant::Int );
 
  616     return( type() == QVariant::LongLong );
 
  622     return( type() == QVariant::UInt );
 
  628     return( type() == QVariant::ULongLong );
 
  634     return( type() == QVariant::Bool );
 
  640     return( type() == QVariant::Double );
 
  646     return( type() == QVariant::String );
 
  652     return( type() == QVariant::Date );
 
  658     return( type() == QVariant::Time );
 
  664     return( type() == QVariant::DateTime );
 
  670     return( type() == QVariant::Url );
 
  676     return( type() == qMetaTypeId<Resource>() ||
 
  683     return( type() == qMetaTypeId<QList<int> >() );
 
  689     return( type() == qMetaTypeId<QList<uint> >() );
 
  695     return( type() == qMetaTypeId<QList<qlonglong> >() );
 
  701     return( type() == qMetaTypeId<QList<qulonglong> >() );
 
  707     return( type() == qMetaTypeId<QList<bool> >() );
 
  713     return( type() == qMetaTypeId<QList<double> >() );
 
  719     return( type() == QVariant::StringList );
 
  725     return( type() == qMetaTypeId<QList<QDate> >() );
 
  731     return( type() == qMetaTypeId<QList<QTime> >() );
 
  737     return( type() == qMetaTypeId<QList<QDateTime> >() );
 
  743     return( type() == qMetaTypeId<QList<QUrl> >() );
 
  749     return( type() == qMetaTypeId<QList<Resource> >() ||
 
  758         QList<int> l = toIntList();
 
  763     return d->value.toInt();
 
  770         QList<qlonglong> l = toInt64List();
 
  775     return d->value.toLongLong();
 
  782         QList<uint> l = toUnsignedIntList();
 
  787     return d->value.toUInt();
 
  794         QList<qulonglong> l = toUnsignedInt64List();
 
  799     return d->value.toULongLong();
 
  806         QList<bool> l = toBoolList();
 
  811     return d->value.toBool();
 
  818         QList<double> l = toDoubleList();
 
  823     return d->value.toDouble();
 
  831         return toStringList().join( 
"," );
 
  834         return QString::number( toInt() );
 
  836         return QString::number( toInt64() );
 
  837     else if( isUnsignedInt() )
 
  838         return QString::number( toUnsignedInt() );
 
  839     else if( isUnsignedInt64() )
 
  840         return QString::number( toUnsignedInt64() );
 
  842         return ( toBool() ? QString(
"true") : QString(
"false" ) );
 
  843     else if( isDouble() )
 
  844         return QString::number( toDouble(), 
'e', 10 );
 
  846         return Soprano::LiteralValue( toDate() ).toString();
 
  848         return Soprano::LiteralValue( toTime() ).toString();
 
  849     else if( isDateTime() )
 
  850         return Soprano::LiteralValue( toDateTime() ).toString();
 
  852         return KUrl(toUrl()).pathOrUrl();
 
  853     else if( isResource() )
 
  854         return toResource().genericLabel();
 
  856         return d->value.toString();
 
  863         QList<QDate> l = toDateList();
 
  867     return d->value.toDate();
 
  874         QList<QTime> l = toTimeList();
 
  878     return d->value.toTime();
 
  885         QList<QDateTime> l = toDateTimeList();
 
  889     return d->value.toDateTime();
 
  896         QList<QUrl> l = toUrlList();
 
  900     else if(type() == qMetaTypeId<Resource>()) {
 
  901         return toResource().uri();
 
  904     return d->value.toUrl();
 
  910     if(isResourceList() || isUrlList()) {
 
  911         QList<Resource> l = toResourceList();
 
  915     else if(type() == QVariant::Url) {
 
  926     if( isUnsignedInt() ||
 
  934     else if ( isUnsignedIntList() ) {
 
  935         return convertList<uint, int>( d->value.value<QList<uint> >() );
 
  937     else if ( isUnsignedInt64List() ) {
 
  938         return convertList<qulonglong, int>( d->value.value<QList<qulonglong> >() );
 
  940     else if ( isInt64List() ) {
 
  941         return convertList<qlonglong, int>( d->value.value<QList<qlonglong> >() );
 
  944         return d->value.value<QList<int> >();
 
  951     if( isUnsignedInt() ||
 
  956         l.append( toInt64() );
 
  959     else if ( isIntList() ) {
 
  960         return convertList<int, qlonglong>( d->value.value<QList<int> >() );
 
  962     else if ( isUnsignedIntList() ) {
 
  963         return convertList<uint, qlonglong>( d->value.value<QList<uint> >() );
 
  965     else if ( isUnsignedInt64List() ) {
 
  966         return convertList<qulonglong, qlonglong>( d->value.value<QList<qulonglong> >() );
 
  969         return d->value.value<QList<qlonglong> >();
 
  976     if( isUnsignedInt() ||
 
  981         l.append( toUnsignedInt() );
 
  984     else if ( isIntList() ) {
 
  985         return convertList<int, uint>( d->value.value<QList<int> >() );
 
  987     else if ( isUnsignedInt64List() ) {
 
  988         return convertList<qulonglong, uint>( d->value.value<QList<qulonglong> >() );
 
  990     else if ( isInt64List() ) {
 
  991         return convertList<qlonglong, uint>( d->value.value<QList<qlonglong> >() );
 
  994         return d->value.value<QList<uint> >();
 
 1001     if( isUnsignedInt() ||
 
 1003         isUnsignedInt64() ||
 
 1005         QList<qulonglong> l;
 
 1006         l.append( toUnsignedInt() );
 
 1009     else if ( isIntList() ) {
 
 1010         return convertList<int, qulonglong>( d->value.value<QList<int> >() );
 
 1012     else if ( isUnsignedIntList() ) {
 
 1013         return convertList<uint, qulonglong>( d->value.value<QList<uint> >() );
 
 1015     else if ( isInt64List() ) {
 
 1016         return convertList<qlonglong, qulonglong>( d->value.value<QList<qlonglong> >() );
 
 1019         return d->value.value<QList<qulonglong> >();
 
 1028         l.append( toBool() );
 
 1032         return d->value.value<QList<bool> >();
 
 1040         l.append( toDouble() );
 
 1044         return d->value.value<QList<double> >();
 
 1051     QListIterator<T> it( l );
 
 1052     while( it.hasNext() )
 
 1062     if( !d->value.isValid() )
 
 1063         return QStringList();
 
 1066         return QStringList( toString() );
 
 1068     else if( isIntList() )
 
 1069         return convertToStringList<int>( toIntList() );
 
 1070     else if( isInt64List() )
 
 1071         return convertToStringList<qlonglong>( toInt64List() );
 
 1072     else if( isUnsignedIntList() )
 
 1073         return convertToStringList<uint>( toUnsignedIntList() );
 
 1074     else if( isUnsignedInt64List() )
 
 1075         return convertToStringList<qulonglong>( toUnsignedInt64List() );
 
 1076     else if( isBoolList() )
 
 1077         return convertToStringList<bool>( toBoolList() );
 
 1078     else if( isDoubleList() )
 
 1079         return convertToStringList<double>( toDoubleList() );
 
 1080     else if( isDateList() )
 
 1081         return convertToStringList<QDate>( toDateList() );
 
 1082     else if( isTimeList() )
 
 1083         return convertToStringList<QTime>( toTimeList() );
 
 1084     else if( isDateTimeList() )
 
 1085         return convertToStringList<QDateTime>( toDateTimeList() );
 
 1086     else if( isUrlList() )
 
 1087         return convertToStringList<QUrl>( toUrlList() );
 
 1088     else if( isResourceList() )
 
 1089         return convertToStringList<Resource>( toResourceList() );
 
 1091         return d->value.value<QStringList>();
 
 1099         l.append( toDate() );
 
 1103         return d->value.value<QList<QDate> >();
 
 1111         l.append( toTime() );
 
 1115         return d->value.value<QList<QTime> >();
 
 1121     if( isDateTime() ) {
 
 1123         l.append( toDateTime() );
 
 1127         return d->value.value<QList<QDateTime> >();
 
 1133     if( type() == qMetaTypeId<Resource>() ||
 
 1134         type() == QVariant::Url ) {
 
 1136         l.append( toUrl() );
 
 1139     else if( type() == qMetaTypeId<QList<Resource> >() ) {
 
 1141         QList<Resource> rl = toResourceList();
 
 1147         return d->value.value<QList<QUrl> >();
 
 1154     if( type() == qMetaTypeId<Resource>() ||
 
 1155         type() == QVariant::Url ) {
 
 1157         l.append( toResource() );
 
 1160     else if( type() == qMetaTypeId<QList<QUrl> >() ) {
 
 1161         QList<QUrl> urls = toUrlList();
 
 1163         foreach(
const QUrl& url, urls)
 
 1168         return d->value.value<QList<Resource> >();
 
 1177     switch( simpleType() ) {
 
 1179         foreach( 
int i, toIntList() ) {
 
 1184     case QVariant::LongLong:
 
 1185         foreach( qlonglong i, toInt64List() ) {
 
 1190     case QVariant::UInt:
 
 1191         foreach( uint i, toUnsignedIntList() ) {
 
 1196     case QVariant::ULongLong:
 
 1197         foreach( qulonglong i, toUnsignedInt64List() ) {
 
 1202     case QVariant::Bool:
 
 1203         foreach( 
bool i, toBoolList() ) {
 
 1208     case QVariant::Double:
 
 1209         foreach( 
double i, toDoubleList() ) {
 
 1214     case QVariant::Date:
 
 1215         foreach( 
const QDate& i, toDateList() ) {
 
 1220     case QVariant::Time:
 
 1221         foreach( 
const QTime& i, toTimeList() ) {
 
 1226     case QVariant::DateTime:
 
 1227         foreach( 
const QDateTime& i, toDateTimeList() ) {
 
 1233         foreach( 
const QUrl& i, toUrlList() ) {
 
 1239         if( simpleType() == qMetaTypeId<Resource>()) {
 
 1240             foreach( 
const Resource& i, toResourceList() ) {
 
 1245             foreach( 
const QString& i, toStringList() ) {
 
 1258     if( !isValid() || isList() )
 
 1259         return Soprano::Node();
 
 1260     else if( isResource() )
 
 1261         return Soprano::Node( toUrl() );
 
 1263         return Soprano::Node( Soprano::LiteralValue( variant() ) );
 
 1269     QList<Soprano::Node> nl;
 
 1271     if ( isResourceList() ) {
 
 1272         QList<QUrl> urls = toUrlList();
 
 1273         for ( QList<QUrl>::const_iterator it = urls.constBegin(); it != urls.constEnd(); ++it ) {
 
 1274             nl.append( Soprano::Node( *it ) );
 
 1277     else if( isList() ) {
 
 1278         QStringList vl = toStringList();
 
 1279         for( QStringList::const_iterator it = vl.constBegin(); it != vl.constEnd(); ++it ) {
 
 1280             nl.append( Soprano::Node( Soprano::LiteralValue::fromString( *it, ( QVariant::Type )simpleType() ) ) );
 
 1283     else if( isValid() ) {
 
 1284         nl.append( toNode() );
 
 1293     return( isIntList() ||
 
 1295             isUnsignedIntList() ||
 
 1296             isUnsignedInt64List() ||
 
 1310     return d->value.userType();
 
 1317         return QVariant::Int;
 
 1318     else if( isInt64List() )
 
 1319         return QVariant::LongLong;
 
 1320     else if( isUnsignedIntList() )
 
 1321         return QVariant::UInt;
 
 1322     else if( isUnsignedInt64List() )
 
 1323         return QVariant::ULongLong;
 
 1324     else if( isBoolList() )
 
 1325         return QVariant::Bool;
 
 1326     else if( isDoubleList() )
 
 1327         return QVariant::Double;
 
 1328     else if( isStringList() )
 
 1329         return QVariant::String;
 
 1330     else if( isDateList() )
 
 1331         return QVariant::Date;
 
 1332     else if( isTimeList() )
 
 1333         return QVariant::Time;
 
 1334     else if( isDateTimeList() )
 
 1335         return QVariant::DateTime;
 
 1336     else if( isUrlList() )
 
 1337         return QVariant::Url;
 
 1338     else if( isResourceList() )
 
 1339         return qMetaTypeId<Resource>();
 
 1341         return d->value.userType();
 
 1349     if( type == qMetaTypeId<Resource>() ) {
 
 1352     else if ( type == 
int( QVariant::Url ) ) {
 
 1353         return Variant( QUrl( value ) );
 
 1358         return Variant( Soprano::LiteralValue::fromString( value, ( QVariant::Type )type ).variant() );
 
 1371     if ( node.isResource() ) {
 
 1374     else if ( node.isLiteral() ) {
 
 1386     if( valueNodes.size() == 1 ) {
 
 1390         if( valueNodes.first().isResource() ) {
 
 1391             QList<Nepomuk2::Resource> resList;
 
 1392             Q_FOREACH( 
const Soprano::Node & n, valueNodes ) {
 
 1393                 if( n.isResource() )
 
 1398         else if( valueNodes.first().isLiteral() ) {
 
 1399             QList<Variant> varList;
 
 1400             Q_FOREACH( 
const Soprano::Node & n, valueNodes ) {
 
 1415     if( isUrl() || isUrlList() )
 
 1416         return other.
toUrlList() == toUrlList();
 
 1417     else if( isResource() || isResourceList() )
 
 1420     if( other.
simpleType() != this->simpleType() )
 
 1423     if( isInt() || isIntList() )
 
 1424         return other.
toIntList() == toIntList();
 
 1425     else if( isInt64() || isInt64List() )
 
 1427     else if( isUnsignedInt() || isUnsignedIntList() )
 
 1429     else if( isUnsignedInt64() || isUnsignedInt64List() )
 
 1431     else if( isBool() || isBoolList() )
 
 1433     else if( isDouble() || isDoubleList() )
 
 1435     else if( isString() || isStringList() )
 
 1436         return other.d->value.value<QStringList>() == d->value.value<QStringList>();
 
 1437     else if( isDate() || isDateList() )
 
 1439     else if( isTime() || isTimeList() )
 
 1441     else if( isDateTime() || isDateTimeList() )
 
 1444         return ( d->value == other.d->value );
 
 1450     return !operator==( other );
 
 1462     return d->value.isValid();
 
 1469         dbg.nospace() << 
"Nepomuk2::Variant(" << v.
toStringList() << 
"@list)";
 
 1471         dbg.nospace() << 
"Nepomuk2::Variant(Nepomuk2::Resource(" << v.
toString() << 
"))";
 
 1473         dbg.nospace() << 
"Nepomuk2::Variant(" << v.
variant() << 
")";
 
bool isResourceList() const 
 
QUrl toUrl() const 
Convert into a QUrl value. 
 
QList< int > toIntList() const 
 
bool isDoubleList() const 
 
bool isDateTimeList() const 
 
bool operator==(const Variant &other) const 
Does compare two Variant objects. 
 
uint toUnsignedInt() const 
Convert into a uint value. 
 
QDataStream & operator<<(QDataStream &, const Nepomuk2::SimpleResource &)
 
bool isUnsignedInt64() const 
 
bool isStringList() const 
 
QDate toDate() const 
Convert into a QDate value. 
 
bool isList() const 
This methods does not handle all list types. 
 
double toDouble() const 
Convert into a double value. 
 
qulonglong toUnsignedInt64() const 
Convert into a qulonglong value. 
 
bool isUnsignedIntList() const 
 
QList< Variant > toVariantList() const 
Convert a Variant to a list of Variants. 
 
The Nepomuk Variant extends over QVariant by introducing direct support for Resource embedding...
 
Resource toResource() const 
Convert into a Resource value. 
 
static Variant fromNode(const Soprano::Node &node)
Create a Variant object from a Soprano::Node. 
 
QList< qlonglong > toInt64List() const 
 
QList< double > toDoubleList() const 
 
QList< QTime > toTimeList() const 
 
QStringList toStringList() const 
Just like the toString method toStringList is able to convert all supported types into a list of stri...
 
QList< bool > toBoolList() const 
 
int toInt() const 
Convert into an int value. 
 
Variant & operator=(const Variant &)
 
QList< Resource > toResourceList() const 
 
static Variant fromNodeList(const QList< Soprano::Node > &node)
Create a Variant object from a list of Soprano::Node. 
 
qlonglong toInt64() const 
Convert into a qlonglong value. 
 
QList< uint > toUnsignedIntList() const 
 
bool operator!=(const Variant &other) const 
Inverse of operator==. 
 
QList< QDate > toDateList() const 
 
QDateTime toDateTime() const 
Convert into a QDateTime value. 
 
bool isUnsignedInt64List() const 
 
QList< qulonglong > toUnsignedInt64List() const 
 
QList< QUrl > toUrlList() const 
 
bool isUnsignedInt() const 
 
static Variant fromString(const QString &value, int type)
Create a Variant object by parsing string value based on type. 
 
QTime toTime() const 
Convert into a QTime value. 
 
QString toString() const 
The toString() method is a little more powerful than other toXXX methods since it actually converts a...
 
Resource is the central object type in Nepomuk. 
 
void append(int i)
Append i to this variant. 
 
QStringList convertToStringList(const QList< T > &l)
 
QUrl uri() const 
The URI of the resource, uniquely identifying it. 
 
Soprano::Node toNode() const 
Convert a Variant to a Node. 
 
QList< QDateTime > toDateTimeList() const 
 
bool toBool() const 
Convert into a bool value. 
 
QList< Soprano::Node > toNodeList() const 
Convert a Variant to a a list of Nodes.