23 #include "engineplugincombobox.h"
25 #include "plugins/engineplugin.h"
26 #include "plugins/pluginloader.h"
28 EnginePluginComboBox::EnginePluginComboBox(QWidget *parent)
29 : QComboBox(parent), allowUnknown(false)
31 this->connect(
this, SIGNAL(currentIndexChanged(
int)), SLOT(onIndexChanged()));
35 EnginePlugin *EnginePluginComboBox::currentPlugin()
const
37 if (currentIndex() >= 0)
39 unsigned enginePluginIndex = itemData(currentIndex()).toUInt();
40 if (enginePluginIndex < gPlugins->numPlugins())
41 return gPlugins->info(enginePluginIndex);
46 void EnginePluginComboBox::loadPlugins()
50 for (
unsigned i = 0; i < gPlugins->numPlugins(); ++i)
53 addItem(plugin->icon(), plugin->data()->name, i);
60 void EnginePluginComboBox::onIndexChanged()
62 emit currentPluginChanged(currentPlugin());
67 this->allowUnknown = allow;
68 if (!allow && this->count() > gPlugins->numPlugins())
70 this->removeItem(gPlugins->numPlugins());
74 bool EnginePluginComboBox::setPluginByName(
const QString &name)
76 int engIndex = gPlugins->pluginIndexFromName(name);
79 if (this->allowUnknown)
81 QString label = tr(
"%1 (unknown)").arg(name);
82 if (this->count() > gPlugins->numPlugins())
85 this->setItemText(gPlugins->numPlugins(), label);
91 this->setCurrentIndex(gPlugins->numPlugins());
95 setCurrentIndex(engIndex);