Qt 4.8
Public Types | Public Functions | Public Variables | Properties | List of all members
QTextFormatCollection Class Reference

#include <qtextformat_p.h>

Public Types

typedef QVector< QTextFormatFormatVector
 

Public Functions

QTextBlockFormat blockFormat (int index) const
 
QTextCharFormat charFormat (int index) const
 
int createObjectIndex (const QTextFormat &f)
 
QFont defaultFont () const
 
QTextFormat format (int idx) const
 
bool hasFormatCached (const QTextFormat &format) const
 
QTextImageFormat imageFormat (int index) const
 
int indexForFormat (const QTextFormat &f)
 
QTextListFormat listFormat (int index) const
 
int numFormats () const
 
QTextFormat objectFormat (int objectIndex) const
 
int objectFormatIndex (int objectIndex) const
 
QTextFormatCollectionoperator= (const QTextFormatCollection &rhs)
 
 QTextFormatCollection ()
 
 QTextFormatCollection (const QTextFormatCollection &rhs)
 
void setDefaultFont (const QFont &f)
 
void setObjectFormat (int objectIndex, const QTextFormat &format)
 
void setObjectFormatIndex (int objectIndex, int formatIndex)
 
QTextTableFormat tableFormat (int index) const
 
 ~QTextFormatCollection ()
 

Public Variables

FormatVector formats
 
QMultiHash< uint, int > hashes
 
QVector< qint32objFormats
 

Properties

QFont defaultFnt
 

Detailed Description

Definition at line 62 of file qtextformat_p.h.

Typedefs

◆ FormatVector

Definition at line 96 of file qtextformat_p.h.

Constructors and Destructors

◆ QTextFormatCollection() [1/2]

QTextFormatCollection::QTextFormatCollection ( )
inline

Definition at line 65 of file qtextformat_p.h.

65 {}

◆ ~QTextFormatCollection()

QTextFormatCollection::~QTextFormatCollection ( )

Definition at line 3865 of file qtextformat.cpp.

3866 {
3867 }

◆ QTextFormatCollection() [2/2]

QTextFormatCollection::QTextFormatCollection ( const QTextFormatCollection rhs)

Definition at line 3852 of file qtextformat.cpp.

3853 {
3854  formats = rhs.formats;
3855  objFormats = rhs.objFormats;
3856 }
FormatVector formats
Definition: qtextformat_p.h:98
QVector< qint32 > objFormats
Definition: qtextformat_p.h:99

Functions

◆ blockFormat()

QTextBlockFormat QTextFormatCollection::blockFormat ( int  index) const
inline

Definition at line 83 of file qtextformat_p.h.

Referenced by QTextDocumentPrivate::setBlockFormat(), and QTextDocumentPrivate::undoRedo().

84  { return format(index).toBlockFormat(); }
QTextFormat format(int idx) const
QTextBlockFormat toBlockFormat() const
Returns this format as a block format.
quint16 index

◆ charFormat()

QTextCharFormat QTextFormatCollection::charFormat ( int  index) const
inline

◆ createObjectIndex()

int QTextFormatCollection::createObjectIndex ( const QTextFormat f)

Definition at line 3937 of file qtextformat.cpp.

Referenced by QTextCopyHelper::convertFormatIndex(), QTextCopyHelper::copy(), and QTextDocumentPrivate::createObject().

3938 {
3939  const int objectIndex = objFormats.size();
3941  return objectIndex;
3942 }
void append(const T &t)
Inserts value at the end of the vector.
Definition: qvector.h:573
QVector< qint32 > objFormats
Definition: qtextformat_p.h:99
int indexForFormat(const QTextFormat &f)
int size() const
Returns the number of items in the vector.
Definition: qvector.h:137

◆ defaultFont()

QFont QTextFormatCollection::defaultFont ( ) const
inline

Definition at line 102 of file qtextformat_p.h.

102 { return defaultFnt; }

◆ format()

QTextFormat QTextFormatCollection::format ( int  idx) const

Definition at line 3944 of file qtextformat.cpp.

Referenced by QTextCopyHelper::appendFragment(), QTextCopyHelper::convertFormat(), QTextCopyHelper::convertFormatIndex(), QTextInlineObject::format(), QTextEngine::format(), QTextDocumentPrivate::insert(), QTextDocumentPrivate::insert_block(), QTextCursorPrivate::insertBlock(), QTextDocumentPrivate::insertBlock(), QTextCursor::insertText(), QTextLine::layout_helper(), QTextDocumentPrivate::objectForFormat(), QTextDocumentPrivate::setCharFormat(), and QTextEngine::shape().

3945 {
3946  if (idx < 0 || idx >= formats.count())
3947  return QTextFormat();
3948 
3949  return formats.at(idx);
3950 }
int count(const T &t) const
Returns the number of occurrences of value in the vector.
Definition: qvector.h:742
The QTextFormat class provides formatting information for a QTextDocument.
Definition: qtextformat.h:129
const T & at(int i) const
Returns the item at index position i in the vector.
Definition: qvector.h:350
FormatVector formats
Definition: qtextformat_p.h:98

