Skip to content

Commit

Permalink
Introduce QgsGui::HigFlags and don't capitalize menu entries and dial…
Browse files Browse the repository at this point in the history
…og titles in languages other than English. Fixes #19724
  • Loading branch information
borysiasty authored and nyalldawson committed Oct 25, 2018
1 parent 0bd1b7a commit d0813a8
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 6 deletions.
18 changes: 18 additions & 0 deletions python/gui/auto_generated/qgsgui.sip.in
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -97,6 +97,21 @@ Sets the global window ``manager``. Ownership is transferred to the QgsGui insta


.. seealso:: :py:func:`windowManager` .. 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 .. versionadded:: 3.4
%End %End


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


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


/************************************************************************ /************************************************************************
* This file has been generated automatically from * * This file has been generated automatically from *
* * * *
Expand Down
7 changes: 4 additions & 3 deletions python/plugins/processing/gui/menus.py
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
from processing.gui.AlgorithmDialog import AlgorithmDialog from processing.gui.AlgorithmDialog import AlgorithmDialog
from qgis.utils import iface from qgis.utils import iface
from qgis.core import QgsApplication, QgsMessageLog, QgsStringUtils, QgsProcessingAlgorithm from qgis.core import QgsApplication, QgsMessageLog, QgsStringUtils, QgsProcessingAlgorithm
from qgis.gui import QgsGui
from processing.gui.MessageBarProgress import MessageBarProgress from processing.gui.MessageBarProgress import MessageBarProgress
from processing.gui.AlgorithmExecutor import execute from processing.gui.AlgorithmExecutor import execute
from processing.gui.Postprocessing import handleAlgorithmResults from processing.gui.Postprocessing import handleAlgorithmResults
Expand Down Expand Up @@ -183,10 +184,10 @@ def removeMenus():


def addAlgorithmEntry(alg, menuName, submenuName, actionText=None, icon=None, addButton=False): def addAlgorithmEntry(alg, menuName, submenuName, actionText=None, icon=None, addButton=False):
if actionText is None: if actionText is None:
if alg.flags() & QgsProcessingAlgorithm.FlagDisplayNameIsLiteral: if (QgsGui.higFlags() & QgsGui.HigMenuTextIsTitleCase) and not (alg.flags() & QgsProcessingAlgorithm.FlagDisplayNameIsLiteral):
alg_title = alg.displayName()
else:
alg_title = QgsStringUtils.capitalize(alg.displayName(), QgsStringUtils.TitleCase) alg_title = QgsStringUtils.capitalize(alg.displayName(), QgsStringUtils.TitleCase)
else:
alg_title = alg.displayName()
actionText = alg_title + QCoreApplication.translate('Processing', '…') actionText = alg_title + QCoreApplication.translate('Processing', '…')
action = QAction(icon or alg.icon(), actionText, iface.mainWindow()) action = QAction(icon or alg.icon(), actionText, iface.mainWindow())
alg_id = alg.id() alg_id = alg.id()
Expand Down
10 changes: 7 additions & 3 deletions src/gui/processing/qgsprocessingalgorithmdialogbase.cpp
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -123,10 +123,14 @@ void QgsProcessingAlgorithmDialogBase::setAlgorithm( QgsProcessingAlgorithm *alg
{ {
mAlgorithm = algorithm; mAlgorithm = algorithm;
QString title; QString title;
if ( algorithm->flags() & QgsProcessingAlgorithm::FlagDisplayNameIsLiteral ) if ( ( QgsGui::higFlags() & QgsGui::HigDialogTitleIsTitleCase ) and !( algorithm->flags() & QgsProcessingAlgorithm::FlagDisplayNameIsLiteral ) )
title = mAlgorithm->displayName(); {
else
title = QgsStringUtils::capitalize( mAlgorithm->displayName(), QgsStringUtils::TitleCase ); title = QgsStringUtils::capitalize( mAlgorithm->displayName(), QgsStringUtils::TitleCase );
}
else
{
title = mAlgorithm->displayName();
}
setWindowTitle( title ); setWindowTitle( title );


QString algHelp = formatHelp( algorithm ); QString algHelp = formatHelp( algorithm );
Expand Down
14 changes: 14 additions & 0 deletions src/gui/qgsgui.cpp
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
#include "qgslogger.h" #include "qgslogger.h"
#include "qgsprocessingrecentalgorithmlog.h" #include "qgsprocessingrecentalgorithmlog.h"
#include "qgswindowmanagerinterface.h" #include "qgswindowmanagerinterface.h"
#include "qgssettings.h"


QgsGui *QgsGui::instance() QgsGui *QgsGui::instance()
{ {
Expand Down Expand Up @@ -113,6 +114,19 @@ void QgsGui::setWindowManager( QgsWindowManagerInterface *manager )
instance()->mWindowManager.reset( 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() QgsGui::~QgsGui()
{ {
delete mProcessingGuiRegistry; delete mProcessingGuiRegistry;
Expand Down
19 changes: 19 additions & 0 deletions src/gui/qgsgui.h
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -125,6 +125,23 @@ class GUI_EXPORT QgsGui
*/ */
static void setWindowManager( QgsWindowManagerInterface *manager SIP_TRANSFER ); 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(); ~QgsGui();


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


}; };


Q_DECLARE_OPERATORS_FOR_FLAGS( QgsGui::HigFlags )

#endif // QGSGUI_H #endif // QGSGUI_H

0 comments on commit d0813a8

Please sign in to comment.