mirror of
				https://github.com/ciphervance/supercell-wx.git
				synced 2025-10-31 06:40:05 +00:00 
			
		
		
		
	Updated MarkerModel to update correctly on add/remove
This commit is contained in:
		
							parent
							
								
									57625b9680
								
							
						
					
					
						commit
						491a33794f
					
				
					 2 changed files with 19 additions and 1 deletions
				
			
		|  | @ -42,6 +42,11 @@ MarkerModel::MarkerModel(QObject* parent) : | |||
|          &manager::MarkerManager::MarkerAdded, | ||||
|          this, | ||||
|          &MarkerModel::HandleMarkerAdded); | ||||
| 
 | ||||
|    connect(p->markerManager_.get(), | ||||
|          &manager::MarkerManager::MarkerRemoved, | ||||
|          this, | ||||
|          &MarkerModel::HandleMarkerRemoved); | ||||
| } | ||||
| 
 | ||||
| MarkerModel::~MarkerModel() = default; | ||||
|  | @ -240,8 +245,8 @@ bool MarkerModel::setData(const QModelIndex& index, | |||
| 
 | ||||
| void MarkerModel::HandleMarkerAdded() | ||||
| { | ||||
|    QModelIndex topLeft = createIndex(0, kFirstColumn); | ||||
|    const int newIndex = static_cast<int>(p->markerManager_->marker_count() - 1); | ||||
|    QModelIndex topLeft = createIndex(newIndex, kFirstColumn); | ||||
|    QModelIndex bottomRight = createIndex(newIndex, kLastColumn); | ||||
| 
 | ||||
|    beginInsertRows(QModelIndex(), newIndex, newIndex); | ||||
|  | @ -250,6 +255,18 @@ void MarkerModel::HandleMarkerAdded() | |||
|    Q_EMIT dataChanged(topLeft, bottomRight); | ||||
| } | ||||
| 
 | ||||
| void MarkerModel::HandleMarkerRemoved(size_t index) | ||||
| { | ||||
|    const int removedIndex = static_cast<int>(index); | ||||
|    QModelIndex topLeft = createIndex(removedIndex, kFirstColumn); | ||||
|    QModelIndex bottomRight = createIndex(removedIndex, kLastColumn); | ||||
| 
 | ||||
|    beginRemoveRows(QModelIndex(), removedIndex, removedIndex); | ||||
|    endRemoveRows(); | ||||
| 
 | ||||
|    Q_EMIT dataChanged(topLeft, bottomRight); | ||||
| } | ||||
| 
 | ||||
| } // namespace model
 | ||||
| } // namespace qt
 | ||||
| } // namespace scwx
 | ||||
|  |  | |||
|  | @ -40,6 +40,7 @@ public: | |||
| 
 | ||||
| public slots: | ||||
|    void HandleMarkerAdded(); | ||||
|    void HandleMarkerRemoved(size_t index); | ||||
| 
 | ||||
| private: | ||||
|    class Impl; | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 AdenKoperczak
						AdenKoperczak