]> SALOME platform Git repositories - modules/gui.git/commitdiff
Salome HOME
Improvement of the highlighting mechanism: list of objects to highlight is sorted...
authorouv <ouv@opencascade.com>
Mon, 11 Jul 2011 07:51:38 +0000 (07:51 +0000)
committerouv <ouv@opencascade.com>
Mon, 11 Jul 2011 07:51:38 +0000 (07:51 +0000)
src/GraphicsView/GraphicsView_Object.cxx
src/GraphicsView/GraphicsView_Object.h
src/GraphicsView/GraphicsView_ViewPort.cxx
src/GraphicsView/GraphicsView_ViewPort.h

index 75523c448677feb772b4e121c52ea60f26122d43..a884e1bbf34533ee534e058894efc511dfe797c8 100644 (file)
@@ -30,6 +30,7 @@
 //=======================================================================
 GraphicsView_Object::GraphicsView_Object( QGraphicsItem* theParent )
 : QGraphicsItemGroup( theParent ),
+  myPriority( 0 ),
   myIsHighlighted( false ),
   myIsSelected( false )
 {
index 7cb2a18c1865304ba53b4f5d13da524688088d61..c1e06cdfb4a78ee91d1765909ab8d48834b27dae 100644 (file)
@@ -42,6 +42,8 @@ public:
   const QString&             getName() const { return myName; }
   virtual void               setName( const QString& theName );
 
+  virtual int                getPriority() const { return myPriority; }
+
   virtual bool               isSelectable() const { return true; }
   virtual bool               isMovable() const { return true; }
 
@@ -76,6 +78,8 @@ protected:
 protected:
   QString                    myName;
 
+  int                        myPriority;
+
   bool                       myIsHighlighted;
   bool                       myIsSelected;
 };
index f7d995c3847f0c17a440186ac494c0ad894b6b29..089b3442d65f6369f74365506127542932d0e221 100644 (file)
@@ -231,6 +231,20 @@ void GraphicsView_ViewPort::cleanup()
 //================================================================
 void GraphicsView_ViewPort::addItem( QGraphicsItem* theItem )
 {
+  if( GraphicsView_Object* anObject = dynamic_cast<GraphicsView_Object*>( theItem ) )
+  {
+    int aPriority = anObject->getPriority();
+    GraphicsView_ObjectList::iterator anIter, anIterEnd = myObjects.end();
+    for( anIter = myObjects.begin(); anIter != anIterEnd; anIter++ )
+    {
+      if( GraphicsView_Object* anObjectRef = *anIter )
+      {
+        if( anObjectRef->getPriority() > aPriority )
+          break;
+      }
+    }
+    myObjects.insert( anIter, anObject );
+  }
   myScene->addItem( theItem );
   onBoundingRectChanged();
 }
@@ -246,6 +260,7 @@ void GraphicsView_ViewPort::removeItem( QGraphicsItem* theItem )
     if( myHighlightedObject == anObject )
       myHighlightedObject = 0;
     mySelectedObjects.removeAll( anObject );
+    myObjects.removeAll( anObject );
   }
   myScene->removeItem( theItem );
   onBoundingRectChanged();
@@ -257,16 +272,45 @@ void GraphicsView_ViewPort::removeItem( QGraphicsItem* theItem )
 //================================================================
 GraphicsView_ObjectList GraphicsView_ViewPort::getObjects( bool theIsSortSelected ) const
 {
+  if( !theIsSortSelected )
+    return myObjects;
+
+  // to append selected objects after their non-selected siblings with similar priority
+  int aCurrentPriority = -1;
+  GraphicsView_ObjectList aSelectedObjects;
+
   GraphicsView_ObjectList aList;
-  QListIterator<QGraphicsItem*> anIter( items() );
+  GraphicsView_ObjectListIterator anIter( myObjects );
   while( anIter.hasNext() )
-    if( GraphicsView_Object* anObject = dynamic_cast<GraphicsView_Object*>( anIter.next() ) )
+  {
+    if( GraphicsView_Object* anObject = anIter.next() )
     {
-      if( theIsSortSelected && anObject->isSelected() )
-        aList.prepend( anObject ); // put the selected objects to a head of the list
+      int aPriority = anObject->getPriority();
+      if( aPriority > aCurrentPriority  )
+      {
+        if( !aSelectedObjects.isEmpty() )
+        {
+          aList.append( aSelectedObjects );
+          aSelectedObjects.clear();
+        }
+        aCurrentPriority = aPriority;
+      }
+
+      if( anObject->isSelected() )
+        aSelectedObjects.append( anObject );
       else
         aList.append( anObject );
     }
+  }
+
+  // for selected objects with highest priority,
+  // which were not pushed to the result list yet
+  if( !aSelectedObjects.isEmpty() )
+  {
+    aList.append( aSelectedObjects );
+    aSelectedObjects.clear();
+  }
+
   return aList;
 }
 
@@ -781,9 +825,10 @@ void GraphicsView_ViewPort::highlight( double theX, double theY )
 
   GraphicsView_ObjectList aList = getObjects( true );
   GraphicsView_ObjectListIterator anIter( aList );
-  while( anIter.hasNext() )
+  anIter.toBack(); // objects with higher priority have to be checked earlier
+  while( anIter.hasPrevious() )
   {
-    if( GraphicsView_Object* anObject = anIter.next() )
+    if( GraphicsView_Object* anObject = anIter.previous() )
     {
       if( anObject->isVisible() && anObject->isSelectable() )
       {
index 0cb8921b4408b656ebb014f7ca44add5b98152db..227040e3038c43e28872c6da631723a5a2d41caf 100644 (file)
@@ -220,6 +220,7 @@ private:
   double                           mySceneGap;
   double                           myFitAllGap;
   bool                             myIsTraceBoundingRectEnabled;
+  GraphicsView_ObjectList          myObjects;
 
   // view name
   NameLabel*                       myNameLabel;