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: case Qt::ForegroundRole:
{ {
if (isLoadOrderError(file->filePath())) if (isLoadOrderError(file))
{ {
QBrush redBackground(Qt::red, Qt::SolidPattern); QBrush redBackground(Qt::red, Qt::SolidPattern);
return redBackground; return redBackground;
@ -213,7 +213,7 @@ QVariant ContentSelectorModel::ContentModel::data(const QModelIndex &index, int
if (column != 0) if (column != 0)
return QVariant(); return QVariant();
return isLoadOrderError(file->filePath()) ? getLoadOrderError(file->filePath()).toolTip() : file->toolTip(); return toolTip(file);
break; break;
} }
@ -302,7 +302,7 @@ 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;
@ -543,26 +543,14 @@ bool ContentSelectorModel::ContentModel::isEnabled (QModelIndex index) const
return (flags(index) & Qt::ItemIsEnabled); 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); return mPluginsWithLoadOrderError.contains(file->filePath());
}
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()));
} }
void ContentSelectorModel::ContentModel::setContentList(const QStringList &fileList, bool isChecked) void ContentSelectorModel::ContentModel::setContentList(const QStringList &fileList, bool isChecked)
{ {
mLoadOrderErrors.clear(); mPluginsWithLoadOrderError.clear();
int previousPosition = -1; int previousPosition = -1;
foreach (const QString &filepath, fileList) foreach (const QString &filepath, fileList)
{ {
@ -590,36 +578,60 @@ void ContentSelectorModel::ContentModel::checkForLoadOrderErrors()
for (int row = 0; row < mFiles.count(); ++row) for (int row = 0; row < mFiles.count(); ++row)
{ {
EsmFile* file = item(row); EsmFile* file = item(row);
bool isRowInError = isLoadOrderError(file->filePath()); bool isRowInError = checkForLoadOrderErrors(file, row).count() != 0;
LoadOrderError::ErrorCode error = LoadOrderError::ErrorCode_None; if (isRowInError)
foreach(QString dependentfileName, file->gameFiles()) {
mPluginsWithLoadOrderError.insert(file->filePath());
}
else
{ {
const EsmFile* dependentFile = item(dependentfileName); mPluginsWithLoadOrderError.remove(file->filePath());
}
}
}
if (!dependentFile) QList<ContentSelectorModel::LoadOrderError> ContentSelectorModel::ContentModel::checkForLoadOrderErrors(const EsmFile *file, int row) const
{ {
error = LoadOrderError::ErrorCode_MissingDependency; QList<LoadOrderError> errors = QList<LoadOrderError>();
} foreach(QString dependentfileName, file->gameFiles())
else if (!isChecked(dependentFile->filePath())) {
{ const EsmFile* dependentFile = item(dependentfileName);
error = LoadOrderError::ErrorCode_InactiveDependency;
}
else if (row < indexFromItem(dependentFile).row())
{
error = LoadOrderError::ErrorCode_LoadOrder;
}
if (!isRowInError && (error != LoadOrderError::ErrorCode_None)) if (!dependentFile)
{ {
setLoadOrderError(file->filePath(), LoadOrderError(error, dependentfileName)); errors.append(LoadOrderError(LoadOrderError::ErrorCode_MissingDependency, dependentfileName));
break; }
} 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 <QAbstractTableModel>
#include <QStringList> #include <QStringList>
#include <QSet>
#include "loadordererror.hpp" #include "loadordererror.hpp"
@ -53,10 +54,6 @@ namespace ContentSelectorModel
ContentFileList checkedItems() const; ContentFileList checkedItems() const;
void uncheckAll(); void uncheckAll();
bool isLoadOrderError(const QString& filepath) const;
LoadOrderError getLoadOrderError(const QString& filepath) const;
void setLoadOrderError(const QString& filepath, const LoadOrderError& loadOrderError);
void refreshModel(); void refreshModel();
private: private:
@ -66,12 +63,22 @@ namespace ContentSelectorModel
EsmFile *item(int row); EsmFile *item(int row);
void sortFiles(); void sortFiles();
/// Checks all plug-ins for load order errors and updates mPluginsWithLoadOrderError with plug-ins with issues
void checkForLoadOrderErrors(); 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; ContentFileList mFiles;
QHash<QString, Qt::CheckState> mCheckStates; QHash<QString, Qt::CheckState> mCheckStates;
QHash<QString, LoadOrderError> mLoadOrderErrors; QSet<QString> mPluginsWithLoadOrderError;
QTextCodec *mCodec; QTextCodec *mCodec;
QString mEncoding; QString mEncoding;

@ -8,15 +8,8 @@ QString ContentSelectorModel::LoadOrderError::sErrorToolTips[ErrorCode_LoadOrder
QString("This file needs to load after %1") QString("This file needs to load after %1")
}; };
ContentSelectorModel::LoadOrderError ContentSelectorModel::LoadOrderError::sNoError = ContentSelectorModel::LoadOrderError();
QString ContentSelectorModel::LoadOrderError::toolTip() const QString ContentSelectorModel::LoadOrderError::toolTip() const
{ {
assert(mErrorCode); assert(mErrorCode);
return sErrorToolTips[mErrorCode - 1].arg(mFileName); 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 ErrorCode errorCode() const { return mErrorCode; }
inline QString fileName() const { return mFileName; } inline QString fileName() const { return mFileName; }
bool operator==(const LoadOrderError& rhs) const;
QString toolTip() const; QString toolTip() const;
/// Sentinel to represent a "No Load Order Error" condition
static LoadOrderError sNoError;
private: private:
ErrorCode mErrorCode; ErrorCode mErrorCode;
QString mFileName; QString mFileName;

Loading…
Cancel
Save