mirror of
				https://github.com/ciphervance/supercell-wx.git
				synced 2025-10-31 08:10:06 +00:00 
			
		
		
		
	Add reset button to layer manager
This commit is contained in:
		
							parent
							
								
									f222b4f666
								
							
						
					
					
						commit
						dd7bfc7a6f
					
				
					 4 changed files with 50 additions and 1 deletions
				
			
		|  | @ -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()); | ||||
|  |  | |||
|  | @ -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; | ||||
| 
 | ||||
|  |  | |||
|  | @ -4,6 +4,7 @@ | |||
| #include <scwx/qt/model/layer_model.hpp> | ||||
| #include <scwx/util/logger.hpp> | ||||
| 
 | ||||
| #include <QPushButton> | ||||
| #include <QSortFilterProxyModel> | ||||
| 
 | ||||
| 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_, | ||||
|  |  | |||
|  | @ -200,11 +200,17 @@ | |||
|       </item> | ||||
|       <item> | ||||
|        <widget class="QDialogButtonBox" name="buttonBox"> | ||||
|         <property name="sizePolicy"> | ||||
|          <sizepolicy hsizetype="Maximum" vsizetype="Fixed"> | ||||
|           <horstretch>0</horstretch> | ||||
|           <verstretch>0</verstretch> | ||||
|          </sizepolicy> | ||||
|         </property> | ||||
|         <property name="orientation"> | ||||
|          <enum>Qt::Horizontal</enum> | ||||
|         </property> | ||||
|         <property name="standardButtons"> | ||||
|          <set>QDialogButtonBox::Close</set> | ||||
|          <set>QDialogButtonBox::Close|QDialogButtonBox::Reset</set> | ||||
|         </property> | ||||
|        </widget> | ||||
|       </item> | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Dan Paulat
						Dan Paulat