]> SALOME platform Git repositories - modules/gui.git/commitdiff
Salome HOME
Objects are stored in a QHash sc/gui_913_for_guithare
authorCHEMIN Sébastien 236498 <sc236498@is245491.intra.cea.fr>
Mon, 14 Oct 2024 12:25:46 +0000 (14:25 +0200)
committerCHEMIN Sébastien 236498 <sc236498@is245491.intra.cea.fr>
Mon, 14 Oct 2024 12:25:46 +0000 (14:25 +0200)
src/QtViewer/QtViewer_Object.cxx
src/QtViewer/QtViewer_Object.h
src/QtViewer/QtViewer_Scene.cxx
src/QtViewer/QtViewer_Scene.h
src/QtViewer/QtViewer_ViewPort.cxx
src/QtViewer/QtViewer_ViewPort.h

index 18fb3a347bf496df5e12c886ce4fc6bedb72fde4..273cd726769766f86b871b653bb6f9dea8aca6f0 100644 (file)
@@ -18,6 +18,7 @@
 //
 
 #include "QtViewer_Object.h"
+#include "QtViewer_Scene.h"
 
 //=======================================================================
 // Name    : QtViewer_Object
@@ -35,3 +36,14 @@ QtViewer_Object::QtViewer_Object( QGraphicsItem* theParent )
 QtViewer_Object::~QtViewer_Object()
 {
 }
+
+void QtViewer_Object::setParentItem(QGraphicsItem *newParent)
+{
+  QGraphicsItem::setParentItem(newParent);
+
+  if(QtViewer_Object* obj = dynamic_cast<QtViewer_Object*>(this))
+    {
+     if (QtViewer_Scene* theScene = dynamic_cast<QtViewer_Scene*>(scene()))
+       theScene->addObject(obj); 
+    }
+}
index 7e69f1a1d8c73686430aaf67a5b6f5b933485216..a28cc838b44986862cb67763002ea58c12f6cf47 100644 (file)
@@ -34,6 +34,8 @@ public:
   QtViewer_Object( QGraphicsItem* theParent = nullptr );
   ~QtViewer_Object();
 
+  virtual void setParentItem(QGraphicsItem *newParent);
+
   const QString& getName() const { return myName; }
   virtual void setName( const QString& theName ) { myName = theName; }
 
index 29675ffe95c3e9ea0abc67cd771e3bbc27c61cf8..b7d9c523a31ea09d01346f124a73d0ff0fc9ad03 100644 (file)
@@ -18,6 +18,7 @@
 //
 
 #include "QtViewer_Scene.h"
+#include "QtViewer_Object.h"
 
 //=======================================================================
 // Name    : QtViewer_Scene
@@ -36,3 +37,35 @@ QtViewer_Scene::~QtViewer_Scene()
 {
 }
 
+void QtViewer_Scene::addItem(QGraphicsItem *item)
+{
+  QGraphicsScene::addItem(item);
+
+  if(QtViewer_Object* obj = dynamic_cast<QtViewer_Object*>(item))
+    addObject(obj);
+}
+
+void QtViewer_Scene::removeItem(QGraphicsItem *item)
+{
+  QGraphicsScene::removeItem(item);
+
+  if(QtViewer_Object* obj = dynamic_cast<QtViewer_Object*>(item))
+    myObjects.remove(obj->getName()); 
+}
+
+QtViewer_Object* QtViewer_Scene::getObject(const QString& name)
+{
+  return myObjects[name];
+}
+
+void QtViewer_Scene::addObject(QtViewer_Object* obj)
+{
+  myObjects[obj->getName()] = obj;
+}
+
+void QtViewer_Scene::clear()
+{
+  myObjects.clear();
+  QGraphicsScene::clear();
+}
+
index 47c1702dada9c8691a84186344e06d0a00279822..1050004c2d321cb8bfbae9fbf3a05c1c582b6fb9 100644 (file)
@@ -22,7 +22,9 @@
 
 #include "QtViewer.h"
 #include <QGraphicsScene>
+#include <QHash>
 
+class QtViewer_Object;
 class QGraphicsRectItem;
 
 /*
@@ -36,5 +38,16 @@ class QTVIEWER_API QtViewer_Scene : public QGraphicsScene
 public:
   QtViewer_Scene( QObject* theParent = 0 );
   ~QtViewer_Scene();
+
+  virtual void addItem(QGraphicsItem *item);
+  virtual void removeItem(QGraphicsItem *item);
+  QtViewer_Object* getObject(const QString& name); 
+  void addObject(QtViewer_Object* obj);
+public slots:
+   virtual void clear(); 
+
+protected:
+  QHash<QString,QtViewer_Object*> myObjects; 
 };
 #endif
index 44402b4188d9271ff2c74ffffce07f9b797cd26e..af79f2f2b6d858da300641ef0d7c2190443754f6 100644 (file)
@@ -92,11 +92,6 @@ void QtViewer_ViewPort::drawForeground(QPainter *painter, const QRectF &rect)
     obj->draw(painter);
 }
 
-void QtViewer_ViewPort::addItem( QGraphicsItem* theItem )
-{
-  scene()->addItem(theItem);
-}
-
 void QtViewer_ViewPort::fitAll()
 {
   QRectF aRect;
index 2749f9dd0c6b02bda2f2054725c999f5f956013a..ae361b6da3d1707a642203562da6dea2d5e15230 100644 (file)
@@ -38,7 +38,6 @@ public:
   QtViewer_ViewPort(QWidget* theParent);
   ~QtViewer_ViewPort();
 
-  void addItem(QGraphicsItem* theItem);
 
   void fitAll();
   void fitSelect();