diff -r 56cd8111b7f7 -r 41300fa6a67c src/gui/math3d/qgenericmatrix.h --- a/src/gui/math3d/qgenericmatrix.h Tue Jan 26 12:42:25 2010 +0200 +++ b/src/gui/math3d/qgenericmatrix.h Tue Feb 02 00:43:10 2010 +0200 @@ -44,6 +44,7 @@ #include #include +#include QT_BEGIN_HEADER @@ -63,7 +64,7 @@ T& operator()(int row, int column); bool isIdentity() const; - void setIdentity(); + void setToIdentity(); void fill(T value); @@ -76,7 +77,7 @@ bool operator==(const QGenericMatrix& other) const; bool operator!=(const QGenericMatrix& other) const; - void toValueArray(T *values); + void copyDataTo(T *values) const; T *data() { return m[0]; } const T *data() const { return m[0]; } @@ -113,7 +114,7 @@ template Q_INLINE_TEMPLATE QGenericMatrix::QGenericMatrix() { - setIdentity(); + setToIdentity(); } template @@ -164,7 +165,7 @@ } template -Q_OUTOFLINE_TEMPLATE void QGenericMatrix::setIdentity() +Q_OUTOFLINE_TEMPLATE void QGenericMatrix::setToIdentity() { for (int col = 0; col < N; ++col) { for (int row = 0; row < M; ++row) { @@ -316,7 +317,7 @@ } template -Q_OUTOFLINE_TEMPLATE void QGenericMatrix::toValueArray(T *values) +Q_OUTOFLINE_TEMPLATE void QGenericMatrix::copyDataTo(T *values) const { for (int col = 0; col < N; ++col) for (int row = 0; row < M; ++row) @@ -352,6 +353,32 @@ #endif +#ifndef QT_NO_DATASTREAM + +template +QDataStream &operator<<(QDataStream &stream, const QGenericMatrix &matrix) +{ + for (int row = 0; row < M; ++row) + for (int col = 0; col < N; ++col) + stream << double(matrix(row, col)); + return stream; +} + +template +QDataStream &operator>>(QDataStream &stream, QGenericMatrix &matrix) +{ + double x; + for (int row = 0; row < M; ++row) { + for (int col = 0; col < N; ++col) { + stream >> x; + matrix(row, col) = T(x); + } + } + return stream; +} + +#endif + QT_END_NAMESPACE Q_DECLARE_METATYPE(QMatrix2x2)