mirror of
				https://github.com/ciphervance/supercell-wx.git
				synced 2025-10-31 10:10:05 +00:00 
			
		
		
		
	Enable loading color palettes from embedded Qt resources
This commit is contained in:
		
							parent
							
								
									1f9392e9f6
								
							
						
					
					
						commit
						1d597eb120
					
				
					 8 changed files with 88 additions and 9 deletions
				
			
		|  | @ -156,6 +156,7 @@ set(UI_UI  source/scwx/qt/ui/alert_dialog.ui | |||
|            source/scwx/qt/ui/radar_site_dialog.ui | ||||
|            source/scwx/qt/ui/settings_dialog.ui) | ||||
| set(HDR_UTIL source/scwx/qt/util/color.hpp | ||||
|              source/scwx/qt/util/file.hpp | ||||
|              source/scwx/qt/util/font.hpp | ||||
|              source/scwx/qt/util/font_buffer.hpp | ||||
|              source/scwx/qt/util/json.hpp | ||||
|  | @ -164,6 +165,7 @@ set(HDR_UTIL source/scwx/qt/util/color.hpp | |||
|              source/scwx/qt/util/q_file_buffer.hpp | ||||
|              source/scwx/qt/util/q_file_input_stream.hpp) | ||||
| set(SRC_UTIL source/scwx/qt/util/color.cpp | ||||
|              source/scwx/qt/util/file.cpp | ||||
|              source/scwx/qt/util/font.cpp | ||||
|              source/scwx/qt/util/font_buffer.cpp | ||||
|              source/scwx/qt/util/json.cpp | ||||
|  |  | |||
|  | @ -23,6 +23,20 @@ | |||
|         <file>res/icons/font-awesome-6/sliders-solid.svg</file> | ||||
|         <file>res/icons/font-awesome-6/square-minus-regular.svg</file> | ||||
|         <file>res/icons/font-awesome-6/square-plus-regular.svg</file> | ||||
|         <file>res/palettes/wct/CC.pal</file> | ||||
|         <file>res/palettes/wct/Default16.pal</file> | ||||
|         <file>res/palettes/wct/DOD_DSD.pal</file> | ||||
|         <file>res/palettes/wct/DR.pal</file> | ||||
|         <file>res/palettes/wct/DV.pal</file> | ||||
|         <file>res/palettes/wct/ET.pal</file> | ||||
|         <file>res/palettes/wct/KDP.pal</file> | ||||
|         <file>res/palettes/wct/KDP2.pal</file> | ||||
|         <file>res/palettes/wct/OHP.pal</file> | ||||
|         <file>res/palettes/wct/SRV.pal</file> | ||||
|         <file>res/palettes/wct/STP.pal</file> | ||||
|         <file>res/palettes/wct/SW.pal</file> | ||||
|         <file>res/palettes/wct/VIL.pal</file> | ||||
|         <file>res/palettes/wct/ZDR.pal</file> | ||||
|         <file>res/textures/lines/default-1x7.png</file> | ||||
|         <file>res/textures/lines/test-pattern.png</file> | ||||
|     </qresource> | ||||
|  |  | |||
|  | @ -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); | ||||
|          } | ||||
| 
 | ||||
|  |  | |||
|  | @ -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); | ||||
|  |  | |||
							
								
								
									
										32
									
								
								scwx-qt/source/scwx/qt/util/file.cpp
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										32
									
								
								scwx-qt/source/scwx/qt/util/file.cpp
									
										
									
									
									
										Normal 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
 | ||||
							
								
								
									
										20
									
								
								scwx-qt/source/scwx/qt/util/file.hpp
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										20
									
								
								scwx-qt/source/scwx/qt/util/file.hpp
									
										
									
									
									
										Normal 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
 | ||||
|  | @ -1,5 +1,6 @@ | |||
| #pragma once | ||||
| 
 | ||||
| #include <istream> | ||||
| #include <memory> | ||||
| #include <string> | ||||
| #include <vector> | ||||
|  | @ -28,7 +29,7 @@ public: | |||
|    explicit ColorTable(); | ||||
|    ~ColorTable(); | ||||
| 
 | ||||
|    ColorTable(const ColorTable&) = delete; | ||||
|    ColorTable(const ColorTable&)            = delete; | ||||
|    ColorTable& operator=(const ColorTable&) = delete; | ||||
| 
 | ||||
|    ColorTable(ColorTable&&) noexcept; | ||||
|  | @ -40,6 +41,7 @@ public: | |||
|    bool                      IsValid() const; | ||||
| 
 | ||||
|    static std::shared_ptr<ColorTable> Load(const std::string& filename); | ||||
|    static std::shared_ptr<ColorTable> Load(std::istream& is); | ||||
| 
 | ||||
| private: | ||||
|    std::unique_ptr<ColorTableImpl> p; | ||||
|  |  | |||
|  | @ -137,13 +137,16 @@ bool ColorTable::IsValid() const | |||
| std::shared_ptr<ColorTable> ColorTable::Load(const std::string& filename) | ||||
| { | ||||
|    logger_->debug("Loading color table: {}", filename); | ||||
|    std::ifstream f(filename, std::ios_base::in); | ||||
|    return Load(f); | ||||
| } | ||||
| 
 | ||||
| std::shared_ptr<ColorTable> ColorTable::Load(std::istream& is) | ||||
| { | ||||
|    std::shared_ptr<ColorTable> p = std::make_shared<ColorTable>(); | ||||
| 
 | ||||
|    std::ifstream f(filename, std::ios_base::in); | ||||
| 
 | ||||
|    std::string line; | ||||
|    while (scwx::util::getline(f, line)) | ||||
|    while (scwx::util::getline(is, line)) | ||||
|    { | ||||
|       std::string              token; | ||||
|       std::istringstream       tokens(line); | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Dan Paulat
						Dan Paulat