Qt 4.8
Public Types | Public Functions | Properties | Friends | List of all members
QTextLength Class Reference

The QTextLength class encapsulates the different types of length used in a QTextDocument. More...

#include <qtextformat.h>

Public Types

enum  Type { VariableLength = 0, FixedLength, PercentageLength }
 This enum describes the different types a length object can have. More...
 

Public Functions

 operator QVariant () const
 Returns the text length as a QVariant. More...
 
bool operator!= (const QTextLength &other) const
 Returns true if this text length is different from the other text length. More...
 
bool operator== (const QTextLength &other) const
 Returns true if this text length is the same as the other text length. More...
 
 QTextLength ()
 Constructs a new length object which represents a variable size. More...
 
 QTextLength (Type type, qreal value)
 Constructs a new length object of the given type and value. More...
 
qreal rawValue () const
 Returns the constraint value that is specific for the type of the length. More...
 
Type type () const
 Returns the type of this length object. More...
 
qreal value (qreal maximumLength) const
 Returns the effective length, constrained by the type of the length object and the specified maximumLength. More...
 

Properties

qreal fixedValueOrPercentage
 
Type lengthType
 

Friends

Q_GUI_EXPORT QDataStreamoperator<< (QDataStream &, const QTextLength &)
 
Q_GUI_EXPORT QDataStreamoperator>> (QDataStream &, QTextLength &)
 

Detailed Description

The QTextLength class encapsulates the different types of length used in a QTextDocument.

Note
This class or function is reentrant.

When we specify a value for the length of an element in a text document, we often need to provide some other information so that the length is used in the way we expect. For example, when we specify a table width, the value can represent a fixed number of pixels, or it can be a percentage value. This information changes both the meaning of the value and the way it is used.

Generally, this class is used to specify table widths. These can be specified either as a fixed amount of pixels, as a percentage of the containing frame's width, or by a variable width that allows it to take up just the space it requires.

See also
QTextTable

Definition at line 84 of file qtextformat.h.

Enumerations

◆ Type

This enum describes the different types a length object can have.

  • VariableLength The width of the object is variable
  • FixedLength The width of the object is fixed
  • PercentageLength The width of the object is in percentage of the maximum width
See also
type()
Enumerator
VariableLength 
FixedLength 
PercentageLength 

Definition at line 87 of file qtextformat.h.

Constructors and Destructors

◆ QTextLength() [1/2]

QTextLength::QTextLength ( )
inlineexplicit

Constructs a new length object which represents a variable size.

Definition at line 89 of file qtextformat.h.

Referenced by QTextFrameFormat::setHeight(), and QTextFrameFormat::setWidth().

◆ QTextLength() [2/2]

QTextLength::QTextLength ( Type  type,
qreal  value 
)
inlineexplicit

Constructs a new length object of the given type and value.

Definition at line 121 of file qtextformat.h.

122  : lengthType(atype), fixedValueOrPercentage(avalue) {}
Type lengthType
Definition: qtextformat.h:115
qreal fixedValueOrPercentage
Definition: qtextformat.h:116

Functions

◆ operator QVariant()

QTextLength::operator QVariant ( ) const

Returns the text length as a QVariant.

Definition at line 173 of file qtextformat.cpp.

174 {
175  return QVariant(QVariant::TextLength, this);
176 }
The QVariant class acts like a union for the most common Qt data types.
Definition: qvariant.h:92

◆ operator!=()

bool QTextLength::operator!= ( const QTextLength other) const
inline

Returns true if this text length is different from the other text length.

Definition at line 109 of file qtextformat.h.

110  { return lengthType != other.lengthType
static Q_DECL_CONSTEXPR bool qFuzzyCompare(double p1, double p2)
Definition: qglobal.h:2030
Type lengthType
Definition: qtextformat.h:115
qreal fixedValueOrPercentage
Definition: qtextformat.h:116

◆ operator==()

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

Returns true if this text length is the same as the other text length.

Definition at line 106 of file qtextformat.h.

Referenced by QTextFormat::isTableCellFormat(), and QTextFormat::operator!=().

107  { return lengthType == other.lengthType
static Q_DECL_CONSTEXPR bool qFuzzyCompare(double p1, double p2)
Definition: qglobal.h:2030
Type lengthType
Definition: qtextformat.h:115
qreal fixedValueOrPercentage
Definition: qtextformat.h:116

◆ rawValue()

qreal QTextLength::rawValue ( ) const
inline

Returns the constraint value that is specific for the type of the length.

If the length is QTextLength::PercentageLength then the raw value is in percent, in the range of 0 to 100. If the length is QTextLength::FixedLength then that fixed amount is returned. For variable lengths, zero is returned.

Definition at line 104 of file qtextformat.h.

Referenced by QTextHtmlExporter::emitTextLength(), and QTextDocumentLayoutPrivate::layoutTable().

104 { return fixedValueOrPercentage; }
qreal fixedValueOrPercentage
Definition: qtextformat.h:116

◆ type()

Type QTextLength::type ( ) const
inline

◆ value()

qreal QTextLength::value ( qreal  maximumLength) const
inline

Returns the effective length, constrained by the type of the length object and the specified maximumLength.

See also
type()

Definition at line 94 of file qtextformat.h.

Referenced by QTextDocumentLayoutPrivate::drawBlock(), QTextFormat::isValid(), QTextDocumentLayoutPrivate::layoutFrame(), and QTextHtmlImporter::scanTable().

95  {
96  switch (lengthType) {
98  case VariableLength: return maximumLength;
99  case PercentageLength: return fixedValueOrPercentage * maximumLength / qreal(100);
100  }
101  return -1;
102  }
double qreal
Definition: qglobal.h:1193
Type lengthType
Definition: qtextformat.h:115
qreal fixedValueOrPercentage
Definition: qtextformat.h:116

Friends and Related Functions

◆ operator<<

Q_GUI_EXPORT QDataStream& operator<< ( QDataStream ,
const QTextLength  
)
friend

Definition at line 179 of file qtextformat.cpp.

Referenced by QTextLength().

180 {
181  return stream << qint32(length.lengthType) << double(length.fixedValueOrPercentage);
182 }
int qint32
Definition: qglobal.h:937
Type lengthType
Definition: qtextformat.h:115
qreal fixedValueOrPercentage
Definition: qtextformat.h:116

◆ operator>>

Q_GUI_EXPORT QDataStream& operator>> ( QDataStream ,
QTextLength  
)
friend

Definition at line 184 of file qtextformat.cpp.

Referenced by QTextLength().

185 {
186  qint32 type;
187  double fixedValueOrPercentage;
188  stream >> type >> fixedValueOrPercentage;
190  length.lengthType = QTextLength::Type(type);
191  return stream;
192 }
int qint32
Definition: qglobal.h:937
Type type() const
Returns the type of this length object.
Definition: qtextformat.h:93
Type
This enum describes the different types a length object can have.
Definition: qtextformat.h:87
static FILE * stream
Type lengthType
Definition: qtextformat.h:115
qreal fixedValueOrPercentage
Definition: qtextformat.h:116

Properties

◆ fixedValueOrPercentage

qreal QTextLength::fixedValueOrPercentage
private

Definition at line 116 of file qtextformat.h.

Referenced by operator!=(), operator<<(), operator==(), and operator>>().

◆ lengthType

Type QTextLength::lengthType
private

Definition at line 115 of file qtextformat.h.

Referenced by operator!=(), operator<<(), operator==(), and operator>>().


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