Don't precompute load order errors after every change

It's much slower than doing it on demand as it only takes a microsecond, but for a really big load order, there are hundreds of thousands of intermediate calls before everything's set up and we can draw the GUI.
This commit is contained in:
AnyOldName3 2025-04-08 01:19:24 +01:00
parent d6b61f1f54
commit 894ea4ba62
3 changed files with 7 additions and 31 deletions

View file

@ -307,7 +307,6 @@ bool ContentSelectorModel::ContentModel::setData(const QModelIndex& index, const
{ {
setCheckState(file->filePath(), success); setCheckState(file->filePath(), success);
emit dataChanged(index, index); emit dataChanged(index, index);
checkForLoadOrderErrors();
} }
else else
return success; return success;
@ -422,7 +421,6 @@ bool ContentSelectorModel::ContentModel::dropMimeData(
dataChanged(index(minRow, 0), index(maxRow, 0)); dataChanged(index(minRow, 0), index(maxRow, 0));
// at this point we know that drag and drop has finished. // at this point we know that drag and drop has finished.
checkForLoadOrderErrors();
return true; return true;
} }
@ -702,12 +700,13 @@ void ContentSelectorModel::ContentModel::setNonUserContent(const QStringList& fi
bool ContentSelectorModel::ContentModel::isLoadOrderError(const EsmFile* file) const bool ContentSelectorModel::ContentModel::isLoadOrderError(const EsmFile* file) const
{ {
return mPluginsWithLoadOrderError.contains(file->filePath()); int index = indexFromItem(file).row();
auto errors = checkForLoadOrderErrors(file, index);
return !errors.empty();
} }
void ContentSelectorModel::ContentModel::setContentList(const QStringList& fileList) void ContentSelectorModel::ContentModel::setContentList(const QStringList& fileList)
{ {
mPluginsWithLoadOrderError.clear();
int previousPosition = -1; int previousPosition = -1;
for (const QString& filepath : fileList) for (const QString& filepath : fileList)
{ {
@ -727,27 +726,9 @@ void ContentSelectorModel::ContentModel::setContentList(const QStringList& fileL
} }
} }
} }
checkForLoadOrderErrors();
emit dataChanged(index(0, 0), index(rowCount(), columnCount())); emit dataChanged(index(0, 0), index(rowCount(), columnCount()));
} }
void ContentSelectorModel::ContentModel::checkForLoadOrderErrors()
{
for (int row = 0; row < mFiles.count(); ++row)
{
EsmFile* file = mFiles.at(row);
bool isRowInError = checkForLoadOrderErrors(file, row).count() != 0;
if (isRowInError)
{
mPluginsWithLoadOrderError.insert(file->filePath());
}
else
{
mPluginsWithLoadOrderError.remove(file->filePath());
}
}
}
QList<ContentSelectorModel::LoadOrderError> ContentSelectorModel::ContentModel::checkForLoadOrderErrors( QList<ContentSelectorModel::LoadOrderError> ContentSelectorModel::ContentModel::checkForLoadOrderErrors(
const EsmFile* file, int row) const const EsmFile* file, int row) const
{ {
@ -786,11 +767,12 @@ QList<ContentSelectorModel::LoadOrderError> ContentSelectorModel::ContentModel::
QString ContentSelectorModel::ContentModel::toolTip(const EsmFile* file) const QString ContentSelectorModel::ContentModel::toolTip(const EsmFile* file) const
{ {
if (isLoadOrderError(file)) int index = indexFromItem(file).row();
auto errors = checkForLoadOrderErrors(file, index);
if (!errors.empty())
{ {
QString text("<b>"); QString text("<b>");
int index = indexFromItem(item(file->filePath())).row(); for (const LoadOrderError& error : errors)
for (const LoadOrderError& error : checkForLoadOrderErrors(file, index))
{ {
assert(error.errorCode() != LoadOrderError::ErrorCode::ErrorCode_None); assert(error.errorCode() != LoadOrderError::ErrorCode::ErrorCode_None);

View file

@ -69,9 +69,6 @@ namespace ContentSelectorModel
void refreshModel(); void refreshModel();
/// Checks all plug-ins for load order errors and updates mPluginsWithLoadOrderError with plug-ins with issues
void checkForLoadOrderErrors();
private: private:
void addFile(EsmFile* file); void addFile(EsmFile* file);
@ -89,7 +86,6 @@ namespace ContentSelectorModel
QStringList mNonUserContent; QStringList mNonUserContent;
std::set<const EsmFile*> mCheckedFiles; std::set<const EsmFile*> mCheckedFiles;
QHash<QString, bool> mNewFiles; QHash<QString, bool> mNewFiles;
QSet<QString> mPluginsWithLoadOrderError;
QString mEncoding; QString mEncoding;
QIcon mWarningIcon; QIcon mWarningIcon;
QIcon mErrorIcon; QIcon mErrorIcon;

View file

@ -211,7 +211,6 @@ void ContentSelectorView::ContentSelector::addFiles(const QString& path, bool ne
ui->gameFileView->setCurrentIndex(0); ui->gameFileView->setCurrentIndex(0);
mContentModel->uncheckAll(); mContentModel->uncheckAll();
mContentModel->checkForLoadOrderErrors();
} }
void ContentSelectorView::ContentSelector::sortFiles() void ContentSelectorView::ContentSelector::sortFiles()
@ -254,7 +253,6 @@ void ContentSelectorView::ContentSelector::slotCurrentGameFileIndexChanged(int i
oldIndex = index; oldIndex = index;
setGameFileSelected(index, true); setGameFileSelected(index, true);
mContentModel->checkForLoadOrderErrors();
} }
emit signalCurrentGamefileIndexChanged(index); emit signalCurrentGamefileIndexChanged(index);