diff --git a/src/Gui/DlgSettings3DViewImp.cpp b/src/Gui/DlgSettings3DViewImp.cpp index b4ba51415..459293006 100644 --- a/src/Gui/DlgSettings3DViewImp.cpp +++ b/src/Gui/DlgSettings3DViewImp.cpp @@ -177,20 +177,15 @@ void DlgSettings3DViewImp::changeEvent(QEvent *e) void DlgSettings3DViewImp::retranslate() { - std::vector types; - Base::Type::getAllDerivedFrom(UserNavigationStyle::getClassTypeId(), types); comboNavigationStyle->clear(); - QRegExp rx(QString::fromLatin1("^\\w+::(\\w+)Navigation\\w+$")); - for (std::vector::iterator it = types.begin(); it != types.end(); ++it) { - if (*it != UserNavigationStyle::getClassTypeId()) { - QString data = QString::fromLatin1(it->getName()); - QString name = data.mid(data.indexOf(QLatin1String("::"))+2); - if (rx.indexIn(data) > -1) { - name = tr("%1 navigation").arg(rx.cap(1)); - } - comboNavigationStyle->addItem(name, data); - } + // add submenu at the end to select navigation style + std::map styles = UserNavigationStyle::getUserFriendlyNames(); + for (std::map::iterator it = styles.begin(); it != styles.end(); ++it) { + QByteArray data(it->first.getName()); + QString name = QApplication::translate(it->first.getName(), it->second.c_str()); + + comboNavigationStyle->addItem(name, data); } } diff --git a/src/Gui/InventorNavigationStyle.cpp b/src/Gui/InventorNavigationStyle.cpp index 12aed4c39..4435d2aa2 100644 --- a/src/Gui/InventorNavigationStyle.cpp +++ b/src/Gui/InventorNavigationStyle.cpp @@ -77,6 +77,12 @@ const char* InventorNavigationStyle::mouseButtons(ViewerMode mode) } } +std::string InventorNavigationStyle::userFriendlyName() const +{ + // do not mark this for translation + return "OpenInventor"; +} + SbBool InventorNavigationStyle::processSoEvent(const SoEvent * const ev) { // Events when in "ready-to-seek" mode are ignored, except those diff --git a/src/Gui/NavigationStyle.cpp b/src/Gui/NavigationStyle.cpp index 6bd3e9251..adcd752f5 100644 --- a/src/Gui/NavigationStyle.cpp +++ b/src/Gui/NavigationStyle.cpp @@ -1498,23 +1498,17 @@ void NavigationStyle::openPopupMenu(const SbVec2s& position) contextMenu.addMenu(&subMenu); // add submenu at the end to select navigation style - QRegExp rx(QString::fromLatin1("^\\w+::(\\w+)Navigation\\w+$")); - std::vector types; - Base::Type::getAllDerivedFrom(UserNavigationStyle::getClassTypeId(), types); - for (std::vector::iterator it = types.begin(); it != types.end(); ++it) { - if (*it != UserNavigationStyle::getClassTypeId()) { - QString data = QString::fromLatin1(it->getName()); - QString name = data.mid(data.indexOf(QLatin1String("::"))+2); - if (rx.indexIn(data) > -1) { - name = QObject::tr("%1 navigation").arg(rx.cap(1)); - QAction* item = subMenuGroup.addAction(name); - item->setData(QByteArray(it->getName())); - item->setCheckable(true); - if (*it == this->getTypeId()) - item->setChecked(true); - subMenu.addAction(item); - } - } + std::map styles = UserNavigationStyle::getUserFriendlyNames(); + for (std::map::iterator it = styles.begin(); it != styles.end(); ++it) { + QByteArray data(it->first.getName()); + QString name = QApplication::translate(it->first.getName(), it->second.c_str()); + + QAction* item = subMenuGroup.addAction(name); + item->setData(data); + item->setCheckable(true); + if (it->first == this->getTypeId()) + item->setChecked(true); + subMenu.addAction(item); } delete view; @@ -1538,3 +1532,35 @@ void NavigationStyle::openPopupMenu(const SbVec2s& position) // ---------------------------------------------------------------------------------- TYPESYSTEM_SOURCE_ABSTRACT(Gui::UserNavigationStyle,Gui::NavigationStyle); + +std::string UserNavigationStyle::userFriendlyName() const +{ + std::string name = this->getTypeId().getName(); + // remove namespaces + std::size_t pos = name.rfind("::"); + if (pos != std::string::npos) + name = name.substr(pos + 2); + + // remove 'NavigationStyle' + pos = name.find("NavigationStyle"); + if (pos != std::string::npos) + name = name.substr(0, pos); + return name; +} + +std::map UserNavigationStyle::getUserFriendlyNames() +{ + std::map names; + std::vector types; + Base::Type::getAllDerivedFrom(UserNavigationStyle::getClassTypeId(), types); + + for (std::vector::iterator it = types.begin(); it != types.end(); ++it) { + if (*it != UserNavigationStyle::getClassTypeId()) { + std::auto_ptr inst(static_cast(it->createInstance())); + if (inst.get()) { + names[*it] = inst->userFriendlyName(); + } + } + } + return names; +} diff --git a/src/Gui/NavigationStyle.h b/src/Gui/NavigationStyle.h index ee9bd1b8c..a1b53ff71 100644 --- a/src/Gui/NavigationStyle.h +++ b/src/Gui/NavigationStyle.h @@ -259,6 +259,8 @@ public: UserNavigationStyle(){} ~UserNavigationStyle(){} virtual const char* mouseButtons(ViewerMode) = 0; + virtual std::string userFriendlyName() const; + static std::map getUserFriendlyNames(); }; class GuiExport InventorNavigationStyle : public UserNavigationStyle { @@ -270,6 +272,7 @@ public: InventorNavigationStyle(); ~InventorNavigationStyle(); const char* mouseButtons(ViewerMode); + virtual std::string userFriendlyName() const; protected: SbBool processSoEvent(const SoEvent * const ev);