]> SALOME platform Git repositories - modules/gui.git/blob - src/LightApp/LightApp_Preferences.cxx
Salome HOME
c97e2d6de68d2cc5d5c35fb90ac11304bfdd8309
[modules/gui.git] / src / LightApp / LightApp_Preferences.cxx
1 //  Copyright (C) 2007-2008  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 //  Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
6 //  This library is free software; you can redistribute it and/or
7 //  modify it under the terms of the GNU Lesser General Public
8 //  License as published by the Free Software Foundation; either
9 //  version 2.1 of the License.
10 //
11 //  This library is distributed in the hope that it will be useful,
12 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
13 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 //  Lesser General Public License for more details.
15 //
16 //  You should have received a copy of the GNU Lesser General Public
17 //  License along with this library; if not, write to the Free Software
18 //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
19 //
20 //  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22 // File:      LightApp_Preferences.cxx
23 // Author:    Sergey TELKOV
24 //
25 #include "LightApp_Preferences.h"
26
27 /*!
28   Constructor.Initialize by resource manager and parent QWidget.
29 */
30 LightApp_Preferences::LightApp_Preferences( QtxResourceMgr* resMgr, QWidget* parent )
31 : SUIT_PreferenceMgr( resMgr, parent )
32 {
33 }
34
35 /*!
36   Destructor.
37 */
38 LightApp_Preferences::~LightApp_Preferences()
39 {
40 }
41
42 /*!
43   Adds preference.
44 */
45 int LightApp_Preferences::addPreference( const QString& label, const int pId, const int type,
46                                          const QString& section, const QString& param )
47 {
48   return addItem( label, pId, (SUIT_PreferenceMgr::PrefItemType)type, section, param );
49 }
50
51 /*!
52   Adds preference.
53 */
54 int LightApp_Preferences::addPreference( const QString& mod, const QString& label, const int pId,
55                                          const int type, const QString& section, const QString& param )
56 {
57   int id = addItem( label, pId, (SUIT_PreferenceMgr::PrefItemType)type, section, param );
58   if ( id != -1 && !mod.isEmpty() )
59     myPrefMod.insert( id, mod );
60   return id;
61 }
62
63 /*!
64   Checks: is preferences has module with name \a mod.
65 */
66 bool LightApp_Preferences::hasModule( const QString& mod ) const
67 {
68   bool res = false;
69   for ( PrefModuleMap::ConstIterator it = myPrefMod.begin(); it != myPrefMod.end() && !res; ++it )
70     res = it.value() == mod;
71   return res;
72 }
73
74 void LightApp_Preferences::activateItem( const QString& mod ) const
75 {
76   QtxPreferenceItem* item = findItem( mod, true );
77
78   if ( !item )
79     return;
80
81   item->ensureVisible();
82   item->activate();
83 }
84
85 /*!Do nothing.*/
86 void LightApp_Preferences::onHelp()
87 {
88 }
89
90 /*!Store preferences on apply.*/
91 void LightApp_Preferences::onApply()
92 {
93   store();
94 }
95
96 /*!Emit preference changed.*/
97 void LightApp_Preferences::changedResources( const ResourceMap& map )
98 {
99   for ( ResourceMap::ConstIterator it = map.begin(); 
100         it != map.end(); ++it )
101   {
102     QString sec, param;
103     it.key()->resource( sec, param );
104     QString mod = module( it.key()->id() );
105     emit preferenceChanged( mod, sec, param );
106   }
107 }
108
109 /*!Gets module name by \a id, if exist.*/
110 QString LightApp_Preferences::module( const int id ) const
111 {
112   QString mod;
113   if ( myPrefMod.contains( id ) )
114     mod = myPrefMod[id];
115   return mod;
116 }