Skip to content

OpenToonz - An open-source full-featured 2D animation creation software

C

Use std::max and std::min instead of qMax and qMin (#2753)

shun-iwasawaa0d489d21ec6
diff --git a/toonz/sources/tnztools/toolutils.cpp b/toonz/sources/tnztools/toolutils.cpp
index cd7832b83..141845b98 100644
--- a/toonz/sources/tnztools/toolutils.cpp
+++ b/toonz/sources/tnztools/toolutils.cpp
@@ -1526,8 +1526,8 @@ void ToolUtils::drawBalloon(const TPointD &pos, std::string text,
delta.x *= devPixRatio;
delta.y *= devPixRatio;
- textRect.moveTo(qMax(delta.x, 10 * devPixRatio + mrg),
- qMax(mrg + 2 * devPixRatio, -delta.y - baseLine));
+ textRect.moveTo(std::max(delta.x, 10 * devPixRatio + mrg),
+ std::max(mrg + 2 * devPixRatio, -delta.y - baseLine));
int y = textRect.top() + baseLine;
int x0 = textRect.left() - mrg;
@@ -1577,7 +1577,7 @@ void ToolUtils::drawBalloon(const TPointD &pos, std::string text,
}
QSize size(textRect.width() + textRect.left() + mrg,
- qMax(textRect.bottom() + mrg, y + delta.y) + 3 * devPixRatio);
+ std::max(textRect.bottom() + mrg, y + delta.y) + 3 * devPixRatio);
QImage label(size.width(), size.height(), QImage::Format_ARGB32);
label.fill(Qt::transparent);
diff --git a/toonz/sources/toonz/xshcellmover.cpp b/toonz/sources/toonz/xshcellmover.cpp
index 1f962f9e7..ece092c07 100644
--- a/toonz/sources/toonz/xshcellmover.cpp
+++ b/toonz/sources/toonz/xshcellmover.cpp
@@ -660,8 +660,8 @@ void LevelMoverTool::drawCellsArea(QPainter &p) {
CellRange(CellPosition(rect.y0, rect.x0),
CellPosition(rect.y1 + 1, rect.x1 + 1)));
else {
- int newY0 = qMax(rect.y0, rect.y1);
- int newY1 = qMin(rect.y0, rect.y1);
+ int newY0 = std::max(rect.y0, rect.y1);
+ int newY1 = std::min(rect.y0, rect.y1);
screen = getViewer()->rangeToXYRect(CellRange(
CellPosition(rect.x0, newY0), CellPosition(rect.x1 + 1, newY1 - 1)));
}
diff --git a/toonz/sources/toonz/xshcellviewer.cpp b/toonz/sources/toonz/xshcellviewer.cpp
index 6f192ce04..7fe015f92 100644
--- a/toonz/sources/toonz/xshcellviewer.cpp
+++ b/toonz/sources/toonz/xshcellviewer.cpp
@@ -1105,8 +1105,8 @@ void CellArea::drawCells(QPainter &p, const QRect toBeUpdated) {
c0 = visible.from().layer();
c1 = visible.to().layer();
if (!m_viewer->orientation()->isVerticalTimeline()) {
- int colCount = qMax(1, xsh->getColumnCount());
- c1 = qMin(c1, colCount - 1);
+ int colCount = std::max(1, xsh->getColumnCount());
+ c1 = std::min(c1, colCount - 1);
}
drawNonEmptyBackground(p);
@@ -1276,8 +1276,8 @@ void CellArea::drawSelectionBackground(QPainter &p) const {
CellRange(CellPosition(selRow0, selCol0),
CellPosition(selRow1 + 1, selCol1 + 1)));
else {
- int newSelCol0 = qMax(selCol0, selCol1);
- int newSelCol1 = qMin(selCol0, selCol1);
+ int newSelCol0 = std::max(selCol0, selCol1);
+ int newSelCol1 = std::min(selCol0, selCol1);
selectionRect = m_viewer->rangeToXYRect(
CellRange(CellPosition(selRow0, newSelCol0),
CellPosition(selRow1 + 1, newSelCol1 - 1)));
diff --git a/toonz/sources/toonz/xshcolumnviewer.cpp b/toonz/sources/toonz/xshcolumnviewer.cpp
index b974f4bcc..1e6cf08d7 100644
--- a/toonz/sources/toonz/xshcolumnviewer.cpp
+++ b/toonz/sources/toonz/xshcolumnviewer.cpp
@@ -1531,8 +1531,8 @@ void ColumnArea::paintEvent(QPaintEvent *event) { // AREA
c0 = cellRange.from().layer();
c1 = cellRange.to().layer();
if (!m_viewer->orientation()->isVerticalTimeline()) {
- int colCount = qMax(1, xsh->getColumnCount());
- c1 = qMin(c1, colCount - 1);
+ int colCount = std::max(1, xsh->getColumnCount());
+ c1 = std::min(c1, colCount - 1);
}
ColumnFan *columnFan = xsh->getColumnFan(m_viewer->orientation());
diff --git a/toonz/sources/toonz/xsheetdragtool.cpp b/toonz/sources/toonz/xsheetdragtool.cpp
index 3523a8482..3e1a13511 100644
--- a/toonz/sources/toonz/xsheetdragtool.cpp
+++ b/toonz/sources/toonz/xsheetdragtool.cpp
@@ -2143,8 +2143,8 @@ public:
CellRange(CellPosition(rect.y0, rect.x0),
CellPosition(rect.y1 + 1, rect.x1 + 1)));
else {
- int newY0 = qMax(rect.y0, rect.y1);
- int newY1 = qMin(rect.y0, rect.y1);
+ int newY0 = std::max(rect.y0, rect.y1);
+ int newY1 = std::min(rect.y0, rect.y1);
screenCell = getViewer()->rangeToXYRect(CellRange(
CellPosition(rect.x0, newY0), CellPosition(rect.x1 + 1, newY1 - 1)));
}
diff --git a/toonz/sources/toonz/xsheetviewer.cpp b/toonz/sources/toonz/xsheetviewer.cpp
index 0c085df5d..4f672952d 100644
--- a/toonz/sources/toonz/xsheetviewer.cpp
+++ b/toonz/sources/toonz/xsheetviewer.cpp
@@ -650,7 +650,7 @@ void XsheetViewer::timerEvent(QTimerEvent *) {
bool XsheetViewer::refreshContentSize(int dx, int dy) {
QSize viewportSize = m_cellScrollArea->viewport()->size();
QPoint offset = m_cellArea->pos();
- offset = QPoint(qMin(0, offset.x() - dx), qMin(0, offset.y() - dy)); // what?
+ offset = QPoint(std::min(0, offset.x() - dx), std::min(0, offset.y() - dy)); // what?
TXsheet *xsh = getXsheet();
int frameCount = xsh ? xsh->getFrameCount() : 0;
@@ -745,7 +745,7 @@ int XsheetViewer::colToTimelineLayerAxis(int layer) const {
int yBottom = o->colToLayerAxis(layer, fan) +
(fan->isActive(layer) ? o->cellHeight() : o->foldedCellSize()) -
1;
- int columnCount = qMax(1, xsh->getColumnCount());
+ int columnCount = std::max(1, xsh->getColumnCount());
int layerHeightActual =
m_columnArea->height() - 2; // o->colToLayerAxis(columnCount, fan) - 1;
@@ -771,7 +771,7 @@ CellPosition XsheetViewer::xyToPosition(const QPoint &point) const {
// For timeline mode, we need to base the Y axis on the bottom of the column
// area
// since the layers are flipped
- int columnCount = qMax(1, xsh->getColumnCount());
+ int columnCount = std::max(1, xsh->getColumnCount());
int colAreaHeight = o->colToLayerAxis(columnCount, fan);
usePoint.setY(colAreaHeight - usePoint.y());
@@ -811,7 +811,7 @@ QPoint XsheetViewer::positionToXY(const CellPosition &pos) const {
usePoint.setY(usePoint.y() + (fan->isActive(pos.layer())
? o->cellHeight()
: o->foldedCellSize()));
- int columnCount = qMax(1, xsh->getColumnCount());
+ int columnCount = std::max(1, xsh->getColumnCount());
int colsHeight = o->colToLayerAxis(columnCount, fan);
if (colsHeight)
@@ -1747,7 +1747,7 @@ int XsheetViewer::getFrameZoomAdjustment() {
int adj = frameRect.width() -
((frameRect.width() * getFrameZoomFactor()) / 100) - 1;
- return qMax(0, adj);
+ return std::max(0, adj);
}
void XsheetViewer::zoomOnFrame(int frame, int factor) {
diff --git a/toonz/sources/toonzlib/Naa2TlvConverter.cpp b/toonz/sources/toonzlib/Naa2TlvConverter.cpp
index 239516f87..a00d4a94e 100644
--- a/toonz/sources/toonzlib/Naa2TlvConverter.cpp
+++ b/toonz/sources/toonzlib/Naa2TlvConverter.cpp
@@ -344,7 +344,7 @@ void Naa2TlvConverter::findBackgroundRegions() {
for (int i = 0; i < m_colors.count(); i++) {
TPixel color = m_colors.at(i);
int v = color.r + color.g + color.b;
- int a = qMin(color.r, qMin(color.g, color.b));
+ int a = std::min({color.r, color.g, color.b});
if (a < 230) continue;
if (v > maxV) {
bgColorIndex = i;
@@ -682,8 +682,8 @@ void Naa2TlvConverter::findSuspectInks() {
if (region.isInk() && 10 <= region.pixelCount && region.pixelCount < 100) {
int lx = region.x1 - region.x0 + 1;
int ly = region.y1 - region.y0 + 1;
- int d = qMax(lx, ly);
- if (qMin(lx, ly) * 2 > qMax(lx, ly) && region.pixelCount > d * d / 2) {
+ int d = std::max(lx, ly);
+ if (std::min(lx, ly) * 2 > std::max(lx, ly) && region.pixelCount > d * d / 2) {
region.type = RegionInfo::Paint;
}
}
diff --git a/toonz/sources/toonzlib/tbinarizer.cpp b/toonz/sources/toonzlib/tbinarizer.cpp
index 49ee49f44..782ed7547 100644
--- a/toonz/sources/toonzlib/tbinarizer.cpp
+++ b/toonz/sources/toonzlib/tbinarizer.cpp
@@ -53,7 +53,7 @@ else color=6;
// ritorna true se i primi pixel del buffer non sono tutti opachi
bool hasAlpha(const TPixel32 *buffer, int w, int h) {
- int n = qMin(500, w * h);
+ int n = std::min(500, w * h);
for (int i = 0; i < n; i++)
if (buffer[i].m < 255) return true;
return false;
@@ -129,10 +129,10 @@ void TBinarizer::process(const TRaster32P &ras) {
// conto i quadrati che hanno un "buon" background
for (int y1 = 0; y1 < h1; y1++) {
int ya = y1 * bsize;
- int yb = qMin(h, ya + bsize) - 1;
+ int yb = std::min(h, ya + bsize) - 1;
for (int x1 = 0; x1 < w1; x1++) {
int xa = x1 * bsize;
- int xb = qMin(w, xa + bsize) - 1;
+ int xb = std::min(w, xa + bsize) - 1;
int tot = 0;
std::vector<int> histo(32, 0);
@@ -140,7 +140,7 @@ void TBinarizer::process(const TRaster32P &ras) {
for (int x = xa; x <= xb; x++) {
int k = y * w + x;
TPixel32 pix = buffer[k];
- int v = qMin(qMin(pix.r, pix.g), pix.b);
+ int v = std::min({pix.r, pix.g, pix.b});
vBuffer[k] = v;
histo[v >> 3] += 1;
tot += 1;
@@ -196,16 +196,16 @@ void TBinarizer::process(const TRaster32P &ras) {
// cerco i pixel sicuramente colorati e i sicuramente neri
for (int y1 = 0; y1 < h1; y1++) {
- int ya = qMax(1, y1 * bsize);
- int yb = qMin(h - 1, ya + bsize) - 1;
+ int ya = std::max(1, y1 * bsize);
+ int yb = std::min(h - 1, ya + bsize) - 1;
for (int x1 = 0; x1 < w1; x1++) {
int k1 = y1 * w1 + x1;
// salto i quadrati completamente bianchi
if (qBuffer[k1] >= thrBuffer[k1] - thrDelta) continue;
for (int y = ya + 1; y <= yb; y++) {
- int xa = qMax(1, x1 * bsize);
- int xb = qMin(w - 1, xa + bsize) - 1;
+ int xa = std::max(1, x1 * bsize);
+ int xb = std::min(w - 1, xa + bsize) - 1;
for (int x = xa + 1; x <= xb; x++) {
int k = y * w + x;
diff --git a/toonz/sources/toonzqt/dvtextedit.cpp b/toonz/sources/toonzqt/dvtextedit.cpp
index 59d6a3080..60173f709 100644
--- a/toonz/sources/toonzqt/dvtextedit.cpp
+++ b/toonz/sources/toonzqt/dvtextedit.cpp
@@ -38,10 +38,10 @@ qreal distanceBetweenPointandRect(const QRect &rect, const QPoint &point) {
sqrt(pow((double)(point.x() - rect.bottomRight().x()), 2) +
pow((double)(point.y() - rect.bottomRight().y()), 2));
- qreal topMax = qMin(topLeftDistance, topRightDistance);
- qreal bottomMax = qMin(bottomLeftDistance, bottomRightDistance);
+ qreal topMax = std::min(topLeftDistance, topRightDistance);
+ qreal bottomMax = std::min(bottomLeftDistance, bottomRightDistance);
- return qMin(topMax, bottomMax);
+ return std::min(topMax, bottomMax);
}
}
diff --git a/toonz/sources/toonzqt/expressionfield.cpp b/toonz/sources/toonzqt/expressionfield.cpp
index 1c47341a5..88cba015d 100644
--- a/toonz/sources/toonzqt/expressionfield.cpp
+++ b/toonz/sources/toonzqt/expressionfield.cpp
@@ -351,7 +351,7 @@ bool ExpressionField::updateCompleterPopup() {
int w = m_completerPopup->sizeHintForColumn(0) +
m_completerPopup->verticalScrollBar()->sizeHint().width() + 5;
int h =
- (m_completerPopup->sizeHintForRow(0) * qMin(7, model->rowCount()) + 3) +
+ (m_completerPopup->sizeHintForRow(0) * std::min(7, model->rowCount()) + 3) +
3;
QSize size(w, h);
diff --git a/toonz/sources/toonzqt/functionpanel.cpp b/toonz/sources/toonzqt/functionpanel.cpp
index 85535d5c7..bd7ed8cf0 100644
--- a/toonz/sources/toonzqt/functionpanel.cpp
+++ b/toonz/sources/toonzqt/functionpanel.cpp
@@ -1466,8 +1466,8 @@ void FunctionPanel::fitGraphToWindow(bool currentCurveOnly) {
f0 = fa;
f1 = fb;
} else {
- f0 = qMin(f0, fa);
- f1 = qMax(f1, fb);
+ f0 = std::min(f0, fa);
+ f1 = std::max(f1, fb);
}
double v = curve->getValue(fa);
if (unit) v = unit->convertTo(v);
@@ -1477,8 +1477,8 @@ void FunctionPanel::fitGraphToWindow(bool currentCurveOnly) {
double t = (double)j / (double)(m - 1);
double v = curve->getValue((1 - t) * fa + t * fb);
if (unit) v = unit->convertTo(v);
- v0 = qMin(v0, v);
- v1 = qMax(v1, v);
+ v0 = std::min(v0, v);
+ v1 = std::max(v1, v);
}
}
}
diff --git a/toonz/sources/toonzqt/functionsegmentviewer.cpp b/toonz/sources/toonzqt/functionsegmentviewer.cpp
index fb1635659..ccf09cba4 100644
--- a/toonz/sources/toonzqt/functionsegmentviewer.cpp
+++ b/toonz/sources/toonzqt/functionsegmentviewer.cpp
@@ -756,7 +756,7 @@ void FileSegmentPage::apply() {
TDoubleKeyframe::FileParams fileParams;
fileParams.m_path = TFilePath(stringPath.toStdWString());
- fileParams.m_fieldIndex = qMax(0, m_fieldIndexFld->text().toInt() - 1);
+ fileParams.m_fieldIndex = std::max(0, m_fieldIndexFld->text().toInt() - 1);
std::string unitName = m_measureFld->text().toStdString();
KeyframeSetter setter(curve, kIndex);
@@ -769,7 +769,7 @@ void FileSegmentPage::getGuiValues(TDoubleKeyframe::FileParams &fileParam,
QString stringPath = m_fileFld->getPath();
stringPath.replace("\\", "\\\\");
fileParam.m_path = TFilePath(stringPath.toStdWString());
- fileParam.m_fieldIndex = qMax(0, m_fieldIndexFld->text().toInt() - 1);
+ fileParam.m_fieldIndex = std::max(0, m_fieldIndexFld->text().toInt() - 1);
unitName = m_measureFld->text().toStdString();
}
diff --git a/toonz/sources/toonzqt/functionsheet.cpp b/toonz/sources/toonzqt/functionsheet.cpp
index 1d60a31a2..6d89233d9 100644
--- a/toonz/sources/toonzqt/functionsheet.cpp
+++ b/toonz/sources/toonzqt/functionsheet.cpp
@@ -166,10 +166,10 @@ public:
void drag(int row, int col, QMouseEvent *e) override {
if (row < 0) row = 0;
if (col < 0) col = 0;
- int r0 = qMin(row, m_firstRow);
- int r1 = qMax(row, m_firstRow);
- int c0 = qMin(col, m_firstCol);
- int c1 = qMax(col, m_firstCol);
+ int r0 = std::min(row, m_firstRow);
+ int r1 = std::max(row, m_firstRow);
+ int c0 = std::min(col, m_firstCol);
+ int c1 = std::max(col, m_firstCol);
QRect selectedCells(c0, r0, c1 - c0 + 1, r1 - r0 + 1);
m_sheet->selectCells(selectedCells);
}
diff --git a/toonz/sources/toonzqt/spreadsheetviewer.cpp b/toonz/sources/toonzqt/spreadsheetviewer.cpp
index bcfb89561..40da2208b 100644
--- a/toonz/sources/toonzqt/spreadsheetviewer.cpp
+++ b/toonz/sources/toonzqt/spreadsheetviewer.cpp
@@ -171,10 +171,10 @@ void SelectionDragTool::click(int row, int col, QMouseEvent *e) {
}
void SelectionDragTool::drag(int row, int col, QMouseEvent *e) {
- int r0 = qMin(row, m_firstRow);
- int r1 = qMax(row, m_firstRow);
- int c0 = qMin(col, m_firstCol);
- int c1 = qMax(col, m_firstCol);
+ int r0 = std::min(row, m_firstRow);
+ int r1 = std::max(row, m_firstRow);
+ int c0 = std::min(col, m_firstCol);
+ int c1 = std::max(col, m_firstCol);
QRect selectedCells(c0, r0, c1 - c0 + 1, r1 - r0 + 1);
m_viewer->selectCells(selectedCells);
}
@@ -708,7 +708,7 @@ bool SpreadsheetViewer::refreshContentSize(int scrollDx, int scrollDy) {
QSize viewportSize = m_cellScrollArea->viewport()->size();
QPoint offset = m_cellScrollArea->widget()->pos();
offset =
- QPoint(qMin(0, offset.x() - scrollDx), qMin(0, offset.y() - scrollDy));
+ QPoint(std::min(0, offset.x() - scrollDx), std::min(0, offset.y() - scrollDy));
QSize contentSize(columnToX(m_columnCount + 1), rowToY(m_rowCount + 1));
@@ -736,7 +736,7 @@ void SpreadsheetViewer::showEvent(QShowEvent *) {
int viewportHeight = m_cellScrollArea->height();
int contentHeight = rowToY(m_rowCount * 0 + 50);
QScrollBar *vSc = m_cellScrollArea->verticalScrollBar();
- int actualContentHeight = qMax(contentHeight, vSc->value() + viewportHeight);
+ int actualContentHeight = std::max(contentHeight, vSc->value() + viewportHeight);
m_rowScrollArea->widget()->setFixedHeight(actualContentHeight);
m_cellScrollArea->widget()->setFixedHeight(actualContentHeight);
if (m_frameHandle)