mirror of
https://gitlab.com/OpenMW/openmw.git
synced 2025-04-28 21:07:59 +03:00
Track source of settings
This one's a biggie. The basic idea's that GameSettings should know: * what the interpreted value of a setting is, so it can actually be used. * what the original value the user put in their config was, so it can be put back when the config's saved. * which path it's processing the openmw.cfg from so relative paths can be resolved correctly. * whether a setting's a user setting that can be modified, or from one of the other openmw.cfg files that can't necessarily be modified. This had fairly wide-reaching implications. The first is that paths are resolved properly in cases where they previously wouldn't have been. Without this commit, if the launcher saw a relative path in an openmw.cfg, it'd be resolved relative to the process' working directory (which we always set to the binary directory for reasons I won't get into). That's not what the engine does, so is bad. It's also not something a user's likely to suspect. This mess is no longer a problem as paths are resolved correctly when they're loaded instead of on demand when they're used by whatever uses them. Another problem was that if paths used slugs like ?userconfig? would be written back to openmw.cfg with the slugs replaced, which defeats the object of using the slugs. This is also fixed. Tracking which settings are user settings and which are in a non-editable openmw.cfg allows the launcher to grey out rows so they can't be edited (which is sensible as they can't be edited on-disk) while still being aware of content files that are provided by non-user data directories etc. This is done in a pretty straightforward way for the data directories and fallback-archives, as those bits of UI are basic, but it's more complicated for content files as that uses a nmodel/view approach and has a lot more moving parts. Thankfully, I'd already implemented that when dealing with builtin.omwscripts, so it just needed wiring up. One more thing of note is that I made the SettingValue struct storable as a QVariant so it could be attached to the UI widgets as userdata, and then I could just grab the original representation and use it instead of needing any complicated mapping from display value to on-disk value.
This commit is contained in:
parent
1af59c3a43
commit
a130ca57a4
13 changed files with 367 additions and 164 deletions
|
@ -220,7 +220,8 @@ QVariant ContentSelectorModel::ContentModel::data(const QModelIndex& index, int
|
|||
if (file == mGameFile)
|
||||
return QVariant();
|
||||
|
||||
return (file->builtIn() || file->fromAnotherConfigFile() || mCheckedFiles.contains(file)) ? Qt::Checked : Qt::Unchecked;
|
||||
return (file->builtIn() || file->fromAnotherConfigFile() || mCheckedFiles.contains(file)) ? Qt::Checked
|
||||
: Qt::Unchecked;
|
||||
}
|
||||
|
||||
case Qt::UserRole:
|
||||
|
@ -467,6 +468,8 @@ void ContentSelectorModel::ContentModel::addFiles(const QString& path, bool newf
|
|||
if (info.fileName().compare("builtin.omwscripts", Qt::CaseInsensitive) == 0)
|
||||
file->setBuiltIn(true);
|
||||
|
||||
file->setFromAnotherConfigFile(mNonUserContent.contains(info.fileName().toLower()));
|
||||
|
||||
if (info.fileName().endsWith(".omwscripts", Qt::CaseInsensitive))
|
||||
{
|
||||
file->setDate(info.lastModified());
|
||||
|
@ -660,6 +663,28 @@ void ContentSelectorModel::ContentModel::setNew(const QString& filepath, bool is
|
|||
mNewFiles[filepath] = isNew;
|
||||
}
|
||||
|
||||
void ContentSelectorModel::ContentModel::setNonUserContent(const QStringList& fileList)
|
||||
{
|
||||
mNonUserContent.clear();
|
||||
for (const auto& file : fileList)
|
||||
mNonUserContent.insert(file.toLower());
|
||||
for (auto* file : mFiles)
|
||||
file->setFromAnotherConfigFile(mNonUserContent.contains(file->fileName().toLower()));
|
||||
|
||||
int insertPosition = 0;
|
||||
while (mFiles.at(insertPosition)->builtIn())
|
||||
++insertPosition;
|
||||
|
||||
for (const auto& filepath : fileList)
|
||||
{
|
||||
const EsmFile* file = item(filepath);
|
||||
int filePosition = indexFromItem(file).row();
|
||||
mFiles.move(filePosition, insertPosition++);
|
||||
}
|
||||
|
||||
sortFiles();
|
||||
}
|
||||
|
||||
bool ContentSelectorModel::ContentModel::isLoadOrderError(const EsmFile* file) const
|
||||
{
|
||||
return mPluginsWithLoadOrderError.contains(file->filePath());
|
||||
|
|
|
@ -62,6 +62,7 @@ namespace ContentSelectorModel
|
|||
bool setCheckState(const QString& filepath, bool isChecked);
|
||||
bool isNew(const QString& filepath) const;
|
||||
void setNew(const QString& filepath, bool isChecked);
|
||||
void setNonUserContent(const QStringList& fileList);
|
||||
void setContentList(const QStringList& fileList);
|
||||
ContentFileList checkedItems() const;
|
||||
void uncheckAll();
|
||||
|
@ -85,7 +86,7 @@ namespace ContentSelectorModel
|
|||
|
||||
const EsmFile* mGameFile;
|
||||
ContentFileList mFiles;
|
||||
QStringList mArchives;
|
||||
QSet<QString> mNonUserContent;
|
||||
std::set<const EsmFile*> mCheckedFiles;
|
||||
QHash<QString, bool> mNewFiles;
|
||||
QSet<QString> mPluginsWithLoadOrderError;
|
||||
|
|
|
@ -123,6 +123,11 @@ void ContentSelectorView::ContentSelector::buildContextMenu()
|
|||
mContextMenu->addAction(tr("&Copy Path(s) to Clipboard"), this, SLOT(slotCopySelectedItemsPaths()));
|
||||
}
|
||||
|
||||
void ContentSelectorView::ContentSelector::setNonUserContent(const QStringList& fileList)
|
||||
{
|
||||
mContentModel->setNonUserContent(fileList);
|
||||
}
|
||||
|
||||
void ContentSelectorView::ContentSelector::setProfileContent(const QStringList& fileList)
|
||||
{
|
||||
clearCheckStates();
|
||||
|
@ -336,4 +341,4 @@ void ContentSelectorView::ContentSelector::slotSearchFilterTextChanged(const QSt
|
|||
void ContentSelectorView::ContentSelector::slotRowsMoved()
|
||||
{
|
||||
ui->addonView->selectionModel()->clearSelection();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -40,6 +40,7 @@ namespace ContentSelectorView
|
|||
void sortFiles();
|
||||
bool containsDataFiles(const QString& path);
|
||||
void clearFiles();
|
||||
void setNonUserContent(const QStringList& fileList);
|
||||
void setProfileContent(const QStringList& fileList);
|
||||
|
||||
void clearCheckStates();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue