本文整理汇总了C++中QTextFormat::merge方法的典型用法代码示例。如果您正苦于以下问题:C++ QTextFormat::merge方法的具体用法?C++ QTextFormat::merge怎么用?C++ QTextFormat::merge使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QTextFormat
的用法示例。
在下文中一共展示了QTextFormat::merge方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: setCharFormat
void QTextDocumentPrivate::setCharFormat(int pos, int length, const QTextCharFormat &newFormat, FormatChangeMode mode)
{
beginEditBlock();
Q_ASSERT(newFormat.isValid());
int newFormatIdx = -1;
if (mode == SetFormatAndPreserveObjectIndices) {
QTextCharFormat cleanFormat = newFormat;
cleanFormat.clearProperty(QTextFormat::ObjectIndex);
newFormatIdx = formats.indexForFormat(cleanFormat);
} else if (mode == SetFormat) {
newFormatIdx = formats.indexForFormat(newFormat);
}
if (pos == -1) {
if (mode == MergeFormat) {
QTextFormat format = formats.format(initialBlockCharFormatIndex);
format.merge(newFormat);
initialBlockCharFormatIndex = formats.indexForFormat(format);
} else if (mode == SetFormatAndPreserveObjectIndices
&& formats.format(initialBlockCharFormatIndex).objectIndex() != -1) {
QTextCharFormat f = newFormat;
f.setObjectIndex(formats.format(initialBlockCharFormatIndex).objectIndex());
initialBlockCharFormatIndex = formats.indexForFormat(f);
} else {
initialBlockCharFormatIndex = newFormatIdx;
}
++pos;
--length;
}
const int startPos = pos;
const int endPos = pos + length;
split(startPos);
split(endPos);
while (pos < endPos) {
FragmentMap::Iterator it = fragments.find(pos);
Q_ASSERT(!it.atEnd());
QTextFragmentData *fragment = it.value();
Q_ASSERT(formats.format(fragment->format).type() == QTextFormat::CharFormat);
int offset = pos - it.position();
int length = qMin(endPos - pos, int(fragment->size - offset));
int oldFormat = fragment->format;
if (mode == MergeFormat) {
QTextFormat format = formats.format(fragment->format);
format.merge(newFormat);
fragment->format = formats.indexForFormat(format);
} else if (mode == SetFormatAndPreserveObjectIndices
&& formats.format(oldFormat).objectIndex() != -1) {
QTextCharFormat f = newFormat;
f.setObjectIndex(formats.format(oldFormat).objectIndex());
fragment->format = formats.indexForFormat(f);
} else {
fragment->format = newFormatIdx;
}
QTextUndoCommand c = { QTextUndoCommand::CharFormatChanged, true, QTextUndoCommand::MoveCursor, oldFormat,
0, pos, { length }, 0 };
appendUndoItem(c);
pos += length;
Q_ASSERT(pos == (int)(it.position() + fragment->size) || pos >= endPos);
}
int n = fragments.findNode(startPos - 1);
if (n)
unite(n);
n = fragments.findNode(endPos);
if (n)
unite(n);
QTextBlock blockIt = blocksFind(startPos);
QTextBlock endIt = blocksFind(endPos);
if (endIt.isValid())
endIt = endIt.next();
for (; blockIt.isValid() && blockIt != endIt; blockIt = blockIt.next())
QTextDocumentPrivate::block(blockIt)->invalidate();
documentChange(startPos, length);
endEditBlock();
}