Make QTextBlockFormat::MarkerType an enum class

This came up during API review.

Change-Id: I9198e1eb96db0c21e46a226a032919bb62d3ca66
Reviewed-by: Giuseppe D'Angelo <giuseppe.dangelo@kdab.com>
This commit is contained in:
Shawn Rutledge 2019-10-02 12:19:11 +02:00
parent a6ece9e88a
commit f1dd6addda
10 changed files with 22 additions and 22 deletions

View File

@ -640,7 +640,7 @@ void TextEdit::textStyle(int styleIndex)
{ {
QTextCursor cursor = textEdit->textCursor(); QTextCursor cursor = textEdit->textCursor();
QTextListFormat::Style style = QTextListFormat::ListStyleUndefined; QTextListFormat::Style style = QTextListFormat::ListStyleUndefined;
QTextBlockFormat::MarkerType marker = QTextBlockFormat::NoMarker; QTextBlockFormat::MarkerType marker = QTextBlockFormat::MarkerType::NoMarker;
switch (styleIndex) { switch (styleIndex) {
case 1: case 1:
@ -657,14 +657,14 @@ void TextEdit::textStyle(int styleIndex)
style = cursor.currentList()->format().style(); style = cursor.currentList()->format().style();
else else
style = QTextListFormat::ListDisc; style = QTextListFormat::ListDisc;
marker = QTextBlockFormat::Unchecked; marker = QTextBlockFormat::MarkerType::Unchecked;
break; break;
case 5: case 5:
if (cursor.currentList()) if (cursor.currentList())
style = cursor.currentList()->format().style(); style = cursor.currentList()->format().style();
else else
style = QTextListFormat::ListDisc; style = QTextListFormat::ListDisc;
marker = QTextBlockFormat::Checked; marker = QTextBlockFormat::MarkerType::Checked;
break; break;
case 6: case 6:
style = QTextListFormat::ListDecimal; style = QTextListFormat::ListDecimal;
@ -823,14 +823,14 @@ void TextEdit::cursorPositionChanged()
break; break;
} }
switch (textEdit->textCursor().block().blockFormat().marker()) { switch (textEdit->textCursor().block().blockFormat().marker()) {
case QTextBlockFormat::NoMarker: case QTextBlockFormat::MarkerType::NoMarker:
actionToggleCheckState->setChecked(false); actionToggleCheckState->setChecked(false);
break; break;
case QTextBlockFormat::Unchecked: case QTextBlockFormat::MarkerType::Unchecked:
comboStyle->setCurrentIndex(4); comboStyle->setCurrentIndex(4);
actionToggleCheckState->setChecked(false); actionToggleCheckState->setChecked(false);
break; break;
case QTextBlockFormat::Checked: case QTextBlockFormat::MarkerType::Checked:
comboStyle->setCurrentIndex(5); comboStyle->setCurrentIndex(5);
actionToggleCheckState->setChecked(true); actionToggleCheckState->setChecked(true);
break; break;

View File

@ -660,7 +660,7 @@ QTextBlock QAbstractTextDocumentLayout::blockWithMarkerAt(const QPointF &pos) co
{ {
QTextBlock block = document()->firstBlock(); QTextBlock block = document()->firstBlock();
while (block.isValid()) { while (block.isValid()) {
if (block.blockFormat().marker() != QTextBlockFormat::NoMarker) { if (block.blockFormat().marker() != QTextBlockFormat::MarkerType::NoMarker) {
QRectF blockBr = blockBoundingRect(block); QRectF blockBr = blockBoundingRect(block);
QTextBlockFormat blockFmt = block.blockFormat(); QTextBlockFormat blockFmt = block.blockFormat();
QFontMetrics fm(block.charFormat().font()); QFontMetrics fm(block.charFormat().font());

View File

@ -2194,11 +2194,11 @@ void QTextDocumentLayoutPrivate::drawListItem(const QPointF &offset, QPainter *p
QBrush brush = context.palette.brush(QPalette::Text); QBrush brush = context.palette.brush(QPalette::Text);
bool marker = bl.blockFormat().marker() != QTextBlockFormat::NoMarker; bool marker = bl.blockFormat().marker() != QTextBlockFormat::MarkerType::NoMarker;
if (marker) { if (marker) {
int adj = fontMetrics.lineSpacing() / 6; int adj = fontMetrics.lineSpacing() / 6;
r.adjust(-adj, 0, -adj, 0); r.adjust(-adj, 0, -adj, 0);
if (bl.blockFormat().marker() == QTextBlockFormat::Checked) { if (bl.blockFormat().marker() == QTextBlockFormat::MarkerType::Checked) {
// ### Qt6: render with QStyle / PE_IndicatorCheckBox. We don't currently // ### Qt6: render with QStyle / PE_IndicatorCheckBox. We don't currently
// have access to that here, because it would be a widget dependency. // have access to that here, because it would be a widget dependency.
painter->setPen(QPen(painter->pen().color(), 2)); painter->setPen(QPen(painter->pen().color(), 2));

View File

@ -627,7 +627,7 @@ public:
LineDistanceHeight = 4 LineDistanceHeight = 4
}; };
enum MarkerType { enum class MarkerType {
NoMarker = 0, NoMarker = 0,
Unchecked = 1, Unchecked = 1,
Checked = 2 Checked = 2

View File

@ -190,8 +190,8 @@ int QTextMarkdownImporter::cbEnterBlock(int blockType, void *det)
m_listItem = true; m_listItem = true;
MD_BLOCK_LI_DETAIL *detail = static_cast<MD_BLOCK_LI_DETAIL *>(det); MD_BLOCK_LI_DETAIL *detail = static_cast<MD_BLOCK_LI_DETAIL *>(det);
m_markerType = detail->is_task ? m_markerType = detail->is_task ?
(detail->task_mark == ' ' ? QTextBlockFormat::Unchecked : QTextBlockFormat::Checked) : (detail->task_mark == ' ' ? QTextBlockFormat::MarkerType::Unchecked : QTextBlockFormat::MarkerType::Checked) :
QTextBlockFormat::NoMarker; QTextBlockFormat::MarkerType::NoMarker;
qCDebug(lcMD) << "LI"; qCDebug(lcMD) << "LI";
} break; } break;
case MD_BLOCK_UL: { case MD_BLOCK_UL: {
@ -549,7 +549,7 @@ void QTextMarkdownImporter::insertBlock()
blockFormat.setTopMargin(m_paragraphMargin); blockFormat.setTopMargin(m_paragraphMargin);
blockFormat.setBottomMargin(m_paragraphMargin); blockFormat.setBottomMargin(m_paragraphMargin);
} }
if (m_markerType == QTextBlockFormat::NoMarker) if (m_markerType == QTextBlockFormat::MarkerType::NoMarker)
blockFormat.clearProperty(QTextFormat::BlockMarker); blockFormat.clearProperty(QTextFormat::BlockMarker);
else else
blockFormat.setMarker(m_markerType); blockFormat.setMarker(m_markerType);

View File

@ -128,7 +128,7 @@ private:
Features m_features; Features m_features;
QTextImageFormat m_imageFormat; QTextImageFormat m_imageFormat;
QTextListFormat m_listFormat; QTextListFormat m_listFormat;
QTextBlockFormat::MarkerType m_markerType = QTextBlockFormat::NoMarker; QTextBlockFormat::MarkerType m_markerType = QTextBlockFormat::MarkerType::NoMarker;
bool m_needsInsertBlock = false; bool m_needsInsertBlock = false;
bool m_needsInsertList = false; bool m_needsInsertList = false;
bool m_listItem = false; // true from the beginning of LI to the end of the first P bool m_listItem = false; // true from the beginning of LI to the end of the first P

View File

@ -327,10 +327,10 @@ int QTextMarkdownWriter::writeBlock(const QTextBlock &block, bool wrap, bool ign
break; break;
} }
switch (blockFmt.marker()) { switch (blockFmt.marker()) {
case QTextBlockFormat::Checked: case QTextBlockFormat::MarkerType::Checked:
bullet += " [x]"; bullet += " [x]";
break; break;
case QTextBlockFormat::Unchecked: case QTextBlockFormat::MarkerType::Unchecked:
bullet += " [ ]"; bullet += " [ ]";
break; break;
default: default:

View File

@ -237,7 +237,7 @@ void QTextEditPrivate::_q_hoveredBlockWithMarkerChanged(const QTextBlock &block)
Qt::CursorShape cursor = cursorToRestoreAfterHover; Qt::CursorShape cursor = cursorToRestoreAfterHover;
if (block.isValid() && !q->isReadOnly()) { if (block.isValid() && !q->isReadOnly()) {
QTextBlockFormat::MarkerType marker = block.blockFormat().marker(); QTextBlockFormat::MarkerType marker = block.blockFormat().marker();
if (marker != QTextBlockFormat::NoMarker) { if (marker != QTextBlockFormat::MarkerType::NoMarker) {
if (viewport->cursor().shape() != Qt::PointingHandCursor) if (viewport->cursor().shape() != Qt::PointingHandCursor)
cursorToRestoreAfterHover = viewport->cursor().shape(); cursorToRestoreAfterHover = viewport->cursor().shape();
cursor = Qt::PointingHandCursor; cursor = Qt::PointingHandCursor;

View File

@ -1810,11 +1810,11 @@ void QWidgetTextControlPrivate::mouseReleaseEvent(QEvent *e, Qt::MouseButton but
if (markerBlock == blockWithMarkerUnderMouse) { if (markerBlock == blockWithMarkerUnderMouse) {
auto fmt = blockWithMarkerUnderMouse.blockFormat(); auto fmt = blockWithMarkerUnderMouse.blockFormat();
switch (fmt.marker()) { switch (fmt.marker()) {
case QTextBlockFormat::Unchecked : case QTextBlockFormat::MarkerType::Unchecked :
fmt.setMarker(QTextBlockFormat::Checked); fmt.setMarker(QTextBlockFormat::MarkerType::Checked);
break; break;
case QTextBlockFormat::Checked: case QTextBlockFormat::MarkerType::Checked:
fmt.setMarker(QTextBlockFormat::Unchecked); fmt.setMarker(QTextBlockFormat::MarkerType::Unchecked);
break; break;
default: default:
break; break;

View File

@ -159,7 +159,7 @@ void tst_QTextMarkdownWriter::testWriteNestedBulletLists()
QTextCursor cursor(document); QTextCursor cursor(document);
QTextBlockFormat blockFmt = cursor.blockFormat(); QTextBlockFormat blockFmt = cursor.blockFormat();
if (checkbox) { if (checkbox) {
blockFmt.setMarker(checked ? QTextBlockFormat::Checked : QTextBlockFormat::Unchecked); blockFmt.setMarker(checked ? QTextBlockFormat::MarkerType::Checked : QTextBlockFormat::MarkerType::Unchecked);
cursor.setBlockFormat(blockFmt); cursor.setBlockFormat(blockFmt);
} }