| 357 | } |
| 358 | |
| 359 | void QmitkToolSelectionBox::RecreateButtons() |
| 360 | { |
| 361 | if (m_ToolManager.IsNull()) |
| 362 | return; |
| 363 | |
| 364 | QList<QAbstractButton *> l = m_ToolButtonGroup->buttons(); |
| 365 | // remove all buttons that are there |
| 366 | QList<QAbstractButton *>::iterator it; |
| 367 | QAbstractButton *btn; |
| 368 | |
| 369 | for (it = l.begin(); it != l.end(); ++it) |
| 370 | { |
| 371 | btn = *it; |
| 372 | m_ToolButtonGroup->removeButton(btn); |
| 373 | delete btn; |
| 374 | } |
| 375 | |
| 376 | mitk::ToolManager::ToolVectorTypeConst allPossibleTools = m_ToolManager->GetTools(); |
| 377 | mitk::ToolManager::ToolVectorTypeConst allTools; |
| 378 | |
| 379 | typedef std::pair<std::string::size_type, const mitk::Tool *> SortPairType; |
| 380 | typedef std::priority_queue<SortPairType> SortedToolQueueType; |
| 381 | SortedToolQueueType toolPositions; |
| 382 | |
| 383 | // clear and sort all tools |
| 384 | // step one: find name/group of all tools in m_DisplayedGroups string. remember these positions for all tools. |
| 385 | for (mitk::ToolManager::ToolVectorTypeConst::const_iterator iter = allPossibleTools.begin(); |
| 386 | iter != allPossibleTools.end(); |
| 387 | ++iter) |
| 388 | { |
| 389 | const mitk::Tool *tool = *iter; |
| 390 | |
| 391 | std::string::size_type namePos = m_DisplayedGroups.find(std::string("'") + tool->GetName() + "'"); |
| 392 | std::string::size_type groupPos = m_DisplayedGroups.find(std::string("'") + tool->GetGroup() + "'"); |
| 393 | |
| 394 | if (!m_DisplayedGroups.empty() && namePos == std::string::npos && groupPos == std::string::npos) |
| 395 | continue; // skip |
| 396 | |
| 397 | if (m_DisplayedGroups.empty() && std::string(tool->GetName()).length() > 0) |
| 398 | { |
| 399 | namePos = static_cast<std::string::size_type>(tool->GetName()[0]); |
| 400 | } |
| 401 | |
| 402 | SortPairType thisPair = std::make_pair(namePos < groupPos ? namePos : groupPos, *iter); |
| 403 | toolPositions.push(thisPair); |
| 404 | } |
| 405 | |
| 406 | // step two: sort tools according to previously found positions in m_DisplayedGroups |
| 407 | MITK_DEBUG << "Sorting order of tools (lower number --> earlier in button group)"; |
| 408 | while (!toolPositions.empty()) |
| 409 | { |
| 410 | SortPairType thisPair = toolPositions.top(); |
| 411 | MITK_DEBUG << "Position " << thisPair.first << " : " << thisPair.second->GetName(); |
| 412 | |
| 413 | allTools.push_back(thisPair.second); |
| 414 | toolPositions.pop(); |
| 415 | } |
| 416 | std::reverse(allTools.begin(), allTools.end()); |
nothing calls this directly
no test coverage detected