mirror of
https://github.com/OpenMW/openmw.git
synced 2025-06-04 13:41:33 +00:00
Avoid repeated item(QString) in plugin toggling-related code
This commit is contained in:
parent
89d6408587
commit
f7f5665588
3 changed files with 8 additions and 13 deletions
|
@ -278,7 +278,7 @@ bool ContentSelectorModel::ContentModel::setData(const QModelIndex& index, const
|
|||
|
||||
if (success)
|
||||
{
|
||||
success = setCheckState(file->filePath(), value.toBool());
|
||||
success = setCheckState(file, value.toBool());
|
||||
emit dataChanged(index, index);
|
||||
}
|
||||
}
|
||||
|
@ -305,7 +305,7 @@ bool ContentSelectorModel::ContentModel::setData(const QModelIndex& index, const
|
|||
|
||||
if (setState)
|
||||
{
|
||||
setCheckState(file->filePath(), success);
|
||||
setCheckState(file, success);
|
||||
emit dataChanged(index, index);
|
||||
}
|
||||
else
|
||||
|
@ -710,11 +710,11 @@ void ContentSelectorModel::ContentModel::setContentList(const QStringList& fileL
|
|||
int previousPosition = -1;
|
||||
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
|
||||
// as necessary, move plug-ins in visible list to match sequence of supplied filelist
|
||||
const EsmFile* file = item(filepath);
|
||||
int filePosition = indexFromItem(file).row();
|
||||
if (filePosition < previousPosition)
|
||||
{
|
||||
|
@ -795,13 +795,8 @@ void ContentSelectorModel::ContentModel::refreshModel()
|
|||
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())
|
||||
return false;
|
||||
|
||||
|
@ -810,7 +805,7 @@ bool ContentSelectorModel::ContentModel::setCheckState(const QString& filepath,
|
|||
else
|
||||
mCheckedFiles.erase(file);
|
||||
|
||||
emit dataChanged(indexFromItem(item(filepath)), indexFromItem(item(filepath)));
|
||||
emit dataChanged(indexFromItem(file), indexFromItem(file));
|
||||
|
||||
if (file->isGameFile())
|
||||
refreshModel();
|
||||
|
|
|
@ -59,7 +59,7 @@ namespace ContentSelectorModel
|
|||
void setCurrentGameFile(const EsmFile* file);
|
||||
|
||||
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;
|
||||
void setNew(const QString& filepath, bool isChecked);
|
||||
void setNonUserContent(const QStringList& fileList);
|
||||
|
|
|
@ -156,7 +156,7 @@ void ContentSelectorView::ContentSelector::setGameFile(const QString& filename)
|
|||
index = ui->gameFileView->findText(file->fileName());
|
||||
|
||||
// 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?
|
||||
return;
|
||||
|
|
Loading…
Reference in a new issue