diff options
Diffstat (limited to 'src/gui/text/qtextformat.cpp')
-rw-r--r-- | src/gui/text/qtextformat.cpp | 76 |
1 files changed, 45 insertions, 31 deletions
diff --git a/src/gui/text/qtextformat.cpp b/src/gui/text/qtextformat.cpp index ec91236f55..dacef70812 100644 --- a/src/gui/text/qtextformat.cpp +++ b/src/gui/text/qtextformat.cpp @@ -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); } } @@ -745,6 +745,7 @@ Q_GUI_EXPORT QDataStream &operator>>(QDataStream &stream, QTextTableCellFormat & \value ImageWidth \value ImageHeight \value ImageQuality + \value ImageMaxWidth This enum value has been added in Qt 6.8. Selection properties @@ -955,7 +956,11 @@ void QTextFormat::merge(const QTextFormat &other) p->props.reserve(p->props.size() + otherProps.size()); 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); + } } } @@ -1212,10 +1217,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); } /*! @@ -2169,7 +2172,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 @@ -2240,13 +2243,8 @@ void QTextBlockFormat::setTabPositions(const QList<QTextOption::Tab> &tabs) { QList<QVariant> list; list.reserve(tabs.size()); - QList<QTextOption::Tab>::ConstIterator iter = tabs.constBegin(); - while (iter != tabs.constEnd()) { - QVariant v; - v.setValue(*iter); - list.append(v); - ++iter; - } + for (const auto &e : tabs) + list.append(QVariant::fromValue(e)); setProperty(TabPositions, list); } @@ -2262,13 +2260,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(); + const QList<QVariant> variantsList = qvariant_cast<QList<QVariant> >(variant); answer.reserve(variantsList.size()); - while(iter != variantsList.end()) { - answer.append( qvariant_cast<QTextOption::Tab>(*iter)); - ++iter; - } + for (const auto &e: variantsList) + answer.append(qvariant_cast<QTextOption::Tab>(e)); return answer; } @@ -3162,7 +3157,8 @@ QTextTableFormat::QTextTableFormat() : QTextFrameFormat() { setObjectType(TableObject); - setCellSpacing(2); + setCellPadding(4); + setBorderCollapse(true); setBorder(1); } @@ -3431,7 +3427,7 @@ QTextImageFormat::QTextImageFormat(const QTextFormat &fmt) Sets the \a width of the rectangle occupied by the image. - \sa width(), setHeight() + \sa width(), setHeight(), maximumWidth() */ @@ -3443,6 +3439,24 @@ QTextImageFormat::QTextImageFormat(const QTextFormat &fmt) \sa height(), setWidth() */ +/*! + \fn void QTextImageFormat::setMaximumWidth(QTextLength maximumWidth) + + Sets the \a maximumWidth of the rectangle occupied by the image. This + can be an absolute number or a percentage of the available document size. + + \sa width(), setHeight() +*/ + + +/*! + \fn QTextLength QTextImageFormat::maximumWidth() const + + Returns the maximum width of the rectangle occupied by the image. + + \sa width(), setMaximumWidth() +*/ + /*! \fn void QTextImageFormat::setHeight(qreal height) @@ -3999,7 +4013,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); } |