mirror of
https://github.com/OpenMW/openmw.git
synced 2025-01-16 17:59:56 +00:00
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.
This commit is contained in:
parent
fb671fed20
commit
083de62be5
4 changed files with 68 additions and 60 deletions
|
@ -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,39 +578,63 @@ 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())
|
|
||||||
{
|
{
|
||||||
const EsmFile* dependentFile = item(dependentfileName);
|
mPluginsWithLoadOrderError.insert(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;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!isRowInError && (error != LoadOrderError::ErrorCode_None))
|
|
||||||
{
|
|
||||||
setLoadOrderError(file->filePath(), LoadOrderError(error, dependentfileName));
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
else
|
||||||
if (isRowInError && (error == LoadOrderError::ErrorCode_None))
|
|
||||||
{
|
{
|
||||||
setLoadOrderError(file->filePath(), LoadOrderError::sNoError);
|
mPluginsWithLoadOrderError.remove(file->filePath());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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 (!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;
|
||||||
|
}
|
||||||
|
|
||||||
|
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))
|
||||||
|
{
|
||||||
|
text += "<p>";
|
||||||
|
text += error.toolTip();
|
||||||
|
text += "</p>";
|
||||||
|
}
|
||||||
|
text += ("</b></font>");
|
||||||
|
text += file->toolTip();
|
||||||
|
return text;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return file->toolTip();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void ContentSelectorModel::ContentModel::refreshModel()
|
void ContentSelectorModel::ContentModel::refreshModel()
|
||||||
{
|
{
|
||||||
emit dataChanged (index(0,0), index(rowCount()-1,0));
|
emit dataChanged (index(0,0), index(rowCount()-1,0));
|
||||||
|
|
|
@ -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…
Reference in a new issue