mirror of
https://github.com/mapmapteam/mapmap.git
synced 2026-06-16 12:33:19 +02:00
Used shared pointers in MapperGLCanvas base accessor functions.
This commit is contained in:
@@ -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<ShapeGraphicsItem> DestinationGLCanvas::getShapeGraphicsItemFromMappingId(uid mappingId) const
|
||||
{
|
||||
if (mappingId == NULL_UID)
|
||||
return NULL;
|
||||
|
||||
return QSharedPointer<ShapeGraphicsItem>();
|
||||
else
|
||||
{
|
||||
return MainWindow::instance()->getMapperByMappingId(mappingId)->getGraphicsItem().data();
|
||||
return MainWindow::instance()->getMapperByMappingId(mappingId)->getGraphicsItem();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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<ShapeGraphicsItem> getShapeGraphicsItemFromMappingId(uid mappingId) const;
|
||||
};
|
||||
|
||||
#endif /* DESTINATIONGLCANVAS_H_ */
|
||||
|
||||
+9
-9
@@ -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<ShapeGraphicsItem> 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<int> 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<Mapping::ptr> mappings = manager.getVisibleMappings();
|
||||
for (QVector<Mapping::ptr>::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;
|
||||
|
||||
|
||||
+4
-5
@@ -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<ShapeGraphicsItem> getShapeGraphicsItemFromMappingId(uid mappingId) const = 0;
|
||||
|
||||
MShape* getCurrentShape();
|
||||
ShapeGraphicsItem* getCurrentShapeGraphicsItem();
|
||||
MShape::ptr getCurrentShape();
|
||||
QSharedPointer<ShapeGraphicsItem> getCurrentShapeGraphicsItem();
|
||||
|
||||
// QSize sizeHint() const;
|
||||
// QSize minimumSizeHint() const;
|
||||
|
||||
+6
-6
@@ -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<ShapeGraphicsItem> SourceGLCanvas::getShapeGraphicsItemFromMappingId(uid mappingId) const
|
||||
{
|
||||
if (mappingId == NULL_UID)
|
||||
return NULL;
|
||||
return QSharedPointer<ShapeGraphicsItem>();
|
||||
|
||||
else
|
||||
{
|
||||
return MainWindow::instance()->getMapperByMappingId(mappingId)->getInputGraphicsItem().data();
|
||||
return MainWindow::instance()->getMapperByMappingId(mappingId)->getInputGraphicsItem();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+2
-2
@@ -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<ShapeGraphicsItem> getShapeGraphicsItemFromMappingId(uid mappingId) const;
|
||||
|
||||
private:
|
||||
// virtual void doDraw(QPainter* painter);
|
||||
|
||||
Reference in New Issue
Block a user