Salome HOME
IPAL54545: Problem with Preferences dialog if HOMARD module is before YACS in the...
authorvsr <vsr@opencascade.com>
Wed, 8 May 2019 10:02:35 +0000 (13:02 +0300)
committervsr <vsr@opencascade.com>
Wed, 8 May 2019 10:04:14 +0000 (13:04 +0300)
src/CAM/CAM_Application.cxx
src/CAM/CAM_Application.h
src/LightApp/LightApp_Application.cxx
src/LightApp/LightApp_Application.h
src/LightApp/LightApp_Preferences.cxx
src/LightApp/LightApp_Preferences.h
src/SUIT/SUIT_PreferenceMgr.cxx
src/SUIT/SUIT_PreferenceMgr.h

index 550a80590c3d66052a25278009fe7210fa79a193..61d979ea59e5aac6f81e7d78338ff7e1e319a2fa 100644 (file)
@@ -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<SUIT_Application*> apps = SUIT_Session::session()->applications();
-  foreach( SUIT_Application* app, apps ) {
-    CAM_Application* camApp = dynamic_cast<CAM_Application*>( 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 );
   }
index a2e8e4bfb828b9bfccb87c476bae25f11f24a81d..2fbc4b4b63c4a02f96fb46fc88cdb770d796c9c9 100644 (file)
@@ -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<ModuleInfo> ModuleInfoList;
index 61e47b75774ec62754a8ca9a5943e779220513ee..de5d7a161731f2f8e64b68c9fca4d1486863a2a3 100644 (file)
@@ -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<QString, QString> iconMap;
-    app->moduleIconNames( iconMap );
+    // icons of modules
+    QMap<QString, QString> 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<CAM_Module*> itr( modList );
+    // step 2: iterate through list of all loaded modules
+    // and initialize their preferences
+    ModuleList loadedModules;
+    app->modules( loadedModules );
+    QListIterator<CAM_Module*> 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<SUIT_Application*> apps = SUIT_Session::session()->applications();
-      foreach( SUIT_Application* app, apps ) {
-        LightApp_Application* lapp = dynamic_cast<LightApp_Application*>( app );
-        if ( lapp && lapp != this )
-          lapp->removeModuleAction( modName );
-      }
-    }
-  }
 
   LightApp_ModuleAction* moduleAction =
     qobject_cast<LightApp_ModuleAction*>( 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;
index 82668bfadc9540f868834f258348f81b37204744..66a9032b3d7c799afaf0f3c7a4267bc0705ce109 100644 (file)
@@ -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& );
index bd53c897a49d3bdf21d51f895ef07e20fbe38279..658928f57c7641e96b368d60c91e268647a378fc 100644 (file)
@@ -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.*/
index 4f04942a041dc39de14d6d04305fc7bd9aeb3374..accbe9b4af10fd588d3831173b1453dafae68b9f 100644 (file)
@@ -30,6 +30,7 @@
 #include <SUIT_PreferenceMgr.h>
 
 #include <QMap>
+#include <QStringList>
 
 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& );
index d1bf51b9d874c6be36494179b71ab036e9333b08..91d0175c790856bcfc6f03c8ed6b8093e65499be 100644 (file)
@@ -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;
+}
index 541d319a3a51ac3c3744630225cb7e6439a47a23..1797c4495ad7118f622bcd5bea5f9a5a42348f2e 100644 (file)
@@ -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;