KDE 4.5 PyKDE API Reference

- KDE's Python API

# Variant Class Reference

`from PyKDE4.nepomuk import *`

Namespace: Nepomuk

## Detailed Description

\class Variant variant.h Nepomuk/Variant

The %Nepomuk Variant extends over QVariant by introducing direct support for Resource embedding, automatic list conversion and a restricted set of supported types.

Important differences are:

- No new types can be added other than the ones that have defined
constructors and get-methods
- Variant supports automatic list generation. For example a Variant
containing an int also can produce an int-list via the toIntList method.
- toString and toStringList always return a valid list and do automatic
conversion from the actual type used in the Variant. Thus, if one only needs to display the value in a Variant toString and toStringList do the job.
- Variant comes with direct support for Resource. There is one special
thing about QUrl Variants though: for both isUrl() and isResource() return true. However, toUrl() will return different values for Resource and for QUrl Variants: in the former case the actual Resource.resourceUri() is returned which can be different in case of file:/ URLs.

Author:
  Sebastian Trueg <trueg@kde.org>

## Methods
| __init__ (self)
| __init__ (self, Nepomuk.Variant other)
| __init__ (self, QVariant other)
| __init__ (self, long i)
| __init__ (self, float d)
| __init__ (self, QString string)
| __init__ (self, QDate date)
| __init__ (self, QTime time)
| __init__ (self, QDateTime datetime)
| __init__ (self, QUrl url)
| __init__ (self, Nepomuk.Resource r)
| __init__ (self, [int] i)
| __init__ (self, [long] i)
| __init__ (self, [float] d)
| __init__ (self, QStringList stringlist)
| __init__ (self, [QDate] date)
| __init__ (self, [QTime] time)
| __init__ (self, [QDateTime] datetime)
| __init__ (self, [QUrl] url)
| __init__ (self, [Nepomuk.Resource] r)
| __init__ (self, [Nepomuk.Variant] vl)
| append (self, long i)
| append (self, float d)
| append (self, QString string)
| append (self, QDate date)
| append (self, QTime time)
| append (self, QDateTime datetime)
| append (self, QUrl url)
| append (self, Nepomuk.Resource r)
| append (self, Nepomuk.Variant v)
bool | isBool (self)
bool | isBoolList (self)
bool | isDate (self)
bool | isDateList (self)
bool | isDateTime (self)
bool | isDateTimeList (self)
bool | isDouble (self)
bool | isDoubleList (self)
bool | isInt (self)
bool | isInt64 (self)
bool | isInt64List (self)
bool | isIntList (self)
bool | isList (self)
bool | isResource (self)
bool | isResourceList (self)
bool | isString (self)
bool | isStringList (self)
bool | isTime (self)
bool | isTimeList (self)
bool | isUnsignedInt (self)
bool | isUnsignedInt64 (self)
bool | isUnsignedInt64List (self)
bool | isUnsignedIntList (self)
bool | isUrl (self)
bool | isUrlList (self)
bool | isValid (self)
bool | operator != (self, Nepomuk.Variant other)
bool | operator == (self, Nepomuk.Variant other)
int | simpleType (self)
bool | toBool (self)
QDate | toDate (self)
[QDate] | toDateList (self)
QDateTime | toDateTime (self)
[QDateTime] | toDateTimeList (self)
float | toDouble (self)
[float] | toDoubleList (self)
int | toInt (self)
long | toInt64 (self)
[int] | toIntList (self)
Nepomuk.Resource | toResource (self)
[Nepomuk.Resource] | toResourceList (self)
QString | toString (self)
QStringList | toStringList (self)
QTime | toTime (self)
[QTime] | toTimeList (self)
long | toUnsignedInt (self)
long | toUnsignedInt64 (self)
[long] | toUnsignedIntList (self)
QUrl | toUrl (self)
[QUrl] | toUrlList (self)
[Nepomuk.Variant] | toVariantList (self)
int | type (self)
QVariant | variant (self)
## Static Methods
Nepomuk.Variant | fromNode (Soprano.Node node)
Nepomuk.Variant | fromString (QString value, int type)

## Method Documentation

__init__ | ( |  | self ) |

__init__ | ( | self, |
|  | Nepomuk.Variant | other
| ) |  |  |

Will create an invalid Variant if other has an unsupported type.

