Skip to content

Commit

Permalink
+ allow to get user friendly names for navigation styles
Browse files Browse the repository at this point in the history
  • Loading branch information
wwmayer committed Mar 10, 2016
1 parent 5b156b2 commit 3f79dff
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 29 deletions.
19 changes: 7 additions & 12 deletions src/Gui/DlgSettings3DViewImp.cpp
Expand Up @@ -177,20 +177,15 @@ void DlgSettings3DViewImp::changeEvent(QEvent *e)

void DlgSettings3DViewImp::retranslate()
{
std::vector<Base::Type> types;
Base::Type::getAllDerivedFrom(UserNavigationStyle::getClassTypeId(), types);
comboNavigationStyle->clear();

QRegExp rx(QString::fromLatin1("^\\w+::(\\w+)Navigation\\w+$"));
for (std::vector<Base::Type>::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<Base::Type, std::string> styles = UserNavigationStyle::getUserFriendlyNames();
for (std::map<Base::Type, std::string>::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);
}
}

Expand Down
6 changes: 6 additions & 0 deletions src/Gui/InventorNavigationStyle.cpp
Expand Up @@ -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
Expand Down
60 changes: 43 additions & 17 deletions src/Gui/NavigationStyle.cpp
Expand Up @@ -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<Base::Type> types;
Base::Type::getAllDerivedFrom(UserNavigationStyle::getClassTypeId(), types);
for (std::vector<Base::Type>::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<Base::Type, std::string> styles = UserNavigationStyle::getUserFriendlyNames();
for (std::map<Base::Type, std::string>::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;
Expand All @@ -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<Base::Type, std::string> UserNavigationStyle::getUserFriendlyNames()
{
std::map<Base::Type, std::string> names;
std::vector<Base::Type> types;
Base::Type::getAllDerivedFrom(UserNavigationStyle::getClassTypeId(), types);

for (std::vector<Base::Type>::iterator it = types.begin(); it != types.end(); ++it) {
if (*it != UserNavigationStyle::getClassTypeId()) {
std::auto_ptr<UserNavigationStyle> inst(static_cast<UserNavigationStyle*>(it->createInstance()));
if (inst.get()) {
names[*it] = inst->userFriendlyName();
}
}
}
return names;
}
3 changes: 3 additions & 0 deletions src/Gui/NavigationStyle.h
Expand Up @@ -259,6 +259,8 @@ class GuiExport UserNavigationStyle : public NavigationStyle {
UserNavigationStyle(){}
~UserNavigationStyle(){}
virtual const char* mouseButtons(ViewerMode) = 0;
virtual std::string userFriendlyName() const;
static std::map<Base::Type, std::string> getUserFriendlyNames();
};

class GuiExport InventorNavigationStyle : public UserNavigationStyle {
Expand All @@ -270,6 +272,7 @@ class GuiExport InventorNavigationStyle : public UserNavigationStyle {
InventorNavigationStyle();
~InventorNavigationStyle();
const char* mouseButtons(ViewerMode);
virtual std::string userFriendlyName() const;

protected:
SbBool processSoEvent(const SoEvent * const ev);
Expand Down

0 comments on commit 3f79dff

Please sign in to comment.