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