__init__ | ( | self, |
|  | QVariant | other
| ) |  |  |

Will create an invalid Variant if other has an unsupported type.

__init__ | ( | self, |
|  | long | i
| ) |  |  |

__init__ | ( | self, |
|  | float | d
| ) |  |  |

__init__ | ( | self, |
|  | QString | string
| ) |  |  |

__init__ | ( | self, |
|  | QDate | date
| ) |  |  |

__init__ | ( | self, |
|  | QTime | time
| ) |  |  |

__init__ | ( | self, |
|  | QDateTime | datetime
| ) |  |  |

__init__ | ( | self, |
|  | QUrl | url
| ) |  |  |

__init__ | ( | self, |
|  | Nepomuk.Resource | r
| ) |  |  |

__init__ | ( | self, |
|  | [int] | i
| ) |  |  |

__init__ | ( | self, |
|  | [long] | i
| ) |  |  |

__init__ | ( | self, |
|  | [float] | d
| ) |  |  |

__init__ | ( | self, |
|  | QStringList | stringlist
| ) |  |  |

__init__ | ( | self, |
|  | [QDate] | date
| ) |  |  |

__init__ | ( | self, |
|  | [QTime] | time
| ) |  |  |

__init__ | ( | self, |
|  | [QDateTime] | datetime
| ) |  |  |

__init__ | ( | self, |
|  | [QUrl] | url
| ) |  |  |

__init__ | ( | self, |
|  | [Nepomuk.Resource] | r
| ) |  |  |

__init__ | ( | self, |
|  | [Nepomuk.Variant] | vl
| ) |  |  |

Create a new Variant from a list of Variants.

Since:
  4.3

append | ( | self, |
|  | long | i
| ) |  |  |

Appends the value stored in v to the list in this Variant. If this Variant contains a value with the same simple type as v they are merged into a list. Otherwise this Variant will contain one list of simple type v.simpleType()

append | ( | self, |
|  | float | d
| ) |  |  |

Appends the value stored in v to the list in this Variant. If this Variant contains a value with the same simple type as v they are merged into a list. Otherwise this Variant will contain one list of simple type v.simpleType()

append | ( | self, |
|  | QString | string
| ) |  |  |

Appends the value stored in v to the list in this Variant. If this Variant contains a value with the same simple type as v they are merged into a list. Otherwise this Variant will contain one list of simple type v.simpleType()

append | ( | self, |
|  | QDate | date
| ) |  |  |

Appends the value stored in v to the list in this Variant. If this Variant contains a value with the same simple type as v they are merged into a list. Otherwise this Variant will contain one list of simple type v.simpleType()

append | ( | self, |
|  | QTime | time
| ) |  |  |

Appends the value stored in v to the list in this Variant. If this Variant contains a value with the same simple type as v they are merged into a list. Otherwise this Variant will contain one list of simple type v.simpleType()

append | ( | self, |
|  | QDateTime | datetime
| ) |  |  |

Appends the value stored in v to the list in this Variant. If this Variant contains a value with the same simple type as v they are merged into a list. Otherwise this Variant will contain one list of simple type v.simpleType()

append | ( | self, |
|  | QUrl | url
| ) |  |  |

Appends the value stored in v to the list in this Variant. If this Variant contains a value with the same simple type as v they are merged into a list. Otherwise this Variant will contain one list of simple type v.simpleType()

append | ( | self, |
|  | Nepomuk.Resource | r
| ) |  |  |

Appends the value stored in v to the list in this Variant. If this Variant contains a value with the same simple type as v they are merged into a list. Otherwise this Variant will contain one list of simple type v.simpleType()

append | ( | self, |
|  | Nepomuk.Variant | v
| ) |  |  |

Appends the value stored in v to the list in this Variant. If this Variant contains a value with the same simple type as v they are merged into a list. Otherwise this Variant will contain one list of simple type v.simpleType()

bool isBool | ( |  | self ) |

bool isBoolList | ( |  | self ) |

bool isDate | ( |  | self ) |

bool isDateList | ( |  | self ) |

bool isDateTime | ( |  | self ) |

bool isDateTimeList | ( |  | self ) |

bool isDouble | ( |  | self ) |

bool isDoubleList | ( |  | self ) |

bool isInt | ( |  | self ) |

bool isInt64 | ( |  | self ) |

bool isInt64List | ( |  | self ) |

