QtBase  v6.3.1
Public Member Functions | 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 Member Functions

constexpr QLine ()
 
constexpr QLine (const QPoint &pt1, const QPoint &pt2)
 
constexpr QLine (int x1, int y1, int x2, int y2)
 
constexpr bool isNull () const
 
constexpr QPoint p1 () const
 
constexpr QPoint p2 () const
 
constexpr int x1 () const
 
constexpr int y1 () const
 
constexpr int x2 () const
 
constexpr int y2 () const
 
constexpr int dx () const
 
constexpr int dy () const
 
void translate (const QPoint &p)
 
void translate (int dx, int dy)
 
constexpr QLine translated (const QPoint &p) const
 
constexpr QLine translated (int dx, int dy) const
 
constexpr QPoint center () const
 
void setP1 (const QPoint &p1)
 
void setP2 (const QPoint &p2)
 
void setPoints (const QPoint &p1, const QPoint &p2)
 
void setLine (int x1, int y1, int x2, int y2)
 
constexpr bool operator== (const QLine &d) const noexcept
 
constexpr bool operator!= (const QLine &d) const noexcept
 

Related Functions

(Note that these are not member functions.)

QDataStreamoperator<< (QDataStream &stream, const QLine &line)
 
QDataStreamoperator>> (QDataStream &stream, QLine &line)
 

Detailed Description

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

\inmodule QtCore

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.

\table \row

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 52 of file qline.h.

Constructor & Destructor Documentation

◆ QLine() [1/3]

constexpr QLine::QLine ( )
inlineconstexpr

Constructs a null line.

Definition at line 98 of file qline.h.

Here is the caller graph for this function:

◆ QLine() [2/3]

constexpr QLine::QLine ( const QPoint p1,
const QPoint p2 
)
inlineconstexpr

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

Definition at line 100 of file qline.h.

◆ QLine() [3/3]

constexpr QLine::QLine ( int  x1,
int  y1,
int  x2,
int  y2 
)
inlineconstexpr

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

Definition at line 102 of file qline.h.

Member Function Documentation

◆ center()

constexpr QPoint QLine::center ( ) const
inlineconstexpr
Since
5.8

Returns the center point of this line. This is equivalent to (p1() + p2()) / 2, except it will never overflow.

Definition at line 170 of file qline.h.

Here is the call graph for this function:

◆ dx()

constexpr int QLine::dx ( ) const
inlineconstexpr

Returns the horizontal component of the line's vector.

See also
dy()

Definition at line 139 of file qline.h.

Here is the call graph for this function:

◆ dy()

constexpr int QLine::dy ( ) const
inlineconstexpr

Returns the vertical component of the line's vector.

See also
dx()

Definition at line 144 of file qline.h.

Here is the call graph for this function:

◆ isNull()

constexpr bool QLine::isNull ( ) const
inlineconstexpr

Returns true if the line does not have distinct start and end points; otherwise returns false.

Definition at line 104 of file qline.h.

◆ operator!=()

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

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 87 of file qline.h.

◆ operator==()

constexpr bool QLine::operator== ( const QLine line) const
inlineconstexprnoexcept

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 197 of file qline.h.

◆ p1()

constexpr QPoint QLine::p1 ( ) const
inlineconstexpr

Returns the line's start point.

See also
x1(), y1(), p2()

Definition at line 129 of file qline.h.

◆ p2()

constexpr QPoint QLine::p2 ( ) const
inlineconstexpr

Returns the line's end point.

See also
x2(), y2(), p1()

Definition at line 134 of file qline.h.

◆ setLine()

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

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

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

Definition at line 191 of file qline.h.

◆ setP1()

void QLine::setP1 ( const QPoint p1)
inline
Since
4.4

Sets the starting point of this line to p1.

See also
setP2(), p1()

Definition at line 175 of file qline.h.

◆ setP2()

void QLine::setP2 ( const QPoint p2)
inline
Since
4.4

Sets the end point of this line to p2.

See also
setP1(), p2()

Definition at line 180 of file qline.h.

◆ setPoints()

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

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

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

Definition at line 185 of file qline.h.

◆ translate() [1/2]

void QLine::translate ( const QPoint offset)
inline

Translates this line by the given offset.

Definition at line 149 of file qline.h.

Here is the caller graph for this function:

◆ translate() [2/2]

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

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

Translates this line the distance specified by dx and dy.

Definition at line 155 of file qline.h.

Here is the call graph for this function:

◆ translated() [1/2]

constexpr QLine QLine::translated ( const QPoint offset) const
inlineconstexpr
Since
4.4

Returns this line translated by the given offset.

Definition at line 160 of file qline.h.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ translated() [2/2]

constexpr QLine QLine::translated ( int  dx,
int  dy 
) const
inlineconstexpr

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

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

Definition at line 165 of file qline.h.

Here is the call graph for this function:

◆ x1()

constexpr int QLine::x1 ( ) const
inlineconstexpr

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

See also
p1()

Definition at line 109 of file qline.h.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ x2()

constexpr int QLine::x2 ( ) const
inlineconstexpr

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

See also
p2()

Definition at line 119 of file qline.h.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ y1()

constexpr int QLine::y1 ( ) const
inlineconstexpr

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

See also
p1()

Definition at line 114 of file qline.h.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ y2()

constexpr int QLine::y2 ( ) const
inlineconstexpr

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

See also
p2()

Definition at line 124 of file qline.h.

Here is the call graph for this function:
Here is the caller graph for this function:

Friends And Related Function Documentation

◆ 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 287 of file qline.cpp.

◆ 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 302 of file qline.cpp.


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