remove redundant Qt::TextFlag::TextExpandTabs enum [ci reset]

Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
This commit is contained in:
Ivailo Monev 2022-01-06 00:56:51 +02:00
parent e1c119fa00
commit 1a98081e34
8 changed files with 41 additions and 183 deletions

View file

@ -687,17 +687,16 @@ public:
enum TextFlag {
TextSingleLine = 0x0100,
TextDontClip = 0x0200,
TextExpandTabs = 0x0400,
TextShowMnemonic = 0x0800,
TextWordWrap = 0x1000,
TextWrapAnywhere = 0x2000,
TextDontPrint = 0x4000,
TextIncludeTrailingSpaces = 0x08000000,
TextHideMnemonic = 0x8000,
TextJustificationForced = 0x10000,
TextForceLeftToRight = 0x20000,
TextForceRightToLeft = 0x40000,
TextLongestVariant = 0x80000
TextShowMnemonic = 0x0400,
TextWordWrap = 0x0800,
TextWrapAnywhere = 0x1000,
TextDontPrint = 0x2000,
TextHideMnemonic = 0x4000,
TextJustificationForced = 0x8000,
TextForceLeftToRight = 0x10000,
TextForceRightToLeft = 0x20000,
TextLongestVariant = 0x40000,
TextIncludeTrailingSpaces = 0x08000000
};
enum TextElideMode {

View file

@ -340,8 +340,6 @@
one line.
\value TextDontClip If it's impossible to stay within the given bounds,
it prints outside.
\value TextExpandTabs Makes the U+0009 (ASCII tab) character move to
the next tab stop.
\value TextShowMnemonic Displays the string "\&P" as \underline{P}
(see QButton for an example). For an ampersand, use "\&\&".
\value TextWordWrap Breaks lines at appropriate points, e.g. at word

View file

@ -194,7 +194,7 @@ QWhatsThat::QWhatsThat(const QString& txt, QWidget* parent, QWidget *showTextFor
r = fontMetrics().boundingRect(0, 0, sw, 1000,
Qt::AlignLeft + Qt::AlignTop
+ Qt::TextWordWrap + Qt::TextExpandTabs,
+ Qt::TextWordWrap,
text);
}
resize(r.width() + 2*hMargin + shadowWidth, r.height() + 2*vMargin + shadowWidth);
@ -306,7 +306,7 @@ void QWhatsThat::paintEvent(QPaintEvent*)
}
else
{
p.drawText(r, Qt::AlignLeft + Qt::AlignTop + Qt::TextWordWrap + Qt::TextExpandTabs, text);
p.drawText(r, Qt::AlignLeft + Qt::AlignTop + Qt::TextWordWrap, text);
}
}

View file

