diff --git a/Core/CppMicroServices/src/util/usShrinkableMap.h b/Core/CppMicroServices/src/util/usShrinkableMap.h index fb5c68a407..dde5ca40a5 100644 --- a/Core/CppMicroServices/src/util/usShrinkableMap.h +++ b/Core/CppMicroServices/src/util/usShrinkableMap.h @@ -1,175 +1,175 @@ /*============================================================================= Library: CppMicroServices Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. =============================================================================*/ #ifndef USSHRINKABLEMAP_H #define USSHRINKABLEMAP_H #include "usConfig.h" #include US_BEGIN_NAMESPACE template class ShrinkableMap { private: static std::map emptyContainer; public: typedef std::map container_type; typedef typename container_type::iterator iterator; typedef typename container_type::const_iterator const_iterator; typedef typename container_type::size_type size_type; typedef typename container_type::key_type key_type; typedef typename container_type::mapped_type mapped_type; typedef typename container_type::value_type value_type; typedef typename container_type::reference reference; typedef typename container_type::const_reference const_reference; ShrinkableMap() : container(emptyContainer) { } iterator begin() { return container.begin(); } const_iterator begin() const { return container.begin(); } iterator end() { return container.end(); } const_iterator end() const { return container.end(); } void erase(iterator pos) { return container.erase(pos); } void erase(iterator first, iterator last) { return container.erase(first, last); } size_type erase(const Key& key) { return container.erase(key); } bool empty() const { return container.empty(); } void clear() { container.clear(); } size_type size() const { return container.size(); } size_type max_size() const { return container.max_size(); } T& operator[](const Key& key) { return container[key]; } size_type count(const Key& key) const { return container.count(key); } iterator find(const Key& key) { return container.find(key); } const_iterator find(const Key& key) const { return container.find(key); } std::pair equal_range(const Key& key) { return container.equal_range(key); } std::pair equal_range(const Key& key) const { return container.equal_range(key); } iterator lower_bound(const Key& key) { return container.lower_bound(key); } const_iterator lower_bound(const Key& key) const { return container.lower_bound(key); } iterator upper_bound(const Key& key) { return container.upper_bound(key); } const_iterator upper_bound(const Key& key) const { return container.upper_bound(key); } private: friend class ServiceHooks; ShrinkableMap(container_type& container) : container(container) {} container_type& container; }; template -typename ShrinkableMap::container_type ShrinkableMap::emptyContainer; +std::map ShrinkableMap::emptyContainer; US_END_NAMESPACE #endif // USSHRINKABLEMAP_H diff --git a/Modules/QmitkExt/QmitkModuleTableModel.cpp b/Modules/QmitkExt/QmitkModuleTableModel.cpp index 3ca717b6b4..be1440015f 100644 --- a/Modules/QmitkExt/QmitkModuleTableModel.cpp +++ b/Modules/QmitkExt/QmitkModuleTableModel.cpp @@ -1,154 +1,153 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ #include "QmitkModuleTableModel.h" #include #include #include #include class QmitkModuleTableModelPrivate { public: QmitkModuleTableModelPrivate(QmitkModuleTableModel* q, us::ModuleContext* mc) : q(q), context(mc) { - std::vector m; - context->GetModules(m); + std::vector m = context->GetModules(); for (std::vector::const_iterator it = m.begin(); it != m.end(); ++it) { modules[(*it)->GetModuleId()] = *it; } context->AddModuleListener(this, &QmitkModuleTableModelPrivate::ModuleChanged); } ~QmitkModuleTableModelPrivate() { context->RemoveModuleListener(this, &QmitkModuleTableModelPrivate::ModuleChanged); } void ModuleChanged(us::ModuleEvent event) { q->insertModule(event.GetModule()); } QmitkModuleTableModel* q; us::ModuleContext* context; QMap modules; }; QmitkModuleTableModel::QmitkModuleTableModel(QObject* parent, us::ModuleContext* mc) : QAbstractTableModel(parent), d(new QmitkModuleTableModelPrivate(this, mc ? mc : us::GetModuleContext())) { } QmitkModuleTableModel::~QmitkModuleTableModel() { delete d; } int QmitkModuleTableModel::rowCount(const QModelIndex& parent) const { if (parent.isValid()) return 0; return d->modules.size(); } int QmitkModuleTableModel::columnCount(const QModelIndex& parent) const { if (parent.isValid()) return 0; return 4; } QVariant QmitkModuleTableModel::data(const QModelIndex& index, int role) const { if (!index.isValid()) return QVariant(); if (role == Qt::DisplayRole) { us::Module* module = d->modules[index.row()+1]; switch(index.column()) { case 0: return QVariant::fromValue(static_cast(module->GetModuleId())); case 1: return QString::fromStdString(module->GetName()); case 2: return QString::fromStdString(module->GetVersion().ToString()); case 3: return QString::fromStdString(module->GetLocation()); } } else if (role == Qt::ForegroundRole) { us::Module* module = d->modules[index.row()+1]; if (!module->IsLoaded()) { return QBrush(Qt::gray); } } else if (role == Qt::ToolTipRole) { us::Module* module = d->modules[index.row()+1]; QString id = QString::number(module->GetModuleId()); QString name = QString::fromStdString(module->GetName()); QString version = QString::fromStdString(module->GetVersion().ToString()); QString location = QString::fromStdString(module->GetLocation()); QString state = module->IsLoaded() ? "Loaded" : "Unloaded"; QString tooltip = "Id: %1\nName: %2\nVersion: %3\nLocation: %7\nState: %9"; return tooltip.arg(id, name, version, location, state); } return QVariant(); } QVariant QmitkModuleTableModel::headerData(int section, Qt::Orientation orientation, int role) const { if (orientation != Qt::Horizontal || role != Qt::DisplayRole) return QVariant(); switch (section) { case 0: return "Id"; case 1: return "Name"; case 2: return "Version"; case 3: return "Location"; } return QVariant(); } void QmitkModuleTableModel::insertModule(us::Module* module) { long id = module->GetModuleId(); if (d->modules.contains(id)) { d->modules[id] = module; emit dataChanged(createIndex(id-1, 0), createIndex(id-1, columnCount())); return; } else { beginInsertRows(QModelIndex(), id-1, id-1); d->modules[id] = module; endInsertRows(); } }