summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorisanae <14251494+isanae@users.noreply.github.com>2019-06-08 00:30:51 -0400
committerisanae <14251494+isanae@users.noreply.github.com>2019-06-15 14:40:40 -0400
commit57c7b1568518acefcbcc1801954a62fdc94e3b1c (patch)
tree99b8b51ed60045b6ad299ef745abcf4260552889 /src
parentf60431f92f9475d59a3e2af41c95cc6723892f9a (diff)
moved functionality to CustomOverwrites and ForcedLibraries helper classes
Diffstat (limited to 'src')
-rw-r--r--src/editexecutablesdialog.cpp163
-rw-r--r--src/editexecutablesdialog.h43
2 files changed, 157 insertions, 49 deletions
diff --git a/src/editexecutablesdialog.cpp b/src/editexecutablesdialog.cpp
index 15b496ef..6f63416d 100644
--- a/src/editexecutablesdialog.cpp
+++ b/src/editexecutablesdialog.cpp
@@ -49,26 +49,13 @@ EditExecutablesDialog::EditExecutablesDialog(
ui->splitter->setStretchFactor(0, 0);
ui->splitter->setStretchFactor(1, 1);
- for (const auto& e : m_executablesList) {
- // custom overwrites
- QString customOverwrite = m_profile->setting("custom_overwrites", e.title()).toString();
- if (!customOverwrite.isEmpty()) {
- m_customOverwrites[e.title()] = customOverwrite;
- }
-
- // forced libraries
- if (m_profile->forcedLibrariesEnabled(e.title())) {
- m_forcedLibraries[e.title()] = m_profile->determineForcedLibraries(e.title());
- }
- }
-
+ m_customOverwrites.load(profile, m_executablesList);
+ m_forcedLibraries.load(profile, m_executablesList);
fillExecutableList();
ui->mods->addItems(modList.allMods());
-
// some widgets need to do more than just save() and have their own handler
-
connect(ui->binary, &QLineEdit::textChanged, [&]{ save(); });
connect(ui->workingDirectory, &QLineEdit::textChanged, [&]{ save(); });
connect(ui->arguments, &QLineEdit::textChanged, [&]{ save(); });
@@ -190,13 +177,12 @@ void EditExecutablesDialog::setEdits(const Executable& e)
{
int modIndex = -1;
- auto itor = m_customOverwrites.find(e.title());
- if (itor != m_customOverwrites.end()) {
- modIndex = ui->mods->findText(itor->second);
+ if (const auto mod=m_customOverwrites.find(e.title())) {
+ modIndex = ui->mods->findText(*mod);
if (modIndex == -1) {
qWarning().nospace()
- << "executable '" << e.title() << "' uses mod '" << itor->second << "' "
+ << "executable '" << e.title() << "' uses mod '" << *mod << "' "
<< "as a custom overwrite, but that mod doesn't exist";
}
}
@@ -207,8 +193,7 @@ void EditExecutablesDialog::setEdits(const Executable& e)
}
{
- auto itor = m_forcedLibraries.find(e.title());
- const auto hasForcedLibraries = (itor != m_forcedLibraries.end());
+ const auto hasForcedLibraries = m_forcedLibraries.find(e.title()).has_value();
ui->forceLoadLibraries->setChecked(hasForcedLibraries);
ui->configureLibraries->setEnabled(hasForcedLibraries);
@@ -247,16 +232,20 @@ void EditExecutablesDialog::save()
// title may have changed, start with the stuff using it
if (ui->createFilesInMod->isChecked()) {
- m_customOverwrites[e->title()] = ui->mods->currentText();
+ m_customOverwrites.set(e->title(), ui->mods->currentText());
} else {
- auto itor = m_customOverwrites.find(e->title());
- if (itor != m_customOverwrites.end()) {
- m_customOverwrites.erase(itor);
- }
+ m_customOverwrites.remove(e->title());
}
// forced libraries are saved in on_configureLibraries_clicked()
+ // now rename both the custom overwrites and forced libraries if the title
+ // is being changed
+ if (e->title() != ui->title->text()) {
+ m_customOverwrites.rename(e->title(), ui->title->text());
+ m_forcedLibraries.rename(e->title(), ui->title->text());
+ }
+
e->title(ui->title->text());
e->binaryInfo(ui->binary->text());
e->workingDirectory(ui->workingDirectory->text());
@@ -316,21 +305,8 @@ void EditExecutablesDialog::on_remove_clicked()
delete item;
- // removing custom overwrite
- {
- auto itor = m_customOverwrites.find(exe->title());
- if (itor != m_customOverwrites.end()) {
- m_customOverwrites.erase(itor);
- }
- }
-
- // removing forced libraries
- {
- auto itor = m_forcedLibraries.find(exe->title());
- if (itor != m_forcedLibraries.end()) {
- m_forcedLibraries.erase(itor);
- }
- }
+ m_customOverwrites.remove(exe->title());
+ m_forcedLibraries.remove(exe->title());
// removing from main list, must be done last because it invalidates the
// exe pointer
@@ -354,8 +330,8 @@ void EditExecutablesDialog::on_title_textChanged(const QString& s)
return;
}
- // must save first because it relies on the text in the list to find the
- // executable to modify
+ // must save before modifying the item in the list widget because saving
+ // relies on the item's text being the same as an item in m_executablesList
save();
// once the executable is saved, the list item must be changed to match the
@@ -443,13 +419,12 @@ void EditExecutablesDialog::on_configureLibraries_clicked()
ForcedLoadDialog dialog(m_gamePlugin, this);
- auto itor = m_forcedLibraries.find(e->title());
- if (itor != m_forcedLibraries.end()) {
- dialog.setValues(itor->second);
+ if (auto list=m_forcedLibraries.find(e->title())) {
+ dialog.setValues(*list);
}
if (dialog.exec() == QDialog::Accepted) {
- m_forcedLibraries[e->title()] = dialog.values();
+ m_forcedLibraries.set(e->title(), dialog.values());
save();
}
}
@@ -725,3 +700,97 @@ void EditExecutablesDialog::on_buttons_rejected()
ui->forceLoadCheckBox->setChecked(forcedLibraries);
}
}*/
+
+
+void CustomOverwrites::load(Profile* p, const ExecutablesList& exes)
+{
+ for (const auto& e : exes) {
+ const auto s = p->setting("custom_overwrites", e.title()).toString();
+
+ if (!s.isEmpty()) {
+ m_map[e.title()] = s;
+ }
+ }
+}
+
+std::optional<QString> CustomOverwrites::find(const QString& title) const
+{
+ auto itor = m_map.find(title);
+ if (itor == m_map.end()) {
+ return {};
+ }
+
+ return itor->second;
+}
+
+void CustomOverwrites::set(const QString& title, const QString& mod)
+{
+ m_map[title] = mod;
+}
+
+void CustomOverwrites::rename(const QString& oldTitle, const QString& newTitle)
+{
+ auto itor = m_map.find(oldTitle);
+ if (itor == m_map.end()) {
+ return;
+ }
+
+ // copy to new title, erase old
+ m_map[newTitle] = itor->second;
+ m_map.erase(itor);
+}
+
+void CustomOverwrites::remove(const QString& title)
+{
+ auto itor = m_map.find(title);
+
+ if (itor != m_map.end()) {
+ m_map.erase(itor);
+ }
+}
+
+
+void ForcedLibraries::load(Profile* p, const ExecutablesList& exes)
+{
+ for (const auto& e : exes) {
+ if (p->forcedLibrariesEnabled(e.title())) {
+ m_map[e.title()] = p->determineForcedLibraries(e.title());
+ }
+ }
+}
+
+std::optional<ForcedLibraries::list_type> ForcedLibraries::find(const QString& title) const
+{
+ auto itor = m_map.find(title);
+ if (itor == m_map.end()) {
+ return {};
+ }
+
+ return itor->second;
+}
+
+void ForcedLibraries::set(const QString& title, const list_type& mod)
+{
+ m_map[title] = mod;
+}
+
+void ForcedLibraries::rename(const QString& oldTitle, const QString& newTitle)
+{
+ auto itor = m_map.find(oldTitle);
+ if (itor == m_map.end()) {
+ return;
+ }
+
+ // copy to new title, erase old
+ m_map[newTitle] = itor->second;
+ m_map.erase(itor);
+}
+
+void ForcedLibraries::remove(const QString& title)
+{
+ auto itor = m_map.find(title);
+
+ if (itor != m_map.end()) {
+ m_map.erase(itor);
+ }
+}
diff --git a/src/editexecutablesdialog.h b/src/editexecutablesdialog.h
index 3145c94f..f8382915 100644
--- a/src/editexecutablesdialog.h
+++ b/src/editexecutablesdialog.h
@@ -27,6 +27,7 @@ along with Mod Organizer. If not, see <http://www.gnu.org/licenses/>.
#include "iplugingame.h"
#include <QTimer>
#include <QAbstractButton>
+#include <optional>
namespace Ui {
class EditExecutablesDialog;
@@ -34,6 +35,44 @@ namespace Ui {
class ModList;
+
+/** helper class to manage custom overwrites within the edit executables
+ * dialog
+ **/
+class CustomOverwrites
+{
+public:
+ void load(Profile* p, const ExecutablesList& exes);
+ std::optional<QString> find(const QString& title) const;
+
+ void set(const QString& title, const QString& mod);
+ void rename(const QString& oldTitle, const QString& newTitle);
+ void remove(const QString& title);
+
+private:
+ std::map<QString, QString> m_map;
+};
+
+
+/** helper class to manage forced libraries within the edit executables dialog
+ **/
+class ForcedLibraries
+{
+public:
+ using list_type = QList<MOBase::ExecutableForcedLoadSetting>;
+
+ void load(Profile* p, const ExecutablesList& exes);
+ std::optional<list_type> find(const QString& title) const;
+
+ void set(const QString& title, const list_type& list);
+ void rename(const QString& oldTitle, const QString& newTitle);
+ void remove(const QString& title);
+
+private:
+ std::map<QString, list_type> m_map;
+};
+
+
/**
* @brief Dialog to manage the list of executables
**/
@@ -81,8 +120,8 @@ private slots:
private:
std::unique_ptr<Ui::EditExecutablesDialog> ui;
ExecutablesList m_executablesList;
- std::map<QString, QString> m_customOverwrites;
- std::map<QString, QList<MOBase::ExecutableForcedLoadSetting>> m_forcedLibraries;
+ CustomOverwrites m_customOverwrites;
+ ForcedLibraries m_forcedLibraries;
Profile *m_profile;
const MOBase::IPluginGame *m_gamePlugin;
bool m_settingUI;