scantools  1.0.4
Graphics manipulation with a view towards scanned documents
Public Types | Public Member Functions | List of all members
length Class Reference

The length stores a length and converts between units. More...

#include <length.h>

Public Types

enum  unit { cm , in , mm , pt }
 List of supported units. More...
 

Public Member Functions

 length ()
 Constructs a zero length.
 
 length (qreal l, unit u)
 Constructs length of given value and unit. More...
 
 length (QString lstring, bool *ok=0)
 Constructs length from a string. More...
 
qreal get (unit u) const
 Returns length in given unit. More...
 
void set (qreal l, unit u)
 Sets length. More...
 
bool set (QString lstring)
 Constructs length from a string. More...
 
bool isNonPositive () const
 Check if length is positive. More...
 
 operator QString () const
 Convert to human-readable string. More...
 
bool operator== (const length other) const
 Checks for equality. More...
 
const length operator+ (const length rhs) const
 Sum of the lengths. More...
 
const length operator- (const length rhs) const
 Difference of two lengths. More...
 
const length operator/ (const qreal div) const
 Divide a length by a number. More...
 

Detailed Description

The length stores a length and converts between units.

This is a trivial class that helps with length storage and conversions. Lengthes are stored intenally in 1/360mm, which allows conversions between units without rounding error.

The class "length" is known to the QMetaType systen and can be used as a custom type in QVariant.

Definition at line 37 of file length.h.

Member Enumeration Documentation

◆ unit

List of supported units.

Enumerator
cm 

Centimeter.

in 

Inch.

mm 

Millimeter.

pt 

Points (=1/72 inch)

Definition at line 41 of file length.h.

Constructor & Destructor Documentation

◆ length() [1/2]

length::length ( qreal  l,
unit  u 
)
inline

Constructs length of given value and unit.

Parameters
lScalar value of the length
uUnit for the length

Definition at line 59 of file length.h.

◆ length() [2/2]

length::length ( QString  lstring,
bool *  ok = 0 
)
inlineexplicit

Constructs length from a string.

This is a convenience method that calls set(QString) internally.

Parameters
lstringA string of the form "<number> unit", such as "12.3 mm".
okIf the string is not recoginzed *ok is set to false and the paper size if empty. Otherwise, *ok is set to true.

Definition at line 72 of file length.h.

Member Function Documentation

◆ get()

qreal length::get ( unit  u) const

Returns length in given unit.

Parameters
uUnit
Returns
Value for length in the given unit

◆ isNonPositive()

bool length::isNonPositive ( ) const
inline

Check if length is positive.

Returns
True if length is zero or less

Definition at line 106 of file length.h.

◆ operator QString()

length::operator QString ( ) const
inline

Convert to human-readable string.

Returns
Length in millimeter as a human-readable string

Definition at line 114 of file length.h.

◆ operator+()

const length length::operator+ ( const length  rhs) const
inline

Sum of the lengths.

Parameters
rhsLength to add
Returns
Sum of the lengths

Definition at line 135 of file length.h.

◆ operator-()

const length length::operator- ( const length  rhs) const
inline

Difference of two lengths.

Parameters
rhsLength to subtract from this length
Returns
Difference of the lengths

Definition at line 148 of file length.h.

◆ operator/()

const length length::operator/ ( const qreal  div) const
inline

Divide a length by a number.

Parameters
divScalar to divide this length by
Returns
Divided length

Definition at line 161 of file length.h.

◆ operator==()

bool length::operator== ( const length  other) const
inline

Checks for equality.

Parameters
otherOther length to check against
Returns
True if lengths are equal

Definition at line 124 of file length.h.

◆ set() [1/2]

void length::set ( qreal  l,
unit  u 
)

Sets length.

Parameters
lScalar value of the length
uUnit for the length

◆ set() [2/2]

bool length::set ( QString  lstring)

Constructs length from a string.

Parameters
lstringA string of the form "<number> unit", such as "12.3 mm".
Returns
If a conversion error occurs, false is returned and the length is undefined. Otherwise, the method returns true.

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