summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMikaël Capelle <capelle.mikael@gmail.com>2020-08-29 15:20:46 +0200
committerMikaël Capelle <capelle.mikael@gmail.com>2020-08-29 15:20:46 +0200
commit97e9e7cf2be5f8f24f62aa25d4669eda885e8567 (patch)
tree721432044b8509465db7c7c5eb24630b14445035 /src
parente421837ba00b7a6cbe9ace477836f067dca58828 (diff)
Refactor the way m_ModStateChanged works.
Diffstat (limited to 'src')
-rw-r--r--src/modlist.cpp28
-rw-r--r--src/modlist.h8
-rw-r--r--src/organizercore.cpp5
3 files changed, 20 insertions, 21 deletions
diff --git a/src/modlist.cpp b/src/modlist.cpp
index 218604b2..c772f5bd 100644
--- a/src/modlist.cpp
+++ b/src/modlist.cpp
@@ -637,18 +637,6 @@ bool ModList::setData(const QModelIndex &index, const QVariant &value, int role)
}
emit postDataChanged();
-
- IModList::ModStates newState = state(modID);
- if (oldState != newState) {
- try {
- m_ModStateChanged(info->name(), newState);
- } catch (const std::exception &e) {
- log::error("failed to invoke state changed notification: {}", e.what());
- } catch (...) {
- log::error("failed to invoke state changed notification: unknown exception");
- }
- }
-
return result;
}
@@ -957,9 +945,6 @@ bool ModList::setActive(const QString &name, bool active)
return false;
} else {
m_Profile->setModEnabled(modIndex, active);
-
- IModList::ModStates newState = state(modIndex);
- m_ModStateChanged(name, newState);
return true;
}
}
@@ -987,12 +972,6 @@ int ModList::setActive(const QStringList& names, bool active) {
m_Profile->setModsEnabled({}, indices);
}
- // Notify callbacks:
- for (auto modIndex : indices) {
- IModList::ModStates newState = state(modIndex);
- m_ModStateChanged(ModInfo::getByIndex(modIndex)->name(), newState);
- }
-
return indices.size();
}
@@ -1028,6 +1007,13 @@ bool ModList::onModStateChanged(const std::function<void (const QString &, IModL
return conn.connected();
}
+void ModList::notifyModStateChanged(QList<unsigned int> modIndices) const {
+ for (auto modIndex : modIndices) {
+ ModInfo::Ptr modInfo = ModInfo::getByIndex(modIndex);
+ m_ModStateChanged(modInfo->name(), state(modIndex));
+ }
+}
+
bool ModList::onModMoved(const std::function<void (const QString &, int, int)> &func)
{
auto conn = m_ModMoved.connect(func);
diff --git a/src/modlist.h b/src/modlist.h
index 22eb7962..1d16339f 100644
--- a/src/modlist.h
+++ b/src/modlist.h
@@ -124,6 +124,14 @@ public:
void highlightMods(const QItemSelectionModel *selection, const MOShared::DirectoryEntry &directoryEntry);
+ /**
+ * @brief Notify the most list that the state of the specified mods has changed. This is used
+ * to notify the plugin that registered through onModStateChanged().
+ *
+ * @param modIndices Indices of the mods that changed.
+ */
+ void notifyModStateChanged(QList<unsigned int> modIndices) const;
+
public:
/// \copydoc MOBase::IModList::displayName
diff --git a/src/organizercore.cpp b/src/organizercore.cpp
index 28bb06db..815c80c2 100644
--- a/src/organizercore.cpp
+++ b/src/organizercore.cpp
@@ -1552,6 +1552,9 @@ void OrganizerCore::modStatusChanged(unsigned int index)
m_DirectoryStructure->getFileRegister()->sortOrigins();
refreshLists();
+
+ m_ModList.notifyModStateChanged({ index });
+
} catch (const std::exception &e) {
reportError(tr("failed to update mod list: %1").arg(e.what()));
}
@@ -1601,6 +1604,8 @@ void OrganizerCore::modStatusChanged(QList<unsigned int> index) {
m_DirectoryStructure->getFileRegister()->sortOrigins();
refreshLists();
+
+ m_ModList.notifyModStateChanged(index);
} catch (const std::exception &e) {
reportError(tr("failed to update mod list: %1").arg(e.what()));
}