Qt 4.8
Public Functions | Properties | Related Functions | List of all members
QLine Class Reference

The QLine class provides a two-dimensional vector using integer precision. More...

#include <qline.h>

Public Functions

int dx () const
 Returns the horizontal component of the line's vector. More...
 
int dy () const
 Returns the vertical component of the line's vector. More...
 
bool isNull () const
 Returns true if the line is not set up with valid start and end point; otherwise returns false. More...
 
bool operator!= (const QLine &d) const
 Returns true if the given line is not the same as this line. More...
 
bool operator== (const QLine &d) const
 Returns true if the given line is the same as this line. More...
 
QPoint p1 () const
 Returns the line's start point. More...
 
QPoint p2 () const
 Returns the line's end point. More...
 
 QLine ()
 Constructs a null line. More...
 
 QLine (const QPoint &pt1, const QPoint &pt2)
 Constructs a line object that represents the line between p1 and p2. More...
 
 QLine (int x1, int y1, int x2, int y2)
 Constructs a line object that represents the line between (x1, y1) and (x2, y2). More...
 
void setLine (int x1, int y1, int x2, int y2)
 Sets this line to the start in x1, y1 and end in x2, y2. More...
 
void setP1 (const QPoint &p1)
 Sets the starting point of this line to p1. More...
 
void setP2 (const QPoint &p2)
 Sets the end point of this line to p2. More...
 
void setPoints (const QPoint &p1, const QPoint &p2)
 Sets the start point of this line to p1 and the end point of this line to p2. More...
 
void translate (const QPoint &p)
 Translates this line by the given offset. More...
 
void translate (int dx, int dy)
 Translates this line the distance specified by dx and dy. More...
 
QLine translated (const QPoint &p) const
 Returns this line translated by the given offset. More...
 
QLine translated (int dx, int dy) const
 Returns this line translated the distance specified by dx and dy. More...
 
int x1 () const
 Returns the x-coordinate of the line's start point. More...
 
int x2 () const
 Returns the x-coordinate of the line's end point. More...
 
int y1 () const
 Returns the y-coordinate of the line's start point. More...
 
int y2 () const
 Returns the y-coordinate of the line's end point. More...
 

Properties

QPoint pt1
 
QPoint pt2
 

Related Functions

(Note that these are not member functions.)

QDataStreamoperator<< (QDataStream &stream, const QLine &line)
 Writes the given line to the given stream and returns a reference to the stream. More...
 
QDataStreamoperator>> (QDataStream &stream, QLine &line)
 Reads a line from the given stream into the given line and returns a reference to the stream. More...
 

Detailed Description

The QLine class provides a two-dimensional vector using integer precision.

A QLine describes a finite length line (or a line segment) on a two-dimensional surface. The start and end points of the line are specified using integer point accuracy for coordinates. Use the QLineF constructor to retrieve a floating point copy.

qline-point.png
qline-coordinates.png

The positions of the line's start and end points can be retrieved using the p1(), x1(), y1(), p2(), x2(), and y2() functions. The dx() and dy() functions return the horizontal and vertical components of the line. Use isNull() to determine whether the QLine represents a valid line or a null line.

Finally, the line can be translated a given offset using the translate() function.

See also
QLineF, QPolygon, QRect

Definition at line 57 of file qline.h.

Constructors and Destructors

◆ QLine() [1/3]

QLine::QLine ( )
inline

Constructs a null line.

Definition at line 101 of file qline.h.

Referenced by translated().

101 { }

◆ QLine() [2/3]

QLine::QLine ( const QPoint pt1,
const QPoint pt2 
)
inline

Constructs a line object that represents the line between p1 and p2.

Definition at line 103 of file qline.h.

103 : pt1(pt1_), pt2(pt2_) { }
QPoint pt2
Definition: qline.h:93
QPoint pt1
Definition: qline.h:93

◆ QLine() [3/3]

QLine::QLine ( int  x1,
int  y1,
int  x2,
int  y2 
)
inline

Constructs a line object that represents the line between (x1, y1) and (x2, y2).

Definition at line 105 of file qline.h.

105 : pt1(QPoint(x1pos, y1pos)), pt2(QPoint(x2pos, y2pos)) { }
QPoint pt2
Definition: qline.h:93
The QPoint class defines a point in the plane using integer precision.
Definition: qpoint.h:53
QPoint pt1
Definition: qline.h:93

Functions

◆ dx()

int QLine::dx ( ) const
inline

Returns the horizontal component of the line's vector.

See also
dy()

Definition at line 142 of file qline.h.

Referenced by QLineF::QLineF().

143 {
144  return pt2.x() - pt1.x();
145 }
QPoint pt2
Definition: qline.h:93
QPoint pt1
Definition: qline.h:93
int x() const
Returns the x coordinate of this point.
Definition: qpoint.h:128

◆ dy()

int QLine::dy ( ) const
inline

Returns the vertical component of the line's vector.

See also
dx()

Definition at line 147 of file qline.h.

Referenced by QLineF::QLineF().

148 {
149  return pt2.y() - pt1.y();
150 }
QPoint pt2
Definition: qline.h:93
int y() const
Returns the y coordinate of this point.
Definition: qpoint.h:131
QPoint pt1
Definition: qline.h:93

◆ isNull()

bool QLine::isNull ( ) const
inline

Returns true if the line is not set up with valid start and end point; otherwise returns false.

Definition at line 107 of file qline.h.

Referenced by QLineF::QLineF().

108 {
109  return pt1 == pt2;
110 }
QPoint pt2
Definition: qline.h:93
QPoint pt1
Definition: qline.h:93

◆ operator!=()

bool QLine::operator!= ( const QLine line) const
inline

Returns true if the given line is not the same as this line.

A line is different from another line if any of their start or end points differ, or the internal order of the points is different.

Definition at line 90 of file qline.h.

90 { return !(*this == d); }
double d
Definition: qnumeric_p.h:62

◆ operator==()

bool QLine::operator== ( const QLine line) const
inline

Returns true if the given line is the same as this line.

A line is identical to another line if the start and end points are identical, and the internal order of the points is the same.

Definition at line 195 of file qline.h.

Referenced by QLineF::QLineF().

196 {
197  return pt1 == d.pt1 && pt2 == d.pt2;
198 }
double d
Definition: qnumeric_p.h:62
QPoint pt2
Definition: qline.h:93
QPoint pt1
Definition: qline.h:93

◆ p1()

QPoint QLine::p1 ( ) const
inline

◆ p2()

QPoint QLine::p2 ( ) const
inline

◆ setLine()

void QLine::setLine ( int  x1,
int  y1,
int  x2,
int  y2 
)
inline

Sets this line to the start in x1, y1 and end in x2, y2.

Since
4.4
See also
setP1(), setP2(), p1(), p2()

Definition at line 189 of file qline.h.

Referenced by QLineF::QLineF().

190 {
191  pt1 = QPoint(aX1, aY1);
192  pt2 = QPoint(aX2, aY2);
193 }
QPoint pt2
Definition: qline.h:93
The QPoint class defines a point in the plane using integer precision.
Definition: qpoint.h:53
QPoint pt1
Definition: qline.h:93

◆ setP1()

void QLine::setP1 ( const QPoint p1)
inline

Sets the starting point of this line to p1.

Since
4.4
See also
setP2(), p1()

Definition at line 173 of file qline.h.

Referenced by QLineF::QLineF().

174 {
175  pt1 = aP1;
176 }
QPoint pt1
Definition: qline.h:93

◆ setP2()

void QLine::setP2 ( const QPoint p2)
inline

Sets the end point of this line to p2.

Since
4.4
See also
setP1(), p2()

Definition at line 178 of file qline.h.

Referenced by QLineF::QLineF().

179 {
180  pt2 = aP2;
181 }
QPoint pt2
Definition: qline.h:93

◆ setPoints()

void QLine::setPoints ( const QPoint p1,
const QPoint p2 
)
inline

Sets the start point of this line to p1 and the end point of this line to p2.

Since
4.4
See also
setP1(), setP2(), p1(), p2()

Definition at line 183 of file qline.h.

Referenced by QLineF::QLineF().

184 {
185  pt1 = aP1;
186  pt2 = aP2;
187 }
QPoint pt2
Definition: qline.h:93
QPoint pt1
Definition: qline.h:93

◆ translate() [1/2]

void QLine::translate ( const QPoint p)
inline

Translates this line by the given offset.

Definition at line 152 of file qline.h.

Referenced by QLineF::QLineF(), and translate().

153 {
154  pt1 += point;
155  pt2 += point;
156 }
QPoint pt2
Definition: qline.h:93
QPoint pt1
Definition: qline.h:93

◆ translate() [2/2]

void QLine::translate ( int  dx,
int  dy 
)
inline

Translates this line the distance specified by dx and dy.

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Definition at line 158 of file qline.h.

159 {
160  this->translate(QPoint(adx, ady));
161 }
void translate(const QPoint &p)
Translates this line by the given offset.
Definition: qline.h:152
The QPoint class defines a point in the plane using integer precision.
Definition: qpoint.h:53

◆ translated() [1/2]

QLine QLine::translated ( const QPoint offset) const
inline

Returns this line translated by the given offset.

Since
4.4

Definition at line 163 of file qline.h.

Referenced by QLineF::QLineF(), and translated().

164 {
165  return QLine(pt1 + p, pt2 + p);
166 }
QPoint pt2
Definition: qline.h:93
QLine()
Constructs a null line.
Definition: qline.h:101
QPoint pt1
Definition: qline.h:93

◆ translated() [2/2]

QLine QLine::translated ( int  dx,
int  dy 
) const
inline

Returns this line translated the distance specified by dx and dy.

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Since
4.4

Definition at line 168 of file qline.h.

169 {
170  return translated(QPoint(adx, ady));
171 }
The QPoint class defines a point in the plane using integer precision.
Definition: qpoint.h:53
QLine translated(const QPoint &p) const
Returns this line translated by the given offset.
Definition: qline.h:163

◆ x1()

int QLine::x1 ( ) const
inline

Returns the x-coordinate of the line's start point.

See also
p1()

Definition at line 112 of file qline.h.

Referenced by QVGPaintEngine::drawLines(), QOpenGLPaintEngine::drawLines(), QPaintEngine::drawLines(), drawLines(), QTransform::map(), and QLineF::QLineF().

113 {
114  return pt1.x();
115 }
QPoint pt1
Definition: qline.h:93
int x() const
Returns the x coordinate of this point.
Definition: qpoint.h:128

◆ x2()

int QLine::x2 ( ) const
inline

Returns the x-coordinate of the line's end point.

See also
p2()

Definition at line 122 of file qline.h.

Referenced by QVGPaintEngine::drawLines(), QOpenGLPaintEngine::drawLines(), QPaintEngine::drawLines(), drawLines(), QTransform::map(), and QLineF::QLineF().

123 {
124  return pt2.x();
125 }
QPoint pt2
Definition: qline.h:93
int x() const
Returns the x coordinate of this point.
Definition: qpoint.h:128

◆ y1()

int QLine::y1 ( ) const
inline

Returns the y-coordinate of the line's start point.

See also
p1()

Definition at line 117 of file qline.h.

Referenced by QVGPaintEngine::drawLines(), QOpenGLPaintEngine::drawLines(), QPaintEngine::drawLines(), drawLines(), QTransform::map(), and QLineF::QLineF().

118 {
119  return pt1.y();
120 }
int y() const
Returns the y coordinate of this point.
Definition: qpoint.h:131
QPoint pt1
Definition: qline.h:93

◆ y2()

int QLine::y2 ( ) const
inline

Returns the y-coordinate of the line's end point.

See also
p2()

Definition at line 127 of file qline.h.

Referenced by QVGPaintEngine::drawLines(), QOpenGLPaintEngine::drawLines(), QPaintEngine::drawLines(), drawLines(), QTransform::map(), and QLineF::QLineF().

128 {
129  return pt2.y();
130 }
QPoint pt2
Definition: qline.h:93
int y() const
Returns the y coordinate of this point.
Definition: qpoint.h:131

Friends and Related Functions

◆ operator<<()

QDataStream & operator<< ( QDataStream stream,
const QLine line 
)
related

Writes the given line to the given stream and returns a reference to the stream.

See also
{Serializing Qt Data Types}

Definition at line 350 of file qline.cpp.

Referenced by operator==().

351 {
352  stream << line.p1() << line.p2();
353  return stream;
354 }
QPoint p1() const
Returns the line&#39;s start point.
Definition: qline.h:132
QPoint p2() const
Returns the line&#39;s end point.
Definition: qline.h:137
static FILE * stream

◆ operator>>()

QDataStream & operator>> ( QDataStream stream,
QLine line 
)
related

Reads a line from the given stream into the given line and returns a reference to the stream.

See also
{Serializing Qt Data Types}

Definition at line 368 of file qline.cpp.

Referenced by operator==().

369 {
370  QPoint p1, p2;
371  stream >> p1;
372  stream >> p2;
373  line = QLine(p1, p2);
374 
375  return stream;
376 }
QPoint p1() const
Returns the line&#39;s start point.
Definition: qline.h:132
QPoint p2() const
Returns the line&#39;s end point.
Definition: qline.h:137
static FILE * stream
QLine()
Constructs a null line.
Definition: qline.h:101
The QPoint class defines a point in the plane using integer precision.
Definition: qpoint.h:53

Properties

◆ pt1

QPoint QLine::pt1
private

Definition at line 93 of file qline.h.

Referenced by dx(), dy(), isNull(), operator==(), p1(), setLine(), setP1(), setPoints(), translate(), translated(), x1(), and y1().

◆ pt2

QPoint QLine::pt2
private

Definition at line 93 of file qline.h.

Referenced by dx(), dy(), isNull(), operator==(), p2(), setLine(), setP2(), setPoints(), translate(), translated(), x2(), and y2().


The documentation for this class was generated from the following files: