From e17b1cec9d367f21f2c8f914052b3df3d2f88d35 Mon Sep 17 00:00:00 2001 From: stv Date: Fri, 17 Jun 2005 08:34:50 +0000 Subject: [PATCH] Preferences Editor. --- src/SalomeApp/Makefile.in | 3 + src/SalomeApp/SalomeApp_Preferences.cxx | 78 +++++++++++++++++++++++++ src/SalomeApp/SalomeApp_Preferences.h | 55 +++++++++++++++++ 3 files changed, 136 insertions(+) create mode 100755 src/SalomeApp/SalomeApp_Preferences.cxx create mode 100755 src/SalomeApp/SalomeApp_Preferences.h diff --git a/src/SalomeApp/Makefile.in b/src/SalomeApp/Makefile.in index a0a189025..fe2749c62 100755 --- a/src/SalomeApp/Makefile.in +++ b/src/SalomeApp/Makefile.in @@ -29,6 +29,7 @@ EXPORT_HEADERS= SalomeApp.h \ SalomeApp_RootObject.h \ SalomeApp_SelectionMgr.h \ SalomeApp_EventFilter.h \ + SalomeApp_Preferences.h \ SalomeApp_PreferencesDlg.h \ SalomeApp_Tools.h \ SalomeApp_NameDlg.h \ @@ -62,6 +63,7 @@ LIB_SRC= SalomeApp_AboutDlg.cxx \ SalomeApp_ExceptionHandler.cxx \ SalomeApp_SelectionMgr.cxx \ SalomeApp_EventFilter.cxx \ + SalomeApp_Preferences.cxx \ SalomeApp_PreferencesDlg.cxx \ SalomeApp_PyInterp.cxx \ SalomeApp_Tools.cxx \ @@ -87,6 +89,7 @@ LIB_MOC = SalomeApp_AboutDlg.h \ SalomeApp_Study.h \ SalomeApp_SelectionMgr.h \ SalomeApp_WidgetContainer.h \ + SalomeApp_Preferences.h \ SalomeApp_PreferencesDlg.h \ SalomeApp_NameDlg.h \ SalomeApp_ModuleDlg.h \ diff --git a/src/SalomeApp/SalomeApp_Preferences.cxx b/src/SalomeApp/SalomeApp_Preferences.cxx new file mode 100755 index 000000000..8175f3bda --- /dev/null +++ b/src/SalomeApp/SalomeApp_Preferences.cxx @@ -0,0 +1,78 @@ +// File: SalomeApp_Preferences.cxx +// Author: Sergey TELKOV + +#include "SalomeApp_Preferences.h" + +#include + +#include + +SalomeApp_Preferences::SalomeApp_Preferences( QtxResourceMgr* resMgr, QWidget* parent ) +: QtxListResourceEdit( resMgr, parent ) +{ +} + +SalomeApp_Preferences::~SalomeApp_Preferences() +{ +} + +int SalomeApp_Preferences::addPreference( const QString& label, const int pId, const int type, + const QString& section, const QString& param ) +{ + return addItem( label, pId, type, section, param ); +} + +int SalomeApp_Preferences::addPreference( const QString& mod, const QString& label, const int pId, + const int type, const QString& section, const QString& param ) +{ + int id = addItem( label, pId, type, section, param ); + if ( id != -1 && !mod.isEmpty() ) + myPrefMod.insert( id, mod ); + return id; +} + +QVariant SalomeApp_Preferences::property( const int id, const QString& param ) const +{ + return QtxResourceEdit::property( id, param ); +} + +void SalomeApp_Preferences::setProperty( const int id, const QString& param, const QVariant& prop ) +{ + QtxResourceEdit::setProperty( id, param, prop ); +} + +bool SalomeApp_Preferences::hasModule( const QString& mod ) const +{ + bool res = false; + for ( PrefModuleMap::ConstIterator it = myPrefMod.begin(); it != myPrefMod.end() && !res; ++it ) + res = it.data() == mod; + return res; +} + +void SalomeApp_Preferences::onHelp() +{ +} + +void SalomeApp_Preferences::onApply() +{ + store(); +} + +void SalomeApp_Preferences::changedResources( const QMap& map ) +{ + for ( QMap::ConstIterator it = map.begin(); it != map.end(); ++it ) + { + QString sec, param; + it.key()->resource( sec, param ); + QString mod = module( it.key()->id() ); + emit preferenceChanged( mod, sec, param ); + } +} + +QString SalomeApp_Preferences::module( const int id ) const +{ + QString mod; + if ( myPrefMod.contains( id ) ) + mod = myPrefMod[id]; + return mod; +} diff --git a/src/SalomeApp/SalomeApp_Preferences.h b/src/SalomeApp/SalomeApp_Preferences.h new file mode 100755 index 000000000..9d76a908e --- /dev/null +++ b/src/SalomeApp/SalomeApp_Preferences.h @@ -0,0 +1,55 @@ +// File: SalomeApp_Preferences.h +// Author: Sergey TELKOV + +#ifndef SALOMEAPP_PREFERENCES_H +#define SALOMEAPP_PREFERENCES_H + +#include + +#include +#include + +#include + +class QtxResourceMgr; + +class SALOMEAPP_EXPORT SalomeApp_Preferences : public QtxListResourceEdit +{ + Q_OBJECT + +public: + enum { Space = QtxListResourceEdit::Space, Bool, Color, String, Selector, DblSpin, IntSpin, Double, Integer }; + +public: + SalomeApp_Preferences( QtxResourceMgr*, QWidget* = 0 ); + virtual ~SalomeApp_Preferences(); + + int addPreference( const QString& label, const int pId = -1, const int = -1, + const QString& section = QString::null, const QString& param = QString::null ); + int addPreference( const QString& modName, const QString& label, const int pId = -1, const int = -1, + const QString& section = QString::null, const QString& param = QString::null ); + + QVariant property( const int, const QString& ) const; + virtual void setProperty( const int, const QString&, const QVariant& ); + + bool hasModule( const QString& ) const; + +signals: + void preferenceChanged( QString&, QString&, QString& ); + +private slots: + void onHelp(); + void onApply(); + virtual void changedResources( const QMap& ); + +private: + QString module( const int ) const; + +private: + typedef QMap PrefModuleMap; + +private: + PrefModuleMap myPrefMod; +}; + +#endif -- 2.39.2