Add reset button to layer manager

This commit is contained in:
Dan Paulat 2023-10-28 05:39:54 -05:00
parent f222b4f666
commit dd7bfc7a6f
4 changed files with 50 additions and 1 deletions

View file

@ -396,6 +396,40 @@ void LayerModel::Impl::WriteLayerSettings()
util::json::WriteJsonFile(layerSettingsPath_, layerJson);
}
void LayerModel::ResetLayers()
{
// Initialize a new layer vector from the default
LayerVector newLayers {};
newLayers.assign(kDefaultLayers_.cbegin(), kDefaultLayers_.cend());
auto colorTableIterator = std::find_if(
newLayers.begin(),
newLayers.end(),
[](const LayerInfo& layerInfo)
{
return std::holds_alternative<types::InformationLayer>(
layerInfo.description_) &&
std::get<types::InformationLayer>(layerInfo.description_) ==
types::InformationLayer::ColorTable;
});
// Add all existing placefile layers
for (auto it = p->layers_.rbegin(); it != p->layers_.rend(); ++it)
{
if (it->type_ == types::LayerType::Placefile)
{
newLayers.insert(
colorTableIterator + 1,
{it->type_, it->description_, it->movable_, it->displayed_});
}
}
// Swap the model
beginResetModel();
p->layers_.swap(newLayers);
endResetModel();
}
int LayerModel::rowCount(const QModelIndex& parent) const
{
return parent.isValid() ? 0 : static_cast<int>(p->layers_.size());

View file

@ -37,6 +37,8 @@ public:
explicit LayerModel(QObject* parent = nullptr);
~LayerModel();
void ResetLayers();
int rowCount(const QModelIndex& parent = QModelIndex()) const override;
int columnCount(const QModelIndex& parent = QModelIndex()) const override;