Salome HOME
Join modifications from branch BR_DEBUG_3_2_0b1
[modules/gui.git] / src / LightApp / LightApp_Preferences.cxx
1 // Copyright (C) 2005  OPEN CASCADE, CEA/DEN, EDF R&D, PRINCIPIA R&D
2 // 
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either 
6 // version 2.1 of the License.
7 // 
8 // This library 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.  See the GNU 
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public  
14 // License along with this library; if not, write to the Free Software 
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19 // File:      LightApp_Preferences.cxx
20 // Author:    Sergey TELKOV
21
22 #include "LightApp_Preferences.h"
23
24 #include <QtxListResourceEdit.h>
25
26 #include <qlayout.h>
27
28 /*!
29   Constructor.Initialize by resource manager and parent QWidget.
30 */
31 LightApp_Preferences::LightApp_Preferences( QtxResourceMgr* resMgr, QWidget* parent )
32 : QtxListResourceEdit( resMgr, parent )
33 {
34 }
35
36 /*!
37   Destructor.
38 */
39 LightApp_Preferences::~LightApp_Preferences()
40 {
41 }
42
43 /*!
44   Adds preference.
45 */
46 int LightApp_Preferences::addPreference( const QString& label, const int pId, const int type,
47                                          const QString& section, const QString& param )
48 {
49   return addItem( label, pId, type, section, param );
50 }
51
52 /*!
53   Adds preference.
54 */
55 int LightApp_Preferences::addPreference( const QString& mod, const QString& label, const int pId,
56                                          const int type, const QString& section, const QString& param )
57 {
58   int id = addItem( label, pId, type, section, param );
59   if ( id != -1 && !mod.isEmpty() )
60     myPrefMod.insert( id, mod );
61   return id;
62 }
63
64 /*!
65   Checks: is preferences has module with name \a mod.
66 */
67 bool LightApp_Preferences::hasModule( const QString& mod ) const
68 {
69   bool res = false;
70   for ( PrefModuleMap::ConstIterator it = myPrefMod.begin(); it != myPrefMod.end() && !res; ++it )
71     res = it.data() == mod;
72   return res;
73 }
74
75 /*!Do nothing.*/
76 void LightApp_Preferences::onHelp()
77 {
78 }
79
80 /*!Store preferences on apply.*/
81 void LightApp_Preferences::onApply()
82 {
83   store();
84 }
85
86 /*!Emit preference changed.*/
87 void LightApp_Preferences::changedResources( const QMap<Item*, QString>& map )
88 {
89   for ( QMap<Item*, QString>::ConstIterator it = map.begin(); it != map.end(); ++it )
90   {
91     QString sec, param;
92     it.key()->resource( sec, param );
93     QString mod = module( it.key()->id() );
94     emit preferenceChanged( mod, sec, param );
95   }
96 }
97
98 /*!Gets module name by \a id, if exist.*/
99 QString LightApp_Preferences::module( const int id ) const
100 {
101   QString mod;
102   if ( myPrefMod.contains( id ) )
103     mod = myPrefMod[id];
104   return mod;
105 }