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); 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 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());

View file

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

View file

@ -4,6 +4,7 @@
#include <scwx/qt/model/layer_model.hpp> #include <scwx/qt/model/layer_model.hpp>
#include <scwx/util/logger.hpp> #include <scwx/util/logger.hpp>
#include <QPushButton>
#include <QSortFilterProxyModel> #include <QSortFilterProxyModel>
namespace scwx namespace scwx
@ -82,6 +83,12 @@ LayerDialog::~LayerDialog()
void LayerDialogImpl::ConnectSignals() void LayerDialogImpl::ConnectSignals()
{ {
QObject::connect(
self_->ui->buttonBox->button(QDialogButtonBox::StandardButton::Reset),
&QAbstractButton::clicked,
self_,
[this]() { layerModel_->ResetLayers(); });
QObject::connect(self_->ui->layerFilter, QObject::connect(self_->ui->layerFilter,
&QLineEdit::textChanged, &QLineEdit::textChanged,
layerProxyModel_, layerProxyModel_,

View file

@ -200,11 +200,17 @@
</item> </item>
<item> <item>
<widget class="QDialogButtonBox" name="buttonBox"> <widget class="QDialogButtonBox" name="buttonBox">
<property name="sizePolicy">
<sizepolicy hsizetype="Maximum" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="orientation"> <property name="orientation">
<enum>Qt::Horizontal</enum> <enum>Qt::Horizontal</enum>
</property> </property>
<property name="standardButtons"> <property name="standardButtons">
<set>QDialogButtonBox::Close</set> <set>QDialogButtonBox::Close|QDialogButtonBox::Reset</set>
</property> </property>
</widget> </widget>
</item> </item>