mirror of
https://github.com/OpenMW/openmw.git
synced 2025-06-21 09:11:33 +00:00
Content selector: allow using non-primary game files as addon files
This commit is contained in:
parent
d589b46f96
commit
5adda00f5e
3 changed files with 18 additions and 7 deletions
|
@ -106,7 +106,7 @@ Qt::ItemFlags ContentSelectorModel::ContentModel::flags(const QModelIndex& index
|
||||||
return Qt::NoItemFlags;
|
return Qt::NoItemFlags;
|
||||||
|
|
||||||
// game files can always be checked
|
// game files can always be checked
|
||||||
if (file->isGameFile())
|
if (file == mGameFile)
|
||||||
return Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsUserCheckable;
|
return Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsUserCheckable;
|
||||||
|
|
||||||
Qt::ItemFlags returnFlags;
|
Qt::ItemFlags returnFlags;
|
||||||
|
@ -216,7 +216,7 @@ QVariant ContentSelectorModel::ContentModel::data(const QModelIndex& index, int
|
||||||
|
|
||||||
case Qt::CheckStateRole:
|
case Qt::CheckStateRole:
|
||||||
{
|
{
|
||||||
if (file->isGameFile())
|
if (file == mGameFile)
|
||||||
return QVariant();
|
return QVariant();
|
||||||
|
|
||||||
return mCheckStates[file->filePath()];
|
return mCheckStates[file->filePath()];
|
||||||
|
@ -224,7 +224,7 @@ QVariant ContentSelectorModel::ContentModel::data(const QModelIndex& index, int
|
||||||
|
|
||||||
case Qt::UserRole:
|
case Qt::UserRole:
|
||||||
{
|
{
|
||||||
if (file->isGameFile())
|
if (file == mGameFile)
|
||||||
return ContentType_GameFile;
|
return ContentType_GameFile;
|
||||||
else if (flags(index))
|
else if (flags(index))
|
||||||
return ContentType_Addon;
|
return ContentType_Addon;
|
||||||
|
@ -577,6 +577,15 @@ QStringList ContentSelectorModel::ContentModel::gameFiles() const
|
||||||
return gameFiles;
|
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()
|
void ContentSelectorModel::ContentModel::sortFiles()
|
||||||
{
|
{
|
||||||
emit layoutAboutToBeChanged();
|
emit layoutAboutToBeChanged();
|
||||||
|
@ -591,10 +600,9 @@ void ContentSelectorModel::ContentModel::sortFiles()
|
||||||
for (int j = 0; j < i; ++j)
|
for (int j = 0; j < i; ++j)
|
||||||
{
|
{
|
||||||
const QStringList& gameFiles = mFiles.at(j)->gameFiles();
|
const QStringList& gameFiles = mFiles.at(j)->gameFiles();
|
||||||
if (gameFiles.contains(file->fileName(), Qt::CaseInsensitive)
|
// All addon files are implicitly dependent on the game file
|
||||||
|| (!mFiles.at(j)->isGameFile() && gameFiles.isEmpty()
|
// so that they don't accidentally become the game file
|
||||||
&& file->fileName().compare("Morrowind.esm", Qt::CaseInsensitive)
|
if (gameFiles.contains(file->fileName(), Qt::CaseInsensitive) || file == mGameFile)
|
||||||
== 0)) // Hack: implicit dependency on Morrowind.esm for dependency-less files
|
|
||||||
{
|
{
|
||||||
index = j;
|
index = j;
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -54,6 +54,7 @@ namespace ContentSelectorModel
|
||||||
const EsmFile* item(int row) const;
|
const EsmFile* item(int row) const;
|
||||||
EsmFile* item(int row);
|
EsmFile* item(int row);
|
||||||
QStringList gameFiles() const;
|
QStringList gameFiles() const;
|
||||||
|
void setCurrentGameFile(const EsmFile* file);
|
||||||
|
|
||||||
bool isEnabled(const QModelIndex& index) const;
|
bool isEnabled(const QModelIndex& index) const;
|
||||||
bool isChecked(const QString& filepath) const;
|
bool isChecked(const QString& filepath) const;
|
||||||
|
@ -81,6 +82,7 @@ namespace ContentSelectorModel
|
||||||
|
|
||||||
QString toolTip(const EsmFile* file) const;
|
QString toolTip(const EsmFile* file) const;
|
||||||
|
|
||||||
|
const EsmFile* mGameFile;
|
||||||
ContentFileList mFiles;
|
ContentFileList mFiles;
|
||||||
QStringList mArchives;
|
QStringList mArchives;
|
||||||
QHash<QString, Qt::CheckState> mCheckStates;
|
QHash<QString, Qt::CheckState> mCheckStates;
|
||||||
|
|
|
@ -232,6 +232,7 @@ void ContentSelectorView::ContentSelector::setGameFileSelected(int index, bool s
|
||||||
QModelIndex index2(mContentModel->indexFromItem(file));
|
QModelIndex index2(mContentModel->indexFromItem(file));
|
||||||
mContentModel->setData(index2, selected, Qt::UserRole + 1);
|
mContentModel->setData(index2, selected, Qt::UserRole + 1);
|
||||||
}
|
}
|
||||||
|
mContentModel->setCurrentGameFile(selected ? file : nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ContentSelectorView::ContentSelector::slotAddonTableItemActivated(const QModelIndex& index)
|
void ContentSelectorView::ContentSelector::slotAddonTableItemActivated(const QModelIndex& index)
|
||||||
|
|
Loading…
Reference in a new issue