mirror of
https://github.com/ciphervance/supercell-wx.git
synced 2025-10-30 17:50:04 +00:00
GPS info dialog
This commit is contained in:
parent
69309ca8e6
commit
1cce358a52
9 changed files with 538 additions and 12 deletions
201
scwx-qt/source/scwx/qt/ui/gps_info_dialog.cpp
Normal file
201
scwx-qt/source/scwx/qt/ui/gps_info_dialog.cpp
Normal file
|
|
@ -0,0 +1,201 @@
|
|||
#include "gps_info_dialog.hpp"
|
||||
#include "ui_gps_info_dialog.h"
|
||||
|
||||
#include <scwx/qt/manager/position_manager.hpp>
|
||||
#include <scwx/common/geographic.hpp>
|
||||
#include <scwx/util/time.hpp>
|
||||
|
||||
#include <units/angle.h>
|
||||
#include <units/length.h>
|
||||
#include <units/velocity.h>
|
||||
#include <QClipboard>
|
||||
#include <QGeoPositionInfo>
|
||||
|
||||
namespace scwx
|
||||
{
|
||||
namespace qt
|
||||
{
|
||||
namespace ui
|
||||
{
|
||||
|
||||
static const QString kDisabledString_ = "---";
|
||||
|
||||
class GpsInfoDialog::Impl
|
||||
{
|
||||
public:
|
||||
explicit Impl(GpsInfoDialog* self) : self_ {self} {};
|
||||
~Impl() = default;
|
||||
|
||||
std::shared_ptr<manager::PositionManager> positionManager_ {
|
||||
manager::PositionManager::Instance()};
|
||||
|
||||
void Update(const QGeoPositionInfo& info, bool updateTime = true);
|
||||
|
||||
GpsInfoDialog* self_;
|
||||
};
|
||||
|
||||
GpsInfoDialog::GpsInfoDialog(QWidget* parent) :
|
||||
QDialog(parent), p {std::make_unique<Impl>(this)}, ui(new Ui::GpsInfoDialog)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
|
||||
p->Update({}, false);
|
||||
|
||||
connect(p->positionManager_.get(),
|
||||
&manager::PositionManager::PositionUpdated,
|
||||
this,
|
||||
[this](const QGeoPositionInfo& info) { p->Update(info); });
|
||||
|
||||
connect(ui->copyCoordinateButton,
|
||||
&QAbstractButton::clicked,
|
||||
this,
|
||||
[this]()
|
||||
{
|
||||
QClipboard* clipboard = QGuiApplication::clipboard();
|
||||
clipboard->setText(ui->coordinateLabel->text());
|
||||
});
|
||||
}
|
||||
|
||||
GpsInfoDialog::~GpsInfoDialog()
|
||||
{
|
||||
delete ui;
|
||||
}
|
||||
|
||||
void GpsInfoDialog::Impl::Update(const QGeoPositionInfo& info, bool updateTime)
|
||||
{
|
||||
auto coordinate = info.coordinate();
|
||||
|
||||
if (coordinate.isValid())
|
||||
{
|
||||
const QString latitude = QString::fromStdString(
|
||||
common::GetLatitudeString(coordinate.latitude()));
|
||||
const QString longitude = QString::fromStdString(
|
||||
common::GetLongitudeString(coordinate.longitude()));
|
||||
|
||||
self_->ui->coordinateLabel->setText(
|
||||
QString("%1, %2").arg(latitude).arg(longitude));
|
||||
}
|
||||
else
|
||||
{
|
||||
self_->ui->coordinateLabel->setText(kDisabledString_);
|
||||
}
|
||||
|
||||
if (coordinate.type() == QGeoCoordinate::CoordinateType::Coordinate3D)
|
||||
{
|
||||
units::length::meters<double> altitude {coordinate.altitude()};
|
||||
self_->ui->altitudeLabel->setText(
|
||||
QString::fromStdString(units::to_string(altitude)));
|
||||
}
|
||||
else
|
||||
{
|
||||
self_->ui->altitudeLabel->setText(kDisabledString_);
|
||||
}
|
||||
|
||||
if (info.hasAttribute(QGeoPositionInfo::Attribute::Direction))
|
||||
{
|
||||
units::angle::degrees<double> direction {
|
||||
info.attribute(QGeoPositionInfo::Attribute::Direction)};
|
||||
self_->ui->directionLabel->setText(
|
||||
QString::fromStdString(units::to_string(direction)));
|
||||
}
|
||||
else
|
||||
{
|
||||
self_->ui->directionLabel->setText(kDisabledString_);
|
||||
}
|
||||
|
||||
if (info.hasAttribute(QGeoPositionInfo::Attribute::GroundSpeed))
|
||||
{
|
||||
units::velocity::meters_per_second<double> groundSpeed {
|
||||
info.attribute(QGeoPositionInfo::Attribute::GroundSpeed)};
|
||||
self_->ui->groundSpeedLabel->setText(
|
||||
QString::fromStdString(units::to_string(groundSpeed)));
|
||||
}
|
||||
else
|
||||
{
|
||||
self_->ui->groundSpeedLabel->setText(kDisabledString_);
|
||||
}
|
||||
|
||||
if (info.hasAttribute(QGeoPositionInfo::Attribute::VerticalSpeed))
|
||||
{
|
||||
units::velocity::meters_per_second<double> verticalSpeed {
|
||||
info.attribute(QGeoPositionInfo::Attribute::VerticalSpeed)};
|
||||
self_->ui->verticalSpeedLabel->setText(
|
||||
QString::fromStdString(units::to_string(verticalSpeed)));
|
||||
}
|
||||
else
|
||||
{
|
||||
self_->ui->verticalSpeedLabel->setText(kDisabledString_);
|
||||
}
|
||||
|
||||
if (info.hasAttribute(QGeoPositionInfo::Attribute::MagneticVariation))
|
||||
{
|
||||
units::angle::degrees<double> magneticVariation {
|
||||
info.attribute(QGeoPositionInfo::Attribute::MagneticVariation)};
|
||||
self_->ui->magneticVariationLabel->setText(
|
||||
QString::fromStdString(units::to_string(magneticVariation)));
|
||||
}
|
||||
else
|
||||
{
|
||||
self_->ui->magneticVariationLabel->setText(kDisabledString_);
|
||||
}
|
||||
|
||||
if (info.hasAttribute(QGeoPositionInfo::Attribute::HorizontalAccuracy))
|
||||
{
|
||||
units::length::meters<double> horizontalAccuracy {
|
||||
info.attribute(QGeoPositionInfo::Attribute::HorizontalAccuracy)};
|
||||
if (!std::isnan(horizontalAccuracy.value()))
|
||||
{
|
||||
self_->ui->horizontalAccuracyLabel->setText(
|
||||
QString::fromStdString(units::to_string(horizontalAccuracy)));
|
||||
}
|
||||
else
|
||||
{
|
||||
self_->ui->horizontalAccuracyLabel->setText(kDisabledString_);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
self_->ui->horizontalAccuracyLabel->setText(kDisabledString_);
|
||||
}
|
||||
|
||||
if (info.hasAttribute(QGeoPositionInfo::Attribute::VerticalAccuracy))
|
||||
{
|
||||
units::length::meters<double> verticalAccuracy {
|
||||
info.attribute(QGeoPositionInfo::Attribute::VerticalAccuracy)};
|
||||
if (!std::isnan(verticalAccuracy.value()))
|
||||
{
|
||||
self_->ui->verticalAccuracyLabel->setText(
|
||||
QString::fromStdString(units::to_string(verticalAccuracy)));
|
||||
}
|
||||
else
|
||||
{
|
||||
self_->ui->verticalAccuracyLabel->setText(kDisabledString_);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
self_->ui->verticalAccuracyLabel->setText(kDisabledString_);
|
||||
}
|
||||
|
||||
if (info.hasAttribute(QGeoPositionInfo::Attribute::DirectionAccuracy))
|
||||
{
|
||||
units::angle::degrees<double> directionAccuracy {
|
||||
info.attribute(QGeoPositionInfo::Attribute::DirectionAccuracy)};
|
||||
self_->ui->directionAccuracyLabel->setText(
|
||||
QString::fromStdString(units::to_string(directionAccuracy)));
|
||||
}
|
||||
else
|
||||
{
|
||||
self_->ui->directionAccuracyLabel->setText(kDisabledString_);
|
||||
}
|
||||
|
||||
if (updateTime)
|
||||
{
|
||||
self_->ui->lastUpdateLabel->setText(
|
||||
info.timestamp().toString(Qt::DateFormat::ISODate));
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace ui
|
||||
} // namespace qt
|
||||
} // namespace scwx
|
||||
36
scwx-qt/source/scwx/qt/ui/gps_info_dialog.hpp
Normal file
36
scwx-qt/source/scwx/qt/ui/gps_info_dialog.hpp
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
#pragma once
|
||||
|
||||
#include <QDialog>
|
||||
|
||||
namespace Ui
|
||||
{
|
||||
class GpsInfoDialog;
|
||||
}
|
||||
|
||||
namespace scwx
|
||||
{
|
||||
namespace qt
|
||||
{
|
||||
namespace ui
|
||||
{
|
||||
|
||||
class GpsInfoDialog : public QDialog
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
private:
|
||||
Q_DISABLE_COPY(GpsInfoDialog)
|
||||
|
||||
public:
|
||||
explicit GpsInfoDialog(QWidget* parent = nullptr);
|
||||
~GpsInfoDialog();
|
||||
|
||||
private:
|
||||
class Impl;
|
||||
std::unique_ptr<Impl> p;
|
||||
Ui::GpsInfoDialog* ui;
|
||||
};
|
||||
|
||||
} // namespace ui
|
||||
} // namespace qt
|
||||
} // namespace scwx
|
||||
266
scwx-qt/source/scwx/qt/ui/gps_info_dialog.ui
Normal file
266
scwx-qt/source/scwx/qt/ui/gps_info_dialog.ui
Normal file
|
|
@ -0,0 +1,266 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>GpsInfoDialog</class>
|
||||
<widget class="QDialog" name="GpsInfoDialog">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>313</width>
|
||||
<height>292</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>GPS Info</string>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<item>
|
||||
<widget class="QWidget" name="widget" native="true">
|
||||
<layout class="QGridLayout" name="gridLayout">
|
||||
<property name="verticalSpacing">
|
||||
<number>6</number>
|
||||
</property>
|
||||
<item row="8" column="0">
|
||||
<widget class="QLabel" name="label_17">
|
||||
<property name="text">
|
||||
<string>Direction Accuracy</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="5" column="1">
|
||||
<widget class="QLabel" name="magneticVariationLabel">
|
||||
<property name="text">
|
||||
<string/>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="6" column="1">
|
||||
<widget class="QLabel" name="horizontalAccuracyLabel">
|
||||
<property name="text">
|
||||
<string/>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="8" column="1">
|
||||
<widget class="QLabel" name="directionAccuracyLabel">
|
||||
<property name="text">
|
||||
<string/>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="10" column="0">
|
||||
<spacer name="verticalSpacer">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Orientation::Vertical</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>20</width>
|
||||
<height>40</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item row="5" column="0">
|
||||
<widget class="QLabel" name="label_11">
|
||||
<property name="text">
|
||||
<string>Magnetic Variation</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="0">
|
||||
<widget class="QLabel" name="label_5">
|
||||
<property name="text">
|
||||
<string>Direction</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="4" column="0">
|
||||
<widget class="QLabel" name="label_9">
|
||||
<property name="text">
|
||||
<string>Vertical Speed</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="1">
|
||||
<widget class="QLabel" name="directionLabel">
|
||||
<property name="text">
|
||||
<string/>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="1">
|
||||
<widget class="QLabel" name="altitudeLabel">
|
||||
<property name="text">
|
||||
<string/>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="7" column="0">
|
||||
<widget class="QLabel" name="label_15">
|
||||
<property name="text">
|
||||
<string>Vertical Accuracy</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="2">
|
||||
<widget class="QToolButton" name="copyCoordinateButton">
|
||||
<property name="text">
|
||||
<string>...</string>
|
||||
</property>
|
||||
<property name="icon">
|
||||
<iconset resource="../../../../scwx-qt.qrc">
|
||||
<normaloff>:/res/icons/font-awesome-6/copy-regular.svg</normaloff>:/res/icons/font-awesome-6/copy-regular.svg</iconset>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="6" column="0">
|
||||
<widget class="QLabel" name="label_13">
|
||||
<property name="text">
|
||||
<string>Horizonal Accuracy</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="1">
|
||||
<widget class="QLabel" name="groundSpeedLabel">
|
||||
<property name="text">
|
||||
<string/>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="0">
|
||||
<widget class="QLabel" name="label_7">
|
||||
<property name="text">
|
||||
<string>Ground Speed</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="4" column="1">
|
||||
<widget class="QLabel" name="verticalSpeedLabel">
|
||||
<property name="text">
|
||||
<string/>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="1">
|
||||
<widget class="QLabel" name="coordinateLabel">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Expanding" vsizetype="Preferred">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string/>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="0">
|
||||
<widget class="QLabel" name="label">
|
||||
<property name="text">
|
||||
<string>Coordinate</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="7" column="1">
|
||||
<widget class="QLabel" name="verticalAccuracyLabel">
|
||||
<property name="text">
|
||||
<string/>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<widget class="QLabel" name="label_2">
|
||||
<property name="text">
|
||||
<string>Altitude</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="9" column="0">
|
||||
<widget class="QLabel" name="label_3">
|
||||
<property name="text">
|
||||
<string>Last Update</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="9" column="1">
|
||||
<widget class="QLabel" name="lastUpdateLabel">
|
||||
<property name="text">
|
||||
<string>Never</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
<zorder>verticalAccuracyLabel</zorder>
|
||||
<zorder>label_11</zorder>
|
||||
<zorder>groundSpeedLabel</zorder>
|
||||
<zorder>magneticVariationLabel</zorder>
|
||||
<zorder>label_2</zorder>
|
||||
<zorder>coordinateLabel</zorder>
|
||||
<zorder>altitudeLabel</zorder>
|
||||
<zorder>directionAccuracyLabel</zorder>
|
||||
<zorder>label_5</zorder>
|
||||
<zorder>label_15</zorder>
|
||||
<zorder>label_13</zorder>
|
||||
<zorder>verticalSpeedLabel</zorder>
|
||||
<zorder>label_7</zorder>
|
||||
<zorder>label</zorder>
|
||||
<zorder>horizontalAccuracyLabel</zorder>
|
||||
<zorder>label_17</zorder>
|
||||
<zorder>directionLabel</zorder>
|
||||
<zorder>label_9</zorder>
|
||||
<zorder>copyCoordinateButton</zorder>
|
||||
<zorder>label_3</zorder>
|
||||
<zorder>lastUpdateLabel</zorder>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QDialogButtonBox" name="buttonBox">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Orientation::Horizontal</enum>
|
||||
</property>
|
||||
<property name="standardButtons">
|
||||
<set>QDialogButtonBox::StandardButton::Close</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<resources>
|
||||
<include location="../../../../scwx-qt.qrc"/>
|
||||
</resources>
|
||||
<connections>
|
||||
<connection>
|
||||
<sender>buttonBox</sender>
|
||||
<signal>accepted()</signal>
|
||||
<receiver>GpsInfoDialog</receiver>
|
||||
<slot>accept()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>248</x>
|
||||
<y>254</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>157</x>
|
||||
<y>274</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
<connection>
|
||||
<sender>buttonBox</sender>
|
||||
<signal>rejected()</signal>
|
||||
<receiver>GpsInfoDialog</receiver>
|
||||
<slot>reject()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>316</x>
|
||||
<y>260</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>286</x>
|
||||
<y>274</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
</connections>
|
||||
</ui>
|
||||
Loading…
Add table
Add a link
Reference in a new issue