+ allow to get user friendly names for navigation styles

This commit is contained in:
wmayer 2016-03-10 18:37:48 +01:00
parent 5b156b2380
commit 3f79dfffb6
4 changed files with 59 additions and 29 deletions

View File

@ -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);
}
}

View File

@ -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

View File

@ -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;
@ -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;
}

View File

@ -259,6 +259,8 @@ public:
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 {
@ -270,6 +272,7 @@ public:
InventorNavigationStyle();
~InventorNavigationStyle();
const char* mouseButtons(ViewerMode);
virtual std::string userFriendlyName() const;
protected:
SbBool processSoEvent(const SoEvent * const ev);