]> SALOME platform Git repositories - modules/gui.git/commitdiff
Salome HOME
Added methods storeState() and restoreState() intended to store/restore object browse...
authorouv <ouv@opencascade.com>
Tue, 26 Jul 2011 10:06:51 +0000 (10:06 +0000)
committerouv <ouv@opencascade.com>
Tue, 26 Jul 2011 10:06:51 +0000 (10:06 +0000)
src/LightApp/LightApp_DataModel.cxx
src/LightApp/LightApp_DataModel.h

index cccf466c94117a2734c0a567137f69428433a255..0b8b2cef6834d1adb2d45e147379a3342e12f862 100644 (file)
@@ -30,6 +30,9 @@
 #include <SUIT_TreeModel.h>
 #include <SUIT_DataBrowser.h>
 #include <SUIT_DataObject.h>
+#include <SUIT_DataObjectIterator.h>
+
+#include <QtxTreeView.h>
 
 /*!
   Constructor
@@ -208,3 +211,153 @@ void LightApp_DataModel::unregisterColumn( SUIT_DataBrowser* browser, const QStr
   if( m )
        m->unregisterColumn( groupId(), name );
 }
+
+/*!
+  Store object browser tree state (expanding and selection)
+  \param theOB - object browser
+  \param theExpanded - map of entry to expanded state
+  \param theSelected - list of selected entries
+*/
+void LightApp_DataModel::storeTree( SUIT_DataBrowser* theOB, 
+                                    QMap<QString, bool>& theExpanded,
+                                    QStringList& theSelected )
+{
+  theExpanded.clear();
+  theSelected.clear();
+  if ( !theOB )
+    return;
+
+  SUIT_AbstractModel* aModel = dynamic_cast<SUIT_AbstractModel*>( theOB->model() );
+  if ( !aModel )
+    return;
+
+  SUIT_DataObject* aRoot = theOB->root();
+  if ( !aRoot )
+    return;
+
+  QtxTreeView* aTreeView = theOB->treeView();
+  if ( !aTreeView )
+    return;
+
+  // expanded
+  QList<SUIT_DataObject*> aChildren;
+  aRoot->children( aChildren, true );
+
+  QList<SUIT_DataObject*>::iterator aCIter;
+  for ( aCIter = aChildren.begin(); aCIter != aChildren.end(); ++aCIter )
+  {
+    LightApp_DataObject* aCurr = dynamic_cast<LightApp_DataObject*>( *aCIter );
+    if ( !aCurr )
+      continue;
+
+    QString anEntry = aCurr->entry();
+
+    QModelIndex anIndex = aModel->index( aCurr );
+    if ( !anIndex.isValid() )
+      continue;
+
+    bool isExp = aTreeView->isExpanded( anIndex );
+    theExpanded.insert( anEntry, isExp );
+  }
+
+  // selected
+  QModelIndexList aList = theOB->selectedIndexes();
+  QModelIndexList::iterator anIter;
+  for ( anIter = aList.begin(); anIter != aList.end(); ++anIter )
+  {
+    LightApp_DataObject* aCurr =
+      dynamic_cast<LightApp_DataObject*>( aModel->object( *anIter ) );
+    if ( !aCurr )
+      continue;
+    
+    QString anEntry = aCurr->entry();
+    theSelected.append( anEntry );
+  }
+}
+
+/*!
+  Restore object browser tree state (expanding and selection)
+  \param theOB - object browser
+  \param theExpanded - map of entry to expanded state
+  \param theSelected - list of selected entries
+*/
+void LightApp_DataModel::restoreTree( SUIT_DataBrowser* theOB, 
+                                      const QMap<QString, bool>& theExpanded,
+                                      const QStringList& theSelected )
+{
+  if ( !theOB )
+    return;
+
+  SUIT_AbstractModel* aModel = dynamic_cast<SUIT_AbstractModel*>( theOB->model() );
+  if ( !aModel )
+    return;
+
+  SUIT_DataObject* aRoot = theOB->root();
+  if ( !aRoot )
+    return;
+
+  QtxTreeView* aTreeView = theOB->treeView();
+  if ( !aTreeView )
+    return;
+
+  // expanded
+  QList<SUIT_DataObject*> aChildren;
+  aRoot->children( aChildren, true );
+
+  QList<SUIT_DataObject*>::iterator aCIter;
+  for ( aCIter = aChildren.begin(); aCIter != aChildren.end(); ++aCIter )
+  {
+    LightApp_DataObject* aCurr = dynamic_cast<LightApp_DataObject*>( *aCIter );
+    if ( !aCurr )
+      continue;
+
+    QString anEntry = aCurr->entry();
+    if ( !theExpanded.contains( anEntry ) )
+      continue;
+
+    QModelIndex anIndex = aModel->index( aCurr );
+    if ( !anIndex.isValid() )
+      continue;
+
+    bool isExp = theExpanded[ anEntry ];
+    aTreeView->setExpanded( anIndex, isExp );
+  }
+
+  // selected
+  QModelIndexList toSel;
+  QStringList::const_iterator anIter;
+  for ( anIter = theSelected.begin(); anIter != theSelected.end(); ++anIter )
+  {
+    QString anEntry = *anIter;
+
+    LightApp_DataObject* aGuiObj = findObjectByEntry( theOB, anEntry );
+    if ( !aGuiObj )
+      continue;
+
+    QModelIndex anIndex = aModel->index( aGuiObj );
+    if ( anIndex.isValid() )
+      toSel.append( anIndex );
+  }
+
+  if ( toSel.count() > 0 )
+    theOB->select( toSel, true );
+}
+
+/*!
+  Find object in the object browser by the specified entry
+  \param theOB - object browser
+  \param theEntry - entry of object to find
+*/
+LightApp_DataObject* LightApp_DataModel::findObjectByEntry( SUIT_DataBrowser* theOB, 
+                                                            const QString& theEntry )
+{
+  LightApp_DataObject* aCurrent;
+  SUIT_DataObjectIterator anIter( theOB->root(), SUIT_DataObjectIterator::DepthLeft );
+  for ( ; anIter.current(); ++anIter )
+  {
+    aCurrent = dynamic_cast<LightApp_DataObject*>( anIter.current() );
+    if ( aCurrent && aCurrent->entry() == theEntry )
+      return aCurrent;
+  }
+  return NULL;
+}
index 8382700106e5c19cdb9f318ba04ad959a0f8558e..2148aab416ebf7d26f43a200fc525c0c342ba35e 100644 (file)
@@ -63,6 +63,17 @@ public:
   void registerColumn( SUIT_DataBrowser*, const QString&, const int );
   void unregisterColumn( SUIT_DataBrowser*, const QString& );
 
+  void                                storeTree( SUIT_DataBrowser* theOB, 
+                                                 QMap<QString, bool>& theExpanded,
+                                                 QStringList& theSelected );
+
+  void                                restoreTree( SUIT_DataBrowser* theOB, 
+                                                   const QMap<QString, bool>& theExpanded,
+                                                   const QStringList& theSelected );
+
+  LightApp_DataObject*                findObjectByEntry( SUIT_DataBrowser* theOB, 
+                                                         const QString& theEntry );
+
 signals:
   void                                opened();
   void                                saved();