diff options
author | Tatiana Borisova <[email protected]> | 2024-07-25 11:59:02 +0200 |
---|---|---|
committer | Ivan Solovev <[email protected]> | 2024-07-30 12:00:33 +0000 |
commit | b4b90bfbaf8edfa7a2084adbaff0a2c0bc68acd1 (patch) | |
tree | 740e523464de142483e0ac4a6bf931f8c9b1c3b0 | |
parent | 7a90ed1238e543f1db1c4e5be5b53f3f07ec679e (diff) |
Use q20::{cmp_{equal,not_equal,{less,greater}{,_equal}} around the code
- edited a few places that compare signed and unsigned integer
variables, using C-style casts. The cmp_<name> functions allow
to do such comparisons in a convenient way.
Task-number: QTBUG-105464
Change-Id: I912893a47a1c93d163b0fbeccb61602adca80dd2
Reviewed-by: Ivan Solovev <[email protected]>
-rw-r--r-- | src/gui/image/qimage_conversions.cpp | 4 | ||||
-rw-r--r-- | src/gui/text/qtextdocument_p.cpp | 10 | ||||
-rw-r--r-- | src/plugins/platforms/linuxfb/qlinuxfbscreen.cpp | 9 | ||||
-rw-r--r-- | src/widgets/itemviews/qtreeview.cpp | 4 | ||||
-rw-r--r-- | src/widgets/styles/qstyle.cpp | 5 |
5 files changed, 19 insertions, 13 deletions
diff --git a/src/gui/image/qimage_conversions.cpp b/src/gui/image/qimage_conversions.cpp index 8d9e0b87e29..09caf558e06 100644 --- a/src/gui/image/qimage_conversions.cpp +++ b/src/gui/image/qimage_conversions.cpp @@ -24,6 +24,8 @@ #endif #endif +#include <QtCore/q20utility.h> + QT_BEGIN_NAMESPACE struct QDefaultColorTables @@ -1773,7 +1775,7 @@ void dither_to_Mono(QImageData *dst, const QImageData *src, } } else { while (p < end) { - if ((uint)qGray(*p++) < qt_bayer_matrix[j++&15][i&15]) + if (q20::cmp_less(qGray(*p++), qt_bayer_matrix[j++&15][i&15])) *m |= 1 << bit; if (bit == 0) { m++; diff --git a/src/gui/text/qtextdocument_p.cpp b/src/gui/text/qtextdocument_p.cpp index 3c1fc04d4b6..9ccd01edb0d 100644 --- a/src/gui/text/qtextdocument_p.cpp +++ b/src/gui/text/qtextdocument_p.cpp @@ -17,6 +17,8 @@ #include "qtexttable.h" #include "qtextengine_p.h" +#include <QtCore/q20utility.h> + #include <stdlib.h> QT_BEGIN_NAMESPACE @@ -461,13 +463,13 @@ int QTextDocumentPrivate::remove_string(int pos, uint length, QTextUndoCommand:: { Q_ASSERT(pos >= 0); Q_ASSERT(blocks.length() == fragments.length()); - Q_ASSERT(blocks.length() >= pos+(int)length); + Q_ASSERT(q20::cmp_greater_equal(blocks.length(), pos+length)); int b = blocks.findNode(pos); uint x = fragments.findNode(pos); Q_ASSERT(blocks.size(b) > length); - Q_ASSERT(x && fragments.position(x) == (uint)pos && fragments.size(x) == length); + Q_ASSERT(x && q20::cmp_equal(fragments.position(x), pos) && fragments.size(x) == length); Q_ASSERT(noBlockInString(QStringView{text}.mid(fragments.fragment(x)->stringPosition, length))); blocks.setSize(b, blocks.size(b)-length); @@ -725,7 +727,7 @@ void QTextDocumentPrivate::setCharFormat(int pos, int length, const QTextCharFor appendUndoItem(c); pos += length; - Q_ASSERT(pos == (int)(it.position() + fragment->size_array[0]) || pos >= endPos); + Q_ASSERT(q20::cmp_equal(pos, (it.position() + fragment->size_array[0])) || pos >= endPos); } int n = fragments.findNode(startPos - 1); @@ -1036,7 +1038,7 @@ void QTextDocumentPrivate::appendUndoItem(const QTextUndoCommand &c) clearUndoRedoStacks(QTextDocument::RedoStack); if (editBlock != 0 && editBlockCursorPosition >= 0) { // we had a beginEditBlock() with a cursor position - if (c.pos != (quint32) editBlockCursorPosition) { // and that cursor position is different from the command + if (q20::cmp_not_equal(c.pos, editBlockCursorPosition)) { // and that cursor position is different from the command // generate a CursorMoved undo item QT_INIT_TEXTUNDOCOMMAND(cc, QTextUndoCommand::CursorMoved, true, QTextUndoCommand::MoveCursor, 0, 0, editBlockCursorPosition, 0, 0); diff --git a/src/plugins/platforms/linuxfb/qlinuxfbscreen.cpp b/src/plugins/platforms/linuxfb/qlinuxfbscreen.cpp index e2826f39461..1096090eff6 100644 --- a/src/plugins/platforms/linuxfb/qlinuxfbscreen.cpp +++ b/src/plugins/platforms/linuxfb/qlinuxfbscreen.cpp @@ -6,6 +6,7 @@ #include <QtFbSupport/private/qfbwindow_p.h> #include <QtCore/QFile> #include <QtCore/QRegularExpression> +#include <QtCore/q20utility.h> #include <QtGui/QPainter> #include <private/qcore_unix_p.h> // overrides QT_OPEN @@ -69,16 +70,16 @@ static QRect determineGeometry(const fb_var_screeninfo &vinfo, const QRect &user if (userGeometry.isValid()) { w = userGeometry.width(); h = userGeometry.height(); - if ((uint)w > vinfo.xres) + if (q20::cmp_greater(w, vinfo.xres)) w = vinfo.xres; - if ((uint)h > vinfo.yres) + if (q20::cmp_greater(h, vinfo.yres)) h = vinfo.yres; int xxoff = userGeometry.x(), yyoff = userGeometry.y(); if (xxoff != 0 || yyoff != 0) { - if (xxoff < 0 || xxoff + w > (int)(vinfo.xres)) + if (xxoff < 0 || q20::cmp_greater(xxoff + w, vinfo.xres)) xxoff = vinfo.xres - w; - if (yyoff < 0 || yyoff + h > (int)(vinfo.yres)) + if (yyoff < 0 || q20::cmp_greater(yyoff + h, vinfo.yres)) yyoff = vinfo.yres - h; xoff += xxoff; yoff += yyoff; diff --git a/src/widgets/itemviews/qtreeview.cpp b/src/widgets/itemviews/qtreeview.cpp index 621e9f220aa..e859a26d670 100644 --- a/src/widgets/itemviews/qtreeview.cpp +++ b/src/widgets/itemviews/qtreeview.cpp @@ -2840,7 +2840,7 @@ void QTreeView::expandToDepth(int depth) d->interruptDelayedItemsLayout(); d->layout(-1); for (int i = 0; i < d->viewItems.size(); ++i) { - if (d->viewItems.at(i).level <= (uint)depth) { + if (q20::cmp_less_equal(d->viewItems.at(i).level, depth)) { d->viewItems[i].expanded = true; d->layout(i); d->storeExpanded(d->viewItems.at(i).index); @@ -3463,7 +3463,7 @@ void QTreeViewPrivate::layout(int i, bool recursiveExpanding, bool afterIsUninit } viewItems.resize(count); afterIsUninitialized = true; - } else if (viewItems[i].total != (uint)count) { + } else if (q20::cmp_not_equal(viewItems[i].total, count)) { if (!afterIsUninitialized) insertViewItems(i + 1, count, QTreeViewItem()); // expand else if (count > 0) diff --git a/src/widgets/styles/qstyle.cpp b/src/widgets/styles/qstyle.cpp index 60b2f51e952..60ce0c3bd8a 100644 --- a/src/widgets/styles/qstyle.cpp +++ b/src/widgets/styles/qstyle.cpp @@ -14,6 +14,7 @@ #ifndef QT_NO_DEBUG #include "qdebug.h" #endif +#include <QtCore/q20utility.h> #include <limits.h> #include <algorithm> @@ -2234,7 +2235,7 @@ int QStyle::sliderPositionFromValue(int min, int max, int logicalValue, int span if (range > (uint)INT_MAX/4096) { double dpos = (double(p))/(double(range)/span); return int(dpos); - } else if (range > (uint)span) { + } else if (q20::cmp_greater(range, span)) { return (2 * p * span + range) / (2*range); } else { uint div = span / range; @@ -2273,7 +2274,7 @@ int QStyle::sliderValueFromPosition(int min, int max, int pos, int span, bool up const qint64 range = qint64(max) - min; - if ((uint)span > range) { + if (q20::cmp_greater(span, range)) { const int tmp = (2 * range * pos + span) / (qint64(2) * span); return upsideDown ? max - tmp : tmp + min; } else { |