From 18c1ccc660e6897da9c28e91ed65377b1907b431 Mon Sep 17 00:00:00 2001 From: vsr Date: Wed, 8 May 2019 13:02:35 +0300 Subject: [PATCH] IPAL54545: Problem with Preferences dialog if HOMARD module is before YACS in the list --- src/CAM/CAM_Application.cxx | 74 ++++----------------- src/CAM/CAM_Application.h | 2 - src/LightApp/LightApp_Application.cxx | 92 +++++++++++++++------------ src/LightApp/LightApp_Application.h | 1 + src/LightApp/LightApp_Preferences.cxx | 24 +++++-- src/LightApp/LightApp_Preferences.h | 4 +- src/SUIT/SUIT_PreferenceMgr.cxx | 26 +++++--- src/SUIT/SUIT_PreferenceMgr.h | 1 + 8 files changed, 101 insertions(+), 123 deletions(-) diff --git a/src/CAM/CAM_Application.cxx b/src/CAM/CAM_Application.cxx index 550a80590..61d979ea5 100644 --- a/src/CAM/CAM_Application.cxx +++ b/src/CAM/CAM_Application.cxx @@ -268,9 +268,6 @@ void CAM_Application::loadModules() { for ( ModuleInfoList::const_iterator it = myInfoList.begin(); it != myInfoList.end(); ++it ) { - if ( !isModuleAccessible( (*it).title ) ) { - continue; - } CAM_Module* mod = loadModule( (*it).title ); if ( mod ) addModule( mod ); @@ -303,11 +300,6 @@ CAM_Module* CAM_Application::loadModule( const QString& modName, const bool show return 0; } - if ( !isModuleAccessible( modName ) ) { - qWarning( qPrintable( tr( "Module \"%1\" cannot be loaded in this application." ).arg( modName ) ) ); - return 0; - } - QString libName = moduleLibrary( modName ); if ( libName.isEmpty() ) { @@ -495,12 +487,10 @@ bool CAM_Application::activateModule( CAM_Module* mod ) */ bool CAM_Application::activateOperation( const QString& modName, int actionId ) { - if (isModuleAccessible(modName)) { - CAM_Module* mod = loadModule(modName, false); - if (mod) { - addModule(mod); - return mod->activateOperation(actionId); - } + CAM_Module* mod = loadModule(modName, false); + if (mod) { + addModule(mod); + return mod->activateOperation(actionId); } return false; } @@ -514,12 +504,10 @@ bool CAM_Application::activateOperation( const QString& modName, int actionId ) */ bool CAM_Application::activateOperation( const QString& modName, const QString& actionId ) { - if (isModuleAccessible(modName)) { - CAM_Module* mod = loadModule(modName, false); - if (mod) { - addModule(mod); - return mod->activateOperation(actionId); - } + CAM_Module* mod = loadModule(modName, false); + if (mod) { + addModule(mod); + return mod->activateOperation(actionId); } return false; } @@ -537,12 +525,10 @@ bool CAM_Application::activateOperation( const QString& modName, const QString& actionId, const QString& pluginName ) { - if (isModuleAccessible(modName)) { - CAM_Module* mod = loadModule(modName, false); - if (mod) { - addModule(mod); - return mod->activateOperation(actionId, pluginName); - } + CAM_Module* mod = loadModule(modName, false); + if (mod) { + addModule(mod); + return mod->activateOperation(actionId, pluginName); } return false; } @@ -666,40 +652,6 @@ QString CAM_Application::moduleIcon( const QString& name ) return res; } -/*! - \brief Returns \c true if module is accessible for the current application. - Singleton module can be loaded only in one application object. In other application - objects this module will be unavailable. - \param title module title (user name) - \return \c true if module is accessible (can be loaded) or \c false otherwise - */ -bool CAM_Application::isModuleAccessible( const QString& title ) -{ - bool found = false; - bool blocked = false; - bool statusOK = false; - - QStringList somewhereLoaded; - QList apps = SUIT_Session::session()->applications(); - foreach( SUIT_Application* app, apps ) { - CAM_Application* camApp = dynamic_cast( app ); - if ( !camApp ) continue; - QStringList loaded; - camApp->modules( loaded, true ); - foreach( QString lm, loaded ) { - if ( !somewhereLoaded.contains( lm ) ) somewhereLoaded << lm; - } - } - - for ( ModuleInfoList::const_iterator it = myInfoList.begin(); it != myInfoList.end() && !found; ++it ) - { - found = (*it).title == title; - blocked = (*it).isSingleton && somewhereLoaded.contains((*it).title); - statusOK = (*it).status == stReady; - } - return found && statusOK && !blocked; -} - /*! \brief Get module library name by its title (user name). \param title module title (user name) @@ -835,7 +787,6 @@ void CAM_Application::readModuleList() else modLibrary = modName; - bool aIsSingleton = resMgr->booleanValue( *it, "singleton", false ); bool hasGui = resMgr->booleanValue( *it, "gui", true ); QString version = resMgr->stringValue( *it, "version", QString() ); @@ -845,7 +796,6 @@ void CAM_Application::readModuleList() inf.status = hasGui ? stUnknown : stNoGui; if ( hasGui ) inf.library = modLibrary; inf.icon = modIcon; - inf.isSingleton = aIsSingleton; inf.version = version; myInfoList.append( inf ); } diff --git a/src/CAM/CAM_Application.h b/src/CAM/CAM_Application.h index a2e8e4bfb..2fbc4b4b6 100644 --- a/src/CAM/CAM_Application.h +++ b/src/CAM/CAM_Application.h @@ -75,7 +75,6 @@ public: static QString moduleTitle( const QString& ); static QString moduleIcon( const QString& ); static QString moduleLibrary( const QString&, const bool = true ); - static bool isModuleAccessible( const QString& ); virtual void createEmptyStudy(); @@ -102,7 +101,6 @@ private: enum { stUnknown = 0, stNoGui, stInaccessible, stReady }; typedef struct { QString name, title, icon, library, version; - bool isSingleton; int status; } ModuleInfo; typedef QList ModuleInfoList; diff --git a/src/LightApp/LightApp_Application.cxx b/src/LightApp/LightApp_Application.cxx index 61e47b757..de5d7a161 100644 --- a/src/LightApp/LightApp_Application.cxx +++ b/src/LightApp/LightApp_Application.cxx @@ -790,9 +790,6 @@ void LightApp_Application::createActions() QStringList::Iterator it; for ( it = modList.begin(); it != modList.end(); ++it ) { - if ( !isModuleAccessible( *it ) ) - continue; - QString modName = moduleName( *it ); QString iconName; @@ -1244,8 +1241,12 @@ void LightApp_Application::showHelp( const QString& path ) if ( SUIT_MessageBox::question( desktop(), tr( "WRN_WARNING" ), tr( "DEFINE_EXTERNAL_BROWSER" ), SUIT_MessageBox::Yes | SUIT_MessageBox::No, SUIT_MessageBox::Yes ) == SUIT_MessageBox::Yes ) - - showPreferences( tr( "PREF_APP" ) ); + { + QStringList path; + path << tr( "PREF_CATEGORY_SALOME" ) << tr( "PREF_TAB_GENERAL" ) + << tr( "PREF_GROUP_EXT_BROWSER" ) << tr( "PREF_APP" ); + showPreferences( path ); + } } } else @@ -1975,7 +1976,12 @@ void LightApp_Application::onPreferences() } /*!Private SLOT. On preferences.*/ -void LightApp_Application::showPreferences( const QString& itemText ) +void LightApp_Application::showPreferences( const QString& path ) +{ + showPreferences( QStringList() << path ); +} + +void LightApp_Application::showPreferences( const QStringList& path ) { QApplication::setOverrideCursor( Qt::WaitCursor ); @@ -1986,7 +1992,7 @@ void LightApp_Application::showPreferences( const QString& itemText ) if ( !prefDlg ) return; - preferences()->activateItem( itemText ); + preferences()->activateItem( path ); if ( ( prefDlg->exec() == QDialog::Accepted || prefDlg->isSaved() ) && resourceMgr() ) { @@ -2194,42 +2200,48 @@ LightApp_Preferences* LightApp_Application::preferences( const bool crt ) const if ( !app ) continue; - QStringList modNameList; - app->modules( modNameList, false ); + // all modules available in current session + QStringList names; + app->modules( names, false ); - QMap iconMap; - app->moduleIconNames( iconMap ); + // icons of modules + QMap icons; + app->moduleIconNames( icons ); - for ( QStringList::const_iterator it = modNameList.begin(); it != modNameList.end(); ++it ) + // step 1: iterate through list of all available modules + // and add empty preferences page + for ( QStringList::const_iterator it = names.begin(); it != names.end(); ++it ) { - if ( !app->isModuleAccessible( *it ) || _prefs_->hasModule( *it ) ) - continue; - - int modId = _prefs_->addPreference( *it ); - if ( iconMap.contains( *it ) ) - _prefs_->setItemIcon( modId, Qtx::scaleIcon( resMgr->loadPixmap( moduleName( *it ), iconMap[*it], false ), 20 ) ); + if ( !_prefs_->hasModule( *it ) ) // prevent possible duplications + { + int modId = _prefs_->addPreference( *it ); // add empty page + if ( icons.contains( *it ) ) // set icon + _prefs_->setItemIcon( modId, Qtx::scaleIcon( resMgr->loadPixmap( moduleName( *it ), + icons[*it], false ), 20 ) ); + } } - ModuleList modList; - app->modules( modList ); - QListIterator itr( modList ); + // step 2: iterate through list of all loaded modules + // and initialize their preferences + ModuleList loadedModules; + app->modules( loadedModules ); + QListIterator itr( loadedModules ); while ( itr.hasNext() ) { - LightApp_Module* mod = 0; + LightApp_Module* module = 0; + CAM_Module* m = itr.next(); + if ( m->inherits( "LightApp_Module" ) ) + module = (LightApp_Module*)m; - CAM_Module* anItem = itr.next(); - if ( anItem->inherits( "LightApp_Module" ) ) - mod = (LightApp_Module*)anItem; - - if ( mod && !_prefs_->hasModule( mod->moduleName() ) ) + if ( module && !_prefs_->hasModule( module->moduleName() ) ) { - _prefs_->addPreference( mod->moduleName() ); - mod->createPreferences(); - that->emptyPreferences( mod->moduleName() ); + _prefs_->addPreference( module->moduleName() ); // add page (for sure, had to be done at step 1) + module->createPreferences(); // initialize preferences + that->emptyPreferences( module->moduleName() ); // show dummy page if module does not export any preferences } } } - _prefs_->setItemProperty( "info", tr( "PREFERENCES_NOT_LOADED" ) ); + _prefs_->setItemProperty( "info", tr( "PREFERENCES_NOT_LOADED" ) ); // dummy page for modules which are not loaded yet return myPrefs; } @@ -3929,17 +3941,8 @@ void LightApp_Application::afterCloseDoc() void LightApp_Application::updateModuleActions() { QString modName; - if ( activeModule() ) { + if ( activeModule() ) modName = activeModule()->moduleName(); - if ( !isModuleAccessible( modName ) ) { - QList apps = SUIT_Session::session()->applications(); - foreach( SUIT_Application* app, apps ) { - LightApp_Application* lapp = dynamic_cast( app ); - if ( lapp && lapp != this ) - lapp->removeModuleAction( modName ); - } - } - } LightApp_ModuleAction* moduleAction = qobject_cast( action( ModulesListId ) ); @@ -4614,7 +4617,12 @@ bool LightApp_Application::event( QEvent* e ) d ? *d : "", SUIT_MessageBox::Yes | SUIT_MessageBox::No, SUIT_MessageBox::Yes ) == SUIT_MessageBox::Yes ) - showPreferences( tr( "PREF_APP" ) ); + { + QStringList path; + path << tr( "PREF_CATEGORY_SALOME" ) << tr( "PREF_TAB_GENERAL" ) + << tr( "PREF_GROUP_EXT_BROWSER" ) << tr( "PREF_APP" ); + showPreferences( path ); + } if( d ) delete d; return true; diff --git a/src/LightApp/LightApp_Application.h b/src/LightApp/LightApp_Application.h index 82668bfad..66a9032b3 100644 --- a/src/LightApp/LightApp_Application.h +++ b/src/LightApp/LightApp_Application.h @@ -307,6 +307,7 @@ protected: virtual bool openAction( const int, const QString& ); void showPreferences( const QString& = QString() ); + void showPreferences( const QStringList& ); private: void emptyPreferences( const QString& ); diff --git a/src/LightApp/LightApp_Preferences.cxx b/src/LightApp/LightApp_Preferences.cxx index bd53c897a..658928f57 100644 --- a/src/LightApp/LightApp_Preferences.cxx +++ b/src/LightApp/LightApp_Preferences.cxx @@ -72,15 +72,25 @@ bool LightApp_Preferences::hasModule( const QString& mod ) const return res; } -void LightApp_Preferences::activateItem( const QString& mod ) const +void LightApp_Preferences::activateItem( const QString& path ) { - QtxPreferenceItem* item = findItem( mod, true ); - - if ( !item ) - return; + activateItem( QStringList() << path ); +} - item->ensureVisible(); - item->activate(); +void LightApp_Preferences::activateItem( const QStringList& path ) +{ + QtxPreferenceItem* item = root(); + foreach( QString label, path ) + { + if ( !item ) + break; + item = item->findItem( label, false ); + } + if ( item ) + { + item->ensureVisible(); + item->activate(); + } } /*!Do nothing.*/ diff --git a/src/LightApp/LightApp_Preferences.h b/src/LightApp/LightApp_Preferences.h index 4f04942a0..accbe9b4a 100644 --- a/src/LightApp/LightApp_Preferences.h +++ b/src/LightApp/LightApp_Preferences.h @@ -30,6 +30,7 @@ #include #include +#include class QtxResourceMgr; @@ -53,7 +54,8 @@ public: bool hasModule( const QString& ) const; - void activateItem( const QString& ) const; + void activateItem( const QString& ); + void activateItem( const QStringList& ); protected: void changedResources( const ResourceMap& ); diff --git a/src/SUIT/SUIT_PreferenceMgr.cxx b/src/SUIT/SUIT_PreferenceMgr.cxx index d1bf51b9d..91d0175c7 100644 --- a/src/SUIT/SUIT_PreferenceMgr.cxx +++ b/src/SUIT/SUIT_PreferenceMgr.cxx @@ -70,23 +70,26 @@ int SUIT_PreferenceMgr::addItem( const QString& title, const int pId, const SUIT_PreferenceMgr::PrefItemType type, const QString& sect, const QString& param ) { - QtxPreferenceItem* parent = pId == -1 ? this : findItem( pId, true ); + QtxPreferenceItem* parent = 0; + if ( pId == -1 ) + { + if ( !myRoot ) + myRoot = new QtxPagePrefListItem( QString( "root" ), this ); + parent = myRoot; + } + else + { + parent = findItem( pId, true ); + } if ( !parent ) return -1; - QtxPreferenceItem* item = parent->findItem( title, true ); + QtxPreferenceItem* item = parent->findItem( title, false ); if ( item && item->depth() < 5 ) return item->id(); - if ( pId == -1 ) - { - if ( !myRoot ) - myRoot = new QtxPagePrefListItem( QString( "root" ), this ); - parent = myRoot; - } - switch( type ) { case Auto: @@ -185,3 +188,8 @@ void SUIT_PreferenceMgr::setOptionValue( const QString& name, const QVariant& va if ( myRoot ) myRoot->setOption( name, val ); } + +QtxPreferenceItem* SUIT_PreferenceMgr::root() const +{ + return myRoot; +} diff --git a/src/SUIT/SUIT_PreferenceMgr.h b/src/SUIT/SUIT_PreferenceMgr.h index 541d319a3..1797c4495 100644 --- a/src/SUIT/SUIT_PreferenceMgr.h +++ b/src/SUIT/SUIT_PreferenceMgr.h @@ -57,6 +57,7 @@ public: protected: virtual QVariant optionValue( const QString& ) const; virtual void setOptionValue( const QString&, const QVariant& ); + QtxPreferenceItem* root() const; private: QtxPreferenceItem* myRoot; -- 2.39.2