本文整理汇总了C++中QVersitProperty::variantValue方法的典型用法代码示例。如果您正苦于以下问题:C++ QVersitProperty::variantValue方法的具体用法?C++ QVersitProperty::variantValue怎么用?C++ QVersitProperty::variantValue使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QVersitProperty
的用法示例。
在下文中一共展示了QVersitProperty::variantValue方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: modifiedProperty
/*!
* Encodes the \a property and writes it to the device.
*/
void QVCard30Writer::encodeVersitProperty(const QVersitProperty& property)
{
QVersitProperty modifiedProperty(property);
QString name = mPropertyNameMappings.value(property.name(),property.name());
modifiedProperty.setName(name);
encodeGroupsAndName(modifiedProperty);
QVariant variant(modifiedProperty.variantValue());
if (variant.type() == QVariant::ByteArray) {
modifiedProperty.insertParameter(QLatin1String("ENCODING"), QLatin1String("b"));
}
encodeParameters(modifiedProperty.parameters());
writeString(QLatin1String(":"));
QString renderedValue;
QByteArray renderedBytes;
if (variant.canConvert<QVersitDocument>()) {
QVersitDocument embeddedDocument = variant.value<QVersitDocument>();
QByteArray data;
QBuffer buffer(&data);
buffer.open(QIODevice::WriteOnly);
QVCard30Writer subWriter(mType);
subWriter.setCodec(mCodec);
subWriter.setDevice(&buffer);
subWriter.encodeVersitDocument(embeddedDocument);
QString documentString(mCodec->toUnicode(data));
backSlashEscape(&documentString);
renderedValue = documentString;
} else if (variant.type() == QVariant::String) {
renderedValue = variant.toString();
if (property.valueType() != QVersitProperty::PreformattedType) {
backSlashEscape(&renderedValue);
}
} else if (variant.type() == QVariant::StringList) {
// We need to backslash escape and concatenate the values in the list
QStringList values = property.variantValue().toStringList();
QString separator;
if (property.valueType() == QVersitProperty::CompoundType) {
separator = QLatin1String(";");
} else {
if (property.valueType() != QVersitProperty::ListType) {
qWarning("Variant value is a QStringList but the property's value type is neither "
"CompoundType or ListType");
}
// Assume it's a ListType
separator = QLatin1String(",");
}
bool first = true;
foreach (QString value, values) {
if (!(value.isEmpty() && property.valueType() == QVersitProperty::ListType)) {
if (!first) {
renderedValue += separator;
}
backSlashEscape(&value);
renderedValue += value;
first = false;
}
}
} else if (variant.type() == QVariant::ByteArray) {
示例2: variant
/*!
* Encodes the \a property and writes it to the device.
*/
void QVCard21Writer::encodeVersitProperty(const QVersitProperty& property)
{
encodeGroupsAndName(property);
QMultiHash<QString,QString> parameters = property.parameters();
QVariant variant(property.variantValue());
QString renderedValue;
QByteArray renderedBytes;
/* Structured values need to have their components backslash-escaped (in vCard 2.1, semicolons
must be escaped for compound values and commas must be escaped for list values). */
if (variant.type() == QVariant::StringList) {
QStringList values = property.variantValue().toStringList();
QString separator;
if (property.valueType() == QVersitProperty::CompoundType) {
separator = QLatin1String(";");
} else {
if (property.valueType() != QVersitProperty::ListType) {
qWarning("Variant value is a QStringList but the property's value type is neither "
"CompoundType or ListType");
}
// Assume it's a ListType
separator = QLatin1String(",");
}
QString replacement = QLatin1Char('\\') + separator;
QRegExp separatorRegex = QRegExp(separator);
// Check first if any of the values need to be UTF-8 encoded (if so, all of them must be
// UTF-8 encoded)
bool forceUtf8 = requiresUtf8(values);
bool first = true;
foreach (QString value, values) {
if (!(value.isEmpty() && property.valueType() == QVersitProperty::ListType)) {
encodeVersitValue(parameters, value, forceUtf8);
if (!first) {
renderedValue += separator;
}
renderedValue += value.replace(separatorRegex, replacement);
first = false;
}
}
} else if (variant.type() == QVariant::String) {
示例3: foreach
QDebug operator<<(QDebug dbg, const QVersitProperty& property)
{
QStringList groups = property.groups();
QString name = property.name();
QMultiHash<QString,QString> parameters = property.parameters();
dbg.nospace() << "QVersitProperty(";
foreach (const QString& group, groups) {
dbg.nospace() << group << '.';
}
dbg.nospace() << name;
QHash<QString,QString>::const_iterator it;
for (it = parameters.constBegin(); it != parameters.constEnd(); ++it) {
dbg.nospace() << ';' << it.key() << '=' << it.value();
}
if (property.valueType() == QVersitProperty::VersitDocumentType)
dbg.nospace() << ':' << property.value<QVersitDocument>();
else
dbg.nospace() << ':' << property.variantValue();
dbg.nospace() << ')';
return dbg.maybeSpace();
}
示例4: propertyProcessed
void SeasidePhotoHandler::propertyProcessed(const QVersitDocument &, const QVersitProperty &property, const QContact &, bool *alreadyProcessed, QList<QContactDetail> * updatedDetails)
{
// if the property is a PHOTO property, store the data to disk
// and then create an avatar detail which points to it.
if (property.name().toLower() != QLatin1String("photo"))
return;
#ifndef QT_VERSION_5
// The Qt4 / QtMobility version has QContactThumbnail support.
// We need to remove any such thumbnail detail from the output,
// as some backends (such as qtcontacts-sqlite) do not support
// that detail type.
for (int i = 0; i < updatedDetails->size(); ++i) {
if (updatedDetails->at(i).definitionName() == QContactThumbnail::DefinitionName) {
updatedDetails->removeAt(i);
--i;
}
}
#endif
// The data might be either a URL, a file path, or encoded image data
// It's hard to tell what the content is, because versit removes the encoding
// information in the process of decoding the data...
// Try to interpret the data as a URL
QString path(property.variantValue().toString());
QUrl url(path);
if (url.isValid()) {
// Treat remote URL as a true URL, and reference it in the avatar
if (!url.scheme().isEmpty() && !url.isLocalFile()) {
QContactAvatar newAvatar;
newAvatar.setImageUrl(url);
updatedDetails->append(newAvatar);
// we have successfully processed this PHOTO property.
*alreadyProcessed = true;
return;
}
}
if (!url.isValid()) {
// See if we can resolve the data as a local file path
url = QUrl::fromLocalFile(path);
}
QByteArray photoData;
if (url.isValid()) {
// Try to read the data from the referenced file
const QString filePath(url.path());
if (QFile::exists(filePath)) {
QFile file(filePath);
if (!file.open(QIODevice::ReadOnly)) {
qWarning() << "Unable to process photo data as file:" << path;
return;
} else {
photoData = file.readAll();
}
}
}
if (photoData.isEmpty()) {
// Try to interpret the encoded property data as the image
photoData = property.variantValue().toByteArray();
if (photoData.isEmpty()) {
qWarning() << "Failed to extract avatar data from vCard PHOTO property";
return;
}
}
QImage img;
bool loaded = img.loadFromData(photoData);
if (!loaded) {
qWarning() << "Failed to load avatar image from vCard PHOTO data";
return;
}
// We will save the avatar image to disk in the system's data location
// Since we're importing user data, it should not require privileged access
const QString subdirectory(QString::fromLatin1(".local/share/system/Contacts/avatars"));
const QString photoDirPath(QDir::home().filePath(subdirectory));
// create the photo file dir if it doesn't exist.
QDir photoDir;
if (!photoDir.mkpath(photoDirPath)) {
qWarning() << "Failed to create avatar image directory when loading avatar image from vCard PHOTO data";
return;
}
// construct the filename of the new avatar image.
QString photoFilePath = QString::fromLatin1(QCryptographicHash::hash(photoData, QCryptographicHash::Md5).toHex());
photoFilePath = photoDirPath + QDir::separator() + photoFilePath + QString::fromLatin1(".jpg");
// save the file to disk
bool saved = img.save(photoFilePath);
if (!saved) {
qWarning() << "Failed to save avatar image from vCard PHOTO data to" << photoFilePath;
return;
}
//.........这里部分代码省略.........