60 #include <ctkPlugin.h>
61 #include <ctkPluginContext.h>
70 : QAbstractTableModel(parent)
72 mFramework = framework;
73 connect(mFramework.get(), SIGNAL(pluginPoolChanged()),
this, SLOT(
resetAll()));
74 mFramework->getPluginContext()->connectPluginListener(
this, SLOT(
pluginChanged(ctkPluginEvent)));
80 this->beginResetModel();
81 QStringList names = mFramework->getPluginSymbolicNames();
82 std::map<QString, ctkPluginPtr> plugins;
83 for (
int i=0; i<names.size(); ++i)
84 plugins[names[i]].clear();
86 QList<ctkPluginPtr> installed = mFramework->getPluginContext()->getPlugins();
87 for (
int i=0; i<installed.size(); ++i)
88 plugins[installed[i]->getSymbolicName()] = installed[i];
92 this->endResetModel();
97 if (!index.isValid())
return QVariant();
99 std::map<QString, ctkPluginPtr>::const_iterator iter = mPlugins.begin();
100 std::advance(iter, index.row());
101 QString name = iter->first;
102 QSharedPointer<ctkPlugin> plugin = iter->second;
104 if (role == Qt::DisplayRole)
106 int col = index.column();
109 return QVariant(name);
114 return QVariant(plugin->getVersion().toString());
124 else if (role == Qt::UserRole)
126 return QVariant(name);
134 if (role == Qt::DisplayRole && orientation == Qt::Horizontal)
138 return QVariant(
"Plugin");
140 else if (section == 1)
142 return QVariant(
"Version");
144 else if (section == 2)
146 return QVariant(
"State");
164 return mPlugins.size();
169 if (!event.getPlugin())
171 qDebug() <<
"!! invalid plugin event";
176 for(std::map<QString, ctkPluginPtr>::iterator iter=mPlugins.begin(); iter!=mPlugins.end(); ++iter, ++i)
178 if (event.getPlugin()->getSymbolicName() != iter->first)
181 iter->second =
event.getPlugin();
183 QModelIndex topLeftIndex = createIndex(i, 0);
184 QModelIndex bottomRightIndex = createIndex(topLeftIndex.row(),
columnCount()-1);
185 emit dataChanged(topLeftIndex, bottomRightIndex);
QVariant headerData(int section, Qt::Orientation orientation, int role=Qt::DisplayRole) const
int rowCount(const QModelIndex &parent=QModelIndex()) const
QString getStringForctkPluginState(const ctkPlugin::State state)
ctkPluginTableModel(PluginFrameworkManagerPtr framework, QObject *parent=0)
int columnCount(const QModelIndex &parent=QModelIndex()) const
boost::shared_ptr< class PluginFrameworkManager > PluginFrameworkManagerPtr
void pluginChanged(const ctkPluginEvent &event)
QVariant data(const QModelIndex &index, int role=Qt::DisplayRole) const