mirror of
https://github.com/ciphervance/supercell-wx.git
synced 2025-10-30 19:50:05 +00:00
initial poi manager and types code
This commit is contained in:
parent
f8efa20b7c
commit
c2209908a0
3 changed files with 169 additions and 0 deletions
109
scwx-qt/source/scwx/qt/manager/poi_manager.cpp
Normal file
109
scwx-qt/source/scwx/qt/manager/poi_manager.cpp
Normal file
|
|
@ -0,0 +1,109 @@
|
|||
#include <scwx/qt/manager/poi_manager.hpp>
|
||||
#include <scwx/util/logger.hpp>
|
||||
#include <scwx/qt/util/json.hpp>
|
||||
|
||||
#include <filesystem>
|
||||
|
||||
#include <boost/json.hpp>
|
||||
|
||||
namespace scwx
|
||||
{
|
||||
namespace qt
|
||||
{
|
||||
namespace manager
|
||||
{
|
||||
|
||||
static const std::string logPrefix_ = "scwx::qt::manager::placefile_manager";
|
||||
static const auto logger_ = scwx::util::Logger::Create(logPrefix_);
|
||||
|
||||
static const std::string kNameName_ = "name";
|
||||
static const std::string kLatitudeName_ = "latitude";
|
||||
static const std::string kLongitudeName_ = "longitude";
|
||||
|
||||
class POIManager::Impl
|
||||
{
|
||||
public:
|
||||
class PointOfInterest;
|
||||
|
||||
explicit Impl(POIManager* self) : self_ {self} {}
|
||||
|
||||
std::string poiSettingsPath_ {};
|
||||
|
||||
POIManager* self_;
|
||||
|
||||
void ReadPOISettings();
|
||||
|
||||
};
|
||||
|
||||
class POIManager::Impl::PointOfInterest
|
||||
{
|
||||
public:
|
||||
PointOfInterest(std::string name, double latitude, double longitude) :
|
||||
name_ {name}, latitude_ {latitude}, longitude_ {longitude}
|
||||
{
|
||||
}
|
||||
|
||||
std::string name_;
|
||||
double latitude_;
|
||||
double longitude_;
|
||||
|
||||
friend void tag_invoke(boost::json::value_from_tag,
|
||||
boost::json::value& jv,
|
||||
const std::shared_ptr<PointOfInterest>& record)
|
||||
{
|
||||
jv = {{kNameName_, record->name_},
|
||||
{kLatitudeName_, record->latitude_},
|
||||
{kLongitudeName_, record->longitude_}};
|
||||
}
|
||||
|
||||
friend PointOfInterest tag_invoke(boost::json::value_to_tag<PointOfInterest>,
|
||||
const boost::json::value& jv)
|
||||
{
|
||||
return PointOfInterest(
|
||||
boost::json::value_to<std::string>(jv.at(kNameName_)),
|
||||
boost::json::value_to<double>(jv.at(kLatitudeName_)),
|
||||
boost::json::value_to<double>(jv.at(kLongitudeName_)));
|
||||
}
|
||||
};
|
||||
|
||||
POIManager::POIManager() : p(std::make_unique<Impl>(this)) {}
|
||||
|
||||
void POIManager::Impl::ReadPOISettings()
|
||||
{
|
||||
logger_->info("Reading point of intrest settings");
|
||||
|
||||
boost::json::value poiJson = nullptr;
|
||||
|
||||
// Determine if poi settings exists
|
||||
if (std::filesystem::exists(poiSettingsPath_))
|
||||
{
|
||||
poiJson = util::json::ReadJsonFile(poiSettingsPath_);
|
||||
}
|
||||
|
||||
if (poiJson != nullptr && poiJson.is_array())
|
||||
{
|
||||
// For each poi entry
|
||||
auto& poiArray = poiJson.as_array();
|
||||
for (auto& poiEntry : poiArray)
|
||||
{
|
||||
try
|
||||
{
|
||||
PointOfInterest record =
|
||||
boost::json::value_to<PointOfInterest>(poiEntry);
|
||||
|
||||
if (!record.name_.empty())
|
||||
{
|
||||
// Add record
|
||||
}
|
||||
}
|
||||
catch (const std::exception& ex)
|
||||
{
|
||||
logger_->warn("Invalid point of interest entry: {}", ex.what());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace manager
|
||||
} // namespace qt
|
||||
} // namespace scwx
|
||||
30
scwx-qt/source/scwx/qt/manager/poi_manager.hpp
Normal file
30
scwx-qt/source/scwx/qt/manager/poi_manager.hpp
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
#pragma once
|
||||
|
||||
#include <scwx/qt/types/poi_types.hpp>
|
||||
|
||||
#include <QObject>
|
||||
|
||||
namespace scwx
|
||||
{
|
||||
namespace qt
|
||||
{
|
||||
namespace manager
|
||||
{
|
||||
|
||||
class POIManager : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit POIManager();
|
||||
~POIManager();
|
||||
|
||||
|
||||
private:
|
||||
class Impl;
|
||||
std::unique_ptr<Impl> p;
|
||||
};
|
||||
|
||||
} // namespace manager
|
||||
} // namespace qt
|
||||
} // namespace scwx
|
||||
30
scwx-qt/source/scwx/qt/types/poi_types.hpp
Normal file
30
scwx-qt/source/scwx/qt/types/poi_types.hpp
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
#pragma once
|
||||
|
||||
#include <string>
|
||||
|
||||
namespace scwx
|
||||
{
|
||||
namespace qt
|
||||
{
|
||||
namespace types
|
||||
{
|
||||
|
||||
struct PointOfInterest
|
||||
{
|
||||
PointOfInterest(std::string name,
|
||||
double latitude,
|
||||
double longitude) :
|
||||
name_ {name},
|
||||
latitude_ {latitude},
|
||||
longitude_ {longitude}
|
||||
{
|
||||
}
|
||||
|
||||
std::string name_;
|
||||
double latitude_;
|
||||
double longitude_;
|
||||
};
|
||||
|
||||
} // namespace types
|
||||
} // namespace qt
|
||||
} // namespace scwx
|
||||
Loading…
Add table
Add a link
Reference in a new issue