From 5d6f97ed9450b88098e425d4cf963655b3508248 Mon Sep 17 00:00:00 2001 From: Maurice Kalinowski Date: Wed, 21 May 2014 12:57:57 +0200 Subject: Add snippet app to verify plugin implementation Useful when creating a new backend to verify behavior. Change-Id: I7a417aabad4d6dbbe494dcd384ca7af57bd78050 Reviewed-by: Alex Blasche --- tests/applications/positioning_backend/main.cpp | 61 +++++ .../positioning_backend/positioning_backend.pro | 14 + tests/applications/positioning_backend/widget.cpp | 168 ++++++++++++ tests/applications/positioning_backend/widget.h | 79 ++++++ tests/applications/positioning_backend/widget.ui | 295 +++++++++++++++++++++ 5 files changed, 617 insertions(+) create mode 100644 tests/applications/positioning_backend/main.cpp create mode 100644 tests/applications/positioning_backend/positioning_backend.pro create mode 100644 tests/applications/positioning_backend/widget.cpp create mode 100644 tests/applications/positioning_backend/widget.h create mode 100644 tests/applications/positioning_backend/widget.ui diff --git a/tests/applications/positioning_backend/main.cpp b/tests/applications/positioning_backend/main.cpp new file mode 100644 index 00000000..2ca4a0aa --- /dev/null +++ b/tests/applications/positioning_backend/main.cpp @@ -0,0 +1,61 @@ +/**************************************************************************** +** +** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the QtPositioning module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** 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 Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +#include "widget.h" +#include + +#include +#include +int main(int argc, char *argv[]) +{ + QApplication a(argc, argv); + + Widget w1; + Widget w2; + + QTabWidget tabWidget; + tabWidget.setTabPosition(QTabWidget::South); + + tabWidget.addTab(&w1, "Instance 1"); + tabWidget.addTab(&w2, "Instance 2"); + + tabWidget.show(); + return a.exec(); +} diff --git a/tests/applications/positioning_backend/positioning_backend.pro b/tests/applications/positioning_backend/positioning_backend.pro new file mode 100644 index 00000000..410dbc86 --- /dev/null +++ b/tests/applications/positioning_backend/positioning_backend.pro @@ -0,0 +1,14 @@ +QT += core gui positioning widgets + +TARGET = posbackendtesting +TEMPLATE = app + + +SOURCES += main.cpp\ + widget.cpp + +HEADERS += widget.h + +FORMS += widget.ui + +winrt: WINRT_MANIFEST.capabilities_device += location diff --git a/tests/applications/positioning_backend/widget.cpp b/tests/applications/positioning_backend/widget.cpp new file mode 100644 index 00000000..0624a837 --- /dev/null +++ b/tests/applications/positioning_backend/widget.cpp @@ -0,0 +1,168 @@ +/**************************************************************************** +** +** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the QtPositioning module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** 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 Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +#include "widget.h" +#include "ui_widget.h" +#include +#include + +Widget::Widget(QWidget *parent) : + QWidget(parent), + ui(new Ui::Widget) +{ + ui->setupUi(this); + qDebug() << "Available:" << QGeoPositionInfoSource::availableSources(); + m_posSource = QGeoPositionInfoSource::createDefaultSource(this); + if (!m_posSource) + qFatal("No Position Source created!"); + connect(m_posSource, SIGNAL(positionUpdated(QGeoPositionInfo)), + this, SLOT(positionUpdated(QGeoPositionInfo))); + + connect(ui->horizontalSlider, SIGNAL(valueChanged(int)), + this, SLOT(setInterval(int))); + connect(m_posSource, SIGNAL(updateTimeout()), + this, SLOT(positionTimedOut())); + + ui->groupBox->setLayout(ui->gridLayout); + ui->horizontalSlider->setMinimum(m_posSource->minimumUpdateInterval()); + ui->labelTimeOut->setVisible(false); + + connect(m_posSource, SIGNAL(error(QGeoPositionInfoSource::Error)), + this, SLOT(errorChanged(QGeoPositionInfoSource::Error))); +} + +void Widget::positionUpdated(QGeoPositionInfo gpsPos) +{ + QGeoCoordinate coord = gpsPos.coordinate(); + ui->labelLatitude->setText(QString::number(coord.latitude())); + ui->labelLongitude->setText(QString::number(coord.longitude())); + ui->labelAltitude->setText(QString::number(coord.altitude())); + ui->labelTimeStamp->setText(gpsPos.timestamp().toString()); + if (gpsPos.hasAttribute(QGeoPositionInfo::HorizontalAccuracy)) + ui->labelHAccuracy->setText(QString::number(gpsPos.attribute(QGeoPositionInfo::HorizontalAccuracy))); + else + ui->labelHAccuracy->setText(QStringLiteral("N/A")); + + if (gpsPos.hasAttribute(QGeoPositionInfo::VerticalAccuracy)) + ui->labelVAccuracy->setText(QString::number(gpsPos.attribute(QGeoPositionInfo::VerticalAccuracy))); + else + ui->labelVAccuracy->setText(QStringLiteral("N/A")); +} + +void Widget::positionTimedOut() +{ + ui->labelTimeOut->setVisible(true); +} + +void Widget::errorChanged(QGeoPositionInfoSource::Error err) +{ + ui->labelErrorState->setText(err == 3 ? QStringLiteral("OK") : QString::number(err)); +} + +Widget::~Widget() +{ + delete ui; +} + +void Widget::setInterval(int msec) +{ + m_posSource->setUpdateInterval(msec); +} + +void Widget::on_buttonRetrieve_clicked() +{ + // Requesting current position for _one_ time + m_posSource->requestUpdate(10000); +} + +void Widget::on_buttonStart_clicked() +{ + // Either start or stop the current position info source + bool running = ui->checkBox->isChecked(); + if (running) { + m_posSource->stopUpdates(); + ui->checkBox->setChecked(false); + } else { + m_posSource->startUpdates(); + ui->checkBox->setChecked(true); + } +} + +void Widget::on_radioButton_clicked() +{ + m_posSource->setPreferredPositioningMethods(QGeoPositionInfoSource::NoPositioningMethods); +} + +void Widget::on_radioButton_2_clicked() +{ + m_posSource->setPreferredPositioningMethods(QGeoPositionInfoSource::SatellitePositioningMethods); +} + +void Widget::on_radioButton_3_clicked() +{ + m_posSource->setPreferredPositioningMethods(QGeoPositionInfoSource::NonSatellitePositioningMethods); +} + +void Widget::on_radioButton_4_clicked() +{ + m_posSource->setPreferredPositioningMethods(QGeoPositionInfoSource::AllPositioningMethods); +} + +void Widget::on_buttonUpdateSupported_clicked() +{ + QGeoPositionInfoSource::PositioningMethods m = m_posSource->supportedPositioningMethods(); + QString text; + switch (m) { + case QGeoPositionInfoSource::NoPositioningMethods: + text = QStringLiteral("None"); + break; + case QGeoPositionInfoSource::SatellitePositioningMethods: + text = QStringLiteral("Satellite"); + break; + case QGeoPositionInfoSource::NonSatellitePositioningMethods: + text = QStringLiteral("Non Satellite"); + break; + case QGeoPositionInfoSource::AllPositioningMethods: + text = QStringLiteral("All"); + break; + } + + ui->labelSupported->setText(text); +} diff --git a/tests/applications/positioning_backend/widget.h b/tests/applications/positioning_backend/widget.h new file mode 100644 index 00000000..94ccceef --- /dev/null +++ b/tests/applications/positioning_backend/widget.h @@ -0,0 +1,79 @@ +/**************************************************************************** +** +** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the QtPositioning module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** 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 Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +#ifndef WIDGET_H +#define WIDGET_H + +#include +#include + +namespace Ui { + class Widget; +} + +class Widget : public QWidget +{ + Q_OBJECT + +public: + explicit Widget(QWidget *parent = 0); + ~Widget(); + +public slots: + void positionUpdated(QGeoPositionInfo gpsPos); + void setInterval(int msec); + void positionTimedOut(); + void errorChanged(QGeoPositionInfoSource::Error err); +private slots: + void on_buttonRetrieve_clicked(); + void on_buttonStart_clicked(); + void on_radioButton_2_clicked(); + void on_radioButton_clicked(); + void on_radioButton_3_clicked(); + void on_radioButton_4_clicked(); + + void on_buttonUpdateSupported_clicked(); + +private: + Ui::Widget *ui; + QGeoPositionInfoSource *m_posSource; +}; + +#endif // WIDGET_H diff --git a/tests/applications/positioning_backend/widget.ui b/tests/applications/positioning_backend/widget.ui new file mode 100644 index 00000000..d19497d2 --- /dev/null +++ b/tests/applications/positioning_backend/widget.ui @@ -0,0 +1,295 @@ + + + Widget + + + + 0 + 0 + 276 + 467 + + + + Widget + + + + + + QFormLayout::AllNonFixedFieldsGrow + + + + + Latitude: + + + + + + + N/A + + + + + + + Longitude: + + + + + + + N/A + + + + + + + Altitude: + + + + + + + N/A + + + + + + + TimeStamp: + + + + + + + N/A + + + + + + + Horizontal Accuracy: + + + + + + + N/A + + + + + + + Vertical Accuracy: + + + + + + + N/A + + + + + + + TimeOut: + + + + + + + true + + + !!!!!TimeOut!!!!! + + + + + + + Supported Methods: + + + + + + + Error State: + + + + + + + N/A + + + + + + + + + N/A + + + + + + + Update + + + + + + + + + + + Method + + + + + 43 + 21 + 243 + 71 + + + + + + + None + + + + + + + Satelite + + + true + + + + + + + Non-Satelite + + + + + + + All + + + + + + + + + + + + + Interval: + + + + + + + 50 + + + 10000 + + + Qt::Horizontal + + + + + + + 0 + + + + + + + + + false + + + Running + + + + + + + + + Start/Stop + + + + + + + Retrieve + + + + + + + + + + + + horizontalSlider + valueChanged(int) + labelInterval + setNum(int) + + + 217 + 137 + + + 386 + 138 + + + + + -- cgit v1.2.1