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

The QTextFormat class provides formatting information for a QTextDocument. More...

#include <qtextformat.h>

Inheritance diagram for QTextFormat:
QTextBlockFormat QTextCharFormat QTextFrameFormat QTextListFormat QTextImageFormat QTextTableCellFormat QTextTableFormat

Public Types

enum  FormatType {
  InvalidFormat = -1, BlockFormat = 1, CharFormat = 2, ListFormat = 3,
  TableFormat = 4, FrameFormat = 5, UserFormat = 100
}
 This enum describes the text item a QTextFormat object is formatting. More...
 
enum  ObjectTypes {
  NoObject, ImageObject, TableObject, TableCellObject,
  UserObject = 0x1000
}
 This enum describes what kind of QTextObject this format is associated with. More...
 
enum  PageBreakFlag { PageBreak_Auto = 0, PageBreak_AlwaysBefore = 0x001, PageBreak_AlwaysAfter = 0x010 }
 This enum describes how page breaking is performed when printing. More...
 
enum  Property {
  ObjectIndex = 0x0, CssFloat = 0x0800, LayoutDirection = 0x0801, OutlinePen = 0x810,
  BackgroundBrush = 0x820, ForegroundBrush = 0x821, BackgroundImageUrl = 0x823, BlockAlignment = 0x1010,
  BlockTopMargin = 0x1030, BlockBottomMargin = 0x1031, BlockLeftMargin = 0x1032, BlockRightMargin = 0x1033,
  TextIndent = 0x1034, TabPositions = 0x1035, BlockIndent = 0x1040, LineHeight = 0x1048,
  LineHeightType = 0x1049, BlockNonBreakableLines = 0x1050, BlockTrailingHorizontalRulerWidth = 0x1060, FirstFontProperty = 0x1FE0,
  FontCapitalization = FirstFontProperty, FontLetterSpacing = 0x1FE1, FontWordSpacing = 0x1FE2, FontStyleHint = 0x1FE3,
  FontStyleStrategy = 0x1FE4, FontKerning = 0x1FE5, FontHintingPreference = 0x1FE6, FontFamily = 0x2000,
  FontPointSize = 0x2001, FontSizeAdjustment = 0x2002, FontSizeIncrement = FontSizeAdjustment, FontWeight = 0x2003,
  FontItalic = 0x2004, FontUnderline = 0x2005, FontOverline = 0x2006, FontStrikeOut = 0x2007,
  FontFixedPitch = 0x2008, FontPixelSize = 0x2009, LastFontProperty = FontPixelSize, TextUnderlineColor = 0x2010,
  TextVerticalAlignment = 0x2021, TextOutline = 0x2022, TextUnderlineStyle = 0x2023, TextToolTip = 0x2024,
  IsAnchor = 0x2030, AnchorHref = 0x2031, AnchorName = 0x2032, ObjectType = 0x2f00,
  ListStyle = 0x3000, ListIndent = 0x3001, ListNumberPrefix = 0x3002, ListNumberSuffix = 0x3003,
  FrameBorder = 0x4000, FrameMargin = 0x4001, FramePadding = 0x4002, FrameWidth = 0x4003,
  FrameHeight = 0x4004, FrameTopMargin = 0x4005, FrameBottomMargin = 0x4006, FrameLeftMargin = 0x4007,
  FrameRightMargin = 0x4008, FrameBorderBrush = 0x4009, FrameBorderStyle = 0x4010, TableColumns = 0x4100,
  TableColumnWidthConstraints = 0x4101, TableCellSpacing = 0x4102, TableCellPadding = 0x4103, TableHeaderRowCount = 0x4104,
  TableCellRowSpan = 0x4810, TableCellColumnSpan = 0x4811, TableCellTopPadding = 0x4812, TableCellBottomPadding = 0x4813,
  TableCellLeftPadding = 0x4814, TableCellRightPadding = 0x4815, ImageName = 0x5000, ImageWidth = 0x5010,
  ImageHeight = 0x5011, FullWidthSelection = 0x06000, PageBreakPolicy = 0x7000, UserProperty = 0x100000
}
 This enum describes the different properties a format can have. More...
 

Public Functions

QBrush background () const
 Returns the brush used to paint the document's background. More...
 
bool boolProperty (int propertyId) const
 Returns the value of the property specified by propertyId. More...
 
QBrush brushProperty (int propertyId) const
 Returns the value of the property given by propertyId; if the property isn't of QVariant::Brush type, Qt::NoBrush is returned instead. More...
 
void clearBackground ()
 Clears the brush used to paint the document's background. More...
 
void clearForeground ()
 Clears the brush used to paint the document's foreground. More...
 
void clearProperty (int propertyId)
 Clears the value of the property given by propertyId. More...
 
QColor colorProperty (int propertyId) const
 Returns the value of the property given by propertyId; if the property isn't of QVariant::Color type, an invalid color is returned instead. More...
 
qreal doubleProperty (int propertyId) const
 Returns the value of the property specified by propertyId. More...
 
QBrush foreground () const
 Returns the brush used to render foreground details, such as text, frame outlines, and table borders. More...
 
bool hasProperty (int propertyId) const
 Returns true if the text format has a property with the given propertyId; otherwise returns false. More...
 
int intProperty (int propertyId) const
 Returns the value of the property specified by propertyId. More...
 
bool isBlockFormat () const
 Returns true if this text format is a BlockFormat; otherwise returns false. More...
 
bool isCharFormat () const
 Returns true if this text format is a CharFormat; otherwise returns false. More...
 
bool isFrameFormat () const
 Returns true if this text format is a FrameFormat; otherwise returns false. More...
 
bool isImageFormat () const
 Returns true if this text format is an image format; otherwise returns false. More...
 
bool isListFormat () const
 Returns true if this text format is a ListFormat; otherwise returns false. More...
 
bool isTableCellFormat () const
 Returns true if this text format is a TableCellFormat; otherwise returns false. More...
 
bool isTableFormat () const
 Returns true if this text format is a TableFormat; otherwise returns false. More...
 
