From 5de173ba1ae9531aaca0c0f022a2b0dae1c09250 Mon Sep 17 00:00:00 2001 From: LostDragonist Date: Wed, 31 Oct 2018 17:05:05 -0500 Subject: Add send to top/bottom options for the plugin list --- src/pluginlist.cpp | 88 +++++++++++++++++++++++++++++++++++++----------------- 1 file changed, 61 insertions(+), 27 deletions(-) (limited to 'src/pluginlist.cpp') diff --git a/src/pluginlist.cpp b/src/pluginlist.cpp index 18e40a6e..4097ba98 100644 --- a/src/pluginlist.cpp +++ b/src/pluginlist.cpp @@ -289,21 +289,26 @@ void PluginList::enableESP(const QString &name, bool enable) } } +int PluginList::findPluginByPriority(int priority) +{ + for (int i = 0; i < m_ESPs.size(); i++ ) { + if (m_ESPs[i].m_Priority == priority) { + return i; + } + } + qCritical(QString("No plugin with priority %1").arg(priority).toLocal8Bit()); + return -1; +} + void PluginList::enableSelected(const QItemSelectionModel *selectionModel) { - if (selectionModel->hasSelection()){ + if (selectionModel->hasSelection()) { bool dirty = false; for (auto row : selectionModel->selectedRows(COL_PRIORITY)) { - int rowPriority = row.data().toInt(); - for (int i = 0; i < m_ESPs.size(); i++) { - if (m_ESPs[i].m_Priority == rowPriority) { - if (!m_ESPs[i].m_Enabled) { - m_ESPs[i].m_Enabled = true; - dirty = true; - } - - break; - } + int rowIndex = findPluginByPriority(row.data().toInt()); + if (!m_ESPs[rowIndex].m_Enabled) { + m_ESPs[rowIndex].m_Enabled = true; + dirty = true; } } if (dirty) emit writePluginsList(); @@ -312,18 +317,13 @@ void PluginList::enableSelected(const QItemSelectionModel *selectionModel) void PluginList::disableSelected(const QItemSelectionModel *selectionModel) { - if (selectionModel->hasSelection()){ + if (selectionModel->hasSelection()) { bool dirty = false; for (auto row : selectionModel->selectedRows(COL_PRIORITY)) { - int rowPriority = row.data().toInt(); - for (int i = 0; i < m_ESPs.size(); i++) { - if (m_ESPs[i].m_Priority == rowPriority) { - if (!m_ESPs[i].m_ForceEnabled && m_ESPs[i].m_Enabled) { - m_ESPs[i].m_Enabled = false; - dirty = true; - } - break; - } + int rowIndex = findPluginByPriority(row.data().toInt()); + if (!m_ESPs[rowIndex].m_ForceEnabled && m_ESPs[rowIndex].m_Enabled) { + m_ESPs[rowIndex].m_Enabled = false; + dirty = true; } } if (dirty) emit writePluginsList(); @@ -356,6 +356,40 @@ void PluginList::disableAll() } } +void PluginList::sendToTop(const QItemSelectionModel *selectionModel) +{ + if (selectionModel->hasSelection()) { + std::vector pluginsToMove; + for (auto row: selectionModel->selectedRows(COL_PRIORITY)) { + int rowIndex = findPluginByPriority(row.data().toInt()); + if (!m_ESPs[rowIndex].m_ForceEnabled) { + pluginsToMove.push_back(rowIndex); + } + } + if (pluginsToMove.size()) { + changePluginPriority(pluginsToMove, 0); + emit SIGNAL(displayPlugin(0)); + } + } +} + +void PluginList::sendToBottom(const QItemSelectionModel *selectionModel) +{ + if (selectionModel->hasSelection()) { + std::vector pluginsToMove; + for (auto row: selectionModel->selectedRows(COL_PRIORITY)) { + int rowIndex = findPluginByPriority(row.data().toInt()); + if (!m_ESPs[rowIndex].m_ForceEnabled) { + pluginsToMove.push_back(rowIndex); + } + } + if (pluginsToMove.size()) { + changePluginPriority(pluginsToMove, INT_MAX); + emit SIGNAL(displayPlugin(INT_MAX)); + } + } +} + bool PluginList::isEnabled(const QString &name) { @@ -1092,6 +1126,12 @@ void PluginList::setPluginPriority(int row, int &newPriority) { int newPriorityTemp = newPriority; + // enforce valid range + if (newPriorityTemp < 0) + newPriorityTemp = 0; + else if (newPriorityTemp >= static_cast(m_ESPsByPriority.size())) + newPriorityTemp = static_cast(m_ESPsByPriority.size()) - 1; + if (!m_ESPs[row].m_IsMaster && !m_ESPs[row].m_IsLight) { // don't allow esps to be moved above esms while ((newPriorityTemp < static_cast(m_ESPsByPriority.size() - 1)) && @@ -1113,12 +1153,6 @@ void PluginList::setPluginPriority(int row, int &newPriority) } } - // enforce valid range - if (newPriorityTemp < 0) - newPriorityTemp = 0; - else if (newPriorityTemp >= static_cast(m_ESPsByPriority.size())) - newPriorityTemp = static_cast(m_ESPsByPriority.size()) - 1; - try { int oldPriority = m_ESPs.at(row).m_Priority; if (newPriorityTemp > oldPriority) { -- cgit v1.3.1