-// Copyright (C) 2007-2016 CEA/DEN, EDF R&D, OPEN CASCADE
+// Copyright (C) 2007-2021 CEA/DEN, EDF R&D, OPEN CASCADE
//
// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
#include <QApplication>
#include <QDesktopWidget>
#include <QtDebug>
-#if QT_VERSION > QT_VERSION_CHECK(5, 0, 0)
#include <QSurfaceFormat>
-#endif
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <clocale>
+#ifdef WIN32
+#include <windows.h>
+#define MAX_VALUE_SIZE 32767 // Limit according to http://msdn.microsoft.com/en-us/library/ms683188.aspx
+#endif
+
+#include <iostream>
+
#define BICOLOR_CHANGE_HUE
/*!
*/
QString Qtx::tmpDir()
{
- const char* tmpdir = ::getenv( "TEMP" );
- if ( !tmpdir )
- tmpdir = ::getenv ( "TMP" );
- if ( !tmpdir )
+ QString tmpdir = getenv( "TEMP" );
+ if ( tmpdir.isEmpty() )
+ tmpdir = getenv ( "TMP" );
+ if ( tmpdir.isEmpty() )
{
#ifdef WIN32
- tmpdir = "C:\\";
+ tmpdir = QString("C:\\");
#else
- tmpdir = "/tmp";
+ tmpdir = QString("/tmp");
#endif
}
- return QString( tmpdir );
+ return tmpdir;
}
/*!
char inbuf[512], outbuf[512];
/* convert buffer */
- int nbread = ::fread( inbuf, 1, sizeof( inbuf ), src );
+ int nbread = (int)::fread( inbuf, 1, sizeof( inbuf ), src ); //!< TODO: conversion from 'size_t' to 'int'
for ( int incnt = 0; incnt < nbread; incnt++ )
{
if ( waitingLF )
waitingLF = ( inbuf[nbread - 1] == CR );
/* write converted buffer to temp file */
- int nbwri = ::fwrite( outbuf, 1, outcnt, tgt );
+ int nbwri = (int)::fwrite( outbuf, 1, outcnt, tgt ); //!< TODO: conversion from 'size_t' to 'int'
if ( nbwri != outcnt )
{
::fclose( src );
break;
QString newStr;
- if ( ::getenv( envName.toUtf8() ) || mode == Always )
- newStr = QString( ::getenv( envName.toUtf8() ) );
+ if ( getenv( envName ).isEmpty() || mode == Always )
+ newStr = QString( getenv( envName ) );
if ( newStr.isNull() )
{
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 constructor of the class forces setting "C" locale temporarily.
The destructor switches back to the initial locale.
+ There are two ways to create a localizer.
+ First constructor accepts category and locale value to be forced as parameters.
+ The second constructor does not take parameters, and is just a shortcut to the
+ first one, setting LC_NUMERIC as a category and "C" as a locale to force.
+
\code
Qtx::Localizer loc;
readSomething();
*/
/*!
- \brief Constructor. Forces "C" locale to be set.
+ \brief Default constructor. Forces "C" locale to be set as LC_NUMERIC.
*/
Qtx::Localizer::Localizer()
{
- myCurLocale = setlocale( LC_NUMERIC, 0 );
- setlocale( LC_NUMERIC, "C" );
+ init( LC_NUMERIC, "C" );
+}
+
+/*!
+ \brief Constructor. Forces \a locale to be set for \a category.
+*/
+Qtx::Localizer::Localizer( int category, const char* locale )
+{
+ init( category, locale );
+}
+
+/*!
+ \brief Internal initialization
+ \internal
+*/
+void Qtx::Localizer::init( int category, const char* locale )
+{
+ myCategory = category;
+ myOriginalLocale = setlocale( category, NULL );
+ setlocale( category, locale );
}
/*!
*/
Qtx::Localizer::~Localizer()
{
- setlocale( LC_NUMERIC, myCurLocale.toLatin1().constData() );
+ setlocale( myCategory, myOriginalLocale.toLatin1().constData() );
}
/*!
The function tries to detect qt installation directory by analyzing the system variables in the following order:
- QT5_ROOT_DIR
- - QT4_ROOT_DIR
- QT_ROOT_DIR
- QTDIR
QString Qtx::qtDir( const QString& context )
{
- const char* vars[] = { "QT5_ROOT_DIR", "QT4_ROOT_DIR", "QT_ROOT_DIR", "QTDIR" };
+
+ QStringList vars = { "QT5_ROOT_DIR", "QT_ROOT_DIR", "QTDIR" };
QString qtPath;
- for (uint i = 0; i < sizeof(vars)/sizeof(vars[0]) && qtPath.isEmpty(); i++ )
- qtPath = qgetenv( vars[i] );
+ for (int i = 0; i < vars.length() && qtPath.isEmpty(); i++ ) {
+ qtPath = getenv(vars[i]);
+ }
if ( !qtPath.isEmpty() && !context.isEmpty() )
qtPath = QDir( qtPath ).absoluteFilePath( context );
return qtPath;
return font;
}
+QString Qtx::getenv(const QString & envVar)
+{
+ QString value;
+#ifndef WIN32
+ value = qgetenv(envVar.toLocal8Bit().constData());
+#else
+ LPTSTR buff = new TCHAR[MAX_VALUE_SIZE];
+#ifdef UNICODE
+ LPTSTR anEnvVar = new TCHAR[envVar.length() + 1];
+ anEnvVar[envVar.toWCharArray(anEnvVar)] = '\0';
+#else
+ const TCHAR* anEnvVar = envVar.toLocal8Bit(buff).constData();
+#endif
+ const DWORD ret = GetEnvironmentVariable(anEnvVar, buff, MAX_VALUE_SIZE);
+ buff[ret] = '\0';
+ if (ret > 0) {
+#ifdef UNICODE
+ value = QString::fromWCharArray(buff);
+#else
+ value = QString::fromLocal8Bit(buff);
+#endif
+ }
+ delete buff;
+#ifdef UNICODE
+ delete anEnvVar;
+#endif
+#endif
+ return value;
+}
+
#if !defined WIN32 && !defined __APPLE__
#include <X11/Xlib.h>
#endif // WIN32
-
-#if QT_VERSION > QT_VERSION_CHECK(5, 0, 0)
/*!
\brief Set default QSurfaceFormat for an application.
QSurfaceFormat::setDefaultFormat(fmt);
}
-#endif
/*!
\class Qtx::CmdLineArgs