Skip to content
Permalink
Browse files

Merge pull request #7357 from elpaso/locale-options-backport

Locale options backport
  • Loading branch information
elpaso committed Jul 3, 2018
2 parents 1c5c9de + ed0f340 commit ee81016ebd603f3c786f3dabe2d3c726c3f62f7b
Showing with 175 additions and 70 deletions.
  1. +32 −3 src/app/main.cpp
  2. +80 −34 src/app/qgsoptions.cpp
  3. +2 −0 src/app/qgsoptions.h
  4. +61 −33 src/ui/qgsoptionsbase.ui
@@ -1142,9 +1142,18 @@ int main( int argc, char *argv[] )
/* Translation file for QGIS.
*/
QString i18nPath = QgsApplication::i18nPath();
QString myUserLocale = mySettings.value( QStringLiteral( "locale/userLocale" ), "" ).toString();
QString myUserTranslation = mySettings.value( QStringLiteral( "locale/userLocale" ), "" ).toString();
QString myGlobalLocale = mySettings.value( QStringLiteral( "locale/globalLocale" ), "" ).toString();
bool myShowGroupSeparatorFlag = false; // Default to false
bool myLocaleOverrideFlag = mySettings.value( QStringLiteral( "locale/overrideFlag" ), false ).toBool();

// Override Show Group Separator if the global override flag is set
if ( myLocaleOverrideFlag )
{
// Default to false again
myShowGroupSeparatorFlag = mySettings.value( QStringLiteral( "locale/showGroupSeparator" ), false ).toBool();
}

//
// Priority of translation is:
// - command line
@@ -1160,7 +1169,7 @@ int main( int argc, char *argv[] )
}
else
{
if ( !myLocaleOverrideFlag || myUserLocale.isEmpty() )
if ( !myLocaleOverrideFlag || myUserTranslation.isEmpty() )
{
myTranslationCode = QLocale().name();
//setting the locale/userLocale when the --lang= option is not set will allow third party
@@ -1169,10 +1178,30 @@ int main( int argc, char *argv[] )
}
else
{
myTranslationCode = myUserLocale;
myTranslationCode = myUserTranslation;
}
}

// Global locale settings
if ( myLocaleOverrideFlag && ! myGlobalLocale.isEmpty( ) )
{
QLocale currentLocale( myGlobalLocale );
QLocale::setDefault( currentLocale );
}

// Number settings
QLocale currentLocale;
if ( myShowGroupSeparatorFlag )
{
currentLocale.setNumberOptions( currentLocale.numberOptions() &= ~QLocale::NumberOption::OmitGroupSeparator );
}
else
{
currentLocale.setNumberOptions( currentLocale.numberOptions() |= QLocale::NumberOption::OmitGroupSeparator );
}
QLocale::setDefault( currentLocale );


QTranslator qgistor( nullptr );
QTranslator qttor( nullptr );
if ( myTranslationCode != QLatin1String( "C" ) )
@@ -96,6 +96,8 @@ QgsOptions::QgsOptions( QWidget *parent, Qt::WindowFlags fl, const QList<QgsOpti
connect( mCustomVariablesChkBx, &QCheckBox::toggled, this, &QgsOptions::mCustomVariablesChkBx_toggled );
connect( mCurrentVariablesQGISChxBx, &QCheckBox::toggled, this, &QgsOptions::mCurrentVariablesQGISChxBx_toggled );
connect( buttonBox, &QDialogButtonBox::helpRequested, this, &QgsOptions::showHelp );
connect( cboGlobalLocale, qgis::overload< int >::of( &QComboBox::currentIndexChanged ), [ = ]( int ) { updateSampleLocaleText( ); } );
connect( cbShowGroupSeparator, &QCheckBox::toggled, this, [ = ]( bool ) { updateSampleLocaleText(); } );

// QgsOptionsDialogBase handles saving/restoring of geometry, splitter and current tab states,
// switching vertical tabs between icon/text to icon-only modes (splitter collapsed to left),
@@ -672,30 +674,30 @@ QgsOptions::QgsOptions( QWidget *parent, Qt::WindowFlags fl, const QList<QgsOpti
mRasterCumulativeCutUpperDoubleSpinBox->setValue( 100.0 * mSettings->value( QStringLiteral( "/Raster/cumulativeCutUpper" ), QString::number( QgsRasterMinMaxOrigin::CUMULATIVE_CUT_UPPER ) ).toDouble() );

//set the color for selections
int myRed = mSettings->value( QStringLiteral( "/qgis/default_selection_color_red" ), 255 ).toInt();
int myGreen = mSettings->value( QStringLiteral( "/qgis/default_selection_color_green" ), 255 ).toInt();
int myBlue = mSettings->value( QStringLiteral( "/qgis/default_selection_color_blue" ), 0 ).toInt();
int myAlpha = mSettings->value( QStringLiteral( "/qgis/default_selection_color_alpha" ), 255 ).toInt();
pbnSelectionColor->setColor( QColor( myRed, myGreen, myBlue, myAlpha ) );
int red = mSettings->value( QStringLiteral( "/qgis/default_selection_color_red" ), 255 ).toInt();
int green = mSettings->value( QStringLiteral( "/qgis/default_selection_color_green" ), 255 ).toInt();
int blue = mSettings->value( QStringLiteral( "/qgis/default_selection_color_blue" ), 0 ).toInt();
int alpha = mSettings->value( QStringLiteral( "/qgis/default_selection_color_alpha" ), 255 ).toInt();
pbnSelectionColor->setColor( QColor( red, green, blue, alpha ) );
pbnSelectionColor->setColorDialogTitle( tr( "Set Selection Color" ) );
pbnSelectionColor->setAllowOpacity( true );
pbnSelectionColor->setContext( QStringLiteral( "gui" ) );
pbnSelectionColor->setDefaultColor( QColor( 255, 255, 0, 255 ) );

//set the default color for canvas background
myRed = mSettings->value( QStringLiteral( "/qgis/default_canvas_color_red" ), 255 ).toInt();
myGreen = mSettings->value( QStringLiteral( "/qgis/default_canvas_color_green" ), 255 ).toInt();
myBlue = mSettings->value( QStringLiteral( "/qgis/default_canvas_color_blue" ), 255 ).toInt();
pbnCanvasColor->setColor( QColor( myRed, myGreen, myBlue ) );
red = mSettings->value( QStringLiteral( "/qgis/default_canvas_color_red" ), 255 ).toInt();
green = mSettings->value( QStringLiteral( "/qgis/default_canvas_color_green" ), 255 ).toInt();
blue = mSettings->value( QStringLiteral( "/qgis/default_canvas_color_blue" ), 255 ).toInt();
pbnCanvasColor->setColor( QColor( red, green, blue ) );
pbnCanvasColor->setColorDialogTitle( tr( "Set Canvas Color" ) );
pbnCanvasColor->setContext( QStringLiteral( "gui" ) );
pbnCanvasColor->setDefaultColor( Qt::white );

// set the default color for the measure tool
myRed = mSettings->value( QStringLiteral( "/qgis/default_measure_color_red" ), 222 ).toInt();
myGreen = mSettings->value( QStringLiteral( "/qgis/default_measure_color_green" ), 155 ).toInt();
myBlue = mSettings->value( QStringLiteral( "/qgis/default_measure_color_blue" ), 67 ).toInt();
pbnMeasureColor->setColor( QColor( myRed, myGreen, myBlue ) );
red = mSettings->value( QStringLiteral( "/qgis/default_measure_color_red" ), 222 ).toInt();
green = mSettings->value( QStringLiteral( "/qgis/default_measure_color_green" ), 155 ).toInt();
blue = mSettings->value( QStringLiteral( "/qgis/default_measure_color_blue" ), 67 ).toInt();
pbnMeasureColor->setColor( QColor( red, green, blue ) );
pbnMeasureColor->setColorDialogTitle( tr( "Set Measuring Tool Color" ) );
pbnMeasureColor->setContext( QStringLiteral( "gui" ) );
pbnMeasureColor->setDefaultColor( QColor( 222, 155, 67 ) );
@@ -901,38 +903,60 @@ QgsOptions::QgsOptions( QWidget *parent, Qt::WindowFlags fl, const QList<QgsOpti
mOffsetYSpinBox->setValue( mSettings->value( QStringLiteral( "LayoutDesigner/defaultSnapGridOffsetY" ), 0, QgsSettings::Gui ).toDouble() );

//
// Locale settings
// Translation and locale settings
//
QString mySystemLocale = QLocale().name();
lblSystemLocale->setText( tr( "Detected active locale on your system: %1" ).arg( mySystemLocale ) );
QString myUserLocale = mSettings->value( QStringLiteral( "locale/userLocale" ), QString() ).toString();
QStringList myI18nList = i18nList();
Q_FOREACH ( const QString &l, myI18nList )
QString currentLocale = QLocale().name();
lblSystemLocale->setText( tr( "Detected active locale on your system: %1" ).arg( currentLocale ) );
QString userLocale = mSettings->value( QStringLiteral( "locale/userLocale" ), QString( ) ).toString();
bool showGroupSeparator = mSettings->value( QStringLiteral( "locale/showGroupSeparator" ), false ).toBool();
QString globalLocale = mSettings->value( QStringLiteral( "locale/globalLocale" ), currentLocale ).toString();
const QStringList language18nList( i18nList() );
for ( const auto &l : language18nList )
{
// QTBUG-57802: eo locale is improperly handled
QString displayName = l.startsWith( QLatin1String( "eo" ) ) ? QLocale::languageToString( QLocale::Esperanto ) : QLocale( l ).nativeLanguageName();
cboLocale->addItem( QIcon( QString( ":/images/flags/%1.svg" ).arg( l ) ), displayName, l );
cboTranslation->addItem( QIcon( QString( ":/images/flags/%1.svg" ).arg( l ) ), displayName, l );
}
cboLocale->setCurrentIndex( cboLocale->findData( myUserLocale ) );
bool myLocaleOverrideFlag = mSettings->value( QStringLiteral( "locale/overrideFlag" ), false ).toBool();
grpLocale->setChecked( myLocaleOverrideFlag );

const QList<QLocale> allLocales = QLocale::matchingLocales(
QLocale::AnyLanguage,
QLocale::AnyScript,
QLocale::AnyCountry );

QSet<QString> addedLocales;
for ( const auto &l : allLocales )
{
// Do not add duplicates (like en_US)
if ( ! addedLocales.contains( l.name() ) )
{
cboGlobalLocale->addItem( QStringLiteral( "%1 %2 (%3)" ).arg( QLocale::languageToString( l.language() ), QLocale::countryToString( l.country() ), l.name() ), l.name() );
addedLocales.insert( l.name() );
}
}

cboTranslation->setCurrentIndex( cboTranslation->findData( userLocale ) );
cboGlobalLocale->setCurrentIndex( cboGlobalLocale->findData( globalLocale ) );
bool localeOverrideFlag = mSettings->value( QStringLiteral( "locale/overrideFlag" ), false ).toBool();
grpLocale->setChecked( localeOverrideFlag );
cbShowGroupSeparator->setChecked( showGroupSeparator );


//set elements in digitizing tab
mLineWidthSpinBox->setValue( mSettings->value( QStringLiteral( "/qgis/digitizing/line_width" ), 1 ).toInt() );
myRed = mSettings->value( QStringLiteral( "/qgis/digitizing/line_color_red" ), 255 ).toInt();
myGreen = mSettings->value( QStringLiteral( "/qgis/digitizing/line_color_green" ), 0 ).toInt();
myBlue = mSettings->value( QStringLiteral( "/qgis/digitizing/line_color_blue" ), 0 ).toInt();
myAlpha = mSettings->value( QStringLiteral( "/qgis/digitizing/line_color_alpha" ), 200 ).toInt();
mLineColorToolButton->setColor( QColor( myRed, myGreen, myBlue, myAlpha ) );
red = mSettings->value( QStringLiteral( "/qgis/digitizing/line_color_red" ), 255 ).toInt();
green = mSettings->value( QStringLiteral( "/qgis/digitizing/line_color_green" ), 0 ).toInt();
blue = mSettings->value( QStringLiteral( "/qgis/digitizing/line_color_blue" ), 0 ).toInt();
alpha = mSettings->value( QStringLiteral( "/qgis/digitizing/line_color_alpha" ), 200 ).toInt();
mLineColorToolButton->setColor( QColor( red, green, blue, alpha ) );
mLineColorToolButton->setAllowOpacity( true );
mLineColorToolButton->setContext( QStringLiteral( "gui" ) );
mLineColorToolButton->setDefaultColor( QColor( 255, 0, 0, 200 ) );

myRed = mSettings->value( QStringLiteral( "/qgis/digitizing/fill_color_red" ), 255 ).toInt();
myGreen = mSettings->value( QStringLiteral( "/qgis/digitizing/fill_color_green" ), 0 ).toInt();
myBlue = mSettings->value( QStringLiteral( "/qgis/digitizing/fill_color_blue" ), 0 ).toInt();
myAlpha = mSettings->value( QStringLiteral( "/qgis/digitizing/fill_color_alpha" ), 30 ).toInt();
mFillColorToolButton->setColor( QColor( myRed, myGreen, myBlue, myAlpha ) );
red = mSettings->value( QStringLiteral( "/qgis/digitizing/fill_color_red" ), 255 ).toInt();
green = mSettings->value( QStringLiteral( "/qgis/digitizing/fill_color_green" ), 0 ).toInt();
blue = mSettings->value( QStringLiteral( "/qgis/digitizing/fill_color_blue" ), 0 ).toInt();
alpha = mSettings->value( QStringLiteral( "/qgis/digitizing/fill_color_alpha" ), 30 ).toInt();
mFillColorToolButton->setColor( QColor( red, green, blue, alpha ) );
mFillColorToolButton->setAllowOpacity( true );
mFillColorToolButton->setContext( QStringLiteral( "gui" ) );
mFillColorToolButton->setDefaultColor( QColor( 255, 0, 0, 30 ) );
@@ -1586,8 +1610,12 @@ void QgsOptions::saveOptions()
//
// Locale settings
//
mSettings->setValue( QStringLiteral( "locale/userLocale" ), cboLocale->currentData().toString() );
mSettings->setValue( QStringLiteral( "locale/userLocale" ), cboTranslation->currentData().toString() );
mSettings->setValue( QStringLiteral( "locale/overrideFlag" ), grpLocale->isChecked() );
mSettings->setValue( QStringLiteral( "locale/globalLocale" ), cboGlobalLocale->currentData( ).toString() );

// Number settings
mSettings->setValue( QStringLiteral( "locale/showGroupSeparator" ), cbShowGroupSeparator->isChecked( ) );

// Gdal skip driver list
if ( mLoadedGdalDriverList )
@@ -2355,6 +2383,24 @@ void QgsOptions::refreshSchemeComboBox()
mColorSchemesComboBox->blockSignals( false );
}

void QgsOptions::updateSampleLocaleText()
{
QLocale locale( cboGlobalLocale->currentData( ).toString() );
if ( cbShowGroupSeparator->isChecked( ) )
{
locale.setNumberOptions( locale.numberOptions() &= ~QLocale::NumberOption::OmitGroupSeparator );
}
else
{
locale.setNumberOptions( locale.numberOptions() |= QLocale::NumberOption::OmitGroupSeparator );
}
lblLocaleSample->setText( tr( "Sample date: %1 money: %2 int: %3 float: %4" ).arg(
QDate::currentDate().toString( locale.dateFormat( QLocale::FormatType::ShortFormat ) ),
locale.toCurrencyString( 1000.00 ),
locale.toString( 1000 ),
locale.toString( 1000.00, 'f', 2 ) ) );
}

void QgsOptions::updateActionsForCurrentColorScheme( QgsColorScheme *scheme )
{
if ( !scheme )
@@ -255,6 +255,8 @@ class APP_EXPORT QgsOptions : public QgsOptionsDialogBase, private Ui::QgsOption

void refreshSchemeComboBox();

void updateSampleLocaleText();

protected:
QgisAppStyleSheet *mStyleSheetBuilder = nullptr;
QMap<QString, QVariant> mStyleSheetNewOpts;

0 comments on commit ee81016

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