mirror of
				https://github.com/subsurface/subsurface.git
				synced 2025-02-19 22:16:15 +00:00 
			
		
		
		
	CylindersModel: listen and react to signals
React to signals from the undo-commands and update the model accordingly. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
		
							parent
							
								
									75f37a7d10
								
							
						
					
					
						commit
						04ce908e8e
					
				
					 2 changed files with 34 additions and 0 deletions
				
			
		|  | @ -19,6 +19,9 @@ CylindersModel::CylindersModel(QObject *parent) : CleanerTableModel(parent), | |||
| 						 << tr("Deco switch at") <<tr("Bot. MOD") <<tr("MND") << tr("Use")); | ||||
| 
 | ||||
| 	connect(&diveListNotifier, &DiveListNotifier::cylindersReset, this, &CylindersModel::cylindersReset); | ||||
| 	connect(&diveListNotifier, &DiveListNotifier::cylinderAdded, this, &CylindersModel::cylinderAdded); | ||||
| 	connect(&diveListNotifier, &DiveListNotifier::cylinderRemoved, this, &CylindersModel::cylinderRemoved); | ||||
| 	connect(&diveListNotifier, &DiveListNotifier::cylinderEdited, this, &CylindersModel::cylinderEdited); | ||||
| } | ||||
| 
 | ||||
| QVariant CylindersModel::headerData(int section, Qt::Orientation orientation, int role) const | ||||
|  | @ -521,6 +524,34 @@ void CylindersModel::remove(QModelIndex index) | |||
| 	changed = true; | ||||
| } | ||||
| 
 | ||||
| void CylindersModel::cylinderAdded(struct dive *changed, int pos) | ||||
| { | ||||
| 	if (d != changed) | ||||
| 		return; | ||||
| 
 | ||||
| 	// The row was already inserted by the undo command. Just inform the model.
 | ||||
| 	beginInsertRows(QModelIndex(), pos, pos); | ||||
| 	endInsertRows(); | ||||
| } | ||||
| 
 | ||||
| void CylindersModel::cylinderRemoved(struct dive *changed, int pos) | ||||
| { | ||||
| 	if (d != changed) | ||||
| 		return; | ||||
| 
 | ||||
| 	// The row was already deleted by the undo command. Just inform the model.
 | ||||
| 	beginRemoveRows(QModelIndex(), pos, pos); | ||||
| 	endRemoveRows(); | ||||
| } | ||||
| 
 | ||||
| void CylindersModel::cylinderEdited(struct dive *changed, int pos) | ||||
| { | ||||
| 	if (d != changed) | ||||
| 		return; | ||||
| 
 | ||||
| 	dataChanged(index(pos, TYPE), index(pos, USE)); | ||||
| } | ||||
| 
 | ||||
| void CylindersModel::moveAtFirst(int cylid) | ||||
| { | ||||
| 	if (!d) | ||||
|  |  | |||
|  | @ -54,6 +54,9 @@ public | |||
| slots: | ||||
| 	void remove(QModelIndex index); | ||||
| 	void cylindersReset(const QVector<dive *> &dives); | ||||
| 	void cylinderAdded(dive *d, int pos); | ||||
| 	void cylinderRemoved(dive *d, int pos); | ||||
| 	void cylinderEdited(dive *d, int pos); | ||||
| 
 | ||||
| private: | ||||
| 	dive *d; | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue