21 class QmitkModuleTableModelPrivate
26 std::vector<us::Module *> m = context->GetModules();
27 for (std::vector<us::Module *>::const_iterator it = m.begin(); it != m.end(); ++it)
29 modules[(*it)->GetModuleId()] = *it;
32 context->AddModuleListener(
this, &QmitkModuleTableModelPrivate::ModuleChanged);
35 ~QmitkModuleTableModelPrivate() { context->RemoveModuleListener(
this, &QmitkModuleTableModelPrivate::ModuleChanged); }
38 us::ModuleContext *context;
39 QMap<long, us::Module *> modules;
43 : QAbstractTableModel(parent), d(new QmitkModuleTableModelPrivate(this, mc ? mc :
us::
GetModuleContext()))
56 return d->modules.size();
71 if (role == Qt::DisplayRole)
73 us::Module *module = d->modules[index.row() + 1];
74 switch (index.column())
77 return QVariant::fromValue(static_cast<int>(module->
GetModuleId()));
79 return QString::fromStdString(module->
GetName());
83 return QString::fromStdString(module->
GetLocation());
86 else if (role == Qt::ForegroundRole)
88 us::Module *module = d->modules[index.row() + 1];
91 return QBrush(Qt::gray);
94 else if (role == Qt::ToolTipRole)
96 us::Module *module = d->modules[index.row() + 1];
97 QString
id = QString::number(module->
GetModuleId());
98 QString name = QString::fromStdString(module->
GetName());
100 QString location = QString::fromStdString(module->
GetLocation());
101 QString state = module->
IsLoaded() ?
"Loaded" :
"Unloaded";
103 QString tooltip =
"Id: %1\nName: %2\nVersion: %3\nLocation: %7\nState: %9";
105 return tooltip.arg(
id, name, version, location, state);
112 if (orientation != Qt::Horizontal || role != Qt::DisplayRole)
129 void QmitkModuleTableModel::insertModule(
us::Module *module)
132 if (d->modules.contains(
id))
134 d->modules[id] = module;
135 emit dataChanged(createIndex(
id - 1, 0), createIndex(
id - 1,
columnCount()));
140 beginInsertRows(QModelIndex(),
id - 1,
id - 1);
141 d->modules[id] = module;
QmitkModuleTableModel(QObject *parent=nullptr, us::ModuleContext *mc=nullptr)
Module * GetModule() const
ModuleVersion GetVersion() const
std::string ToString() const
std::string GetLocation() const
QVariant headerData(int section, Qt::Orientation orientation, int role) const override
int rowCount(const QModelIndex &parent=QModelIndex()) const override
QVariant data(const QModelIndex &index, int role) const override
int columnCount(const QModelIndex &parent=QModelIndex()) const override
std::string GetName() const
static ModuleContext * GetModuleContext()
Returns the module context of the calling module.
~QmitkModuleTableModel() override