diff options
| author | Tannin <devnull@localhost> | 2015-03-31 18:31:54 +0200 |
|---|---|---|
| committer | Tannin <devnull@localhost> | 2015-03-31 18:31:54 +0200 |
| commit | eed3664302e915c058962e339070058a181b2c7a (patch) | |
| tree | 2b7e70c0df8ae5f4714ff8a21d04ff0d53f36b49 /src/pluginlist.cpp | |
| parent | 35eb41daf94ece8843bda1a0ba68cd92d031eed6 (diff) | |
a signal is now emitted when the state (checked/unchecked) of a plugin changes
Diffstat (limited to 'src/pluginlist.cpp')
| -rw-r--r-- | src/pluginlist.cpp | 43 |
1 files changed, 32 insertions, 11 deletions
diff --git a/src/pluginlist.cpp b/src/pluginlist.cpp index 94c6340e..e758ce18 100644 --- a/src/pluginlist.cpp +++ b/src/pluginlist.cpp @@ -89,9 +89,9 @@ PluginList::~PluginList() {
m_Refreshed.disconnect_all_slots();
m_PluginMoved.disconnect_all_slots();
+ m_PluginStateChanged.disconnect_all_slots();
}
-
QString PluginList::getColumnName(int column)
{
switch (column) {
@@ -297,13 +297,11 @@ void PluginList::addInformation(const QString &name, const QString &message) }
}
-
bool PluginList::isEnabled(int index)
{
return m_ESPs.at(index).m_Enabled;
}
-
bool PluginList::readLoadOrder(const QString &fileName)
{
std::set<QString> availableESPs;
@@ -562,7 +560,6 @@ bool PluginList::isESPLocked(int index) const return m_LockedOrder.find(m_ESPs.at(index).m_Name.toLower()) != m_LockedOrder.end();
}
-
void PluginList::lockESPIndex(int index, bool lock)
{
if (lock) {
@@ -577,7 +574,6 @@ qDebug(__FUNCTION__); emit writePluginsList();
}
-
void PluginList::syncLoadOrder()
{
int loadOrder = 0;
@@ -630,10 +626,13 @@ void PluginList::refreshLoadOrder() }
}
+void PluginList::disconnectSlots() {
+ m_PluginMoved.disconnect_all_slots();
+ m_Refreshed.disconnect_all_slots();
+ m_PluginStateChanged.disconnect_all_slots();
+}
-
-
-IPluginList::PluginState PluginList::state(const QString &name) const
+IPluginList::PluginStates PluginList::state(const QString &name) const
{
auto iter = m_ESPsByName.find(name.toLower());
if (iter == m_ESPsByName.end()) {
@@ -697,6 +696,12 @@ QString PluginList::origin(const QString &name) const }
}
+bool PluginList::onPluginStateChanged(const std::function<void (const QString &, PluginStates)> &func)
+{
+ auto conn = m_PluginStateChanged.connect(func);
+ return conn.connected();
+}
+
bool PluginList::onRefreshed(const std::function<void ()> &callback)
{
auto conn = m_Refreshed.connect(callback);
@@ -765,15 +770,13 @@ void PluginList::testMasters() // emit layoutChanged();
}
-
QVariant PluginList::data(const QModelIndex &modelIndex, int role) const
{
int index = modelIndex.row();
-
if ((role == Qt::DisplayRole)
|| (role == Qt::EditRole)) {
switch (modelIndex.column()) {
- case COL_NAME: {
+ case COL_NAME: {
return m_ESPs[index].m_Name;
} break;
case COL_PRIORITY: {
@@ -884,7 +887,11 @@ QVariant PluginList::data(const QModelIndex &modelIndex, int role) const bool PluginList::setData(const QModelIndex &modIndex, const QVariant &value, int role)
{
+ QString modName = modIndex.data().toString();
+ IPluginList::PluginStates oldState = state(modName);
+
bool result = false;
+
if (role == Qt::CheckStateRole) {
m_ESPs[modIndex.row()].m_Enabled = value.toInt() == Qt::Checked;
emit dataChanged(modIndex, modIndex);
@@ -904,6 +911,20 @@ bool PluginList::setData(const QModelIndex &modIndex, const QVariant &value, int refreshLoadOrder();
}
}
+
+ IPluginList::PluginStates newState = state(modName);
+ if (oldState != newState) {
+ try {
+ m_PluginStateChanged(modName, newState);
+ testMasters();
+ emit dataChanged(this->index(0, 0), this->index(m_ESPs.size(), columnCount()));
+ } catch (const std::exception &e) {
+ qCritical("failed to invoke state changed notification: %s", e.what());
+ } catch (...) {
+ qCritical("failed to invoke state changed notification: unknown exception");
+ }
+ }
+
return result;
}
|
