Qt 4.8
Classes | Public Functions | Public Variables | Private Functions | Properties | Friends | List of all members
QTextFormatPrivate Class Reference
Inheritance diagram for QTextFormatPrivate:
QSharedData

Classes

struct  Property
 

Public Functions

void clearProperty (qint32 key)
 
const QFontfont () const
 
uint hash () const
 
bool hasProperty (qint32 key) const
 
void insertProperty (qint32 key, const QVariant &value)
 
bool operator== (const QTextFormatPrivate &rhs) const
 
QVariant property (qint32 key) const
 
int propertyIndex (qint32 key) const
 
 QTextFormatPrivate ()
 
void resolveFont (const QFont &defaultFont)
 
- Public Functions inherited from QSharedData
 QSharedData ()
 Constructs a QSharedData object with a reference count of 0. More...
 
 QSharedData (const QSharedData &)
 Constructs a QSharedData object with reference count 0. More...
 

Public Variables

QVector< Propertyprops
 
- Public Variables inherited from QSharedData
QAtomicInt ref
 

Private Functions

void recalcFont () const
 
uint recalcHash () const
 

Properties

QFont fnt
 
bool fontDirty
 
bool hashDirty
 
uint hashValue
 

Friends

QDataStreamoperator<< (QDataStream &, const QTextFormat &)
 
QDataStreamoperator>> (QDataStream &, QTextFormat &)
 

Detailed Description

Definition at line 195 of file qtextformat.cpp.

Constructors and Destructors

◆ QTextFormatPrivate()

QTextFormatPrivate::QTextFormatPrivate ( )
inline

Definition at line 198 of file qtextformat.cpp.

Referenced by operator>>().

Functions

◆ clearProperty()

void QTextFormatPrivate::clearProperty ( qint32  key)
inline

Definition at line 241 of file qtextformat.cpp.

Referenced by QTextFormat::clearProperty(), and QTextFormat::setObjectIndex().

242  {
243  for (int i = 0; i < props.count(); ++i)
244  if (props.at(i).key == key) {
245  hashDirty = true;
247  fontDirty = true;
248  props.remove(i);
249  return;
250  }
251  }
int key
QVector< Property > props

◆ font()

const QFont& QTextFormatPrivate::font ( ) const
inline

Definition at line 274 of file qtextformat.cpp.

Referenced by QTextCharFormat::font().

274  {
275  if (fontDirty)
276  recalcFont();
277  return fnt;
278  }
void recalcFont() const

◆ hash()

uint QTextFormatPrivate::hash ( ) const
inline

Definition at line 214 of file qtextformat.cpp.

Referenced by getHash(), hash(), operator==(), and variantHash().

215  {
216  if (!hashDirty)
217  return hashValue;
218  return recalcHash();
219  }
uint recalcHash() const

◆ hasProperty()

bool QTextFormatPrivate::hasProperty ( qint32  key) const
inline

Definition at line 269 of file qtextformat.cpp.

Referenced by QTextFormat::hasProperty(), recalcFont(), and resolveFont().

270  { return propertyIndex(key) != -1; }
int propertyIndex(qint32 key) const
int key

◆ insertProperty()

void QTextFormatPrivate::insertProperty ( qint32  key,
const QVariant value 
)
inline

Definition at line 228 of file qtextformat.cpp.

Referenced by QTextFormat::merge(), operator>>(), QTextFormat::setObjectIndex(), and QTextFormat::setProperty().

229  {
230  hashDirty = true;
232  fontDirty = true;
233  for (int i = 0; i < props.count(); ++i)
234  if (props.at(i).key == key) {
235  props[i].value = value;
236  return;
237  }
238  props.append(Property(key, value));
239  }
int key
QVector< Property > props

◆ operator==()

bool QTextFormatPrivate::operator== ( const QTextFormatPrivate rhs) const
inline

Definition at line 221 of file qtextformat.cpp.

221  {
222  if (hash() != rhs.hash())
223  return false;
224 
225  return props == rhs.props;
226  }
uint hash() const
QVector< Property > props

◆ property()

QVariant QTextFormatPrivate::property ( qint32  key) const
inline

Definition at line 261 of file qtextformat.cpp.

Referenced by QTextFormat::boolProperty(), QTextFormat::brushProperty(), QTextFormat::colorProperty(), QTextFormat::doubleProperty(), QTextFormat::intProperty(), QTextFormat::lengthProperty(), QTextFormat::lengthVectorProperty(), QTextFormat::objectIndex(), QTextFormat::penProperty(), QTextFormat::property(), resolveFont(), and QTextFormat::stringProperty().

262  {
263  const int idx = propertyIndex(key);
264  if (idx < 0)
265  return QVariant();
266  return props.at(idx).value;
267  }
The QVariant class acts like a union for the most common Qt data types.
Definition: qvariant.h:92
int propertyIndex(qint32 key) const
int key
QVector< Property > props

◆ propertyIndex()

int QTextFormatPrivate::propertyIndex ( qint32  key) const
inline

Definition at line 253 of file qtextformat.cpp.

Referenced by hasProperty(), and property().

254  {
255  for (int i = 0; i < props.count(); ++i)
256  if (props.at(i).key == key)
257  return i;
258  return -1;
259  }
int key
QVector< Property > props

◆ recalcFont()

void QTextFormatPrivate::recalcFont ( ) const
private

Definition at line 387 of file qtextformat.cpp.

Referenced by font(), and resolveFont().

388 {
389  // update cached font as well
390  QFont f;
391 
392  for (int i = 0; i < props.count(); ++i) {
393  switch (props.at(i).key) {
395  f.setFamily(props.at(i).value.toString());
396  break;
398  f.setPointSizeF(props.at(i).value.toReal());
399  break;
401  f.setPixelSize(props.at(i).value.toInt());
402  break;
404  int weight = props.at(i).value.toInt();
405  if (weight == 0) weight = QFont::Normal;
406  f.setWeight(weight);
407  break; }
409  f.setItalic(props.at(i).value.toBool());
410  break;
412  if (! hasProperty(QTextFormat::TextUnderlineStyle)) // don't use the old one if the new one is there.
413  f.setUnderline(props.at(i).value.toBool());
414  break;
416  f.setUnderline(static_cast<QTextCharFormat::UnderlineStyle>(props.at(i).value.toInt()) == QTextCharFormat::SingleUnderline);
417  break;
419  f.setOverline(props.at(i).value.toBool());
420  break;
422  f.setStrikeOut(props.at(i).value.toBool());
423  break;
425  f.setLetterSpacing(QFont::PercentageSpacing, props.at(i).value.toReal());
426  break;
428  f.setWordSpacing(props.at(i).value.toReal());
429  break;
431  f.setCapitalization(static_cast<QFont::Capitalization> (props.at(i).value.toInt()));
432  break;
434  const bool value = props.at(i).value.toBool();
435  if (f.fixedPitch() != value)
436  f.setFixedPitch(value);
437  break; }
439  f.setStyleHint(static_cast<QFont::StyleHint>(props.at(i).value.toInt()), f.styleStrategy());
440  break;
442  f.setHintingPreference(static_cast<QFont::HintingPreference>(props.at(i).value.toInt()));
443  break;
445  f.setStyleStrategy(static_cast<QFont::StyleStrategy>(props.at(i).value.toInt()));
446  break;
448  f.setKerning(props.at(i).value.toBool());
449  break;
450  default:
451  break;
452  }
453  }
454  fnt = f;
455  fontDirty = false;
456 }
void setWordSpacing(qreal spacing)
Sets the word spacing for the font to spacing.
Definition: qfont.cpp:1757
void setCapitalization(Capitalization)
Sets the capitalization of the text in this font to caps.
Definition: qfont.cpp:1798
void setKerning(bool)
Enables kerning for this font if enable is true; otherwise disables it.
Definition: qfont.cpp:1432
void setUnderline(bool)
If enable is true, sets underline on; otherwise sets underline off.
Definition: qfont.cpp:1331
void setItalic(bool b)
Sets the style() of the font to QFont::StyleItalic if enable is true; otherwise the style is set to Q...
Definition: qfont.h:360
void setHintingPreference(HintingPreference hintingPreference)
Set the preference for the hinting level of the glyphs to hintingPreference.
Definition: qfont.cpp:1071
void setStyleStrategy(StyleStrategy s)
Sets the style strategy for the font to s.
Definition: qfont.cpp:1578
bool hasProperty(qint32 key) const
void setFamily(const QString &)
Sets the family name of the font.
Definition: qfont.cpp:924
void setStrikeOut(bool)
If enable is true, sets strikeout on; otherwise sets strikeout off.
Definition: qfont.cpp:1378
void setStyleHint(StyleHint, StyleStrategy=PreferDefault)
Sets the style hint and strategy to hint and strategy, respectively.
Definition: qfont.cpp:1554
bool fixedPitch() const
Returns true if fixed pitch has been set; otherwise returns false.
Definition: qfont.cpp:1391
The QFont class specifies a font used for drawing text.
Definition: qfont.h:64
void setOverline(bool)
If enable is true, sets overline on; otherwise sets overline off.
Definition: qfont.cpp:1354
void setFixedPitch(bool)
If enable is true, sets fixed pitch on; otherwise sets fixed pitch off.
Definition: qfont.cpp:1402
void setWeight(int)
Sets the weight the font to weight, which should be a value from the QFont::Weight enumeration...
Definition: qfont.cpp:1278
QVector< Property > props
void setPointSizeF(qreal)
Sets the point size to pointSize.
Definition: qfont.cpp:1121
void setLetterSpacing(SpacingType type, qreal spacing)
Sets the letter spacing for the font to spacing and the type of spacing to type.
Definition: qfont.cpp:1696
StyleStrategy styleStrategy() const
Returns the StyleStrategy.
Definition: qfont.cpp:1447
void setPixelSize(int)
Sets the font size to pixelSize pixels.
Definition: qfont.cpp:1156

