Gui: add convenience function Command::translatedGroupName()

This commit is contained in:
wmayer
2021-09-29 15:25:46 +02:00
parent d06bee745b
commit bc57ba6027
6 changed files with 18 additions and 7 deletions

View File

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

View File

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

View File

@@ -93,7 +93,7 @@ DlgCustomCommandsImp::DlgCustomCommandsImp( QWidget* parent )
for (std::map<std::string,Command*>::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<Command*> 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;

View File

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

View File

@@ -86,7 +86,7 @@ DlgCustomKeyboardImp::DlgCustomKeyboardImp( QWidget* parent )
for (std::map<std::string,Command*>::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<Command*> 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);
}
}

View File

@@ -93,7 +93,7 @@ DlgCustomToolbars::DlgCustomToolbars(DlgCustomToolbars::Type t, QWidget* parent)
for (std::map<std::string,Command*>::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<Command*> 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);
}
}