Code_TYMPAN  4.4.0
Industrial site acoustic simulation
OLocalizator.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (C) <2012-2024> <EDF-DTG> <FRANCE>
3  * This file is part of Code_TYMPAN (R).
4  * Code_TYMPAN (R) is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation, either version 3 of the License, or
7  * (at your option) any later version.
8  * Code_TYMPAN (R) is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
11  * See the GNU General Public License for more details.
12  * You should have received a copy of the GNU General Public License along
13  * with Code_TYMPAN (R). If not, see <https://www.gnu.org/licenses/>.
14  */
15 
16 /*
17  *
18  */
19 
20 #include <qstring.h>
21 // #include <qdom.h>
22 #include "OLocalizator.h"
23 
24 //----------------------------------------------------------------------------
25 // public methods
26 //----------------------------------------------------------------------------
27 
28 bool OLocalizator::setRessourceFile(const QString& filename)
29 {
30  _stringMap.empty();
32  return _isRessourceFile;
33 }
34 
35 QString OLocalizator::getString(const QString& className, const QString& stringId)
36 {
37  QString string = "";
38 
39  if (_isRessourceFile)
40  {
41  QString keyForMap = className + stringId;
42  OptimMap::Iterator it;
43  if (_stringMap.find(keyForMap) != _stringMap.end())
44  {
45  return _stringMap[keyForMap];
46  }
47 
48  if (selectClassDirectory(className))
49  {
50  if (_treeManager.setCurrentDirectory("message"))
51  {
52  findIdAndSetValue("string", stringId, string);
53  }
54  }
55  _stringMap[keyForMap] = string;
56  }
57 
58  return string;
59 }
60 
61 QString OLocalizator::getPicture(const QString& className, const QString& pictureId)
62 {
63  QString string = "";
64  if (_isRessourceFile)
65  {
66  if (selectClassDirectory(className))
67  {
68  if (_treeManager.setCurrentDirectory("picture"))
69  {
70  if (findIdAndSetValue("image", pictureId, string))
71  {
72  string.prepend(_ressourcePath);
73  }
74  }
75  }
76  }
77 
78  return string;
79 }
80 
81 //----------------------------------------------------------------------------
82 // private members
83 //----------------------------------------------------------------------------
84 
86 
90 
91 //----------------------------------------------------------------------------
92 // private methods
93 //----------------------------------------------------------------------------
94 
95 bool OLocalizator::selectClassDirectory(const QString& classname)
96 {
97  bool bFound = false;
98 
100 
101  unsigned int i = 0;
102  unsigned int classcount = _treeManager.getSubDirectoryCount("class");
103 
104  while ((i < classcount) && (bFound == false))
105  {
106  QString str;
107 
108  if (_treeManager.setCurrentDirectory("class", true, i))
109  {
110  if (_treeManager.getFieldStringValue("name", str))
111  {
112  if (str == classname)
113  {
114  bFound = true;
115  }
116  }
117  }
118  i++;
119  }
120 
121  return bFound;
122 }
123 
124 bool OLocalizator::findIdAndSetValue(const QString& directory, const QString& stringId, QString& returnString)
125 {
126  bool bFound = false;
127 
128  unsigned int i = 0;
129  unsigned int directorycount = _treeManager.getSubDirectoryCount(directory);
130 
131  while ((i < directorycount) && (bFound == false))
132  {
133  QString objectid;
134 
135  if (_treeManager.setCurrentDirectory(directory, false, i))
136  {
137  if (_treeManager.getFieldStringValue("id", objectid))
138  {
139  if (objectid == stringId)
140  {
141  bFound = _treeManager.getFieldStringValue("value", returnString);
142  }
143  }
145  }
146  i++;
147  }
148 
149  return bFound;
150 }
static OptimMap _stringMap
Definition: OLocalizator.h:90
QMap< QString, QString > OptimMap
Definition: OLocalizator.h:89
static bool _isRessourceFile
Definition: OLocalizator.h:87
static bool setRessourceFile(const QString &filename)
static bool findIdAndSetValue(const QString &directory, const QString &stringId, QString &returnString)
static bool selectClassDirectory(const QString &classname)
static QString _ressourcePath
Definition: OLocalizator.h:91
static QString getPicture(const QString &classname, const QString &pictureId)
static QString getString(const QString &classname, const QString &stringId)
static OXMLTreeManager _treeManager
Definition: OLocalizator.h:92
unsigned long getSubDirectoryCount(const QString &directory=QString())
bool setCurrentDirectory(const QString &directory, bool absolute=false, int index=0)
virtual bool load(const QString &filename)
bool getFieldStringValue(const QString &field, QString &value)