mirror of
				https://github.com/OpenMW/openmw.git
				synced 2025-10-25 11:26:37 +00:00 
			
		
		
		
	Merge remote-tracking branch 'smbas/fix-info-tables'
This commit is contained in:
		
						commit
						fdf6645dbc
					
				
					 4 changed files with 61 additions and 27 deletions
				
			
		|  | @ -97,7 +97,8 @@ bool CSMWorld::InfoCollection::reorderRows (int baseIndex, const std::vector<int | ||||||
|         return false; |         return false; | ||||||
| 
 | 
 | ||||||
|     // Check that topics match
 |     // Check that topics match
 | ||||||
|     if (getRecord (baseIndex).get().mTopicId!=getRecord (lastIndex).get().mTopicId) |     if (!Misc::StringUtils::ciEqual(getRecord(baseIndex).get().mTopicId, | ||||||
|  |                                     getRecord(lastIndex).get().mTopicId)) | ||||||
|         return false; |         return false; | ||||||
| 
 | 
 | ||||||
|     // reorder
 |     // reorder
 | ||||||
|  |  | ||||||
|  | @ -1,12 +1,24 @@ | ||||||
| #include "infotableproxymodel.hpp" | #include "infotableproxymodel.hpp" | ||||||
| 
 | 
 | ||||||
|  | #include <components/misc/stringops.hpp> | ||||||
|  | 
 | ||||||
| #include "idtablebase.hpp" | #include "idtablebase.hpp" | ||||||
| #include "columns.hpp" | #include "columns.hpp" | ||||||
| 
 | 
 | ||||||
|  | namespace | ||||||
|  | { | ||||||
|  |     QString toLower(const QString &str) | ||||||
|  |     { | ||||||
|  | 		return QString::fromUtf8(Misc::StringUtils::lowerCase(str.toStdString()).c_str()); | ||||||
|  |     } | ||||||
|  | } | ||||||
|  | 
 | ||||||
| CSMWorld::InfoTableProxyModel::InfoTableProxyModel(CSMWorld::UniversalId::Type type, QObject *parent) | CSMWorld::InfoTableProxyModel::InfoTableProxyModel(CSMWorld::UniversalId::Type type, QObject *parent) | ||||||
|     : IdTableProxyModel(parent), |     : IdTableProxyModel(parent), | ||||||
|       mType(type), |       mType(type), | ||||||
|       mSourceModel(NULL) |       mSourceModel(NULL), | ||||||
|  | 	  mInfoColumnId(type == UniversalId::Type_TopicInfos ? Columns::ColumnId_Topic :  | ||||||
|  |                                                            Columns::ColumnId_Journal) | ||||||
| { | { | ||||||
|     Q_ASSERT(type == UniversalId::Type_TopicInfos || type == UniversalId::Type_JournalInfos); |     Q_ASSERT(type == UniversalId::Type_TopicInfos || type == UniversalId::Type_JournalInfos); | ||||||
| } | } | ||||||
|  | @ -15,44 +27,53 @@ void CSMWorld::InfoTableProxyModel::setSourceModel(QAbstractItemModel *sourceMod | ||||||
| { | { | ||||||
|     IdTableProxyModel::setSourceModel(sourceModel); |     IdTableProxyModel::setSourceModel(sourceModel); | ||||||
|     mSourceModel = dynamic_cast<IdTableBase *>(sourceModel); |     mSourceModel = dynamic_cast<IdTableBase *>(sourceModel); | ||||||
|  |     if (mSourceModel != NULL) | ||||||
|  |     { | ||||||
|         connect(mSourceModel,  |         connect(mSourceModel,  | ||||||
|             SIGNAL(dataChanged(const QModelIndex &, const QModelIndex &)), |                 SIGNAL(rowsInserted(const QModelIndex &, int, int)), | ||||||
|                 this,  |                 this,  | ||||||
|             SLOT(modelDataChanged(const QModelIndex &, const QModelIndex &))); |                 SLOT(modelRowsChanged(const QModelIndex &, int, int))); | ||||||
|  |         connect(mSourceModel,  | ||||||
|  |                 SIGNAL(rowsRemoved(const QModelIndex &, int, int)), | ||||||
|  |                 this,  | ||||||
|  |                 SLOT(modelRowsChanged(const QModelIndex &, int, int))); | ||||||
|         mFirstRowCache.clear(); |         mFirstRowCache.clear(); | ||||||
|  |     } | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| bool CSMWorld::InfoTableProxyModel::lessThan(const QModelIndex &left, const QModelIndex &right) const | bool CSMWorld::InfoTableProxyModel::lessThan(const QModelIndex &left, const QModelIndex &right) const | ||||||
| { | { | ||||||
|     QModelIndex first = mSourceModel->index(getFirstInfoRow(left.row()), left.column()); |     QModelIndex first = mSourceModel->index(getFirstInfoRow(left.row()), left.column()); | ||||||
|     QModelIndex second = mSourceModel->index(getFirstInfoRow(right.row()), right.column()); |     QModelIndex second = mSourceModel->index(getFirstInfoRow(right.row()), right.column()); | ||||||
|  | 
 | ||||||
|  |     // If both indexes are belonged to the same Topic/Journal, compare their original rows only
 | ||||||
|  |     if (first.row() == second.row()) | ||||||
|  |     { | ||||||
|  |         return sortOrder() == Qt::AscendingOrder ? left.row() < right.row() : right.row() < left.row(); | ||||||
|  |     } | ||||||
|     return IdTableProxyModel::lessThan(first, second); |     return IdTableProxyModel::lessThan(first, second); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| int CSMWorld::InfoTableProxyModel::getFirstInfoRow(int currentRow) const | int CSMWorld::InfoTableProxyModel::getFirstInfoRow(int currentRow) const | ||||||
| { | { | ||||||
|     Columns::ColumnId columnId = Columns::ColumnId_Topic; |     int row = currentRow; | ||||||
|     if (mType == UniversalId::Type_JournalInfos) |     int column = mSourceModel->findColumnIndex(mInfoColumnId); | ||||||
|     { |     QString info = toLower(mSourceModel->data(mSourceModel->index(row, column)).toString()); | ||||||
|         columnId = Columns::ColumnId_Journal; |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
|     int column = mSourceModel->findColumnIndex(columnId); |  | ||||||
|     QString info = mSourceModel->data(mSourceModel->index(currentRow, column)).toString(); |  | ||||||
| 
 | 
 | ||||||
|     if (mFirstRowCache.contains(info)) |     if (mFirstRowCache.contains(info)) | ||||||
|     { |     { | ||||||
|         return mFirstRowCache[info]; |         return mFirstRowCache[info]; | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     while (--currentRow >= 0 && |     while (--row >= 0 &&  | ||||||
|            mSourceModel->data(mSourceModel->index(currentRow, column)) == info); |            toLower(mSourceModel->data(mSourceModel->index(row, column)).toString()) == info); | ||||||
|  |     ++row; | ||||||
| 
 | 
 | ||||||
|     mFirstRowCache[info] = currentRow + 1; |     mFirstRowCache[info] = row; | ||||||
|     return currentRow + 1; |     return row; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| void CSMWorld::InfoTableProxyModel::modelDataChanged(const QModelIndex &/*topLeft*/, const QModelIndex &/*bottomRight*/) | void CSMWorld::InfoTableProxyModel::modelRowsChanged(const QModelIndex &/*parent*/, int /*start*/, int /*end*/) | ||||||
| { | { | ||||||
|     mFirstRowCache.clear(); |     mFirstRowCache.clear(); | ||||||
| } | } | ||||||
|  |  | ||||||
|  | @ -4,6 +4,7 @@ | ||||||
| #include <QHash> | #include <QHash> | ||||||
| 
 | 
 | ||||||
| #include "idtableproxymodel.hpp" | #include "idtableproxymodel.hpp" | ||||||
|  | #include "columns.hpp" | ||||||
| #include "universalid.hpp" | #include "universalid.hpp" | ||||||
| 
 | 
 | ||||||
| namespace CSMWorld | namespace CSMWorld | ||||||
|  | @ -16,6 +17,8 @@ namespace CSMWorld | ||||||
| 
 | 
 | ||||||
|             UniversalId::Type mType; |             UniversalId::Type mType; | ||||||
|             IdTableBase *mSourceModel; |             IdTableBase *mSourceModel; | ||||||
|  |             Columns::ColumnId mInfoColumnId; | ||||||
|  |             ///< Contains ID for Topic or Journal ID
 | ||||||
| 
 | 
 | ||||||
|             mutable QHash<QString, int> mFirstRowCache; |             mutable QHash<QString, int> mFirstRowCache; | ||||||
| 
 | 
 | ||||||
|  | @ -31,7 +34,7 @@ namespace CSMWorld | ||||||
|             virtual bool lessThan(const QModelIndex &left, const QModelIndex &right) const; |             virtual bool lessThan(const QModelIndex &left, const QModelIndex &right) const; | ||||||
| 
 | 
 | ||||||
|         private slots: |         private slots: | ||||||
|             void modelDataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight); |             void modelRowsChanged(const QModelIndex &parent, int start, int end); | ||||||
|     }; |     }; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -9,6 +9,8 @@ | ||||||
| #include <QString> | #include <QString> | ||||||
| #include <QtCore/qnamespace.h> | #include <QtCore/qnamespace.h> | ||||||
| 
 | 
 | ||||||
|  | #include <components/misc/stringops.hpp> | ||||||
|  | 
 | ||||||
| #include "../../model/doc/document.hpp" | #include "../../model/doc/document.hpp" | ||||||
| 
 | 
 | ||||||
| #include "../../model/world/data.hpp" | #include "../../model/world/data.hpp" | ||||||
|  | @ -128,17 +130,24 @@ void CSVWorld::Table::contextMenuEvent (QContextMenuEvent *event) | ||||||
|                 { |                 { | ||||||
|                     int row = mProxyModel->mapToSource ( |                     int row = mProxyModel->mapToSource ( | ||||||
|                         mProxyModel->index (selectedRows.begin()->row(), 0)).row(); |                         mProxyModel->index (selectedRows.begin()->row(), 0)).row(); | ||||||
|  |                     QString curData = mModel->data(mModel->index(row, column)).toString(); | ||||||
| 
 | 
 | ||||||
|                     if (row>0 && mModel->data (mModel->index (row, column))== |                     if (row > 0) | ||||||
|                         mModel->data (mModel->index (row-1, column))) |  | ||||||
|                     { |                     { | ||||||
|                         menu.addAction (mMoveUpAction); |                         QString prevData = mModel->data(mModel->index(row - 1, column)).toString(); | ||||||
|  |                         if (Misc::StringUtils::ciEqual(curData.toStdString(), prevData.toStdString())) | ||||||
|  |                         { | ||||||
|  |                             menu.addAction(mMoveUpAction); | ||||||
|  |                         } | ||||||
|                     } |                     } | ||||||
| 
 | 
 | ||||||
|                     if (row<mModel->rowCount()-1 && mModel->data (mModel->index (row, column))== |                     if (row < mModel->rowCount() - 1) | ||||||
|                         mModel->data (mModel->index (row+1, column))) |  | ||||||
|                     { |                     { | ||||||
|                         menu.addAction (mMoveDownAction); |                         QString nextData = mModel->data(mModel->index(row + 1, column)).toString(); | ||||||
|  |                         if (Misc::StringUtils::ciEqual(curData.toStdString(), nextData.toStdString())) | ||||||
|  |                         { | ||||||
|  |                             menu.addAction(mMoveDownAction); | ||||||
|  |                         } | ||||||
|                     } |                     } | ||||||
|                 } |                 } | ||||||
|             } |             } | ||||||
|  |  | ||||||
		Loading…
	
		Reference in a new issue