bool isValid () const
 Returns true if the format is valid (i. More...
 
Qt::LayoutDirection layoutDirection () const
 Returns the document's layout direction. More...
 
QTextLength lengthProperty (int propertyId) const
 Returns the value of the property given by propertyId. More...
 
QVector< QTextLengthlengthVectorProperty (int propertyId) const
 Returns the value of the property given by propertyId. More...
 
void merge (const QTextFormat &other)
 Merges the other format with this format; where there are conflicts the other format takes precedence. More...
 
int objectIndex () const
 Returns the index of the format object, or -1 if the format object is invalid. More...
 
int objectType () const
 Returns the text format's object type. More...
 
 operator QVariant () const
 Returns the text format as a QVariant. More...
 
bool operator!= (const QTextFormat &rhs) const
 Returns true if this text format is different from the other text format. More...
 
QTextFormatoperator= (const QTextFormat &rhs)
 Assigns the other text format to this text format, and returns a reference to this text format. More...
 
bool operator== (const QTextFormat &rhs) const
 Returns true if this text format is the same as the other text format. More...
 
QPen penProperty (int propertyId) const
 Returns the value of the property given by propertyId; if the property isn't of QVariant::Pen type, Qt::NoPen is returned instead. More...
 
QMap< int, QVariantproperties () const
 Returns a map with all properties of this text format. More...
 
QVariant property (int propertyId) const
 Returns the property specified by the given propertyId. More...
 
int propertyCount () const
 Returns the number of properties stored in the format. More...
 
 QTextFormat ()
 Creates a new text format with an InvalidFormat. More...
 
 QTextFormat (int type)
 Creates a new text format of the given type. More...
 
 QTextFormat (const QTextFormat &rhs)
 Creates a new text format with the same attributes as the other text format. More...
 
void setBackground (const QBrush &brush)
 Sets the brush use to paint the document's background to the brush specified. More...
 
void setForeground (const QBrush &brush)
 Sets the foreground brush to the specified brush. More...
 
void setLayoutDirection (Qt::LayoutDirection direction)
 Sets the document's layout direction to the specified direction. More...
 
void setObjectIndex (int object)
 Sets the format object's object index. More...
 
void setObjectType (int type)
 Sets the text format's object type to type. More...
 
void setProperty (int propertyId, const QVariant &value)
 Sets the property specified by the propertyId to the given value. More...
 
void setProperty (int propertyId, const QVector< QTextLength > &lengths)
 Sets the value of the property given by propertyId to value. More...
 
QString stringProperty (int propertyId) const
 Returns the value of the property given by propertyId; if the property isn't of QVariant::String type, an empty string is returned instead. More...
 
QTextBlockFormat toBlockFormat () const
 Returns this format as a block format. More...
 
QTextCharFormat toCharFormat () const
 Returns this format as a character format. More...
 
QTextFrameFormat toFrameFormat () const
 Returns this format as a frame format. More...
 
QTextImageFormat toImageFormat () const
 Returns this format as an image format. More...
 
QTextListFormat toListFormat () const
 Returns this format as a list format. More...
 
QTextTableCellFormat toTableCellFormat () const
 Returns this format as a table cell format. More...
 
QTextTableFormat toTableFormat () const
 Returns this format as a table format. More...
 
int type () const
 Returns the type of this format. More...
 
 ~QTextFormat ()
 Destroys this text format. More...
 

Properties

QSharedDataPointer< QTextFormatPrivated
 
qint32 format_type
 

Friends

Q_GUI_EXPORT QDataStreamoperator<< (QDataStream &, const QTextFormat &)
 
Q_GUI_EXPORT QDataStreamoperator>> (QDataStream &, QTextFormat &)
 
class QTextCharFormat
 
class QTextFormatCollection
 

Detailed Description

The QTextFormat class provides formatting information for a QTextDocument.

Note
This class or function is reentrant.

A QTextFormat is a generic class used for describing the format of parts of a QTextDocument. The derived classes QTextCharFormat, QTextBlockFormat, QTextListFormat, and QTextTableFormat are usually more useful, and describe the formatting that is applied to specific parts of the document.

A format has a FormatType which specifies the kinds of text item it can format; e.g. a block of text, a list, a table, etc. A format also has various properties (some specific to particular format types), as described by the Property enum. Every property has a corresponding Property.

The format type is given by type(), and the format can be tested with isCharFormat(), isBlockFormat(), isListFormat(), isTableFormat(), isFrameFormat(), and isImageFormat(). If the type is determined, it can be retrieved with toCharFormat(), toBlockFormat(), toListFormat(), toTableFormat(), toFrameFormat(), and toImageFormat().

A format's properties can be set with the setProperty() functions, and retrieved with boolProperty(), intProperty(), doubleProperty(), and stringProperty() as appropriate. All the property IDs used in the format can be retrieved with allPropertyIds(). One format can be merged into another using merge().

A format's object index can be set with setObjectIndex(), and retrieved with objectIndex(). These methods can be used to associate the format with a QTextObject. It is used to represent lists, frames, and tables inside the document.

See also
{Rich Text Processing}

Definition at line 129 of file qtextformat.h.

Enumerations

◆ FormatType

This enum describes the text item a QTextFormat object is formatting.

  • InvalidFormat An invalid format as created by the default constructor
  • BlockFormat The object formats a text block
  • CharFormat The object formats a single character
  • ListFormat The object formats a list
  • TableFormat The object formats a table
  • FrameFormat The object formats a frame
  • UserFormat
See also
QTextCharFormat, QTextBlockFormat, QTextListFormat, QTextTableFormat, type()
Enumerator
InvalidFormat 
BlockFormat 
CharFormat 
ListFormat 
TableFormat 
FrameFormat 
UserFormat 

Definition at line 134 of file qtextformat.h.

◆ ObjectTypes

This enum describes what kind of QTextObject this format is associated with.

  • NoObject
  • ImageObject
  • TableObject
  • TableCellObject
  • UserObject The first object that can be used for application-specific purposes.
See also
QTextObject, QTextTable, QTextObject::format()
Enumerator
NoObject 
ImageObject 
TableObject 
TableCellObject 
UserObject 

Definition at line 260 of file qtextformat.h.

◆ PageBreakFlag

This enum describes how page breaking is performed when printing.

Since
4.2

It maps to the corresponding css properties.

  • PageBreak_Auto The page break is determined automatically depending on the available space on the current page
  • PageBreak_AlwaysBefore The page is always broken before the paragraph/table
  • PageBreak_AlwaysAfter A new page is always started after the paragraph/table
See also
QTextBlockFormat::pageBreakPolicy(), QTextFrameFormat::pageBreakPolicy(), PageBreakPolicy
Enumerator
PageBreak_Auto 
PageBreak_AlwaysBefore 
PageBreak_AlwaysAfter 

Definition at line 269 of file qtextformat.h.

269  {
270  PageBreak_Auto = 0,
271  PageBreak_AlwaysBefore = 0x001,
272  PageBreak_AlwaysAfter = 0x010
273  // PageBreak_AlwaysInside = 0x100
274  };

◆ Property

This enum describes the different properties a format can have.

  • ObjectIndex The index of the formatted object. See objectIndex().

Paragraph and character properties

  • CssFloat How a frame is located relative to the surrounding text
  • LayoutDirection The layout direction of the text in the document (Qt::LayoutDirection).
  • OutlinePen
  • ForegroundBrush
  • BackgroundBrush
  • BackgroundImageUrl

Paragraph properties

  • BlockAlignment
  • BlockTopMargin
  • BlockBottomMargin
  • BlockLeftMargin
  • BlockRightMargin
  • TextIndent
  • TabPositions Specifies the tab positions. The tab positions are structs of QTextOption::Tab which are stored in a QList (internally, in a QList<QVariant>).
  • BlockIndent
  • LineHeight
  • LineHeightType
  • BlockNonBreakableLines
  • BlockTrailingHorizontalRulerWidth The width of a horizontal ruler element.

Character properties

  • FontFamily
  • FontPointSize
  • FontPixelSize
  • FontSizeAdjustment Specifies the change in size given to the fontsize already set using FontPointSize or FontPixelSize.
  • FontFixedPitch
  • FontSizeIncrement
  • FontWeight
  • FontItalic
  • FontUnderline This property has been deprecated. Use QTextFormat::TextUnderlineStyle instead.
  • FontOverline
  • FontStrikeOut
  • FontCapitalization Specifies the capitalization type that is to be applied to the text.
  • FontLetterSpacing Changes the default spacing between individual letters in the font. The value is specified in percentage, with 100 as the default value.
  • FontWordSpacing Changes the default spacing between individual words. A positive value increases the word spacing by the corresponding pixels; a negative value decreases the spacing.
  • FontStyleHint Corresponds to the QFont::StyleHint property
  • FontStyleStrategy Corresponds to the QFont::StyleStrategy property
  • FontKerning Specifies whether the font has kerning turned on.
  • FontHintingPreference Controls the use of hinting according to values of the QFont::HintingPreference enum.
  • FirstFontProperty
  • LastFontProperty
  • TextUnderlineColor
  • TextVerticalAlignment
  • TextOutline
  • TextUnderlineStyle
  • TextToolTip Specifies the (optional) tool tip to be displayed for a fragment of text.
  • IsAnchor
  • AnchorHref
  • AnchorName
  • ObjectType

List properties

  • ListStyle Specifies the style used for the items in a list, described by values of the QTextListFormat::Style enum.
  • ListIndent Specifies the amount of indentation used for a list.
  • ListNumberPrefix Defines the text which is prepended to item numbers in numeric lists.
  • ListNumberSuffix Defines the text which is appended to item numbers in numeric lists.

Table and frame properties

  • FrameBorder
  • FrameBorderBrush
  • FrameBorderStyle See the BorderStyle enum.
  • FrameBottomMargin
  • FrameHeight
  • FrameLeftMargin
  • FrameMargin
  • FramePadding
  • FrameRightMargin
  • FrameTopMargin
  • FrameWidth
  • TableCellSpacing
  • TableCellPadding
  • TableColumns
  • TableColumnWidthConstraints
  • TableHeaderRowCount

Table cell properties

  • TableCellRowSpan
  • TableCellColumnSpan
  • TableCellLeftPadding
  • TableCellRightPadding
  • TableCellTopPadding
  • TableCellBottomPadding

Image properties

  • ImageName
  • ImageWidth
  • ImageHeight

Selection properties

  • FullWidthSelection When set on the characterFormat of a selection, the whole width of the text will be shown selected.

Page break properties

  • PageBreakPolicy Specifies how pages are broken. See the PageBreakFlag enum.
  • UserProperty
See also
property(), setProperty()
Enumerator
ObjectIndex 
CssFloat 
LayoutDirection 
OutlinePen 
BackgroundBrush 
ForegroundBrush 
BackgroundImageUrl 
BlockAlignment 
BlockTopMargin 
BlockBottomMargin 
BlockLeftMargin 
BlockRightMargin 
TextIndent 
TabPositions 
BlockIndent 
LineHeight 
LineHeightType 
BlockNonBreakableLines 
BlockTrailingHorizontalRulerWidth 
FirstFontProperty 
FontCapitalization 
FontLetterSpacing 
FontWordSpacing 
FontStyleHint 
FontStyleStrategy 
FontKerning 
FontHintingPreference 
FontFamily 
FontPointSize 
FontSizeAdjustment 
FontSizeIncrement 
FontWeight 
FontItalic 
FontUnderline 
FontOverline 
FontStrikeOut 
FontFixedPitch 
FontPixelSize 
LastFontProperty 
TextUnderlineColor 
TextVerticalAlignment 
TextOutline 
TextUnderlineStyle 
TextToolTip 
IsAnchor 
AnchorHref 
AnchorName 
ObjectType 
ListStyle 
ListIndent 
ListNumberPrefix 
ListNumberSuffix 
FrameBorder 
FrameMargin 
FramePadding 
FrameWidth 
FrameHeight 
FrameTopMargin 
FrameBottomMargin 
FrameLeftMargin 
FrameRightMargin 
FrameBorderBrush 
FrameBorderStyle 
TableColumns 
TableColumnWidthConstraints 
TableCellSpacing 
TableCellPadding 
TableHeaderRowCount 
TableCellRowSpan 
TableCellColumnSpan 
TableCellTopPadding 
TableCellBottomPadding 
TableCellLeftPadding 
TableCellRightPadding 
ImageName 
ImageWidth 
ImageHeight 
FullWidthSelection 
PageBreakPolicy 
UserProperty 

Definition at line 145 of file qtextformat.h.

145  {
146  ObjectIndex = 0x0,
147 
148  // paragraph and char
149  CssFloat = 0x0800,
150  LayoutDirection = 0x0801,
151 
152  OutlinePen = 0x810,
153  BackgroundBrush = 0x820,
154  ForegroundBrush = 0x821,
155  // Internal to qtextlayout.cpp: ObjectSelectionBrush = 0x822
156  BackgroundImageUrl = 0x823,
157 
158  // paragraph
159  BlockAlignment = 0x1010,
160  BlockTopMargin = 0x1030,
161  BlockBottomMargin = 0x1031,
162  BlockLeftMargin = 0x1032,
163  BlockRightMargin = 0x1033,
164  TextIndent = 0x1034,
165  TabPositions = 0x1035,
166  BlockIndent = 0x1040,
167  LineHeight = 0x1048,
168  LineHeightType = 0x1049,
169  BlockNonBreakableLines = 0x1050,
171 
172  // character properties
173  FirstFontProperty = 0x1FE0,
175  FontLetterSpacing = 0x1FE1,
176  FontWordSpacing = 0x1FE2,
177  FontStyleHint = 0x1FE3,
178  FontStyleStrategy = 0x1FE4,
179  FontKerning = 0x1FE5,
180  FontHintingPreference = 0x1FE6,
181  FontFamily = 0x2000,
182  FontPointSize = 0x2001,
183  FontSizeAdjustment = 0x2002,
184  FontSizeIncrement = FontSizeAdjustment, // old name, compat
185  FontWeight = 0x2003,
186  FontItalic = 0x2004,
187  FontUnderline = 0x2005, // deprecated, use TextUnderlineStyle instead
188  FontOverline = 0x2006,
189  FontStrikeOut = 0x2007,
190  FontFixedPitch = 0x2008,
191  FontPixelSize = 0x2009,
193 
194  TextUnderlineColor = 0x2010,
195  TextVerticalAlignment = 0x2021,
196  TextOutline = 0x2022,
197  TextUnderlineStyle = 0x2023,
198  TextToolTip = 0x2024,
199 
200  IsAnchor = 0x2030,
201  AnchorHref = 0x2031,
202  AnchorName = 0x2032,
203  ObjectType = 0x2f00,
204 
205  // list properties
206  ListStyle = 0x3000,
207  ListIndent = 0x3001,
208  ListNumberPrefix = 0x3002,
209  ListNumberSuffix = 0x3003,
210 
211  // table and frame properties
212  FrameBorder = 0x4000,
213  FrameMargin = 0x4001,
214  FramePadding = 0x4002,
215  FrameWidth = 0x4003,
216  FrameHeight = 0x4004,
217  FrameTopMargin = 0x4005,
218  FrameBottomMargin = 0x4006,
219  FrameLeftMargin = 0x4007,
220  FrameRightMargin = 0x4008,
221  FrameBorderBrush = 0x4009,
222  FrameBorderStyle = 0x4010,
223 
224  TableColumns = 0x4100,
226  TableCellSpacing = 0x4102,
227  TableCellPadding = 0x4103,
228  TableHeaderRowCount = 0x4104,
229 
230  // table cell properties
231  TableCellRowSpan = 0x4810,
232  TableCellColumnSpan = 0x4811,
233 
234  TableCellTopPadding = 0x4812,
235  TableCellBottomPadding = 0x4813,
236  TableCellLeftPadding = 0x4814,
237  TableCellRightPadding = 0x4815,
238 
239  // image properties
240  ImageName = 0x5000,
241  ImageWidth = 0x5010,
242  ImageHeight = 0x5011,
243 
244  // internal
245  /*
246  SuppressText = 0x5012,
247  SuppressBackground = 0x513
248  */
249 
250  // selection properties
251  FullWidthSelection = 0x06000,
252 
253  // page break properties
254  PageBreakPolicy = 0x7000,
255 
256  // --
257  UserProperty = 0x100000
258  };

Constructors and Destructors

◆ QTextFormat() [1/3]

QTextFormat::QTextFormat ( )

Creates a new text format with an InvalidFormat.

See also
FormatType

Definition at line 814 of file qtextformat.cpp.

Referenced by QTextFormatCollection::format(), and QTextFormatCollection::objectFormat().

◆ QTextFormat() [2/3]

QTextFormat::QTextFormat ( int  type)
explicit

Creates a new text format of the given type.

See also
FormatType

Definition at line 824 of file qtextformat.cpp.

825  : format_type(type)
826 {
827 }
int type() const
Returns the type of this format.
qint32 format_type
Definition: qtextformat.h:359

◆ QTextFormat() [3/3]

QTextFormat::QTextFormat ( const QTextFormat rhs)

Creates a new text format with the same attributes as the other text format.

Definition at line 839 of file qtextformat.cpp.

840  : d(rhs.d), format_type(rhs.format_type)
841 {
842 }
qint32 format_type
Definition: qtextformat.h:359
QSharedDataPointer< QTextFormatPrivate > d
Definition: qtextformat.h:358

◆ ~QTextFormat()

QTextFormat::~QTextFormat ( )

Destroys this text format.

Definition at line 863 of file qtextformat.cpp.

864 {
865 }

Functions

◆ background()

QColor QTextFormat::background ( ) const
inline

◆ boolProperty()

bool QTextFormat::boolProperty ( int  propertyId) const

Returns the value of the property specified by propertyId.

If the property isn't of QTextFormat::Bool type, false is returned instead.

See also
setProperty() intProperty() doubleProperty() stringProperty() colorProperty() lengthProperty() lengthVectorProperty() Property

Definition at line 980 of file qtextformat.cpp.

Referenced by QTextLayout::draw(), QTextCharFormat::fontFixedPitch(), QTextCharFormat::fontItalic(), QTextCharFormat::fontKerning(), QTextCharFormat::fontOverline(), QTextCharFormat::fontStrikeOut(), QTextCharFormat::fontUnderline(), QTextItemInt::initWithScriptItem(), QTextCharFormat::isAnchor(), and QTextControl::setExtraSelections().

981 {
982  if (!d)
983  return false;
984  const QVariant prop = d->property(propertyId);
985  if (prop.userType() != QVariant::Bool)
986  return false;
987  return prop.toBool();
988 }
The QVariant class acts like a union for the most common Qt data types.
Definition: qvariant.h:92
bool toBool() const
Returns the variant as a bool if the variant has type() Bool.
Definition: qvariant.cpp:2691
QVariant property(qint32 key) const
int userType() const
Returns the storage type of the value stored in the variant.
Definition: qvariant.cpp:1913
QSharedDataPointer< QTextFormatPrivate > d
Definition: qtextformat.h:358

◆ brushProperty()

QBrush QTextFormat::brushProperty ( int  propertyId) const

Returns the value of the property given by propertyId; if the property isn't of QVariant::Brush type, Qt::NoBrush is returned instead.

See also
setProperty() boolProperty() intProperty() doubleProperty() stringProperty() lengthProperty() lengthVectorProperty() Property

Definition at line 1085 of file qtextformat.cpp.

Referenced by QTextLayout::draw(), and QTextLine::draw().

1086 {
1087  if (!d)
1088  return QBrush(Qt::NoBrush);
1089  const QVariant prop = d->property(propertyId);
1090  if (prop.userType() != QVariant::Brush)
1091  return QBrush(Qt::NoBrush);
1092  return qvariant_cast<QBrush>(prop);
1093 }
The QVariant class acts like a union for the most common Qt data types.
Definition: qvariant.h:92
QVariant property(qint32 key) const
The QBrush class defines the fill pattern of shapes drawn by QPainter.
Definition: qbrush.h:76
int userType() const
Returns the storage type of the value stored in the variant.
Definition: qvariant.cpp:1913
QSharedDataPointer< QTextFormatPrivate > d
Definition: qtextformat.h:358
T qvariant_cast(const QVariant &)
Definition: qvariant.h:571

◆ clearBackground()

void QTextFormat::clearBackground ( )
inline

Clears the brush used to paint the document's background.

The default brush will be used.

See also
background() setBackground() clearForeground()

Definition at line 347 of file qtextformat.h.

Referenced by QTextLine::draw().

void clearProperty(int propertyId)
Clears the value of the property given by propertyId.

◆ clearForeground()

void QTextFormat::clearForeground ( )
inline

Clears the brush used to paint the document's foreground.

The default brush will be used.

See also
foreground() setForeground() clearBackground()

Definition at line 354 of file qtextformat.h.

Referenced by QTextLine::draw().

void clearProperty(int propertyId)
Clears the value of the property given by propertyId.

◆ clearProperty()

void QTextFormat::clearProperty ( int  propertyId)

◆ colorProperty()

QColor QTextFormat::colorProperty ( int  propertyId) const

Returns the value of the property given by propertyId; if the property isn't of QVariant::Color type, an invalid color is returned instead.

See also
setProperty(), boolProperty(), intProperty(), doubleProperty(), stringProperty(), lengthProperty(), lengthVectorProperty(), Property

Definition at line 1051 of file qtextformat.cpp.

Referenced by QTextCharFormat::underlineColor().

1052 {
1053  if (!d)
1054  return QColor();
1055  const QVariant prop = d->property(propertyId);
1056  if (prop.userType() != QVariant::Color)
1057  return QColor();
1058  return qvariant_cast<QColor>(prop);
1059 }
The QVariant class acts like a union for the most common Qt data types.
Definition: qvariant.h:92
The QColor class provides colors based on RGB, HSV or CMYK values.
Definition: qcolor.h:67
QVariant property(qint32 key) const
int userType() const
Returns the storage type of the value stored in the variant.
Definition: qvariant.cpp:1913
QSharedDataPointer< QTextFormatPrivate > d
Definition: qtextformat.h:358
T qvariant_cast(const QVariant &)
Definition: qvariant.h:571

◆ doubleProperty()

qreal QTextFormat::doubleProperty ( int  propertyId) const

Returns the value of the property specified by propertyId.

If the property isn't of QVariant::Double or QMetaType::Float type, 0 is returned instead.

See also
setProperty() boolProperty() intProperty() stringProperty() colorProperty() lengthProperty() lengthVectorProperty() Property

Definition at line 1016 of file qtextformat.cpp.

Referenced by QTextFrameFormat::bottomMargin(), QTextTableCellFormat::bottomPadding(), QTextCharFormat::fontLetterSpacing(), QTextCharFormat::fontPointSize(), QTextCharFormat::fontWordSpacing(), QTextFrameFormat::leftMargin(), QTextTableCellFormat::leftPadding(), QTextBlockFormat::lineHeight(), QTextFrameFormat::rightMargin(), QTextTableCellFormat::rightPadding(), QTextFrameFormat::topMargin(), and QTextTableCellFormat::topPadding().

1017 {
1018  if (!d)
1019  return 0.;
1020  const QVariant prop = d->property(propertyId);
1021  if (prop.userType() != QVariant::Double && prop.userType() != QMetaType::Float)
1022  return 0.;
1023  return qvariant_cast<qreal>(prop);
1024 }
The QVariant class acts like a union for the most common Qt data types.
Definition: qvariant.h:92
double qreal
Definition: qglobal.h:1193
QVariant property(qint32 key) const
int userType() const
Returns the storage type of the value stored in the variant.
Definition: qvariant.cpp:1913
QSharedDataPointer< QTextFormatPrivate > d
Definition: qtextformat.h:358
T qvariant_cast(const QVariant &)
Definition: qvariant.h:571

◆ foreground()

QBrush QTextFormat::foreground ( ) const
inline

Returns the brush used to render foreground details, such as text, frame outlines, and table borders.

See also
setForeground() clearForeground() background()

Definition at line 352 of file qtextformat.h.

Referenced by QTextEditPrivate::_q_currentCharFormatChanged(), QAccessibleTextWidget::attributes(), QCalendarModel::data(), QTextLayout::draw(), QTextLine::draw(), QTextDocumentLayoutPrivate::drawListItem(), QTextHtmlExporter::emitCharFormatStyle(), setPenAndDrawBackground(), and QTextOdfWriter::writeCharacterFormat().

353  { return brushProperty(ForegroundBrush); }
QBrush brushProperty(int propertyId) const
Returns the value of the property given by propertyId; if the property isn&#39;t of QVariant::Brush type...

◆ hasProperty()

bool QTextFormat::hasProperty ( int  propertyId) const

Returns true if the text format has a property with the given propertyId; otherwise returns false.

See also
properties() Property

Definition at line 1254 of file qtextformat.cpp.

Referenced by QTextControlPrivate::anchorForCursor(), QTextHtmlImporter::appendNodeText(), QTextFrameFormat::bottomMargin(), QTextDocumentLayoutPrivate::drawBlock(), QTextDocumentLayoutPrivate::drawListItem(), QTextHtmlExporter::emitBackgroundAttribute(), QTextHtmlExporter::emitBlock(), QTextHtmlExporter::emitBlockAttributes(), QTextHtmlExporter::emitCharFormatStyle(), QTextHtmlExporter::emitFragment(), QTextHtmlExporter::emitFrameStyle(), QTextHtmlExporter::emitTable(), QTextHtmlExporter::emitTextFrame(), QTextControl::findNextPrevAnchor(), QTextCharFormat::fontUnderline(), getImageSize(), getPixmapSize(), QTextHtmlImporter::import(), QTextHtmlParserNode::initializeProperties(), QTextItemInt::initWithScriptItem(), isEmptyBlockBeforeTable(), QTextDocumentLayoutPrivate::layoutBlock(), QTextFrameFormat::leftMargin(), QPlainTextEdit::paintEvent(), QTextFrameFormat::rightMargin(), QTextHtmlImporter::scanTable(), QTextHtmlExporter::toHtml(), QTextFrameFormat::topMargin(), QTextOdfWriter::writeBlockFormat(), QTextOdfWriter::writeCharacterFormat(), QTextOdfWriter::writeFrameFormat(), QTextOdfWriter::writeInlineCharacter(), QTextOdfWriter::writeListFormat(), and QTextOdfWriter::writeTableCellFormat().

1255 {
1256  return d ? d->hasProperty(propertyId) : false;
1257 }
bool hasProperty(qint32 key) const
QSharedDataPointer< QTextFormatPrivate > d
Definition: qtextformat.h:358

◆ intProperty()

int QTextFormat::intProperty ( int  propertyId) const

Returns the value of the property specified by propertyId.

If the property is not of QTextFormat::Integer type, 0 is returned instead.

See also
setProperty() boolProperty() doubleProperty() stringProperty() colorProperty() lengthProperty() lengthVectorProperty() Property

Definition at line 996 of file qtextformat.cpp.

Referenced by QTextDocumentLayoutPrivate::drawListItem(), QTextHtmlExporter::emitCharFormatStyle(), QTextCharFormat::fontCapitalization(), QTextCharFormat::fontHintingPreference(), QTextCharFormat::fontStyleHint(), QTextCharFormat::fontStyleStrategy(), QTextCharFormat::fontWeight(), QTextBlockFormat::lineHeight(), QTextCharFormat::tableCellColumnSpan(), QTextCharFormat::tableCellRowSpan(), QTextHtmlExporter::toHtml(), QTextCharFormat::underlineStyle(), and QTextCharFormat::verticalAlignment().

997 {
998  // required, since the default layout direction has to be LayoutDirectionAuto, which is not integer 0
999  int def = (propertyId == QTextFormat::LayoutDirection) ? int(Qt::LayoutDirectionAuto) : 0;
1000 
1001  if (!d)
1002  return def;
1003  const QVariant prop = d->property(propertyId);
1004  if (prop.userType() != QVariant::Int)
1005  return def;
1006  return prop.toInt();
1007 }
The QVariant class acts like a union for the most common Qt data types.
Definition: qvariant.h:92
QVariant property(qint32 key) const
int toInt(bool *ok=0) const
Returns the variant as an int if the variant has type() Int , Bool , ByteArray , Char ...
Definition: qvariant.cpp:2625
int userType() const
Returns the storage type of the value stored in the variant.
Definition: qvariant.cpp:1913
QSharedDataPointer< QTextFormatPrivate > d
Definition: qtextformat.h:358

◆ isBlockFormat()

bool QTextFormat::isBlockFormat ( ) const
inline

Returns true if this text format is a BlockFormat; otherwise returns false.

Definition at line 319 of file qtextformat.h.

Referenced by QTextCursorPrivate::insertBlock(), and QTextDocumentPrivate::insertBlock().

319 { return type() == BlockFormat; }
int type() const
Returns the type of this format.

◆ isCharFormat()

bool QTextFormat::isCharFormat ( ) const
inline

Returns true if this text format is a CharFormat; otherwise returns false.

Definition at line 318 of file qtextformat.h.

Referenced by QTextDocumentPrivate::insert(), QTextDocumentPrivate::insertBlock(), QTextCursor::insertText(), and QTextCharFormat::isValid().

318 { return type() == CharFormat; }
int type() const
Returns the type of this format.

◆ isFrameFormat()

bool QTextFormat::isFrameFormat ( ) const
inline

Returns true if this text format is a FrameFormat; otherwise returns false.

Definition at line 321 of file qtextformat.h.

Referenced by QTextDocument::createObject().

321 { return type() == FrameFormat; }
int type() const
Returns the type of this format.

◆ isImageFormat()

bool QTextFormat::isImageFormat ( ) const
inline

Returns true if this text format is an image format; otherwise returns false.

Definition at line 322 of file qtextformat.h.

Referenced by QTextHtmlExporter::emitFragment(), and QTextOdfWriter::writeInlineCharacter().

322 { return type() == CharFormat && objectType() == ImageObject; }
int type() const
Returns the type of this format.
int objectType() const
Returns the text format&#39;s object type.
Definition: qtextformat.h:315

◆ isListFormat()

bool QTextFormat::isListFormat ( ) const
inline

Returns true if this text format is a ListFormat; otherwise returns false.

Definition at line 320 of file qtextformat.h.

Referenced by QTextDocument::createObject().

320 { return type() == ListFormat; }
int type() const
Returns the type of this format.

◆ isTableCellFormat()

bool QTextFormat::isTableCellFormat ( ) const
inline

Returns true if this text format is a TableCellFormat; otherwise returns false.

Since
4.4

Definition at line 324 of file qtextformat.h.

Referenced by QTextOdfWriter::writeFormats(), and QTextOdfWriter::writeFrame().

324 { return type() == CharFormat && objectType() == TableCellObject; }
int type() const
Returns the type of this format.
int objectType() const
Returns the text format&#39;s object type.
Definition: qtextformat.h:315

◆ isTableFormat()

bool QTextFormat::isTableFormat ( ) const
inline

Returns true if this text format is a TableFormat; otherwise returns false.

Definition at line 323 of file qtextformat.h.

Referenced by QTextDocument::createObject().

323 { return type() == FrameFormat && objectType() == TableObject; }
int type() const
Returns the type of this format.
int objectType() const
Returns the text format&#39;s object type.
Definition: qtextformat.h:315

◆ isValid()

bool QTextFormat::isValid ( ) const
inline

Returns true if the format is valid (i.

e. is not InvalidFormat); otherwise returns false.

Definition at line 287 of file qtextformat.h.

287 { return type() != InvalidFormat; }
int type() const
Returns the type of this format.

◆ layoutDirection()

Qt::LayoutDirection QTextFormat::layoutDirection ( ) const
inline

Returns the document's layout direction.

See also
setLayoutDirection()

Definition at line 340 of file qtextformat.h.

Referenced by QAccessibleTextWidget::characterRect(), QTextHtmlParserNode::initializeProperties(), and QTextHtmlImporter::scanTable().

LayoutDirection
Definition: qnamespace.h:1580
int intProperty(int propertyId) const
Returns the value of the property specified by propertyId.

◆ lengthProperty()

QTextLength QTextFormat::lengthProperty ( int  propertyId) const

Returns the value of the property given by propertyId.

See also
setProperty() boolProperty() intProperty() doubleProperty() stringProperty() colorProperty() lengthVectorProperty() Property

Definition at line 1100 of file qtextformat.cpp.

Referenced by QTextDocumentLayoutPrivate::drawBlock(), and QTextHtmlExporter::emitBlock().

1101 {
1102  if (!d)
1103  return QTextLength();
1104  return qvariant_cast<QTextLength>(d->property(propertyId));
1105 }
QVariant property(qint32 key) const
QSharedDataPointer< QTextFormatPrivate > d
Definition: qtextformat.h:358
The QTextLength class encapsulates the different types of length used in a QTextDocument.
Definition: qtextformat.h:84
T qvariant_cast(const QVariant &)
Definition: qvariant.h:571

◆ lengthVectorProperty()

QVector< QTextLength > QTextFormat::lengthVectorProperty ( int  propertyId) const

Returns the value of the property given by propertyId.

If the property isn't of QTextFormat::LengthVector type, an empty length vector is returned instead.

See also
setProperty() boolProperty() intProperty() doubleProperty() stringProperty() colorProperty() lengthProperty() Property

Definition at line 1114 of file qtextformat.cpp.

1115 {
1116  QVector<QTextLength> vector;
1117  if (!d)
1118  return vector;
1119  const QVariant prop = d->property(propertyId);
1120  if (prop.userType() != QVariant::List)
1121  return vector;
1122 
1123  QList<QVariant> propertyList = prop.toList();
1124  for (int i=0; i<propertyList.size(); ++i) {
1125  QVariant var = propertyList.at(i);
1126  if (var.userType() == QVariant::TextLength)
1127  vector.append(qvariant_cast<QTextLength>(var));
1128  }
1129 
1130  return vector;
1131 }
The QVariant class acts like a union for the most common Qt data types.
Definition: qvariant.h:92
QList< QVariant > toList() const
Returns the variant as a QVariantList if the variant has type() List or StringList ; otherwise return...
Definition: qvariant.cpp:2751
The QVector class is a template class that provides a dynamic array.
Definition: qdatastream.h:64
QVariant property(qint32 key) const
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
void append(const T &t)
Inserts value at the end of the vector.
Definition: qvector.h:573
int userType() const
Returns the storage type of the value stored in the variant.
Definition: qvariant.cpp:1913
QSharedDataPointer< QTextFormatPrivate > d
Definition: qtextformat.h:358
int size() const
Returns the number of items in the list.
Definition: qlist.h:137

◆ merge()

void QTextFormat::merge ( const QTextFormat other)

Merges the other format with this format; where there are conflicts the other format takes precedence.

Definition at line 880 of file qtextformat.cpp.

Referenced by QTextLine::draw(), QTextHtmlExporter::emitBlock(), QTextHtmlExporter::emitTable(), QTextEngine::format(), QCalendarModel::formatForCell(), QTextCursor::mergeCharFormat(), QTextHtmlImporter::processBlockNode(), QTextHtmlImporter::processSpecialNodes(), QTextDocumentPrivate::setBlockFormat(), and QTextDocumentPrivate::setCharFormat().

881 {
882  if (format_type != other.format_type)
883  return;
884 
885  if (!d) {
886  d = other.d;
887  return;
888  }
889 
890  if (!other.d)
891  return;
892 
893  QTextFormatPrivate *d = this->d;
894 
895  const QVector<QTextFormatPrivate::Property> &otherProps = other.d->props;
896  d->props.reserve(d->props.size() + otherProps.size());
897  for (int i = 0; i < otherProps.count(); ++i) {
898  const QTextFormatPrivate::Property &p = otherProps.at(i);
899  d->insertProperty(p.key, p.value);
900  }
901 }
int count(const T &t) const
Returns the number of occurrences of value in the vector.
Definition: qvector.h:742
const T & at(int i) const
Returns the item at index position i in the vector.
Definition: qvector.h:350
qint32 format_type
Definition: qtextformat.h:359
QSharedDataPointer< QTextFormatPrivate > d
Definition: qtextformat.h:358
QVector< Property > props
void insertProperty(qint32 key, const QVariant &value)
int size() const
Returns the number of items in the vector.
Definition: qvector.h:137

◆ objectIndex()

int QTextFormat::objectIndex ( ) const

Returns the index of the format object, or -1 if the format object is invalid.

See also
setObjectIndex()

Definition at line 1215 of file qtextformat.cpp.

Referenced by QTextCopyHelper::appendFragment(), QTextCursorPrivate::canDelete(), QTextCopyHelper::convertFormatIndex(), QTextFormatCollection::createObjectIndex(), QTextDocumentPrivate::insertBlock(), QTextDocumentPrivate::objectForFormat(), QTextDocumentPrivate::setCharFormat(), QTextFormatCollection::setObjectFormat(), and QTextFormatCollection::setObjectFormatIndex().

1216 {
1217  if (!d)
1218  return -1;
1219  const QVariant prop = d->property(ObjectIndex);
1220  if (prop.userType() != QVariant::Int) // ####
1221  return -1;
1222  return prop.toInt();
1223 }
The QVariant class acts like a union for the most common Qt data types.
Definition: qvariant.h:92
QVariant property(qint32 key) const
int toInt(bool *ok=0) const
Returns the variant as an int if the variant has type() Int , Bool , ByteArray , Char ...
Definition: qvariant.cpp:2625
int userType() const
Returns the storage type of the value stored in the variant.
Definition: qvariant.cpp:1913
QSharedDataPointer< QTextFormatPrivate > d
Definition: qtextformat.h:358

◆ objectType()

int QTextFormat::objectType ( ) const
inline

◆ operator QVariant()

QTextFormat::operator QVariant ( ) const

Returns the text format as a QVariant.

Definition at line 871 of file qtextformat.cpp.

872 {
873  return QVariant(QVariant::TextFormat, this);
874 }
The QVariant class acts like a union for the most common Qt data types.
Definition: qvariant.h:92

◆ operator!=()

bool QTextFormat::operator!= ( const QTextFormat rhs) const
inline

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

Definition at line 335 of file qtextformat.h.

335 { return !operator==(rhs); }
bool operator==(const QTextFormat &rhs) const
Returns true if this text format is the same as the other text format.

◆ operator=()

QTextFormat & QTextFormat::operator= ( const QTextFormat rhs)

Assigns the other text format to this text format, and returns a reference to this text format.

Definition at line 853 of file qtextformat.cpp.

854 {
855  d = rhs.d;
856  format_type = rhs.format_type;
857  return *this;
858 }
qint32 format_type
Definition: qtextformat.h:359
QSharedDataPointer< QTextFormatPrivate > d
Definition: qtextformat.h:358

◆ operator==()

bool QTextFormat::operator== ( const QTextFormat rhs) const

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

Definition at line 1310 of file qtextformat.cpp.

1311 {
1312  if (format_type != rhs.format_type)
1313  return false;
1314 
1315  if (d == rhs.d)
1316  return true;
1317 
1318  if (d && d->props.isEmpty() && !rhs.d)
1319  return true;
1320 
1321  if (!d && rhs.d && rhs.d->props.isEmpty())
1322  return true;
1323 
1324  if (!d || !rhs.d)
1325  return false;
1326 
1327  return *d == *rhs.d;
1328 }
qint32 format_type
Definition: qtextformat.h:359
QSharedDataPointer< QTextFormatPrivate > d
Definition: qtextformat.h:358
QVector< Property > props

◆ penProperty()

QPen QTextFormat::penProperty ( int  propertyId) const

Returns the value of the property given by propertyId; if the property isn't of QVariant::Pen type, Qt::NoPen is returned instead.

See also
setProperty() boolProperty() intProperty() doubleProperty() stringProperty() lengthProperty() lengthVectorProperty() Property

Definition at line 1068 of file qtextformat.cpp.

Referenced by QTextLayout::draw(), QTextLine::draw(), and QTextCharFormat::textOutline().

1069 {
1070  if (!d)
1071  return QPen(Qt::NoPen);
1072  const QVariant prop = d->property(propertyId);
1073  if (prop.userType() != QVariant::Pen)
1074  return QPen(Qt::NoPen);
1075  return qvariant_cast<QPen>(prop);
1076 }
The QVariant class acts like a union for the most common Qt data types.
Definition: qvariant.h:92
QVariant property(qint32 key) const
The QPen class defines how a QPainter should draw lines and outlines of shapes.
Definition: qpen.h:64
int userType() const
Returns the storage type of the value stored in the variant.
Definition: qvariant.cpp:1913
QSharedDataPointer< QTextFormatPrivate > d
Definition: qtextformat.h:358
T qvariant_cast(const QVariant &)
Definition: qvariant.h:571

◆ properties()

QMap< int, QVariant > QTextFormat::properties ( ) const

Returns a map with all properties of this text format.

Definition at line 1268 of file qtextformat.cpp.

Referenced by QTextHtmlExporter::emitBlock(), formatDifference(), and operator<<().

1269 {
1271  if (d) {
1272  for (int i = 0; i < d->props.count(); ++i)
1273  map.insert(d->props.at(i).key, d->props.at(i).value);
1274  }
1275  return map;
1276 }
QFuture< void > map(Sequence &sequence, MapFunction function)
QSharedDataPointer< QTextFormatPrivate > d
Definition: qtextformat.h:358
iterator insert(const Key &key, const T &value)
Inserts a new item with the key key and a value of value.
Definition: qmap.h:559
QVector< Property > props
The QMap class is a template class that provides a skip-list-based dictionary.
Definition: qdatastream.h:67

◆ property()

QVariant QTextFormat::property ( int  propertyId) const

Returns the property specified by the given propertyId.

See also
Property

Definition at line 1138 of file qtextformat.cpp.

Referenced by QTextCharFormat::anchorName(), QTextCharFormat::anchorNames(), QTextLayout::draw(), QTextLine::draw(), QTextHtmlExporter::emitBackgroundAttribute(), QTextHtmlExporter::emitBlockAttributes(), formatDifference(), QTextTableData::paddingProperty(), setPenAndDrawBackground(), and QTextBlockFormat::tabPositions().

1139 {
1140  return d ? d->property(propertyId) : QVariant();
1141 }
The QVariant class acts like a union for the most common Qt data types.
Definition: qvariant.h:92
QVariant property(qint32 key) const
QSharedDataPointer< QTextFormatPrivate > d
Definition: qtextformat.h:358

◆ propertyCount()

int QTextFormat::propertyCount ( ) const

Returns the number of properties stored in the format.

Since
4.3

Definition at line 1285 of file qtextformat.cpp.

Referenced by QTextHtmlImporter::processBlockNode().

1286 {
1287  return d ? d->props.count() : 0;
1288 }
QSharedDataPointer< QTextFormatPrivate > d
Definition: qtextformat.h:358
QVector< Property > props

◆ setBackground()

void QTextFormat::setBackground ( const QBrush brush)
inline

◆ setForeground()

void QTextFormat::setForeground ( const QBrush brush)
inline

◆ setLayoutDirection()

void QTextFormat::setLayoutDirection ( Qt::LayoutDirection  direction)
inline

Sets the document's layout direction to the specified direction.

See also
layoutDirection()

Definition at line 338 of file qtextformat.h.

Referenced by QTextHtmlParser::applyAttributes(), QTextHtmlParserNode::initializeProperties(), QTextControlPrivate::keyPressEvent(), and QTextHtmlImporter::scanTable().

void setProperty(int propertyId, const QVariant &value)
Sets the property specified by the propertyId to the given value.
Qt::LayoutDirection direction

◆ setObjectIndex()

void QTextFormat::setObjectIndex ( int  index)

Sets the format object's object index.

See also
objectIndex()

Definition at line 1235 of file qtextformat.cpp.

Referenced by QTextList::add(), QTextCopyHelper::convertFormatIndex(), QTextCursor::createList(), QTextTablePrivate::createTable(), QTextDocumentPrivate::insertFrame(), QTextCursor::insertImage(), QTextList::remove(), and QTextDocumentPrivate::setCharFormat().

1236 {
1237  if (o == -1) {
1238  if (d)
1240  } else {
1241  if (!d)
1242  d = new QTextFormatPrivate;
1243  // ### type
1245  }
1246 }
void clearProperty(qint32 key)
QSharedDataPointer< QTextFormatPrivate > d
Definition: qtextformat.h:358
void insertProperty(qint32 key, const QVariant &value)

◆ setObjectType()

void QTextFormat::setObjectType ( int  type)
inline

Sets the text format's object type to type.

See also
ObjectTypes, objectType()

Definition at line 367 of file qtextformat.h.

Referenced by QTextTablePrivate::createTable(), QTextTableCell::format(), QTextImageFormat::QTextImageFormat(), QTextTableCellFormat::QTextTableCellFormat(), QTextTableFormat::QTextTableFormat(), and QTextTableCell::setFormat().

368 { setProperty(ObjectType, atype); }
void setProperty(int propertyId, const QVariant &value)
Sets the property specified by the propertyId to the given value.

◆ setProperty() [1/2]

void QTextFormat::setProperty ( int  propertyId,
const QVariant value 
)

Sets the property specified by the propertyId to the given value.

See also
Property

Definition at line 1148 of file qtextformat.cpp.

Referenced by QTextHtmlParser::applyAttributes(), QTextHtmlParserNode::applyBackgroundImage(), QTextHtmlParserNode::applyCssDeclarations(), QTextLayout::draw(), QTextControl::getPaintContext(), QTextHtmlParserNode::initializeProperties(), QTextHtmlImporter::processSpecialNodes(), QTextHtmlImporter::scanTable(), QTextBlockFormat::setAlignment(), QTextTableFormat::setAlignment(), QTextCharFormat::setAnchor(), QTextCharFormat::setAnchorHref(), QTextCharFormat::setAnchorNames(), QTextFrameFormat::setBorder(), QTextFrameFormat::setBottomMargin(), QTextTableCellFormat::setBottomPadding(), QTextTableFormat::setCellPadding(), QTextTableFormat::setColumns(), QTextCharFormat::setFont(), QTextCharFormat::setFontCapitalization(), QTextCharFormat::setFontFamily(), QTextCharFormat::setFontFixedPitch(), QTextCharFormat::setFontHintingPreference(), QTextCharFormat::setFontItalic(), QTextCharFormat::setFontKerning(), QTextCharFormat::setFontLetterSpacing(), QTextCharFormat::setFontOverline(), QTextCharFormat::setFontPointSize(), QTextCharFormat::setFontStrikeOut(), QTextCharFormat::setFontStyleHint(), QTextCharFormat::setFontStyleStrategy(), QTextCharFormat::setFontUnderline(), QTextCharFormat::setFontWeight(), QTextCharFormat::setFontWordSpacing(), QTextImageFormat::setHeight(), QTextFrameFormat::setHeight(), QTextBlockFormat::setIndent(), QTextListFormat::setIndent(), QTextFrameFormat::setLeftMargin(), QTextTableCellFormat::setLeftPadding(), QTextHtmlParserNode::setListStyle(), QTextFrameFormat::setMargin(), QTextImageFormat::setName(), QTextListFormat::setNumberPrefix(), QTextListFormat::setNumberSuffix(), setObjectType(), QTextFrameFormat::setPadding(), QTextFrameFormat::setRightMargin(), QTextTableCellFormat::setRightPadding(), QTextListFormat::setStyle(), QTextCharFormat::setTableCellColumnSpan(), QTextCharFormat::setTableCellRowSpan(), QTextBlockFormat::setTabPositions(), QTextCharFormat::setTextOutline(), QTextCharFormat::setToolTip(), QTextFrameFormat::setTopMargin(), QTextTableCellFormat::setTopPadding(), QTextCharFormat::setUnderlineColor(), QTextCharFormat::setUnderlineStyle(), QTextCharFormat::setVerticalAlignment(), QTextImageFormat::setWidth(), QTextFrameFormat::setWidth(), QCommonStyle::styleHint(), and QScriptEdit::updateExtraSelections().

1149 {
1150  if (!d)
1151  d = new QTextFormatPrivate;
1152  if (!value.isValid())
1153  clearProperty(propertyId);
1154  else
1155  d->insertProperty(propertyId, value);
1156 }
QSharedDataPointer< QTextFormatPrivate > d
Definition: qtextformat.h:358
void insertProperty(qint32 key, const QVariant &value)
void clearProperty(int propertyId)
Clears the value of the property given by propertyId.
bool isValid() const
Returns true if the storage type of this variant is not QVariant::Invalid; otherwise returns false...
Definition: qvariant.h:485

◆ setProperty() [2/2]

void QTextFormat::setProperty ( int  propertyId,
const QVector< QTextLength > &  value 
)

Sets the value of the property given by propertyId to value.

See also
lengthVectorProperty() Property

Definition at line 1163 of file qtextformat.cpp.

1164 {
1165  if (!d)
1166  d = new QTextFormatPrivate;
1167  QVariantList list;
1168  for (int i=0; i<value.size(); ++i)
1169  list << value.at(i);
1170  d->insertProperty(propertyId, list);
1171 }
const T & at(int i) const
Returns the item at index position i in the vector.
Definition: qvector.h:350
QSharedDataPointer< QTextFormatPrivate > d
Definition: qtextformat.h:358
void insertProperty(qint32 key, const QVariant &value)
int size() const
Returns the number of items in the vector.
Definition: qvector.h:137

◆ stringProperty()

QString QTextFormat::stringProperty ( int  propertyId) const

Returns the value of the property given by propertyId; if the property isn't of QVariant::String type, an empty string is returned instead.

See also
setProperty() boolProperty() intProperty() doubleProperty() colorProperty() lengthProperty() lengthVectorProperty() Property

Definition at line 1033 of file qtextformat.cpp.

Referenced by QTextControlPrivate::anchorForCursor(), QTextCharFormat::anchorHref(), QTextCharFormat::fontFamily(), and QTextCharFormat::toolTip().

1034 {
1035  if (!d)
1036  return QString();
1037  const QVariant prop = d->property(propertyId);
1038  if (prop.userType() != QVariant::String)
1039  return QString();
1040  return prop.toString();
1041 }
The QVariant class acts like a union for the most common Qt data types.
Definition: qvariant.h:92
QString toString() const
Returns the variant as a QString if the variant has type() String , Bool , ByteArray ...
Definition: qvariant.cpp:2270
The QString class provides a Unicode character string.
Definition: qstring.h:83
QVariant property(qint32 key) const
int userType() const
Returns the storage type of the value stored in the variant.
Definition: qvariant.cpp:1913
QSharedDataPointer< QTextFormatPrivate > d
Definition: qtextformat.h:358

◆ toBlockFormat()

QTextBlockFormat QTextFormat::toBlockFormat ( ) const

Returns this format as a block format.

Definition at line 916 of file qtextformat.cpp.

Referenced by QTextBlock::blockFormat(), and QTextOdfWriter::writeFormats().

917 {
918  return QTextBlockFormat(*this);
919 }
The QTextBlockFormat class provides formatting information for blocks of text in a QTextDocument...
Definition: qtextformat.h:545

◆ toCharFormat()

QTextCharFormat QTextFormat::toCharFormat ( ) const

◆ toFrameFormat()

QTextFrameFormat QTextFormat::toFrameFormat ( ) const

Returns this format as a frame format.

Definition at line 948 of file qtextformat.cpp.

Referenced by QTextFrame::frameFormat(), and QTextOdfWriter::writeFormats().

949 {
950  return QTextFrameFormat(*this);
951 }
The QTextFrameFormat class provides formatting information for frames in a QTextDocument.
Definition: qtextformat.h:727

◆ toImageFormat()

QTextImageFormat QTextFormat::toImageFormat ( ) const

Returns this format as an image format.

Definition at line 956 of file qtextformat.cpp.

Referenced by QTextImageHandler::drawObject(), QTextHtmlExporter::emitFragment(), QTextImageHandler::intrinsicSize(), and QTextOdfWriter::writeInlineCharacter().

957 {
958  return QTextImageFormat(*this);
959 }
The QTextImageFormat class provides formatting information for images in a QTextDocument.
Definition: qtextformat.h:694

◆ toListFormat()

QTextListFormat QTextFormat::toListFormat ( ) const

Returns this format as a list format.

Definition at line 932 of file qtextformat.cpp.

Referenced by QTextDocumentLayoutPrivate::blockIndent(), QTextDocumentLayoutPrivate::drawBlock(), QTextDocumentLayoutPrivate::drawListItem(), QTextList::format(), and QTextOdfWriter::writeFormats().

933 {
934  return QTextListFormat(*this);
935 }
The QTextListFormat class provides formatting information for lists in a QTextDocument.
Definition: qtextformat.h:642

◆ toTableCellFormat()

QTextTableCellFormat QTextFormat::toTableCellFormat ( ) const

Returns this format as a table cell format.

Since
4.4

Definition at line 969 of file qtextformat.cpp.

Referenced by QTextHtmlExporter::emitTable(), QTextHtmlImporter::processBlockNode(), and QTextOdfWriter::writeFormats().

970 {
971  return QTextTableCellFormat(*this);
972 }
The QTextTableCellFormat class provides formatting information for table cells in a QTextDocument...
Definition: qtextformat.h:898

◆ toTableFormat()

QTextTableFormat QTextFormat::toTableFormat ( ) const

Returns this format as a table format.

Definition at line 940 of file qtextformat.cpp.

Referenced by QTextTable::format(), and QTextHtmlImporter::scanTable().

941 {
942  return QTextTableFormat(*this);
943 }
The QTextTableFormat class provides formatting information for tables in a QTextDocument.
Definition: qtextformat.h:842

◆ type()

int QTextFormat::type ( ) const

Returns the type of this format.

See also
FormatType

Definition at line 908 of file qtextformat.cpp.

Referenced by QTextCopyHelper::convertFormatIndex(), QTextDocumentPrivate::setCharFormat(), and QTextOdfWriter::writeFormats().

909 {
910  return format_type;
911 }
qint32 format_type
Definition: qtextformat.h:359

Friends and Related Functions

◆ operator<<

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

Definition at line 459 of file qtextformat.cpp.

460 {
461  stream << fmt.format_type << fmt.properties();
462  return stream;
463 }
QMap< int, QVariant > properties() const
Returns a map with all properties of this text format.
static FILE * stream
qint32 format_type
Definition: qtextformat.h:359

◆ operator>>

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

Definition at line 465 of file qtextformat.cpp.

466 {
468  stream >> fmt.format_type >> properties;
469 
470  // QTextFormat's default constructor doesn't allocate the private structure, so
471  // we have to do this, in case fmt is a default constructed value.
472  if(!fmt.d)
473  fmt.d = new QTextFormatPrivate();
474 
476  it != properties.constEnd(); ++it)
477  fmt.d->insertProperty(it.key(), it.value());
478 
479  return stream;
480 }
#define it(className, varName)
QMap< int, QVariant > properties() const
Returns a map with all properties of this text format.
static FILE * stream
const_iterator constBegin() const
Returns a const STL-style iterator pointing to the first item in the map.
Definition: qmap.h:374
qint32 format_type
Definition: qtextformat.h:359
The QMap::const_iterator class provides an STL-style const iterator for QMap and QMultiMap.
Definition: qmap.h:301
const_iterator constEnd() const
Returns a const STL-style iterator pointing to the imaginary item after the last item in the map...
Definition: qmap.h:380
QSharedDataPointer< QTextFormatPrivate > d
Definition: qtextformat.h:358
void insertProperty(qint32 key, const QVariant &value)
The QMap class is a template class that provides a skip-list-based dictionary.
Definition: qdatastream.h:67

◆ QTextCharFormat

friend class QTextCharFormat
friend

Definition at line 362 of file qtextformat.h.

Referenced by toCharFormat().

◆ QTextFormatCollection

Definition at line 361 of file qtextformat.h.

Properties

◆ d

QSharedDataPointer<QTextFormatPrivate> QTextFormat::d
private

◆ format_type

qint32 QTextFormat::format_type
private

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