mirror of
				https://github.com/subsurface/subsurface.git
				synced 2025-02-19 22:16:15 +00:00 
			
		
		
		
	Dive list: clear internal data when clearing model
The DiveListModelBase::clear() implementation was flawed: It cleared the data in the core, but left the data in the model untouched. The code was relying on the fact that the caller would reset the model manually. Not a good idea. Therefore, clear the internal data to keep the model consistent at all times. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
		
							parent
							
								
									9f573df971
								
							
						
					
					
						commit
						635d67ee7f
					
				
					 2 changed files with 14 additions and 0 deletions
				
			
		|  | @ -376,6 +376,7 @@ void DiveTripModelBase::clear() | ||||||
| { | { | ||||||
| 	beginResetModel(); | 	beginResetModel(); | ||||||
| 	clear_dive_file_data(); | 	clear_dive_file_data(); | ||||||
|  | 	clearData(); | ||||||
| 	emit diveListNotifier.divesSelected({}, nullptr); // Inform profile, etc of changed selection
 | 	emit diveListNotifier.divesSelected({}, nullptr); // Inform profile, etc of changed selection
 | ||||||
| 	endResetModel(); | 	endResetModel(); | ||||||
| } | } | ||||||
|  | @ -607,6 +608,11 @@ int DiveTripModelTree::rowCount(const QModelIndex &parent) const | ||||||
| 	return entry.d_or_t.trip ? entry.dives.size() : 0; | 	return entry.d_or_t.trip ? entry.dives.size() : 0; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | void DiveTripModelList::clearData() | ||||||
|  | { | ||||||
|  | 	items.clear(); | ||||||
|  | } | ||||||
|  | 
 | ||||||
| static const quintptr noParent = ~(quintptr)0; // This is the "internalId" marker for top-level item
 | static const quintptr noParent = ~(quintptr)0; // This is the "internalId" marker for top-level item
 | ||||||
| 
 | 
 | ||||||
| QModelIndex DiveTripModelTree::index(int row, int column, const QModelIndex &parent) const | QModelIndex DiveTripModelTree::index(int row, int column, const QModelIndex &parent) const | ||||||
|  | @ -1238,6 +1244,11 @@ int DiveTripModelList::rowCount(const QModelIndex &parent) const | ||||||
| 	return parent.isValid() ? 0 : items.size(); | 	return parent.isValid() ? 0 : items.size(); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | void DiveTripModelTree::clearData() | ||||||
|  | { | ||||||
|  | 	items.clear(); | ||||||
|  | } | ||||||
|  | 
 | ||||||
| QModelIndex DiveTripModelList::index(int row, int column, const QModelIndex &parent) const | QModelIndex DiveTripModelList::index(int row, int column, const QModelIndex &parent) const | ||||||
| { | { | ||||||
| 	if (!hasIndex(row, column, parent)) | 	if (!hasIndex(row, column, parent)) | ||||||
|  |  | ||||||
|  | @ -100,6 +100,7 @@ protected: | ||||||
| 	static QVariant tripData(const dive_trip *trip, int column, int role); | 	static QVariant tripData(const dive_trip *trip, int column, int role); | ||||||
| 
 | 
 | ||||||
| 	virtual dive *diveOrNull(const QModelIndex &index) const = 0;	// Returns a dive if this index represents a dive, null otherwise
 | 	virtual dive *diveOrNull(const QModelIndex &index) const = 0;	// Returns a dive if this index represents a dive, null otherwise
 | ||||||
|  | 	virtual void clearData() = 0; | ||||||
| }; | }; | ||||||
| 
 | 
 | ||||||
| class DiveTripModelTree : public DiveTripModelBase | class DiveTripModelTree : public DiveTripModelBase | ||||||
|  | @ -119,6 +120,7 @@ public: | ||||||
| 	DiveTripModelTree(QObject *parent = nullptr); | 	DiveTripModelTree(QObject *parent = nullptr); | ||||||
| private: | private: | ||||||
| 	int rowCount(const QModelIndex &parent) const override; | 	int rowCount(const QModelIndex &parent) const override; | ||||||
|  | 	void clearData() override; | ||||||
| 	QModelIndex index(int row, int column, const QModelIndex &parent) const override; | 	QModelIndex index(int row, int column, const QModelIndex &parent) const override; | ||||||
| 	QModelIndex parent(const QModelIndex &index) const override; | 	QModelIndex parent(const QModelIndex &index) const override; | ||||||
| 	QVariant data(const QModelIndex &index, int role) const override; | 	QVariant data(const QModelIndex &index, int role) const override; | ||||||
|  | @ -184,6 +186,7 @@ public: | ||||||
| 	DiveTripModelList(QObject *parent = nullptr); | 	DiveTripModelList(QObject *parent = nullptr); | ||||||
| private: | private: | ||||||
| 	int rowCount(const QModelIndex &parent) const override; | 	int rowCount(const QModelIndex &parent) const override; | ||||||
|  | 	void clearData() override; | ||||||
| 	QModelIndex index(int row, int column, const QModelIndex &parent) const override; | 	QModelIndex index(int row, int column, const QModelIndex &parent) const override; | ||||||
| 	QModelIndex parent(const QModelIndex &index) const override; | 	QModelIndex parent(const QModelIndex &index) const override; | ||||||
| 	QVariant data(const QModelIndex &index, int role) const override; | 	QVariant data(const QModelIndex &index, int role) const override; | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue