KReportUnit
#include <KReportUnit.h>
Public Types | |
enum class | Type { Invalid , Millimeter , Centimeter , Decimeter , Inch , Pica , Cicero , Point , Pixel , Last = Pixel } |
Public Member Functions | |
KReportUnit () | |
KReportUnit (const KReportUnit &other) | |
KReportUnit (Type type, qreal factor=1.0) | |
QPointF | convertFromPoint (const QPointF &ptValue) const |
QSizeF | convertFromPoint (const QSizeF &ptValue) const |
qreal | convertFromPoint (qreal ptValue) const |
QPointF | convertToPoint (const QPointF &value) const |
QSizeF | convertToPoint (const QSizeF &value) const |
qreal | convertToPoint (const QString &value, bool *ok=nullptr) const |
qreal | convertToPoint (qreal value) const |
QString | description () const |
qreal | factor () const |
qreal | fromUserValue (const QString &value, bool *ok=nullptr) const |
qreal | fromUserValue (qreal value) const |
bool | isValid () const |
bool | operator!= (const KReportUnit &other) const |
KReportUnit & | operator= (const KReportUnit &other) |
KReportUnit & | operator= (Type type) |
bool | operator== (const KReportUnit &other) const |
void | setFactor (qreal factor) |
QString | symbol () const |
QString | toString () const |
QString | toUserStringValue (qreal ptValue) const |
qreal | toUserValue (qreal ptValue) const |
KReportUnit::Type | type () const |
Static Public Member Functions | |
static QList< Type > | allTypes () |
static QPointF | convertFromUnitToUnit (const QPointF &value, const KReportUnit &fromUnit, const KReportUnit &toUnit) |
static QSizeF | convertFromUnitToUnit (const QSizeF &value, const KReportUnit &fromUnit, const KReportUnit &toUnit) |
static qreal | convertFromUnitToUnit (qreal value, const KReportUnit &fromUnit, const KReportUnit &toUnit, qreal factor=1.0) |
static QString | description (KReportUnit::Type type) |
static QStringList | descriptions (const QList< Type > &types) |
static qreal | parseAngle (const QString &value, qreal defaultVal=0.0) |
static qreal | parseValue (const QString &value, qreal defaultVal=0.0) |
static qreal | ptToUnit (qreal ptValue, const KReportUnit &unit) |
static QString | symbol (KReportUnit::Type type) |
static QStringList | symbols (const QList< Type > &types) |
static KReportUnit::Type | symbolToType (const QString &symbol) |
static qreal | toCentimeter (qreal ptValue) |
static qreal | toCicero (qreal ptValue) |
static qreal | toDecimeter (qreal ptValue) |
static qreal | toInch (qreal ptValue) |
static qreal | toMillimeter (qreal ptValue) |
static qreal | toPica (qreal ptValue) |
static qreal | toPoint (qreal ptValue) |
Detailed Description
Converts between different units.
KReportUnit stores everything in pt (using "qreal") internally. When displaying a value to the user, the value is converted to the user's unit of choice, and rounded to a reasonable precision to avoid 0.999999
For implementing the selection of a unit type in the UI use the allTypes() method. it ensure the same order of the unit types in all places, with the order not bound to the order in the enum so ABI-compatible extension is possible.
Definition at line 70 of file KReportUnit.h.
Member Enumeration Documentation
◆ Type
|
strong |
Length units supported by KReport.
Enumerator | |
---|---|
Point | Postscript point, 1/72th of an Inco. |
Last | internal |
Definition at line 75 of file KReportUnit.h.
Constructor & Destructor Documentation
◆ KReportUnit() [1/3]
KReportUnit::KReportUnit | ( | ) |
◆ KReportUnit() [2/3]
|
explicit |
Construct unit with given type and factor.
Definition at line 81 of file KReportUnit.cpp.
◆ KReportUnit() [3/3]
KReportUnit::KReportUnit | ( | const KReportUnit & | other | ) |
Definition at line 87 of file KReportUnit.cpp.
◆ ~KReportUnit()
KReportUnit::~KReportUnit | ( | ) |
Definition at line 93 of file KReportUnit.cpp.
Member Function Documentation
◆ allTypes()
|
static |
Returns list of all supported types (without Invalid)
- Since
- 3.1
Definition at line 126 of file KReportUnit.cpp.
◆ convertFromPoint() [1/3]
- Returns
- the value converted from points to the actual unit with high accuracy
Definition at line 251 of file KReportUnit.cpp.
◆ convertFromPoint() [2/3]
- Returns
- the value converted from points to the actual unit with high accuracy
Definition at line 256 of file KReportUnit.cpp.
◆ convertFromPoint() [3/3]
qreal KReportUnit::convertFromPoint | ( | qreal | ptValue | ) | const |
- Returns
- the value converted from points to the actual unit with high accuracy
Definition at line 228 of file KReportUnit.cpp.
◆ convertFromUnitToUnit() [1/3]
|
static |
convert the given value directly from one unit to another with high accuracy
Definition at line 437 of file KReportUnit.cpp.
◆ convertFromUnitToUnit() [2/3]
|
static |
convert the given value directly from one unit to another with high accuracy
Definition at line 446 of file KReportUnit.cpp.
◆ convertFromUnitToUnit() [3/3]
|
static |
convert the given value directly from one unit to another with high accuracy
Definition at line 383 of file KReportUnit.cpp.
◆ convertToPoint() [1/4]
- Returns
- the value converted to points with high accuracy
Definition at line 291 of file KReportUnit.cpp.
◆ convertToPoint() [2/4]
- Returns
- the value converted to points with high accuracy
Definition at line 297 of file KReportUnit.cpp.
◆ convertToPoint() [3/4]
qreal KReportUnit::convertToPoint | ( | const QString & | value, |
bool * | ok = nullptr ) const |
- Returns
- the value converted to points with high accuracy
- Parameters
-
value value entered by the user ok if set, the pointed bool is set to true if the value could be converted to a qreal, and to false otherwise.
- Returns
- the value converted to points for internal use
Definition at line 286 of file KReportUnit.cpp.
◆ convertToPoint() [4/4]
qreal KReportUnit::convertToPoint | ( | qreal | value | ) | const |
- Returns
- the value converted to points with high accuracy
Definition at line 261 of file KReportUnit.cpp.
◆ description() [1/2]
QString KReportUnit::description | ( | ) | const |
Returns (translated) description string for type of this unit.
- Since
- 3.1
Definition at line 158 of file KReportUnit.cpp.
◆ description() [2/2]
|
static |
Returns (translated) description string for given unit type.
- Since
- 3.1
Definition at line 132 of file KReportUnit.cpp.
◆ descriptions()
|
static |
Returns the list of (translated) description strings for given list of types.
- Since
- 3.1
Definition at line 163 of file KReportUnit.cpp.
◆ factor()
qreal KReportUnit::factor | ( | ) | const |
Definition at line 515 of file KReportUnit.cpp.
◆ fromUserValue() [1/2]
|
inline |
Equal to convertToPoint(), use convertToPoint() instead for clarity.
Definition at line 287 of file KReportUnit.h.
◆ fromUserValue() [2/2]
|
inline |
Equal to convertToPoint(), use convertToPoint() instead for clarity.
Definition at line 271 of file KReportUnit.h.
◆ isValid()
bool KReportUnit::isValid | ( | ) | const |
Returns true if type of this unit is valid.
- Since
- 3.1
Definition at line 525 of file KReportUnit.cpp.
◆ operator!=()
bool KReportUnit::operator!= | ( | const KReportUnit & | other | ) | const |
Definition at line 105 of file KReportUnit.cpp.
◆ operator=() [1/2]
KReportUnit & KReportUnit::operator= | ( | const KReportUnit & | other | ) |
Definition at line 118 of file KReportUnit.cpp.
◆ operator=() [2/2]
KReportUnit & KReportUnit::operator= | ( | Type | type | ) |
Assigns specified type and factor 1.0 to the object.
- Parameters
-
unit Type of unit
Definition at line 111 of file KReportUnit.cpp.
◆ operator==()
bool KReportUnit::operator== | ( | const KReportUnit & | other | ) | const |
Definition at line 98 of file KReportUnit.cpp.
◆ parseAngle()
|
static |
parse an angle to its value in degrees defaultVal is in degrees
Definition at line 460 of file KReportUnit.cpp.
◆ parseValue()
|
static |
Parses common KReport and ODF values, like "10cm", "5mm" to pt.
If no unit is specified, pt is assumed. defaultVal is in Points
- Todo
- add support for mi/ft ?
Definition at line 303 of file KReportUnit.cpp.
◆ ptToUnit()
|
static |
Convert the value ptValue to a given unit unit Unlike KReportUnit::ptToUnit the return value remains unrounded, so that it can be used in complex calculation.
- Returns
- the converted value
Definition at line 198 of file KReportUnit.cpp.
◆ setFactor()
void KReportUnit::setFactor | ( | qreal | factor | ) |
Definition at line 510 of file KReportUnit.cpp.
◆ symbol() [1/2]
QString KReportUnit::symbol | ( | ) | const |
Returns the symbol string of the unit Symbol for Invalid type is empty string.
Definition at line 455 of file KReportUnit.cpp.
◆ symbol() [2/2]
|
static |
Returns the symbol string of given unit type Symbol for Invalid type is empty string.
Definition at line 350 of file KReportUnit.cpp.
◆ symbols()
|
static |
Returns the list of unit symbols for the given types.
- Since
- 3.1
Definition at line 374 of file KReportUnit.cpp.
◆ symbolToType()
|
static |
Returns a unit symbol string to type.
- Parameters
-
symbol symbol to convert, must be lowercase
- Returns
- Invalid type for unsupported symbol
- Since
- 3.1
Definition at line 356 of file KReportUnit.cpp.
◆ toCentimeter()
|
inlinestatic |
Prepare ptValue to be displayed in cm This method will round to 0.0001 precision, use POINT_TO_CM() for lossless conversion.
Definition at line 178 of file KReportUnit.h.
◆ toCicero()
|
inlinestatic |
Prepare ptValue to be displayed in cicero This method will round to 0.00001 precision, use POINT_TO_CC() for lossless conversion.
Definition at line 216 of file KReportUnit.h.
◆ toDecimeter()
|
inlinestatic |
Prepare ptValue to be displayed in dm This method will round to 0.0001 precision, use POINT_TO_DM() for lossless conversion.
Definition at line 187 of file KReportUnit.h.
◆ toInch()
|
inlinestatic |
Prepare ptValue to be displayed in inch This method will round to 0.00001 precision, use POINT_TO_INCH() for lossless conversion.
Definition at line 196 of file KReportUnit.h.
◆ toMillimeter()
|
inlinestatic |
Prepare ptValue to be displayed in mm This method will round to 0.0001 precision, use POINT_TO_MM() for lossless conversion.
Definition at line 168 of file KReportUnit.h.
◆ toPica()
|
inlinestatic |
Prepare ptValue to be displayed in pica This method will round to 0.00001 precision, use POINT_TO_PI() for lossless conversion.
Definition at line 206 of file KReportUnit.h.
◆ toPoint()
|
inlinestatic |
Prepare ptValue to be displayed in pt This method will round to 0.001 precision.
Definition at line 158 of file KReportUnit.h.
◆ toString()
|
inline |
Equal to symbol(): returns the symbol string of the unit.
Definition at line 302 of file KReportUnit.h.
◆ toUserStringValue()
QString KReportUnit::toUserStringValue | ( | qreal | ptValue | ) | const |
This method is the one to use to display a value in a dialog.
- Returns
- the value ptValue converted the unit and rounded, ready to be displayed
Definition at line 223 of file KReportUnit.cpp.
◆ toUserValue()
qreal KReportUnit::toUserValue | ( | qreal | ptValue | ) | const |
This method is the one to use to display a value in a dialog.
- Returns
- the value ptValue converted to unit and rounded, ready to be displayed
Definition at line 172 of file KReportUnit.cpp.
◆ type()
KReportUnit::Type KReportUnit::type | ( | ) | const |
Returns the type of this unit.
Definition at line 520 of file KReportUnit.cpp.
The documentation for this class was generated from the following files:
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Oct 11 2024 12:16:25 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006
KDE's Doxygen guidelines are available online.