diff --git a/Plugins/org.mitk.gui.qt.cli/src/QmitkCmdLineModuleMenuComboBox.cpp b/Plugins/org.mitk.gui.qt.cli/src/QmitkCmdLineModuleMenuComboBox.cpp index 3d5a5b4881..f1dd6be7ed 100644 --- a/Plugins/org.mitk.gui.qt.cli/src/QmitkCmdLineModuleMenuComboBox.cpp +++ b/Plugins/org.mitk.gui.qt.cli/src/QmitkCmdLineModuleMenuComboBox.cpp @@ -1,189 +1,190 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) University College London (UCL). 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 "QmitkCmdLineModuleMenuComboBox.h" #include #include #include #include #include #include #include #include #include #include #include // ------------------------------------------------------------------------- QmitkCmdLineModuleMenuComboBox::QmitkCmdLineModuleMenuComboBox(QWidget* parent) : ctkMenuComboBox(parent) , m_ModuleManager(NULL) { + qRegisterMetaType(); } // ------------------------------------------------------------------------- QmitkCmdLineModuleMenuComboBox::~QmitkCmdLineModuleMenuComboBox() { } // ------------------------------------------------------------------------- void QmitkCmdLineModuleMenuComboBox::SetManager(ctkCmdLineModuleManager* manager) { if (m_ModuleManager != NULL) { QObject::disconnect(manager, 0, this, 0); } m_ModuleManager = manager; connect(m_ModuleManager, SIGNAL(moduleRegistered(const ctkCmdLineModuleReference&)), this, SLOT(OnModuleRegistered(const ctkCmdLineModuleReference&))); connect(m_ModuleManager, SIGNAL(moduleUnregistered(const ctkCmdLineModuleReference&)), this, SLOT(OnModuleUnRegistered(const ctkCmdLineModuleReference&))); } // ------------------------------------------------------------------------- ctkCmdLineModuleManager* QmitkCmdLineModuleMenuComboBox::GetManager() const { return m_ModuleManager; } // ------------------------------------------------------------------------- void QmitkCmdLineModuleMenuComboBox::OnModuleRegistered(const ctkCmdLineModuleReference&) { this->RebuildMenu(); } // ------------------------------------------------------------------------- void QmitkCmdLineModuleMenuComboBox::OnModuleUnRegistered(const ctkCmdLineModuleReference&) { this->RebuildMenu(); } // ------------------------------------------------------------------------- void QmitkCmdLineModuleMenuComboBox::AddName( QList< QHash* >& listOfHashMaps, const int& depth, const QString& name, QMenu* menu ) { if (depth >= listOfHashMaps.size()) { int need = depth - listOfHashMaps.size(); for (int i = 0; i <= need; i++) { QHash *newHashMap = new QHash(); listOfHashMaps.push_back(newHashMap); } } listOfHashMaps[depth]->insert(name, menu); } // ------------------------------------------------------------------------- void QmitkCmdLineModuleMenuComboBox::RebuildMenu() { if (m_ModuleManager == NULL) { qDebug() << "QmitkCmdLineModuleMenuComboBox::RebuildMenu(): Module Manager is NULL? Surely a bug?"; return; } // Can't see another way to get a nested menu, without rebuilding the whole thing each time. // :-( QMenu *menu = new QMenu(); QStringList listOfModules; QList references = m_ModuleManager->moduleReferences(); // Get full names for (int i = 0; i < references.size(); i++) { ctkCmdLineModuleReference reference = references[i]; ctkCmdLineModuleDescription description = reference.description(); QString title = description.title(); QString category = description.category(); QString fullName = category + "." + title; listOfModules << fullName; } // Sort list, so menu comes out in some sort of nice order. listOfModules.sort(); // Temporary data structure to enable connecting menus together. QList< QHash* > list; // Iterate through all modules. foreach (QString fullName, listOfModules) { // Pointer to keep track of where we are in the menu tree. QMenu *currentMenu = menu; // Get individual parts, as they correspond to menu levels. QStringList nameParts = fullName.split(".", QString::SkipEmptyParts); // Iterate over each part, building up either a QMenu or QAction. for (int i = 0; i < nameParts.size(); i++) { QString part = nameParts[i]; if (i != nameParts.size() - 1) { // Need to add a menu/submenu, not an action. if (list.size() <= i || list[i] == NULL || !list[i]->contains(part)) { QMenu *newMenu = new QMenu(part); currentMenu->addMenu(newMenu); currentMenu = newMenu; // Add this newMenu pointer to temporary datastructure, // so we know we have already created it. this->AddName(list, i, part, newMenu); } else { currentMenu = list[i]->value(part); } } else { // Leaf node, just add the action. QAction *action = currentMenu->addAction(part); // We set the object name, so we can retrieve it later when we want to // rebuild a new GUI depending on the name of the action. // see QmitkCmdLineModuleProgressWidget. action->setObjectName(fullName); } } } // Clearup termporary data structure for (int i = 0; i < list.size(); i++) { delete list[i]; } // Set the constructed menu on the base class combo box. this->setMenu(menu); }