mirror of
https://github.com/LMMS/lmms.git
synced 2026-05-17 11:18:30 -04:00
Fix decimal separator handling (#4547)
Makes LMMS can handle both periods and commas properly when loading real numbers.
This commit is contained in:
@@ -38,6 +38,7 @@
|
||||
#include "Effect.h"
|
||||
#include "embed.h"
|
||||
#include "GuiApplication.h"
|
||||
#include "LocaleHelper.h"
|
||||
#include "PluginFactory.h"
|
||||
#include "ProjectVersion.h"
|
||||
#include "SongEditor.h"
|
||||
@@ -65,37 +66,6 @@ DataFile::typeDescStruct
|
||||
|
||||
|
||||
|
||||
DataFile::LocaleHelper::LocaleHelper( Mode mode )
|
||||
{
|
||||
switch( mode )
|
||||
{
|
||||
case ModeLoad:
|
||||
// set a locale for which QString::fromFloat() returns valid values if
|
||||
// floating point separator is a comma - otherwise we would fail to load
|
||||
// older projects made by people from various countries due to their
|
||||
// locale settings
|
||||
QLocale::setDefault( QLocale::German );
|
||||
break;
|
||||
|
||||
case ModeSave:
|
||||
// set default locale to C so that floating point decimals are rendered to
|
||||
// strings with periods as decimal point instead of commas in some countries
|
||||
QLocale::setDefault( QLocale::C );
|
||||
|
||||
default: break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
DataFile::LocaleHelper::~LocaleHelper()
|
||||
{
|
||||
// revert to original locale
|
||||
QLocale::setDefault( QLocale::system() );
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
DataFile::DataFile( Type type ) :
|
||||
QDomDocument( "lmms-project" ),
|
||||
@@ -416,8 +386,8 @@ void DataFile::upgrade_0_2_1_20070501()
|
||||
QDomElement el = list.item( i ).toElement();
|
||||
if( el.attribute( "vol" ) != "" )
|
||||
{
|
||||
el.setAttribute( "vol", el.attribute(
|
||||
"vol" ).toFloat() * 100.0f );
|
||||
el.setAttribute( "vol", LocaleHelper::toFloat(
|
||||
el.attribute( "vol" ) ) * 100.0f );
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -543,7 +513,7 @@ void DataFile::upgrade_0_2_1_20070508()
|
||||
QDomElement el = list.item( i ).toElement();
|
||||
if( el.hasAttribute( "vol" ) )
|
||||
{
|
||||
float value = el.attribute( "vol" ).toFloat();
|
||||
float value = LocaleHelper::toFloat( el.attribute( "vol" ) );
|
||||
value = roundf( value * 0.585786438f );
|
||||
el.setAttribute( "vol", value );
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user