Salome HOME
refs #339 - Regression: Drag and select operation is not available after first action
authornds <nds@opencascade.com>
Wed, 29 Jan 2014 08:30:55 +0000 (08:30 +0000)
committernds <nds@opencascade.com>
Wed, 29 Jan 2014 08:30:55 +0000 (08:30 +0000)
refs #351 - regression - impossible to move Zone to another Region

src/HYDROGUI/HYDROGUI_DataBrowser.cxx

index 2c16b0c6383c3efdc03373dc493ce0ad033d9aab..d5460b64f0bb1abc31f70d1c963182732c19b45c 100644 (file)
         
 #define VISIBILITY_COLUMN_WIDTH 25
 
         
 #define VISIBILITY_COLUMN_WIDTH 25
 
+
+#include <SUIT_Selector.h>
+#include <SUIT_DataOwner.h>
+
+#include <QObject>
+
+class SUIT_DataBrowser;
+class LightApp_DataObject;
+
+
+#include "LightApp_DataOwner.h"
+#include "LightApp_DataObject.h"
+#include "LightApp_Application.h"
+#include <SUIT_DataBrowser.h>
+#include <SUIT_Session.h>
+#include <SUIT_DataObjectIterator.h>
+#include <QTime>
+#include <time.h>
+
+
+// The selector is redefined in order to correct the selection in the browser.
+// The main modification is to call fillEntries without the selector modified
+// time compare. The modified time is result of the clock() method.
+// On Linux, the method clock() returns the same values with some delay. So, it is possible,
+// that time has the same value, but the browser has already other objects.
+// So, the obsole entries can be in the saved entries by the filled method.
+// May be it will be improved in the latest version of GUI_SRC.
+// This redefinition is done for tag V7_3_0 of GUI_SRC.
+class HYDROGUI_OBSelector : public LightApp_OBSelector
+{
+public:
+  HYDROGUI_OBSelector( SUIT_DataBrowser*, SUIT_SelectionMgr* );
+  virtual ~HYDROGUI_OBSelector();
+
+protected:
+  virtual void       getSelection( SUIT_DataOwnerPtrList& ) const;
+  virtual void       setSelection( const SUIT_DataOwnerPtrList& );
+
+private:
+  void               fillEntries( QMap<QString, LightApp_DataObject*>& );
+
+private:
+  SUIT_DataOwnerPtrList               mySelectedList;
+  QMap<QString, LightApp_DataObject*> myEntries;
+};
+
+HYDROGUI_OBSelector::HYDROGUI_OBSelector( SUIT_DataBrowser* ob, SUIT_SelectionMgr* mgr )
+: LightApp_OBSelector( ob, mgr )
+{
+}
+
+/*!
+  \brief Destructor.
+*/
+HYDROGUI_OBSelector::~HYDROGUI_OBSelector()
+{
+}
+
+/*!
+  \brief Get list of currently selected objects.
+  \param theList list to be filled with the selected objects owners
+  \ This method is necessary to fill the cach containter mySelectedList
+  \ It is the same as in LightApp_OBSelector
+*/
+void HYDROGUI_OBSelector::getSelection( SUIT_DataOwnerPtrList& theList ) const
+{
+  SUIT_DataBrowser* aBrowser = browser();
+
+  if ( mySelectedList.count() == 0 ) {
+    SUIT_Session* session = SUIT_Session::session();
+    SUIT_Application* sapp = session ? session->activeApplication() : 0;
+    LightApp_Application* app = dynamic_cast<LightApp_Application*>( sapp );
+    if( !app || !aBrowser )
+      return;
+
+    DataObjectList objlist;
+    aBrowser->getSelected( objlist );
+    HYDROGUI_OBSelector* that = (HYDROGUI_OBSelector*)this;
+    QListIterator<SUIT_DataObject*> it( objlist );
+    while ( it.hasNext() ) {
+      LightApp_DataObject* obj = dynamic_cast<LightApp_DataObject*>( it.next() );
+      if ( obj && app->checkDataObject( obj) ) {
+#ifndef DISABLE_SALOMEOBJECT
+        Handle(SALOME_InteractiveObject) aSObj = new SALOME_InteractiveObject
+          ( obj->entry().toLatin1().constData(),
+            obj->componentDataType().toLatin1().constData(),
+            obj->name().toLatin1().constData() );
+        LightApp_DataOwner* owner = new LightApp_DataOwner( aSObj  );
+#else
+        LightApp_DataOwner* owner = new LightApp_DataOwner( obj->entry() );
+#endif
+        that->mySelectedList.append( SUIT_DataOwnerPtr( owner ) );
+      }
+    }
+  }
+  theList = mySelectedList;
+}
+
+/*!
+  \brief Set selection.
+  \param theList list of the object owners to be set selected
+  \ It is the same as in LightApp_OBSelector. The difference is in the row with
+  \ the modification time check.
+*/
+void HYDROGUI_OBSelector::setSelection( const SUIT_DataOwnerPtrList& theList )
+{
+  SUIT_DataBrowser* aBrowser = browser();
+  if ( !aBrowser )
+    return;
+
+  // this is the difference to LightApp_OBSelector. For this, this class is redefined
+  //if( myEntries.count() == 0 || myModifiedTime < aBrowser->getModifiedTime() )
+  {
+    fillEntries( myEntries );
+  }
+
+  DataObjectList objList;
+  for ( SUIT_DataOwnerPtrList::const_iterator it = theList.begin(); 
+        it != theList.end(); ++it ) {
+    const LightApp_DataOwner* owner = dynamic_cast<const LightApp_DataOwner*>( (*it).operator->() );
+
+    if ( owner && myEntries.contains( owner->entry() ) )
+      objList.append( myEntries[owner->entry()] );
+  }
+
+  aBrowser->setSelected( objList );
+  mySelectedList.clear();
+}
+
+/*!
+  \brief Fill map of the data objects currently shown in the Object Browser.
+  \param entries map to be filled
+  \ It is the same as in LightApp_OBSelector
+*/
+void HYDROGUI_OBSelector::fillEntries( QMap<QString, LightApp_DataObject*>& entries )
+{
+  entries.clear();
+
+  SUIT_DataBrowser* aBrowser = browser();
+  if ( !aBrowser )
+    return;
+
+  for ( SUIT_DataObjectIterator it( aBrowser->root(),
+                                    SUIT_DataObjectIterator::DepthLeft ); it.current(); ++it ) {
+    LightApp_DataObject* obj = dynamic_cast<LightApp_DataObject*>( it.current() );
+    if ( obj )
+      entries.insert( obj->entry(), obj );
+  }
+
+  setModified();
+}
+
+
 HYDROGUI_DataBrowser::HYDROGUI_DataBrowser( HYDROGUI_Module* theModule, SUIT_DataObject* theRoot, QWidget* theParent )
 : SUIT_DataBrowser( theRoot, theParent ), myModule( theModule )
 {
 HYDROGUI_DataBrowser::HYDROGUI_DataBrowser( HYDROGUI_Module* theModule, SUIT_DataObject* theRoot, QWidget* theParent )
 : SUIT_DataBrowser( theRoot, theParent ), myModule( theModule )
 {
@@ -117,7 +270,7 @@ HYDROGUI_DataBrowser::HYDROGUI_DataBrowser( HYDROGUI_Module* theModule, SUIT_Dat
   */
 
   // Create OBSelector
   */
 
   // Create OBSelector
-  new LightApp_OBSelector( this, theModule->getApp()->selectionMgr() );
+  new HYDROGUI_OBSelector( this, theModule->getApp()->selectionMgr() );
 
   treeView()->header()->setResizeMode(SUIT_DataObject::VisibilityId, QHeaderView::Fixed);
   treeView()->header()->moveSection(SUIT_DataObject::NameId,SUIT_DataObject::VisibilityId);
 
   treeView()->header()->setResizeMode(SUIT_DataObject::VisibilityId, QHeaderView::Fixed);
   treeView()->header()->moveSection(SUIT_DataObject::NameId,SUIT_DataObject::VisibilityId);