1
0
Fork 0
mirror of https://github.com/OpenMW/openmw.git synced 2025-06-19 18:11:35 +00:00

Avoid repeated item(QString) in plugin toggling-related code

This commit is contained in:
Alexei Kotov 2025-05-15 21:55:19 +03:00
parent 89d6408587
commit f7f5665588
3 changed files with 8 additions and 13 deletions

View file

@ -278,7 +278,7 @@ bool ContentSelectorModel::ContentModel::setData(const QModelIndex& index, const
if (success) if (success)
{ {
success = setCheckState(file->filePath(), value.toBool()); success = setCheckState(file, value.toBool());
emit dataChanged(index, index); emit dataChanged(index, index);
} }
} }
@ -305,7 +305,7 @@ bool ContentSelectorModel::ContentModel::setData(const QModelIndex& index, const
if (setState) if (setState)
{ {
setCheckState(file->filePath(), success); setCheckState(file, success);
emit dataChanged(index, index); emit dataChanged(index, index);
} }
else else
@ -710,11 +710,11 @@ void ContentSelectorModel::ContentModel::setContentList(const QStringList& fileL
int previousPosition = -1; int previousPosition = -1;
for (const QString& filepath : fileList) for (const QString& filepath : fileList)
{ {
if (setCheckState(filepath, true)) const EsmFile* file = item(filepath);
if (setCheckState(file, true))
{ {
// setCheckState already gracefully handles builtIn and fromAnotherConfigFile // setCheckState already gracefully handles builtIn and fromAnotherConfigFile
// as necessary, move plug-ins in visible list to match sequence of supplied filelist // as necessary, move plug-ins in visible list to match sequence of supplied filelist
const EsmFile* file = item(filepath);
int filePosition = indexFromItem(file).row(); int filePosition = indexFromItem(file).row();
if (filePosition < previousPosition) if (filePosition < previousPosition)
{ {
@ -795,13 +795,8 @@ void ContentSelectorModel::ContentModel::refreshModel()
emit dataChanged(index(0, 0), index(rowCount() - 1, 0)); emit dataChanged(index(0, 0), index(rowCount() - 1, 0));
} }
bool ContentSelectorModel::ContentModel::setCheckState(const QString& filepath, bool checkState) bool ContentSelectorModel::ContentModel::setCheckState(const EsmFile* file, bool checkState)
{ {
if (filepath.isEmpty())
return false;
const EsmFile* file = item(filepath);
if (!file || file->builtIn() || file->fromAnotherConfigFile()) if (!file || file->builtIn() || file->fromAnotherConfigFile())
return false; return false;
@ -810,7 +805,7 @@ bool ContentSelectorModel::ContentModel::setCheckState(const QString& filepath,
else else
mCheckedFiles.erase(file); mCheckedFiles.erase(file);
emit dataChanged(indexFromItem(item(filepath)), indexFromItem(item(filepath))); emit dataChanged(indexFromItem(file), indexFromItem(file));
if (file->isGameFile()) if (file->isGameFile())
refreshModel(); refreshModel();

View file

@ -59,7 +59,7 @@ namespace ContentSelectorModel
void setCurrentGameFile(const EsmFile* file); void setCurrentGameFile(const EsmFile* file);
bool isEnabled(const QModelIndex& index) const; bool isEnabled(const QModelIndex& index) const;
bool setCheckState(const QString& filepath, bool isChecked); bool setCheckState(const EsmFile* file, bool isChecked);
bool isNew(const QString& filepath) const; bool isNew(const QString& filepath) const;
void setNew(const QString& filepath, bool isChecked); void setNew(const QString& filepath, bool isChecked);
void setNonUserContent(const QStringList& fileList); void setNonUserContent(const QStringList& fileList);

View file

@ -156,7 +156,7 @@ void ContentSelectorView::ContentSelector::setGameFile(const QString& filename)
index = ui->gameFileView->findText(file->fileName()); index = ui->gameFileView->findText(file->fileName());
// verify that the current index is also checked in the model // verify that the current index is also checked in the model
if (!mContentModel->setCheckState(filename, true)) if (!mContentModel->setCheckState(file, true))
{ {
// throw error in case file not found? // throw error in case file not found?
return; return;