//
#include "QtViewer_Object.h"
+#include "QtViewer_Scene.h"
//=======================================================================
// Name : QtViewer_Object
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);
+ }
+}
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; }
//
#include "QtViewer_Scene.h"
+#include "QtViewer_Object.h"
//=======================================================================
// Name : 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();
+}
+
#include "QtViewer.h"
#include <QGraphicsScene>
+#include <QHash>
+class QtViewer_Object;
class QGraphicsRectItem;
/*
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
obj->draw(painter);
}
-void QtViewer_ViewPort::addItem( QGraphicsItem* theItem )
-{
- scene()->addItem(theItem);
-}
-
void QtViewer_ViewPort::fitAll()
{
QRectF aRect;
QtViewer_ViewPort(QWidget* theParent);
~QtViewer_ViewPort();
- void addItem(QGraphicsItem* theItem);
void fitAll();
void fitSelect();