diff options
author | Gunnar Sletta <gunnar.sletta@nokia.com> | 2012-04-13 09:28:44 +0200 |
---|---|---|
committer | Qt by Nokia <qt-info@nokia.com> | 2012-04-13 18:15:26 +0200 |
commit | 84caba25d8cc0b7a050abc4d60393fbb3ec73391 (patch) | |
tree | 5f2ae53aa2f86019b170e0b1d7c25e62c8b4e4e7 /src | |
parent | 19524b7499c0a4b6f66d4797f04f06e140234149 (diff) |
Move QPainterPathPrivate to the private header files.
This was made inline for the sake of performance, but has in hindsight
proven to be not really worth it. It also prevents us from aligning
the internal datastructure of QPainterPath with that of QPolygonF
and the internal QVectorPath class which would make mapping
between the two inside QPainter a lot faster.
Making all this out-of-line now as discussed in the task
https://bugreports.qt-project.org/browse/QTBUG-19998
so we can adress this in a binary compatible fashion during
Qt 5.x
Change-Id: I61058171ed31f8a845fa45517248367c85ce52cd
Reviewed-by: Lars Knoll <lars.knoll@nokia.com>
Reviewed-by: Samuel Rødal <samuel.rodal@nokia.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/gui/painting/qmatrix.cpp | 1 | ||||
-rw-r--r-- | src/gui/painting/qpainterpath.cpp | 37 | ||||
-rw-r--r-- | src/gui/painting/qpainterpath.h | 67 | ||||
-rw-r--r-- | src/gui/painting/qpainterpath_p.h | 23 | ||||
-rw-r--r-- | src/gui/painting/qtransform.cpp | 1 |
5 files changed, 66 insertions, 63 deletions
diff --git a/src/gui/painting/qmatrix.cpp b/src/gui/painting/qmatrix.cpp index ced2e4548c..c26d7e5d98 100644 --- a/src/gui/painting/qmatrix.cpp +++ b/src/gui/painting/qmatrix.cpp @@ -44,6 +44,7 @@ #include "qmatrix.h" #include "qregion.h" #include "qpainterpath.h" +#include "qpainterpath_p.h" #include "qvariant.h" #include <qmath.h> diff --git a/src/gui/painting/qpainterpath.cpp b/src/gui/painting/qpainterpath.cpp index e098e7c761..0e8811b934 100644 --- a/src/gui/painting/qpainterpath.cpp +++ b/src/gui/painting/qpainterpath.cpp @@ -478,14 +478,26 @@ static void qt_debug_path(const QPainterPath &path) \sa ElementType, elementAt(), isEmpty() */ +int QPainterPath::elementCount() const +{ + return d_ptr ? d_ptr->elements.size() : 0; +} + /*! - \fn const QPainterPath::Element &QPainterPath::elementAt(int index) const + \fn QPainterPath::Element QPainterPath::elementAt(int index) const Returns the element at the given \a index in the painter path. \sa ElementType, elementCount(), isEmpty() */ +QPainterPath::Element QPainterPath::elementAt(int i) const +{ + Q_ASSERT(d_ptr); + Q_ASSERT(i >= 0 && i < elementCount()); + return d_ptr->elements.at(i); +} + /*! \fn void QPainterPath::setElementPositionAt(int index, qreal x, qreal y) \since 4.2 @@ -494,6 +506,17 @@ static void qt_debug_path(const QPainterPath &path) x and \a y. */ +void QPainterPath::setElementPositionAt(int i, qreal x, qreal y) +{ + Q_ASSERT(d_ptr); + Q_ASSERT(i >= 0 && i < elementCount()); + detach(); + QPainterPath::Element &e = d_ptr->elements[i]; + e.x = x; + e.y = y; +} + + /*### \fn QPainterPath &QPainterPath::operator +=(const QPainterPath &other) @@ -535,6 +558,13 @@ QPainterPath::QPainterPath(const QPointF &startPoint) d_func()->elements << e; } +void QPainterPath::detach() +{ + if (d_ptr->ref.load() != 1) + detach_helper(); + setDirty(true); +} + /*! \internal */ @@ -1451,6 +1481,11 @@ QRectF QPainterPath::controlPointRect() const \sa elementCount() */ +bool QPainterPath::isEmpty() const +{ + return !d_ptr || (d_ptr->elements.size() == 1 && d_ptr->elements.first().type == MoveToElement); +} + /*! Creates and returns a reversed copy of the path. diff --git a/src/gui/painting/qpainterpath.h b/src/gui/painting/qpainterpath.h index 40456bc163..7bb52f4125 100644 --- a/src/gui/painting/qpainterpath.h +++ b/src/gui/painting/qpainterpath.h @@ -165,7 +165,7 @@ public: Qt::FillRule fillRule() const; void setFillRule(Qt::FillRule fillRule); - inline bool isEmpty() const; + bool isEmpty() const; QPainterPath toReversed() const; QList<QPolygonF> toSubpathPolygons(const QMatrix &matrix = QMatrix()) const; @@ -175,9 +175,9 @@ public: QList<QPolygonF> toFillPolygons(const QTransform &matrix) const; QPolygonF toFillPolygon(const QTransform &matrix) const; - inline int elementCount() const; - inline const QPainterPath::Element &elementAt(int i) const; - inline void setElementPositionAt(int i, qreal x, qreal y); + int elementCount() const; + QPainterPath::Element elementAt(int i) const; + void setElementPositionAt(int i, qreal x, qreal y); qreal length() const; qreal percentAtLength(qreal t) const; @@ -211,7 +211,7 @@ private: inline void ensureData() { if (!d_ptr) ensureData_helper(); } void ensureData_helper(); - inline void detach(); + void detach(); void detach_helper(); void setDirty(bool); void computeBoundingRect() const; @@ -233,29 +233,6 @@ private: #endif }; -class QPainterPathPrivate -{ -public: - friend class QPainterPath; - friend class QPainterPathData; - friend class QPainterPathStroker; - friend class QPainterPathStrokerPrivate; - friend class QMatrix; - friend class QTransform; - friend class QVectorPath; - friend struct QPainterPathPrivateDeleter; -#ifndef QT_NO_DATASTREAM - friend Q_GUI_EXPORT QDataStream &operator<<(QDataStream &, const QPainterPath &); - friend Q_GUI_EXPORT QDataStream &operator>>(QDataStream &, QPainterPath &); -#endif - - QPainterPathPrivate() : ref(1) {} - -private: - QAtomicInt ref; - QVector<QPainterPath::Element> elements; -}; - Q_DECLARE_TYPEINFO(QPainterPath::Element, Q_PRIMITIVE_TYPE); #ifndef QT_NO_DATASTREAM @@ -391,40 +368,6 @@ inline void QPainterPath::translate(const QPointF &offset) inline QPainterPath QPainterPath::translated(const QPointF &offset) const { return translated(offset.x(), offset.y()); } -inline bool QPainterPath::isEmpty() const -{ - return !d_ptr || (d_ptr->elements.size() == 1 && d_ptr->elements.first().type == MoveToElement); -} - -inline int QPainterPath::elementCount() const -{ - return d_ptr ? d_ptr->elements.size() : 0; -} - -inline const QPainterPath::Element &QPainterPath::elementAt(int i) const -{ - Q_ASSERT(d_ptr); - Q_ASSERT(i >= 0 && i < elementCount()); - return d_ptr->elements.at(i); -} - -inline void QPainterPath::setElementPositionAt(int i, qreal x, qreal y) -{ - Q_ASSERT(d_ptr); - Q_ASSERT(i >= 0 && i < elementCount()); - detach(); - QPainterPath::Element &e = d_ptr->elements[i]; - e.x = x; - e.y = y; -} - - -inline void QPainterPath::detach() -{ - if (d_ptr->ref.load() != 1) - detach_helper(); - setDirty(true); -} #ifndef QT_NO_DEBUG_STREAM Q_GUI_EXPORT QDebug operator<<(QDebug, const QPainterPath &); diff --git a/src/gui/painting/qpainterpath_p.h b/src/gui/painting/qpainterpath_p.h index a9068f3855..116ea63425 100644 --- a/src/gui/painting/qpainterpath_p.h +++ b/src/gui/painting/qpainterpath_p.h @@ -65,6 +65,29 @@ QT_BEGIN_NAMESPACE +class QPainterPathPrivate +{ +public: + friend class QPainterPath; + friend class QPainterPathData; + friend class QPainterPathStroker; + friend class QPainterPathStrokerPrivate; + friend class QMatrix; + friend class QTransform; + friend class QVectorPath; + friend struct QPainterPathPrivateDeleter; +#ifndef QT_NO_DATASTREAM + friend Q_GUI_EXPORT QDataStream &operator<<(QDataStream &, const QPainterPath &); + friend Q_GUI_EXPORT QDataStream &operator>>(QDataStream &, QPainterPath &); +#endif + + QPainterPathPrivate() : ref(1) {} + +private: + QAtomicInt ref; + QVector<QPainterPath::Element> elements; +}; + class QPainterPathStrokerPrivate { public: diff --git a/src/gui/painting/qtransform.cpp b/src/gui/painting/qtransform.cpp index e5c41efc15..ba971d454d 100644 --- a/src/gui/painting/qtransform.cpp +++ b/src/gui/painting/qtransform.cpp @@ -45,6 +45,7 @@ #include "qmatrix.h" #include "qregion.h" #include "qpainterpath.h" +#include "qpainterpath_p.h" #include "qvariant.h" #include <qmath.h> #include <qnumeric.h> |