mirror of
				https://github.com/ciphervance/supercell-wx.git
				synced 2025-10-31 15:00:06 +00:00 
			
		
		
		
	Add mapbox_api_key to settings
This commit is contained in:
		
							parent
							
								
									ba64627f5d
								
							
						
					
					
						commit
						a96e017917
					
				
					 7 changed files with 47 additions and 11 deletions
				
			
		|  | @ -57,7 +57,11 @@ public: | |||
|          } | ||||
|       } | ||||
| 
 | ||||
|       std::string mapboxApiKey = | ||||
|          manager::SettingsManager::general_settings()->mapbox_api_key(); | ||||
| 
 | ||||
|       settings_.resetToTemplate(QMapboxGLSettings::MapboxSettings); | ||||
|       settings_.setApiKey(QString {mapboxApiKey.c_str()}); | ||||
|       settings_.setCacheDatabasePath(QString {cacheDbPath.c_str()}); | ||||
|       settings_.setCacheDatabaseMaximumSize(20 * 1024 * 1024); | ||||
|    } | ||||
|  |  | |||
|  | @ -15,6 +15,7 @@ static const auto        logger_    = scwx::util::Logger::Create(logPrefix_); | |||
| static const std::string DEFAULT_DEFAULT_RADAR_SITE = "KLSX"; | ||||
| static const int64_t     DEFAULT_GRID_WIDTH         = 1; | ||||
| static const int64_t     DEFAULT_GRID_HEIGHT        = 1; | ||||
| static const std::string DEFAULT_MAPBOX_API_KEY     = "?"; | ||||
| 
 | ||||
| static const int64_t GRID_WIDTH_MINIMUM  = 1; | ||||
| static const int64_t GRID_WIDTH_MAXIMUM  = 2; | ||||
|  | @ -24,7 +25,7 @@ static const int64_t GRID_HEIGHT_MAXIMUM = 2; | |||
| class GeneralSettingsImpl | ||||
| { | ||||
| public: | ||||
|    explicit GeneralSettingsImpl() {} | ||||
|    explicit GeneralSettingsImpl() { SetDefaults(); } | ||||
| 
 | ||||
|    ~GeneralSettingsImpl() {} | ||||
| 
 | ||||
|  | @ -33,11 +34,13 @@ public: | |||
|       defaultRadarSite_ = DEFAULT_DEFAULT_RADAR_SITE; | ||||
|       gridWidth_        = DEFAULT_GRID_WIDTH; | ||||
|       gridHeight_       = DEFAULT_GRID_HEIGHT; | ||||
|       mapboxApiKey_     = DEFAULT_MAPBOX_API_KEY; | ||||
|    } | ||||
| 
 | ||||
|    std::string defaultRadarSite_; | ||||
|    int64_t     gridWidth_; | ||||
|    int64_t     gridHeight_; | ||||
|    std::string mapboxApiKey_; | ||||
| }; | ||||
| 
 | ||||
| GeneralSettings::GeneralSettings() : p(std::make_unique<GeneralSettingsImpl>()) | ||||
|  | @ -49,7 +52,7 @@ GeneralSettings::GeneralSettings(GeneralSettings&&) noexcept = default; | |||
| GeneralSettings& | ||||
| GeneralSettings::operator=(GeneralSettings&&) noexcept = default; | ||||
| 
 | ||||
| const std::string& GeneralSettings::default_radar_site() const | ||||
| std::string GeneralSettings::default_radar_site() const | ||||
| { | ||||
|    return p->defaultRadarSite_; | ||||
| } | ||||
|  | @ -64,6 +67,11 @@ int64_t GeneralSettings::grid_width() const | |||
|    return p->gridWidth_; | ||||
| } | ||||
| 
 | ||||
| std::string GeneralSettings::mapbox_api_key() const | ||||
| { | ||||
|    return p->mapboxApiKey_; | ||||
| } | ||||
| 
 | ||||
