diff --git a/DestinationGLCanvas.cpp b/DestinationGLCanvas.cpp index e92b1ee..05c507d 100644 --- a/DestinationGLCanvas.cpp +++ b/DestinationGLCanvas.cpp @@ -26,21 +26,20 @@ DestinationGLCanvas::DestinationGLCanvas(MainWindow* mainWindow, QWidget* parent { } -MShape* DestinationGLCanvas::getShapeFromMappingId(uid mappingId) const +MShape::ptr DestinationGLCanvas::getShapeFromMappingId(uid mappingId) const { if (mappingId == NULL_UID) - return NULL; + return MShape::ptr(); else - return getMainWindow()->getMappingManager().getMappingById(mappingId)->getShape().data(); + return getMainWindow()->getMappingManager().getMappingById(mappingId)->getShape(); } -ShapeGraphicsItem* DestinationGLCanvas::getShapeGraphicsItemFromMappingId(uid mappingId) const +QSharedPointer DestinationGLCanvas::getShapeGraphicsItemFromMappingId(uid mappingId) const { if (mappingId == NULL_UID) - return NULL; - + return QSharedPointer(); else { - return MainWindow::instance()->getMapperByMappingId(mappingId)->getGraphicsItem().data(); + return MainWindow::instance()->getMapperByMappingId(mappingId)->getGraphicsItem(); } } diff --git a/DestinationGLCanvas.h b/DestinationGLCanvas.h index ef5b443..df51cb8 100644 --- a/DestinationGLCanvas.h +++ b/DestinationGLCanvas.h @@ -35,8 +35,8 @@ public: virtual ~DestinationGLCanvas() {} virtual bool isOutput() const { return true; } - virtual MShape* getShapeFromMappingId(uid mappingId) const; - virtual ShapeGraphicsItem* getShapeGraphicsItemFromMappingId(uid mappingId) const; + virtual MShape::ptr getShapeFromMappingId(uid mappingId) const; + virtual QSharedPointer getShapeGraphicsItemFromMappingId(uid mappingId) const; }; #endif /* DESTINATIONGLCANVAS_H_ */ diff --git a/MapperGLCanvas.cpp b/MapperGLCanvas.cpp index a559013..958f423 100644 --- a/MapperGLCanvas.cpp +++ b/MapperGLCanvas.cpp @@ -61,12 +61,12 @@ MapperGLCanvas::MapperGLCanvas(MainWindow* mainWindow, QWidget* parent, const QG this->scene()->setBackgroundBrush(Qt::black); } -MShape* MapperGLCanvas::getCurrentShape() +MShape::ptr MapperGLCanvas::getCurrentShape() { return getShapeFromMappingId(MainWindow::instance()->getCurrentMappingId()); } -ShapeGraphicsItem* MapperGLCanvas::getCurrentShapeGraphicsItem() +QSharedPointer MapperGLCanvas::getCurrentShapeGraphicsItem() { return getShapeGraphicsItemFromMappingId(MainWindow::instance()->getCurrentMappingId()); } @@ -81,7 +81,7 @@ void MapperGLCanvas::drawForeground(QPainter *painter , const QRectF &rect) if (mid != NULL_UID) { // Use current shape graphics item to draw controls. - ShapeGraphicsItem* item = getCurrentShapeGraphicsItem(); + ShapeGraphicsItem::ptr item = getCurrentShapeGraphicsItem(); if (item) { QList selected; @@ -118,7 +118,7 @@ void MapperGLCanvas::mousePressEvent(QMouseEvent* event) // Check for vertex selection first. else if (event->buttons() & Qt::LeftButton) { - MShape* shape = getCurrentShape(); + MShape::ptr shape = getCurrentShape(); if (shape) { // Note: we compare with the square value for fastest computation of the distance @@ -148,14 +148,14 @@ void MapperGLCanvas::mousePressEvent(QMouseEvent* event) // Check for shape selection. if (event->buttons() & (Qt::LeftButton | Qt::RightButton)) // Add Right click for context menu { - MShape* selectedShape = getCurrentShape(); + MShape::ptr selectedShape = getCurrentShape(); // Possibility of changing shape in output by clicking on it. MappingManager manager = getMainWindow()->getMappingManager(); QVector mappings = manager.getVisibleMappings(); for (QVector::const_iterator it = mappings.end() - 1; it >= mappings.begin(); --it) { - MShape *shape = getShapeFromMappingId((*it)->getId()); + MShape::ptr shape = getShapeFromMappingId((*it)->getId()); // Check if mouse was pressed on that shape. if (shape && shape->includesPoint(pos)) @@ -240,7 +240,7 @@ void MapperGLCanvas::mouseMoveEvent(QMouseEvent* event) if (_vertexGrabbed) { // std::cout << "Move event " << std::endl; - MShape* shape = getCurrentShape(); + MShape::ptr shape = getCurrentShape(); if (shape && hasActiveVertex()) { // QPointF p = shape->getVertex(_activeVertex); @@ -262,7 +262,7 @@ void MapperGLCanvas::mouseMoveEvent(QMouseEvent* event) else if (_shapeGrabbed) { // std::cout << "Move event " << std::endl; - MShape* shape = getCurrentShape(); + MShape::ptr shape = getCurrentShape(); if (shape) { if (_shapeFirstGrab) @@ -301,7 +301,7 @@ void MapperGLCanvas::keyPressEvent(QKeyEvent* event) // Active vertex selected. if (hasActiveVertex()) { - MShape* shape = getCurrentShape(); + MShape::ptr shape = getCurrentShape(); QPointF p = shape->getVertex(_activeVertex); handledKey = true; diff --git a/MapperGLCanvas.h b/MapperGLCanvas.h index 12f5dc5..f21ace4 100644 --- a/MapperGLCanvas.h +++ b/MapperGLCanvas.h @@ -47,7 +47,6 @@ class ShapeGraphicsItem; class MapperGLCanvas: public QGraphicsView { Q_OBJECT - public: /// Constructor. MapperGLCanvas(MainWindow* mainWindow, QWidget* parent = 0, const QGLWidget* shareWidget = 0, QGraphicsScene* scene = 0); @@ -55,11 +54,11 @@ public: /// Returns shape associated with mapping id. virtual bool isOutput() const = 0; - virtual MShape* getShapeFromMappingId(uid mappingId) const = 0; - virtual ShapeGraphicsItem* getShapeGraphicsItemFromMappingId(uid mappingId) const = 0; + virtual MShape::ptr getShapeFromMappingId(uid mappingId) const = 0; + virtual QSharedPointer getShapeGraphicsItemFromMappingId(uid mappingId) const = 0; - MShape* getCurrentShape(); - ShapeGraphicsItem* getCurrentShapeGraphicsItem(); + MShape::ptr getCurrentShape(); + QSharedPointer getCurrentShapeGraphicsItem(); // QSize sizeHint() const; // QSize minimumSizeHint() const; diff --git a/SourceGLCanvas.cpp b/SourceGLCanvas.cpp index 9a57277..5af3f0a 100644 --- a/SourceGLCanvas.cpp +++ b/SourceGLCanvas.cpp @@ -28,27 +28,27 @@ SourceGLCanvas::SourceGLCanvas(MainWindow* mainWindow, QWidget* parent) { } -MShape* SourceGLCanvas::getShapeFromMappingId(uid mappingId) const +MShape::ptr SourceGLCanvas::getShapeFromMappingId(uid mappingId) const { if (mappingId == NULL_UID) - return NULL; + return MShape::ptr(); else { Mapping::ptr mapping = getMainWindow()->getMappingManager().getMappingById(mappingId); Q_CHECK_PTR(mapping); - return mapping->getInputShape().data(); + return mapping->getInputShape(); } } -ShapeGraphicsItem* SourceGLCanvas::getShapeGraphicsItemFromMappingId(uid mappingId) const +QSharedPointer SourceGLCanvas::getShapeGraphicsItemFromMappingId(uid mappingId) const { if (mappingId == NULL_UID) - return NULL; + return QSharedPointer(); else { - return MainWindow::instance()->getMapperByMappingId(mappingId)->getInputGraphicsItem().data(); + return MainWindow::instance()->getMapperByMappingId(mappingId)->getInputGraphicsItem(); } } diff --git a/SourceGLCanvas.h b/SourceGLCanvas.h index 09c581c..c0f0119 100644 --- a/SourceGLCanvas.h +++ b/SourceGLCanvas.h @@ -36,8 +36,8 @@ public: virtual ~SourceGLCanvas() {} virtual bool isOutput() const { return false; } - virtual MShape* getShapeFromMappingId(uid mappingId) const; - virtual ShapeGraphicsItem* getShapeGraphicsItemFromMappingId(uid mappingId) const; + virtual MShape::ptr getShapeFromMappingId(uid mappingId) const; + virtual QSharedPointer getShapeGraphicsItemFromMappingId(uid mappingId) const; private: // virtual void doDraw(QPainter* painter);