Changed tr1 shared_ptr for QSharedPointers and QWeakPointers.

This commit is contained in:
Tats
2015-07-17 13:41:55 -06:00
parent fce0715c5a
commit aef4f2d8d8
14 changed files with 113 additions and 135 deletions
+45 -56
View File
@@ -45,7 +45,7 @@ void ShapeControlPainter::_paintVertices(QPainter *painter, const QList<int>& se
void PolygonControlPainter::_paintShape(QPainter *painter)
{
Polygon* poly = static_cast<Polygon*>(getShape().get());
Polygon* poly = static_cast<Polygon*>(getShape().data());
Q_ASSERT(poly);
// Init colors and stroke.
@@ -58,7 +58,7 @@ void PolygonControlPainter::_paintShape(QPainter *painter)
void EllipseControlPainter::_paintShape(QPainter *painter)
{
Ellipse* ellipse = static_cast<Ellipse*>(getShape().get());
Ellipse* ellipse = static_cast<Ellipse*>(getShape().data());
Q_ASSERT(ellipse);
// Init colors and stroke.
@@ -76,7 +76,7 @@ void EllipseControlPainter::_paintShape(QPainter *painter)
void MeshControlPainter::_paintShape(QPainter *painter)
{
Mesh* mesh = static_cast<Mesh*>(getShape().get());
Mesh* mesh = static_cast<Mesh*>(getShape().data());
Q_ASSERT(mesh);
// Init colors and stroke.
@@ -207,7 +207,7 @@ QPen ShapeGraphicsItem::_getRescaledShapeStroke(bool innerStroke)
void ColorGraphicsItem::_prePaint(QPainter *painter,
const QStyleOptionGraphicsItem *option)
{
Color* color = static_cast<Color*>(_mapping->getPaint().get());
Color* color = static_cast<Color*>(_mapping->getPaint().data());
Q_ASSERT(color);
painter->setPen(Qt::NoPen);
@@ -221,7 +221,7 @@ void ColorGraphicsItem::_prePaint(QPainter *painter,
QPainterPath PolygonColorGraphicsItem::shape() const
{
QPainterPath path;
Polygon* poly = static_cast<Polygon*>(_shape.get());
Polygon* poly = static_cast<Polygon*>(_shape.data());
Q_ASSERT(poly);
path.addPolygon(poly->toPolygon());
return mapFromScene(path);
@@ -231,7 +231,7 @@ void PolygonColorGraphicsItem::_doPaint(QPainter *painter,
const QStyleOptionGraphicsItem *option)
{
Q_UNUSED(option);
Polygon* poly = static_cast<Polygon*>(_shape.get());
Polygon* poly = static_cast<Polygon*>(_shape.data());
Q_ASSERT(poly);
painter->drawPolygon(mapFromScene(poly->toPolygon()));
}
@@ -240,7 +240,7 @@ void PolygonColorGraphicsItem::_doPaintControls(QPainter* painter, const QStyleO
{
Q_UNUSED(option);
painter->setPen(_getRescaledShapeStroke());
Polygon* poly = static_cast<Polygon*>(_shape.get());
Polygon* poly = static_cast<Polygon*>(_shape.data());
Q_ASSERT(poly);
painter->drawPolygon(mapFromScene(poly->toPolygon()));
}
@@ -249,7 +249,7 @@ QPainterPath EllipseColorGraphicsItem::shape() const
{
// Create path for ellipse.
QPainterPath path;
Ellipse* ellipse = static_cast<Ellipse*>(_shape.get());
Ellipse* ellipse = static_cast<Ellipse*>(_shape.data());
Q_ASSERT(ellipse);
QTransform transform;
transform.translate(ellipse->getCenter().x(), ellipse->getCenter().y());
@@ -269,13 +269,13 @@ void EllipseColorGraphicsItem::_doPaint(QPainter* painter,
TextureGraphicsItem::TextureGraphicsItem(Mapping::ptr mapping, bool output)
: ShapeGraphicsItem(mapping, output)
{
_textureMapping = std::tr1::static_pointer_cast<TextureMapping>(mapping);
_textureMapping = qSharedPointerCast<TextureMapping>(mapping);
Q_CHECK_PTR(_textureMapping);
_texture = std::tr1::static_pointer_cast<Texture>(_textureMapping->getPaint());
_texture = qSharedPointerCast<Texture>(_textureMapping->getPaint());
Q_CHECK_PTR(_texture);
_inputShape = std::tr1::static_pointer_cast<MShape>(_textureMapping->getInputShape());
_inputShape = qSharedPointerCast<MShape>(_textureMapping->getInputShape());
Q_CHECK_PTR(_inputShape);
}
@@ -369,7 +369,7 @@ void TextureGraphicsItem::_postPaint(QPainter* painter,
QPainterPath PolygonTextureGraphicsItem::shape() const
{
QPainterPath path;
Polygon* poly = static_cast<Polygon*>(_shape.get());
Polygon* poly = static_cast<Polygon*>(_shape.data());
Q_ASSERT(poly);
path.addPolygon(poly->toPolygon());
return mapFromScene(path);
@@ -399,7 +399,7 @@ void PolygonTextureGraphicsItem::_doPaintControls(QPainter* painter, const QStyl
{
Q_UNUSED(option);
painter->setPen(_getRescaledShapeStroke());
Polygon* poly = static_cast<Polygon*>(_shape.get());
Polygon* poly = static_cast<Polygon*>(_shape.data());
Q_ASSERT(poly);
painter->drawPolygon(mapFromScene(poly->toPolygon()));
}
@@ -409,8 +409,8 @@ void MeshTextureGraphicsItem::_doDrawOutput(QPainter* painter)
Q_UNUSED(painter);
if (isOutput())
{
std::tr1::shared_ptr<Mesh> outputMesh = std::tr1::static_pointer_cast<Mesh>(_shape);
std::tr1::shared_ptr<Mesh> inputMesh = std::tr1::static_pointer_cast<Mesh>(_inputShape);
QSharedPointer<Mesh> outputMesh = qSharedPointerCast<Mesh>(_shape);
QSharedPointer<Mesh> inputMesh = qSharedPointerCast<Mesh>(_inputShape);
QVector<QVector<Quad> > outputQuads = outputMesh->getQuads2d();
QVector<QVector<Quad> > inputQuads = inputMesh->getQuads2d();
for (int x = 0; x < outputMesh->nHorizontalQuads(); x++)
@@ -430,7 +430,7 @@ void MeshTextureGraphicsItem::_doPaintControls(QPainter* painter, const QStyleOp
{
Q_UNUSED(option);
Mesh* mesh = static_cast<Mesh*>(_shape.get());
Mesh* mesh = static_cast<Mesh*>(_shape.data());
Q_ASSERT(mesh);
// Init colors and stroke.
@@ -526,7 +526,7 @@ QPainterPath EllipseTextureGraphicsItem::shape() const
{
// Create path for ellipse.
QPainterPath path;
Ellipse* ellipse = static_cast<Ellipse*>(_shape.get());
Ellipse* ellipse = static_cast<Ellipse*>(_shape.data());
Q_ASSERT(ellipse);
QTransform transform;
transform.translate(ellipse->getCenter().x(), ellipse->getCenter().y());
@@ -544,8 +544,8 @@ void EllipseTextureGraphicsItem::_doDrawOutput(QPainter* painter)
{
Q_UNUSED(painter);
// Get input and output ellipses.
std::tr1::shared_ptr<Ellipse> inputEllipse = std::tr1::static_pointer_cast<Ellipse>(_inputShape);
std::tr1::shared_ptr<Ellipse> outputEllipse = std::tr1::static_pointer_cast<Ellipse>(_shape);
QSharedPointer<Ellipse> inputEllipse = qSharedPointerCast<Ellipse>(_inputShape);
QSharedPointer<Ellipse> outputEllipse = qSharedPointerCast<Ellipse>(_shape);
// Start / end angle.
//const float startAngle = 0;
@@ -645,7 +645,7 @@ Mapper::Mapper(Mapping::ptr mapping)
_outputItem = _variantManager->addProperty(QtVariantPropertyManager::groupTypeId(),
QObject::tr("Output shape"));
_buildShapeProperty(_outputItem, mapping->getShape().get());
_buildShapeProperty(_outputItem, mapping->getShape().data());
_topItem->addSubProperty(_outputItem);
// Collapse output shape.
@@ -697,6 +697,11 @@ void Mapper::setValue(QtProperty* property, const QVariant& value)
}
}
void Mapper::updatePaint()
{
_mapping->getPaint()->update();
}
void Mapper::_buildShapeProperty(QtProperty* shapeItem, MShape* shape)
{
for (int i=0; i<shape->nVertices(); i++)
@@ -732,14 +737,7 @@ void Mapper::_updateShapeProperty(QtProperty* shapeItem, MShape* shape)
ColorMapper::ColorMapper(Mapping::ptr mapping)
: Mapper(mapping)
{
color = std::tr1::static_pointer_cast<Color>(_mapping->getPaint());
Q_CHECK_PTR(color);
}
void ColorMapper::updatePaint()
{
color.reset();
color = std::tr1::static_pointer_cast<Color>(_mapping->getPaint());
color = qSharedPointerCast<Color>(_mapping->getPaint());
Q_CHECK_PTR(color);
}
@@ -757,7 +755,7 @@ void ColorMapper::updatePaint()
// painter->setPen(Qt::NoPen);
// painter->setBrush(color->getColor());
//
// std::tr1::shared_ptr<Mesh> outputMesh = std::tr1::static_pointer_cast<Mesh>(outputShape);
// QSharedPointer<Mesh> outputMesh = qSharedPointerCast<Mesh>(outputShape);
// QVector<QVector<Quad> > outputQuads = outputMesh->getQuads2d();
// for (int x = 0; x < outputMesh->nHorizontalQuads(); x++)
// {
@@ -771,7 +769,7 @@ void ColorMapper::updatePaint()
//
//void MeshColorMapper::drawControls(QPainter* painter, const QList<int>* selectedVertices)
//{
// std::tr1::shared_ptr<Mesh> outputMesh = std::tr1::static_pointer_cast<Mesh>(outputShape);
// QSharedPointer<Mesh> outputMesh = qSharedPointerCast<Mesh>(outputShape);
// Util::drawControlsMesh(painter, selectedVertices, *outputMesh);
//}
//
@@ -792,24 +790,24 @@ void ColorMapper::updatePaint()
// ColorMapper::setValue(property, value);
//}
TextureMapper::TextureMapper(std::tr1::shared_ptr<TextureMapping> mapping)
TextureMapper::TextureMapper(QSharedPointer<TextureMapping> mapping)
: Mapper(mapping),
_meshItem(NULL)
{
// Assign members pointers.
textureMapping = std::tr1::static_pointer_cast<TextureMapping>(_mapping);
textureMapping = qSharedPointerCast<TextureMapping>(_mapping);
Q_CHECK_PTR(textureMapping);
texture = std::tr1::static_pointer_cast<Texture>(textureMapping->getPaint());
texture = qSharedPointerCast<Texture>(_mapping->getPaint());
Q_CHECK_PTR(texture);
inputShape = std::tr1::static_pointer_cast<MShape>(textureMapping->getInputShape());
inputShape = textureMapping.toStrongRef()->getInputShape();
Q_CHECK_PTR(inputShape);
// Input shape.
_inputItem = _variantManager->addProperty(QtVariantPropertyManager::groupTypeId(),
QObject::tr("Input shape"));
_buildShapeProperty(_inputItem, textureMapping->getInputShape().get());
_buildShapeProperty(_inputItem, inputShape.data());
_topItem->insertSubProperty(_inputItem, _opacityItem); // insert
// Collapse input shape.
@@ -844,14 +842,14 @@ TextureMapper::TextureMapper(std::tr1::shared_ptr<TextureMapping> mapping)
void TextureMapper::updateShape(MShape* shape)
{
std::tr1::shared_ptr<TextureMapping> textureMapping = std::tr1::static_pointer_cast<TextureMapping>(_mapping);
QSharedPointer<TextureMapping> textureMapping = qSharedPointerCast<TextureMapping>(_mapping);
Q_CHECK_PTR(textureMapping);
std::tr1::shared_ptr<Texture> texture = std::tr1::static_pointer_cast<Texture>(textureMapping->getPaint());
QSharedPointer<Texture> texture = qSharedPointerCast<Texture>(textureMapping->getPaint());
Q_CHECK_PTR(texture);
MShape* inputShape = textureMapping->getInputShape().get();
MShape* outputShape = textureMapping->getShape().get();
MShape* inputShape = textureMapping->getInputShape().data();
MShape* outputShape = textureMapping->getShape().data();
if (shape == inputShape)
{
_updateShapeProperty(_inputItem, inputShape);
@@ -863,12 +861,6 @@ void TextureMapper::updateShape(MShape* shape)
}
void TextureMapper::updatePaint()
{
texture.reset();
texture = std::tr1::static_pointer_cast<Texture>(textureMapping->getPaint());
Q_CHECK_PTR(texture);
}
//
//void TextureMapper::_preDraw(QPainter* painter)
//{
@@ -910,17 +902,17 @@ void TextureMapper::updatePaint()
//
//void PolygonTextureMapper::drawControls(QPainter* painter, const QList<int>* selectedVertices)
//{
// std::tr1::shared_ptr<Polygon> outputPoly = std::tr1::static_pointer_cast<Polygon>(outputShape);
// QSharedPointer<Polygon> outputPoly = qSharedPointerCast<Polygon>(outputShape);
// Util::drawControlsPolygon(painter, selectedVertices, *outputPoly);
//}
//
//void PolygonTextureMapper::drawInputControls(QPainter* painter, const QList<int>* selectedVertices)
//{
// std::tr1::shared_ptr<Polygon> inputPoly = std::tr1::static_pointer_cast<Polygon>(inputShape);
// QSharedPointer<Polygon> inputPoly = qSharedPointerCast<Polygon>(inputShape);
// Util::drawControlsPolygon(painter, selectedVertices, *inputPoly);
//}
TriangleTextureMapper::TriangleTextureMapper(std::tr1::shared_ptr<TextureMapping> mapping)
TriangleTextureMapper::TriangleTextureMapper(QSharedPointer<TextureMapping> mapping)
: PolygonTextureMapper(mapping)
{
_graphicsItem = new TriangleTextureGraphicsItem(_mapping, true);
@@ -941,14 +933,14 @@ TriangleTextureMapper::TriangleTextureMapper(std::tr1::shared_ptr<TextureMapping
//// glEnd();
//}
MeshTextureMapper::MeshTextureMapper(std::tr1::shared_ptr<TextureMapping> mapping)
MeshTextureMapper::MeshTextureMapper(QSharedPointer<TextureMapping> mapping)
: PolygonTextureMapper(mapping)
{
_graphicsItem = new MeshTextureGraphicsItem(_mapping, true);
_inputGraphicsItem = new MeshTextureGraphicsItem(_mapping, false);
// Add mesh sub property.
Mesh* mesh = (Mesh*)textureMapping->getShape().get();
QSharedPointer<Mesh> mesh = qSharedPointerCast<Mesh>(_mapping->getShape());
_meshItem = _variantManager->addProperty(QVariant::Size, QObject::tr("Dimensions"));
_meshItem->setValue(QSize(mesh->nColumns(), mesh->nRows()));
_meshItem->setAttribute("minimum", QSize(2,2));
@@ -959,11 +951,8 @@ void MeshTextureMapper::setValue(QtProperty* property, const QVariant& value)
{
if (property == _meshItem)
{
std::tr1::shared_ptr<TextureMapping> textureMapping = std::tr1::static_pointer_cast<TextureMapping>(_mapping);
Q_CHECK_PTR(textureMapping);
Mesh* outputMesh = static_cast<Mesh*>(textureMapping->getShape().get());
Mesh* inputMesh = static_cast<Mesh*>(textureMapping->getInputShape().get());
QSharedPointer<Mesh> outputMesh = qSharedPointerCast<Mesh>(_mapping->getShape());
QSharedPointer<Mesh> inputMesh = qSharedPointerCast<Mesh>(textureMapping.toStrongRef()->getShape());
QSize size = (static_cast<QtVariantProperty*>(property))->value().toSize();
if (outputMesh->nColumns() != size.width() || outputMesh->nRows() != size.height() ||
inputMesh->nColumns() != size.width() || inputMesh->nRows() != size.height())
@@ -983,7 +972,7 @@ void MeshTextureMapper::setValue(QtProperty* property, const QVariant& value)
TextureMapper::setValue(property, value);
}
EllipseTextureMapper::EllipseTextureMapper(std::tr1::shared_ptr<TextureMapping> mapping)
EllipseTextureMapper::EllipseTextureMapper(QSharedPointer<TextureMapping> mapping)
: PolygonTextureMapper(mapping)
{
_graphicsItem = new EllipseTextureGraphicsItem(_mapping, true);