diff --git a/scwx-qt/source/scwx/qt/model/layer_model.cpp b/scwx-qt/source/scwx/qt/model/layer_model.cpp index 5645d330..c2d1fcce 100644 --- a/scwx-qt/source/scwx/qt/model/layer_model.cpp +++ b/scwx-qt/source/scwx/qt/model/layer_model.cpp @@ -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( + layerInfo.description_) && + std::get(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(p->layers_.size()); diff --git a/scwx-qt/source/scwx/qt/model/layer_model.hpp b/scwx-qt/source/scwx/qt/model/layer_model.hpp index 55b51b2b..0058aa43 100644 --- a/scwx-qt/source/scwx/qt/model/layer_model.hpp +++ b/scwx-qt/source/scwx/qt/model/layer_model.hpp @@ -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; diff --git a/scwx-qt/source/scwx/qt/ui/layer_dialog.cpp b/scwx-qt/source/scwx/qt/ui/layer_dialog.cpp index 18a34655..1f754ae9 100644 --- a/scwx-qt/source/scwx/qt/ui/layer_dialog.cpp +++ b/scwx-qt/source/scwx/qt/ui/layer_dialog.cpp @@ -4,6 +4,7 @@ #include #include +#include #include namespace scwx @@ -82,6 +83,12 @@ LayerDialog::~LayerDialog() void LayerDialogImpl::ConnectSignals() { + QObject::connect( + self_->ui->buttonBox->button(QDialogButtonBox::StandardButton::Reset), + &QAbstractButton::clicked, + self_, + [this]() { layerModel_->ResetLayers(); }); + QObject::connect(self_->ui->layerFilter, &QLineEdit::textChanged, layerProxyModel_, diff --git a/scwx-qt/source/scwx/qt/ui/layer_dialog.ui b/scwx-qt/source/scwx/qt/ui/layer_dialog.ui index 20979d63..f9b2a076 100644 --- a/scwx-qt/source/scwx/qt/ui/layer_dialog.ui +++ b/scwx-qt/source/scwx/qt/ui/layer_dialog.ui @@ -200,11 +200,17 @@ + + + 0 + 0 + + Qt::Horizontal - QDialogButtonBox::Close + QDialogButtonBox::Close|QDialogButtonBox::Reset