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.
openmw-35
dteviot 10 years ago
parent fb671fed20
commit 083de62be5

@ -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::LoadOrderError> ContentSelectorModel::ContentModel::checkForLoadOrderErrors(const EsmFile *file, int row) const
{
QList<LoadOrderError> errors = QList<LoadOrderError>();
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("<font color=#840000><b>");
int index = indexFromItem(item(file->filePath())).row();
foreach(const LoadOrderError& error, checkForLoadOrderErrors(file, index))
{
setLoadOrderError(file->filePath(), LoadOrderError::sNoError);
text += "<p>";
text += error.toolTip();
text += "</p>";
}
text += ("</b></font>");
text += file->toolTip();
return text;
}
else
{
return file->toolTip();
}
}

@ -3,6 +3,7 @@
#include <QAbstractTableModel>
#include <QStringList>
#include <QSet>
#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<LoadOrderError> 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<QString, Qt::CheckState> mCheckStates;
QHash<QString, LoadOrderError> mLoadOrderErrors;
QSet<QString> mPluginsWithLoadOrderError;
QTextCodec *mCodec;
QString mEncoding;

@ -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));
}

@ -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;

Loading…
Cancel
Save