diff --git a/BlueBerry/Bundles/org.blueberry.core.runtime/src/berryReflection.cpp b/BlueBerry/Bundles/org.blueberry.core.runtime/src/berryReflection.cpp index 1623423279..ed6db9c471 100644 --- a/BlueBerry/Bundles/org.blueberry.core.runtime/src/berryReflection.cpp +++ b/BlueBerry/Bundles/org.blueberry.core.runtime/src/berryReflection.cpp @@ -1,107 +1,109 @@ /*=================================================================== BlueBerry Platform 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 "berryReflection.h" #include "berryObject.h" // Better name demangling for gcc #if __GNUC__ > 3 || ( __GNUC__ == 3 && __GNUC_MINOR__ > 0 ) #define GCC_USEDEMANGLE #endif #ifdef GCC_USEDEMANGLE #include #include #endif #if defined(_WIN32) && defined(NDEBUG) // exported from VC CRT extern "C" char * __unDName(char * outputString, const char * name, int maxStringLength, void * (* pAlloc )(size_t), void (* pFree )(void *), unsigned short disableFlags); #endif namespace berry { namespace Reflection { QString DemangleName(const char* mangledName) { QString name(mangledName); #ifdef GCC_USEDEMANGLE int status; char* unmangled = abi::__cxa_demangle(mangledName, 0, 0, &status); if(status == 0) { name = QString(unmangled); free(unmangled); } #elif defined(_WIN32) && defined(NDEBUG) char * const unmangled = __unDName(0, mangledName, 0, malloc, free, 0x2800); if (unmangled) { QString unmangledName(unmangled); name = unmangledName.split(' ', QString::SkipEmptyParts).back(); free(unmangled); } #else name = name.split(' ', QString::SkipEmptyParts).back(); #endif return name; } #ifdef GetClassName // clash with WinUser.h definition #undef GetClassName #endif QString GetClassName(const Object* obj) { return DemangleName(typeid(*const_cast(obj)).name()); } +TypeInfo::Concept::~Concept(){} + template<> struct TypeInfo::Model : Concept { QString GetName() const { return QString(); } QList GetSuperclasses() const { return QList(); } }; TypeInfo::TypeInfo() : m_Self(std::make_shared >()) { } bool TypeInfo::operator==(const TypeInfo& other) const { return this->GetName() == other.GetName(); } QString TypeInfo::GetName() const { return m_Self->GetName(); } QList TypeInfo::GetSuperclasses() const { return m_Self->GetSuperclasses(); } } } diff --git a/BlueBerry/Bundles/org.blueberry.core.runtime/src/berryReflection.h b/BlueBerry/Bundles/org.blueberry.core.runtime/src/berryReflection.h index 35a4e56235..94723ac4ba 100644 --- a/BlueBerry/Bundles/org.blueberry.core.runtime/src/berryReflection.h +++ b/BlueBerry/Bundles/org.blueberry.core.runtime/src/berryReflection.h @@ -1,239 +1,240 @@ /*=================================================================== BlueBerry Platform 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. ===================================================================*/ #ifndef BERRYREFLECTION_H #define BERRYREFLECTION_H #include #include #include #include #include #ifdef GetClassName // clash with WinUser.h definition #undef GetClassName #endif namespace berry { class Object; namespace Reflection { org_blueberry_core_runtime_EXPORT QString DemangleName(const char* typeName); org_blueberry_core_runtime_EXPORT QString GetClassName(const Object* obj); template QString GetClassName() { return DemangleName(typeid(T).name()); } class TypeInfo; template QList GetSuperclasses(); struct EmptyType {}; template< typename T0=EmptyType, typename T1=EmptyType, typename T2=EmptyType, typename T3=EmptyType, typename T4=EmptyType, typename T5=EmptyType, typename T6=EmptyType, typename T7=EmptyType, typename T8=EmptyType, typename T9=EmptyType > struct TypeList; template< typename T0, typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7, typename T8, typename T9 > struct TypeList { typedef T0 head; typedef TypeList tail; enum { length = tail::length+1 }; }; template<> struct TypeList { enum { length = 0 }; }; // MapReduce template< typename TL, template class Map, template class Reduce > struct MapReduce { typedef typename Map::type map_type; typedef typename Reduce::result type; static type& value(type& result) { return MapReduce::value(Reduce::value(result, Map::value())); } static type value() { type result; return MapReduce::value(Reduce::value(result, Map::value())); } }; template< template class Map, template class Reduce > struct MapReduce, Map, Reduce> { typedef typename Map::type map_type; typedef typename Reduce::result type; static type value() { return type(); } static type& value(type& result) { return result; } }; class org_blueberry_core_runtime_EXPORT TypeInfo { public: TypeInfo(); template explicit TypeInfo(T* /*dummy*/) : m_Self(std::make_shared >()) {} bool operator==(const TypeInfo& other) const; template static TypeInfo New() { T* dummy = nullptr; return TypeInfo(dummy); } QString GetName() const; QList GetSuperclasses() const; + private: - struct Concept { - virtual ~Concept() = default; + struct org_blueberry_core_runtime_EXPORT Concept { + virtual ~Concept(); virtual QString GetName() const = 0; virtual QList GetSuperclasses() const = 0; }; template struct Model : Concept { QString GetName() const { return GetClassName(); } QList GetSuperclasses() const; }; std::shared_ptr m_Self; }; template struct MapToTypeInfo { typedef TypeInfo type; static type value() { return TypeInfo::New(); } }; template struct ReduceToList { typedef T type; typedef QList result; static result& value(result& list, const type& item) { list.push_back(item); return list; } }; template class HasTypeSuperclass { typedef char Small; struct Big { char dummy[2]; }; template static Small Test(typename U::SuperclassTypes*); template static Big Test(...); public: enum { value = sizeof(Test(NULL)) == sizeof(Small) }; }; template struct GetSuperclassTypeList { typedef TypeList<> value; }; template struct GetSuperclassTypeList { typedef typename T::SuperclassTypes value; }; template QList GetSuperclasses() { return MapReduce::value>::value, MapToTypeInfo, ReduceToList>::value(); } template QList TypeInfo::Model::GetSuperclasses() const { return ::berry::Reflection::GetSuperclasses(); } } // end namespace Reflection } // end namespace berry #endif // BERRYREFLECTION_H diff --git a/BlueBerry/Bundles/org.blueberry.core.runtime/src/registry/berryIExtensionPointFilter.cpp b/BlueBerry/Bundles/org.blueberry.core.runtime/src/registry/berryIExtensionPointFilter.cpp index 46fabbcd34..e72882ac11 100644 --- a/BlueBerry/Bundles/org.blueberry.core.runtime/src/registry/berryIExtensionPointFilter.cpp +++ b/BlueBerry/Bundles/org.blueberry.core.runtime/src/registry/berryIExtensionPointFilter.cpp @@ -1,41 +1,46 @@ /*=================================================================== BlueBerry Platform 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 "berryIExtensionPointFilter.h" namespace berry { IExtensionPointFilter::IExtensionPointFilter(const IExtensionPointFilter::Concept* concept) : m_Self(concept) { } +IExtensionPointFilter::Concept::~Concept() +{ + +} + bool IExtensionPointFilter::IsNull() const { return m_Self.get() == nullptr; } const IExtensionPointFilter::Concept* IExtensionPointFilter::GetConcept() const { return m_Self.get(); } bool IExtensionPointFilter::Matches(const IExtensionPoint* target) const { return m_Self->Matches(target); } } diff --git a/BlueBerry/Bundles/org.blueberry.core.runtime/src/registry/berryIExtensionPointFilter.h b/BlueBerry/Bundles/org.blueberry.core.runtime/src/registry/berryIExtensionPointFilter.h index 335381aec2..7bf4849c4a 100644 --- a/BlueBerry/Bundles/org.blueberry.core.runtime/src/registry/berryIExtensionPointFilter.h +++ b/BlueBerry/Bundles/org.blueberry.core.runtime/src/registry/berryIExtensionPointFilter.h @@ -1,67 +1,67 @@ /*=================================================================== BlueBerry Platform 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. ===================================================================*/ #ifndef BERRYIEXTENSIONPOINTFILTER_H #define BERRYIEXTENSIONPOINTFILTER_H #include #include namespace berry { struct IExtensionPoint; /** * A filter compares the given object to some pattern and returns * true if the two match and false otherwise. *