◆ hasFormatCached()

bool QTextFormatCollection::hasFormatCached ( const QTextFormat format) const

Definition at line 3899 of file qtextformat.cpp.

3900 {
3901  uint hash = getHash(format.d, format.format_type);
3903  while (i != hashes.end() && i.key() == hash) {
3904  if (formats.value(i.value()) == format) {
3905  return true;
3906  }
3907  ++i;
3908  }
3909  return false;
3910 }
The QMultiHash class is a convenience QHash subclass that provides multi-valued hashes.
Definition: qcontainerfwd.h:58
static int getHash(const QTextFormatPrivate *d, int format)
QHash< Key, T >::iterator find(const Key &key, const T &value)
Returns an iterator pointing to the item with the key and value.
Definition: qhash.h:972
const T value(const Key &key) const
Returns the value associated with the key.
Definition: qhash.h:606
static uint hash(float d)
T value(int i) const
Returns the value at index position i in the vector.
Definition: qvector.h:559
unsigned int uint
Definition: qglobal.h:996
qint32 format_type
Definition: qtextformat.h:359
FormatVector formats
Definition: qtextformat_p.h:98
QMultiHash< uint, int > hashes
iterator end()
Returns an STL-style iterator pointing to the imaginary item after the last item in the hash...
Definition: qhash.h:467
QSharedDataPointer< QTextFormatPrivate > d
Definition: qtextformat.h:358
const Key key(const T &value) const
Returns the first key mapped to value.
Definition: qhash.h:674

◆ imageFormat()

QTextImageFormat QTextFormatCollection::imageFormat ( int  index) const
inline

Definition at line 91 of file qtextformat_p.h.

92  { return format(index).toImageFormat(); }
QTextFormat format(int idx) const
QTextImageFormat toImageFormat() const
Returns this format as an image format.
quint16 index

◆ indexForFormat()

int QTextFormatCollection::indexForFormat ( const QTextFormat f)

Definition at line 3869 of file qtextformat.cpp.

Referenced by QTextCopyHelper::convertFormatIndex(), QTextTablePrivate::createTable(), QTextEngine::indexAdditionalFormats(), QTextDocumentPrivate::init(), QTextCursorPrivate::insertBlock(), QTextTable::insertColumns(), QTextDocumentPrivate::insertFrame(), QTextCursor::insertImage(), QTextTable::insertRows(), QTextCursor::insertText(), QTextCursor::mergeCharFormat(), QTextEngine::resolveAdditionalFormats(), QTextDocumentPrivate::setBlockFormat(), QTextCursor::setCharFormat(), QTextDocumentPrivate::setCharFormat(), and QTextTable::splitCell().

3870 {
3871  uint hash = getHash(format.d, format.format_type);
3873  while (i != hashes.end() && i.key() == hash) {
3874  if (formats.value(i.value()) == format) {
3875  return i.value();
3876  }
3877  ++i;
3878  }
3879 
3880  int idx = formats.size();
3882 
3883  QT_TRY{
3884  QTextFormat &f = formats.last();
3885  if (!f.d)
3886  f.d = new QTextFormatPrivate;
3887  f.d->resolveFont(defaultFnt);
3888 
3889  if (!hashes.contains(hash, idx))
3890  hashes.insert(hash, idx);
3891 
3892  } QT_CATCH(...) {
3893  formats.pop_back();
3894  QT_RETHROW;
3895  }
3896  return idx;
3897 }
The QMultiHash class is a convenience QHash subclass that provides multi-valued hashes.
Definition: qcontainerfwd.h:58
static int getHash(const QTextFormatPrivate *d, int format)
QHash< Key, T >::iterator find(const Key &key, const T &value)
Returns an iterator pointing to the item with the key and value.
Definition: qhash.h:972
const T value(const Key &key) const
Returns the value associated with the key.
Definition: qhash.h:606
void pop_back()
This function is provided for STL compatibility.
Definition: qvector.h:283
#define QT_RETHROW
Definition: qglobal.h:1539
void resolveFont(const QFont &defaultFont)
static uint hash(float d)
The QTextFormat class provides formatting information for a QTextDocument.
Definition: qtextformat.h:129
T value(int i) const
Returns the value at index position i in the vector.
Definition: qvector.h:559
bool contains(const Key &key, const T &value) const
Returns true if the hash contains an item with the key and value; otherwise returns false...
Definition: qhash.h:1000
void append(const T &t)
Inserts value at the end of the vector.
Definition: qvector.h:573
unsigned int uint
Definition: qglobal.h:996
#define QT_CATCH(A)
Definition: qglobal.h:1537
FormatVector formats
Definition: qtextformat_p.h:98
QHash< Key, T >::iterator insert(const Key &key, const T &value)
Inserts a new item with the key and a value of value.
Definition: qhash.h:934
QMultiHash< uint, int > hashes
iterator end()
Returns an STL-style iterator pointing to the imaginary item after the last item in the hash...
Definition: qhash.h:467
QSharedDataPointer< QTextFormatPrivate > d
Definition: qtextformat.h:358
const Key key(const T &value) const
Returns the first key mapped to value.
Definition: qhash.h:674
T & last()
Returns a reference to the last item in the vector.
Definition: qvector.h:262
int size() const
Returns the number of items in the vector.
Definition: qvector.h:137
#define QT_TRY
Definition: qglobal.h:1536

