From e36cb1a9915bf34fcc91f94062e75ac161da20a0 Mon Sep 17 00:00:00 2001 From: Tats Date: Sun, 9 Feb 2014 01:02:54 -0500 Subject: [PATCH] Replace std::vector and std::map by QVector and QMap (not everywhere yet). --- MainWindow.cpp | 8 +++--- MainWindow.h | 8 +++--- Mapper.cpp | 14 +++++----- ProjectReader.cpp | 14 +++++----- ProjectReader.h | 8 +++--- Shape.cpp | 29 ++++++++++----------- Shape.h | 66 ++++++++++++----------------------------------- 7 files changed, 56 insertions(+), 91 deletions(-) diff --git a/MainWindow.cpp b/MainWindow.cpp index d5c7177..96d6102 100644 --- a/MainWindow.cpp +++ b/MainWindow.cpp @@ -409,7 +409,7 @@ uid MainWindow::createColorPaint(uid paintId, QColor color) uid MainWindow::createMeshTextureMapping(uid mappingId, uid paintId, int nColumns, int nRows, - const QList &src, const QList &dst) + const QVector &src, const QVector &dst) { // Cannot create element with already existing id or element for which no paint exists. if (Mapping::getUidAllocator().exists(mappingId) || @@ -441,7 +441,7 @@ uid MainWindow::createMeshTextureMapping(uid mappingId, uid MainWindow::createTriangleTextureMapping(uid mappingId, uid paintId, - const QList &src, const QList &dst) + const QVector &src, const QVector &dst) { // Cannot create element with already existing id or element for which no paint exists. if (Mapping::getUidAllocator().exists(mappingId) || @@ -471,7 +471,7 @@ uid MainWindow::createTriangleTextureMapping(uid mappingId, uid MainWindow::createQuadColorMapping(uid mappingId, uid paintId, - const QList &dst) + const QVector &dst) { // Cannot create element with already existing id or element for which no paint exists. if (Mapping::getUidAllocator().exists(mappingId) || @@ -500,7 +500,7 @@ uid MainWindow::createQuadColorMapping(uid mappingId, uid MainWindow::createTriangleColorMapping(uid mappingId, uid paintId, - const QList &dst) + const QVector &dst) { // Cannot create element with already existing id or element for which no paint exists. if (Mapping::getUidAllocator().exists(mappingId) || diff --git a/MainWindow.h b/MainWindow.h index d229298..ef6e102 100644 --- a/MainWindow.h +++ b/MainWindow.h @@ -104,14 +104,14 @@ public slots: uid createMeshTextureMapping(uid mappingId, uid paintId, int nColumns, int nRows, - const QList &src, const QList &dst); + const QVector &src, const QVector &dst); /** * Creates a textured triangle. */ uid createTriangleTextureMapping(uid mappingId, uid paintId, - const QList &src, const QList &dst); + const QVector &src, const QVector &dst); /** @@ -119,14 +119,14 @@ public slots: */ uid createQuadColorMapping(uid mappingId, uid paintId, - const QList &dst); + const QVector &dst); /** * Creates a color triangle. */ uid createTriangleColorMapping(uid mappingId, uid paintId, - const QList &dst); + const QVector &dst); private: // Methods. diff --git a/Mapper.cpp b/Mapper.cpp index 8519c47..86de884 100644 --- a/Mapper.cpp +++ b/Mapper.cpp @@ -187,7 +187,7 @@ void MeshColorMapper::draw(QPainter* painter) painter->setBrush(color->getColor()); std::tr1::shared_ptr outputMesh = std::tr1::static_pointer_cast(outputShape); - std::vector > outputQuads = outputMesh->getQuads2d(); + QVector > outputQuads = outputMesh->getQuads2d(); for (int x = 0; x < outputMesh->nHorizontalQuads(); x++) { for (int y = 0; y < outputMesh->nVerticalQuads(); y++) @@ -201,8 +201,8 @@ void MeshColorMapper::draw(QPainter* painter) void MeshColorMapper::drawControls(QPainter* painter) { std::tr1::shared_ptr outputMesh = std::tr1::static_pointer_cast(outputShape); - std::vector outputQuads = outputMesh->getQuads(); - for (std::vector::const_iterator it = outputQuads.begin(); it != outputQuads.end(); ++it) + QVector outputQuads = outputMesh->getQuads(); + for (QVector::const_iterator it = outputQuads.begin(); it != outputQuads.end(); ++it) { drawShapeContour(painter, *it, 1, QColor(0, 0, 255)); } @@ -356,8 +356,8 @@ void MeshTextureMapper::setValue(QtProperty* property, const QVariant& value) void MeshTextureMapper::drawControls(QPainter* painter) { std::tr1::shared_ptr outputMesh = std::tr1::static_pointer_cast(outputShape); - std::vector outputQuads = outputMesh->getQuads(); - for (std::vector::const_iterator it = outputQuads.begin(); it != outputQuads.end(); ++it) + QVector outputQuads = outputMesh->getQuads(); + for (QVector::const_iterator it = outputQuads.begin(); it != outputQuads.end(); ++it) { drawShapeContour(painter, *it, 1, QColor(0, 0, 255)); } @@ -366,8 +366,8 @@ void MeshTextureMapper::drawControls(QPainter* painter) void MeshTextureMapper::drawInputControls(QPainter* painter) { std::tr1::shared_ptr inputMesh = std::tr1::static_pointer_cast(inputShape); - std::vector inputQuads = inputMesh->getQuads(); - for (std::vector::const_iterator it = inputQuads.begin(); it != inputQuads.end(); ++it) + QVector inputQuads = inputMesh->getQuads(); + for (QVector::const_iterator it = inputQuads.begin(); it != inputQuads.end(); ++it) { drawShapeContour(painter, *it, 1, QColor(0, 0, 255)); } diff --git a/ProjectReader.cpp b/ProjectReader.cpp index d8cbbb1..69b37d1 100644 --- a/ProjectReader.cpp +++ b/ProjectReader.cpp @@ -121,7 +121,7 @@ void ProjectReader::parseMapping(const QDomElement& mapping) // Get destination shape. QDomElement dst = mapping.firstChildElement("destination"); - QList dstPoints; + QVector dstPoints; if (mappingAttrType == "triangle_texture") { @@ -130,7 +130,7 @@ void ProjectReader::parseMapping(const QDomElement& mapping) // Get / parse source shape. QDomElement src = mapping.firstChildElement("source"); - QList srcPoints; + QVector srcPoints; _parseTriangle(src, srcPoints); uid id = _window->createTriangleTextureMapping(mappingAttrId.toInt(), mappingAttrPaintId.toInt(), srcPoints, dstPoints); @@ -147,7 +147,7 @@ void ProjectReader::parseMapping(const QDomElement& mapping) // Get / parse source shape. QDomElement src = mapping.firstChildElement("source"); - QList srcPoints; + QVector srcPoints; _parseMesh(src, srcPoints, nColumns, nRows); uid id = _window->createMeshTextureMapping(mappingAttrId.toInt(), mappingAttrPaintId.toInt(), nColumns, nRows, srcPoints, dstPoints); @@ -180,7 +180,7 @@ void ProjectReader::parseMapping(const QDomElement& mapping) _xml.raiseError(QObject::tr("Unsupported mapping type: %1.").arg(mappingAttrType)); } -void ProjectReader::_parseStandardShape(const QString& type, int nVertices, const QDomElement& shape, QList& points) +void ProjectReader::_parseStandardShape(const QString& type, int nVertices, const QDomElement& shape, QVector& points) { // Check that the element is really a triangle. QString typeAttr = shape.attribute("shape", ""); @@ -202,18 +202,18 @@ void ProjectReader::_parseStandardShape(const QString& type, int nVertices, cons _xml.raiseError(QObject::tr("Shape has %1 vertices: expected %2.").arg(points.size()).arg(nVertices)); } -void ProjectReader::_parseQuad(const QDomElement& quad, QList& points) +void ProjectReader::_parseQuad(const QDomElement& quad, QVector& points) { _parseStandardShape("quad", 4, quad, points); } -void ProjectReader::_parseTriangle(const QDomElement& triangle, QList& points) +void ProjectReader::_parseTriangle(const QDomElement& triangle, QVector& points) { _parseStandardShape("triangle", 3, triangle, points); } -void ProjectReader::_parseMesh(const QDomElement& mesh, QList& points, int& nColumns, int& nRows) +void ProjectReader::_parseMesh(const QDomElement& mesh, QVector& points, int& nColumns, int& nRows) { // Check that the element is really a mash. QString type = mesh.attribute("shape", ""); diff --git a/ProjectReader.h b/ProjectReader.h index d42a762..747828e 100644 --- a/ProjectReader.h +++ b/ProjectReader.h @@ -37,10 +37,10 @@ private: void parsePaint(const QDomElement& paint); void parseMapping(const QDomElement& mapping); - void _parseStandardShape(const QString& type, int nVertices, const QDomElement& shape, QList& points); - void _parseQuad(const QDomElement& quad, QList& points); - void _parseTriangle(const QDomElement& triangle, QList& points); - void _parseMesh(const QDomElement& mesh, QList& points, int& nColumns, int& nRows); + void _parseStandardShape(const QString& type, int nVertices, const QDomElement& shape, QVector& points); + void _parseQuad(const QDomElement& quad, QVector& points); + void _parseTriangle(const QDomElement& triangle, QVector& points); + void _parseMesh(const QDomElement& mesh, QVector& points, int& nColumns, int& nRows); QPointF _parseVertex(const QDomElement& vertex); // void readPaint(); //Paint *item); diff --git a/Shape.cpp b/Shape.cpp index 1a417eb..9a08c4c 100644 --- a/Shape.cpp +++ b/Shape.cpp @@ -60,26 +60,25 @@ bool Shape::includesPoint(int x, int y) void Shape::translate(int x, int y) { - for (std::vector::iterator it = vertices.begin() ; + for (QVector::iterator it = vertices.begin() ; it != vertices.end(); ++it) { - (*it)->setX((*it)->x() + x); - (*it)->setY((*it)->y() + y); + it->setX(it->x() + x); + it->setY(it->y() + y); } } QPolygonF Shape::toPolygon() const { QPolygonF polygon; - for (std::vector::const_iterator it = vertices.begin() ; + for (QVector::const_iterator it = vertices.begin() ; it != vertices.end(); ++it) { - polygon.append((*it)->toPoint()); + polygon.append(*it); } return polygon; } - Mesh::Mesh(QPointF p1, QPointF p2, QPointF p3, QPointF p4, int nColumns, int nRows) : Quad(p1, p2, p3, p4), _nColumns(0), _nRows(0) { @@ -87,7 +86,7 @@ Mesh::Mesh(QPointF p1, QPointF p2, QPointF p3, QPointF p4, int nColumns, int nRo init(nColumns, nRows); } -Mesh::Mesh(const QList& points, int nColumns, int nRows) +Mesh::Mesh(const QVector& points, int nColumns, int nRows) : Quad(), _nColumns(nColumns), _nRows(nRows) { Q_ASSERT(nColumns >= 2 && nRows >= 2); @@ -148,7 +147,7 @@ void Mesh::init(int nColumns, int nRows) void Mesh::addColumn() { // Create new vertices 2d (temporary). - std::vector< std::vector > newVertices2d; + IndexVector2d newVertices2d; resizeVertices2d(newVertices2d, nColumns()+1, nRows()); // Left displacement of points already there. @@ -201,7 +200,7 @@ void Mesh::addColumn() void Mesh::addRow() { // Create new vertices 2d (temporary). - std::vector< std::vector > newVertices2d; + IndexVector2d newVertices2d; resizeVertices2d(newVertices2d, nColumns(), nRows()+1); // Top displacement of points already there. @@ -313,9 +312,9 @@ void Mesh::resize(int nColumns_, int nRows_) // // } -std::vector Mesh::getQuads() const +QVector Mesh::getQuads() const { - std::vector quads; + QVector quads; for (int i=0; i Mesh::getQuads() const return quads; } -std::vector< std::vector > Mesh::getQuads2d() const +QVector< QVector > Mesh::getQuads2d() const { - std::vector< std::vector > quads2d; + QVector< QVector > quads2d; for (int i=0; i column; + QVector column; for (int j=0; j > Mesh::getQuads2d() const void Mesh::_reorderVertices() { // Populate new vertices vector. - std::vector newVertices(vertices.size()); + QVector newVertices(vertices.size()); int k = 0; for (int x=0; x +#include + #include +#include #include #include -#include -#include - -#include -#include +#include +#include #include -#include #include -#include + /** * Point (or vertex) on the 2-D canvas. */ - -Q_DECLARE_METATYPE (qreal) - -class Point: public QObject, public QPointF -{ - Q_OBJECT - -public: - Q_PROPERTY(qreal x READ x WRITE setX NOTIFY xChanged) - Q_PROPERTY(qreal y READ y WRITE setY NOTIFY yChanged) - Q_INVOKABLE Point(qreal x, qreal y): QPointF(x,y) {} - Q_INVOKABLE Point(): QPointF(0,0) {} - -signals: - void xChanged(); - void yChanged(); - -public slots: - void setX(qreal x) - { - QPointF::setX(x); - emit xChanged(); - } - void setY(qreal y) - { - QPointF::setY(y); - emit yChanged(); - } - void setValue(const QPointF& p) - { - setX(p.x()); - setY(p.y()); - } - -}; /** * Series of vertices. (points) */ @@ -80,7 +45,7 @@ public: typedef std::tr1::shared_ptr ptr; Shape() {} - Shape(std::vector vertices_) : + Shape(QVector vertices_) : vertices(vertices_) {} virtual ~Shape() {} @@ -164,12 +129,15 @@ public: }; class Mesh : public Quad { + + typedef QVector > IndexVector2d; + public: Mesh() : _nColumns(0), _nRows(0) { init(1, 1); } Mesh(QPointF p1, QPointF p2, QPointF p3, QPointF p4, int nColumns=2, int nRows=2); - Mesh(const QList& points, int nColumns, int nRows); + Mesh(const QVector& points, int nColumns, int nRows); virtual ~Mesh() {} virtual QString getType() const { return "mesh"; } @@ -191,7 +159,7 @@ public: vertices[_vertices2d[i][j]] = QPointF(x, y); } - void resizeVertices2d(std::vector< std::vector >& vertices2d, int nColumns, int nRows); + void resizeVertices2d(IndexVector2d& vertices2d, int nColumns, int nRows); void init(int nColumns, int nRows); @@ -203,8 +171,8 @@ public: // void removeColumn(int columnId); - std::vector getQuads() const; - std::vector< std::vector > getQuads2d() const; + QVector getQuads() const; + QVector > getQuads2d() const; int nColumns() const { return _nColumns; } int nRows() const { return _nRows; } @@ -216,9 +184,7 @@ protected: int _nColumns; int _nRows; // _vertices[i][j] contains vertex id of vertex at position (i,j) where i = 0..nColumns and j = 0..nRows - std::vector< std::vector > _vertices2d; - // Maps a vertex id to the pair of vertex ids it "splits". - std::map > _splitVertices; + IndexVector2d _vertices2d; /** * Reorder vertices in a standard order: