From 6c86a0321ba11c30de2d50c73b785c9bd3818da8 Mon Sep 17 00:00:00 2001 From: Mikaƫl Capelle Date: Sun, 30 Aug 2020 14:03:49 +0200 Subject: Add IPluginList::setPriority implementation. --- src/pluginlist.cpp | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'src/pluginlist.cpp') diff --git a/src/pluginlist.cpp b/src/pluginlist.cpp index c2667557..67ca0133 100644 --- a/src/pluginlist.cpp +++ b/src/pluginlist.cpp @@ -766,6 +766,29 @@ int PluginList::priority(const QString &name) const } } +bool PluginList::setPriority(const QString& name, int newPriority) { + + if (newPriority < 0 || newPriority >= static_cast(m_ESPsByPriority.size())) { + return false; + } + + auto oldPriority = priority(name); + if (oldPriority == -1) { + return false; + } + + int rowIndex = findPluginByPriority(oldPriority); + + // We need to increment newPriority if its above the old one, otherwise the + // plugin is place right below the new priority. + if (oldPriority < newPriority) { + newPriority += 1; + } + changePluginPriority({ rowIndex }, newPriority); + + return true; +} + int PluginList::loadOrder(const QString &name) const { auto iter = m_ESPsByName.find(name.toLower()); -- cgit v1.3.1