mirror of
https://github.com/ciphervance/supercell-wx.git
synced 2025-10-30 16:40:05 +00:00
Added location marker icon support to marker_types and marker_manager
This commit is contained in:
parent
7ed89fdd5d
commit
6da34fc151
3 changed files with 67 additions and 14 deletions
|
|
@ -1,5 +1,6 @@
|
|||
#include <scwx/qt/manager/marker_manager.hpp>
|
||||
#include <scwx/qt/types/marker_types.hpp>
|
||||
#include <scwx/qt/util/color.hpp>
|
||||
#include <scwx/qt/util/json.hpp>
|
||||
#include <scwx/qt/main/application.hpp>
|
||||
#include <scwx/util/logger.hpp>
|
||||
|
|
@ -27,6 +28,12 @@ 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";
|
||||
static const std::string kIconName_ = "icon";
|
||||
static const std::string kIconColorName_ = "icon-color";
|
||||
|
||||
static const std::string defaultIconName = types::getMarkerIcons()[0].name;
|
||||
static const boost::gil::rgba8_pixel_t defaultIconColor =
|
||||
util::color::ToRgba8PixelT("#ffff0000");
|
||||
|
||||
class MarkerManager::Impl
|
||||
{
|
||||
|
|
@ -59,10 +66,7 @@ public:
|
|||
class MarkerManager::Impl::MarkerRecord
|
||||
{
|
||||
public:
|
||||
MarkerRecord(const std::string& name, double latitude, double longitude) :
|
||||
markerInfo_ {types::MarkerInfo(name, latitude, longitude)}
|
||||
{
|
||||
}
|
||||
|
||||
MarkerRecord(const types::MarkerInfo& info) :
|
||||
markerInfo_ {info}
|
||||
{
|
||||
|
|
@ -81,16 +85,47 @@ public:
|
|||
{
|
||||
jv = {{kNameName_, record->markerInfo_.name},
|
||||
{kLatitudeName_, record->markerInfo_.latitude},
|
||||
{kLongitudeName_, record->markerInfo_.longitude}};
|
||||
{kLongitudeName_, record->markerInfo_.longitude},
|
||||
{kIconName_, record->markerInfo_.iconName},
|
||||
{kIconColorName_, util::color::ToArgbString(record->markerInfo_.iconColor)}};
|
||||
}
|
||||
|
||||
|
||||
friend MarkerRecord tag_invoke(boost::json::value_to_tag<MarkerRecord>,
|
||||
const boost::json::value& jv)
|
||||
{
|
||||
return MarkerRecord(
|
||||
|
||||
const boost::json::object& jo = jv.as_object();
|
||||
|
||||
std::string iconName = defaultIconName;
|
||||
boost::gil::rgba8_pixel_t iconColor = defaultIconColor;
|
||||
|
||||
if (jo.contains(kIconName_) && jo.at(kIconName_).is_string())
|
||||
{
|
||||
iconName = boost::json::value_to<std::string>(jv.at(kIconName_));
|
||||
}
|
||||
|
||||
if (jo.contains(kIconColorName_) && jo.at(kIconName_).is_string())
|
||||
{
|
||||
try {
|
||||
iconColor = util::color::ToRgba8PixelT(
|
||||
boost::json::value_to<std::string>(jv.at(kIconColorName_)));
|
||||
}
|
||||
catch (const std::exception& ex)
|
||||
{
|
||||
logger_->warn(
|
||||
"Could not parse color value in location-markers.json with the "
|
||||
"following exception: {}",
|
||||
ex.what());
|
||||
}
|
||||
}
|
||||
|
||||
return MarkerRecord(types::MarkerInfo(
|
||||
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_)));
|
||||
boost::json::value_to<double>(jv.at(kLongitudeName_)),
|
||||
iconName,
|
||||
iconColor));
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@
|
|||
#include <string>
|
||||
#include <cstdint>
|
||||
|
||||
#include <boost/gil.hpp>
|
||||
#include <QIcon>
|
||||
|
||||
namespace scwx
|
||||
|
|
@ -17,15 +18,25 @@ typedef std::uint64_t MarkerId;
|
|||
|
||||
struct MarkerInfo
|
||||
{
|
||||
MarkerInfo(const std::string& name, double latitude, double longitude) :
|
||||
name {name}, latitude {latitude}, longitude {longitude}
|
||||
MarkerInfo(const std::string& name,
|
||||
double latitude,
|
||||
double longitude,
|
||||
const std::string iconName,
|
||||
boost::gil::rgba8_pixel_t iconColor) :
|
||||
name {name},
|
||||
latitude {latitude},
|
||||
longitude {longitude},
|
||||
iconName {iconName},
|
||||
iconColor {iconColor}
|
||||
{
|
||||
}
|
||||
|
||||
MarkerId id;
|
||||
std::string name;
|
||||
double latitude;
|
||||
double longitude;
|
||||
MarkerId id;
|
||||
std::string name;
|
||||
double latitude;
|
||||
double longitude;
|
||||
std::string iconName;
|
||||
boost::gil::rgba8_pixel_t iconColor;
|
||||
};
|
||||
|
||||
struct MarkerIconInfo {
|
||||
|
|
|
|||
|
|
@ -7,6 +7,8 @@
|
|||
#include <scwx/qt/ui/open_url_dialog.hpp>
|
||||
#include <scwx/util/logger.hpp>
|
||||
|
||||
#include <scwx/qt/util/color.hpp>
|
||||
|
||||
#include <QSortFilterProxyModel>
|
||||
|
||||
namespace scwx
|
||||
|
|
@ -63,7 +65,12 @@ void MarkerSettingsWidgetImpl::ConnectSignals()
|
|||
self_,
|
||||
[this]()
|
||||
{
|
||||
markerManager_->add_marker(types::MarkerInfo("", 0, 0));
|
||||
markerManager_->add_marker(types::MarkerInfo(
|
||||
"",
|
||||
0,
|
||||
0,
|
||||
types::getMarkerIcons()[0].name,
|
||||
util::color::ToRgba8PixelT("#ffff0000")));
|
||||
});
|
||||
QObject::connect(
|
||||
self_->ui->removeButton,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue