Skip to content

Commit

Permalink
Require C++17 even with Qt5. Port from qAsConst to std::as_const.
Browse files Browse the repository at this point in the history
  • Loading branch information
dfaure-kdab committed Oct 12, 2024
1 parent f931a44 commit b1db06a
Show file tree
Hide file tree
Showing 18 changed files with 49 additions and 52 deletions.
5 changes: 1 addition & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -141,11 +141,8 @@ set(CMAKE_AUTOMOC TRUE)
set(CMAKE_AUTOUIC TRUE)
set(CMAKE_AUTORCC TRUE)

set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
if(TARGET Qt6::Core)
set(CMAKE_CXX_STANDARD 17)
endif()

# Default to hidden visibility for symbols
set(CMAKE_C_VISIBILITY_PRESET hidden)
Expand Down
4 changes: 2 additions & 2 deletions examples/Plotter/BigDataset/MainWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ MainWidget::MainWidget()
m_functionSelector << m_controls.sineRadio << m_controls.triangleRadio << m_controls.squareRadio
<< m_controls.noiseRadio << m_controls.oneDivSineRadio
<< m_controls.sineOneDivRadio;
for (QRadioButton *r : qAsConst(m_functionSelector)) {
for (QRadioButton *r : std::as_const(m_functionSelector)) {
connect(r, &QRadioButton::toggled, this, &MainWidget::functionToggled);
}

Expand All @@ -64,7 +64,7 @@ MainWidget::MainWidget()

// order matters again
m_addPointsButtons << m_controls.add1kButton << m_controls.add10kButton << m_controls.add100kButton;
for (QPushButton *b : qAsConst(m_addPointsButtons)) {
for (QPushButton *b : std::as_const(m_addPointsButtons)) {
connect(b, &QPushButton::clicked, this, &MainWidget::addPointsButtonClicked);
}
}
Expand Down
4 changes: 2 additions & 2 deletions examples/demo/gradientdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ void GradientDialog::Private::updateGradientDisplay()
gradient.setStart(0, 0);
gradient.setStart(1, 0);
gradient.setCoordinateMode(QGradient::ObjectBoundingMode);
for (const QGradientStop &stop : qAsConst(m_gradient))
for (const QGradientStop &stop : std::as_const(m_gradient))
gradient.setColorAt(stop.first, stop.second);
QPalette palette = ui->gradientDisplay->palette();
palette.setBrush(QPalette::Window, gradient);
Expand Down Expand Up @@ -230,7 +230,7 @@ QGradient GradientDialog::gradient() const
gradient.setStart(0, 0);
gradient.setStart(1, 0);
gradient.setCoordinateMode(QGradient::ObjectBoundingMode);
for (const QGradientStop &stop : qAsConst(d->m_gradient))
for (const QGradientStop &stop : std::as_const(d->m_gradient))
gradient.setColorAt(stop.first, stop.second);
return gradient;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ void PercentPlotter::paint(PaintContext *ctx)
QList<qreal> xValues = diagramValues.keys();
// make sure it's sorted
std::sort(xValues.begin(), xValues.end());
for (const qreal xValue : qAsConst(xValues)) {
for (const qreal xValue : std::as_const(xValues)) {
// the y-values to the current x-value
QVector<QPair<Value, QModelIndex>> &yValues = diagramValues[xValue];
Q_ASSERT(yValues.count() == colCount);
Expand Down
2 changes: 1 addition & 1 deletion src/KDChart/Cartesian/KDChartAbstractCartesianDiagram.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ AbstractCartesianDiagram::AbstractCartesianDiagram(QWidget *parent, CartesianCoo

KDChart::AbstractCartesianDiagram::~AbstractCartesianDiagram()
{
for (CartesianAxis *axis : qAsConst(d->axesList)) {
for (CartesianAxis *axis : std::as_const(d->axesList)) {
axis->deleteObserver(this);
}
d->axesList.clear();
Expand Down
2 changes: 1 addition & 1 deletion src/KDChart/Cartesian/KDChartBarDiagram_p.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ void BarDiagram::BarDiagramType::paintBars(PaintContext *ctx, const QModelIndex
bool drawIt = false;
bool hasPointOutside = false;
const QRectF r(ctx->rectangle().adjusted(0, -1, 1, 0));
for (QPointF pt : qAsConst(topPoints)) {
for (QPointF pt : std::as_const(topPoints)) {
if (r.contains(pt)) {
drawIt = true;
} else {
Expand Down
2 changes: 1 addition & 1 deletion src/KDChart/Cartesian/KDChartCartesianAxis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,7 @@ CartesianAxis::~CartesianAxis()
auto *cd = qobject_cast<AbstractCartesianDiagram *>(d->mDiagram);
cd->takeAxis(this);
}
for (AbstractDiagram *diagram : qAsConst(d->secondaryDiagrams)) {
for (AbstractDiagram *diagram : std::as_const(d->secondaryDiagrams)) {
auto *cd = qobject_cast<AbstractCartesianDiagram *>(diagram);
cd->takeAxis(this);
}
Expand Down
2 changes: 1 addition & 1 deletion src/KDChart/Cartesian/KDChartLeveyJenningsAxis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ LeveyJenningsAxis::~LeveyJenningsAxis()
auto *cd = qobject_cast<LeveyJenningsDiagram *>(d->mDiagram);
cd->takeAxis(this);
}
for (AbstractDiagram *diagram : qAsConst(d->secondaryDiagrams)) {
for (AbstractDiagram *diagram : std::as_const(d->secondaryDiagrams)) {
auto *cd = qobject_cast<LeveyJenningsDiagram *>(diagram);
cd->takeAxis(this);
}
Expand Down
6 changes: 3 additions & 3 deletions src/KDChart/Cartesian/KDChartLeveyJenningsDiagram.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@ void LeveyJenningsDiagram::calculateMeanAndStandardDeviation() const

qreal sum = 0.0;
qreal sumSquares = 0.0;
for (qreal value : qAsConst(values)) {
for (qreal value : std::as_const(values)) {
sum += value;
sumSquares += value * value;
}
Expand Down Expand Up @@ -478,13 +478,13 @@ void LeveyJenningsDiagram::drawChanges(PaintContext *ctx)
{
const unsigned int minTime = timeRange().first.toSecsSinceEpoch();

for (const QDateTime &dt : qAsConst(d->fluidicsPackChanges)) {
for (const QDateTime &dt : std::as_const(d->fluidicsPackChanges)) {
const qreal xValue = (dt.toSecsSinceEpoch() - minTime) / static_cast<qreal>(24 * 60 * 60);
const QPointF point(xValue, 0.0);
drawFluidicsPackChangedSymbol(ctx, point);
}

for (const QDateTime &dt : qAsConst(d->sensorChanges)) {
for (const QDateTime &dt : std::as_const(d->sensorChanges)) {
const qreal xValue = (dt.toSecsSinceEpoch() - minTime) / static_cast<qreal>(24 * 60 * 60);
const QPointF point(xValue, 0.0);
drawSensorChangedSymbol(ctx, point);
Expand Down
8 changes: 4 additions & 4 deletions src/KDChart/KDChartAbstractCoordinatePlane.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ void KDChart::AbstractCoordinatePlane::mousePressEvent(QMouseEvent *event)
}
}

for (AbstractDiagram *a : qAsConst(d->diagrams)) {
for (AbstractDiagram *a : std::as_const(d->diagrams)) {
a->mousePressEvent(event);
}
}
Expand All @@ -317,7 +317,7 @@ void KDChart::AbstractCoordinatePlane::mouseDoubleClickEvent(QMouseEvent *event)
// which is pretty annoying when zooming out fast
mousePressEvent(event);
}
for (AbstractDiagram *a : qAsConst(d->diagrams)) {
for (AbstractDiagram *a : std::as_const(d->diagrams)) {
a->mouseDoubleClickEvent(event);
}
}
Expand Down Expand Up @@ -367,7 +367,7 @@ void KDChart::AbstractCoordinatePlane::mouseReleaseEvent(QMouseEvent *event)
event->accept();
}

for (AbstractDiagram *a : qAsConst(d->diagrams)) {
for (AbstractDiagram *a : std::as_const(d->diagrams)) {
a->mouseReleaseEvent(event);
}
}
Expand All @@ -381,7 +381,7 @@ void KDChart::AbstractCoordinatePlane::mouseMoveEvent(QMouseEvent *event)
event->accept();
}

for (AbstractDiagram *a : qAsConst(d->diagrams)) {
for (AbstractDiagram *a : std::as_const(d->diagrams)) {
a->mouseMoveEvent(event);
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/KDChart/KDChartAbstractDiagram_p.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,7 @@ void AbstractDiagram::Private::paintDataValueTextsAndMarkers(
ctx->painter()->setClipping(false);

if (paintMarkers && !justCalculateRect) {
for (const LabelPaintInfo &info : qAsConst(cache.paintReplay)) {
for (const LabelPaintInfo &info : std::as_const(cache.paintReplay)) {
diagram->paintMarker(ctx->painter(), info.index, info.markerPos);
}
}
Expand All @@ -389,7 +389,7 @@ void AbstractDiagram::Private::paintDataValueTextsAndMarkers(

forgetAlreadyPaintedDataValues();

for (const LabelPaintInfo &info : qAsConst(cache.paintReplay)) {
for (const LabelPaintInfo &info : std::as_const(cache.paintReplay)) {
const QPointF pos = info.labelArea.elementAt(0);
paintDataValueText(ctx->painter(), info.attrs, pos, info.isValuePositive,
info.value, justCalculateRect, cumulatedBoundingRect);
Expand Down
42 changes: 21 additions & 21 deletions src/KDChart/KDChartChart.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ void Chart::Private::slotUnregisterDestroyedHeaderFooter(HeaderFooter *hf)
void Chart::Private::slotUnregisterDestroyedPlane(AbstractCoordinatePlane *plane)
{
coordinatePlanes.removeAll(plane);
for (AbstractCoordinatePlane *p : qAsConst(coordinatePlanes)) {
for (AbstractCoordinatePlane *p : std::as_const(coordinatePlanes)) {
if (p->referenceCoordinatePlane() == plane) {
p->setReferenceCoordinatePlane(nullptr);
}
Expand Down Expand Up @@ -328,7 +328,7 @@ static QVector<LayoutGraphNode *> getPrioritySortedConnectedComponents(QVector<L
{
QVector<LayoutGraphNode *> connectedComponents;
QHash<LayoutGraphNode *, VisitorState> visitedComponents;
for (LayoutGraphNode *node : qAsConst(nodeList)) {
for (LayoutGraphNode *node : std::as_const(nodeList)) {
visitedComponents[node] = Unknown;
}

Expand Down Expand Up @@ -474,7 +474,7 @@ QVector<LayoutGraphNode *> Chart::Private::buildPlaneLayoutGraph()
QHash<AbstractCoordinatePlane *, LayoutGraphNode *> planeNodeMapping;
QVector<LayoutGraphNode *> allNodes;
// create all nodes and a mapping between plane and nodes
for (AbstractCoordinatePlane *curPlane : qAsConst(coordinatePlanes)) {
for (AbstractCoordinatePlane *curPlane : std::as_const(coordinatePlanes)) {
if (curPlane->diagram()) {
allNodes.append(new LayoutGraphNode);
allNodes[allNodes.size() - 1]->diagramPlane = curPlane;
Expand All @@ -484,7 +484,7 @@ QVector<LayoutGraphNode *> Chart::Private::buildPlaneLayoutGraph()
}
}
// build the graph connections
for (LayoutGraphNode *curNode : qAsConst(allNodes)) {
for (LayoutGraphNode *curNode : std::as_const(allNodes)) {
QVector<CartesianAxis *> sharedAxes;
CoordinatePlaneList xSharedPlanes = findSharingAxisDiagrams(curNode->diagramPlane, coordinatePlanes, Abscissa, &sharedAxes);
Q_ASSERT(sharedAxes.size() < 2);
Expand Down Expand Up @@ -570,7 +570,7 @@ QHash<AbstractCoordinatePlane *, PlaneInfo> Chart::Private::buildPlaneLayoutInfo
* laid out vertically or horizontally next to each other. */
QHash<CartesianAxis *, AxisInfo> axisInfos;
QHash<AbstractCoordinatePlane *, PlaneInfo> planeInfos;
for (AbstractCoordinatePlane *plane : qAsConst(coordinatePlanes)) {
for (AbstractCoordinatePlane *plane : std::as_const(coordinatePlanes)) {
PlaneInfo p;
// first check if we share space with another plane
p.referencePlane = plane->referenceCoordinatePlane();
Expand Down Expand Up @@ -647,11 +647,11 @@ void Chart::Private::slotLayoutPlanes()
if (hadPlanesLayout)
planesLayout->getContentsMargins(&left, &top, &right, &bottom);

for (AbstractLayoutItem *plane : qAsConst(planeLayoutItems)) {
for (AbstractLayoutItem *plane : std::as_const(planeLayoutItems)) {
plane->removeFromParentLayout();
}
// TODO they should get a correct parent, but for now it works
for (AbstractLayoutItem *plane : qAsConst(planeLayoutItems)) {
for (AbstractLayoutItem *plane : std::as_const(planeLayoutItems)) {
if (dynamic_cast<AutoSpacerLayoutItem *>(plane))
delete plane;
}
Expand Down Expand Up @@ -814,7 +814,7 @@ void Chart::Private::slotLayoutPlanes()
* gets their own. See buildPlaneLayoutInfos() for more details. */
QHash<AbstractCoordinatePlane *, PlaneInfo> planeInfos = buildPlaneLayoutInfos();
QHash<AbstractAxis *, AxisInfo> axisInfos;
for (AbstractCoordinatePlane *plane : qAsConst(coordinatePlanes)) {
for (AbstractCoordinatePlane *plane : std::as_const(coordinatePlanes)) {
Q_ASSERT(planeInfos.contains(plane));
PlaneInfo &pi = planeInfos[plane];
const int column = pi.horizontalOffset;
Expand Down Expand Up @@ -1052,15 +1052,15 @@ void Chart::Private::slotResizePlanes()
layout->activate();
}
// Adapt diagram drawing to the new size
for (AbstractCoordinatePlane *plane : qAsConst(coordinatePlanes)) {
for (AbstractCoordinatePlane *plane : std::as_const(coordinatePlanes)) {
plane->layoutDiagrams();
}
}

void Chart::Private::updateDirtyLayouts()
{
if (isPlanesLayoutDirty) {
for (AbstractCoordinatePlane *p : qAsConst(coordinatePlanes)) {
for (AbstractCoordinatePlane *p : std::as_const(coordinatePlanes)) {
p->setGridNeedsRecalculate();
p->layoutPlanes();
p->layoutDiagrams();
Expand Down Expand Up @@ -1097,13 +1097,13 @@ void Chart::Private::paintAll(QPainter *painter)

chart->reLayoutFloatingLegends();

for (AbstractLayoutItem *planeLayoutItem : qAsConst(planeLayoutItems)) {
for (AbstractLayoutItem *planeLayoutItem : std::as_const(planeLayoutItems)) {
planeLayoutItem->paintAll(*painter);
}
for (TextArea *textLayoutItem : qAsConst(textLayoutItems)) {
for (TextArea *textLayoutItem : std::as_const(textLayoutItems)) {
textLayoutItem->paintAll(*painter);
}
for (Legend *legend : qAsConst(legends)) {
for (Legend *legend : std::as_const(legends)) {
const bool hidden = legend->isHidden() && legend->testAttribute(Qt::WA_WState_ExplicitShowHide);
if (!hidden) {
// qDebug() << "painting legend at " << legend->geometry();
Expand Down Expand Up @@ -1383,7 +1383,7 @@ void Chart::resizeEvent(QResizeEvent *event)

void Chart::reLayoutFloatingLegends()
{
for (Legend *legend : qAsConst(d->legends)) {
for (Legend *legend : std::as_const(d->legends)) {
const bool hidden = legend->isHidden() && legend->testAttribute(Qt::WA_WState_ExplicitShowHide);
if (legend->position().isFloating() && !hidden) {
// resize the legend
Expand Down Expand Up @@ -1671,7 +1671,7 @@ void Chart::mousePressEvent(QMouseEvent *event)
{
const QPoint pos = mapFromGlobal(event->globalPos());

for (AbstractCoordinatePlane *plane : qAsConst(d->coordinatePlanes)) {
for (AbstractCoordinatePlane *plane : std::as_const(d->coordinatePlanes)) {
if (plane->geometry().contains(event->pos()) && plane->diagrams().size() > 0) {
QMouseEvent ev(QEvent::MouseButtonPress, pos, event->globalPos(),
event->button(), event->buttons(), event->modifiers());
Expand All @@ -1685,7 +1685,7 @@ void Chart::mouseDoubleClickEvent(QMouseEvent *event)
{
const QPoint pos = mapFromGlobal(event->globalPos());

for (AbstractCoordinatePlane *plane : qAsConst(d->coordinatePlanes)) {
for (AbstractCoordinatePlane *plane : std::as_const(d->coordinatePlanes)) {
if (plane->geometry().contains(event->pos()) && plane->diagrams().size() > 0) {
QMouseEvent ev(QEvent::MouseButtonPress, pos, event->globalPos(),
event->button(), event->buttons(), event->modifiers());
Expand All @@ -1703,15 +1703,15 @@ void Chart::mouseMoveEvent(QMouseEvent *event)
QSet<AbstractCoordinatePlane *>::fromList(d->mouseClickedPlanes);
#endif

for (AbstractCoordinatePlane *plane : qAsConst(d->coordinatePlanes)) {
for (AbstractCoordinatePlane *plane : std::as_const(d->coordinatePlanes)) {
if (plane->geometry().contains(event->pos()) && plane->diagrams().size() > 0) {
eventReceivers.insert(plane);
}
}

const QPoint pos = mapFromGlobal(event->globalPos());

for (AbstractCoordinatePlane *plane : qAsConst(eventReceivers)) {
for (AbstractCoordinatePlane *plane : std::as_const(eventReceivers)) {
QMouseEvent ev(QEvent::MouseMove, pos, event->globalPos(),
event->button(), event->buttons(), event->modifiers());
plane->mouseMoveEvent(&ev);
Expand All @@ -1727,15 +1727,15 @@ void Chart::mouseReleaseEvent(QMouseEvent *event)
QSet<AbstractCoordinatePlane *>::fromList(d->mouseClickedPlanes);
#endif

for (AbstractCoordinatePlane *plane : qAsConst(d->coordinatePlanes)) {
for (AbstractCoordinatePlane *plane : std::as_const(d->coordinatePlanes)) {
if (plane->geometry().contains(event->pos()) && plane->diagrams().size() > 0) {
eventReceivers.insert(plane);
}
}

const QPoint pos = mapFromGlobal(event->globalPos());

for (AbstractCoordinatePlane *plane : qAsConst(eventReceivers)) {
for (AbstractCoordinatePlane *plane : std::as_const(eventReceivers)) {
QMouseEvent ev(QEvent::MouseButtonRelease, pos, event->globalPos(),
event->button(), event->buttons(), event->modifiers());
plane->mouseReleaseEvent(&ev);
Expand All @@ -1749,7 +1749,7 @@ bool Chart::event(QEvent *event)
if (event->type() == QEvent::ToolTip) {
const QHelpEvent *const helpEvent = static_cast<QHelpEvent *>(event);
for (int stage = 0; stage < 2; ++stage) {
for (const AbstractCoordinatePlane *const plane : qAsConst(d->coordinatePlanes)) {
for (const AbstractCoordinatePlane *const plane : std::as_const(d->coordinatePlanes)) {
const auto constDiagrams = plane->diagrams();
for (const AbstractDiagram *diagram : constDiagrams) {

Expand Down
6 changes: 3 additions & 3 deletions src/KDChart/KDChartLegend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ QSize Legend::sizeHint() const
#ifdef DEBUG_LEGEND_PAINT
qDebug() << "Legend::sizeHint() started";
#endif
for (AbstractLayoutItem *paintItem : qAsConst(d->paintItems)) {
for (AbstractLayoutItem *paintItem : std::as_const(d->paintItems)) {
paintItem->sizeHint();
}
return AbstractAreaWidget::sizeHint();
Expand Down Expand Up @@ -212,7 +212,7 @@ void Legend::paint(QPainter *painter)

activateTheLayout();

for (AbstractLayoutItem *paintItem : qAsConst(d->paintItems)) {
for (AbstractLayoutItem *paintItem : std::as_const(d->paintItems)) {
paintItem->paint(painter);
}

Expand Down Expand Up @@ -1134,7 +1134,7 @@ int Legend::heightForWidth(int width) const

int currentLineWidth = 0;
int currentLineHeight = 0;
for (const HDatasetItem &hdsItem : qAsConst(d->hLayoutDatasets)) {
for (const HDatasetItem &hdsItem : std::as_const(d->hLayoutDatasets)) {
const int payloadWidth = hdsItem.markerLine->sizeHint().width() + hdsItem.label->sizeHint().width();
if (!currentLineWidth) {
// first iteration
Expand Down
2 changes: 1 addition & 1 deletion src/KDChart/Polar/KDChartPieDiagram.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -489,7 +489,7 @@ void PieDiagram::paintInternal(PaintContext *paintContext)
const QPointF center = paintContext->rectangle().center();
const PainterSaver painterSaver(paintContext->painter());
paintContext->painter()->setBrush(Qt::NoBrush);
for (const LabelPaintInfo &pi : qAsConst(d->labelPaintCache.paintReplay)) {
for (const LabelPaintInfo &pi : std::as_const(d->labelPaintCache.paintReplay)) {
// we expect the PainterPath to be a rectangle
if (pi.labelArea.elementCount() != 5) {
continue;
Expand Down
2 changes: 1 addition & 1 deletion src/KDChart/Ternary/KDChartTernaryGrid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ void TernaryGrid::drawGrid(PaintContext *context)

QVector<QLineF> lines[MaxDepth];
{
for (const TickInfo &tick : qAsConst(m_tickInfo)) {
for (const TickInfo &tick : std::as_const(m_tickInfo)) {
const qreal &percent = tick.percentage;
{ // draw parallels to B
TernaryPoint ternaryStart(percent, 1.0 - percent);
Expand Down
Loading

0 comments on commit b1db06a

Please sign in to comment.