From 4b1a89648fffea98b447e4289dbc559d717d0b52 Mon Sep 17 00:00:00 2001 From: Mikaƫl Capelle Date: Tue, 29 Sep 2020 22:47:38 +0200 Subject: Display plugins in a tree instead of a list in the settings dialog. --- src/plugincontainer.cpp | 89 ++++++++++++++++++++++++++++++------------------- 1 file changed, 54 insertions(+), 35 deletions(-) (limited to 'src/plugincontainer.cpp') diff --git a/src/plugincontainer.cpp b/src/plugincontainer.cpp index 90a7e95f..60acc63c 100644 --- a/src/plugincontainer.cpp +++ b/src/plugincontainer.cpp @@ -34,6 +34,55 @@ template <> struct PluginTypeName { static QString value() template <> struct PluginTypeName { static QString value() { return QT_TR_NOOP("Proxy"); } }; template <> struct PluginTypeName { static QString value() { return QT_TR_NOOP("File Mapper"); } }; + +QStringList PluginContainer::pluginInterfaces() +{ + // Find all the names: + QStringList names; + boost::mp11::mp_for_each([&names](const auto* p) { + using plugin_type = std::decay_t; + auto name = PluginTypeName::value(); + if (!name.isEmpty()) { + names.append(name); + } + }); + + return names; +} + + +PluginContainer::PluginContainer(OrganizerCore *organizer) + : m_Organizer(organizer) + , m_UserInterface(nullptr) +{ +} + +PluginContainer::~PluginContainer() { + m_Organizer = nullptr; + unloadPlugins(); +} + + +void PluginContainer::setUserInterface(IUserInterface *userInterface, QWidget *widget) +{ + for (IPluginProxy *proxy : bf::at_key(m_Plugins)) { + proxy->setParentWidget(widget); + } + + if (userInterface != nullptr) { + for (IPluginModPage *modPage : bf::at_key(m_Plugins)) { + userInterface->registerModPage(modPage); + } + + for (IPluginTool *tool : bf::at_key(m_Plugins)) { + userInterface->registerPluginTool(tool); + } + } + + m_UserInterface = userInterface; +} + + QStringList PluginContainer::implementedInterfaces(IPlugin* plugin) const { // We need a QObject to be able to qobject_cast<> to the plugin types: @@ -45,7 +94,7 @@ QStringList PluginContainer::implementedInterfaces(IPlugin* plugin) const // Find all the names: QStringList names; - boost::mp11::mp_for_each([oPlugin, &names](const auto *p) { + boost::mp11::mp_for_each([oPlugin, &names](const auto* p) { using plugin_type = std::decay_t; if (qobject_cast(oPlugin)) { auto name = PluginTypeName::value(); @@ -53,7 +102,7 @@ QStringList PluginContainer::implementedInterfaces(IPlugin* plugin) const names.append(name); } } - }); + }); // If the plugin implements at least one interface other than IPlugin, remove IPlugin: if (names.size() > 1) { @@ -63,6 +112,7 @@ QStringList PluginContainer::implementedInterfaces(IPlugin* plugin) const return names; } + QString PluginContainer::topImplementedInterface(IPlugin* plugin) const { // We need a QObject to be able to qobject_cast<> to the plugin types: @@ -74,7 +124,7 @@ QString PluginContainer::topImplementedInterface(IPlugin* plugin) const // Find all the names: QString name; - boost::mp11::mp_for_each([oPlugin, &name](auto *p) { + boost::mp11::mp_for_each([oPlugin, &name](auto* p) { using plugin_type = std::decay_t; if (name.isEmpty() && qobject_cast(oPlugin)) { auto tname = PluginTypeName::value(); @@ -82,42 +132,11 @@ QString PluginContainer::topImplementedInterface(IPlugin* plugin) const name = tname; } } - }); + }); return name; } -PluginContainer::PluginContainer(OrganizerCore *organizer) - : m_Organizer(organizer) - , m_UserInterface(nullptr) -{ -} - -PluginContainer::~PluginContainer() { - m_Organizer = nullptr; - unloadPlugins(); -} - - -void PluginContainer::setUserInterface(IUserInterface *userInterface, QWidget *widget) -{ - for (IPluginProxy *proxy : bf::at_key(m_Plugins)) { - proxy->setParentWidget(widget); - } - - if (userInterface != nullptr) { - for (IPluginModPage *modPage : bf::at_key(m_Plugins)) { - userInterface->registerModPage(modPage); - } - - for (IPluginTool *tool : bf::at_key(m_Plugins)) { - userInterface->registerPluginTool(tool); - } - } - - m_UserInterface = userInterface; -} - QStringList PluginContainer::pluginFileNames() const { -- cgit v1.3.1