diff options
author | Alex Blasche <alexander.blasche@digia.com> | 2014-03-10 14:52:00 +0100 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2014-03-11 15:50:42 +0100 |
commit | ef98583d2a5350602d0dac2736c772bfd84ebadb (patch) | |
tree | d89480f6b49b34027c1ab5cfa7947d80fef804c9 /examples | |
parent | 2d2dbd3199a10985c713e97d32688e001e4cb226 (diff) | |
download | qtconnectivity-ef98583d2a5350602d0dac2736c772bfd84ebadb.tar.gz |
Improve NFC documentation
1.) Extend the NFC overview page
2.) Ensure that snippets are compiled at all times
3.) Mark Qt 5.3 APIs using \since
Task-number: QTBUG-32401
Task-number: QTBUG-34978
Change-Id: I8928be3d7dd2c9de1314eb1ec6ed55c8d4301f4a
Reviewed-by: Leena Miettinen <riitta-leena.miettinen@digia.com>
Reviewed-by: Jerome Pasion <jerome.pasion@digia.com>
Reviewed-by: Alex Blasche <alexander.blasche@digia.com>
Diffstat (limited to 'examples')
-rw-r--r-- | examples/nfc/annotatedurl/annotatedurl.cpp | 17 | ||||
-rw-r--r-- | examples/nfc/annotatedurl/main.cpp | 2 | ||||
-rw-r--r-- | examples/nfc/ndefeditor/mainwindow.cpp | 14 |
3 files changed, 24 insertions, 9 deletions
diff --git a/examples/nfc/annotatedurl/annotatedurl.cpp b/examples/nfc/annotatedurl/annotatedurl.cpp index 293decf7..f29045b6 100644 --- a/examples/nfc/annotatedurl/annotatedurl.cpp +++ b/examples/nfc/annotatedurl/annotatedurl.cpp @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). +** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). ** Contact: http://www.qt-project.org/legal ** ** This file is part of the QtNfc module. @@ -63,8 +63,10 @@ AnnotatedUrl::~AnnotatedUrl() { } +//! [handleMessage 1] void AnnotatedUrl::handleMessage(const QNdefMessage &message, QNearFieldTarget *target) { +//! [handleMessage 1] Q_UNUSED(target); enum { @@ -81,39 +83,40 @@ void AnnotatedUrl::handleMessage(const QNdefMessage &message, QNearFieldTarget * QUrl url; QPixmap pixmap; +//! [handleMessage 2] foreach (const QNdefRecord &record, message) { if (record.isRecordType<QNdefNfcTextRecord>()) { QNdefNfcTextRecord textRecord(record); + title = textRecord.text(); QLocale locale(textRecord.locale()); - +//! [handleMessage 2] // already found best match if (bestMatch == MatchedLanguageAndCountry) { // do nothing } else if (bestMatch <= MatchedLanguage && locale == defaultLocale) { - title = textRecord.text(); bestMatch = MatchedLanguageAndCountry; } else if (bestMatch <= MatchedEnglish && locale.language() == defaultLocale.language()) { - title = textRecord.text(); bestMatch = MatchedLanguage; } else if (bestMatch <= MatchedFirst && locale.language() == QLocale::English) { - title = textRecord.text(); bestMatch = MatchedEnglish; } else if (bestMatch == MatchedNone) { - title = textRecord.text(); bestMatch = MatchedFirst; } +//! [handleMessage 3] } else if (record.isRecordType<QNdefNfcUriRecord>()) { QNdefNfcUriRecord uriRecord(record); url = uriRecord.uri(); +//! [handleMessage 3] } else if (record.typeNameFormat() == QNdefRecord::Mime && record.type().startsWith("image/")) { pixmap = QPixmap::fromImage(QImage::fromData(record.payload())); +//! [handleMessage 4] } } emit annotatedUrl(url, title, pixmap); } - +//! [handleMessage 4] diff --git a/examples/nfc/annotatedurl/main.cpp b/examples/nfc/annotatedurl/main.cpp index c669e57b..351f33bf 100644 --- a/examples/nfc/annotatedurl/main.cpp +++ b/examples/nfc/annotatedurl/main.cpp @@ -57,6 +57,7 @@ int main(int argc, char *argv[]) QApplication a(argc, argv); MainWindow mainWindow; + //! [QNearFieldManager register handler] QNearFieldManager manager; AnnotatedUrl annotatedUrl; @@ -66,6 +67,7 @@ int main(int argc, char *argv[]) filter.appendRecord<QNdefNfcUriRecord>(); manager.registerNdefMessageHandler(filter, &annotatedUrl, SLOT(handleMessage(QNdefMessage,QNearFieldTarget*))); + //! [QNearFieldManager register handler] QObject::connect(&annotatedUrl, SIGNAL(annotatedUrl(QUrl,QString,QPixmap)), &mainWindow, SLOT(displayAnnotatedUrl(QUrl,QString,QPixmap))); diff --git a/examples/nfc/ndefeditor/mainwindow.cpp b/examples/nfc/ndefeditor/mainwindow.cpp index df8f758c..fedb0866 100644 --- a/examples/nfc/ndefeditor/mainwindow.cpp +++ b/examples/nfc/ndefeditor/mainwindow.cpp @@ -120,8 +120,7 @@ void addRecord(Ui::MainWindow *ui, const QNdefRecord &record = QNdefRecord()) } MainWindow::MainWindow(QWidget *parent) -: QMainWindow(parent), ui(new Ui::MainWindow), m_manager(new QNearFieldManager(this)), - m_touchAction(NoAction) +: QMainWindow(parent), ui(new Ui::MainWindow), m_touchAction(NoAction) { ui->setupUi(this); @@ -135,10 +134,13 @@ MainWindow::MainWindow(QWidget *parent) QVBoxLayout *vbox = new QVBoxLayout; ui->scrollAreaWidgetContents->setLayout(vbox); + //! [QNearFieldManager init] + m_manager = new QNearFieldManager(this); connect(m_manager, SIGNAL(targetDetected(QNearFieldTarget*)), this, SLOT(targetDetected(QNearFieldTarget*))); connect(m_manager, SIGNAL(targetLost(QNearFieldTarget*)), this, SLOT(targetLost(QNearFieldTarget*))); + //! [QNearFieldManager init] } MainWindow::~MainWindow() @@ -205,7 +207,9 @@ void MainWindow::touchReceive() m_touchAction = ReadNdef; m_manager->setTargetAccessModes(QNearFieldManager::NdefReadTargetAccess); + //! [QNearFieldManager start detection] m_manager->startTargetDetection(); + //! [QNearFieldManager start detection] } void MainWindow::touchStore() @@ -218,6 +222,7 @@ void MainWindow::touchStore() m_manager->startTargetDetection(); } +//! [QNearFieldTarget detected] void MainWindow::targetDetected(QNearFieldTarget *target) { switch (m_touchAction) { @@ -240,11 +245,14 @@ void MainWindow::targetDetected(QNearFieldTarget *target) break; } } +//! [QNearFieldTarget detected] +//! [QNearFieldTarget lost] void MainWindow::targetLost(QNearFieldTarget *target) { target->deleteLater(); } +//! [QNearFieldTarget lost] void MainWindow::ndefMessageRead(const QNdefMessage &message) { @@ -267,7 +275,9 @@ void MainWindow::ndefMessageRead(const QNdefMessage &message) ui->status->setStyleSheet(QString()); m_manager->setTargetAccessModes(QNearFieldManager::NoTargetAccess); + //! [QNearFieldManager stop detection] m_manager->stopTargetDetection(); + //! [QNearFieldManager stop detection] m_request = QNearFieldTarget::RequestId(); ui->statusBar->clearMessage(); } |