◆ listFormat()

QTextListFormat QTextFormatCollection::listFormat ( int  index) const
inline

Definition at line 87 of file qtextformat_p.h.

88  { return format(index).toListFormat(); }
QTextFormat format(int idx) const
QTextListFormat toListFormat() const
Returns this format as a list format.
quint16 index

◆ numFormats()

int QTextFormatCollection::numFormats ( ) const
inline

Definition at line 94 of file qtextformat_p.h.

94 { return formats.count(); }
int count(const T &t) const
Returns the number of occurrences of value in the vector.
Definition: qvector.h:742
FormatVector formats
Definition: qtextformat_p.h:98

◆ objectFormat()

QTextFormat QTextFormatCollection::objectFormat ( int  objectIndex) const

Definition at line 3912 of file qtextformat.cpp.

Referenced by QTextCopyHelper::convertFormatIndex(), and QTextDocumentPrivate::objectForIndex().

3913 {
3914  if (objectIndex == -1)
3915  return QTextFormat();
3916  return format(objFormats.at(objectIndex));
3917 }
QTextFormat format(int idx) const
The QTextFormat class provides formatting information for a QTextDocument.
Definition: qtextformat.h:129
const T & at(int i) const
Returns the item at index position i in the vector.
Definition: qvector.h:350
QVector< qint32 > objFormats
Definition: qtextformat_p.h:99

◆ objectFormatIndex()

int QTextFormatCollection::objectFormatIndex ( int  objectIndex) const

Definition at line 3925 of file qtextformat.cpp.

Referenced by QTextDocumentPrivate::changeObjectFormat(), and QTextDocumentPrivate::undoRedo().

3926 {
3927  if (objectIndex == -1)
3928  return -1;
3929  return objFormats.at(objectIndex);
3930 }
const T & at(int i) const
Returns the item at index position i in the vector.
Definition: qvector.h:350
QVector< qint32 > objFormats
Definition: qtextformat_p.h:99

◆ operator=()

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

Definition at line 3858 of file qtextformat.cpp.

3859 {
3860  formats = rhs.formats;
3861  objFormats = rhs.objFormats;
3862  return *this;
3863 }
FormatVector formats
Definition: qtextformat_p.h:98
QVector< qint32 > objFormats
Definition: qtextformat_p.h:99

◆ setDefaultFont()

void QTextFormatCollection::setDefaultFont ( const QFont f)

Definition at line 3952 of file qtextformat.cpp.

3953 {
3954  defaultFnt = f;
3955  for (int i = 0; i < formats.count(); ++i)
3956  if (formats[i].d)
3957  formats[i].d->resolveFont(defaultFnt);
3958 }
double d
Definition: qnumeric_p.h:62
int count(const T &t) const
Returns the number of occurrences of value in the vector.
Definition: qvector.h:742
QVectorData * d
Definition: qvector.h:109
FormatVector formats
Definition: qtextformat_p.h:98

◆ setObjectFormat()

void QTextFormatCollection::setObjectFormat ( int  objectIndex,
const QTextFormat format 
)

Definition at line 3919 of file qtextformat.cpp.

3920 {
3921  const int formatIndex = indexForFormat(f);
3922  objFormats[objectIndex] = formatIndex;
3923 }
QVector< qint32 > objFormats
Definition: qtextformat_p.h:99
int indexForFormat(const QTextFormat &f)

◆ setObjectFormatIndex()

void QTextFormatCollection::setObjectFormatIndex ( int  objectIndex,
int  formatIndex 
)

Definition at line 3932 of file qtextformat.cpp.

Referenced by QTextDocumentPrivate::changeObjectFormat().

3933 {
3934  objFormats[objectIndex] = formatIndex;
3935 }
QVector< qint32 > objFormats
Definition: qtextformat_p.h:99

◆ tableFormat()

QTextTableFormat QTextFormatCollection::tableFormat ( int  index) const
inline

Definition at line 89 of file qtextformat_p.h.

90  { return format(index).toTableFormat(); }
QTextTableFormat toTableFormat() const
Returns this format as a table format.
QTextFormat format(int idx) const
quint16 index

Properties

◆ defaultFnt

QFont QTextFormatCollection::defaultFnt
private

Definition at line 106 of file qtextformat_p.h.

◆ formats

FormatVector QTextFormatCollection::formats

Definition at line 98 of file qtextformat_p.h.

Referenced by operator=(), and QTextFormatCollection().

◆ hashes

QMultiHash<uint,int> QTextFormatCollection::hashes

Definition at line 100 of file qtextformat_p.h.

◆ objFormats

QVector<qint32> QTextFormatCollection::objFormats

Definition at line 99 of file qtextformat_p.h.

Referenced by operator=(), and QTextFormatCollection().


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