From 083de62be59ad0fe701af233eff2e8d0411ebb18 Mon Sep 17 00:00:00 2001 From: dteviot Date: Thu, 8 Jan 2015 11:18:42 +1300 Subject: [PATCH] Fixed issues found by Zinnschlag. 1. Errors found are added to default tool tip text. (Instead of replacing it.) 2. If multiple errors are found, all are shown in tool tip text, not just first one. 3. Load Order Errors are updated when files are activated/deactivated, not just when the files have their position in list changed. --- .../contentselector/model/contentmodel.cpp | 94 +++++++++++-------- .../contentselector/model/contentmodel.hpp | 17 +++- .../contentselector/model/loadordererror.cpp | 7 -- .../contentselector/model/loadordererror.hpp | 4 - 4 files changed, 65 insertions(+), 57 deletions(-) diff --git a/components/contentselector/model/contentmodel.cpp b/components/contentselector/model/contentmodel.cpp index 6366d7f54..57b231357 100644 --- a/components/contentselector/model/contentmodel.cpp +++ b/components/contentselector/model/contentmodel.cpp @@ -173,7 +173,7 @@ QVariant ContentSelectorModel::ContentModel::data(const QModelIndex &index, int { case Qt::ForegroundRole: { - if (isLoadOrderError(file->filePath())) + if (isLoadOrderError(file)) { QBrush redBackground(Qt::red, Qt::SolidPattern); return redBackground; @@ -213,7 +213,7 @@ QVariant ContentSelectorModel::ContentModel::data(const QModelIndex &index, int if (column != 0) return QVariant(); - return isLoadOrderError(file->filePath()) ? getLoadOrderError(file->filePath()).toolTip() : file->toolTip(); + return toolTip(file); break; } @@ -302,7 +302,7 @@ bool ContentSelectorModel::ContentModel::setData(const QModelIndex &index, const { setCheckState(file->filePath(), success); emit dataChanged(index, index); - + checkForLoadOrderErrors(); } else return success; @@ -543,26 +543,14 @@ bool ContentSelectorModel::ContentModel::isEnabled (QModelIndex index) const return (flags(index) & Qt::ItemIsEnabled); } -bool ContentSelectorModel::ContentModel::isLoadOrderError(const QString& filepath) const +bool ContentSelectorModel::ContentModel::isLoadOrderError(const EsmFile *file) const { - return !(getLoadOrderError(filepath) == LoadOrderError::sNoError); -} - -ContentSelectorModel::LoadOrderError ContentSelectorModel::ContentModel::getLoadOrderError(const QString& filepath) const -{ - return mLoadOrderErrors.contains(filepath) ? mLoadOrderErrors[filepath] : ContentSelectorModel::LoadOrderError::sNoError; -} - -void ContentSelectorModel::ContentModel::setLoadOrderError(const QString& filepath, const ContentSelectorModel::LoadOrderError& loadOrderError) -{ - mLoadOrderErrors[filepath] = loadOrderError; - int filePosition = indexFromItem(item(filepath)).row(); - emit dataChanged(index(filePosition, 0, QModelIndex()), index(filePosition, 0, QModelIndex())); + return mPluginsWithLoadOrderError.contains(file->filePath()); } void ContentSelectorModel::ContentModel::setContentList(const QStringList &fileList, bool isChecked) { - mLoadOrderErrors.clear(); + mPluginsWithLoadOrderError.clear(); int previousPosition = -1; foreach (const QString &filepath, fileList) { @@ -590,36 +578,60 @@ void ContentSelectorModel::ContentModel::checkForLoadOrderErrors() for (int row = 0; row < mFiles.count(); ++row) { EsmFile* file = item(row); - bool isRowInError = isLoadOrderError(file->filePath()); - LoadOrderError::ErrorCode error = LoadOrderError::ErrorCode_None; - foreach(QString dependentfileName, file->gameFiles()) + bool isRowInError = checkForLoadOrderErrors(file, row).count() != 0; + if (isRowInError) + { + mPluginsWithLoadOrderError.insert(file->filePath()); + } + else { - const EsmFile* dependentFile = item(dependentfileName); + mPluginsWithLoadOrderError.remove(file->filePath()); + } + } +} - if (!dependentFile) - { - error = LoadOrderError::ErrorCode_MissingDependency; - } - else if (!isChecked(dependentFile->filePath())) - { - error = LoadOrderError::ErrorCode_InactiveDependency; - } - else if (row < indexFromItem(dependentFile).row()) - { - error = LoadOrderError::ErrorCode_LoadOrder; - } +QList ContentSelectorModel::ContentModel::checkForLoadOrderErrors(const EsmFile *file, int row) const +{ + QList errors = QList(); + foreach(QString dependentfileName, file->gameFiles()) + { + const EsmFile* dependentFile = item(dependentfileName); - if (!isRowInError && (error != LoadOrderError::ErrorCode_None)) - { - setLoadOrderError(file->filePath(), LoadOrderError(error, dependentfileName)); - break; - } + if (!dependentFile) + { + errors.append(LoadOrderError(LoadOrderError::ErrorCode_MissingDependency, dependentfileName)); + } + if (!isChecked(dependentFile->filePath())) + { + errors.append(LoadOrderError(LoadOrderError::ErrorCode_InactiveDependency, dependentfileName)); } + if (row < indexFromItem(dependentFile).row()) + { + errors.append(LoadOrderError(LoadOrderError::ErrorCode_LoadOrder, dependentfileName)); + } + } + return errors; +} - if (isRowInError && (error == LoadOrderError::ErrorCode_None)) +QString ContentSelectorModel::ContentModel::toolTip(const EsmFile *file) const +{ + if (isLoadOrderError(file)) + { + QString text(""); + int index = indexFromItem(item(file->filePath())).row(); + foreach(const LoadOrderError& error, checkForLoadOrderErrors(file, index)) { - setLoadOrderError(file->filePath(), LoadOrderError::sNoError); + text += "

"; + text += error.toolTip(); + text += "

"; } + text += ("
"); + text += file->toolTip(); + return text; + } + else + { + return file->toolTip(); } } diff --git a/components/contentselector/model/contentmodel.hpp b/components/contentselector/model/contentmodel.hpp index 2a9f2c93b..f6e3d62bd 100644 --- a/components/contentselector/model/contentmodel.hpp +++ b/components/contentselector/model/contentmodel.hpp @@ -3,6 +3,7 @@ #include #include +#include #include "loadordererror.hpp" @@ -53,10 +54,6 @@ namespace ContentSelectorModel ContentFileList checkedItems() const; void uncheckAll(); - bool isLoadOrderError(const QString& filepath) const; - LoadOrderError getLoadOrderError(const QString& filepath) const; - void setLoadOrderError(const QString& filepath, const LoadOrderError& loadOrderError); - void refreshModel(); private: @@ -66,12 +63,22 @@ namespace ContentSelectorModel EsmFile *item(int row); void sortFiles(); + + /// Checks all plug-ins for load order errors and updates mPluginsWithLoadOrderError with plug-ins with issues void checkForLoadOrderErrors(); + /// Checks a specific plug-in for load order errors + /// \return all errors found for specific plug-in + QList checkForLoadOrderErrors(const EsmFile *file, int row) const; + + /// \return true if plug-in has a Load Order error + bool isLoadOrderError(const EsmFile *file) const; + + QString toolTip(const EsmFile *file) const; ContentFileList mFiles; QHash mCheckStates; - QHash mLoadOrderErrors; + QSet mPluginsWithLoadOrderError; QTextCodec *mCodec; QString mEncoding; diff --git a/components/contentselector/model/loadordererror.cpp b/components/contentselector/model/loadordererror.cpp index 0d02efbeb..aa69f330e 100644 --- a/components/contentselector/model/loadordererror.cpp +++ b/components/contentselector/model/loadordererror.cpp @@ -8,15 +8,8 @@ QString ContentSelectorModel::LoadOrderError::sErrorToolTips[ErrorCode_LoadOrder QString("This file needs to load after %1") }; -ContentSelectorModel::LoadOrderError ContentSelectorModel::LoadOrderError::sNoError = ContentSelectorModel::LoadOrderError(); - QString ContentSelectorModel::LoadOrderError::toolTip() const { assert(mErrorCode); return sErrorToolTips[mErrorCode - 1].arg(mFileName); } - -bool ContentSelectorModel::LoadOrderError::operator== (const ContentSelectorModel::LoadOrderError& rhs) const -{ - return (mErrorCode == rhs.mErrorCode) && ((mErrorCode == ErrorCode_None) || (mFileName == rhs.mFileName)); -} \ No newline at end of file diff --git a/components/contentselector/model/loadordererror.hpp b/components/contentselector/model/loadordererror.hpp index f3d3b0f8a..2b840cf69 100644 --- a/components/contentselector/model/loadordererror.hpp +++ b/components/contentselector/model/loadordererror.hpp @@ -25,12 +25,8 @@ namespace ContentSelectorModel } inline ErrorCode errorCode() const { return mErrorCode; } inline QString fileName() const { return mFileName; } - bool operator==(const LoadOrderError& rhs) const; QString toolTip() const; - /// Sentinel to represent a "No Load Order Error" condition - static LoadOrderError sNoError; - private: ErrorCode mErrorCode; QString mFileName;