mirror of
				https://github.com/subsurface/subsurface.git
				synced 2025-02-19 22:16:15 +00:00 
			
		
		
		
	QML UI: correctly notify of model change
This may seem weird, but it seems to work to make sure that the model actually is correctly updated when updating a dive. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
		
							parent
							
								
									9342dedb26
								
							
						
					
					
						commit
						6f953d51de
					
				
					 2 changed files with 19 additions and 2 deletions
				
			
		|  | @ -16,12 +16,27 @@ void DiveListModel::addDive(dive *d) | ||||||
| 	endInsertRows(); | 	endInsertRows(); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | void DiveListModel::insertDive(int i, DiveObjectHelper *newDive) | ||||||
|  | { | ||||||
|  | 	beginInsertRows(QModelIndex(), i, i); | ||||||
|  | 	m_dives.insert(i, newDive); | ||||||
|  | 	endInsertRows(); | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | void DiveListModel::removeDive(int i) | ||||||
|  | { | ||||||
|  | 	beginRemoveRows(QModelIndex(), i, i); | ||||||
|  | 	m_dives.removeAt(i); | ||||||
|  | 	endRemoveRows(); | ||||||
|  | } | ||||||
|  | 
 | ||||||
| void DiveListModel::updateDive(dive *d) | void DiveListModel::updateDive(dive *d) | ||||||
| { | { | ||||||
| 	for (int i = 0; i < m_dives.count(); i++) { | 	for (int i = 0; i < m_dives.count(); i++) { | ||||||
| 		if (m_dives.at(i)->id() == d->id) { | 		if (m_dives.at(i)->id() == d->id) { | ||||||
| 			DiveObjectHelper *newDive = new DiveObjectHelper(d); | 			DiveObjectHelper *newDive = new DiveObjectHelper(d); | ||||||
| 			m_dives.replace(i, newDive); | 			removeDive(i); | ||||||
|  | 			insertDive(i, newDive); | ||||||
| 			break; | 			break; | ||||||
| 		} | 		} | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
|  | @ -20,6 +20,8 @@ public: | ||||||
| 	static DiveListModel *instance(); | 	static DiveListModel *instance(); | ||||||
| 	DiveListModel(QObject *parent = 0); | 	DiveListModel(QObject *parent = 0); | ||||||
| 	void addDive(dive *d); | 	void addDive(dive *d); | ||||||
|  | 	void insertDive(int i, DiveObjectHelper *newDive); | ||||||
|  | 	void removeDive(int i); | ||||||
| 	void updateDive(dive *d); | 	void updateDive(dive *d); | ||||||
| 	void clear(); | 	void clear(); | ||||||
| 	int rowCount(const QModelIndex &parent = QModelIndex()) const; | 	int rowCount(const QModelIndex &parent = QModelIndex()) const; | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue