Qt 4.8
qpoint.cpp
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/legal
5 **
6 ** This file is part of the QtCore module of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia. For licensing terms and
14 ** conditions see http://qt.digia.com/licensing. For further information
15 ** use the contact form at http://qt.digia.com/contact-us.
16 **
17 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24 **
25 ** In addition, as a special exception, Digia gives you certain additional
26 ** rights. These rights are described in the Digia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28 **
29 ** GNU General Public License Usage
30 ** Alternatively, this file may be used under the terms of the GNU
31 ** General Public License version 3.0 as published by the Free Software
32 ** Foundation and appearing in the file LICENSE.GPL included in the
33 ** packaging of this file. Please review the following information to
34 ** ensure the GNU General Public License version 3.0 requirements will be
35 ** met: http://www.gnu.org/copyleft/gpl.html.
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41 
42 #include "qpoint.h"
43 #include "qdatastream.h"
44 #include "qdebug.h"
45 
47 
84 /*****************************************************************************
85  QPoint member functions
86  *****************************************************************************/
87 
418 /*****************************************************************************
419  QPoint stream functions
420  *****************************************************************************/
421 #ifndef QT_NO_DATASTREAM
422 
436 {
437  if (s.version() == 1)
438  s << (qint16)p.x() << (qint16)p.y();
439  else
440  s << (qint32)p.x() << (qint32)p.y();
441  return s;
442 }
443 
458 {
459  if (s.version() == 1) {
460  qint16 x, y;
461  s >> x; p.rx() = x;
462  s >> y; p.ry() = y;
463  }
464  else {
465  qint32 x, y;
466  s >> x; p.rx() = x;
467  s >> y; p.ry() = y;
468  }
469  return s;
470 }
471 
472 #endif // QT_NO_DATASTREAM
473 
490 {
491  return qAbs(x())+qAbs(y());
492 }
493 
494 #ifndef QT_NO_DEBUG_STREAM
495 QDebug operator<<(QDebug dbg, const QPoint &p) {
496  dbg.nospace() << "QPoint(" << p.x() << ',' << p.y() << ')';
497  return dbg.space();
498 }
499 
501 {
502  d.nospace() << "QPointF(" << p.x() << ", " << p.y() << ')';
503  return d.space();
504 }
505 #endif
506 
604 {
605  return qAbs(x())+qAbs(y());
606 }
607 
835 #ifndef QT_NO_DATASTREAM
836 
850 {
851  s << double(p.x()) << double(p.y());
852  return s;
853 }
854 
869 {
870  double x, y;
871  s >> x;
872  s >> y;
873  p.setX(qreal(x));
874  p.setY(qreal(y));
875  return s;
876 }
877 #endif // QT_NO_DATASTREAM
878 
The QDebug class provides an output stream for debugging information.
Definition: qdebug.h:62
double d
Definition: qnumeric_p.h:62
double qreal
Definition: qglobal.h:1193
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
int qint32
Definition: qglobal.h:937
QDebug & nospace()
Clears the stream&#39;s internal flag that records whether the last character was a space and returns a r...
Definition: qdebug.h:92
void setY(qreal y)
Sets the y coordinate of this point to the given y coordinate.
Definition: qpoint.h:297
The QPointF class defines a point in the plane using floating point precision.
Definition: qpoint.h:214
int & ry()
Returns a reference to the y coordinate of this point.
Definition: qpoint.h:143
Q_DECL_CONSTEXPR T qAbs(const T &t)
Definition: qglobal.h:1201
qreal x() const
Returns the x-coordinate of this point.
Definition: qpoint.h:282
QDataStream & operator<<(QDataStream &stream, const QPoint &point)
Writes the given point to the given stream and returns a reference to the stream. ...
Definition: qpoint.cpp:435
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
int manhattanLength() const
Returns the sum of the absolute values of x() and y(), traditionally known as the "Manhattan length" ...
Definition: qpoint.cpp:489
short qint16
Definition: qglobal.h:935
int & rx()
Returns a reference to the x coordinate of this point.
Definition: qpoint.h:140
int version() const
Returns the version number of the data serialization format.
Definition: qdatastream.h:212
qreal manhattanLength() const
Returns the sum of the absolute values of x() and y(), traditionally known as the "Manhattan length" ...
Definition: qpoint.cpp:603
QDataStream & operator>>(QDataStream &stream, QPoint &point)
Reads a point from the given stream into the given point and returns a reference to the stream...
Definition: qpoint.cpp:457
The QPoint class defines a point in the plane using integer precision.
Definition: qpoint.h:53
int y() const
Returns the y coordinate of this point.
Definition: qpoint.h:131
void setX(qreal x)
Sets the x coordinate of this point to the given x coordinate.
Definition: qpoint.h:292
qreal y() const
Returns the y-coordinate of this point.
Definition: qpoint.h:287
The QDataStream class provides serialization of binary data to a QIODevice.
Definition: qdatastream.h:71
int x() const
Returns the x coordinate of this point.
Definition: qpoint.h:128
QDebug & space()
Writes a space character to the debug stream and returns a reference to the stream.
Definition: qdebug.h:91
QDataStream & operator<<(QDataStream &out, const QUrl &url)
Writes url url to the stream out and returns a reference to the stream.
Definition: qurl.cpp:6757
QDataStream & operator>>(QDataStream &in, QUrl &url)
Reads a url into url from the stream in and returns a reference to the stream.
Definition: qurl.cpp:6774