diff options
Diffstat (limited to 'src/gui/text/qtextformat.cpp')
-rw-r--r-- | src/gui/text/qtextformat.cpp | 111 |
1 files changed, 68 insertions, 43 deletions
diff --git a/src/gui/text/qtextformat.cpp b/src/gui/text/qtextformat.cpp index be38aba368..daa79a55d2 100644 --- a/src/gui/text/qtextformat.cpp +++ b/src/gui/text/qtextformat.cpp @@ -168,7 +168,7 @@ public: if (key >= QTextFormat::FirstFontProperty && key <= QTextFormat::LastFontProperty) fontDirty = true; - for (int i = 0; i < props.count(); ++i) + for (int i = 0; i < props.size(); ++i) if (props.at(i).key == key) { props[i].value = value; return; @@ -178,7 +178,7 @@ public: inline void clearProperty(qint32 key) { - for (int i = 0; i < props.count(); ++i) + for (int i = 0; i < props.size(); ++i) if (props.at(i).key == key) { hashDirty = true; if (key >= QTextFormat::FirstFontProperty && key <= QTextFormat::LastFontProperty) @@ -190,7 +190,7 @@ public: inline int propertyIndex(qint32 key) const { - for (int i = 0; i < props.count(); ++i) + for (int i = 0; i < props.size(); ++i) if (props.at(i).key == key) return i; return -1; @@ -257,7 +257,7 @@ static inline size_t variantHash(const QVariant &variant) case QMetaType::Bool: return 0x371818 + variant.toBool(); case QMetaType::QPen: return 0x02020202 + hash(qvariant_cast<QPen>(variant)); case QMetaType::QVariantList: - return 0x8377U + qvariant_cast<QVariantList>(variant).count(); + return 0x8377U + qvariant_cast<QVariantList>(variant).size(); case QMetaType::QColor: return hash(qvariant_cast<QColor>(variant)); case QMetaType::QTextLength: return 0x377 + hash(qvariant_cast<QTextLength>(variant).rawValue()); @@ -318,7 +318,7 @@ void QTextFormatPrivate::recalcFont() const QFont::SpacingType spacingType = QFont::PercentageSpacing; qreal letterSpacing = 0.0; - for (int i = 0; i < props.count(); ++i) { + for (int i = 0; i < props.size(); ++i) { switch (props.at(i).key) { case QTextFormat::FontFamilies: f.setFamilies(props.at(i).value.toStringList()); @@ -405,27 +405,27 @@ Q_GUI_EXPORT QDataStream &operator<<(QDataStream &stream, const QTextFormat &fmt { QMap<int, QVariant> properties = fmt.properties(); if (stream.version() < QDataStream::Qt_6_0) { - auto it = properties.find(QTextFormat::FontLetterSpacingType); - if (it != properties.end()) { + auto it = properties.constFind(QTextFormat::FontLetterSpacingType); + if (it != properties.cend()) { properties[QTextFormat::OldFontLetterSpacingType] = it.value(); properties.erase(it); } - it = properties.find(QTextFormat::FontStretch); - if (it != properties.end()) { + it = properties.constFind(QTextFormat::FontStretch); + if (it != properties.cend()) { properties[QTextFormat::OldFontStretch] = it.value(); properties.erase(it); } - it = properties.find(QTextFormat::TextUnderlineColor); - if (it != properties.end()) { + it = properties.constFind(QTextFormat::TextUnderlineColor); + if (it != properties.cend()) { properties[QTextFormat::OldTextUnderlineColor] = it.value(); properties.erase(it); } - it = properties.find(QTextFormat::FontFamilies); - if (it != properties.end()) { - properties[QTextFormat::OldFontFamily] = QVariant(it.value().toStringList().first()); + it = properties.constFind(QTextFormat::FontFamilies); + if (it != properties.cend()) { + properties[QTextFormat::OldFontFamily] = QVariant(it.value().toStringList().constFirst()); properties.erase(it); } } @@ -684,6 +684,8 @@ Q_GUI_EXPORT QDataStream &operator>>(QDataStream &stream, QTextTableCellFormat & numeric lists. \value ListNumberSuffix Defines the text which is appended to item numbers in numeric lists. + \value [since 6.6] ListStart + Defines the first value of a list. Table and frame properties @@ -951,9 +953,13 @@ void QTextFormat::merge(const QTextFormat &other) const QList<QT_PREPEND_NAMESPACE(Property)> &otherProps = other.d.constData()->props; p->props.reserve(p->props.size() + otherProps.size()); - for (int i = 0; i < otherProps.count(); ++i) { + for (int i = 0; i < otherProps.size(); ++i) { const QT_PREPEND_NAMESPACE(Property) &prop = otherProps.at(i); - p->insertProperty(prop.key, prop.value); + if (prop.value.isValid()) { + p->insertProperty(prop.key, prop.value); + } else { + p->clearProperty(prop.key); + } } } @@ -1210,10 +1216,8 @@ void QTextFormat::setProperty(int propertyId, const QVariant &value) { if (!d) d = new QTextFormatPrivate; - if (!value.isValid()) - clearProperty(propertyId); - else - d->insertProperty(propertyId, value); + + d->insertProperty(propertyId, value); } /*! @@ -1323,7 +1327,7 @@ QMap<int, QVariant> QTextFormat::properties() const { QMap<int, QVariant> map; if (d) { - for (int i = 0; i < d->props.count(); ++i) + for (int i = 0; i < d->props.size(); ++i) map.insert(d->props.at(i).key, d->props.at(i).value); } return map; @@ -1335,7 +1339,7 @@ QMap<int, QVariant> QTextFormat::properties() const */ int QTextFormat::propertyCount() const { - return d ? d->props.count() : 0; + return d ? d->props.size() : 0; } /*! @@ -2167,7 +2171,7 @@ QFont QTextCharFormat::font() const associated QTextBlockFormat that specifies its characteristics. To cater for left-to-right and right-to-left languages you can set - a block's direction with setDirection(). Paragraph alignment is + a block's direction with setLayoutDirection(). Paragraph alignment is set with setAlignment(). Margins are controlled by setTopMargin(), setBottomMargin(), setLeftMargin(), setRightMargin(). Overall indentation is set with setIndent(), the indentation of the first @@ -2237,14 +2241,9 @@ QTextBlockFormat::QTextBlockFormat(const QTextFormat &fmt) void QTextBlockFormat::setTabPositions(const QList<QTextOption::Tab> &tabs) { QList<QVariant> list; - list.reserve(tabs.count()); - QList<QTextOption::Tab>::ConstIterator iter = tabs.constBegin(); - while (iter != tabs.constEnd()) { - QVariant v; - v.setValue(*iter); - list.append(v); - ++iter; - } + list.reserve(tabs.size()); + for (const auto &e : tabs) + list.append(QVariant::fromValue(e)); setProperty(TabPositions, list); } @@ -2260,13 +2259,10 @@ QList<QTextOption::Tab> QTextBlockFormat::tabPositions() const if (variant.isNull()) return QList<QTextOption::Tab>(); QList<QTextOption::Tab> answer; - QList<QVariant> variantsList = qvariant_cast<QList<QVariant> >(variant); - QList<QVariant>::Iterator iter = variantsList.begin(); - answer.reserve(variantsList.count()); - while(iter != variantsList.end()) { - answer.append( qvariant_cast<QTextOption::Tab>(*iter)); - ++iter; - } + const QList<QVariant> variantsList = qvariant_cast<QList<QVariant> >(variant); + answer.reserve(variantsList.size()); + for (const auto &e: variantsList) + answer.append(qvariant_cast<QTextOption::Tab>(e)); return answer; } @@ -2610,7 +2606,8 @@ QList<QTextOption::Tab> QTextBlockFormat::tabPositions() const The style used to decorate each item is set with setStyle() and can be read with the style() function. The style controls the type of bullet points and numbering scheme used for items in the list. Note that lists that use the - decimal numbering scheme begin counting at 1 rather than 0. + decimal numbering scheme begin counting at 1 rather than 0, unless it has + been overridden via setStart(). Style properties can be set to further configure the appearance of list items; for example, the ListNumberPrefix and ListNumberSuffix properties @@ -2647,6 +2644,7 @@ QTextListFormat::QTextListFormat() : QTextFormat(ListFormat) { setIndent(1); + setStart(1); } /*! @@ -2751,6 +2749,32 @@ QTextListFormat::QTextListFormat(const QTextFormat &fmt) */ /*! + \fn void QTextListFormat::setStart(int start) + \since 6.6 + + Sets the list format's \a start index. + + This allows you to start a list with an index other than 1. This can be + used with all sorted list types: for example if the style() is + QTextListFormat::ListLowerAlpha and start() is \c 4, the first list item + begins with "d". It does not have any effect on unsorted list types. + + The default start is \c 1. + + \sa start() +*/ + +/*! + \fn int QTextListFormat::start() const + \since 6.6 + + Returns the number to be shown by the first list item, if the style() is + QTextListFormat::ListDecimal, or to offset other sorted list types. + + \sa setStart() +*/ + +/*! \class QTextFrameFormat \reentrant @@ -3132,7 +3156,8 @@ QTextTableFormat::QTextTableFormat() : QTextFrameFormat() { setObjectType(TableObject); - setCellSpacing(2); + setCellPadding(4); + setBorderCollapse(true); setBorder(1); } @@ -3969,7 +3994,7 @@ bool QTextFormatCollection::hasFormatCached(const QTextFormat &format) const int QTextFormatCollection::objectFormatIndex(int objectIndex) const { - if (objectIndex == -1) + if (objectIndex == -1 || objectIndex >= objFormats.size()) return -1; return objFormats.at(objectIndex); } @@ -3988,7 +4013,7 @@ int QTextFormatCollection::createObjectIndex(const QTextFormat &f) QTextFormat QTextFormatCollection::format(int idx) const { - if (idx < 0 || idx >= formats.count()) + if (idx < 0 || idx >= formats.size()) return QTextFormat(); return formats.at(idx); @@ -3997,7 +4022,7 @@ QTextFormat QTextFormatCollection::format(int idx) const void QTextFormatCollection::setDefaultFont(const QFont &f) { defaultFnt = f; - for (int i = 0; i < formats.count(); ++i) + for (int i = 0; i < formats.size(); ++i) if (formats.at(i).d) formats[i].d->resolveFont(defaultFnt); } |