summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFabian Bumberger <fbumberger@rim.com>2013-09-25 18:07:20 +0200
committerThe Qt Project <gerrit-noreply@qt-project.org>2013-09-30 15:00:59 +0200
commit171a0e2568c639ac40329a9d2ace01344eb395b0 (patch)
treecafc0d50acadf9b0fd5edeb6a05f3b47dd8956d6
parent2ef02cb4d0474dce51658d381743de96204dce72 (diff)
Alter the way type and TNF are treated in the qml API
Change-Id: Iff972e1645447a57eb72e3006318a9dd5b2d5c9b Reviewed-by: Alex Blasche <alexander.blasche@digia.com>
-rw-r--r--examples/nfc/poster/poster.qml4
-rw-r--r--src/imports/nfc/qdeclarativendeffilter.cpp14
-rw-r--r--src/imports/nfc/qdeclarativendeffilter_p.h8
-rw-r--r--src/imports/nfc/qdeclarativenearfield.cpp41
-rw-r--r--src/imports/nfc/qdeclarativenearfield_p.h2
-rw-r--r--src/nfc/qdeclarativendefrecord.cpp116
-rw-r--r--src/nfc/qdeclarativendefrecord.h23
-rw-r--r--tests/auto/qndefrecord/tst_qndefrecord.cpp91
8 files changed, 202 insertions, 97 deletions
diff --git a/examples/nfc/poster/poster.qml b/examples/nfc/poster/poster.qml
index 058f8e4f..7dcd0db5 100644
--- a/examples/nfc/poster/poster.qml
+++ b/examples/nfc/poster/poster.qml
@@ -50,8 +50,8 @@ Rectangle {
id: nearfield
filter: [
- NdefFilter { type: "urn:nfc:wkt:U"; minimum: 1; maximum: 1 },
- NdefFilter { type: "urn:nfc:wkt:T"; minimum: 1 }
+ NdefFilter { type: "U"; typeNameFormat: NearFiledRecord.NfcRtd; minimum: 1; maximum: 1 },
+ NdefFilter { type: "T"; typeNameFormat: NearFiledRecord.NfcRtd; minimum: 1 }
]
onMessageRecordsChanged: {
diff --git a/src/imports/nfc/qdeclarativendeffilter.cpp b/src/imports/nfc/qdeclarativendeffilter.cpp
index cdb99461..ae551774 100644
--- a/src/imports/nfc/qdeclarativendeffilter.cpp
+++ b/src/imports/nfc/qdeclarativendeffilter.cpp
@@ -119,6 +119,20 @@ void QDeclarativeNdefFilter::setType(const QString &t)
emit typeChanged();
}
+QDeclarativeNdefRecord::TypeNameFormat QDeclarativeNdefFilter::typeNameFormat() const
+{
+ return m_typeNameFormat;
+}
+
+void QDeclarativeNdefFilter::setTypeNameFormat(QDeclarativeNdefRecord::TypeNameFormat format)
+{
+ if (m_typeNameFormat == format)
+ return;
+
+ m_typeNameFormat = format;
+ Q_EMIT(typeNameFormatChanged());
+}
+
int QDeclarativeNdefFilter::minimum() const
{
return m_minimum;
diff --git a/src/imports/nfc/qdeclarativendeffilter_p.h b/src/imports/nfc/qdeclarativendeffilter_p.h
index d64db531..8622aece 100644
--- a/src/imports/nfc/qdeclarativendeffilter_p.h
+++ b/src/imports/nfc/qdeclarativendeffilter_p.h
@@ -43,21 +43,25 @@
#define QDECLARATIVENDEFFILTER_P_H
#include <QtCore/QObject>
+#include <qdeclarativendefrecord.h>
class QDeclarativeNdefFilter : public QObject
{
Q_OBJECT
Q_PROPERTY(QString type READ type WRITE setType NOTIFY typeChanged)
+ Q_PROPERTY(QDeclarativeNdefRecord::TypeNameFormat typeNameFormat READ typeNameFormat WRITE setTypeNameFormat NOTIFY typeNameFormatChanged)
Q_PROPERTY(int minimum READ minimum WRITE setMinimum NOTIFY minimumChanged)
Q_PROPERTY(int maximum READ maximum WRITE setMaximum NOTIFY maximumChanged)
-
public:
explicit QDeclarativeNdefFilter(QObject *parent = 0);
QString type() const;
void setType(const QString &t);
+ QDeclarativeNdefRecord::TypeNameFormat typeNameFormat() const;
+ void setTypeNameFormat(QDeclarativeNdefRecord::TypeNameFormat format);
+
int minimum() const;
void setMinimum(int value);
@@ -68,11 +72,13 @@ signals:
void typeChanged();
void minimumChanged();
void maximumChanged();
+ void typeNameFormatChanged();
private:
QString m_type;
int m_minimum;
int m_maximum;
+ QDeclarativeNdefRecord::TypeNameFormat m_typeNameFormat;
};
#endif // QDECLARATIVENDEFFILTER_P_H
diff --git a/src/imports/nfc/qdeclarativenearfield.cpp b/src/imports/nfc/qdeclarativenearfield.cpp
index 681e2e9e..81a27730 100644
--- a/src/imports/nfc/qdeclarativenearfield.cpp
+++ b/src/imports/nfc/qdeclarativenearfield.cpp
@@ -72,7 +72,7 @@
\code
NearField {
- filter: [ NdefFilter { type: "urn:nfc:wkt:U"; minimum: 1; maximum: 1 } ]
+ filter: [ NdefFilter { type: "U"; typeNameFormat: NdefRecord.NfcRtd; minimum: 1; maximum: 1 } ]
orderMatch: false
onMessageRecordsChanged: displayMessage()
@@ -143,7 +143,7 @@ void QDeclarativeNearField::componentComplete()
{
m_componentCompleted = true;
- if (!m_filter.isEmpty())
+ if (!m_filterList.isEmpty())
registerMessageHandler();
}
@@ -156,27 +156,20 @@ void QDeclarativeNearField::registerMessageHandler()
m_manager->unregisterNdefMessageHandler(m_messageHandlerId);
// no filter abort
- if (m_filter.isEmpty())
+ if (m_filterList.isEmpty())
return;
- QNdefFilter filter;
- filter.setOrderMatch(m_orderMatch);
- foreach (QDeclarativeNdefFilter *f, m_filter) {
- const QString type = f->type();
- uint min = f->minimum() < 0 ? UINT_MAX : f->minimum();
- uint max = f->maximum() < 0 ? UINT_MAX : f->maximum();
-
- if (type.startsWith(QLatin1String("urn:nfc:wkt:")))
- filter.appendRecord(QNdefRecord::NfcRtd, type.mid(12).toUtf8(), min, max);
- else if (type.startsWith(QLatin1String("urn:nfc:ext:")))
- filter.appendRecord(QNdefRecord::ExternalRtd, type.mid(12).toUtf8(), min, max);
- else if (type.startsWith(QLatin1String("urn:nfc:mime")))
- filter.appendRecord(QNdefRecord::Mime, type.mid(13).toUtf8(), min, max);
- else
- qWarning("Unknown NDEF record type %s", qPrintable(type));
+ QNdefFilter ndefFilter;
+ ndefFilter.setOrderMatch(m_orderMatch);
+ foreach (const QDeclarativeNdefFilter *filter, m_filterList) {
+ const QString type = filter->type();
+ uint min = filter->minimum() < 0 ? UINT_MAX : filter->minimum();
+ uint max = filter->maximum() < 0 ? UINT_MAX : filter->maximum();
+
+ ndefFilter.appendRecord(static_cast<QNdefRecord::TypeNameFormat>(filter->typeNameFormat()), type.toUtf8(), min, max);
}
- m_messageHandlerId = m_manager->registerNdefMessageHandler(filter, this, SLOT(_q_handleNdefMessage(QNdefMessage)));
+ m_messageHandlerId = m_manager->registerNdefMessageHandler(ndefFilter, this, SLOT(_q_handleNdefMessage(QNdefMessage)));
}
void QDeclarativeNearField::_q_handleNdefMessage(const QNdefMessage &message)
@@ -246,7 +239,7 @@ void QDeclarativeNearField::append_filter(QQmlListProperty<QDeclarativeNdefFilte
return;
filter->setParent(nearField);
- nearField->m_filter.append(filter);
+ nearField->m_filterList.append(filter);
emit nearField->filterChanged();
if (nearField->m_componentCompleted)
@@ -259,7 +252,7 @@ int QDeclarativeNearField::count_filters(QQmlListProperty<QDeclarativeNdefFilter
if (!nearField)
return 0;
- return nearField->m_filter.count();
+ return nearField->m_filterList.count();
}
QDeclarativeNdefFilter *QDeclarativeNearField::at_filter(QQmlListProperty<QDeclarativeNdefFilter> *list,
@@ -269,7 +262,7 @@ QDeclarativeNdefFilter *QDeclarativeNearField::at_filter(QQmlListProperty<QDecla
if (!nearField)
return 0;
- return nearField->m_filter.at(index);
+ return nearField->m_filterList.at(index);
}
void QDeclarativeNearField::clear_filter(QQmlListProperty<QDeclarativeNdefFilter> *list)
@@ -278,8 +271,8 @@ void QDeclarativeNearField::clear_filter(QQmlListProperty<QDeclarativeNdefFilter
if (!nearField)
return;
- qDeleteAll(nearField->m_filter);
- nearField->m_filter.clear();
+ qDeleteAll(nearField->m_filterList);
+ nearField->m_filterList.clear();
emit nearField->filterChanged();
if (nearField->m_componentCompleted)
nearField->registerMessageHandler();
diff --git a/src/imports/nfc/qdeclarativenearfield_p.h b/src/imports/nfc/qdeclarativenearfield_p.h
index d3f4b50f..ad551308 100644
--- a/src/imports/nfc/qdeclarativenearfield_p.h
+++ b/src/imports/nfc/qdeclarativenearfield_p.h
@@ -87,7 +87,7 @@ private slots:
private:
QList<QDeclarativeNdefRecord *> m_message;
- QList<QDeclarativeNdefFilter *> m_filter;
+ QList<QDeclarativeNdefFilter *> m_filterList;
bool m_orderMatch;
bool m_componentCompleted;
bool m_messageUpdating;
diff --git a/src/nfc/qdeclarativendefrecord.cpp b/src/nfc/qdeclarativendefrecord.cpp
index 4d560500..edec632e 100644
--- a/src/nfc/qdeclarativendefrecord.cpp
+++ b/src/nfc/qdeclarativendefrecord.cpp
@@ -106,10 +106,32 @@ QT_BEGIN_NAMESPACE
*/
/*!
- \qmlproperty string NdefRecord::recordType
+ \qmlproperty string NdefRecord::type
- This property holds the fully qualified record type of the NDEF record. The fully qualified
- record type includes the NIS and NSS prefixes.
+ This property holds the type of the NDEF record.
+*/
+
+/*!
+ \qmlproperty enumeration NdefRecord::typeNameFormat
+
+ This property holds the TNF of the NDEF record.
+
+ \table
+ \header \li Property \li Description
+ \row \li \c NdefRecord.Empty
+ \li An empty NDEF record, the record does not contain a payload.
+ \row \li \c NdefRecord.NfcRtd
+ \li The NDEF record type is defined by an NFC RTD Specification.
+ \row \li \c NdefRecord.Mime
+ \li The NDEF record type follows the construct described in RFC 2046.
+ \row \li \c NdefRecord.Uri
+ \li The NDEF record type follows the construct described in RFC 3986.
+ \row \li \c NdefRecord.ExternalRtd
+ \li The NDEF record type follows the construct for external type names
+ described the NFC RTD Specification.
+ \endtable
+
+ \sa QNdefRecord::typeNameFormat()
*/
/*!
@@ -119,7 +141,7 @@ QT_BEGIN_NAMESPACE
*/
/*!
- \fn void QDeclarativeNdefRecord::recordTypeChanged()
+ \fn void QDeclarativeNdefRecord::typeChanged()
This signal is emitted when the record type changes.
*/
@@ -131,9 +153,15 @@ QT_BEGIN_NAMESPACE
*/
/*!
- \property QDeclarativeNdefRecord::recordType
+ \property QDeclarativeNdefRecord::type
+
+ This property hold the type of the NDEF record.
+*/
+
+/*!
+ \property QDeclarativeNdefRecord::typeNameFormat
- This property hold the record type of the NDEF record that this class represents.
+ This property hold the TNF of the NDEF record.
*/
/*!
@@ -223,44 +251,76 @@ QDeclarativeNdefRecord::QDeclarativeNdefRecord(const QNdefRecord &record, QObjec
}
/*!
- Returns the fully qualified record type of the record. The fully qualified record type
- includes both the NIS and NSS prefixes.
+ \enum QDeclarativeNdefRecord::TypeNameFormat
+
+ This enum describes the type name format of an NDEF record. The values of this enum are according to
+ \l QNdefRecord::TypeNameFormat
+
+ \value Empty An empty NDEF record, the record does not contain a payload.
+ \value NfcRtd The NDEF record type is defined by an NFC RTD Specification.
+ \value Mime The NDEF record type follows the construct described in RFC 2046.
+ \value Uri The NDEF record type follows the construct described in RFC 3986.
+ \value ExternalRtd The NDEF record type follows the construct for external type names
+ described the NFC RTD Specification.
*/
-QString QDeclarativeNdefRecord::recordType() const
+
+/*!
+ Returns the type of the record.
+
+ \sa QNdefRecord::setType(), QNdefRecord::type()
+*/
+QString QDeclarativeNdefRecord::type() const
{
Q_D(const QDeclarativeNdefRecord);
- if (d->record.typeNameFormat() == QNdefRecord::Empty)
- return QString();
-
- return urnForRecordType(d->record.typeNameFormat(), d->record.type());
+ return QLatin1String(d->record.type());
}
/*!
Sets the record type to \a type if it is not currently equal to \a type; otherwise does
- nothing. If the record type is set the recordTypeChanged() signal will be emitted.
+ nothing. If the record type is set the typeChanged() signal will be emitted.
+
+ \sa QNdefRecord::setType(), QNdefRecord::type()
*/
-void QDeclarativeNdefRecord::setRecordType(const QString &type)
+void QDeclarativeNdefRecord::setType(const QString &newtype)
{
- if (type == recordType())
+ if (newtype == type())
return;
Q_D(QDeclarativeNdefRecord);
+ d->record.setType(newtype.toUtf8());
+
+ emit typeChanged();
+}
- if (type.startsWith(QLatin1String("urn:nfc:wkt:"))) {
- d->record.setTypeNameFormat(QNdefRecord::NfcRtd);
- d->record.setType(type.mid(12).toUtf8());
- } else if (type.startsWith(QLatin1String("urn:nfc:ext:"))) {
- d->record.setTypeNameFormat(QNdefRecord::ExternalRtd);
- d->record.setType(type.mid(12).toUtf8());
- } else if (type.startsWith(QLatin1String("urn:nfc:mime:"))) {
- d->record.setTypeNameFormat(QNdefRecord::Mime);
- d->record.setType(type.mid(13).toUtf8());
- } else {
- qWarning("Don't know how to decode NDEF type %s\n", qPrintable(type));
+/*!
+ Sets the type name format of the NDEF record to \a typeNameFormat.
+*/
+void QDeclarativeNdefRecord::setTypeNameFormat(QDeclarativeNdefRecord::TypeNameFormat typeNameFormat)
+{
+ Q_D(QDeclarativeNdefRecord);
+ bool emitChanged = true;
+ if (static_cast<QDeclarativeNdefRecord::TypeNameFormat>(d->record.typeNameFormat()) == typeNameFormat) {
+ emitChanged = false;
}
- emit recordTypeChanged();
+ //We always have to set the tnf, otherwise we run into problems when tnf is empty. Then
+ //the QNdefRecordPrivate is not created
+ d->record.setTypeNameFormat(static_cast<QNdefRecord::TypeNameFormat>(typeNameFormat));
+
+ if (emitChanged)
+ Q_EMIT(typeNameFormatChanged());
+}
+
+/*!
+ \fn QDeclarativeNdefRecord::TypeNameFormat QDeclarativeNdefRecord::typeNameFormat() const
+
+ Returns the type name format of the NDEF record.
+*/
+QDeclarativeNdefRecord::TypeNameFormat QDeclarativeNdefRecord::typeNameFormat() const
+{
+ Q_D(const QDeclarativeNdefRecord);
+ return static_cast<QDeclarativeNdefRecord::TypeNameFormat>(d->record.typeNameFormat());
}
/*!
diff --git a/src/nfc/qdeclarativendefrecord.h b/src/nfc/qdeclarativendefrecord.h
index ab7031f4..52c436fe 100644
--- a/src/nfc/qdeclarativendefrecord.h
+++ b/src/nfc/qdeclarativendefrecord.h
@@ -56,21 +56,36 @@ class Q_NFC_EXPORT QDeclarativeNdefRecord : public QObject
Q_DECLARE_PRIVATE(QDeclarativeNdefRecord)
- Q_PROPERTY(QString recordType READ recordType WRITE setRecordType NOTIFY recordTypeChanged)
+ Q_PROPERTY(QString type READ type WRITE setType NOTIFY typeChanged)
+ Q_PROPERTY(TypeNameFormat typeNameFormat READ typeNameFormat WRITE setTypeNameFormat NOTIFY typeNameFormatChanged)
Q_PROPERTY(QNdefRecord record READ record WRITE setRecord NOTIFY recordChanged)
+ Q_ENUMS(TypeNameFormat)
public:
+ enum TypeNameFormat {
+ Empty = QNdefRecord::Empty,
+ NfcRtd = QNdefRecord::NfcRtd,
+ Mime = QNdefRecord::Mime,
+ Uri = QNdefRecord::Uri,
+ ExternalRtd = QNdefRecord::ExternalRtd,
+ Unknown = QNdefRecord::Unknown
+ };
+
explicit QDeclarativeNdefRecord(QObject *parent = 0);
explicit QDeclarativeNdefRecord(const QNdefRecord &record, QObject *parent = 0);
- QString recordType() const;
- void setRecordType(const QString &t);
+ QString type() const;
+ void setType(const QString &t);
+
+ void setTypeNameFormat(TypeNameFormat typeNameFormat);
+ TypeNameFormat typeNameFormat() const;
QNdefRecord record() const;
void setRecord(const QNdefRecord &record);
Q_SIGNALS:
- void recordTypeChanged();
+ void typeChanged();
+ void typeNameFormatChanged();
void recordChanged();
private:
diff --git a/tests/auto/qndefrecord/tst_qndefrecord.cpp b/tests/auto/qndefrecord/tst_qndefrecord.cpp
index cccd1c61..6ccb9566 100644
--- a/tests/auto/qndefrecord/tst_qndefrecord.cpp
+++ b/tests/auto/qndefrecord/tst_qndefrecord.cpp
@@ -101,7 +101,8 @@ void tst_QNdefRecord::tst_record()
QDeclarativeNdefRecord declRecord;
QCOMPARE(declRecord.record(), record);
- QCOMPARE(declRecord.recordType(), QString());
+ QCOMPARE(declRecord.type(), QString());
+ QCOMPARE(declRecord.typeNameFormat(), QDeclarativeNdefRecord::Empty);
}
// test type name format
@@ -257,7 +258,8 @@ void tst_QNdefRecord::tst_textRecord()
QDeclarativeNdefRecord declRecord(record);
QCOMPARE(declRecord.record(), QNdefRecord(record));
- QCOMPARE(declRecord.recordType(), QString("urn:nfc:wkt:T"));
+ QCOMPARE(declRecord.type(), QString("T"));
+ QCOMPARE(declRecord.typeNameFormat(), QDeclarativeNdefRecord::NfcRtd);
}
// test getters
@@ -325,7 +327,8 @@ void tst_QNdefRecord::tst_uriRecord()
QDeclarativeNdefRecord declRecord(record);
QCOMPARE(declRecord.record(), QNdefRecord(record));
- QCOMPARE(declRecord.recordType(), QString("urn:nfc:wkt:U"));
+ QCOMPARE(declRecord.type(), QString("U"));
+ QCOMPARE(declRecord.typeNameFormat(), QDeclarativeNdefRecord::NfcRtd);
}
// test getters
@@ -360,27 +363,21 @@ void tst_QNdefRecord::tst_uriRecord()
void tst_QNdefRecord::tst_declarative_record_data()
{
QTest::addColumn<QNdefRecord::TypeNameFormat>("typeNameFormat");
- QTest::addColumn<QNdefRecord::TypeNameFormat>("typeNameFormatOut");
QTest::addColumn<QByteArray>("type");
- QTest::addColumn<QByteArray>("typeOut");
- QTest::addColumn<QString>("recordType");
-
- QTest::newRow("NfcRtd:U") << QNdefRecord::NfcRtd << QNdefRecord::NfcRtd << QByteArray("U") << QByteArray("U") << QString("urn:nfc:wkt:U");
- QTest::newRow("NfcRtd:T") << QNdefRecord::NfcRtd << QNdefRecord::NfcRtd << QByteArray("T") << QByteArray("T") << QString("urn:nfc:wkt:T");
- QTest::newRow("Empty:BLAH") << QNdefRecord::Empty << QNdefRecord::Empty << QByteArray("BLAH") << QByteArray("") << QString("");
- QTest::newRow("Empty") << QNdefRecord::Empty << QNdefRecord::Empty << QByteArray("") << QByteArray("") << QString("");
- QTest::newRow("Unknown") << QNdefRecord::Unknown << QNdefRecord::Empty << QByteArray("BLAHfoo") << QByteArray("") << QString("");
- QTest::newRow("Mime") << QNdefRecord::Mime << QNdefRecord::Mime << QByteArray("foobar") << QByteArray("foobar") << QString("urn:nfc:mime:foobar");
- QTest::newRow("ExternalRtd") << QNdefRecord::ExternalRtd << QNdefRecord::ExternalRtd << QByteArray("") << QByteArray("") << QString("urn:nfc:ext:");
+
+ QTest::newRow("NfcRtd:U") << QNdefRecord::NfcRtd << QByteArray("U");
+ QTest::newRow("NfcRtd:T") << QNdefRecord::NfcRtd << QByteArray("T");
+ QTest::newRow("Empty:BLAH") << QNdefRecord::Empty << QByteArray("BLAH");
+ QTest::newRow("Empty") << QNdefRecord::Empty << QByteArray("");
+ QTest::newRow("Unknown") << QNdefRecord::Unknown << QByteArray("BLAHfoo");
+ QTest::newRow("Mime") << QNdefRecord::Mime << QByteArray("foobar");
+ QTest::newRow("ExternalRtd") << QNdefRecord::ExternalRtd << QByteArray("");
}
void tst_QNdefRecord::tst_declarative_record()
{
QFETCH(QNdefRecord::TypeNameFormat, typeNameFormat);
- QFETCH(QNdefRecord::TypeNameFormat, typeNameFormatOut);
QFETCH(QByteArray, type);
- QFETCH(QByteArray, typeOut);
- QFETCH(QString, recordType);
{
QNdefRecord record;
@@ -393,74 +390,94 @@ void tst_QNdefRecord::tst_declarative_record()
QCOMPARE(declRecord.record(), record);
QCOMPARE(declRecord.record().typeNameFormat(), typeNameFormat);
QCOMPARE(declRecord.record().type(), type);
- QCOMPARE(declRecord.recordType(), recordType);
+ QCOMPARE(declRecord.type(), QString(type));
+ QCOMPARE(declRecord.typeNameFormat(), static_cast<QDeclarativeNdefRecord::TypeNameFormat>(typeNameFormat));
QDeclarativeNdefRecord declRecord2;
declRecord2.setRecord(record);
QCOMPARE(declRecord2.record(), record);
QCOMPARE(declRecord2.record().typeNameFormat(), typeNameFormat);
QCOMPARE(declRecord2.record().type(), type);
- QCOMPARE(declRecord2.recordType(), recordType);
+ QCOMPARE(declRecord2.type(), QString(type));
+ QCOMPARE(declRecord2.typeNameFormat(), static_cast<QDeclarativeNdefRecord::TypeNameFormat>(typeNameFormat));
QDeclarativeNdefRecord declRecord3;
- declRecord3.setRecordType(recordType);
- QCOMPARE(declRecord3.recordType(), recordType);
- QCOMPARE(declRecord3.record().typeNameFormat(), typeNameFormatOut);
- QCOMPARE(declRecord3.record().type(), typeOut);
+ declRecord3.setTypeNameFormat((QDeclarativeNdefRecord::TypeNameFormat)typeNameFormat);
+ declRecord3.setType(type);
+ QCOMPARE(declRecord3.type(), QString(type));
+ QCOMPARE(declRecord3.record().typeNameFormat(), typeNameFormat);
+ QCOMPARE(declRecord3.record().type(), type);
+ QCOMPARE(declRecord3.typeNameFormat(), static_cast<QDeclarativeNdefRecord::TypeNameFormat>(typeNameFormat));
}
}
void tst_QNdefRecord::tst_declarativeChangedSignals()
{
QDeclarativeNdefRecord record;
- QSignalSpy typeSpy(&record, SIGNAL(recordTypeChanged()));
+ QSignalSpy typeSpy(&record, SIGNAL(typeChanged()));
+ QSignalSpy tnfSpy(&record, SIGNAL(typeNameFormatChanged()));
QSignalSpy recordSpy(&record, SIGNAL(recordChanged()));
QCOMPARE(typeSpy.count(), 0);
QCOMPARE(recordSpy.count(), 0);
- record.setRecordType("urn:nfc:wkt:U");
+ record.setType("U");
+ record.setTypeNameFormat(QDeclarativeNdefRecord::NfcRtd);
QCOMPARE(typeSpy.count(), 1);
+ QCOMPARE(tnfSpy.count(), 1);
QCOMPARE(recordSpy.count(), 0);
- QCOMPARE(record.recordType(), QString("urn:nfc:wkt:U"));
+ QCOMPARE(record.type(), QString("U"));
QCOMPARE(record.record().type(), QByteArray("U"));
QCOMPARE(record.record().typeNameFormat(), QNdefRecord::NfcRtd);
+ QCOMPARE(record.typeNameFormat(), QDeclarativeNdefRecord::NfcRtd);
- record.setRecordType("urn:nfc:wkt:U"); //same value, no signal
+ record.setType("U"); //same value, no signal
QCOMPARE(typeSpy.count(), 1);
+ QCOMPARE(tnfSpy.count(), 1);
QCOMPARE(recordSpy.count(), 0);
- QCOMPARE(record.recordType(), QString("urn:nfc:wkt:U"));
+ QCOMPARE(record.type(), QString("U"));
QCOMPARE(record.record().type(), QByteArray("U"));
QCOMPARE(record.record().typeNameFormat(), QNdefRecord::NfcRtd);
+ QCOMPARE(record.typeNameFormat(), QDeclarativeNdefRecord::NfcRtd);
- record.setRecordType("urn:nfc:ext:blah");
- record.setRecordType("urn:nfc:ext:blah2");
+ record.setType("blah");
+ record.setType("blah2");
+ record.setTypeNameFormat(QDeclarativeNdefRecord::ExternalRtd);
QCOMPARE(typeSpy.count(), 3);
+ QCOMPARE(tnfSpy.count(), 2);
QCOMPARE(recordSpy.count(), 0);
- QCOMPARE(record.recordType(), QString("urn:nfc:ext:blah2"));
+ QCOMPARE(record.type(), QString("blah2"));
QCOMPARE(record.record().type(), QByteArray("blah2"));
QCOMPARE(record.record().typeNameFormat(), QNdefRecord::ExternalRtd);
+ QCOMPARE(record.typeNameFormat(), QDeclarativeNdefRecord::ExternalRtd);
- record.setRecordType("Rubbish");
+ record.setType("Rubbish");
QCOMPARE(typeSpy.count(), 4);
+ QCOMPARE(tnfSpy.count(), 2);
QCOMPARE(recordSpy.count(), 0);
- QCOMPARE(record.recordType(), QString("urn:nfc:ext:blah2"));
- QCOMPARE(record.record().type(), QByteArray("blah2"));
+ QCOMPARE(record.type(), QString("Rubbish"));
+ QCOMPARE(record.record().type(), QByteArray("Rubbish"));
QCOMPARE(record.record().typeNameFormat(), QNdefRecord::ExternalRtd);
+ QCOMPARE(record.typeNameFormat(), QDeclarativeNdefRecord::ExternalRtd);
- record.setRecordType("urn:nfc:mime:QQQQ");
+ record.setType("QQQQ");
+ record.setTypeNameFormat(QDeclarativeNdefRecord::Mime);
QCOMPARE(typeSpy.count(), 5);
+ QCOMPARE(tnfSpy.count(), 3);
QCOMPARE(recordSpy.count(), 0);
- QCOMPARE(record.recordType(), QString("urn:nfc:mime:QQQQ"));
+ QCOMPARE(record.type(), QString("QQQQ"));
QCOMPARE(record.record().type(), QByteArray("QQQQ"));
QCOMPARE(record.record().typeNameFormat(), QNdefRecord::Mime);
+ QCOMPARE(record.typeNameFormat(), QDeclarativeNdefRecord::Mime);
record.setRecord(QNdefRecord());
QCOMPARE(typeSpy.count(), 5); //setting record -> no recordChanged signal
+ QCOMPARE(tnfSpy.count(), 3);
QCOMPARE(recordSpy.count(), 1);
- QCOMPARE(record.recordType(), QString(""));
+ QCOMPARE(record.type(), QString(""));
QCOMPARE(record.record().type(), QByteArray());
QCOMPARE(record.record().typeNameFormat(), QNdefRecord::Empty);
+ QCOMPARE(record.typeNameFormat(), QDeclarativeNdefRecord::Empty);
}
QTEST_MAIN(tst_QNdefRecord)