From: vsr Date: Mon, 1 Nov 2010 14:46:10 +0000 (+0000) Subject: 0021048: [CEA 429] Problem with Dump view in SMESH X-Git-Tag: V5_1_5rc2~6 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=4ee213d449ddf3d70d0438da28d78645d527954d;p=modules%2Fgui.git 0021048: [CEA 429] Problem with Dump view in SMESH --- diff --git a/src/Qtx/Qtx.cxx b/src/Qtx/Qtx.cxx index ded4dd501..a095db966 100755 --- a/src/Qtx/Qtx.cxx +++ b/src/Qtx/Qtx.cxx @@ -1384,6 +1384,45 @@ bool Qtx::stringToConicalGradient( const QString& str, QConicalGradient& gradien return success; } +/*! + \class Qtx::Localizer + \brief Localization helper + + This helper class can be used to solve the localization problems, + usually related to the textual files reading/writing, namely when + floating point values are read / written with API functions. + The problem relates to such locale specific settings as decimal point + separator, thousands separator, etc. + + To use the Localizer class, just create a local variable in the beginning + of the code where you need to read / write data from textual file(s). + The constructor of the class forces setting "C" locale temporariy. + The destructor switches back to the initial locale. + + \code + Qtx::Localizer loc; + readSomething(); + writeSomething(); + \endcode +*/ + +/*! + \brief Constructor. Forces "C" locale to be set. +*/ +Qtx::Localizer::Localizer() +{ + myCurLocale = setlocale( LC_NUMERIC, 0 ); + setlocale( LC_NUMERIC, "C" ); +} + +/*! + \brief Destructor. Reverts back to the initial locale. +*/ +Qtx::Localizer::~Localizer() +{ + setlocale( LC_NUMERIC, myCurLocale.toLatin1().constData() ); +} + #ifndef WIN32 #include diff --git a/src/Qtx/Qtx.h b/src/Qtx/Qtx.h index c5bc82b2d..85784e6ba 100755 --- a/src/Qtx/Qtx.h +++ b/src/Qtx/Qtx.h @@ -113,6 +113,15 @@ public: Auto //!< substitute environment variable by it's value if variable exists, and keep it as is otherwise } SubstMode; + class Localizer + { + public: + Localizer(); + ~Localizer(); + private: + QString myCurLocale; + }; + static QString toQString( const char*, const int = -1 ); static QString toQString( const short*, const int = -1 ); static QString toQString( const unsigned char*, const int = -1 ); diff --git a/src/SUIT/SUIT_ViewWindow.cxx b/src/SUIT/SUIT_ViewWindow.cxx index ebf0055c9..68d27fb67 100755 --- a/src/SUIT/SUIT_ViewWindow.cxx +++ b/src/SUIT/SUIT_ViewWindow.cxx @@ -119,6 +119,7 @@ bool SUIT_ViewWindow::dumpViewToFormat( const QImage& img, const QString& fileNa */ bool SUIT_ViewWindow::dumpViewToFormat( const QString& fileName, const QString& format ) { + Qtx::Localizer loc; return dumpViewToFormat( dumpView(), fileName, format ); } @@ -185,11 +186,12 @@ bool SUIT_ViewWindow::event( QEvent* e ) QString fileName = app->getFileName( false, QString(), filter(), tr( "TLT_DUMP_VIEW" ), 0 ); if ( !fileName.isEmpty() ) { - QString fmt = SUIT_Tools::extension( fileName ).toUpper(); - bOk = dumpViewToFormat( im, fileName, fmt ); + QString fmt = SUIT_Tools::extension( fileName ).toUpper(); + Qtx::Localizer loc; + bOk = dumpViewToFormat( im, fileName, fmt ); } else - bOk = true; // cancelled + bOk = true; // cancelled } if ( !bOk ) SUIT_MessageBox::critical( this, tr( "ERROR" ), tr( "ERR_CANT_DUMP_VIEW" ) );