mirror of
				https://github.com/OpenMW/openmw.git
				synced 2025-10-31 13:26:38 +00:00 
			
		
		
		
	Cache topic/journal first rows in InfoTableProxyModel
This commit is contained in:
		
							parent
							
								
									2e40b68862
								
							
						
					
					
						commit
						a6624ca576
					
				
					 2 changed files with 29 additions and 2 deletions
				
			
		|  | @ -15,6 +15,11 @@ void CSMWorld::InfoTableProxyModel::setSourceModel(QAbstractItemModel *sourceMod | |||
| { | ||||
|     IdTableProxyModel::setSourceModel(sourceModel); | ||||
|     mSourceModel = dynamic_cast<IdTableBase *>(sourceModel); | ||||
|     connect(mSourceModel,  | ||||
|             SIGNAL(dataChanged(const QModelIndex &, const QModelIndex &)), | ||||
|             this,  | ||||
|             SLOT(modelDataChanged(const QModelIndex &, const QModelIndex &))); | ||||
|     mFirstRowCache.clear(); | ||||
| } | ||||
| 
 | ||||
| bool CSMWorld::InfoTableProxyModel::lessThan(const QModelIndex &left, const QModelIndex &right) const | ||||
|  | @ -33,8 +38,21 @@ int CSMWorld::InfoTableProxyModel::getFirstInfoRow(int currentRow) const | |||
|     } | ||||
| 
 | ||||
|     int column = mSourceModel->findColumnIndex(columnId); | ||||
|     QVariant info = mSourceModel->data(mSourceModel->index(currentRow, column)); | ||||
|     while (--currentRow >= 0 &&  | ||||
|     QString info = mSourceModel->data(mSourceModel->index(currentRow, column)).toString(); | ||||
| 
 | ||||
|     if (mFirstRowCache.contains(info)) | ||||
|     { | ||||
|         return mFirstRowCache[info]; | ||||
|     } | ||||
| 
 | ||||
|     while (--currentRow >= 0 && | ||||
|            mSourceModel->data(mSourceModel->index(currentRow, column)) == info); | ||||
| 
 | ||||
|     mFirstRowCache[info] = currentRow + 1; | ||||
|     return currentRow + 1; | ||||
| } | ||||
| 
 | ||||
| void CSMWorld::InfoTableProxyModel::modelDataChanged(const QModelIndex &/*topLeft*/, const QModelIndex &/*bottomRight*/) | ||||
| { | ||||
|     mFirstRowCache.clear(); | ||||
| } | ||||
|  |  | |||
|  | @ -1,6 +1,8 @@ | |||
| #ifndef CSM_WORLD_INFOTABLEPROXYMODEL_HPP | ||||
| #define CSM_WORLD_INFOTABLEPROXYMODEL_HPP | ||||
| 
 | ||||
| #include <QHash> | ||||
| 
 | ||||
| #include "idtableproxymodel.hpp" | ||||
| #include "universalid.hpp" | ||||
| 
 | ||||
|  | @ -10,9 +12,13 @@ namespace CSMWorld | |||
| 
 | ||||
|     class InfoTableProxyModel : public IdTableProxyModel | ||||
|     { | ||||
|             Q_OBJECT | ||||
| 
 | ||||
|             UniversalId::Type mType; | ||||
|             IdTableBase *mSourceModel; | ||||
| 
 | ||||
|             mutable QHash<QString, int> mFirstRowCache; | ||||
| 
 | ||||
|             int getFirstInfoRow(int currentRow) const; | ||||
|             ///< Finds the first row with the same topic (journal entry) as in \a currentRow
 | ||||
| 
 | ||||
|  | @ -23,6 +29,9 @@ namespace CSMWorld | |||
| 
 | ||||
|         protected: | ||||
|             virtual bool lessThan(const QModelIndex &left, const QModelIndex &right) const; | ||||
| 
 | ||||
|         private slots: | ||||
|             void modelDataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight); | ||||
|     }; | ||||
| } | ||||
| 
 | ||||
|  |  | |||
		Loading…
	
		Reference in a new issue