Skip to content
Permalink
Browse files

Introduce QgsGui::HigFlags and don't capitalize menu entries and dial…

…og titles in languages other than English. Fixes #19724
  • Loading branch information
borysiasty authored and nyalldawson committed Oct 24, 2018
1 parent 0bd1b7a commit d0813a88229372069c64dc868c813f4e6848a1df
@@ -97,6 +97,21 @@ Sets the global window ``manager``. Ownership is transferred to the QgsGui insta

.. seealso:: :py:func:`windowManager`

.. versionadded:: 3.4
%End

enum HigFlag
{
HigMenuTextIsTitleCase,
HigDialogTitleIsTitleCase
};
typedef QFlags<QgsGui::HigFlag> HigFlags;


static QgsGui::HigFlags higFlags();
%Docstring
Returns HIG flags. Currently indicates whether titles should be title case depending on the current locale.

.. versionadded:: 3.4
%End

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

QFlags<QgsGui::HigFlag> operator|(QgsGui::HigFlag f1, QFlags<QgsGui::HigFlag> f2);


/************************************************************************
* This file has been generated automatically from *
* *
@@ -33,6 +33,7 @@
from processing.gui.AlgorithmDialog import AlgorithmDialog
from qgis.utils import iface
from qgis.core import QgsApplication, QgsMessageLog, QgsStringUtils, QgsProcessingAlgorithm
from qgis.gui import QgsGui
from processing.gui.MessageBarProgress import MessageBarProgress
from processing.gui.AlgorithmExecutor import execute
from processing.gui.Postprocessing import handleAlgorithmResults
@@ -183,10 +184,10 @@ def removeMenus():

def addAlgorithmEntry(alg, menuName, submenuName, actionText=None, icon=None, addButton=False):
if actionText is None:
if alg.flags() & QgsProcessingAlgorithm.FlagDisplayNameIsLiteral:
alg_title = alg.displayName()
else:
if (QgsGui.higFlags() & QgsGui.HigMenuTextIsTitleCase) and not (alg.flags() & QgsProcessingAlgorithm.FlagDisplayNameIsLiteral):
alg_title = QgsStringUtils.capitalize(alg.displayName(), QgsStringUtils.TitleCase)
else:
alg_title = alg.displayName()
actionText = alg_title + QCoreApplication.translate('Processing', '…')
action = QAction(icon or alg.icon(), actionText, iface.mainWindow())
alg_id = alg.id()
@@ -123,10 +123,14 @@ void QgsProcessingAlgorithmDialogBase::setAlgorithm( QgsProcessingAlgorithm *alg
{
mAlgorithm = algorithm;
QString title;
if ( algorithm->flags() & QgsProcessingAlgorithm::FlagDisplayNameIsLiteral )
title = mAlgorithm->displayName();
else
if ( ( QgsGui::higFlags() & QgsGui::HigDialogTitleIsTitleCase ) and !( algorithm->flags() & QgsProcessingAlgorithm::FlagDisplayNameIsLiteral ) )
{
title = QgsStringUtils::capitalize( mAlgorithm->displayName(), QgsStringUtils::TitleCase );
}
else
{
title = mAlgorithm->displayName();
}
setWindowTitle( title );

QString algHelp = formatHelp( algorithm );
@@ -42,6 +42,7 @@
#include "qgslogger.h"
#include "qgsprocessingrecentalgorithmlog.h"
#include "qgswindowmanagerinterface.h"
#include "qgssettings.h"

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

QgsGui::HigFlags QgsGui::higFlags()
{
QgsSettings settings;
if ( settings.value( QStringLiteral( "locale/userLocale" ), "" ).toString().startsWith( "en" ) )
{
return HigMenuTextIsTitleCase | HigDialogTitleIsTitleCase;
}
else
{
return NULL;
}
}

QgsGui::~QgsGui()
{
delete mProcessingGuiRegistry;
@@ -125,6 +125,23 @@ class GUI_EXPORT QgsGui
*/
static void setWindowManager( QgsWindowManagerInterface *manager SIP_TRANSFER );

/**
* HIG flags. Currently indicate whether titles should be title case depending on the current locale.
* \since QGIS 3.4
*/
enum HigFlag
{
HigMenuTextIsTitleCase = 1 << 0, //!< Menu action texts should be title case
HigDialogTitleIsTitleCase = 1 << 1 //!< Dialog titles should be title case
};
Q_DECLARE_FLAGS( HigFlags, HigFlag )

/**
* Returns HIG flags. Currently indicates whether titles should be title case depending on the current locale.
* \since QGIS 3.4
*/
static QgsGui::HigFlags higFlags();

~QgsGui();

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

};

Q_DECLARE_OPERATORS_FOR_FLAGS( QgsGui::HigFlags )

#endif // QGSGUI_H

0 comments on commit d0813a8

Please sign in to comment.
You can’t perform that action at this time.