Create LayerModel singleton

This commit is contained in:
Dan Paulat 2023-10-28 05:54:38 -05:00
parent dd7bfc7a6f
commit b6aef07af4
3 changed files with 26 additions and 6 deletions

View file

@ -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

View file

@ -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,