From 76da77f80e7391c2c24cc83b16f44f22c35b580b Mon Sep 17 00:00:00 2001 From: wmayer Date: Wed, 29 Sep 2021 15:25:46 +0200 Subject: [PATCH] Gui: add convenience function Command::translatedGroupName() --- src/Gui/Command.cpp | 10 ++++++++++ src/Gui/Command.h | 1 + src/Gui/DlgCommandsImp.cpp | 4 ++-- src/Gui/DlgCustomizeSpaceball.cpp | 2 +- src/Gui/DlgKeyboardImp.cpp | 4 ++-- src/Gui/DlgToolbarsImp.cpp | 4 ++-- 6 files changed, 18 insertions(+), 7 deletions(-) diff --git a/src/Gui/Command.cpp b/src/Gui/Command.cpp index 4bd6c99699..2f34ea1e60 100644 --- a/src/Gui/Command.cpp +++ b/src/Gui/Command.cpp @@ -579,6 +579,16 @@ void Command::setGroupName(const char* s) this->sGroup = StringCache::New(s); } +QString Command::translatedGroupName() const +{ + QString text = qApp->translate(className(), getGroupName()); +#if 0 // not yet activated + if (text == QString::fromLatin1(getGroupName())) + text = qApp->translate("Workbench", getGroupName()); +#endif + return text; +} + //-------------------------------------------------------------------------- // UNDO REDO transaction handling //-------------------------------------------------------------------------- diff --git a/src/Gui/Command.h b/src/Gui/Command.h index 852da24852..59ac11416e 100644 --- a/src/Gui/Command.h +++ b/src/Gui/Command.h @@ -568,6 +568,7 @@ public: /// Get the name of the grouping of the command const char* getGroupName() const { return sGroup; } void setGroupName(const char*); + QString translatedGroupName() const; //@} diff --git a/src/Gui/DlgCommandsImp.cpp b/src/Gui/DlgCommandsImp.cpp index ba478bbc97..3b5e5bb14c 100644 --- a/src/Gui/DlgCommandsImp.cpp +++ b/src/Gui/DlgCommandsImp.cpp @@ -93,7 +93,7 @@ DlgCustomCommandsImp::DlgCustomCommandsImp( QWidget* parent ) for (std::map::iterator it = sCommands.begin(); it != sCommands.end(); ++it) { QLatin1String group(it->second->getGroupName()); - QString text = qApp->translate(it->second->className(), it->second->getGroupName()); + QString text = it->second->translatedGroupName(); GroupMap::iterator jt; jt = std::find_if(groupMap.begin(), groupMap.end(), GroupMap_find(group)); if (jt != groupMap.end()) { @@ -263,7 +263,7 @@ void DlgCustomCommandsImp::changeEvent(QEvent *e) QVariant data = (*it)->data(0, Qt::UserRole); std::vector aCmds = cCmdMgr.getGroupCommands(data.toByteArray()); if (!aCmds.empty()) { - QString text = qApp->translate(aCmds[0]->className(), aCmds[0]->getGroupName()); + QString text = aCmds[0]->translatedGroupName(); (*it)->setText(0, text); } ++it; diff --git a/src/Gui/DlgCustomizeSpaceball.cpp b/src/Gui/DlgCustomizeSpaceball.cpp index ae8296d5e5..dad8999c7f 100644 --- a/src/Gui/DlgCustomizeSpaceball.cpp +++ b/src/Gui/DlgCustomizeSpaceball.cpp @@ -422,7 +422,7 @@ QVariant CommandModel::data(const QModelIndex &index, int role) const if (node->children.size() < 1) return QVariant(); CommandNode *childNode = node->children.at(0); - return QVariant(qApp->translate(childNode->aCommand->className(), childNode->aCommand->getGroupName())); + return QVariant(childNode->aCommand->translatedGroupName()); } return QVariant(); } diff --git a/src/Gui/DlgKeyboardImp.cpp b/src/Gui/DlgKeyboardImp.cpp index 44e1c47af9..f993a687eb 100644 --- a/src/Gui/DlgKeyboardImp.cpp +++ b/src/Gui/DlgKeyboardImp.cpp @@ -86,7 +86,7 @@ DlgCustomKeyboardImp::DlgCustomKeyboardImp( QWidget* parent ) for (std::map::iterator it = sCommands.begin(); it != sCommands.end(); ++it) { QLatin1String group(it->second->getGroupName()); - QString text = qApp->translate(it->second->className(), it->second->getGroupName()); + QString text = it->second->translatedGroupName(); GroupMap::iterator jt; jt = std::find_if(groupMap.begin(), groupMap.end(), GroupMap_find(group)); if (jt != groupMap.end()) { @@ -484,7 +484,7 @@ void DlgCustomKeyboardImp::changeEvent(QEvent *e) QVariant data = ui->categoryBox->itemData(i, Qt::UserRole); std::vector aCmds = cCmdMgr.getGroupCommands(data.toByteArray()); if (!aCmds.empty()) { - QString text = qApp->translate(aCmds[0]->className(), aCmds[0]->getGroupName()); + QString text = aCmds[0]->translatedGroupName(); ui->categoryBox->setItemText(i, text); } } diff --git a/src/Gui/DlgToolbarsImp.cpp b/src/Gui/DlgToolbarsImp.cpp index 85df18d71b..bf7f43a59a 100644 --- a/src/Gui/DlgToolbarsImp.cpp +++ b/src/Gui/DlgToolbarsImp.cpp @@ -93,7 +93,7 @@ DlgCustomToolbars::DlgCustomToolbars(DlgCustomToolbars::Type t, QWidget* parent) for (std::map::iterator it = sCommands.begin(); it != sCommands.end(); ++it) { QLatin1String group(it->second->getGroupName()); - QString text = qApp->translate(it->second->className(), it->second->getGroupName()); + QString text = it->second->translatedGroupName(); GroupMap::iterator jt; jt = std::find_if(groupMap.begin(), groupMap.end(), GroupMap_find(group)); if (jt != groupMap.end()) { @@ -642,7 +642,7 @@ void DlgCustomToolbars::changeEvent(QEvent *e) QVariant data = ui->categoryBox->itemData(i, Qt::UserRole); std::vector aCmds = cCmdMgr.getGroupCommands(data.toByteArray()); if (!aCmds.empty()) { - QString text = qApp->translate(aCmds[0]->className(), aCmds[0]->getGroupName()); + QString text = aCmds[0]->translatedGroupName(); ui->categoryBox->setItemText(i, text); } }