bool isIntList | ( |  | self ) |

bool isList | ( |  | self ) |

This methods does not handle all list types. It checks the following:

- QList<Resource>
- QList<int>
- QList<double>
- QList<bool>
- QList<QDate>
- QList<QTime>
- QList<QDateTime>
- QList<QUrl>
- QList<String> (QStringList)

bool isResource | ( |  | self ) |

bool isResourceList | ( |  | self ) |

bool isString | ( |  | self ) |

bool isStringList | ( |  | self ) |

bool isTime | ( |  | self ) |

bool isTimeList | ( |  | self ) |

bool isUnsignedInt | ( |  | self ) |

bool isUnsignedInt64 | ( |  | self ) |

bool isUnsignedInt64List | ( |  | self ) |

bool isUnsignedIntList | ( |  | self ) |

bool isUrl | ( |  | self ) |

bool isUrlList | ( |  | self ) |

bool isValid | ( |  | self ) |

bool operator != | ( | self, |
|  | Nepomuk.Variant | other
| ) |  |  |

Inverse of operator==

bool operator == | ( | self, |
|  | Nepomuk.Variant | other
| ) |  |  |

Does compare two Variant objects. single-valued lists are treated as the single value itself. For example a QStringList variant with one element "x" equals a QString variant with value "x".

int simpleType | ( |  | self ) |

Returns:
  the type of the simple value, i.e. with the list stripped.

bool toBool | ( |  | self ) |

Convert into a bool value.

Will return the first value of a bool list.

QDate toDate | ( |  | self ) |

Convert into a QDate value.

Will return the first value of a QDate list.

[QDate] toDateList | ( |  | self ) |

QDateTime toDateTime | ( |  | self ) |

Convert into a QDateTime value.

Will return the first value of a QDateTime list.

[QDateTime] toDateTimeList | ( |  | self ) |

float toDouble | ( |  | self ) |

Convert into a double value.

Will return the first value of a double list.

[float] toDoubleList | ( |  | self ) |

int toInt | ( |  | self ) |

Convert into an int value. Returns a valid value for all decimal types.

Will return the first value of an int list.

long toInt64 | ( |  | self ) |

Convert into a qlonglong value. Returns a valid value for all decimal types.

Will return the first value of a qlonglong list.

[int] toIntList | ( |  | self ) |

Nepomuk.Resource toResource | ( |  | self ) |

Convert into a Resource value.

Will return the first value of a Resource list. Will also convert QUrl variants.

[Nepomuk.Resource] toResourceList | ( |  | self ) |

QString toString | ( |  | self ) |

The toString() method is a little more powerful than other toXXX methods since it actually converts all values to string. Thus, toString should work always (even list variants are converted to a comma-separated list)

Resources are converted to a string representation of their URI.

QStringList toStringList | ( |  | self ) |

Just like the toString method toStringList is able to convert all supported types into a list of strings.

QTime toTime | ( |  | self ) |

Convert into a QTime value.

Will return the first value of a QTime list.

[QTime] toTimeList | ( |  | self ) |

long toUnsignedInt | ( |  | self ) |

Convert into a uint value. Returns a valid value for all decimal types.

Will return the first value of a uint list.

long toUnsignedInt64 | ( |  | self ) |

Convert into a qulonglong value. Returns a valid value for all decimal types.

Will return the first value of a qulonglong list.

[long] toUnsignedIntList | ( |  | self ) |

QUrl toUrl | ( |  | self ) |

Convert into a QUrl value. Can handle both QUrl and Resource variants. The latter will be converted into its resource URI

Will return the first value of a QUrl list.

\sa Resource.resourceUri

[QUrl] toUrlList | ( |  | self ) |

[Nepomuk.Variant] toVariantList | ( |  | self ) |

Convert a Variant to a list of Variants.

Since:
  4.3

int type | ( |  | self ) |

Returns:
  the QT Meta type id of the type

QVariant variant | ( |  | self ) |

## Static Method Documentation

Nepomuk.Variant fromNode | ( | Soprano.Node | node
| ) |  |  |

Create a Variant object from a Soprano.Node.

Since:
  4.5

Nepomuk.Variant fromString | ( | QString | value,
|  | int | type
| ) |  |  |

Create a Variant object by parsing string value based on type. If type is unknown a simple string Variant object is returned containing the plain string value.