diff options
Diffstat (limited to 'examples/positioning/satelliteinfo')
-rw-r--r-- | examples/positioning/satelliteinfo/CMakeLists.txt | 49 | ||||
-rw-r--r-- | examples/positioning/satelliteinfo/doc/images/example-satelliteinfo.png | bin | 27371 -> 0 bytes | |||
-rw-r--r-- | examples/positioning/satelliteinfo/doc/src/satelliteinfo.qdoc | 134 | ||||
-rw-r--r-- | examples/positioning/satelliteinfo/main.cpp | 71 | ||||
-rw-r--r-- | examples/positioning/satelliteinfo/satelliteinfo.pro | 26 | ||||
-rw-r--r-- | examples/positioning/satelliteinfo/satelliteinfo.qml | 316 | ||||
-rw-r--r-- | examples/positioning/satelliteinfo/satelliteinfo.qrc | 5 | ||||
-rw-r--r-- | examples/positioning/satelliteinfo/satellitemodel.cpp | 324 | ||||
-rw-r--r-- | examples/positioning/satelliteinfo/satellitemodel.h | 140 |
9 files changed, 0 insertions, 1065 deletions
diff --git a/examples/positioning/satelliteinfo/CMakeLists.txt b/examples/positioning/satelliteinfo/CMakeLists.txt deleted file mode 100644 index dd90a6e1..00000000 --- a/examples/positioning/satelliteinfo/CMakeLists.txt +++ /dev/null @@ -1,49 +0,0 @@ -# Generated from satelliteinfo.pro. - -cmake_minimum_required(VERSION 3.16) -project(satelliteinfo LANGUAGES CXX) - -set(CMAKE_INCLUDE_CURRENT_DIR ON) - -set(CMAKE_AUTOMOC ON) -set(CMAKE_AUTORCC ON) -set(CMAKE_AUTOUIC ON) - -if(NOT DEFINED INSTALL_EXAMPLESDIR) - set(INSTALL_EXAMPLESDIR "examples") -endif() - -set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/positioning/satelliteinfo") - -find_package(Qt6 COMPONENTS Core) -find_package(Qt6 COMPONENTS Gui) -find_package(Qt6 COMPONENTS Quick) -find_package(Qt6 COMPONENTS Positioning) - -qt_add_executable(satelliteinfo - main.cpp - satellitemodel.cpp satellitemodel.h -) -set_target_properties(satelliteinfo PROPERTIES - WIN32_EXECUTABLE TRUE - MACOSX_BUNDLE TRUE -) -target_link_libraries(satelliteinfo PRIVATE - Qt::Core - Qt::Gui - Qt::Positioning - Qt::Quick -) - -qt_add_qml_module(satelliteinfo - URI Local - VERSION 1.0 - QML_FILES satelliteinfo.qml - NO_RESOURCE_TARGET_PATH -) - -install(TARGETS satelliteinfo - RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}" - BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}" - LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}" -) diff --git a/examples/positioning/satelliteinfo/doc/images/example-satelliteinfo.png b/examples/positioning/satelliteinfo/doc/images/example-satelliteinfo.png Binary files differdeleted file mode 100644 index aa9a217c..00000000 --- a/examples/positioning/satelliteinfo/doc/images/example-satelliteinfo.png +++ /dev/null diff --git a/examples/positioning/satelliteinfo/doc/src/satelliteinfo.qdoc b/examples/positioning/satelliteinfo/doc/src/satelliteinfo.qdoc deleted file mode 100644 index fb314ea3..00000000 --- a/examples/positioning/satelliteinfo/doc/src/satelliteinfo.qdoc +++ /dev/null @@ -1,134 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2021 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** 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 The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/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: https://www.gnu.org/licenses/fdl-1.3.html. -** $QT_END_LICENSE$ -** -****************************************************************************/ - -/*! - \example satelliteinfo - \title SatelliteInfo (C++/QML) - - \brief The SatelliteInfo example shows 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 \l{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 is 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. - - \include examples-run.qdocinc - - \section1 Satellite Info Model - - The key part of this example is the \c SatelliteModel data model. It - represents the information about the satellites. - It uses the \l Q_PROPERTY and \l QML_ELEMENT macros, so that it can be - available from QML. - - \snippet satelliteinfo/satellitemodel.h 0 - \snippet satelliteinfo/satellitemodel.h 1 - \snippet satelliteinfo/satellitemodel.h 2 - - The \c SatelliteModel object creates an instance of - \l QGeoSatelliteInfoSource using the \l {QGeoSatelliteInfoSource::} - {createDefaultSource()} method. Once the source is created, the - \l {QGeoSatelliteInfoSource::}{satellitesInViewUpdated()} and - \l {QGeoSatelliteInfoSource::}{satellitesInUseUpdated()} signals are used - to notify about the changes in satellite information. - - \snippet satelliteinfo/satellitemodel.cpp 0 - - The aforementioned signals provide the lists of \l QGeoSatelliteInfo - objects that represent satellites in view and satellites in use, - respectively. This data is used to update the model. - - \snippet satelliteinfo/satellitemodel.cpp 1 - - If the satellite info source is not available, demo data is used to simulate - satellite information updates. - - \snippet satelliteinfo/satellitemodel.cpp 2 - - The model is later used in QML to visualize the data. - - \section1 Exposing the Model to QML - - To expose \c SatelliteModel to QML, we use the \l QML_ELEMENT macro. - See the \l QQmlEngine class documentation for more details on it. - - To make the type available in QML, we need to update our build accordingly. - - \section2 CMake Build - - For a CMake-based build, we need to add the following to the - \c {CMakeLists.txt}: - - \quotefromfile satelliteinfo/CMakeLists.txt - \skipto qt_add_qml_module(satelliteinfo - \printuntil ) - - \section2 qmake Build - - For a qmake build, we need to modify the \c {satelliteinfo.pro} file in the - following way: - - \quotefromfile satelliteinfo/satelliteinfo.pro - \skipto CONFIG - \printuntil QML_IMPORT_MAJOR_VERSION -*/ diff --git a/examples/positioning/satelliteinfo/main.cpp b/examples/positioning/satelliteinfo/main.cpp deleted file mode 100644 index 4a96c4c9..00000000 --- a/examples/positioning/satelliteinfo/main.cpp +++ /dev/null @@ -1,71 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2017 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the examples of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:BSD$ -** 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 The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** BSD License Usage -** Alternatively, 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 The Qt Company Ltd 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); - - QQuickView view; - view.setSource(QStringLiteral("qrc:///satelliteinfo.qml")); - view.setResizeMode(QQuickView::SizeRootObjectToView); - - QObject::connect(view.engine(), SIGNAL(quit()), qApp, SLOT(quit())); - view.show(); - - return app.exec(); -} - - diff --git a/examples/positioning/satelliteinfo/satelliteinfo.pro b/examples/positioning/satelliteinfo/satelliteinfo.pro deleted file mode 100644 index ebee0945..00000000 --- a/examples/positioning/satelliteinfo/satelliteinfo.pro +++ /dev/null @@ -1,26 +0,0 @@ -TEMPLATE = app -TARGET = satelliteinfo - -QT += quick positioning - -CONFIG += qmltypes -QML_IMPORT_NAME = Local -QML_IMPORT_MAJOR_VERSION = 1 - -SOURCES += main.cpp \ - satellitemodel.cpp - -HEADERS += \ - satellitemodel.h - -OTHER_FILES += \ - satelliteinfo.qml - -RESOURCES += \ - satelliteinfo.qrc - -target.path = $$[QT_INSTALL_EXAMPLES]/positioning/satelliteinfo -INSTALLS += target - - - diff --git a/examples/positioning/satelliteinfo/satelliteinfo.qml b/examples/positioning/satelliteinfo/satelliteinfo.qml deleted file mode 100644 index ef0c965e..00000000 --- a/examples/positioning/satelliteinfo/satelliteinfo.qml +++ /dev/null @@ -1,316 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2017 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the examples of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:BSD$ -** 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 The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** BSD License Usage -** Alternatively, 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 The Qt Company Ltd 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: function(code) { - 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 deleted file mode 100644 index 8745f87e..00000000 --- a/examples/positioning/satelliteinfo/satelliteinfo.qrc +++ /dev/null @@ -1,5 +0,0 @@ -<RCC> - <qresource prefix="/"> - <file>satelliteinfo.qml</file> - </qresource> -</RCC> diff --git a/examples/positioning/satelliteinfo/satellitemodel.cpp b/examples/positioning/satelliteinfo/satellitemodel.cpp deleted file mode 100644 index 77c89035..00000000 --- a/examples/positioning/satelliteinfo/satellitemodel.cpp +++ /dev/null @@ -1,324 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2017 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the examples of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:BSD$ -** 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 The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** BSD License Usage -** Alternatively, 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 The Qt Company Ltd 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> - -//! [0] -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(errorOccurred(QGeoSatelliteInfoSource::Error)), - this, SLOT(error(QGeoSatelliteInfoSource::Error))); - } - - if (demo) { - timer = new QTimer(this); - connect(timer, SIGNAL(timeout()), this, SLOT(updateDemoData())); - timer->start(3000); - } -} -//! [0] - -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(); -} - -//! [2] -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); - } -} -//! [2] - -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 - -//! [1] -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(); -} -//! [1] diff --git a/examples/positioning/satelliteinfo/satellitemodel.h b/examples/positioning/satelliteinfo/satellitemodel.h deleted file mode 100644 index 18d94a59..00000000 --- a/examples/positioning/satelliteinfo/satellitemodel.h +++ /dev/null @@ -1,140 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2017 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the examples of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:BSD$ -** 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 The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** BSD License Usage -** Alternatively, 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 The Qt Company Ltd 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) - -//! [0] -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) - QML_ELEMENT -public: - explicit SatelliteModel(QObject *parent = 0); - - enum { - IdentifierRole = Qt::UserRole + 1, - InUseRole, - SignalStrengthRole, - ElevationRole, - AzimuthRole - }; - - //From QAbstractListModel - int rowCount(const QModelIndex &parent) const override; - QVariant data(const QModelIndex &index, int role) const override; - QHash<int, QByteArray> roleNames() const override; - - //From QQmlParserStatus - void classBegin() override {} - void componentComplete() override; -//! [0] - - bool running() const; - void setRunning(bool isActive); - - bool isSingleRequest() const; - void setSingleRequest(bool single); - - int entryCount() const; - - bool canProvideSatelliteInfo() const; - -//! [1] -signals: - void runningChanged(); - void entryCountChanged(); - void errorFound(int code); - void canProvideSatelliteInfoChanged(); - void singleRequestChanged(); - -public slots: - void clearModel(); - void updateDemoData(); -//! [1] - -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; -//! [2] -}; -//! [2] - -QML_DECLARE_TYPE(SatelliteModel) - -#endif // SATELLITEMODEL_H |