mirror of
				https://github.com/ciphervance/supercell-wx.git
				synced 2025-10-31 04:10:06 +00:00 
			
		
		
		
	Create LayerModel singleton
This commit is contained in:
		
							parent
							
								
									dd7bfc7a6f
								
							
						
					
					
						commit
						b6aef07af4
					
				
					 3 changed files with 26 additions and 6 deletions
				
			
		|  | @ -1117,6 +1117,24 @@ LayerInfo tag_invoke(boost::json::value_to_tag<LayerInfo>, | |||
|       boost::json::value_to<std::array<bool, 4>>(jv.at(kDisplayedName_))}; | ||||
| } | ||||
| 
 | ||||
| std::shared_ptr<LayerModel> LayerModel::Instance() | ||||
| { | ||||
|    static std::weak_ptr<LayerModel> layerModelReference_ {}; | ||||
|    static std::mutex                instanceMutex_ {}; | ||||
| 
 | ||||
|    std::unique_lock lock(instanceMutex_); | ||||
| 
 | ||||
|    std::shared_ptr<LayerModel> layerModel = layerModelReference_.lock(); | ||||
| 
 | ||||
|    if (layerModel == nullptr) | ||||
|    { | ||||
|       layerModel           = std::make_shared<LayerModel>(); | ||||
|       layerModelReference_ = layerModel; | ||||
|    } | ||||
| 
 | ||||
|    return layerModel; | ||||
| } | ||||
| 
 | ||||
| } // namespace model
 | ||||
| } // namespace qt
 | ||||
| } // namespace scwx
 | ||||
|  |  | |||
|  | @ -74,6 +74,8 @@ public: | |||
|                  const QModelIndex& destinationParent, | ||||
|                  int                destinationChild) override; | ||||
| 
 | ||||
|    static std::shared_ptr<LayerModel> Instance(); | ||||
| 
 | ||||
| public slots: | ||||
|    void HandlePlacefileRemoved(const std::string& name); | ||||
|    void HandlePlacefileRenamed(const std::string& oldName, | ||||
|  |  | |||
|  | @ -22,10 +22,10 @@ class LayerDialogImpl | |||
| public: | ||||
|    explicit LayerDialogImpl(LayerDialog* self) : | ||||
|        self_ {self}, | ||||
|        layerModel_ {new model::LayerModel(self)}, | ||||
|        layerModel_ {model::LayerModel::Instance()}, | ||||
|        layerProxyModel_ {new QSortFilterProxyModel(self_)} | ||||
|    { | ||||
|       layerProxyModel_->setSourceModel(layerModel_); | ||||
|       layerProxyModel_->setSourceModel(layerModel_.get()); | ||||
|       layerProxyModel_->setFilterCaseSensitivity( | ||||
|          Qt::CaseSensitivity::CaseInsensitive); | ||||
|       layerProxyModel_->setFilterKeyColumn(-1); | ||||
|  | @ -38,9 +38,9 @@ public: | |||
|    std::vector<int>              GetSelectedRows(); | ||||
|    std::vector<std::vector<int>> GetContiguousRows(); | ||||
| 
 | ||||
|    LayerDialog*           self_; | ||||
|    model::LayerModel*     layerModel_; | ||||
|    QSortFilterProxyModel* layerProxyModel_; | ||||
|    LayerDialog*                       self_; | ||||
|    std::shared_ptr<model::LayerModel> layerModel_; | ||||
|    QSortFilterProxyModel*             layerProxyModel_; | ||||
| }; | ||||
| 
 | ||||
| LayerDialog::LayerDialog(QWidget* parent) : | ||||
|  | @ -101,7 +101,7 @@ void LayerDialogImpl::ConnectSignals() | |||
|                            const QItemSelection& /* deselected */) | ||||
|                     { UpdateMoveButtonsEnabled(); }); | ||||
| 
 | ||||
|    QObject::connect(layerModel_, | ||||
|    QObject::connect(layerModel_.get(), | ||||
|                     &QAbstractItemModel::rowsMoved, | ||||
|                     self_, | ||||
|                     [this]() | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Dan Paulat
						Dan Paulat