ContentModel: Don't confuse file path with file name (Fixes #1352)

deque
scrawl 11 years ago
parent 7b5482f25b
commit 47172fb8a2

@ -239,7 +239,7 @@ bool ContentSelectorModel::ContentModel::setData(const QModelIndex &index, const
return false; return false;
EsmFile *file = item(index.row()); EsmFile *file = item(index.row());
QString fileName = file->filePath(); QString fileName = file->fileName();
bool success = false; bool success = false;
switch(role) switch(role)
@ -266,7 +266,7 @@ bool ContentSelectorModel::ContentModel::setData(const QModelIndex &index, const
if (success) if (success)
{ {
success = setCheckState(fileName, value.toBool()); success = setCheckState(file->filePath(), value.toBool());
emit dataChanged(index, index); emit dataChanged(index, index);
} }
} }
@ -277,19 +277,19 @@ bool ContentSelectorModel::ContentModel::setData(const QModelIndex &index, const
int checkValue = value.toInt(); int checkValue = value.toInt();
bool success = false; bool success = false;
bool setState = false; bool setState = false;
if ((checkValue==Qt::Checked) && !isChecked(fileName)) if ((checkValue==Qt::Checked) && !isChecked(file->filePath()))
{ {
setState = true; setState = true;
success = true; success = true;
} }
else if ((checkValue == Qt::Checked) && isChecked (fileName)) else if ((checkValue == Qt::Checked) && isChecked (file->filePath()))
setState = true; setState = true;
else if (checkValue == Qt::Unchecked) else if (checkValue == Qt::Unchecked)
setState = true; setState = true;
if (setState) if (setState)
{ {
setCheckState(fileName, success); setCheckState(file->filePath(), success);
emit dataChanged(index, index); emit dataChanged(index, index);
} }
@ -517,10 +517,10 @@ void ContentSelectorModel::ContentModel::sortFiles()
} }
} }
bool ContentSelectorModel::ContentModel::isChecked(const QString& name) const bool ContentSelectorModel::ContentModel::isChecked(const QString& filepath) const
{ {
if (mCheckStates.contains(name)) if (mCheckStates.contains(filepath))
return (mCheckStates[name] == Qt::Checked); return (mCheckStates[filepath] == Qt::Checked);
return false; return false;
} }
@ -543,12 +543,12 @@ void ContentSelectorModel::ContentModel::refreshModel()
emit dataChanged (index(0,0), index(rowCount()-1,0)); emit dataChanged (index(0,0), index(rowCount()-1,0));
} }
bool ContentSelectorModel::ContentModel::setCheckState(const QString &name, bool checkState) bool ContentSelectorModel::ContentModel::setCheckState(const QString &filepath, bool checkState)
{ {
if (name.isEmpty()) if (filepath.isEmpty())
return false; return false;
const EsmFile *file = item(name); const EsmFile *file = item(filepath);
if (!file) if (!file)
return false; return false;
@ -558,8 +558,8 @@ bool ContentSelectorModel::ContentModel::setCheckState(const QString &name, bool
if (checkState) if (checkState)
state = Qt::Checked; state = Qt::Checked;
mCheckStates[name] = state; mCheckStates[filepath] = state;
emit dataChanged(indexFromItem(item(name)), indexFromItem(item(name))); emit dataChanged(indexFromItem(item(filepath)), indexFromItem(item(filepath)));
if (file->isGameFile()) if (file->isGameFile())
refreshModel(); refreshModel();
@ -586,7 +586,10 @@ bool ContentSelectorModel::ContentModel::setCheckState(const QString &name, bool
{ {
foreach (const EsmFile *downstreamFile, mFiles) foreach (const EsmFile *downstreamFile, mFiles)
{ {
if (downstreamFile->gameFiles().contains(name)) QFileInfo fileInfo(filepath);
QString filename = fileInfo.fileName();
if (downstreamFile->gameFiles().contains(filename))
{ {
if (mCheckStates.contains(downstreamFile->filePath())) if (mCheckStates.contains(downstreamFile->filePath()))
mCheckStates[downstreamFile->filePath()] = Qt::Unchecked; mCheckStates[downstreamFile->filePath()] = Qt::Unchecked;

@ -45,8 +45,8 @@ namespace ContentSelectorModel
const EsmFile *item(const QString &name) const; const EsmFile *item(const QString &name) const;
bool isEnabled (QModelIndex index) const; bool isEnabled (QModelIndex index) const;
bool isChecked(const QString &name) const; bool isChecked(const QString &filepath) const;
bool setCheckState(const QString &name, bool isChecked); bool setCheckState(const QString &filepath, bool isChecked);
void setCheckStates (const QStringList &fileList, bool isChecked); void setCheckStates (const QStringList &fileList, bool isChecked);
ContentFileList checkedItems() const; ContentFileList checkedItems() const;
void uncheckAll(); void uncheckAll();

@ -53,6 +53,8 @@ namespace ContentSelectorModel
inline QDateTime modified() const { return mModified; } inline QDateTime modified() const { return mModified; }
inline float format() const { return mFormat; } inline float format() const { return mFormat; }
inline QString filePath() const { return mPath; } inline QString filePath() const { return mPath; }
/// @note Contains file names, not paths.
inline const QStringList &gameFiles() const { return mGameFiles; } inline const QStringList &gameFiles() const { return mGameFiles; }
inline QString description() const { return mDescription; } inline QString description() const { return mDescription; }
inline QString toolTip() const { return sToolTip.arg(mAuthor) inline QString toolTip() const { return sToolTip.arg(mAuthor)

Loading…
Cancel
Save