◆ recalcHash()

uint QTextFormatPrivate::recalcHash ( ) const
private

Definition at line 352 of file qtextformat.cpp.

Referenced by hash().

353 {
354  hashValue = 0;
355  for (QVector<Property>::ConstIterator it = props.constBegin(); it != props.constEnd(); ++it)
356  hashValue += (it->key << 16) + variantHash(it->value);
357 
358  hashDirty = false;
359 
360  return hashValue;
361 }
#define it(className, varName)
QVector< Property > props
static uint variantHash(const QVariant &variant)
const_iterator ConstIterator
Qt-style synonym for QVector::const_iterator.
Definition: qvector.h:279

◆ resolveFont()

void QTextFormatPrivate::resolveFont ( const QFont defaultFont)

Definition at line 363 of file qtextformat.cpp.

Referenced by hasProperty(), and QTextFormatCollection::indexForFormat().

364 {
365  recalcFont();
366  const uint oldMask = fnt.resolve();
367  fnt = fnt.resolve(defaultFont);
368 
370  const qreal scaleFactors[7] = {qreal(0.7), qreal(0.8), qreal(1.0), qreal(1.2), qreal(1.5), qreal(2), qreal(2.4)};
371 
372  const int htmlFontSize = qBound(0, property(QTextFormat::FontSizeAdjustment).toInt() + 3 - 1, 6);
373 
374 
375  if (defaultFont.pointSize() <= 0) {
376  qreal pixelSize = scaleFactors[htmlFontSize] * defaultFont.pixelSize();
377  fnt.setPixelSize(qRound(pixelSize));
378  } else {
379  qreal pointSize = scaleFactors[htmlFontSize] * defaultFont.pointSizeF();
380  fnt.setPointSizeF(pointSize);
381  }
382  }
383 
384  fnt.resolve(oldMask);
385 }
double qreal
Definition: qglobal.h:1193
int pixelSize() const
Returns the pixel size of the font if it was set with setPixelSize().
Definition: qfont.cpp:1178
QVariant property(qint32 key) const
bool hasProperty(qint32 key) const
void recalcFont() const
QFont resolve(const QFont &) const
Returns a new QFont that has attributes copied from other that have not been previously set on this f...
Definition: qfont.cpp:1983
qreal pointSizeF() const
Returns the point size of the font.
Definition: qfont.cpp:1142
static float pixelSize(const QFontDef &request, int dpi)
Definition: qfont_win.cpp:80
static int toInt(const QByteArray &str)
Definition: generator.cpp:167
unsigned int uint
Definition: qglobal.h:996
Q_DECL_CONSTEXPR const T & qBound(const T &min, const T &val, const T &max)
Definition: qglobal.h:1219
void setPointSizeF(qreal)
Sets the point size to pointSize.
Definition: qfont.cpp:1121
int pointSize() const
Returns the point size of the font.
Definition: qfont.cpp:981
void setPixelSize(int)
Sets the font size to pixelSize pixels.
Definition: qfont.cpp:1156
static float pointSize(const QFontDef &fd, int dpi)
Definition: qfont_win.cpp:90
Q_DECL_CONSTEXPR int qRound(qreal d)
Definition: qglobal.h:1203

Friends and Related Functions

◆ operator<<

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>>

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)
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
static const QCssKnownValue properties[NumProperties - 1]
Definition: qcssparser.cpp:67
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

Properties

◆ fnt

QFont QTextFormatPrivate::fnt
mutableprivate

Definition at line 289 of file qtextformat.cpp.

Referenced by font(), recalcFont(), and resolveFont().

◆ fontDirty

bool QTextFormatPrivate::fontDirty
mutableprivate

Definition at line 287 of file qtextformat.cpp.

Referenced by clearProperty(), font(), insertProperty(), and recalcFont().

◆ hashDirty

bool QTextFormatPrivate::hashDirty
mutableprivate

Definition at line 286 of file qtextformat.cpp.

Referenced by clearProperty(), hash(), insertProperty(), and recalcHash().

◆ hashValue

uint QTextFormatPrivate::hashValue
mutableprivate

Definition at line 288 of file qtextformat.cpp.

Referenced by hash(), and recalcHash().

◆ props

QVector<Property> QTextFormatPrivate::props

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