@ -47,10 +47,8 @@ QT_BEGIN_NAMESPACE
// #define QT_DEBUG_DRAW
void qt_format_text(const QFont &font,
const QRectF &_r, int tf, const QTextOption *option, const QString& str, QRectF *brect,
int tabstops, int* tabarray, int tabarraylen,
QPainter *painter);
void qt_format_text(const QFont &font, const QRectF &_r, int tf, const QTextOption *option,
const QString& str, QRectF *brect, QPainter *painter);
static void drawTextItemDecoration(QPainter *painter, const QPointF &pos, const QFontEngine *fe,
QTextCharFormat::UnderlineStyle underlineStyle,
QTextItem::RenderFlags flags, qreal width,
@ -4785,7 +4783,7 @@ void QPainter::drawText(const QRect &r, int flags, const QString &str, QRect *br
d->updateState(d->state);
QRectF bounds;
qt_format_text(d->state->font, r, flags, 0, str, br ? &bounds : 0, 0, 0, 0, this);
qt_format_text(d->state->font, r, flags, 0, str, br ? &bounds : nullptr, this);
if (br)
*br = bounds.toAlignedRect();
}
@ -4832,7 +4830,6 @@ void QPainter::drawText(const QRect &r, int flags, const QString &str, QRect *br
\o Qt::AlignCenter
\o Qt::TextDontClip
\o Qt::TextSingleLine
\o Qt::TextExpandTabs
\o Qt::TextShowMnemonic
\o Qt::TextWordWrap
\o Qt::TextIncludeTrailingSpaces
@ -4859,7 +4856,7 @@ void QPainter::drawText(const QRectF &r, int flags, const QString &str, QRectF *
if (!d->extended)
d->updateState(d->state);
qt_format_text(d->state->font, r, flags, 0, str, br, 0, 0, 0, this);
qt_format_text(d->state->font, r, flags, 0, str, br, this);
}
/*!
@ -4912,7 +4909,6 @@ void QPainter::drawText(const QRectF &r, int flags, const QString &str, QRectF *
\o Qt::AlignVCenter
\o Qt::AlignCenter
\o Qt::TextSingleLine
\o Qt::TextExpandTabs
\o Qt::TextShowMnemonic
\o Qt::TextWordWrap
\endlist
@ -4951,7 +4947,7 @@ void QPainter::drawText(const QRectF &r, const QString &text, const QTextOption
if (!d->extended)
d->updateState(d->state);
qt_format_text(d->state->font, r, 0, &o, text, 0, 0, 0, 0, this);
qt_format_text(d->state->font, r, 0, &o, text, nullptr, this);
}
/*!
@ -5223,7 +5219,6 @@ void QPainter::drawTextItem(const QPointF &p, const QTextItem &_ti)
\o Qt::AlignVCenter
\o Qt::AlignCenter
\o Qt::TextSingleLine
\o Qt::TextExpandTabs
\o Qt::TextShowMnemonic
\o Qt::TextWordWrap
\o Qt::TextIncludeTrailingSpaces
@ -5296,7 +5291,7 @@ QRectF QPainter::boundingRect(const QRectF &r, const QString &text, const QTextO
return QRectF(r.x(),r.y(), 0,0);
QRectF br;
qt_format_text(d->state->font, r, Qt::TextDontPrint, &o, text, &br, 0, 0, 0, this);
qt_format_text(d->state->font, r, Qt::TextDontPrint, &o, text, &br, this);
return br;
}
@ -5915,17 +5910,12 @@ void QPainter::setViewTransformEnabled(bool enable)
}
void qt_format_text(const QFont &fnt, const QRectF &_r,
int tf, const QString& str, QRectF *brect,
int tabstops, int *ta, int tabarraylen)
int tf, const QString& str, QRectF *brect)
{
qt_format_text(fnt, _r,
tf, 0, str, brect,
tabstops, ta, tabarraylen,
nullptr);
qt_format_text(fnt, _r, tf, nullptr, str, brect, nullptr);
}
void qt_format_text(const QFont &fnt, const QRectF &_r,
int tf, const QTextOption *option, const QString& str, QRectF *brect,
int tabstops, int *ta, int tabarraylen,
QPainter *painter)
{
Q_ASSERT(!((tf & ~Qt::TextDontPrint) != 0 && option != 0) ); // we either have an option or flags
@ -5937,9 +5927,6 @@ void qt_format_text(const QFont &fnt, const QRectF &_r,
if (option->flags() & QTextOption::IncludeTrailingSpaces)
tf |= Qt::TextIncludeTrailingSpaces;
if (option->tabStop() >= 0 || !option->tabArray().isEmpty())
tf |= Qt::TextExpandTabs;
}
// we need to copy r here to protect against the case (&r == brect).
@ -5965,10 +5952,7 @@ void qt_format_text(const QFont &fnt, const QRectF &_r,
tf = QStyle::visualAlignment(layout_direction, QFlag(tf));
bool isRightToLeft = layout_direction == Qt::RightToLeft;
bool expandtabs = ((tf & Qt::TextExpandTabs) &&
(((tf & Qt::AlignLeft) && !isRightToLeft) ||
((tf & Qt::AlignRight) && isRightToLeft)));
bool isRightToLeft = (layout_direction == Qt::RightToLeft);
if (!painter)
tf |= Qt::TextDontPrint;
@ -5982,23 +5966,16 @@ void qt_format_text(const QFont &fnt, const QRectF &_r,
int offset = 0;
start_lengthVariant:
bool hasMoreLengthVariants = false;
// compatible behaviour to the old implementation. Replace
// tabs by spaces
int old_offset = offset;
for (; offset < text.length(); offset++) {
QChar chr = text.at(offset);
// replace tabs with spaces for compatibility
if (chr == QLatin1Char('\r') || (singleline && chr == QLatin1Char('\n'))) {
text[offset] = QLatin1Char(' ');
} else if (chr == QLatin1Char('\n')) {
text[offset] = QChar::LineSeparator;
} else if (chr == QLatin1Char('&')) {
++maxUnderlines;
} else if (chr == QLatin1Char('\t')) {
if (!expandtabs) {
text[offset] = QLatin1Char(' ');
} else if (!tabarraylen && !tabstops) {
tabstops = qRound(fm.width(QLatin1Char('x'))*8);
}
} else if (chr == QChar(ushort(0x9c))) {
// string with multiple length variants
hasMoreLengthVariants = true;
@ -6045,16 +6022,6 @@ start_lengthVariant:
textoption = *option;
}
if (textoption.tabStop() < 0 && tabstops > 0)
textoption.setTabStop(tabstops);
if (textoption.tabs().isEmpty() && ta) {
QList<qreal> tabs;
for (int i = 0; i < tabarraylen; i++)
tabs.append(qreal(ta[i]));
textoption.setTabArray(tabs);
}
textoption.setTextDirection(layout_direction);
if (tf & Qt::AlignJustify)
textoption.setAlignment(Qt::AlignJustify);

View file

@ -40,8 +40,7 @@ extern const QX11Info *qt_x11Info(const QPaintDevice *pd);
#endif
extern void qt_format_text(const QFont& font, const QRectF &_r,
int tf, const QString &text, QRectF *brect,
int tabStops, int *tabArray, int tabArrayLen);
int tf, const QString &text, QRectF *brect);
/*****************************************************************************
QFontMetrics member functions
@ -113,17 +112,12 @@ extern void qt_format_text(const QFont& font, const QRectF &_r,
/*!
\fn QRect QFontMetrics::boundingRect(int x, int y, int width, int height,
int flags, const QString &text, int tabStops, int *tabArray) const
int flags, const QString &text) const
\overload
Returns the bounding rectangle for the given \a text within the
rectangle specified by the \a x and \a y coordinates, \a width, and
\a height.
If Qt::TextExpandTabs is set in \a flags and \a tabArray is
non-null, it specifies a 0-terminated sequence of pixel-positions
for tabs; otherwise, if \a tabStops is non-zero, it is used as the
tab spacing (in pixels).
*/
/*!
@ -560,7 +554,6 @@ QRect QFontMetrics::boundingRect(QChar ch) const
\o Qt::AlignVCenter aligns vertically centered
\o Qt::AlignCenter (== \c{Qt::AlignHCenter | Qt::AlignVCenter})
\o Qt::TextSingleLine ignores newline characters in the text.
\o Qt::TextExpandTabs expands tabs (see below)
\o Qt::TextShowMnemonic interprets "&x" as \underline{x}; i.e., underlined.
\o Qt::TextWordWrap breaks the text to fit the rectangle.
\endlist
@ -571,11 +564,6 @@ QRect QFontMetrics::boundingRect(QChar ch) const
If several of the horizontal or several of the vertical alignment
flags are set, the resulting alignment is undefined.
If Qt::TextExpandTabs is set in \a flags, then: if \a tabArray is
non-null, it specifies a 0-terminated sequence of pixel-positions
for tabs; otherwise if \a tabStops is non-zero, it is used as the
tab spacing (in pixels).
Note that the bounding rectangle may extend to the left of (0, 0),
e.g. for italicized fonts, and that the text output may cover \e
all pixels in the bounding rectangle.
@ -595,18 +583,10 @@ QRect QFontMetrics::boundingRect(QChar ch) const
\sa width(), QPainter::boundingRect(), Qt::Alignment
*/
QRect QFontMetrics::boundingRect(const QRect &rect, int flags, const QString &text, int tabStops,
int *tabArray) const
QRect QFontMetrics::boundingRect(const QRect &rect, int flags, const QString &text) const
{
int tabArrayLen = 0;
if (tabArray)
while (tabArray[tabArrayLen])
tabArrayLen++;
QRectF rb;
qt_format_text(QFont(d.data()), rect, flags | Qt::TextDontPrint, text, &rb, tabStops, tabArray,
tabArrayLen);
qt_format_text(QFont(d.data()), rect, flags | Qt::TextDontPrint, text, &rb);
return rb.toAlignedRect();
}
@ -616,16 +596,10 @@ QRect QFontMetrics::boundingRect(const QRect &rect, int flags, const QString &te
The \a flags argument is the bitwise OR of the following flags:
\list
\o Qt::TextSingleLine ignores newline characters.
\o Qt::TextExpandTabs expands tabs (see below)
\o Qt::TextShowMnemonic interprets "&x" as \underline{x}; i.e., underlined.
\o Qt::TextWordBreak breaks the text to fit the rectangle.
\endlist
If Qt::TextExpandTabs is set in \a flags, then: if \a tabArray is
non-null, it specifies a 0-terminated sequence of pixel-positions
for tabs; otherwise if \a tabStops is non-zero, it is used as the
tab spacing (in pixels).
Newline characters are processed as linebreaks.
Despite the different actual character heights, the heights of the
@ -633,9 +607,9 @@ QRect QFontMetrics::boundingRect(const QRect &rect, int flags, const QString &te
\sa boundingRect()
*/
QSize QFontMetrics::size(int flags, const QString &text, int tabStops, int *tabArray) const
QSize QFontMetrics::size(int flags, const QString &text) const
{
return boundingRect(QRect(0,0,0,0), flags | Qt::TextLongestVariant, text, tabStops, tabArray).size();
return boundingRect(QRect(0,0,0,0), flags | Qt::TextLongestVariant, text).size();
}
/*!
@ -1217,7 +1191,6 @@ QRectF QFontMetricsF::boundingRect(QChar ch) const
\o Qt::AlignVCenter aligns vertically centered
\o Qt::AlignCenter (== \c{Qt::AlignHCenter | Qt::AlignVCenter})
\o Qt::TextSingleLine ignores newline characters in the text.
\o Qt::TextExpandTabs expands tabs (see below)
\o Qt::TextShowMnemonic interprets "&x" as \underline{x}; i.e., underlined.
\o Qt::TextWordWrap breaks the text to fit the rectangle.
\endlist
@ -1230,14 +1203,6 @@ QRectF QFontMetricsF::boundingRect(QChar ch) const
These flags are defined in \l{Qt::AlignmentFlag}.
If Qt::TextExpandTabs is set in \a flags, the following behavior is
used to interpret tab characters in the text:
\list
\o If \a tabArray is non-null, it specifies a 0-terminated sequence of
pixel-positions for tabs in the text.
\o If \a tabStops is non-zero, it is used as the tab spacing (in pixels).
\endlist
Note that the bounding rectangle may extend to the left of (0, 0),
e.g. for italicized fonts.
@ -1256,17 +1221,10 @@ QRectF QFontMetricsF::boundingRect(QChar ch) const
\sa width(), QPainter::boundingRect(), Qt::Alignment
*/
QRectF QFontMetricsF::boundingRect(const QRectF &rect, int flags, const QString& text,
int tabStops, int *tabArray) const
QRectF QFontMetricsF::boundingRect(const QRectF &rect, int flags, const QString& text) const
{
int tabArrayLen = 0;
if (tabArray)
while (tabArray[tabArrayLen])
tabArrayLen++;
QRectF rb;
qt_format_text(QFont(d.data()), rect, flags | Qt::TextDontPrint, text, &rb, tabStops, tabArray,
tabArrayLen);
qt_format_text(QFont(d.data()), rect, flags | Qt::TextDontPrint, text, &rb);
return rb;
}
@ -1276,21 +1234,12 @@ QRectF QFontMetricsF::boundingRect(const QRectF &rect, int flags, const QString&
The \a flags argument is the bitwise OR of the following flags:
\list
\o Qt::TextSingleLine ignores newline characters.
\o Qt::TextExpandTabs expands tabs (see below)
\o Qt::TextShowMnemonic interprets "&x" as \underline{x}; i.e., underlined.
\o Qt::TextWordBreak breaks the text to fit the rectangle.
\endlist
These flags are defined in \l{Qt::TextFlags}.
If Qt::TextExpandTabs is set in \a flags, the following behavior is
used to interpret tab characters in the text:
\list
\o If \a tabArray is non-null, it specifies a 0-terminated sequence of
pixel-positions for tabs in the text.
\o If \a tabStops is non-zero, it is used as the tab spacing (in pixels).
\endlist
Newline characters are processed as line breaks.
Note: Despite the different actual character heights, the heights of the
@ -1298,9 +1247,9 @@ QRectF QFontMetricsF::boundingRect(const QRectF &rect, int flags, const QString&
\sa boundingRect()
*/
QSizeF QFontMetricsF::size(int flags, const QString &text, int tabStops, int *tabArray) const
QSizeF QFontMetricsF::size(int flags, const QString &text) const
{
return boundingRect(QRectF(), flags | Qt::TextLongestVariant, text, tabStops, tabArray).size();
return boundingRect(QRectF(), flags | Qt::TextLongestVariant, text).size();
}
/*!
@ -1384,55 +1333,4 @@ qreal QFontMetricsF::lineWidth() const
return engine->lineThickness().toReal();
}
/*!
\fn QSize QFontMetrics::size(int flags, const QString &text, int len,
int tabStops, int *tabArray) const
\compat
Use the size() function in combination with QString::left()
instead.
\oldcode
QSize size = size(flags, str, len, tabstops, tabarray);
\newcode
QSize size = size(flags, str.left(len), tabstops, tabarray);
\endcode
*/
/*!
\fn QRect QFontMetrics::boundingRect(int x, int y, int w, int h, int flags,
const QString& text, int len, int tabStops, int *tabArray) const
\compat
Use the boundingRect() function in combination with
QString::left() and a QRect constructor instead.
\oldcode
QRect rect = boundingRect(x, y, w, h , flags, text, len,
tabStops, tabArray);
\newcode
QRect rect = boundingRect(QRect(x, y, w, h), flags, text.left(len),
tabstops, tabarray);
\endcode
*/
/*!
\fn QRect QFontMetrics::boundingRect(const QString &text, int len) const
\compat
Use the boundingRect() function in combination with
QString::left() instead.
\oldcode
QRect rect = boundingRect(text, len);
\newcode
QRect rect = boundingRect(text.left(len));
\endcode
*/
QT_END_NAMESPACE

View file

@ -65,11 +65,10 @@ public:
QRect boundingRect(QChar) const;
QRect boundingRect(const QString &text) const;
QRect boundingRect(const QRect &r, int flags, const QString &text, int tabstops=0, int *tabarray=0) const;
inline QRect boundingRect(int x, int y, int w, int h, int flags, const QString &text,
int tabstops=0, int *tabarray=0) const
{ return boundingRect(QRect(x, y, w, h), flags, text, tabstops, tabarray); }
QSize size(int flags, const QString& str, int tabstops=0, int *tabarray=0) const;
QRect boundingRect(const QRect &r, int flags, const QString &text) const;
inline QRect boundingRect(int x, int y, int w, int h, int flags, const QString &text) const
{ return boundingRect(QRect(x, y, w, h), flags, text); }
QSize size(int flags, const QString& str) const;
QString elidedText(const QString &text, Qt::TextElideMode mode, int width, int flags = 0) const;
@ -123,8 +122,8 @@ public:
QRectF boundingRect(const QString &string) const;
QRectF boundingRect(QChar) const;
QRectF boundingRect(const QRectF &r, int flags, const QString& string, int tabstops=0, int *tabarray=0) const;
QSizeF size(int flags, const QString& str, int tabstops=0, int *tabarray=0) const;
QRectF boundingRect(const QRectF &r, int flags, const QString& string) const;
QSizeF size(int flags, const QString& str) const;
QString elidedText(const QString &text, Qt::TextElideMode mode, qreal width, int flags = 0) const;

View file

@ -154,9 +154,6 @@ private:
friend class QPSPrinter;
friend class QGraphicsSimpleTextItemPrivate;
friend class QGraphicsSimpleTextItem;
friend void qt_format_text(const QFont &font, const QRectF &_r, int tf, const QTextOption *, const QString& str,
QRectF *brect, int tabstops, int* tabarray, int tabarraylen,
QPainter *painter);
QTextEngine *d;
};

View file

@ -84,8 +84,8 @@ QT_BEGIN_NAMESPACE
By default, labels display \l{alignment}{left-aligned, vertically-centered}
text and images, where any tabs in the text to be displayed are
\l{Qt::TextExpandTabs}{automatically expanded}. However, the look
of a QLabel can be adjusted and fine-tuned in several ways.
\l{automatically expanded}. However, the look of a QLabel can be adjusted
and fine-tuned in several ways.
The positioning of the content within the QLabel widget area can
be tuned with setAlignment() and setIndent(). Text content can
@ -185,7 +185,7 @@ void QLabelPrivate::init()
pixmap = 0;
scaledpixmap = 0;
cachedimage = 0;
align = Qt::AlignLeft | Qt::AlignVCenter | Qt::TextExpandTabs;
align = Qt::AlignLeft | Qt::AlignVCenter;
indent = -1;
scaledcontents = false;
textLayoutDirty = false;