* This interface may be implemented by clients, however factory methods are * available on IExtensionTracker. *

*/ struct org_blueberry_core_runtime_EXPORT IExtensionPointFilter { struct org_blueberry_core_runtime_EXPORT Concept { virtual bool Matches(const IExtensionPoint* target) const = 0; - virtual ~Concept() = default; + virtual ~Concept(); }; IExtensionPointFilter(const Concept* concept); bool IsNull() const; const Concept* GetConcept() const; /** * Return true if the given object matches the criteria * for this filter. * * @param target the object to match * @return true if the target matches this filter - * and false otherwise + * and false otherwise */ bool Matches(const IExtensionPoint* target) const; private: std::shared_ptr m_Self; }; } #endif // BERRYIEXTENSIONPOINTFILTER_H diff --git a/BlueBerry/Bundles/org.blueberry.ui.qt/src/internal/berrySwitchToWindowMenu.cpp b/BlueBerry/Bundles/org.blueberry.ui.qt/src/internal/berrySwitchToWindowMenu.cpp index 0b54df2426..943e4b35c0 100644 --- a/BlueBerry/Bundles/org.blueberry.ui.qt/src/internal/berrySwitchToWindowMenu.cpp +++ b/BlueBerry/Bundles/org.blueberry.ui.qt/src/internal/berrySwitchToWindowMenu.cpp @@ -1,158 +1,159 @@ /*=================================================================== BlueBerry Platform 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 "berrySwitchToWindowMenu.h" #include #include #include #include #include #include #include #include namespace berry { void SwitchToWindowMenu::AboutToShow(IMenuManager* manager) { manager->MarkDirty(); dirty = true; } void SwitchToWindowMenu::MenuItemTriggered(int index) { if (index < 0 || index >= windows.size()) return; IWorkbenchWindow* window = windows[index]; Shell::Pointer windowShell = window->GetShell(); if (windowShell->GetMinimized()) { windowShell->SetMinimized(false); } windowShell->SetActive(); windowShell->GetControl()->raise(); } QString SwitchToWindowMenu::CalcText(int number, IWorkbenchWindow* window) { QString suffix = window->GetShell()->GetText(); if (suffix.isEmpty()) { return QString::null; } QString sb; if (number < 10) { sb.append('&'); } sb.append(QString::number(number)); sb.append(' '); if (suffix.size() <= MAX_TEXT_LENGTH) { sb.append(suffix); } else { sb.append(suffix.left(MAX_TEXT_LENGTH)); sb.append("..."); } return sb; } SwitchToWindowMenu::SwitchToWindowMenu(IWorkbenchWindow* window, const QString& id, bool showSeparator) : ContributionItem(id) , workbenchWindow(window) , showSeparator(showSeparator) + , dirty(true) { } void SwitchToWindowMenu::Fill(QMenu* menu, QAction* before) { // Get workbench windows. IWorkbench* workbench = workbenchWindow->GetWorkbench(); windows.clear(); for (auto window : workbench->GetWorkbenchWindows()) { windows.push_back(window.GetPointer()); } // avoid showing the separator and list for 0 or 1 items if (windows.size() < 2) { return; } if (MenuManager* mm = dynamic_cast(GetParent())) { this->connect(mm, SIGNAL(AboutToShow(IMenuManager*)), SLOT(AboutToShow(IMenuManager*))); } if (!dirty) { return; } // Add separator. if (showSeparator) { menu->insertSeparator(before); } // Add one item for each window. QActionGroup* actionGroup = new QActionGroup(menu); actionGroup->setExclusive(true); QSignalMapper* signalMapper = new QSignalMapper(menu); connect(signalMapper, SIGNAL(mapped(int)), SLOT(MenuItemTriggered(int))); int count = 0; for (auto window : windows) { // can encounter disposed shells if this update is in response to a shell closing //if (!window->GetShell()->IsDisposed()) //{ QString name = CalcText(count, window); if (!name.isEmpty()) { QAction* mi = new QAction(name, menu); mi->setCheckable(true); mi->setChecked(window == workbenchWindow); actionGroup->addAction(mi); menu->insertAction(before, mi); signalMapper->setMapping(mi, count); connect(mi, SIGNAL(triggered()), signalMapper, SLOT(map())); } ++count; } //} dirty = false; } bool SwitchToWindowMenu::IsDirty() const { return dirty; } bool SwitchToWindowMenu::IsDynamic() const { return true; } } diff --git a/BlueBerry/Bundles/org.blueberry.ui.qt/src/internal/berrySwitchToWindowMenu.h b/BlueBerry/Bundles/org.blueberry.ui.qt/src/internal/berrySwitchToWindowMenu.h index 6564c19459..75531ac26b 100644 --- a/BlueBerry/Bundles/org.blueberry.ui.qt/src/internal/berrySwitchToWindowMenu.h +++ b/BlueBerry/Bundles/org.blueberry.ui.qt/src/internal/berrySwitchToWindowMenu.h @@ -1,89 +1,89 @@ /*=================================================================== BlueBerry Platform 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. ===================================================================*/ #ifndef BERRYSWITCHTOWINDOWMENU_H #define BERRYSWITCHTOWINDOWMENU_H #include "berryContributionItem.h" namespace berry { struct IMenuManager; struct IWorkbenchWindow; /** * A dynamic menu item to switch to other opened workbench windows. */ class SwitchToWindowMenu : public QObject, public ContributionItem { Q_OBJECT private: static const int MAX_TEXT_LENGTH = 40; IWorkbenchWindow* workbenchWindow; QList windows; bool showSeparator; - bool dirty = true; + bool dirty; Q_SLOT void AboutToShow(IMenuManager* manager); Q_SLOT void MenuItemTriggered(int index); /** * Returns the text for a window. This may be truncated to fit * within the MAX_TEXT_LENGTH. */ QString CalcText(int number, IWorkbenchWindow* window); public: /** * Creates a new instance of this class. * * @param window the workbench window this action applies to * @param showSeparator whether to add a separator in the menu */ SwitchToWindowMenu(IWorkbenchWindow* window, const QString& id, bool showSeparator); /** * Fills the given menu with menu items for all * opened workbench windows. */ void Fill(QMenu* menu, QAction* before); using ContributionItem::Fill; /** * Overridden to always return true and force dynamic menu building. */ bool IsDirty() const; /** * Overridden to always return true and force dynamic menu building. */ bool IsDynamic() const; }; } #endif // BERRYSWITCHTOWINDOWMENU_H