Enable loading color palettes from embedded Qt resources

This commit is contained in:
Dan Paulat 2023-01-02 00:23:46 -06:00
parent 1f9392e9f6
commit 1d597eb120
8 changed files with 88 additions and 9 deletions

View file

@ -9,6 +9,7 @@
#include <scwx/qt/map/radar_product_layer.hpp>
#include <scwx/qt/map/radar_range_layer.hpp>
#include <scwx/qt/model/imgui_context_model.hpp>
#include <scwx/qt/util/file.hpp>
#include <scwx/qt/view/radar_product_view_factory.hpp>
#include <scwx/util/logger.hpp>
#include <scwx/util/threads.hpp>
@ -415,7 +416,7 @@ void MapWidget::SelectRadarProduct(
radarId,
common::GetRadarProductGroupName(group),
product,
util::TimeString(time));
scwx::util::TimeString(time));
p->SetRadarSite(radarId);
p->selectedTime_ = time;
@ -796,7 +797,7 @@ void MapWidgetImpl::RadarProductManagerConnect()
});
// Load file
util::async(
scwx::util::async(
[=]()
{
if (group == common::RadarProductGroup::Level2)
@ -830,7 +831,7 @@ void MapWidgetImpl::RadarProductManagerDisconnect()
void MapWidgetImpl::InitializeNewRadarProductView(
const std::string& colorPalette)
{
util::async(
scwx::util::async(
[=]()
{
auto radarProductView = context_->radar_product_view();
@ -841,8 +842,10 @@ void MapWidgetImpl::InitializeNewRadarProductView(
.GetValue();
if (!colorTableFile.empty())
{
std::unique_ptr<std::istream> colorTableStream =
util::OpenFile(colorTableFile);
std::shared_ptr<common::ColorTable> colorTable =
common::ColorTable::Load(colorTableFile);
common::ColorTable::Load(*colorTableStream);
radarProductView->LoadColorTable(colorTable);
}

View file

@ -8,6 +8,7 @@
#include <scwx/qt/settings/settings_interface.hpp>
#include <scwx/qt/ui/radar_site_dialog.hpp>
#include <scwx/qt/util/color.hpp>
#include <scwx/qt/util/file.hpp>
#include <scwx/util/logger.hpp>
#include <scwx/util/threads.hpp>
@ -557,8 +558,10 @@ void SettingsDialogImpl::LoadColorTablePreview(const std::string& key,
scwx::util::async(
[key, value, imageLabel]()
{
std::unique_ptr<std::istream> is = util::OpenFile(value);
std::shared_ptr<common::ColorTable> colorTable =
common::ColorTable::Load(value);
common::ColorTable::Load(*is);
if (colorTable->IsValid())
{
auto& conversions = kColorTableConversions_.at(key);

View file

@ -0,0 +1,32 @@
#include <scwx/qt/util/file.hpp>
#include <scwx/qt/util/q_file_input_stream.hpp>
#include <fstream>
#include <QFile>
namespace scwx
{
namespace qt
{
namespace util
{
static const std::string logPrefix_ = "scwx::qt::util::file";
std::unique_ptr<std::istream> OpenFile(const std::string& filename,
std::ios_base::openmode mode)
{
if (filename.starts_with(':'))
{
return std::make_unique<QFileInputStream>(filename, mode);
}
else
{
return std::make_unique<std::ifstream>(filename, mode);
}
}
} // namespace util
} // namespace qt
} // namespace scwx

View file

@ -0,0 +1,20 @@
#pragma once
#include <istream>
#include <memory>
#include <string>
namespace scwx
{
namespace qt
{
namespace util
{
std::unique_ptr<std::istream>
OpenFile(const std::string& filename,
std::ios_base::openmode mode = std::ios_base::in);
} // namespace util
} // namespace qt
} // namespace scwx