Salome HOME
add SVTK resources
[modules/gui.git] / src / LightApp / LightApp_Preferences.cxx
1 // File:      LightApp_Preferences.cxx
2 // Author:    Sergey TELKOV
3
4 #include "LightApp_Preferences.h"
5
6 #include <QtxListResourceEdit.h>
7
8 #include <qlayout.h>
9
10 /*!
11   Constructor.Initialize by resource manager and parent QWidget.
12 */
13 LightApp_Preferences::LightApp_Preferences( QtxResourceMgr* resMgr, QWidget* parent )
14 : QtxListResourceEdit( resMgr, parent )
15 {
16 }
17
18 /*!
19   Destructor.
20 */
21 LightApp_Preferences::~LightApp_Preferences()
22 {
23 }
24
25 /*!
26   Adds preference.
27 */
28 int LightApp_Preferences::addPreference( const QString& label, const int pId, const int type,
29                                          const QString& section, const QString& param )
30 {
31   return addItem( label, pId, type, section, param );
32 }
33
34 /*!
35   Adds preference.
36 */
37 int LightApp_Preferences::addPreference( const QString& mod, const QString& label, const int pId,
38                                          const int type, const QString& section, const QString& param )
39 {
40   int id = addItem( label, pId, type, section, param );
41   if ( id != -1 && !mod.isEmpty() )
42     myPrefMod.insert( id, mod );
43   return id;
44 }
45
46 /*
47   Checks: is preferences has module with name \a mod.
48 */
49 bool LightApp_Preferences::hasModule( const QString& mod ) const
50 {
51   bool res = false;
52   for ( PrefModuleMap::ConstIterator it = myPrefMod.begin(); it != myPrefMod.end() && !res; ++it )
53     res = it.data() == mod;
54   return res;
55 }
56
57 /*!Do nothing.*/
58 void LightApp_Preferences::onHelp()
59 {
60 }
61
62 /*!Store preferences on apply.*/
63 void LightApp_Preferences::onApply()
64 {
65   store();
66 }
67
68 /*!Emit preference changed.*/
69 void LightApp_Preferences::changedResources( const QMap<Item*, QString>& map )
70 {
71   for ( QMap<Item*, QString>::ConstIterator it = map.begin(); it != map.end(); ++it )
72   {
73     QString sec, param;
74     it.key()->resource( sec, param );
75     QString mod = module( it.key()->id() );
76     emit preferenceChanged( mod, sec, param );
77   }
78 }
79
80 /*!Gets module name by \a id, if exist.*/
81 QString LightApp_Preferences::module( const int id ) const
82 {
83   QString mod;
84   if ( myPrefMod.contains( id ) )
85     mod = myPrefMod[id];
86   return mod;
87 }