| boost::json::value GeneralSettings::ToJson() const | ||||
| { | ||||
|    boost::json::object json; | ||||
|  | @ -71,6 +79,7 @@ boost::json::value GeneralSettings::ToJson() const | |||
|    json["default_radar_site"] = p->defaultRadarSite_; | ||||
|    json["grid_width"]         = p->gridWidth_; | ||||
|    json["grid_height"]        = p->gridHeight_; | ||||
|    json["mapbox_api_key"]     = p->mapboxApiKey_; | ||||
| 
 | ||||
|    return json; | ||||
| } | ||||
|  | @ -110,6 +119,12 @@ GeneralSettings::Load(const boost::json::value* json, bool& jsonDirty) | |||
|                                               DEFAULT_GRID_HEIGHT, | ||||
|                                               GRID_HEIGHT_MINIMUM, | ||||
|                                               GRID_HEIGHT_MAXIMUM); | ||||
|       jsonDirty |= | ||||
|          !util::json::FromJsonString(json->as_object(), | ||||
|                                      "mapbox_api_key", | ||||
|                                      generalSettings->p->mapboxApiKey_, | ||||
|                                      DEFAULT_MAPBOX_API_KEY, | ||||
|                                      1); | ||||
|    } | ||||
|    else | ||||
|    { | ||||
|  | @ -133,7 +148,8 @@ bool operator==(const GeneralSettings& lhs, const GeneralSettings& rhs) | |||
| { | ||||
|    return (lhs.p->defaultRadarSite_ == rhs.p->defaultRadarSite_ && | ||||
|            lhs.p->gridWidth_ == rhs.p->gridWidth_ && | ||||
|            lhs.p->gridHeight_ == rhs.p->gridHeight_); | ||||
|            lhs.p->gridHeight_ == rhs.p->gridHeight_ && | ||||
|            lhs.p->mapboxApiKey_ == rhs.p->mapboxApiKey_); | ||||
| } | ||||
| 
 | ||||
| } // namespace settings
 | ||||
|  |  | |||
|  | @ -26,9 +26,10 @@ public: | |||
|    GeneralSettings(GeneralSettings&&) noexcept; | ||||
|    GeneralSettings& operator=(GeneralSettings&&) noexcept; | ||||
| 
 | ||||
|    const std::string& default_radar_site() const; | ||||
|    std::string default_radar_site() const; | ||||
|    int64_t     grid_height() const; | ||||
|    int64_t     grid_width() const; | ||||
|    std::string mapbox_api_key() const; | ||||
| 
 | ||||
|    boost::json::value ToJson() const; | ||||
| 
 | ||||
|  |  | |||
|  | @ -92,7 +92,8 @@ bool FromJsonInt64(const boost::json::object& json, | |||
| bool FromJsonString(const boost::json::object& json, | ||||
|                     const std::string&         key, | ||||
|                     std::string&               value, | ||||
|                     const std::string&         defaultValue) | ||||
|                     const std::string&         defaultValue, | ||||
|                     size_t                     minLength) | ||||
| { | ||||
|    const boost::json::value* jv    = json.if_contains(key); | ||||
|    bool                      dirty = true; | ||||
|  | @ -102,9 +103,22 @@ bool FromJsonString(const boost::json::object& json, | |||
|       if (jv->is_string()) | ||||
|       { | ||||
|          value = boost::json::value_to<std::string>(*jv); | ||||
| 
 | ||||
|          if (value.length() >= minLength) | ||||
|          { | ||||
|             dirty = false; | ||||
|          } | ||||
|          else | ||||
|          { | ||||
|             logger_->warn( | ||||
|                "{} is shorter than {} characters, setting to default: {}", | ||||
|                key, | ||||
|                minLength, | ||||
|                defaultValue); | ||||
|             value = defaultValue; | ||||
|          } | ||||
|       } | ||||
|       else | ||||
|       { | ||||
|          logger_->warn( | ||||
|             "{} is not a string, setting to default: {}", key, defaultValue); | ||||
|  |  | |||
|  | @ -22,7 +22,8 @@ bool FromJsonInt64(const boost::json::object& json, | |||
| bool FromJsonString(const boost::json::object& json, | ||||
|                     const std::string&         key, | ||||
|                     std::string&               value, | ||||
|                     const std::string&         defaultValue); | ||||
|                     const std::string&         defaultValue, | ||||
|                     size_t                     minLength = 0); | ||||
| 
 | ||||
| boost::json::value ReadJsonFile(const std::string& path); | ||||
| void               WriteJsonFile(const std::string&        path, | ||||
|  |  | |||
|  | @ -102,7 +102,7 @@ | |||
| <context> | ||||
|     <name>scwx::qt::main::MainWindow</name> | ||||
|     <message> | ||||
|         <location filename="../source/scwx/qt/main/main_window.cpp" line="279"/> | ||||
|         <location filename="../source/scwx/qt/main/main_window.cpp" line="283"/> | ||||
|         <source>Unrecognized NEXRAD Product:</source> | ||||
|         <translation type="unfinished"></translation> | ||||
|     </message> | ||||
|  |  | |||
|  | @ -1 +1 @@ | |||
| Subproject commit ede24dd1b4e1f7f4591217769b74f80ca6ebbcf1 | ||||
| Subproject commit 288b2cb9b2dd540d44f684229973a97e61c79911 | ||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Dan Paulat
						Dan Paulat