本文整理汇总了C++中QVersitProperty类的典型用法代码示例。如果您正苦于以下问题:C++ QVersitProperty类的具体用法?C++ QVersitProperty怎么用?C++ QVersitProperty使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了QVersitProperty类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: vCard30
void tst_QVersitWriter::testByteArrayOutput()
{
const QByteArray vCard30(
"BEGIN:VCARD\r\n"
"VERSION:3.0\r\n"
"FN:John\r\n"
"END:VCARD\r\n");
delete mWriter; // we don't want the init()ed writer.
QByteArray output;
mWriter = new QVersitWriter(&output);
QVERIFY(mWriter->device() == 0);
QVersitDocument document(QVersitDocument::VCard30Type);
document.setComponentType(QStringLiteral("VCARD"));
QVersitProperty property;
property.setName(QString(QStringLiteral("FN")));
property.setValue(QStringLiteral("John"));
document.addProperty(property);
QVERIFY2(mWriter->startWriting(document), QString::number(mWriter->error()).toLatin1().data());
QVERIFY2(mWriter->waitForFinished(), QString::number(mWriter->error()).toLatin1().data());
QCOMPARE(output, vCard30);
}
示例2: QVERIFY
void tst_QVersitDocument::testEquality()
{
QVersitDocument document1;
QVersitDocument document2;
QVERIFY(document1.isEmpty());
QVERIFY(document1 == document2);
QVERIFY(!(document1 != document2));
QVersitProperty property;
property.setName(QLatin1String("FN"));
property.setValue(QLatin1String("John Citizen"));
document2.addProperty(property);
QVERIFY(!(document1 == document2));
QVERIFY(document1 != document2);
QVERIFY(!document2.isEmpty());
document1.addProperty(property);
QVERIFY(document1 == document2);
QVERIFY(!(document1 != document2));
document2.clear();
QVERIFY(document2.isEmpty());
document1.clear();
QVERIFY(document1 == document2);
QVERIFY(!(document1 != document2));
document2.setType(QVersitDocument::VCard21Type);
QVERIFY(!(document1 == document2));
QVERIFY(document1 != document2);
QVERIFY(!document2.isEmpty());
document2 = document1;
QVERIFY(document1 == document2);
}
示例3: propertyProcessed
void CntVersitPrefPlugin::propertyProcessed(
const QVersitDocument& document,
const QVersitProperty& property,
const QContact& contact,
bool* alreadyProcessed,
QList<QContactDetail>* updatedDetails)
{
Q_UNUSED(document);
Q_UNUSED(contact);
if (*alreadyProcessed && !updatedDetails->isEmpty())
{
QStringList typeParameters = property.parameters().values(QLatin1String("TYPE"));
if (typeParameters.contains(QLatin1String("PREF"), Qt::CaseInsensitive))
{
if ((mDetailMappings.value(property.name()) == QContactPhoneNumber::DefinitionName) ||
(mDetailMappings.value(property.name()) == QContactEmailAddress::DefinitionName) ||
(mDetailMappings.value(property.name()) == QContactOnlineAccount::DefinitionName) ||
(mDetailMappings.value(property.name()) == QContactUrl::DefinitionName))
{
// This method is called before the corresponding detail gets imported to QContact.
// setPreferredDetail() cannot be called here -> detail is stored and will be set
// preferred after whole versit document is processed
mPrefDetailList.append(updatedDetails->last());
}
}
}
}
示例4: myCard
void MT_CntVersitMyCardPlugin::exportOwnContact()
{
//create contact
QContact phonecontact;
QContactName contactName;
contactName.setFirstName("Jo");
contactName.setLastName("Black");
phonecontact.saveDetail(&contactName);
QContactPhoneNumber number;
number.setContexts("Home");
number.setSubTypes("Mobile");
number.setNumber("+02644424429");
phonecontact.saveDetail(&number);
//set MyCard detail
QContactDetail myCard(MYCARD_DEFINTION_NAME);
phonecontact.saveDetail(&myCard);
//export
QList<QContact> list;
list.append(phonecontact);
QVersitContactExporter exporter;
QVERIFY(exporter.exportContacts(list, QVersitDocument::VCard21Type));
QList<QVersitDocument> documents = exporter.documents();
//X-SELF property is exported if MyCard
QVersitDocument document = documents.first();
QVersitProperty property;
property.setName(QLatin1String("X-SELF"));
property.setValue("0");
bool propertyFound = document.properties().contains(property);
QVERIFY(propertyFound);
}
示例5: QCOMPARE
void tst_QVersitDocument::testRemoveProperty()
{
// Remove an empty property.
QCOMPARE(mVersitDocument->properties().count(), 0);
QVersitProperty property;
mVersitDocument->addProperty(property);
mVersitDocument->removeProperty(property);
QCOMPARE(mVersitDocument->properties().count(), 0);
// A full property.
property.setName(QLatin1String("TEL"));
property.setGroups(QStringList(QLatin1String("HOME")));
QMultiHash<QString, QString> params;
params.insert(QLatin1String("TYPE"), QLatin1String("HOME"));
property.setParameters(params);
property.setValue(QLatin1String("123"));
mVersitDocument->addProperty(property);
QCOMPARE(mVersitDocument->properties().count(), 1);
QVersitProperty property2;
property2.setName(QLatin1String("TEL"));
// Remove with a partial property fails.
mVersitDocument->removeProperty(property2);
QCOMPARE(mVersitDocument->properties().count(), 1);
property2.setGroups(QStringList(QLatin1String("HOME")));
property2.setParameters(params);
property2.setValue(QLatin1String("123"));
// Remove with a fully specified property succeeds.
mVersitDocument->removeProperty(property2);
QCOMPARE(mVersitDocument->properties().count(), 0);
}
示例6: propertyProcessed
void SeasidePropertyHandler::propertyProcessed(const QVersitDocument &, const QVersitProperty &property, const QContact &, bool *alreadyProcessed, QList<QContactDetail> * updatedDetails)
{
if (property.name().toLower() == QLatin1String("photo")) {
processPhoto(property, alreadyProcessed, updatedDetails);
} else if (property.name().toLower() == QLatin1String("x-nemomobile-onlineaccount-demo")) {
processOnlineAccount(property, alreadyProcessed, updatedDetails);
}
}
示例7: encodeGroupsAndName
/*!
* Encodes the groups and name in the \a property and writes it to the device
*/
void QVersitDocumentWriter::encodeGroupsAndName(const QVersitProperty& property)
{
QStringList groups = property.groups();
if (!groups.isEmpty()) {
writeString(groups.join(QStringLiteral(".")));
writeString(QStringLiteral("."));
}
writeString(property.name());
}
示例8: contactProcessed
void contactProcessed(const QContact& contact,
QVersitDocument* document)
{
Q_UNUSED(contact)
QVersitProperty property;
property.setName("TEST-PROPERTY");
property.setValue("3");
document->addProperty(property);
}
示例9: testEmbeddedDocument
void tst_QVersitProperty::testEmbeddedDocument()
{
QVersitDocument document;
QVersitProperty property;
property.setName(QLatin1String("X-tension"));
document.addProperty(property);
mVersitProperty->setValue(QVariant::fromValue(document));
QList<QVersitProperty> embeddedDocumentProperties =
mVersitProperty->value<QVersitDocument>().properties();
QCOMPARE(embeddedDocumentProperties.count(),1);
QCOMPARE(embeddedDocumentProperties[0].name(),QLatin1String("X-TENSION"));
}
示例10: qHash
/*! Returns the hash value for \a key. */
uint qHash(const QVersitProperty &key)
{
uint hash = QT_PREPEND_NAMESPACE(qHash)(key.name()) + QT_PREPEND_NAMESPACE(qHash)(key.value());
foreach (const QString& group, key.groups()) {
hash += QT_PREPEND_NAMESPACE(qHash)(group);
}
QHash<QString,QString>::const_iterator it = key.parameters().constBegin();
QHash<QString,QString>::const_iterator end = key.parameters().constEnd();
while (it != end) {
hash += QT_PREPEND_NAMESPACE(qHash)(it.key()) + QT_PREPEND_NAMESPACE(qHash)(it.value());
++it;
}
return hash;
}
示例11: foreach
foreach(const QVersitProperty& expectedProperty, expectedProperties) {
QList<QVersitProperty> actualProperties =
findPropertiesByName(subDocuments.first(), expectedProperty.name());
if (!actualProperties.contains(expectedProperty)) {
qDebug() << "Actual:" << actualProperties;
qDebug() << "Expected to find:" << expectedProperty;
QVERIFY(false);
}
}
示例12: 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) {
示例13: propertyProcessed
bool QVCardRestoreHandler::propertyProcessed(
const QVersitProperty& property,
QList<QContactDetail>* updatedDetails)
{
bool success = false;
QString group;
if (!property.groups().isEmpty())
group = property.groups().first();
if (property.name() == PropertyName) {
if (property.groups().size() != 1)
return false;
QMultiHash<QString, QString> parameters = property.parameters();
QContactDetail::DetailType detailType = QContactDetail::DetailType(parameters.value(DetailTypeParameter).toUInt());
QString fieldName = parameters.value(FieldParameter);
// Find a detail previously seen with the same definitionName, which was generated from
// a property from the same group
QContactDetail detail(detailType);
foreach (const QContactDetail& previousDetail, mDetailGroupMap.detailsInGroup(group)) {
if (previousDetail.type() == detailType) {
detail = previousDetail;
}
}
// If not found, it's a new empty detail with the definitionName set.
detail.setValue(fieldName.toInt(), deserializeValue(property));
// Replace the equivalent detail in updatedDetails with the new one
QMutableListIterator<QContactDetail> it(*updatedDetails);
while (it.hasNext()) {
if (it.next().key() == detail.key()) {
it.remove();
break;
}
}
updatedDetails->append(detail);
success = true;
}
if (!group.isEmpty()) {
// Keep track of which details were generated from which Versit groups
foreach (const QContactDetail& detail, *updatedDetails) {
mDetailGroupMap.insert(group, detail);
}
}
示例14: testWritingVersions
void tst_QVersitWriter::testWritingVersions()
{
mWriter->setDevice(mOutputDevice);
mOutputDevice->open(QBuffer::ReadWrite);
QVersitDocument document;
QVersitProperty property;
property.setName(QString(QString::fromLatin1("FN")));
property.setValue(QString::fromLatin1("John"));
document.addProperty(property);
QByteArray vCard30(
"BEGIN:VCARD\r\n"
"VERSION:3.0\r\n"
"FN:John\r\n"
"END:VCARD\r\n");
QByteArray vCard21(
"BEGIN:VCARD\r\n"
"VERSION:2.1\r\n"
"FN:John\r\n"
"END:VCARD\r\n");
// Given no type or componentType, it should be vCard 3.0
QVERIFY(mWriter->startWriting(document));
mWriter->waitForFinished();
QCOMPARE(mOutputDevice->buffer(), vCard30);
// document type should override the guess
document.setType(QVersitDocument::VCard21Type);
mOutputDevice->buffer().clear();
mOutputDevice->seek(0);
QVERIFY(mWriter->startWriting(document));
mWriter->waitForFinished();
QCOMPARE(mOutputDevice->buffer(), vCard21);
// param to startWriting should override document type
mOutputDevice->buffer().clear();
mOutputDevice->seek(0);
QVERIFY(mWriter->startWriting(document, QVersitDocument::VCard30Type));
mWriter->waitForFinished();
QCOMPARE(mOutputDevice->buffer(), vCard30);
}
示例15: importer
void tst_QVersitContactPlugins::testImporterPlugins() {
QVersitContactImporter importer("Test");
QVersitDocument document;
document.setComponentType("VCARD");
QVersitProperty property;
property.setName("FN");
property.setValue("Bob");
document.addProperty(property);
QVERIFY(importer.importDocuments(QList<QVersitDocument>() << document));
QCOMPARE(importer.contacts().size(), 1);
QList<QContactDetail> details(importer.contacts().first().details("TestDetail"));
QCOMPARE(details.size(), 5);
// The plugins have had their index set such that they should be executed in reverse order
// Check that they are all loaded, and run in the correct order
QCOMPARE(details.at(0).value<int>("Plugin"), 5);
QCOMPARE(details.at(1).value<int>("Plugin"), 4);
QCOMPARE(details.at(2).value<int>("Plugin"), 3);
QCOMPARE(details.at(3).value<int>("Plugin"), 2);
QCOMPARE(details.at(4).value<int>("Plugin"), 1);
}