25 class QmitkModuleTableModelPrivate
30 std::vector<us::Module *> m = context->GetModules();
31 for (std::vector<us::Module *>::const_iterator it = m.begin(); it != m.end(); ++it)
33 modules[(*it)->GetModuleId()] = *it;
36 context->AddModuleListener(
this, &QmitkModuleTableModelPrivate::ModuleChanged);
39 ~QmitkModuleTableModelPrivate() { context->RemoveModuleListener(
this, &QmitkModuleTableModelPrivate::ModuleChanged); }
42 us::ModuleContext *context;
43 QMap<long, us::Module *> modules;
47 : QAbstractTableModel(parent), d(new QmitkModuleTableModelPrivate(this, mc ? mc :
us::
GetModuleContext()))
60 return d->modules.size();
75 if (role == Qt::DisplayRole)
77 us::Module *module = d->modules[index.row() + 1];
78 switch (index.column())
81 return QVariant::fromValue(static_cast<int>(module->
GetModuleId()));
83 return QString::fromStdString(module->
GetName());
87 return QString::fromStdString(module->
GetLocation());
90 else if (role == Qt::ForegroundRole)
92 us::Module *module = d->modules[index.row() + 1];
95 return QBrush(Qt::gray);
98 else if (role == Qt::ToolTipRole)
100 us::Module *module = d->modules[index.row() + 1];
101 QString
id = QString::number(module->
GetModuleId());
102 QString name = QString::fromStdString(module->
GetName());
104 QString location = QString::fromStdString(module->
GetLocation());
105 QString state = module->
IsLoaded() ?
"Loaded" :
"Unloaded";
107 QString tooltip =
"Id: %1\nName: %2\nVersion: %3\nLocation: %7\nState: %9";
109 return tooltip.arg(
id, name, version, location, state);
116 if (orientation != Qt::Horizontal || role != Qt::DisplayRole)
133 void QmitkModuleTableModel::insertModule(
us::Module *module)
136 if (d->modules.contains(
id))
138 d->modules[id] = module;
139 emit dataChanged(createIndex(
id - 1, 0), createIndex(
id - 1,
columnCount()));
144 beginInsertRows(QModelIndex(),
id - 1,
id - 1);
145 d->modules[id] = module;
QmitkModuleTableModel(QObject *parent=nullptr, us::ModuleContext *mc=nullptr)
std::string GetName() const
ModuleVersion GetVersion() const
Module * GetModule() 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 ToString() const
static ModuleContext * GetModuleContext()
Returns the module context of the calling module.