Code_TYMPAN  4.4.0
Industrial site acoustic simulation
TYPreferenceManager.h
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  *
21  */
22 
23 #ifndef __TY_PREFERENCE_MANAGER__
24 #define __TY_PREFERENCE_MANAGER__
25 
26 #include "Tympan/core/defines.h"
27 #include <qfile.h>
28 #include <memory>
29 
30 #if TY_USE_IHM
31 
33 
34 class QWidget;
35 class QString;
36 class TYSpectre;
37 
43 class TYPreferenceManager
44 {
45 public:
49  static OPreferenceManager& getInstance();
50 
54  static void completePreferences();
55 
71  static bool init(const QString& regularSettingsFileName, bool& isCopiedFromDefaultSettings,
72  const std::unique_ptr<QFile> settingsFile);
73 
77  static void reset();
78 
84  static void setFileName(const QString& fileName);
85 
93  static bool read();
94 
102  static bool write();
103 
112  static bool exists(const QString& pref);
113 
119  static void setCurrentDirectory(QString dir)
120  {
121  getInstance().setCurrentDirectory(dir);
122  }
123 
129  static QString getCurrentDirectory()
130  {
131  return getInstance().getCurrentDirectory();
132  }
133 
141  static void setString(const QString& pref, const QString& value)
142  {
143  getInstance().setString(pref, value);
144  }
145 
153  static QString getString(const QString& pref)
154  {
155  return getInstance().getString(pref);
156  }
157 
166  static void setStringArray(const QString& pref, const QString* valueArray, const int& sizeArray)
167  {
168  getInstance().setStringArray(pref, valueArray, sizeArray);
169  }
170 
180  static QString* getStringArray(const QString& pref, int& sizeArray)
181  {
182  return getInstance().getStringArray(pref, sizeArray);
183  }
184 
185  #if TY_ARCH_TYPE == TY_ARCHITECTURE_64
193  static void setUInt(const QString& pref, const unsigned int& value)
194  {
195  getInstance().setUInt(pref, value);
196  }
197 
205  static void setUInt(const QString& pref, const size_t& value)
206  {
207  getInstance().setUInt(pref, value);
208  }
209  #if TY_COMPILER == TY_COMPILER_MSVC
217  static void setUInt(const QString& pref, const unsigned long& value)
218  {
219  getInstance().setUInt(pref, value);
220  }
221  #endif
222  #else
230  static void setUInt(const QString& pref, const size_t& value)
231  {
232  getInstance().setUInt(pref, value);
233  }
234 
242  static void setUInt(const QString& pref, const unsigned long& value)
243  {
244  getInstance().setUInt(pref, value);
245  }
246  #endif
247 
255  static void setInt(const QString& pref, const int& value)
256  {
257  getInstance().setInt(pref, value);
258  }
259 
267  static int getInt(const QString& pref)
268  {
269  return getInstance().getInt(pref);
270  }
271 
279  static void setBool(const QString& pref, const bool& value)
280  {
281  getInstance().setBool(pref, value);
282  }
283 
291  static bool getBool(const QString& pref)
292  {
293  return getInstance().getBool(pref);
294  }
295 
303  static void setFloat(const QString& pref, const float& value)
304  {
305  getInstance().setFloat(pref, value);
306  }
307 
315  static float getFloat(const QString& pref)
316  {
317  return getInstance().getFloat(pref);
318  }
319 
327  static void setDouble(const QString& pref, const double& value)
328  {
329  getInstance().setDouble(pref, value);
330  }
331 
339  static double getDouble(const QString& pref)
340  {
341  return getInstance().getDouble(pref);
342  }
343 
351  static void saveGeometryToPreferences(const QString& pref, const QWidget* pWidget);
352 
359  static void loadGeometryFromPreferences(const QString& pref, QWidget* pWidget);
360 
369  static void setPoint(const QString& pref, const int& x, const int& y)
370  {
371  getInstance().setPoint(pref, x, y);
372  }
373 
381  static void getPoint(const QString& pref, int& x, int& y)
382  {
383  getInstance().getPoint(pref, x, y);
384  }
385 
395  static void setColor(const QString& pref, const float& r, const float& g, const float& b)
396  {
397  getInstance().setColor(pref, r, g, b);
398  }
399 
408  static void getColor(const QString& pref, float& r, float& g, float& b)
409  {
410  getInstance().getColor(pref, r, g, b);
411  }
412 
420  static void setSpectre(const QString& pref, const TYSpectre*);
421 
429  static TYSpectre* getSpectre(const QString& pref);
430 
441  static bool exists(const QString& dir, const QString& pref)
442  {
443  return getInstance().exists(dir, pref);
444  }
445 
455  static void setString(const QString& dir, const QString& pref, const QString& value)
456  {
457  getInstance().setString(dir, pref, value);
458  }
459 
469  static QString getString(const QString& dir, const QString& pref)
470  {
471  return getInstance().getString(dir, pref);
472  }
473 
484  static void setStringArray(const QString& dir, const QString& pref, const QString* valueArray,
485  const int& sizeArray)
486  {
487  getInstance().setStringArray(dir, pref, valueArray, sizeArray);
488  }
489 
501  static QString* getStringArray(const QString& dir, const QString& pref, int& sizeArray)
502  {
503  return getInstance().getStringArray(dir, pref, sizeArray);
504  }
505 
506  #if TY_ARCH_TYPE == TY_ARCHITECTURE_64
516  static void setUInt(const QString& dir, const QString& pref, const unsigned int& value)
517  {
518  getInstance().setUInt(dir, pref, value);
519  }
520 
530  static void setUInt(const QString& dir, const QString& pref, const size_t& value)
531  {
532  getInstance().setUInt(dir, pref, value);
533  }
534  #if TY_COMPILER == TY_COMPILER_MSVC
544  static void setUInt(const QString& dir, const QString& pref, const unsigned long& value)
545  {
546  getInstance().setUInt(dir, pref, value);
547  }
548  #endif
549  #else
559  static void setUInt(const QString& dir, const QString& pref, const size_t& value)
560  {
561  getInstance().setUInt(dir, pref, value);
562  }
563 
573  static void setUInt(const QString& dir, const QString& pref, const unsigned long& value)
574  {
575  getInstance().setUInt(dir, pref, value);
576  }
577  #endif
578 
588  static void setInt(const QString& dir, const QString& pref, const int& value)
589  {
590  getInstance().setInt(dir, pref, value);
591  }
592 
602  static int getInt(const QString& dir, const QString& pref)
603  {
604  return getInstance().getInt(dir, pref);
605  }
606 
616  static void setBool(const QString& dir, const QString& pref, const bool& value)
617  {
618  getInstance().setBool(dir, pref, value);
619  }
620 
630  static bool getBool(const QString& dir, const QString& pref)
631  {
632  return getInstance().getBool(dir, pref);
633  }
634 
644  static void setFloat(const QString& dir, const QString& pref, const float& value)
645  {
646  getInstance().setFloat(dir, pref, value);
647  }
648 
658  static float getFloat(const QString& dir, const QString& pref)
659  {
660  return getInstance().getFloat(dir, pref);
661  }
662 
672  static void setDouble(const QString& dir, const QString& pref, const double& value)
673  {
674  getInstance().setDouble(dir, pref, value);
675  }
676 
686  static double getDouble(const QString& dir, const QString& pref)
687  {
688  return getInstance().getDouble(dir, pref);
689  }
690 
701  static void setPoint(const QString& dir, const QString& pref, const int& x, const int& y)
702  {
703  getInstance().setPoint(dir, pref, x, y);
704  }
705 
715  static void getPoint(const QString& dir, const QString& pref, int& x, int& y)
716  {
717  getInstance().getPoint(dir, pref, x, y);
718  }
719 
731  static void setColor(const QString& dir, const QString& pref, const float& r, const float& g,
732  const float& b)
733  {
734  getInstance().setColor(dir, pref, r, g, b);
735  }
736 
747  static void getColor(const QString& dir, const QString& pref, float& r, float& g, float& b)
748  {
749  getInstance().getColor(dir, pref, r, g, b);
750  }
751 
761  static void setSpectre(const QString& dir, const QString& pref, const TYSpectre*);
762 
772  static TYSpectre* getSpectre(const QString& dir, const QString& pref);
773 
777  static int getLastModificationCode()
778  {
779  return getInstance().getLastModificationCode();
780  }
781 
790  static bool copyDefaultSettings(const QString& sourcePath, const QString& destinationPath);
791 
792 private:
794  static OPreferenceManager* _prefMngr;
795 
797  static QString& getFileName();
798  static QString* _fileName;
799 };
800 
801 #endif // TY_USE_IHM
802 
803 #endif // __O_PREFERENCE_MANAGER__
QColor getColor
Systeme de gestion des preferences.