From: stv Date: Fri, 10 Jun 2005 04:55:03 +0000 (+0000) Subject: Resource (Preferences) editor. Not fully implemented. X-Git-Tag: T3_0_0_a3~19 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=e0d6fb42260448f334e3ed98f4c3b4a39ece9196;p=modules%2Fgui.git Resource (Preferences) editor. Not fully implemented. --- diff --git a/src/Qtx/Makefile.in b/src/Qtx/Makefile.in index 726818f95..9e03cb665 100755 --- a/src/Qtx/Makefile.in +++ b/src/Qtx/Makefile.in @@ -42,7 +42,8 @@ EXPORT_HEADERS= Qtx.h \ QtxMainWindow.h \ QtxWorkspaceAction.h \ QtxWorkstackAction.h \ - QtxResourceEditor.h \ + QtxResourceEdit.h \ + QtxListResourceEdit.h \ QtxWorkstack.h \ QtxListView.h @@ -85,7 +86,8 @@ LIB_SRC= \ QtxMainWindow.cxx \ QtxWorkspaceAction.cxx \ QtxWorkstackAction.cxx \ - QtxResourceEditor.cxx \ + QtxResourceEdit.cxx \ + QtxListResourceEdit.cxx \ QtxWorkstack.cxx \ QtxListView.cxx @@ -115,7 +117,8 @@ LIB_MOC = \ QtxWorkspaceAction.h \ QtxWorkstackAction.h \ QtxWorkstack.h \ - QtxListView.h + QtxListView.h \ + QtxListResourceEdit.h RESOURCES_FILES = \ diff --git a/src/Qtx/QtxListResourceEdit.cxx b/src/Qtx/QtxListResourceEdit.cxx index 717d4f3db..5a6c1867a 100644 --- a/src/Qtx/QtxListResourceEdit.cxx +++ b/src/Qtx/QtxListResourceEdit.cxx @@ -80,6 +80,23 @@ QtxResourceEdit::Item* QtxListResourceEdit::createItem( const QString& title, co return category; } +void QtxListResourceEdit::changedResources( const QMap& map ) +{ + QMap idMap; + for ( QMap::ConstIterator it = map.begin(); it != map.end(); ++it ) + { + idMap.insert( it.key()->id(), it.data() ); + + emit resourceChanged( it.key()->id() ); + + QString sec, param; + it.key()->resource( sec, param ); + emit resourceChanged( sec, param ); + } + + emit resourcesChanged( idMap ); +} + void QtxListResourceEdit::updateState() { if ( myStack->visibleWidget() ) diff --git a/src/Qtx/QtxListResourceEdit.h b/src/Qtx/QtxListResourceEdit.h index 554cec23b..29a46cc9a 100644 --- a/src/Qtx/QtxListResourceEdit.h +++ b/src/Qtx/QtxListResourceEdit.h @@ -51,11 +51,17 @@ public: QtxListResourceEdit( QtxResourceMgr*, QWidget* = 0 ); virtual ~QtxListResourceEdit(); +signals: + void resourceChanged( int ); + void resourceChanged( QString&, QString& ); + void resourcesChanged( const QMap& ); + private slots: void onSelectionChanged(); protected: virtual Item* createItem( const QString&, const int ); + virtual void changedResources( const QMap& ); private: void updateState(); diff --git a/src/SalomeApp/Makefile.in b/src/SalomeApp/Makefile.in index 48f75cb03..241d84571 100755 --- a/src/SalomeApp/Makefile.in +++ b/src/SalomeApp/Makefile.in @@ -29,7 +29,7 @@ EXPORT_HEADERS= SalomeApp.h \ SalomeApp_RootObject.h \ SalomeApp_SelectionMgr.h \ SalomeApp_EventFilter.h \ - SalomeApp_ResourceEditor.h \ + SalomeApp_PreferencesDlg.h \ SalomeApp_Tools.h \ SalomeApp_NameDlg.h \ SalomeApp_ImportOperation.h \ @@ -61,7 +61,7 @@ LIB_SRC= SalomeApp_AboutDlg.cxx \ SalomeApp_ExceptionHandler.cxx \ SalomeApp_SelectionMgr.cxx \ SalomeApp_EventFilter.cxx \ - SalomeApp_ResourceEditor.cxx \ + SalomeApp_PreferencesDlg.cxx \ SalomeApp_PyInterp.cxx \ SalomeApp_Tools.cxx \ SalomeApp_NameDlg.cxx \ @@ -84,7 +84,7 @@ LIB_MOC = SalomeApp_AboutDlg.h \ SalomeApp_Study.h \ SalomeApp_SelectionMgr.h \ SalomeApp_WidgetContainer.h \ - SalomeApp_ResourceEditor.h \ + SalomeApp_PreferencesDlg.h \ SalomeApp_NameDlg.h \ SalomeApp_ModuleDlg.h diff --git a/src/SalomeApp/SalomeApp_Application.cxx b/src/SalomeApp/SalomeApp_Application.cxx index c8e92652e..ffd325319 100644 --- a/src/SalomeApp/SalomeApp_Application.cxx +++ b/src/SalomeApp/SalomeApp_Application.cxx @@ -17,6 +17,7 @@ #include "SalomeApp_AboutDlg.h" #include "SalomeApp_ModuleDlg.h" +#include "SalomeApp_PreferencesDlg.h" #include "SalomeApp_GLSelector.h" #include "SalomeApp_OBSelector.h" @@ -109,7 +110,8 @@ extern "C" SALOMEAPP_EXPORT SUIT_Application* createApplication() */ SalomeApp_Application::SalomeApp_Application() -: CAM_Application( false ) +: CAM_Application( false ), +myPrefDlg( 0 ) { STD_TabDesktop* desk = new STD_TabDesktop(); @@ -672,6 +674,31 @@ PythonConsole* SalomeApp_Application::pythonConsole() return console; } +QtxResourceEdit* SalomeApp_Application::resourceEdit() const +{ + return 0; + /* + QtxResourceEdit* edit = 0; + if ( !myPrefDlg ) + { + SalomeApp_Application* that = (SalomeApp_Application*)this; + that->myPrefDlg = new SalomeApp_PreferencesDlg( that->desktop() ); + + edit = myPrefDlg->resourceEdit(); + + QStringList modList; + modules( modList, false ); + for ( QStringList::const_iterator it = modList.begin(); it != modList.end(); ++it ) + { + int id = edit->addItem( *it ); + edit->setProperty( id, "info", tr( "PREFERENCES_NOT_LOADED" ).arg( *it ) ); + } + } + else + edit = myPrefDlg->resourceEdit(); + */ +} + SUIT_ViewManager* SalomeApp_Application::getViewManager( const QString& vmType, const bool create ) { SUIT_ViewManager* aVM = viewManager( vmType ); @@ -745,6 +772,8 @@ void SalomeApp_Application::onStudyCreated( SUIT_Study* theStudy ) objectBrowser()->setRootObject( aRoot ); activateModule( defaultModule() ); + + activateWindows(); } void SalomeApp_Application::onStudyOpened( SUIT_Study* theStudy ) @@ -759,10 +788,10 @@ void SalomeApp_Application::onStudyOpened( SUIT_Study* theStudy ) objectBrowser()->setRootObject( aRoot ); } - activateWindows(); - activateModule( defaultModule() ); + activateWindows(); + emit studyOpened(); } diff --git a/src/SalomeApp/SalomeApp_Application.h b/src/SalomeApp/SalomeApp_Application.h index dc2004eb0..6a7170acc 100644 --- a/src/SalomeApp/SalomeApp_Application.h +++ b/src/SalomeApp/SalomeApp_Application.h @@ -28,9 +28,12 @@ class QDockWindow; class LogWindow; class OB_Browser; class PythonConsole; +class QtxResourceEdit; class SalomeApp_Module; class SalomeApp_SelectionMgr; +class SalomeApp_PreferencesDlg; class SalomeApp_WidgetContainer; + class SALOME_LifeCycleCORBA; #ifdef WIN32 @@ -64,10 +67,12 @@ public: SalomeApp_SelectionMgr* selectionMgr() const; - OB_Browser* objectBrowser(); LogWindow* logWindow(); + OB_Browser* objectBrowser(); PythonConsole* pythonConsole(); + QtxResourceEdit* resourceEdit() const; + virtual QString getFileFilter() const; SUIT_ViewManager* getViewManager( const QString&, const bool ); @@ -154,6 +159,7 @@ private: private: SalomeApp_SelectionMgr* mySelMgr; + SalomeApp_PreferencesDlg* myPrefDlg; ActionMap myActions; WindowMap myWindows; }; diff --git a/src/SalomeApp/SalomeApp_PreferencesDlg.cxx b/src/SalomeApp/SalomeApp_PreferencesDlg.cxx new file mode 100755 index 000000000..189fe1082 --- /dev/null +++ b/src/SalomeApp/SalomeApp_PreferencesDlg.cxx @@ -0,0 +1,100 @@ +// File: SalomeApp_PreferencesDlg.cxx +// Author: Sergey TELKOV + +#include "SalomeApp_PreferencesDlg.h" + +#include + +#include + +SalomeApp_PreferencesDlg::SalomeApp_PreferencesDlg( QtxResourceMgr* resMgr, QWidget* parent ) +: QtxDialog( parent, 0, true, false, Standard | Apply ) +{ + setCaption( tr( "CAPTION" ) ); + + QVBoxLayout* main = new QVBoxLayout( mainFrame(), 5 ); + + myEdit = new QtxListResourceEdit( resMgr, mainFrame() ); + main->addWidget( myEdit ); + + setFocusProxy( myEdit ); + + setDialogFlags( AlignOnce ); + + connect( this, SIGNAL( dlgHelp() ), this, SLOT( onHelp() ) ); + connect( this, SIGNAL( dlgApply() ), this, SLOT( onApply() ) ); + connect( myEdit, SIGNAL( resourceChanged( QString&, QString& ) ), + this, SIGNAL( resourceChanged( QString&, QString& ) ) ); +} + +SalomeApp_PreferencesDlg::~SalomeApp_PreferencesDlg() +{ +} + +void SalomeApp_PreferencesDlg::store() +{ + myEdit->store(); +} + +void SalomeApp_PreferencesDlg::retrieve() +{ + myEdit->retrieve(); +} + +void SalomeApp_PreferencesDlg::show() +{ + retrieve(); + myEdit->toBackup(); + + QtxDialog::show(); +} + +void SalomeApp_PreferencesDlg::accept() +{ + QtxDialog::accept(); + + store(); +} + +void SalomeApp_PreferencesDlg::reject() +{ + QtxDialog::reject(); + + myEdit->fromBackup(); +} + +int SalomeApp_PreferencesDlg::addPreference( const QString& label, const int pId, const int type, + const QString& section, const QString& param, SalomeApp_Module* mod ) +{ + int id = myEdit->addItem( label, pId, type, section, param ); + if ( id != -1 && mod ) + myPrefMod.insert( id, mod ); + return id; +} + +QVariant SalomeApp_PreferencesDlg::property( const int id, const QString& param ) const +{ + return myEdit->QtxResourceEdit::property( id, param ); +} + +void SalomeApp_PreferencesDlg::setProperty( const int id, const QString& param, const QVariant& prop ) +{ + myEdit->QtxResourceEdit::setProperty( id, param, prop ); +} + +void SalomeApp_PreferencesDlg::onHelp() +{ +} + +void SalomeApp_PreferencesDlg::onApply() +{ + myEdit->store(); +} + +SalomeApp_Module* SalomeApp_PreferencesDlg::module( const int id ) const +{ + SalomeApp_Module* mod = 0; + if ( myPrefMod.contains( id ) ) + mod = myPrefMod[id]; + return mod; +} diff --git a/src/SalomeApp/SalomeApp_PreferencesDlg.h b/src/SalomeApp/SalomeApp_PreferencesDlg.h new file mode 100755 index 000000000..5888e7693 --- /dev/null +++ b/src/SalomeApp/SalomeApp_PreferencesDlg.h @@ -0,0 +1,57 @@ +// File: SalomeApp_PreferencesDlg.h +// Author: Sergey TELKOV + +#ifndef SALOMEAPP_PREFERENCESDLG_H +#define SALOMEAPP_PREFERENCESDLG_H + +#include + +#include + +#include + +class QtxResourceMgr; +class SalomeApp_Module; +class QtxListResourceEdit; + +class SALOMEAPP_EXPORT SalomeApp_PreferencesDlg : public QtxDialog +{ + Q_OBJECT + +public: + SalomeApp_PreferencesDlg( QtxResourceMgr*, QWidget* = 0 ); + virtual ~SalomeApp_PreferencesDlg(); + + virtual void show(); + virtual void accept(); + virtual void reject(); + + void store(); + void retrieve(); + + int addPreference( const QString& label, const int pId = -1, const int = -1, + const QString& section = QString::null, + const QString& param = QString::null, SalomeApp_Module* = 0 ); + + QVariant property( const int, const QString& ) const; + void setProperty( const int, const QString&, const QVariant& ); + +signals: + void resourceChanged( QString&, QString& ); + +private slots: + void onHelp(); + void onApply(); + +private: + SalomeApp_Module* module( const int ) const; + +private: + typedef QMap PrefModuleMap; + +private: + QtxListResourceEdit* myEdit; + PrefModuleMap myPrefMod; +}; + +#endif diff --git a/src/SalomeApp/SalomeApp_ResourceEditor.cxx b/src/SalomeApp/SalomeApp_ResourceEditor.cxx deleted file mode 100755 index aafc91df8..000000000 --- a/src/SalomeApp/SalomeApp_ResourceEditor.cxx +++ /dev/null @@ -1,900 +0,0 @@ -// File: SalomeApp_ResourceEditor.cxx -// Created: -// Author: Alexander Sladkov -// Copyright: - -#include "SalomeApp_ResourceEditor.h" - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include - -#include - -/* - Class: SalomeApp_ResourceEditor::ListItem - Descr: GUI implementation of resources list item. -*/ - -SalomeApp_ResourceEditor::ListItem::ListItem( SalomeApp_ResourceEditor* ed, QWidget* parent ) -: Item( ed ) -{ - mypName = new QLabel( parent ); - mypList = new QComboBox( false, parent ); -} - -SalomeApp_ResourceEditor::ListItem::~ListItem() -{ -} - -void SalomeApp_ResourceEditor::ListItem::Set( const QString& sect, const QString& key, - const int type, const QString& label ) -{ - Item::Set( sect, key, type, label ); - mypName->setText( label ); -} - -void SalomeApp_ResourceEditor::ListItem::SetList( const QValueList& ids, - const QStringList& names ) -{ - myIndex.clear(); - mypList->clear(); - - for ( uint i = 0; i < QMIN( ids.count(), names.count() ); i++ ) - { - mypList->insertItem( *names.at( i ) ); - myIndex.insert( mypList->count() - 1, *ids.at( i ) ); - } -} - -void SalomeApp_ResourceEditor::ListItem::Store() -{ - int type; - QString key, label; - QString sect = Get( key, type, label ); - - if ( !sect.isEmpty() ) - { - QString sVal; - int iVal, index = mypList->currentItem(); - if ( GetInteger( sect, key, iVal ) && myIndex.contains( index ) ) - SetInteger( sect, key, myIndex[index] ); - else if ( GetString( sect, key, sVal ) ) - SetString( sect, key, mypList->text( index ) ); - } -} - -void SalomeApp_ResourceEditor::ListItem::Retrieve() -{ - int type; - QString key, label; - QString sect = Get( key, type, label ); - - int index = -1; - if ( !sect.isEmpty() ) - { - int iVal; - QString sVal; - if ( GetInteger( sect, key, iVal ) ) - { - for ( QMap::ConstIterator it = myIndex.begin(); it != myIndex.end() && index == -1; ++it ) - if ( it.data() == iVal ) - index = it.key(); - } - else if ( GetString( sect, key, sVal ) ) - { - for ( int i = 0; i < (int)mypList->count() && index == -1; i++ ) - if ( mypList->text( i ) == sVal ) - index = i; - } - } - mypList->setCurrentItem( index ); -} - -/* - Class: SalomeApp_ResourceEditor::ColorItem - Descr: GUI implementation of resources color item. -*/ - -SalomeApp_ResourceEditor::ColorItem::ColorItem( SalomeApp_ResourceEditor* ed, QWidget* parent ) -: Item( ed ) -{ - mypName = new QLabel( parent ); - mypColor = new ColorButton( parent ); - mypColor->setAutoDefault( false ); -} - -SalomeApp_ResourceEditor::ColorItem::~ColorItem() -{ -} - -void SalomeApp_ResourceEditor::ColorItem::Set( const QString& sect, const QString& key, - const int type, const QString& label ) -{ - Item::Set( sect, key, type, label ); - mypName->setText( label ); -} - -void SalomeApp_ResourceEditor::ColorItem::Store() -{ - int type; - QString key, label; - QString sect = Get( key, type, label ); - - if ( !sect.isEmpty() ) - SetColor( sect, key, mypColor->paletteBackgroundColor() ); -} - -void SalomeApp_ResourceEditor::ColorItem::Retrieve() -{ - int type; - QColor color; - QString key, label; - QString sect = Get( key, type, label ); - - if ( !sect.isEmpty() && GetColor( sect, key, color ) ) - mypColor->setPaletteBackgroundColor( color ); -} - -/* - Class: SalomeApp_ResourceEditor::StateItem - Descr: GUI implementation of resources bool item. -*/ - -SalomeApp_ResourceEditor::StateItem::StateItem( SalomeApp_ResourceEditor* ed, QWidget* parent ) -: Item( ed ) -{ - mypName = new QLabel( parent ); - mypState = new QCheckBox( parent ); -} - -SalomeApp_ResourceEditor::StateItem::~StateItem() -{ -} - -void SalomeApp_ResourceEditor::StateItem::Set( const QString& sect, const QString& key, - const int type, const QString& label ) -{ - Item::Set( sect, key, type, label ); - mypName->setText( label ); -} - -void SalomeApp_ResourceEditor::StateItem::Store() -{ - int type; - QString key, label; - QString sect = Get( key, type, label ); - if ( !sect.isEmpty() ) - SetBoolean( sect, key, mypState->isChecked() ); -} - -void SalomeApp_ResourceEditor::StateItem::Retrieve() -{ - int type; - bool state; - QString key, label; - QString sect = Get( key, type, label ); - if ( !sect.isEmpty() && GetBoolean( sect, key, state ) ) - mypState->setChecked( state ); -} - -/* - Class: SalomeApp_ResourceEditor::StringItem - Descr: GUI implementation of resources string item. -*/ - -SalomeApp_ResourceEditor::StringItem::StringItem( SalomeApp_ResourceEditor* ed, QWidget* parent ) -: Item( ed ) -{ - mypName = new QLabel( parent ); - mypString = new QLineEdit( parent ); -} - -SalomeApp_ResourceEditor::StringItem::~StringItem() -{ -} - -void SalomeApp_ResourceEditor::StringItem::Set( const QString& sect, const QString& key, - const int type, const QString& label ) -{ - Item::Set( sect, key, type, label ); - mypName->setText( label ); -} - -void SalomeApp_ResourceEditor::StringItem::Store() -{ - int type; - QString key, label; - QString sect = Get( key, type, label ); - if ( !sect.isEmpty() ) - SetString( sect, key, mypString->text() ); -} - -void SalomeApp_ResourceEditor::StringItem::Retrieve() -{ - int type; - QString val, key, label; - QString sect = Get( key, type, label ); - if ( !sect.isEmpty() && GetString( sect, key, val ) ) - mypString->setText( val ); -} - -/* - Class: SalomeApp_ResourceEditor::DoubleSpinItem - Descr: GUI implementation of resources string item. -*/ - -SalomeApp_ResourceEditor::DoubleSpinItem::DoubleSpinItem - ( SalomeApp_ResourceEditor* ed, QWidget* parent ) -: Item( ed ) -{ - mypName = new QLabel( parent ); - mypDouble = new QtxDblSpinBox( parent, "spinboxdouble" ); - mypDouble->setSizePolicy( QSizePolicy( QSizePolicy::Preferred, QSizePolicy::Fixed ) ); -} - -SalomeApp_ResourceEditor::DoubleSpinItem::~DoubleSpinItem() -{ -} - -void SalomeApp_ResourceEditor::DoubleSpinItem::Set( const QString& sect, const QString& key, - const int type, const QString& label ) -{ - Item::Set( sect, key, type, label ); - mypName->setText( label ); - mypDouble->setName( label ); // for debug purposes.. -} - -void SalomeApp_ResourceEditor::DoubleSpinItem::SetRange( const double min, const double max, - const double prec, const double step ) -{ - mypDouble->setMinValue( min ); - mypDouble->setMaxValue( max ); - mypDouble->setPrecision( prec ); - if ( step > 0 ) - mypDouble->setSteps( step, step*5 ); -} - -void SalomeApp_ResourceEditor::DoubleSpinItem::Store() -{ - int type; - QString key, label; - QString sect = Get( key, type, label ); - if ( !sect.isEmpty() ) - SetDouble( sect, key, mypDouble->value() ); -} - -void SalomeApp_ResourceEditor::DoubleSpinItem::Retrieve() -{ - int type; - double val; - QString key, label; - QString sect = Get( key, type, label ); - if ( sect.isEmpty() && GetDouble( sect, key, val ) ) - mypDouble->setValue( val ); -} - -/* - Class: SalomeApp_ResourceEditor::DoubleEditItem - Descr: GUI implementation of resources string item. -*/ - -SalomeApp_ResourceEditor::DoubleEditItem::DoubleEditItem - ( SalomeApp_ResourceEditor* ed, QWidget* parent ) -: Item( ed ) -{ - mypName = new QLabel( parent ); - mypDouble = new QLineEdit( parent ); - mypDouble->setValidator( new QDoubleValidator( mypDouble ) ); -} - -SalomeApp_ResourceEditor::DoubleEditItem::~DoubleEditItem() -{ -} - -void SalomeApp_ResourceEditor::DoubleEditItem::Set( const QString& sect, const QString& key, - const int type, const QString& label ) -{ - Item::Set( sect, key, type, label ); - mypName->setText( label ); -} - -void SalomeApp_ResourceEditor::DoubleEditItem::Store() -{ - int type; - QString key, label; - QString sect = Get( key, type, label ); - if ( !sect.isEmpty() ) - SetDouble( sect, key, mypDouble->text().toDouble() ); -} - -void SalomeApp_ResourceEditor::DoubleEditItem::Retrieve() -{ - int type; - double val; - QString key, label; - QString sect = Get( key, type, label ); - if ( sect.isEmpty() && GetDouble( sect, key, val ) ) - mypDouble->setText( QString().setNum( val, 'g', 16 ) ); -} - -/* - Class: SalomeApp_ResourceEditor::IntegerSpinItem - Descr: GUI implementation of resources integer item. -*/ - -SalomeApp_ResourceEditor::IntegerSpinItem::IntegerSpinItem -( SalomeApp_ResourceEditor* ed, QWidget* parent ) -: Item( ed ) -{ - mypName = new QLabel( parent ); - mypInteger = new QSpinBox( parent ); -} - -SalomeApp_ResourceEditor::IntegerSpinItem::~IntegerSpinItem() -{ -} - -void SalomeApp_ResourceEditor::IntegerSpinItem::Set( const QString& sect, const QString& key, - const int type, const QString& label ) -{ - Item::Set( sect, key, type, label ); - mypName->setText( label ); -} - -void SalomeApp_ResourceEditor::IntegerSpinItem::SetRange( const double min, const double max, - const double, const double step ) -{ - mypInteger->setMinValue( (int)min ); - mypInteger->setMaxValue( (int)max ); - int aStep = (int)step; - if ( aStep > 0 ) - mypInteger->setLineStep( aStep ); -} - -void SalomeApp_ResourceEditor::IntegerSpinItem::Store() -{ - int type; - QString key, label; - QString sect = Get( key, type, label ); - if ( !sect.isEmpty() ) - SetInteger( sect, key, mypInteger->value() ); -} - -void SalomeApp_ResourceEditor::IntegerSpinItem::Retrieve() -{ - int val, type; - QString key, label; - QString sect = Get( key, type, label ); - if ( !sect.isEmpty() && GetInteger( sect, key, val ) ) - mypInteger->setValue( val ); -} - -/* - Class: SalomeApp_ResourceEditor::IntegerEditItem - Descr: GUI implementation of resources integer item. -*/ - -SalomeApp_ResourceEditor::IntegerEditItem::IntegerEditItem - ( SalomeApp_ResourceEditor* ed, QWidget* parent ) -: Item( ed ) -{ - mypName = new QLabel( parent ); - mypInteger = new QLineEdit( parent ); - mypInteger->setValidator( new QIntValidator( mypInteger ) ); -} - -SalomeApp_ResourceEditor::IntegerEditItem::~IntegerEditItem() -{ -} - -void SalomeApp_ResourceEditor::IntegerEditItem::Set( const QString& sect, const QString& key, - const int type, const QString& label ) -{ - Item::Set( sect, key, type, label ); - mypName->setText( label ); -} - -void SalomeApp_ResourceEditor::IntegerEditItem::Store() -{ - int type; - QString key, label; - QString sect = Get( key, type, label ); - if ( !sect.isEmpty() ) - SetInteger( sect, key, mypInteger->text().toInt() ); -} - -void SalomeApp_ResourceEditor::IntegerEditItem::Retrieve() -{ - int val, type; - QString key, label; - QString sect = Get( key, type, label ); - if ( !sect.isEmpty() && GetInteger( sect, key, val ) ) - mypInteger->setText( QString().setNum( val ) ); -} - -/* - Class: SalomeApp_ResourceEditor::Spacing - Descr: GUI implementation of resources spacer. -*/ - -SalomeApp_ResourceEditor::Spacing::Spacing( SalomeApp_ResourceEditor* ed, QWidget* parent ) -: Item( ed ) -{ - new QLabel( parent ); - new QLabel( parent ); -} - -SalomeApp_ResourceEditor::Spacing::~Spacing() -{ -} - -void SalomeApp_ResourceEditor::Spacing::Store() -{ -} - -void SalomeApp_ResourceEditor::Spacing::Retrieve() -{ -} - -/* - Class: SalomeApp_ResourceEditor::PrefGroup - Descr: GUI implementation of resources group. -*/ - -SalomeApp_ResourceEditor::PrefGroup::PrefGroup( const QString& name, - SalomeApp_ResourceEditor* ed, - QWidget* parent ) -: QGroupBox( 4, Qt::Horizontal, name, parent ), - Group( name ), - myEditor( ed ) -{ -} - -SalomeApp_ResourceEditor::PrefGroup::~PrefGroup() -{ -} - -void SalomeApp_ResourceEditor::PrefGroup::SetColumns( const int cols ) -{ - setColumns( 2 * cols ); -} - -void SalomeApp_ResourceEditor::PrefGroup::SetTitle( const QString& title ) -{ - setTitle( title ); -} - -SalomeApp_ResourceEditor::Item* SalomeApp_ResourceEditor::PrefGroup::createItem( const int type, const QString& label ) -{ - Item* item = 0; - - switch ( type ) - { - case Color: - item = new ColorItem( myEditor, this ); - break; - case Bool: - item = new StateItem( myEditor, this ); - break; - case String: - item = new StringItem( myEditor, this ); - break; - case List: - item = new ListItem( myEditor, this ); - break; - case RealSpin: - item = new DoubleSpinItem( myEditor, this ); - break; - case IntegerSpin: - item = new IntegerSpinItem( myEditor, this ); - break; - case RealEdit: - item = new DoubleEditItem( myEditor, this ); - break; - case IntegerEdit: - item = new IntegerEditItem( myEditor, this ); - break; - case Space: - item = new Spacing( myEditor, this ); - break; - } - - return item; -} - -/* - Class: SalomeApp_ResourceEditor::PrefTab - Descr: GUI implementation of resources tab. -*/ - -SalomeApp_ResourceEditor::PrefTab::PrefTab( const QString& name, - SalomeApp_ResourceEditor* ed, - QTabWidget* parent ) -: QFrame( parent ), -Tab( name ), -mypTabWidget( parent ), -myEditor( ed ) -{ - QVBoxLayout* main = new QVBoxLayout( this ); - mypMainFrame = new QGroupBox( 1, Qt::Horizontal, "", this ); - mypMainFrame->setFrameStyle( QFrame::NoFrame ); - mypMainFrame->setInsideMargin( 5 ); - main->addWidget( mypMainFrame ); -} - -SalomeApp_ResourceEditor::PrefTab::~PrefTab() -{ -} - -void SalomeApp_ResourceEditor::PrefTab::SetTitle( const QString& title ) -{ - if ( !mypTabWidget ) - return; - - mypTabWidget->setTabLabel( this, title ); -} - -void SalomeApp_ResourceEditor::PrefTab::adjustLabels() -{ - QObjectList* labels = queryList( "QLabel" ); - if ( labels ) - { - int w = 0; - for ( QObjectListIt it1( *labels ); it1.current(); ++it1 ) - { - if ( it1.current()->isWidgetType() ) - { - QWidget* wid = (QWidget*)it1.current(); - w = QMAX( w, wid->sizeHint().width() ); - } - } - for ( QObjectListIt it2( *labels ); it2.current(); ++it2 ) - { - if ( it2.current()->isWidgetType() ) - { - QWidget* wid = (QWidget*)it2.current(); - wid->setMinimumWidth( w ); - } - } - delete labels; - } -} - -SalomeApp_ResourceEditor::Group* SalomeApp_ResourceEditor::PrefTab::createGroup( const QString& name ) -{ - return new PrefGroup( name, myEditor, mypMainFrame ); -} - - -/* - Class: SalomeApp_ResourceEditor::PrefCategory - Descr: GUI implementation of preferences category. -*/ - -SalomeApp_ResourceEditor::PrefCategory::PrefCategory( const QString& name, - SalomeApp_ResourceEditor* ed, - QListBox* listBox, - QWidgetStack* parent ) -: QTabWidget( parent ), -Category( name ), -mypListBox( listBox ), -mypWidgetStack( parent ), -myEditor( ed ) -{ -} - -SalomeApp_ResourceEditor::PrefCategory::~PrefCategory() -{ -} - -void SalomeApp_ResourceEditor::PrefCategory::SetTitle( const QString& title ) -{ - if ( !mypWidgetStack || !mypListBox ) - return; - - int id = mypWidgetStack->id( this ); - if ( id < 0 ) - return; - - //int idx = mypListBox->index( mypListBox->selectedItem() ); - int idx = mypListBox->currentItem(); - - mypListBox->changeItem( title, id ); - mypListBox->setSelected( idx, true ); -} - -void SalomeApp_ResourceEditor::PrefCategory::adjustLabels() -{ - for ( int i = 0; i < count(); i++ ) - { - QWidget* wid = page( i ); - if ( wid ) - { - PrefTab* tab = (PrefTab*)wid; - tab->adjustLabels(); - } - } -} - -SalomeApp_ResourceEditor::Tab* SalomeApp_ResourceEditor::PrefCategory::createTab( const QString& name ) -{ - PrefTab* aTab = new PrefTab( name, myEditor, this ); - addTab( aTab, name ); - return aTab; -} - -//======================================================================= -//function : SalomeApp_ResourceEditor -//purpose : -//======================================================================= - -SalomeApp_ResourceEditor::SalomeApp_ResourceEditor( QtxResourceMgr* theMgr, - QWidget* theParent ) -: QtxDialog( theParent, 0, true, false, Standard | Apply ), - QtxResourceEditor( theMgr ) -{ - setCaption( tr( "CAPTION" ) ); - - QHBoxLayout* main = new QHBoxLayout( mainFrame(), 5, 5 ); - - mypCatList = new QListBox( mainFrame() ); - mypCatStack = new QWidgetStack( mainFrame() ); - - main->addWidget( mypCatList ); - main->addWidget( mypCatStack ); - - mypCatList->setSelectionMode( QListBox::Single ); - - //int defId = addUserButton( tr( "DEFAULT" ) ); - //QButton* defButton = userButton( defId ); - - //if ( defId != -1 ) - // setUserButtonPosition( Right, defId ); - - setTabOrder( button( OK ), button( Cancel ), - /*defButton,*/ button( Help ), 0 ); - - connect( this, SIGNAL( dlgHelp() ), this, SLOT( onHelp() ) ); - connect( this, SIGNAL( dlgApply() ), this, SLOT( onApply() ) ); - connect( mypCatList, SIGNAL( selectionChanged() ), this, SLOT( onSelectionChanged() ) ); - -/* if ( defButton ) - connect( defButton, SIGNAL( clicked() ), this, SLOT( onDefault() ) );*/ - - setFocusProxy( mypCatList ); -} - -//======================================================================= -//function : ~SalomeApp_ResourceEditor -//purpose : -//======================================================================= - -SalomeApp_ResourceEditor::~SalomeApp_ResourceEditor() -{ -} - -//======================================================================= -//function : show -//purpose : -//======================================================================= - -void SalomeApp_ResourceEditor::show() -{ - SUIT_OverrideCursor c; - - setAlignment( 0 ); -/* - for ( QPtrListIterator it( categories() ); it.current(); ++it ) - { - PrefCategory* aCat = (PrefCategory*)it.current(); - aCat->adjustLabels(); - } -*/ - Update(); // update all tabs, groups, items. - -// Backup(); - Retrieve(); - - QtxDialog::show(); -} - -//======================================================================= -//function : accept -//purpose : -//======================================================================= - -void SalomeApp_ResourceEditor::accept() -{ - SUIT_OverrideCursor c; - - QtxDialog::accept(); - - Store(); - updateViewer(); -} - -//======================================================================= -//function : reject -//purpose : -//======================================================================= - -void SalomeApp_ResourceEditor::reject() -{ - SUIT_OverrideCursor c; - - QtxDialog::reject(); - -// Restore(); - updateViewer(); -} - -//======================================================================= -//function : onHelp -//purpose : -//======================================================================= - -void SalomeApp_ResourceEditor::onHelp() -{ - /*LH3DGui_Desktop* desk = LH3DGui_Desktop::getDesktop(); - if ( desk ) - { - LH3DGui_Helper* helper = desk->getHelper(); - if ( helper ) - helper->ShowPage( "preferences" ); - }*/ -} - -//======================================================================= -//function : onApply -//purpose : -//======================================================================= - -void SalomeApp_ResourceEditor::onApply() -{ - SUIT_OverrideCursor c; - - Store(); - updateViewer(); -} - -//======================================================================= -//function : onSelectionChanged -//purpose : -//======================================================================= - -void SalomeApp_ResourceEditor::onSelectionChanged() -{ - //int index = mypCatList->index( mypCatList->selectedItem() ); - int index = mypCatList->currentItem(); - if ( index < 0 ) - return; - - mypCatStack->raiseWidget( index ); -} - -//======================================================================= -//function : updateViewer -//purpose : -//======================================================================= - -void SalomeApp_ResourceEditor::updateViewer() -{ -/* LH3DGui_Desktop* desktop = LH3DGui_Desktop::getDesktop(); - if ( !desktop ) - return; - - LH3DGui_Modeler* active = desktop->getActiveModeler(); - if ( !active ) - return; - - active->Update( LH3DGui_Desktop::Viewer3d ); - if ( desktop->getViewer3d() ) - desktop->getViewer3d()->update();*/ -} - -//======================================================================= -//function : createCategory -//purpose : -//======================================================================= - -SalomeApp_ResourceEditor::Category* SalomeApp_ResourceEditor::createCategory( const QString& name ) -{ - PrefCategory* aCat = new PrefCategory( name, this, mypCatList, mypCatStack ); - mypCatList->insertItem( name ); - int id = mypCatList->count() - 1; - mypCatStack->addWidget( aCat, id ); - - if ( !mypCatList->currentItem() ) - mypCatList->setSelected( 0, true ); - - return aCat; -} - -//======================================================================= -//function : setTabOrder -//purpose : -//======================================================================= - -void SalomeApp_ResourceEditor::setTabOrder( QObject* first, ... ) -{ - va_list objs; - va_start( objs, first ); - - QObjectList objList; - - QObject* cur = first; - while ( cur ) - { - objList.append( cur ); - cur = va_arg( objs, QObject* ); - } - - setTabOrder( objList ); -} - -//======================================================================= -//function : setTabOrder -//purpose : -//======================================================================= - -void SalomeApp_ResourceEditor::setTabOrder( const QObjectList& objs ) -{ - QPtrList widgets; - - for ( QObjectListIt it( objs ); it.current(); ++it ) - { - QWidget* wid = 0; - QObject* cur = *it; - if ( cur->isWidgetType() ) - wid = (QWidget*)cur; - if ( wid ) - widgets.append( wid ); - } - - if ( widgets.count() < 2 ) - return; - - QWidget* prev = widgets.first(); - for ( QWidget* next = widgets.at( 1 ); next; next = widgets.next() ) - { - QWidget::setTabOrder( prev, next ); - prev = next; - } -} - - - - -ColorButton::ColorButton( QWidget* parent ) -: QPushButton( parent ) -{ - connect( this, SIGNAL( clicked() ), this, SLOT( onColor() ) ); -} - -ColorButton::~ColorButton() -{ -} - -void ColorButton::onColor() -{ - setDown( true ); - - QColor c = QColorDialog::getColor( paletteBackgroundColor(), this ); - if ( c.isValid() ) - setPaletteBackgroundColor( c ); - - setDown( false ); -} - diff --git a/src/SalomeApp/SalomeApp_ResourceEditor.h b/src/SalomeApp/SalomeApp_ResourceEditor.h deleted file mode 100755 index 73f4d3842..000000000 --- a/src/SalomeApp/SalomeApp_ResourceEditor.h +++ /dev/null @@ -1,291 +0,0 @@ -// File: SalomeApp_ResourceEditor.h -// Created: -// Author: Alexander Sladkov -// Copyright: - -#ifndef SALOMEAPP_RESOURCEEDITOR_H -#define SALOMEAPP_RESOURCEEDITOR_H - -#include -#include -#include -#include -#include - -class QLabel; -class QListBox; -class QSpinBox; -class QLineEdit; -class QCheckBox; -class QComboBox; -class QWidgetStack; - -class QtxDblSpinBox; - -/* - Class: SalomeApp_ResourceEditor - Descr: GUI implementation of QtxResourceEditor - manager of resources -*/ - -#include -#include -#include - -class SALOMEAPP_EXPORT SalomeApp_ResourceEditor : - public QtxDialog, public QtxResourceEditor -{ - Q_OBJECT - -public: - class PrefTab; - class PrefGroup; - class PrefCategory; - - class Spacing; - class ListItem; - class ColorItem; - class StateItem; - class StringItem; - class DoubleSpinItem; - class DoubleEditItem; - class DataDoubleEditItem; - class IntegerSpinItem; - class IntegerEditItem; - -public: - SalomeApp_ResourceEditor( QtxResourceMgr*, QWidget* = 0 ); - virtual ~SalomeApp_ResourceEditor(); - - virtual void show(); - virtual void accept(); - virtual void reject(); - -private slots: - void onHelp(); - void onApply(); - //void onDefault(); - void onSelectionChanged(); - -protected: - virtual Category* createCategory( const QString& ); - virtual void updateViewer(); - - void setTabOrder( QObject*, ... ); - void setTabOrder( const QObjectList& ); - -private: - QListBox* mypCatList; - QWidgetStack* mypCatStack; -}; - -class SalomeApp_ResourceEditor::Spacing : public Item -{ -public: - Spacing( SalomeApp_ResourceEditor*, QWidget* = 0 ); - virtual ~Spacing(); - - virtual void Store(); - virtual void Retrieve(); -}; - -class SalomeApp_ResourceEditor::ListItem : public Item -{ -public: - ListItem( SalomeApp_ResourceEditor*, QWidget* = 0 ); - virtual ~ListItem(); - - virtual void Set( const QString&, const QString&, const int, const QString& ); - virtual void SetList( const QValueList&, const QStringList& ); - virtual void Store(); - virtual void Retrieve(); - -private: - QLabel* mypName; - QComboBox* mypList; - QMap myIndex; -}; - - -class SalomeApp_ResourceEditor::ColorItem : public Item -{ -public: - ColorItem( SalomeApp_ResourceEditor*, QWidget* = 0 ); - virtual ~ColorItem(); - - virtual void Set( const QString&, const QString&, const int, const QString& ); - virtual void Store(); - virtual void Retrieve(); - -private: - QLabel* mypName; - QPushButton* mypColor; -}; - - -class SalomeApp_ResourceEditor::StateItem : public Item -{ -public: - StateItem( SalomeApp_ResourceEditor*, QWidget* = 0 ); - virtual ~StateItem(); - - virtual void Set( const QString&, const QString&, const int, const QString& ); - virtual void Store(); - virtual void Retrieve(); - -private: - QLabel* mypName; - QCheckBox* mypState; -}; - - -class SalomeApp_ResourceEditor::StringItem : public Item -{ -public: - StringItem( SalomeApp_ResourceEditor*, QWidget* = 0 ); - virtual ~StringItem(); - - virtual void Set( const QString&, const QString&, const int, const QString& ); - virtual void Store(); - virtual void Retrieve(); - -private: - QLabel* mypName; - QLineEdit* mypString; -}; - - -class SalomeApp_ResourceEditor::DoubleSpinItem : public Item -{ -public: - DoubleSpinItem( SalomeApp_ResourceEditor*, QWidget* = 0 ); - virtual ~DoubleSpinItem(); - - virtual void Set( const QString&, const QString&, const int, const QString& ); - virtual void SetRange( const double, const double, const double = 3, const double = -1 ); - virtual void Store(); - virtual void Retrieve(); - -private: - QLabel* mypName; - QtxDblSpinBox* mypDouble; -}; - - -class SalomeApp_ResourceEditor::DoubleEditItem : public Item -{ -public: - DoubleEditItem( SalomeApp_ResourceEditor*, QWidget* = 0); - virtual ~DoubleEditItem(); - - virtual void Set( const QString&, const QString&, const int, const QString& ); - virtual void Store(); - virtual void Retrieve(); - -private: - QLabel* mypName; - QLineEdit* mypDouble; -}; - - -class SalomeApp_ResourceEditor::IntegerSpinItem : public Item -{ -public: - IntegerSpinItem( SalomeApp_ResourceEditor*, QWidget* = 0 ); - virtual ~IntegerSpinItem(); - - virtual void Set( const QString&, const QString&, const int, const QString& ); - virtual void SetRange( const double, const double, const double = 3, const double = -1 ); - virtual void Store(); - virtual void Retrieve(); - -private: - QLabel* mypName; - QSpinBox* mypInteger; -}; - - -class SalomeApp_ResourceEditor::IntegerEditItem : public Item -{ -public: - IntegerEditItem( SalomeApp_ResourceEditor*, QWidget* = 0 ); - virtual ~IntegerEditItem(); - - virtual void Set( const QString&, const QString&, const int, const QString& ); - virtual void Store(); - virtual void Retrieve(); - -private: - QLabel* mypName; - QLineEdit* mypInteger; -}; - -class SalomeApp_ResourceEditor::PrefGroup : public QGroupBox, public Group -{ -public: - PrefGroup( const QString&, SalomeApp_ResourceEditor*, QWidget* = 0 ); - virtual ~PrefGroup(); - - virtual void SetColumns( const int ); - virtual void SetTitle( const QString& ); - -protected: - virtual Item* createItem( const int, const QString& = QString::null ); - -private: - SalomeApp_ResourceEditor* myEditor; -}; - - -class SalomeApp_ResourceEditor::PrefTab : public QFrame, public Tab -{ -public: - PrefTab( const QString&, SalomeApp_ResourceEditor*, QTabWidget* ); - virtual ~PrefTab(); - - virtual void SetTitle( const QString& ); - - void adjustLabels(); - -protected: - virtual Group* createGroup( const QString& ); - -private: - QTabWidget* mypTabWidget; - QGroupBox* mypMainFrame; - SalomeApp_ResourceEditor* myEditor; -}; - - -class SalomeApp_ResourceEditor::PrefCategory : public QTabWidget, public Category -{ -public: - PrefCategory( const QString&, SalomeApp_ResourceEditor*, QListBox*, QWidgetStack* ); - virtual ~PrefCategory(); - - virtual void SetTitle( const QString& ); - - void adjustLabels(); - -protected: - virtual Tab* createTab( const QString& ); - -private: - QListBox* mypListBox; - QWidgetStack* mypWidgetStack; - SalomeApp_ResourceEditor* myEditor; -}; - - -class ColorButton : public QPushButton -{ - Q_OBJECT - -public: - ColorButton( QWidget* = 0 ); - virtual ~ColorButton(); - -private slots: - void onColor(); -}; - -#endif diff --git a/src/SalomeApp/SalomeApp_Study.cxx b/src/SalomeApp/SalomeApp_Study.cxx index 0ba477280..0d6c28ae5 100644 --- a/src/SalomeApp/SalomeApp_Study.cxx +++ b/src/SalomeApp/SalomeApp_Study.cxx @@ -144,14 +144,15 @@ bool SalomeApp_Study::saveDocumentAs( const QString& theFileName ) for ( ; aModel; aModel = (SalomeApp_DataModel*)list.next() ) aModel->saveAs( theFileName, this ); - bool res = CAM_Study::saveDocumentAs( theFileName ); - // save SALOMEDS document bool isMultiFile = false, isAscii = false;// TODO: This information should be taken from preferences afterwards! - isAscii ? SalomeApp_Application::studyMgr()->SaveAsASCII( theFileName.latin1(), studyDS(), isMultiFile ) : - SalomeApp_Application::studyMgr()->SaveAs ( theFileName.latin1(), studyDS(), isMultiFile ); + /* bool res = */isAscii ? SalomeApp_Application::studyMgr()->SaveAsASCII( theFileName.latin1(), studyDS(), isMultiFile ) : + SalomeApp_Application::studyMgr()->SaveAs ( theFileName.latin1(), studyDS(), isMultiFile ); - emit saved( this ); + bool res = res && CAM_Study::saveDocumentAs( theFileName ); + + if ( res ) + emit saved( this ); return res; }