mirror of
				https://github.com/ciphervance/supercell-wx.git
				synced 2025-10-31 03:20:05 +00:00 
			
		
		
		
	Synchronize placefile layers with placefile manager after initialization
This commit is contained in:
		
							parent
							
								
									b6aef07af4
								
							
						
					
					
						commit
						ba75326c0c
					
				
					 3 changed files with 44 additions and 0 deletions
				
			
		|  | @ -162,6 +162,7 @@ PlacefileManager::PlacefileManager() : p(std::make_unique<Impl>(this)) | ||||||
|                         // Read placefile settings on startup
 |                         // Read placefile settings on startup
 | ||||||
|                         main::Application::WaitForInitialization(); |                         main::Application::WaitForInitialization(); | ||||||
|                         p->ReadPlacefileSettings(); |                         p->ReadPlacefileSettings(); | ||||||
|  |                         Q_EMIT PlacefilesInitialized(); | ||||||
|                      }); |                      }); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -51,6 +51,7 @@ public: | ||||||
|    static std::shared_ptr<PlacefileManager> Instance(); |    static std::shared_ptr<PlacefileManager> Instance(); | ||||||
| 
 | 
 | ||||||
| signals: | signals: | ||||||
|  |    void PlacefilesInitialized(); | ||||||
|    void PlacefileEnabled(const std::string& name, bool enabled); |    void PlacefileEnabled(const std::string& name, bool enabled); | ||||||
|    void PlacefileRemoved(const std::string& name); |    void PlacefileRemoved(const std::string& name); | ||||||
|    void PlacefileRenamed(const std::string& oldName, |    void PlacefileRenamed(const std::string& oldName, | ||||||
|  |  | ||||||
|  | @ -99,6 +99,7 @@ public: | ||||||
|    void AddPlacefile(const std::string& name); |    void AddPlacefile(const std::string& name); | ||||||
|    void InitializeLayerSettings(); |    void InitializeLayerSettings(); | ||||||
|    void ReadLayerSettings(); |    void ReadLayerSettings(); | ||||||
|  |    void SynchronizePlacefileLayers(); | ||||||
|    void WriteLayerSettings(); |    void WriteLayerSettings(); | ||||||
| 
 | 
 | ||||||
|    static void ValidateLayerSettings(LayerVector& layers); |    static void ValidateLayerSettings(LayerVector& layers); | ||||||
|  | @ -107,6 +108,9 @@ public: | ||||||
| 
 | 
 | ||||||
|    std::string layerSettingsPath_ {}; |    std::string layerSettingsPath_ {}; | ||||||
| 
 | 
 | ||||||
|  |    bool                     placefilesInitialized_ {false}; | ||||||
|  |    std::vector<std::string> initialPlacefiles_ {}; | ||||||
|  | 
 | ||||||
|    std::shared_ptr<manager::PlacefileManager> placefileManager_ { |    std::shared_ptr<manager::PlacefileManager> placefileManager_ { | ||||||
|       manager::PlacefileManager::Instance()}; |       manager::PlacefileManager::Instance()}; | ||||||
| 
 | 
 | ||||||
|  | @ -116,6 +120,11 @@ public: | ||||||
| LayerModel::LayerModel(QObject* parent) : | LayerModel::LayerModel(QObject* parent) : | ||||||
|     QAbstractTableModel(parent), p(std::make_unique<Impl>(this)) |     QAbstractTableModel(parent), p(std::make_unique<Impl>(this)) | ||||||
| { | { | ||||||
|  |    connect(p->placefileManager_.get(), | ||||||
|  |            &manager::PlacefileManager::PlacefilesInitialized, | ||||||
|  |            this, | ||||||
|  |            [this]() { p->SynchronizePlacefileLayers(); }); | ||||||
|  | 
 | ||||||
|    connect(p->placefileManager_.get(), |    connect(p->placefileManager_.get(), | ||||||
|            &manager::PlacefileManager::PlacefileEnabled, |            &manager::PlacefileManager::PlacefileEnabled, | ||||||
|            this, |            this, | ||||||
|  | @ -430,6 +439,34 @@ void LayerModel::ResetLayers() | ||||||
|    endResetModel(); |    endResetModel(); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | void LayerModel::Impl::SynchronizePlacefileLayers() | ||||||
|  | { | ||||||
|  |    placefilesInitialized_ = true; | ||||||
|  | 
 | ||||||
|  |    int row = 0; | ||||||
|  |    for (auto it = layers_.begin(); it != layers_.end();) | ||||||
|  |    { | ||||||
|  |       if (it->type_ == types::LayerType::Placefile && | ||||||
|  |           std::find(initialPlacefiles_.begin(), | ||||||
|  |                     initialPlacefiles_.end(), | ||||||
|  |                     std::get<std::string>(it->description_)) == | ||||||
|  |              initialPlacefiles_.end()) | ||||||
|  |       { | ||||||
|  |          // If the placefile layer was not loaded by the placefile manager,
 | ||||||
|  |          // erase it
 | ||||||
|  |          self_->beginRemoveRows(QModelIndex(), row, row); | ||||||
|  |          it = layers_.erase(it); | ||||||
|  |          self_->endRemoveRows(); | ||||||
|  |          continue; | ||||||
|  |       } | ||||||
|  | 
 | ||||||
|  |       ++it; | ||||||
|  |       ++row; | ||||||
|  |    } | ||||||
|  | 
 | ||||||
|  |    initialPlacefiles_.clear(); | ||||||
|  | } | ||||||
|  | 
 | ||||||
| int LayerModel::rowCount(const QModelIndex& parent) const | int LayerModel::rowCount(const QModelIndex& parent) const | ||||||
| { | { | ||||||
|    return parent.isValid() ? 0 : static_cast<int>(p->layers_.size()); |    return parent.isValid() ? 0 : static_cast<int>(p->layers_.size()); | ||||||
|  | @ -973,6 +1010,11 @@ void LayerModel::HandlePlacefileRenamed(const std::string& oldName, | ||||||
| 
 | 
 | ||||||
| void LayerModel::HandlePlacefileUpdate(const std::string& name) | void LayerModel::HandlePlacefileUpdate(const std::string& name) | ||||||
| { | { | ||||||
|  |    if (!p->placefilesInitialized_) | ||||||
|  |    { | ||||||
|  |       p->initialPlacefiles_.push_back(name); | ||||||
|  |    } | ||||||
|  | 
 | ||||||
|    auto it = |    auto it = | ||||||
|       std::find_if(p->layers_.begin(), |       std::find_if(p->layers_.begin(), | ||||||
|                    p->layers_.end(), |                    p->layers_.end(), | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Dan Paulat
						Dan Paulat