mirror of
https://github.com/ciphervance/supercell-wx.git
synced 2025-10-30 18:30:06 +00:00
Updating radar site display fields to be more human-friendly
- Latitude/longitude in degrees N/S/E/W - Radar types with hyphens - Sort by raw decimal values
This commit is contained in:
parent
1bc6e714f5
commit
6e7a13494a
11 changed files with 186 additions and 5 deletions
|
|
@ -38,6 +38,7 @@ set(SRC_EXE_MAIN source/scwx/qt/main/main.cpp)
|
||||||
set(HDR_MAIN source/scwx/qt/main/main_window.hpp)
|
set(HDR_MAIN source/scwx/qt/main/main_window.hpp)
|
||||||
set(SRC_MAIN source/scwx/qt/main/main_window.cpp)
|
set(SRC_MAIN source/scwx/qt/main/main_window.cpp)
|
||||||
set(UI_MAIN source/scwx/qt/main/main_window.ui)
|
set(UI_MAIN source/scwx/qt/main/main_window.ui)
|
||||||
|
set(HDR_COMMON source/scwx/qt/common/types.hpp)
|
||||||
set(HDR_CONFIG source/scwx/qt/config/radar_site.hpp)
|
set(HDR_CONFIG source/scwx/qt/config/radar_site.hpp)
|
||||||
set(SRC_CONFIG source/scwx/qt/config/radar_site.cpp)
|
set(SRC_CONFIG source/scwx/qt/config/radar_site.cpp)
|
||||||
set(SRC_EXTERNAL source/scwx/qt/external/stb_rect_pack.cpp)
|
set(SRC_EXTERNAL source/scwx/qt/external/stb_rect_pack.cpp)
|
||||||
|
|
@ -153,6 +154,7 @@ set(TS_FILES ts/scwx_en_US.ts)
|
||||||
|
|
||||||
set(PROJECT_SOURCES ${HDR_MAIN}
|
set(PROJECT_SOURCES ${HDR_MAIN}
|
||||||
${SRC_MAIN}
|
${SRC_MAIN}
|
||||||
|
${HDR_COMMON}
|
||||||
${HDR_CONFIG}
|
${HDR_CONFIG}
|
||||||
${SRC_CONFIG}
|
${SRC_CONFIG}
|
||||||
${SRC_EXTERNAL}
|
${SRC_EXTERNAL}
|
||||||
|
|
@ -189,6 +191,7 @@ set(EXECUTABLE_SOURCES ${SRC_EXE_MAIN})
|
||||||
|
|
||||||
source_group("Header Files\\main" FILES ${HDR_MAIN})
|
source_group("Header Files\\main" FILES ${HDR_MAIN})
|
||||||
source_group("Source Files\\main" FILES ${SRC_MAIN})
|
source_group("Source Files\\main" FILES ${SRC_MAIN})
|
||||||
|
source_group("Header Files\\common" FILES ${HDR_COMMON})
|
||||||
source_group("Header Files\\config" FILES ${HDR_CONFIG})
|
source_group("Header Files\\config" FILES ${HDR_CONFIG})
|
||||||
source_group("Source Files\\config" FILES ${SRC_CONFIG})
|
source_group("Source Files\\config" FILES ${SRC_CONFIG})
|
||||||
source_group("Source Files\\external" FILES ${SRC_EXTERNAL})
|
source_group("Source Files\\external" FILES ${SRC_EXTERNAL})
|
||||||
|
|
|
||||||
19
scwx-qt/source/scwx/qt/common/types.hpp
Normal file
19
scwx-qt/source/scwx/qt/common/types.hpp
Normal file
|
|
@ -0,0 +1,19 @@
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <Qt>
|
||||||
|
|
||||||
|
namespace scwx
|
||||||
|
{
|
||||||
|
namespace qt
|
||||||
|
{
|
||||||
|
namespace common
|
||||||
|
{
|
||||||
|
|
||||||
|
enum ItemDataRole
|
||||||
|
{
|
||||||
|
SortRole = Qt::UserRole
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace common
|
||||||
|
} // namespace qt
|
||||||
|
} // namespace scwx
|
||||||
|
|
@ -20,6 +20,9 @@ static const auto logger_ = scwx::util::Logger::Create(logPrefix_);
|
||||||
static const std::string defaultRadarSiteFile_ =
|
static const std::string defaultRadarSiteFile_ =
|
||||||
":/res/config/radar_sites.json";
|
":/res/config/radar_sites.json";
|
||||||
|
|
||||||
|
static const std::unordered_map<std::string, std::string> typeNameMap_ {
|
||||||
|
{"wsr88d", "WSR-88D"}, {"tdwr", "TDWR"}, {"?", "?"}};
|
||||||
|
|
||||||
static std::unordered_map<std::string, std::shared_ptr<RadarSite>>
|
static std::unordered_map<std::string, std::shared_ptr<RadarSite>>
|
||||||
radarSiteMap_;
|
radarSiteMap_;
|
||||||
static std::unordered_map<std::string, std::string> siteIdMap_;
|
static std::unordered_map<std::string, std::string> siteIdMap_;
|
||||||
|
|
@ -63,6 +66,19 @@ std::string RadarSite::type() const
|
||||||
return p->type_;
|
return p->type_;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::string RadarSite::type_name() const
|
||||||
|
{
|
||||||
|
auto it = typeNameMap_.find(p->type_);
|
||||||
|
if (it != typeNameMap_.cend())
|
||||||
|
{
|
||||||
|
return it->second;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return typeNameMap_.at("?");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
std::string RadarSite::id() const
|
std::string RadarSite::id() const
|
||||||
{
|
{
|
||||||
return p->id_;
|
return p->id_;
|
||||||
|
|
|
||||||
|
|
@ -26,6 +26,7 @@ public:
|
||||||
RadarSite& operator=(RadarSite&&) noexcept;
|
RadarSite& operator=(RadarSite&&) noexcept;
|
||||||
|
|
||||||
std::string type() const;
|
std::string type() const;
|
||||||
|
std::string type_name() const;
|
||||||
std::string id() const;
|
std::string id() const;
|
||||||
double latitude() const;
|
double latitude() const;
|
||||||
double longitude() const;
|
double longitude() const;
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,7 @@
|
||||||
#include <scwx/qt/model/radar_site_model.hpp>
|
#include <scwx/qt/model/radar_site_model.hpp>
|
||||||
|
#include <scwx/qt/common/types.hpp>
|
||||||
#include <scwx/qt/config/radar_site.hpp>
|
#include <scwx/qt/config/radar_site.hpp>
|
||||||
|
#include <scwx/common/geographic.hpp>
|
||||||
#include <scwx/util/logger.hpp>
|
#include <scwx/util/logger.hpp>
|
||||||
|
|
||||||
namespace scwx
|
namespace scwx
|
||||||
|
|
@ -42,7 +44,8 @@ int RadarSiteModel::columnCount(const QModelIndex& parent) const
|
||||||
QVariant RadarSiteModel::data(const QModelIndex& index, int role) const
|
QVariant RadarSiteModel::data(const QModelIndex& index, int role) const
|
||||||
{
|
{
|
||||||
if (index.isValid() && index.row() >= 0 &&
|
if (index.isValid() && index.row() >= 0 &&
|
||||||
index.row() < p->radarSites_.size() && role == Qt::DisplayRole)
|
index.row() < p->radarSites_.size() &&
|
||||||
|
(role == Qt::DisplayRole || role == common::SortRole))
|
||||||
{
|
{
|
||||||
const auto& site = p->radarSites_.at(index.row());
|
const auto& site = p->radarSites_.at(index.row());
|
||||||
|
|
||||||
|
|
@ -57,11 +60,27 @@ QVariant RadarSiteModel::data(const QModelIndex& index, int role) const
|
||||||
case 3:
|
case 3:
|
||||||
return QString::fromStdString(site->country());
|
return QString::fromStdString(site->country());
|
||||||
case 4:
|
case 4:
|
||||||
return QString("%1").arg(site->latitude());
|
if (role == Qt::DisplayRole)
|
||||||
|
{
|
||||||
|
return QString::fromStdString(
|
||||||
|
scwx::common::GetLatitudeString(site->latitude()));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return site->latitude();
|
||||||
|
}
|
||||||
case 5:
|
case 5:
|
||||||
return QString("%1").arg(site->longitude());
|
if (role == Qt::DisplayRole)
|
||||||
|
{
|
||||||
|
return QString::fromStdString(
|
||||||
|
scwx::common::GetLongitudeString(site->longitude()));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return site->longitude();
|
||||||
|
}
|
||||||
case 6:
|
case 6:
|
||||||
return QString::fromStdString(site->type());
|
return QString::fromStdString(site->type_name());
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
#include "radar_site_dialog.hpp"
|
#include "radar_site_dialog.hpp"
|
||||||
#include "./ui_radar_site_dialog.h"
|
#include "./ui_radar_site_dialog.h"
|
||||||
|
|
||||||
|
#include <scwx/qt/common/types.hpp>
|
||||||
#include <scwx/qt/model/radar_site_model.hpp>
|
#include <scwx/qt/model/radar_site_model.hpp>
|
||||||
#include <scwx/util/logger.hpp>
|
#include <scwx/util/logger.hpp>
|
||||||
|
|
||||||
|
|
@ -25,6 +26,7 @@ public:
|
||||||
proxyModel_ {new QSortFilterProxyModel(self_)}
|
proxyModel_ {new QSortFilterProxyModel(self_)}
|
||||||
{
|
{
|
||||||
proxyModel_->setSourceModel(radarSiteModel_);
|
proxyModel_->setSourceModel(radarSiteModel_);
|
||||||
|
proxyModel_->setSortRole(common::SortRole);
|
||||||
proxyModel_->setFilterCaseSensitivity(Qt::CaseInsensitive);
|
proxyModel_->setFilterCaseSensitivity(Qt::CaseInsensitive);
|
||||||
proxyModel_->setFilterKeyColumn(-1);
|
proxyModel_->setFilterKeyColumn(-1);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,12 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
|
||||||
namespace scwx
|
namespace scwx
|
||||||
{
|
{
|
||||||
namespace common
|
namespace common
|
||||||
{
|
{
|
||||||
|
|
||||||
namespace Characters
|
namespace Characters
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
@ -11,5 +14,13 @@ constexpr char DEGREE = static_cast<char>(0xb0);
|
||||||
constexpr char ETX = static_cast<char>(0x03);
|
constexpr char ETX = static_cast<char>(0x03);
|
||||||
|
|
||||||
} // namespace Characters
|
} // namespace Characters
|
||||||
|
|
||||||
|
namespace Unicode
|
||||||
|
{
|
||||||
|
|
||||||
|
extern const std::string kDegree;
|
||||||
|
|
||||||
|
} // namespace Unicode
|
||||||
|
|
||||||
} // namespace common
|
} // namespace common
|
||||||
} // namespace scwx
|
} // namespace scwx
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,7 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
|
||||||
namespace scwx
|
namespace scwx
|
||||||
{
|
{
|
||||||
namespace common
|
namespace common
|
||||||
|
|
@ -26,5 +28,18 @@ struct Coordinate
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
enum class DegreeStringType
|
||||||
|
{
|
||||||
|
Decimal,
|
||||||
|
DegreesMinutesSeconds
|
||||||
|
};
|
||||||
|
|
||||||
|
std::string
|
||||||
|
GetLatitudeString(double latitude,
|
||||||
|
DegreeStringType type = DegreeStringType::Decimal);
|
||||||
|
std::string
|
||||||
|
GetLongitudeString(double longitude,
|
||||||
|
DegreeStringType type = DegreeStringType::Decimal);
|
||||||
|
|
||||||
} // namespace common
|
} // namespace common
|
||||||
} // namespace scwx
|
} // namespace scwx
|
||||||
|
|
|
||||||
16
wxdata/source/scwx/common/characters.cpp
Normal file
16
wxdata/source/scwx/common/characters.cpp
Normal file
|
|
@ -0,0 +1,16 @@
|
||||||
|
#include <scwx/common/characters.hpp>
|
||||||
|
|
||||||
|
namespace scwx
|
||||||
|
{
|
||||||
|
namespace common
|
||||||
|
{
|
||||||
|
|
||||||
|
namespace Unicode
|
||||||
|
{
|
||||||
|
|
||||||
|
const std::string kDegree {"\302\260"};
|
||||||
|
|
||||||
|
} // namespace Unicode
|
||||||
|
|
||||||
|
} // namespace common
|
||||||
|
} // namespace scwx
|
||||||
77
wxdata/source/scwx/common/geographic.cpp
Normal file
77
wxdata/source/scwx/common/geographic.cpp
Normal file
|
|
@ -0,0 +1,77 @@
|
||||||
|
#include <scwx/common/geographic.hpp>
|
||||||
|
#include <scwx/common/characters.hpp>
|
||||||
|
|
||||||
|
#include <format>
|
||||||
|
|
||||||
|
namespace scwx
|
||||||
|
{
|
||||||
|
namespace common
|
||||||
|
{
|
||||||
|
|
||||||
|
static std::string GetDegreeString(double degrees,
|
||||||
|
DegreeStringType type,
|
||||||
|
const std::string& suffix);
|
||||||
|
|
||||||
|
std::string GetLatitudeString(double latitude, DegreeStringType type)
|
||||||
|
{
|
||||||
|
std::string suffix {};
|
||||||
|
|
||||||
|
if (latitude > 0.0)
|
||||||
|
{
|
||||||
|
suffix = " N";
|
||||||
|
}
|
||||||
|
else if (latitude < 0.0)
|
||||||
|
{
|
||||||
|
suffix = " S";
|
||||||
|
}
|
||||||
|
|
||||||
|
return GetDegreeString(latitude, type, suffix);
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string GetLongitudeString(double longitude, DegreeStringType type)
|
||||||
|
{
|
||||||
|
std::string suffix {};
|
||||||
|
|
||||||
|
if (longitude > 0.0)
|
||||||
|
{
|
||||||
|
suffix = " E";
|
||||||
|
}
|
||||||
|
else if (longitude < 0.0)
|
||||||
|
{
|
||||||
|
suffix = " W";
|
||||||
|
}
|
||||||
|
|
||||||
|
return GetDegreeString(longitude, type, suffix);
|
||||||
|
}
|
||||||
|
|
||||||
|
static std::string GetDegreeString(double degrees,
|
||||||
|
DegreeStringType type,
|
||||||
|
const std::string& suffix)
|
||||||
|
{
|
||||||
|
std::string degreeString {};
|
||||||
|
|
||||||
|
degrees = std::fabs(degrees);
|
||||||
|
|
||||||
|
switch (type)
|
||||||
|
{
|
||||||
|
case DegreeStringType::Decimal:
|
||||||
|
degreeString =
|
||||||
|
std::format("{:.6f}{}{}", degrees, Unicode::kDegree, suffix);
|
||||||
|
break;
|
||||||
|
case DegreeStringType::DegreesMinutesSeconds:
|
||||||
|
{
|
||||||
|
uint32_t dd = static_cast<uint32_t>(degrees);
|
||||||
|
degrees = (degrees - dd) * 60.0;
|
||||||
|
uint32_t mm = static_cast<uint32_t>(degrees);
|
||||||
|
double ss = (degrees - mm) * 60.0;
|
||||||
|
degreeString = std::format(
|
||||||
|
"{}{} {}' {:.2f}\"{}", dd, Unicode::kDegree, mm, ss, suffix);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return degreeString;
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace common
|
||||||
|
} // namespace scwx
|
||||||
|
|
@ -32,7 +32,9 @@ set(HDR_COMMON include/scwx/common/characters.hpp
|
||||||
include/scwx/common/sites.hpp
|
include/scwx/common/sites.hpp
|
||||||
include/scwx/common/types.hpp
|
include/scwx/common/types.hpp
|
||||||
include/scwx/common/vcp.hpp)
|
include/scwx/common/vcp.hpp)
|
||||||
set(SRC_COMMON source/scwx/common/color_table.cpp
|
set(SRC_COMMON source/scwx/common/characters.cpp
|
||||||
|
source/scwx/common/color_table.cpp
|
||||||
|
source/scwx/common/geographic.cpp
|
||||||
source/scwx/common/products.cpp
|
source/scwx/common/products.cpp
|
||||||
source/scwx/common/sites.cpp
|
source/scwx/common/sites.cpp
|
||||||
source/scwx/common/vcp.cpp)
|
source/scwx/common/vcp.cpp)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue