some code improvements
This commit is contained in:
parent
afe3a77da6
commit
07594d7729
1 changed files with 12 additions and 33 deletions
|
@ -35,9 +35,7 @@ void CSettings::Load()
|
||||||
|
|
||||||
if ( file.open ( QIODevice::ReadOnly ) )
|
if ( file.open ( QIODevice::ReadOnly ) )
|
||||||
{
|
{
|
||||||
QTextStream in ( &file );
|
IniXMLDocument.setContent ( QTextStream ( &file ).readAll(), false );
|
||||||
IniXMLDocument.setContent ( in.readAll(), false );
|
|
||||||
|
|
||||||
file.close();
|
file.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -56,11 +54,10 @@ void CSettings::Save()
|
||||||
// prepare file name for storing initialization data in XML file and store
|
// prepare file name for storing initialization data in XML file and store
|
||||||
// XML data in file
|
// XML data in file
|
||||||
QFile file ( strFileName );
|
QFile file ( strFileName );
|
||||||
|
|
||||||
if ( file.open ( QIODevice::WriteOnly ) )
|
if ( file.open ( QIODevice::WriteOnly ) )
|
||||||
{
|
{
|
||||||
QTextStream out ( &file );
|
QTextStream ( &file ) << IniXMLDocument.toString();
|
||||||
out << IniXMLDocument.toString();
|
|
||||||
|
|
||||||
file.close();
|
file.close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -68,25 +65,22 @@ void CSettings::Save()
|
||||||
void CSettings::SetFileName ( const QString& sNFiName,
|
void CSettings::SetFileName ( const QString& sNFiName,
|
||||||
const QString& sDefaultFileName )
|
const QString& sDefaultFileName )
|
||||||
{
|
{
|
||||||
// return the file name with complete path, take care if given file name is
|
// return the file name with complete path, take care if given file name is empty
|
||||||
// empty
|
|
||||||
strFileName = sNFiName;
|
strFileName = sNFiName;
|
||||||
|
|
||||||
if ( strFileName.isEmpty() )
|
if ( strFileName.isEmpty() )
|
||||||
{
|
{
|
||||||
// we use the Qt default setting file paths for the different OSs by
|
// we use the Qt default setting file paths for the different OSs by
|
||||||
// utilizing the QSettings class
|
// utilizing the QSettings class
|
||||||
const QSettings TempSettingsObject (
|
const QString sConfigDir = QFileInfo ( QSettings ( QSettings::IniFormat,
|
||||||
QSettings::IniFormat, QSettings::UserScope, APP_NAME, APP_NAME );
|
QSettings::UserScope,
|
||||||
|
APP_NAME,
|
||||||
const QString sConfigDir =
|
APP_NAME ).fileName() ).absolutePath();
|
||||||
QFileInfo ( TempSettingsObject.fileName() ).absolutePath();
|
|
||||||
|
|
||||||
// make sure the directory exists
|
// make sure the directory exists
|
||||||
if ( !QFile::exists ( sConfigDir ) )
|
if ( !QFile::exists ( sConfigDir ) )
|
||||||
{
|
{
|
||||||
QDir TempDirectoryObject;
|
QDir().mkpath ( sConfigDir );
|
||||||
TempDirectoryObject.mkpath ( sConfigDir );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// append the actual file name
|
// append the actual file name
|
||||||
|
@ -100,7 +94,7 @@ void CSettings::SetNumericIniSet ( QDomDocument& xmlFile,
|
||||||
const int iValue )
|
const int iValue )
|
||||||
{
|
{
|
||||||
// convert input parameter which is an integer to string and store
|
// convert input parameter which is an integer to string and store
|
||||||
PutIniSetting ( xmlFile, strSection, strKey, QString("%1").arg(iValue) );
|
PutIniSetting ( xmlFile, strSection, strKey, QString::number ( iValue ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CSettings::GetNumericIniSet ( const QDomDocument& xmlFile,
|
bool CSettings::GetNumericIniSet ( const QDomDocument& xmlFile,
|
||||||
|
@ -137,14 +131,7 @@ void CSettings::SetFlagIniSet ( QDomDocument& xmlFile,
|
||||||
const bool bValue )
|
const bool bValue )
|
||||||
{
|
{
|
||||||
// we encode true -> "1" and false -> "0"
|
// we encode true -> "1" and false -> "0"
|
||||||
if ( bValue == true )
|
PutIniSetting ( xmlFile, strSection, strKey, bValue ? "1" : "0" );
|
||||||
{
|
|
||||||
PutIniSetting ( xmlFile, strSection, strKey, "1" );
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
PutIniSetting ( xmlFile, strSection, strKey, "0" );
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CSettings::GetFlagIniSet ( const QDomDocument& xmlFile,
|
bool CSettings::GetFlagIniSet ( const QDomDocument& xmlFile,
|
||||||
|
@ -159,15 +146,7 @@ bool CSettings::GetFlagIniSet ( const QDomDocument& xmlFile,
|
||||||
|
|
||||||
if ( !strGetIni.isEmpty() )
|
if ( !strGetIni.isEmpty() )
|
||||||
{
|
{
|
||||||
if ( strGetIni.toInt() )
|
bValue = ( strGetIni.toInt() != 0 );
|
||||||
{
|
|
||||||
bValue = true;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
bValue = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
bReturn = true;
|
bReturn = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue