Skip to content

Commit d0813a8

Browse files
borysiastynyalldawson
authored andcommitted
Introduce QgsGui::HigFlags and don't capitalize menu entries and dialog titles in languages other than English. Fixes #19724
1 parent 0bd1b7a commit d0813a8

File tree

5 files changed

+62
-6
lines changed

5 files changed

+62
-6
lines changed

python/gui/auto_generated/qgsgui.sip.in

+18
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,21 @@ Sets the global window ``manager``. Ownership is transferred to the QgsGui insta
9797

9898
.. seealso:: :py:func:`windowManager`
9999

100+
.. versionadded:: 3.4
101+
%End
102+
103+
enum HigFlag
104+
{
105+
HigMenuTextIsTitleCase,
106+
HigDialogTitleIsTitleCase
107+
};
108+
typedef QFlags<QgsGui::HigFlag> HigFlags;
109+
110+
111+
static QgsGui::HigFlags higFlags();
112+
%Docstring
113+
Returns HIG flags. Currently indicates whether titles should be title case depending on the current locale.
114+
100115
.. versionadded:: 3.4
101116
%End
102117

@@ -106,6 +121,9 @@ Sets the global window ``manager``. Ownership is transferred to the QgsGui insta
106121
QgsGui( const QgsGui &other );
107122
};
108123

124+
QFlags<QgsGui::HigFlag> operator|(QgsGui::HigFlag f1, QFlags<QgsGui::HigFlag> f2);
125+
126+
109127
/************************************************************************
110128
* This file has been generated automatically from *
111129
* *

python/plugins/processing/gui/menus.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
from processing.gui.AlgorithmDialog import AlgorithmDialog
3434
from qgis.utils import iface
3535
from qgis.core import QgsApplication, QgsMessageLog, QgsStringUtils, QgsProcessingAlgorithm
36+
from qgis.gui import QgsGui
3637
from processing.gui.MessageBarProgress import MessageBarProgress
3738
from processing.gui.AlgorithmExecutor import execute
3839
from processing.gui.Postprocessing import handleAlgorithmResults
@@ -183,10 +184,10 @@ def removeMenus():
183184

184185
def addAlgorithmEntry(alg, menuName, submenuName, actionText=None, icon=None, addButton=False):
185186
if actionText is None:
186-
if alg.flags() & QgsProcessingAlgorithm.FlagDisplayNameIsLiteral:
187-
alg_title = alg.displayName()
188-
else:
187+
if (QgsGui.higFlags() & QgsGui.HigMenuTextIsTitleCase) and not (alg.flags() & QgsProcessingAlgorithm.FlagDisplayNameIsLiteral):
189188
alg_title = QgsStringUtils.capitalize(alg.displayName(), QgsStringUtils.TitleCase)
189+
else:
190+
alg_title = alg.displayName()
190191
actionText = alg_title + QCoreApplication.translate('Processing', '…')
191192
action = QAction(icon or alg.icon(), actionText, iface.mainWindow())
192193
alg_id = alg.id()

src/gui/processing/qgsprocessingalgorithmdialogbase.cpp

+7-3
Original file line numberDiff line numberDiff line change
@@ -123,10 +123,14 @@ void QgsProcessingAlgorithmDialogBase::setAlgorithm( QgsProcessingAlgorithm *alg
123123
{
124124
mAlgorithm = algorithm;
125125
QString title;
126-
if ( algorithm->flags() & QgsProcessingAlgorithm::FlagDisplayNameIsLiteral )
127-
title = mAlgorithm->displayName();
128-
else
126+
if ( ( QgsGui::higFlags() & QgsGui::HigDialogTitleIsTitleCase ) and !( algorithm->flags() & QgsProcessingAlgorithm::FlagDisplayNameIsLiteral ) )
127+
{
129128
title = QgsStringUtils::capitalize( mAlgorithm->displayName(), QgsStringUtils::TitleCase );
129+
}
130+
else
131+
{
132+
title = mAlgorithm->displayName();
133+
}
130134
setWindowTitle( title );
131135

132136
QString algHelp = formatHelp( algorithm );

src/gui/qgsgui.cpp

+14
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
#include "qgslogger.h"
4343
#include "qgsprocessingrecentalgorithmlog.h"
4444
#include "qgswindowmanagerinterface.h"
45+
#include "qgssettings.h"
4546

4647
QgsGui *QgsGui::instance()
4748
{
@@ -113,6 +114,19 @@ void QgsGui::setWindowManager( QgsWindowManagerInterface *manager )
113114
instance()->mWindowManager.reset( manager );
114115
}
115116

117+
QgsGui::HigFlags QgsGui::higFlags()
118+
{
119+
QgsSettings settings;
120+
if ( settings.value( QStringLiteral( "locale/userLocale" ), "" ).toString().startsWith( "en" ) )
121+
{
122+
return HigMenuTextIsTitleCase | HigDialogTitleIsTitleCase;
123+
}
124+
else
125+
{
126+
return NULL;
127+
}
128+
}
129+
116130
QgsGui::~QgsGui()
117131
{
118132
delete mProcessingGuiRegistry;

src/gui/qgsgui.h

+19
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,23 @@ class GUI_EXPORT QgsGui
125125
*/
126126
static void setWindowManager( QgsWindowManagerInterface *manager SIP_TRANSFER );
127127

128+
/**
129+
* HIG flags. Currently indicate whether titles should be title case depending on the current locale.
130+
* \since QGIS 3.4
131+
*/
132+
enum HigFlag
133+
{
134+
HigMenuTextIsTitleCase = 1 << 0, //!< Menu action texts should be title case
135+
HigDialogTitleIsTitleCase = 1 << 1 //!< Dialog titles should be title case
136+
};
137+
Q_DECLARE_FLAGS( HigFlags, HigFlag )
138+
139+
/**
140+
* Returns HIG flags. Currently indicates whether titles should be title case depending on the current locale.
141+
* \since QGIS 3.4
142+
*/
143+
static QgsGui::HigFlags higFlags();
144+
128145
~QgsGui();
129146

130147
private:
@@ -149,4 +166,6 @@ class GUI_EXPORT QgsGui
149166

150167
};
151168

169+
Q_DECLARE_OPERATORS_FOR_FLAGS( QgsGui::HigFlags )
170+
152171
#endif // QGSGUI_H

0 commit comments

Comments
 (0)