39 #include <ctkPlugin.h>
40 #include <ctkPluginContext.h>
49 : QAbstractTableModel(parent)
51 mFramework = framework;
52 connect(mFramework.get(), SIGNAL(pluginPoolChanged()),
this, SLOT(
resetAll()));
53 mFramework->getPluginContext()->connectPluginListener(
this, SLOT(
pluginChanged(ctkPluginEvent)));
59 this->beginResetModel();
60 QStringList names = mFramework->getPluginSymbolicNames();
61 std::map<QString, ctkPluginPtr> plugins;
62 for (
int i=0; i<names.size(); ++i)
63 plugins[names[i]].clear();
65 QList<ctkPluginPtr> installed = mFramework->getPluginContext()->getPlugins();
66 for (
int i=0; i<installed.size(); ++i)
67 plugins[installed[i]->getSymbolicName()] = installed[i];
71 this->endResetModel();
76 if (!index.isValid())
return QVariant();
78 std::map<QString, ctkPluginPtr>::const_iterator iter = mPlugins.begin();
79 std::advance(iter, index.row());
80 QString name = iter->first;
81 QSharedPointer<ctkPlugin> plugin = iter->second;
83 if (role == Qt::DisplayRole)
85 int col = index.column();
88 return QVariant(name);
93 return QVariant(plugin->getVersion().toString());
103 else if (role == Qt::UserRole)
105 return QVariant(name);
113 if (role == Qt::DisplayRole && orientation == Qt::Horizontal)
117 return QVariant(
"Plugin");
119 else if (section == 1)
121 return QVariant(
"Version");
123 else if (section == 2)
125 return QVariant(
"State");
143 return mPlugins.size();
148 if (!event.getPlugin())
150 qDebug() <<
"!! invalid plugin event";
155 for(std::map<QString, ctkPluginPtr>::iterator iter=mPlugins.begin(); iter!=mPlugins.end(); ++iter, ++i)
157 if (event.getPlugin()->getSymbolicName() != iter->first)
160 iter->second =
event.getPlugin();
162 QModelIndex topLeftIndex = createIndex(i, 0);
163 QModelIndex bottomRightIndex = createIndex(topLeftIndex.row(),
columnCount()-1);
164 emit dataChanged(topLeftIndex, bottomRightIndex);