diff --git a/components/contentselector/model/contentmodel.cpp b/components/contentselector/model/contentmodel.cpp index 08f240d27e..1c899fe2af 100644 --- a/components/contentselector/model/contentmodel.cpp +++ b/components/contentselector/model/contentmodel.cpp @@ -106,7 +106,7 @@ Qt::ItemFlags ContentSelectorModel::ContentModel::flags(const QModelIndex& index return Qt::NoItemFlags; // game files can always be checked - if (file->isGameFile()) + if (file == mGameFile) return Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsUserCheckable; Qt::ItemFlags returnFlags; @@ -216,7 +216,7 @@ QVariant ContentSelectorModel::ContentModel::data(const QModelIndex& index, int case Qt::CheckStateRole: { - if (file->isGameFile()) + if (file == mGameFile) return QVariant(); return mCheckStates[file->filePath()]; @@ -224,7 +224,7 @@ QVariant ContentSelectorModel::ContentModel::data(const QModelIndex& index, int case Qt::UserRole: { - if (file->isGameFile()) + if (file == mGameFile) return ContentType_GameFile; else if (flags(index)) return ContentType_Addon; @@ -577,6 +577,15 @@ QStringList ContentSelectorModel::ContentModel::gameFiles() const return gameFiles; } +void ContentSelectorModel::ContentModel::setCurrentGameFile(const EsmFile* file) +{ + QModelIndex oldIndex = indexFromItem(mGameFile); + QModelIndex index = indexFromItem(file); + mGameFile = file; + emit dataChanged(oldIndex, oldIndex); + emit dataChanged(index, index); +} + void ContentSelectorModel::ContentModel::sortFiles() { emit layoutAboutToBeChanged(); @@ -591,10 +600,9 @@ void ContentSelectorModel::ContentModel::sortFiles() for (int j = 0; j < i; ++j) { const QStringList& gameFiles = mFiles.at(j)->gameFiles(); - if (gameFiles.contains(file->fileName(), Qt::CaseInsensitive) - || (!mFiles.at(j)->isGameFile() && gameFiles.isEmpty() - && file->fileName().compare("Morrowind.esm", Qt::CaseInsensitive) - == 0)) // Hack: implicit dependency on Morrowind.esm for dependency-less files + // All addon files are implicitly dependent on the game file + // so that they don't accidentally become the game file + if (gameFiles.contains(file->fileName(), Qt::CaseInsensitive) || file == mGameFile) { index = j; break; diff --git a/components/contentselector/model/contentmodel.hpp b/components/contentselector/model/contentmodel.hpp index 09fed11519..f79959b51f 100644 --- a/components/contentselector/model/contentmodel.hpp +++ b/components/contentselector/model/contentmodel.hpp @@ -54,6 +54,7 @@ namespace ContentSelectorModel const EsmFile* item(int row) const; EsmFile* item(int row); QStringList gameFiles() const; + void setCurrentGameFile(const EsmFile* file); bool isEnabled(const QModelIndex& index) const; bool isChecked(const QString& filepath) const; @@ -81,6 +82,7 @@ namespace ContentSelectorModel QString toolTip(const EsmFile* file) const; + const EsmFile* mGameFile; ContentFileList mFiles; QStringList mArchives; QHash mCheckStates; diff --git a/components/contentselector/view/contentselector.cpp b/components/contentselector/view/contentselector.cpp index 937309a864..2f01200927 100644 --- a/components/contentselector/view/contentselector.cpp +++ b/components/contentselector/view/contentselector.cpp @@ -232,6 +232,7 @@ void ContentSelectorView::ContentSelector::setGameFileSelected(int index, bool s QModelIndex index2(mContentModel->indexFromItem(file)); mContentModel->setData(index2, selected, Qt::UserRole + 1); } + mContentModel->setCurrentGameFile(selected ? file : nullptr); } void ContentSelectorView::ContentSelector::slotAddonTableItemActivated(const QModelIndex& index)