diff options
-rw-r--r-- | examples/positioning/positioning.pro | 2 | ||||
-rw-r--r-- | examples/positioning/satelliteinfo/main.cpp | 66 | ||||
-rw-r--r-- | examples/positioning/satelliteinfo/satelliteinfo.pro | 22 | ||||
-rw-r--r-- | examples/positioning/satelliteinfo/satelliteinfo.qml | 304 | ||||
-rw-r--r-- | examples/positioning/satelliteinfo/satelliteinfo.qrc | 5 | ||||
-rw-r--r-- | examples/positioning/satelliteinfo/satellitemodel.cpp | 309 | ||||
-rw-r--r-- | examples/positioning/satelliteinfo/satellitemodel.h | 124 | ||||
-rw-r--r-- | src/positioning/doc/images/example-satelliteinfo.png | bin | 0 -> 27371 bytes | |||
-rw-r--r-- | src/positioning/doc/src/examples/satelliteinfo.qdoc | 73 | ||||
-rw-r--r-- | src/positioning/doc/src/qtpositioning.qdoc | 1 |
10 files changed, 905 insertions, 1 deletions
diff --git a/examples/positioning/positioning.pro b/examples/positioning/positioning.pro index 468ff9eb..2f40d326 100644 --- a/examples/positioning/positioning.pro +++ b/examples/positioning/positioning.pro @@ -1,4 +1,4 @@ TEMPLATE = subdirs qtHaveModule(widgets): SUBDIRS += logfilepositionsource -qtHaveModule(quick): SUBDIRS += flickr weatherinfo +qtHaveModule(quick): SUBDIRS += flickr weatherinfo satelliteinfo diff --git a/examples/positioning/satelliteinfo/main.cpp b/examples/positioning/satelliteinfo/main.cpp new file mode 100644 index 00000000..328b69d7 --- /dev/null +++ b/examples/positioning/satelliteinfo/main.cpp @@ -0,0 +1,66 @@ +/**************************************************************************** +** +** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Digia Plc and its Subsidiary(-ies) nor the names +** of its contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include <QtGui/QGuiApplication> +#include <QtQml/qqml.h> +#include <QtQml/QQmlEngine> +#include <QtQuick/QQuickView> +#include "satellitemodel.h" + +int main(int argc, char *argv[]) +{ + QGuiApplication app(argc, argv); + qmlRegisterType<SatelliteModel>("Local", 1, 0, "SatelliteModel"); + + QQuickView view; + view.setSource(QStringLiteral("qrc:///satelliteinfo.qml")); + view.setResizeMode(QQuickView::SizeRootObjectToView); + + QObject::connect(view.engine(), SIGNAL(quit()), qApp, SLOT(quit())); +#if defined(Q_OS_QNX) + view.showFullScreen(); +#else + view.show(); +#endif + + return app.exec(); +} + + diff --git a/examples/positioning/satelliteinfo/satelliteinfo.pro b/examples/positioning/satelliteinfo/satelliteinfo.pro new file mode 100644 index 00000000..fe4f728e --- /dev/null +++ b/examples/positioning/satelliteinfo/satelliteinfo.pro @@ -0,0 +1,22 @@ +TEMPLATE = app +TARGET = satelliteinfo + +QT += quick positioning + +SOURCES += main.cpp \ + satellitemodel.cpp + +HEADERS += \ + satellitemodel.h + +OTHER_FILES += \ + satelliteinfo.qml + +RESOURCES += \ + satelliteinfo.qrc + +target.path = $$[QT_INSTALL_EXAMPLES]/qtpositioning/satelliteinfo +INSTALLS += target + + + diff --git a/examples/positioning/satelliteinfo/satelliteinfo.qml b/examples/positioning/satelliteinfo/satelliteinfo.qml new file mode 100644 index 00000000..f3fc5a78 --- /dev/null +++ b/examples/positioning/satelliteinfo/satelliteinfo.qml @@ -0,0 +1,304 @@ +/**************************************************************************** +** +** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Digia Plc and its Subsidiary(-ies) nor the names +** of its contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +import QtQuick 2.0 +import Local 1.0 + +Rectangle { + id: page + width: 360 + height: 360 + + SatelliteModel { + id: satelliteModel + running: true + onErrorFound: errorLabel.text = qsTr("Last Error: %1", "%1=error number").arg(code) + } + + Item { + id: header + height: column.height + 30 + width: parent.width + state: "running" + + anchors.top: parent.top + + function toggle() + { + switch (header.state) { + case "single": header.state = "running"; break; + default: + case "running": header.state = "stopped"; break; + case "stopped": header.state = "single"; break; + } + } + + function enterSingle() + { + satelliteModel.singleRequestMode = true; + satelliteModel.running = true; + } + + function enterRunning() + { + satelliteModel.running = false; + satelliteModel.singleRequestMode = false; + satelliteModel.running = true; + } + + states: [ + State { + name: "stopped" + PropertyChanges { target: startStop; bText: qsTr("Single") } + PropertyChanges { + target: modeLabel; text: qsTr("Current Mode: stopped") + } + PropertyChanges { target: satelliteModel; running: false; } + }, + State { + name: "single" + PropertyChanges { target: startStop; bText: qsTr("Start") } + PropertyChanges { + target: modeLabel; text: qsTr("Current Mode: single") + } + StateChangeScript { script: header.enterSingle(); } + }, + State { + name: "running" + PropertyChanges { target: startStop; bText: qsTr("Stop") } + PropertyChanges { + target: modeLabel; text: qsTr("Current Mode: running") + } + StateChangeScript { script: header.enterRunning(); } + } + ] + + Column { + id: column + anchors.verticalCenter: parent.verticalCenter + anchors.left: parent.left + anchors.margins: 7 + Text { + id: overview + text: satelliteModel.satelliteInfoAvailable + ? qsTr("Known Satellites") + : qsTr("Known Satellites (Demo Mode)") + font.pointSize: 12 + } + + Text { + id: modeLabel + font.pointSize: 12 + } + + Text { + id: errorLabel + text: qsTr("Last Error: None") + font.pointSize: 12 + } + } + Rectangle { + id: startStop + border.color: "black" + border.width: 3 + anchors.right: parent.right + anchors.verticalCenter: parent.verticalCenter + anchors.margins: 7 + radius: 10 + height: maxField.height*1.4 + width: maxField.width*1.4 + + property string bText: qsTr("Stop"); + + Text { //need this for sizing + id: maxField + text: qsTr("Single") + font.pointSize: 13 + opacity: 0 + } + + Text { + id: buttonText + anchors.centerIn: parent + text: startStop.bText + font.pointSize: 13 + } + + MouseArea { + anchors.fill: parent + onPressed: { startStop.color = "lightGray" } + onClicked: { header.toggle() } + onReleased: { startStop.color = "white" } + } + } + } + + Rectangle { + anchors.top: header.bottom + anchors.bottom: parent.bottom + anchors.left: parent.left + anchors.right: parent.right + anchors.margins: rect.myMargin + border.width: 3 + radius: 10 + border.color: "black" + + Item { + id: rect + anchors.fill: parent + anchors.margins: myMargin + property int myMargin: 7 + + Row { + id: view + property int rows: repeater.model.entryCount + property int singleWidth: ((rect.width - scale.width)/rows )-rect.myMargin + spacing: rect.myMargin + + Rectangle { + id: scale + width: strengthLabel.width+10 + height: rect.height + color: "#32cd32" + Text { + anchors.horizontalCenter: parent.horizontalCenter + anchors.bottom: lawngreenRect.top + font.pointSize: 11 + text: "50" + } + Text { + anchors.horizontalCenter: parent.horizontalCenter + anchors.top: parent.top + font.pointSize: 11 + text: "100" + } + + Rectangle { + id: redRect + width: parent.width + color: "red" + height: parent.height*10/100 + anchors.bottom: parent.bottom + Text { + id: strengthLabel + anchors.horizontalCenter: parent.horizontalCenter + anchors.bottom: parent.bottom + font.pointSize: 11 + text: "00" + } + } + Rectangle { + id: orangeRect + height: parent.height*10/100 + anchors.bottom: redRect.top + width: parent.width + color: "#ffa500" + Text { + anchors.horizontalCenter: parent.horizontalCenter + anchors.bottom: parent.bottom + font.pointSize: 11 + text: "10" + } + } + Rectangle { + id: goldRect + height: parent.height*10/100 + anchors.bottom: orangeRect.top + width: parent.width + color: "#ffd700" + Text { + anchors.horizontalCenter: parent.horizontalCenter + anchors.bottom: parent.bottom + font.pointSize: 11 + text: "20" + } + } + Rectangle { + id: yellowRect + height: parent.height*10/100 + anchors.bottom: goldRect.top + width: parent.width + color: "yellow" + Text { + anchors.horizontalCenter: parent.horizontalCenter + anchors.bottom: parent.bottom + font.pointSize: 11 + text: "30" + } + } + Rectangle { + id: lawngreenRect + height: parent.height*10/100 + anchors.bottom: yellowRect.top + width: parent.width + color: "#7cFc00" + Text { + anchors.horizontalCenter: parent.horizontalCenter + anchors.bottom: parent.bottom + font.pointSize: 11 + text: "40" + } + } + } + + Repeater { + id: repeater + model: satelliteModel + delegate: Rectangle { + height: rect.height + width: view.singleWidth + Rectangle { + anchors.bottom: parent.bottom + width: parent.width + height: parent.height*signalStrength/100 + color: isInUse ? "#7FFF0000" : "#7F0000FF" + } + Text { + anchors.horizontalCenter: parent.horizontalCenter + anchors.bottom: parent.bottom + text: satelliteIdentifier + } + } + } + } + } + } +} + diff --git a/examples/positioning/satelliteinfo/satelliteinfo.qrc b/examples/positioning/satelliteinfo/satelliteinfo.qrc new file mode 100644 index 00000000..8745f87e --- /dev/null +++ b/examples/positioning/satelliteinfo/satelliteinfo.qrc @@ -0,0 +1,5 @@ +<RCC> + <qresource prefix="/"> + <file>satelliteinfo.qml</file> + </qresource> +</RCC> diff --git a/examples/positioning/satelliteinfo/satellitemodel.cpp b/examples/positioning/satelliteinfo/satellitemodel.cpp new file mode 100644 index 00000000..d8c45ccb --- /dev/null +++ b/examples/positioning/satelliteinfo/satellitemodel.cpp @@ -0,0 +1,309 @@ +/**************************************************************************** +** +** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Digia Plc and its Subsidiary(-ies) nor the names +** of its contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "satellitemodel.h" +#include <QTimer> +#include <QDebug> + +SatelliteModel::SatelliteModel(QObject *parent) : + QAbstractListModel(parent), source(0), m_componentCompleted(false), m_running(false), + m_runningRequested(false), demo(false), isSingle(false), singleRequestServed(false) +{ + source = QGeoSatelliteInfoSource::createDefaultSource(this); + if (!demo && !source) { + qWarning() << "No satellite data source found. Changing to demo mode."; + demo = true; + } + if (!demo) { + source->setUpdateInterval(3000); + connect(source, SIGNAL(satellitesInViewUpdated(QList<QGeoSatelliteInfo>)), + this, SLOT(satellitesInViewUpdated(QList<QGeoSatelliteInfo>))); + connect(source, SIGNAL(satellitesInUseUpdated(QList<QGeoSatelliteInfo>)), + this, SLOT(satellitesInUseUpdated(QList<QGeoSatelliteInfo>))); + connect(source, SIGNAL(error(QGeoSatelliteInfoSource::Error)), + this, SLOT(error(QGeoSatelliteInfoSource::Error))); + } + + if (demo) { + timer = new QTimer(this); + connect(timer, SIGNAL(timeout()), this, SLOT(updateDemoData())); + timer->start(3000); + } +} + +int SatelliteModel::rowCount(const QModelIndex &parent) const +{ + Q_UNUSED(parent); + if (!source && !demo) + return 0; + + return knownSatellites.count(); +} + +QVariant SatelliteModel::data(const QModelIndex &index, int role) const +{ + if (!demo && !source) + return QVariant(); + + if (!index.isValid() || index.row() < 0) + return QVariant(); + + if (index.row() >= knownSatellites.count()) { + qWarning() << "SatelliteModel: Index out of bound"; + return QVariant(); + } + + const QGeoSatelliteInfo &info = knownSatellites.at(index.row()); + switch (role) { + case IdentifierRole: + return info.satelliteIdentifier(); + case InUseRole: + return satellitesInUse.contains(info.satelliteIdentifier()); + case SignalStrengthRole: + return info.signalStrength(); + case ElevationRole: + if (!info.hasAttribute(QGeoSatelliteInfo::Elevation)) + return QVariant(); + return info.attribute(QGeoSatelliteInfo::Elevation); + case AzimuthRole: + if (!info.hasAttribute(QGeoSatelliteInfo::Azimuth)) + return QVariant(); + return info.attribute(QGeoSatelliteInfo::Azimuth); + default: + break; + + } + + return QVariant(); +} + +QHash<int, QByteArray> SatelliteModel::roleNames() const +{ + QHash<int, QByteArray> roleNames; + roleNames.insert(IdentifierRole, "satelliteIdentifier"); + roleNames.insert(InUseRole, "isInUse"); + roleNames.insert(SignalStrengthRole, "signalStrength"); + roleNames.insert(ElevationRole, "elevation"); + roleNames.insert(AzimuthRole, "azimuth"); + return roleNames; +} + +void SatelliteModel::componentComplete() +{ + m_componentCompleted = true; + if (m_runningRequested) + setRunning(true); +} + +bool SatelliteModel::running() const +{ + return m_running; +} + +bool SatelliteModel::isSingleRequest() const +{ + return isSingle; +} + +void SatelliteModel::setSingleRequest(bool single) +{ + if (running()) { + qWarning() << "Cannot change single request mode while running"; + return; + } + + if (single != isSingle) { //flag changed + isSingle = single; + emit singleRequestChanged(); + } +} + +void SatelliteModel::setRunning(bool isActive) +{ + if (!source && !demo) + return; + + if (!m_componentCompleted) { + m_runningRequested = isActive; + return; + } + + if (m_running == isActive) + return; + + m_running = isActive; + + if (m_running) { + clearModel(); + if (demo) + timer->start(2000); + else if (isSingleRequest()) + source->requestUpdate(10000); + else + source->startUpdates(); + + if (demo) + singleRequestServed = false; + } else { + if (demo) + timer->stop(); + else if (!isSingleRequest()) + source->stopUpdates(); + } + + + Q_EMIT runningChanged(); +} + +int SatelliteModel::entryCount() const +{ + return knownSatellites.count(); +} + +bool SatelliteModel::canProvideSatelliteInfo() const +{ + return !demo; +} + +void SatelliteModel::clearModel() +{ + beginResetModel(); + knownSatelliteIds.clear(); + knownSatellites.clear(); + satellitesInUse.clear(); + endResetModel(); +} + +void SatelliteModel::updateDemoData() +{ + static bool flag = true; + QList<QGeoSatelliteInfo> satellites; + if (flag) { + for (int i = 0; i<5; i++) { + QGeoSatelliteInfo info; + info.setSatelliteIdentifier(i); + info.setSignalStrength(20 + 20*i); + satellites.append(info); + } + } else { + for (int i = 0; i<9; i++) { + QGeoSatelliteInfo info; + info.setSatelliteIdentifier(i*2); + info.setSignalStrength(20 + 10*i); + satellites.append(info); + } + } + + + satellitesInViewUpdated(satellites); + flag ? satellitesInUseUpdated(QList<QGeoSatelliteInfo>() << satellites.at(2)) + : satellitesInUseUpdated(QList<QGeoSatelliteInfo>() << satellites.at(3)); + flag = !flag; + + emit errorFound(flag); + + if (isSingleRequest() && !singleRequestServed) { + singleRequestServed = true; + setRunning(false); + } +} + +void SatelliteModel::error(QGeoSatelliteInfoSource::Error error) +{ + emit errorFound((int)error); +} + +QT_BEGIN_NAMESPACE +inline bool operator<(const QGeoSatelliteInfo& a, const QGeoSatelliteInfo& b) +{ + return a.satelliteIdentifier() < b.satelliteIdentifier(); +} +QT_END_NAMESPACE + +void SatelliteModel::satellitesInViewUpdated(const QList<QGeoSatelliteInfo> &infos) +{ + if (!running()) + return; + + int oldEntryCount = knownSatellites.count(); + + + QSet<int> satelliteIdsInUpdate; + foreach (const QGeoSatelliteInfo &info, infos) + satelliteIdsInUpdate.insert(info.satelliteIdentifier()); + + QSet<int> toBeRemoved = knownSatelliteIds - satelliteIdsInUpdate; + + //We reset the model as in reality just about all entry values change + //and there are generally a lot of inserts and removals each time + //Hence we don't bother with complex model update logic beyond resetModel() + beginResetModel(); + + knownSatellites = infos; + + //sort them for presentation purposes + std::sort(knownSatellites.begin(), knownSatellites.end()); + + //remove old "InUse" data + //new satellites are by default not in "InUse" + //existing satellites keep their "inUse" state + satellitesInUse -= toBeRemoved; + + knownSatelliteIds = satelliteIdsInUpdate; + endResetModel(); + + if (oldEntryCount != knownSatellites.count()) + emit entryCountChanged(); +} + +void SatelliteModel::satellitesInUseUpdated(const QList<QGeoSatelliteInfo> &infos) +{ + if (!running()) + return; + + beginResetModel(); + + satellitesInUse.clear(); + foreach (const QGeoSatelliteInfo &info, infos) + satellitesInUse.insert(info.satelliteIdentifier()); + + endResetModel(); +} + diff --git a/examples/positioning/satelliteinfo/satellitemodel.h b/examples/positioning/satelliteinfo/satellitemodel.h new file mode 100644 index 00000000..d7ce84e3 --- /dev/null +++ b/examples/positioning/satelliteinfo/satellitemodel.h @@ -0,0 +1,124 @@ +/**************************************************************************** +** +** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Digia Plc and its Subsidiary(-ies) nor the names +** of its contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef SATELLITEMODEL_H +#define SATELLITEMODEL_H + +#include <QAbstractListModel> +#include <QSet> +#include <QtQml/qqml.h> +#include <QtQml/QQmlParserStatus> +#include <QtPositioning/QGeoSatelliteInfoSource> + +QT_FORWARD_DECLARE_CLASS(QTimer) +QT_FORWARD_DECLARE_CLASS(QGeoSatelliteInfoSource) + +class SatelliteModel : public QAbstractListModel, public QQmlParserStatus +{ + Q_OBJECT + Q_PROPERTY(bool running READ running WRITE setRunning NOTIFY runningChanged) + Q_PROPERTY(bool satelliteInfoAvailable READ canProvideSatelliteInfo NOTIFY canProvideSatelliteInfoChanged) + Q_PROPERTY(int entryCount READ entryCount NOTIFY entryCountChanged) + Q_PROPERTY(bool singleRequestMode READ isSingleRequest WRITE setSingleRequest NOTIFY singleRequestChanged) + Q_INTERFACES(QQmlParserStatus) +public: + explicit SatelliteModel(QObject *parent = 0); + + enum { + IdentifierRole = Qt::UserRole + 1, + InUseRole, + SignalStrengthRole, + ElevationRole, + AzimuthRole + }; + + //From QAbstractListModel + int rowCount(const QModelIndex &parent) const; + QVariant data(const QModelIndex &index, int role) const; + QHash<int, QByteArray> roleNames() const; + + //From QQmlParserStatus + void classBegin() {} + void componentComplete(); + + bool running() const; + void setRunning(bool isActive); + + bool isSingleRequest() const; + void setSingleRequest(bool single); + + int entryCount() const; + + bool canProvideSatelliteInfo() const; + +signals: + void runningChanged(); + void entryCountChanged(); + void errorFound(int code); + void canProvideSatelliteInfoChanged(); + void singleRequestChanged(); + +public slots: + void clearModel(); + void updateDemoData(); + +private slots: + void error(QGeoSatelliteInfoSource::Error); + void satellitesInViewUpdated(const QList<QGeoSatelliteInfo> &infos); + void satellitesInUseUpdated(const QList<QGeoSatelliteInfo> &infos); + +private: + QGeoSatelliteInfoSource *source; + bool m_componentCompleted; + bool m_running; + bool m_runningRequested; + QList <QGeoSatelliteInfo> knownSatellites; + QSet<int> knownSatelliteIds; + QSet<int> satellitesInUse; + bool demo; + QTimer *timer; + bool isSingle; + bool singleRequestServed; + +}; + +QML_DECLARE_TYPE(SatelliteModel) + +#endif // SATELLITEMODEL_H diff --git a/src/positioning/doc/images/example-satelliteinfo.png b/src/positioning/doc/images/example-satelliteinfo.png Binary files differnew file mode 100644 index 00000000..aa9a217c --- /dev/null +++ b/src/positioning/doc/images/example-satelliteinfo.png diff --git a/src/positioning/doc/src/examples/satelliteinfo.qdoc b/src/positioning/doc/src/examples/satelliteinfo.qdoc new file mode 100644 index 00000000..1edb8f6c --- /dev/null +++ b/src/positioning/doc/src/examples/satelliteinfo.qdoc @@ -0,0 +1,73 @@ +/**************************************************************************** +** +** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the documentation of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:FDL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Free Documentation License Usage +** Alternatively, this file may be used under the terms of the GNU Free +** Documentation License version 1.3 as published by the Free Software +** Foundation and appearing in the file included in the packaging of +** this file. Please review the following information to ensure +** the GNU Free Documentation License version 1.3 requirements +** will be met: http://www.gnu.org/copyleft/fdl.html. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +/*! + \example satelliteinfo + \title SatelliteInfo (C++/QML) + + \brief The SatelliteInfo example shows how the available satellites + at the user's current position and marks the satellites + currently contributing to the GPS fix as pink. + + \ingroup qtpositioning-examples + + Key Qt Positioning classes used in this example: + + \list + \li \l{QGeoSatelliteInfo} + \li \l{QGeoSatelliteInfoSource} + \endlist + + \image ../images/example-satelliteinfo.png + + The example displays the signal strength of all satellites in view. Any satellite + that is currently used to calculate the GPS fix has been marked pink. The number at + the bottom of each signal bar is the individual satellite identifier. + + The application operates in three different modes: + + \table + \header + \li Application mode + \li Description + \row + \li running + \li The application continuously queries the system for satellite updates. When new data + is available it will be displayed. + \row + \li stopped + \li The application stops updating the satellite information. + \row + \li single + \li The application makes a single update request with a timeout of 10s. The display + remains empty until the request was answered by the system. + \endtable + + If the platform does not provide satellite information the application automatically + switches into a demo mode whereby it continuously switches between predefined + sets of satellite data. +*/ diff --git a/src/positioning/doc/src/qtpositioning.qdoc b/src/positioning/doc/src/qtpositioning.qdoc index ea353942..091b8c77 100644 --- a/src/positioning/doc/src/qtpositioning.qdoc +++ b/src/positioning/doc/src/qtpositioning.qdoc @@ -115,6 +115,7 @@ such as speed and direction. This provides the fundamental location information \list \li \l {Flickr (QML)} \li \l {Log File Position Source (C++)} + \li \l {SatelliteInfo (C++/QML)} \li \l {Weather Info (C++/QML)} \endlist */ |