Libs: Use qAsConst with non-const Qt containers in range-loops

Change-Id: I00d9f7c1634bbb62191470d58158e1fd150533c0
Reviewed-by: Jarek Kobus <jaroslaw.kobus@qt.io>
This commit is contained in:
Alessandro Portale
2021-02-16 15:01:44 +01:00
parent 72d91dc94a
commit 97a45f7512
13 changed files with 30 additions and 31 deletions

View File

@@ -406,7 +406,7 @@ namespace ADS
{ {
DockWidget* dockWidget = d->m_tabBar->currentTab()->dockWidget(); DockWidget* dockWidget = d->m_tabBar->currentTab()->dockWidget();
if (!d->m_dockWidgetActionsButtons.isEmpty()) { if (!d->m_dockWidgetActionsButtons.isEmpty()) {
for (auto button : d->m_dockWidgetActionsButtons) { for (auto button : qAsConst(d->m_dockWidgetActionsButtons)) {
d->m_layout->removeWidget(button); d->m_layout->removeWidget(button);
delete button; delete button;
} }

View File

@@ -236,7 +236,7 @@ namespace ADS
return; return;
m_visibleDockAreaCount = 0; m_visibleDockAreaCount = 0;
for (auto dockArea : m_dockAreas) for (auto dockArea : qAsConst(m_dockAreas))
m_visibleDockAreaCount += dockArea->isHidden() ? 0 : 1; m_visibleDockAreaCount += dockArea->isHidden() ? 0 : 1;
} }
@@ -1146,7 +1146,7 @@ namespace ADS
DockAreaWidget *DockContainerWidget::dockAreaAt(const QPoint &globalPosition) const DockAreaWidget *DockContainerWidget::dockAreaAt(const QPoint &globalPosition) const
{ {
for (auto dockArea : d->m_dockAreas) { for (auto dockArea : qAsConst(d->m_dockAreas)) {
if (dockArea->isVisible() if (dockArea->isVisible()
&& dockArea->rect().contains(dockArea->mapFromGlobal(globalPosition))) && dockArea->rect().contains(dockArea->mapFromGlobal(globalPosition)))
return dockArea; return dockArea;
@@ -1167,7 +1167,7 @@ namespace ADS
int DockContainerWidget::visibleDockAreaCount() const int DockContainerWidget::visibleDockAreaCount() const
{ {
int result = 0; int result = 0;
for (auto dockArea : d->m_dockAreas) for (auto dockArea : qAsConst(d->m_dockAreas))
result += dockArea->isHidden() ? 0 : 1; result += dockArea->isHidden() ? 0 : 1;
return result; return result;
@@ -1257,7 +1257,7 @@ namespace ADS
QList<DockAreaWidget *> DockContainerWidget::openedDockAreas() const QList<DockAreaWidget *> DockContainerWidget::openedDockAreas() const
{ {
QList<DockAreaWidget *> result; QList<DockAreaWidget *> result;
for (auto dockArea : d->m_dockAreas) { for (auto dockArea : qAsConst(d->m_dockAreas)) {
if (!dockArea->isHidden()) if (!dockArea->isHidden())
result.append(dockArea); result.append(dockArea);
} }
@@ -1397,7 +1397,7 @@ namespace ADS
QList<DockWidget *> DockContainerWidget::dockWidgets() const QList<DockWidget *> DockContainerWidget::dockWidgets() const
{ {
QList<DockWidget *> result; QList<DockWidget *> result;
for (const auto dockArea : d->m_dockAreas) for (const auto dockArea : qAsConst(d->m_dockAreas))
result.append(dockArea->dockWidgets()); result.append(dockArea->dockWidgets());
return result; return result;
@@ -1406,7 +1406,7 @@ namespace ADS
DockWidget::DockWidgetFeatures DockContainerWidget::features() const DockWidget::DockWidgetFeatures DockContainerWidget::features() const
{ {
DockWidget::DockWidgetFeatures features(DockWidget::AllDockWidgetFeatures); DockWidget::DockWidgetFeatures features(DockWidget::AllDockWidgetFeatures);
for (const auto dockArea : d->m_dockAreas) for (const auto dockArea : qAsConst(d->m_dockAreas))
features &= dockArea->features(); features &= dockArea->features();
return features; return features;
@@ -1419,7 +1419,7 @@ namespace ADS
void DockContainerWidget::closeOtherAreas(DockAreaWidget *keepOpenArea) void DockContainerWidget::closeOtherAreas(DockAreaWidget *keepOpenArea)
{ {
for (const auto dockArea : d->m_dockAreas) { for (const auto dockArea : qAsConst(d->m_dockAreas)) {
if (dockArea == keepOpenArea) if (dockArea == keepOpenArea)
continue; continue;

View File

@@ -247,7 +247,7 @@ namespace ADS
// function are invisible to the user now and have no assigned dock area // function are invisible to the user now and have no assigned dock area
// They do not belong to any dock container, until the user toggles the // They do not belong to any dock container, until the user toggles the
// toggle view action the next time // toggle view action the next time
for (auto dockWidget : m_dockWidgetsMap) { for (auto dockWidget : qAsConst(m_dockWidgetsMap)) {
if (dockWidget->property(internal::dirtyProperty).toBool()) { if (dockWidget->property(internal::dirtyProperty).toBool()) {
dockWidget->flagAsUnassigned(); dockWidget->flagAsUnassigned();
emit dockWidget->viewToggled(false); emit dockWidget->viewToggled(false);
@@ -264,7 +264,7 @@ namespace ADS
// The dock areas because the previous toggleView() action has changed // The dock areas because the previous toggleView() action has changed
// the dock area index // the dock area index
int count = 0; int count = 0;
for (auto dockContainer : m_containers) { for (auto dockContainer : qAsConst(m_containers)) {
count++; count++;
for (int i = 0; i < dockContainer->dockAreaCount(); ++i) { for (int i = 0; i < dockContainer->dockAreaCount(); ++i) {
DockAreaWidget *dockArea = dockContainer->dockArea(i); DockAreaWidget *dockArea = dockContainer->dockArea(i);
@@ -290,7 +290,7 @@ namespace ADS
{ {
// Finally we need to send the topLevelChanged() signals for all dock // Finally we need to send the topLevelChanged() signals for all dock
// widgets if top level changed // widgets if top level changed
for (auto dockContainer : m_containers) { for (auto dockContainer : qAsConst(m_containers)) {
DockWidget *topLevelDockWidget = dockContainer->topLevelDockWidget(); DockWidget *topLevelDockWidget = dockContainer->topLevelDockWidget();
if (topLevelDockWidget) { if (topLevelDockWidget) {
topLevelDockWidget->emitTopLevelChanged(true); topLevelDockWidget->emitTopLevelChanged(true);
@@ -357,7 +357,7 @@ namespace ADS
save(); save();
saveStartupWorkspace(); saveStartupWorkspace();
for (auto floatingWidget : d->m_floatingWidgets) { for (auto floatingWidget : qAsConst(d->m_floatingWidgets)) {
/* There have been crashes with partially destructed widgets in /* There have been crashes with partially destructed widgets in
m_floatingWidgets. Those do not have a parent. */ m_floatingWidgets. Those do not have a parent. */
if (floatingWidget && floatingWidget->parent() == this) if (floatingWidget && floatingWidget->parent() == this)
@@ -507,7 +507,7 @@ namespace ADS
stream.writeAttribute("version", QString::number(CurrentVersion)); stream.writeAttribute("version", QString::number(CurrentVersion));
stream.writeAttribute("userVersion", QString::number(version)); stream.writeAttribute("userVersion", QString::number(version));
stream.writeAttribute("containers", QString::number(d->m_containers.count())); stream.writeAttribute("containers", QString::number(d->m_containers.count()));
for (auto container : d->m_containers) for (auto container : qAsConst(d->m_containers))
container->saveState(stream); container->saveState(stream);
stream.writeEndElement(); stream.writeEndElement();
@@ -551,7 +551,7 @@ namespace ADS
if (d->m_uninitializedFloatingWidgets.empty()) if (d->m_uninitializedFloatingWidgets.empty())
return; return;
for (auto floatingWidget : d->m_uninitializedFloatingWidgets) for (auto floatingWidget : qAsConst(d->m_uninitializedFloatingWidgets))
floatingWidget->show(); floatingWidget->show();
d->m_uninitializedFloatingWidgets.clear(); d->m_uninitializedFloatingWidgets.clear();

View File

@@ -624,7 +624,7 @@ namespace ADS {
if (windowHandle()->devicePixelRatio() == d->m_lastDevicePixelRatio) // TODO if (windowHandle()->devicePixelRatio() == d->m_lastDevicePixelRatio) // TODO
return; return;
for (auto widget : d->m_dropIndicatorWidgets) for (auto widget : qAsConst(d->m_dropIndicatorWidgets))
d->updateDropIndicatorIcon(widget); d->updateDropIndicatorIcon(widget);
d->m_lastDevicePixelRatio = devicePixelRatioF(); d->m_lastDevicePixelRatio = devicePixelRatioF();

View File

@@ -829,7 +829,7 @@ void DiagramSceneModel::onEndRemoveElement(int row, const MDiagram *diagram)
Q_UNUSED(diagram) Q_UNUSED(diagram)
QMT_CHECK(m_busyState == RemoveElement); QMT_CHECK(m_busyState == RemoveElement);
// update elements from store (see above) // update elements from store (see above)
for (const Uid &end_uid : m_relationEndsUid) { for (const Uid &end_uid : qAsConst(m_relationEndsUid)) {
DElement *dEnd = m_diagramController->findElement(end_uid, diagram); DElement *dEnd = m_diagramController->findElement(end_uid, diagram);
if (dEnd) if (dEnd)
updateGraphicsItem(graphicsItem(dEnd), dEnd); updateGraphicsItem(graphicsItem(dEnd), dEnd);

View File

@@ -1220,7 +1220,7 @@ void ModelManagerInterface::updateImportPaths()
QSet<QString> newLibraries; QSet<QString> newLibraries;
for (const Document::Ptr &doc : qAsConst(snapshot)) for (const Document::Ptr &doc : qAsConst(snapshot))
findNewLibraryImports(doc, snapshot, this, &importedFiles, &scannedPaths, &newLibraries); findNewLibraryImports(doc, snapshot, this, &importedFiles, &scannedPaths, &newLibraries);
for (const QString &path : allApplicationDirectories) for (const QString &path : qAsConst(allApplicationDirectories))
findNewQmlApplicationInPath(path, snapshot, this, &newLibraries); findNewQmlApplicationInPath(path, snapshot, this, &newLibraries);
updateSourceFiles(importedFiles, true); updateSourceFiles(importedFiles, true);

View File

@@ -162,7 +162,7 @@ void SftpTransfer::doStart()
break; break;
} }
} }
for (const FileToTransfer &f : d->files) { for (const FileToTransfer &f : qAsConst(d->files)) {
QString sourceFileOrLinkTarget = f.sourceFile; QString sourceFileOrLinkTarget = f.sourceFile;
bool link = false; bool link = false;
if (d->transferType == Internal::FileTransferType::Upload) { if (d->transferType == Internal::FileTransferType::Upload) {

View File

@@ -1580,7 +1580,7 @@ void AspectContainer::addAspectHelper(BaseAspect *aspect)
*/ */
void AspectContainer::addToLayout(LayoutBuilder &builder) void AspectContainer::addToLayout(LayoutBuilder &builder)
{ {
for (BaseAspect *aspect : d->m_items) { for (BaseAspect *aspect : qAsConst(d->m_items)) {
if (aspect->isVisible()) if (aspect->isVisible())
aspect->addToLayout(builder); aspect->addToLayout(builder);
} }
@@ -1591,7 +1591,7 @@ void AspectContainer::addToLayout(LayoutBuilder &builder)
*/ */
void AspectContainer::fromMap(const QVariantMap &map) void AspectContainer::fromMap(const QVariantMap &map)
{ {
for (BaseAspect *aspect : d->m_items) for (BaseAspect *aspect : qAsConst(d->m_items))
aspect->fromMap(map); aspect->fromMap(map);
} }
@@ -1600,7 +1600,7 @@ void AspectContainer::fromMap(const QVariantMap &map)
*/ */
void AspectContainer::toMap(QVariantMap &map) const void AspectContainer::toMap(QVariantMap &map) const
{ {
for (BaseAspect *aspect : d->m_items) for (BaseAspect *aspect : qAsConst(d->m_items))
aspect->toMap(map); aspect->toMap(map);
} }

View File

@@ -89,14 +89,13 @@ static QList<Diff> decode(const QList<Diff> &diffList, const QStringList &lines)
{ {
QList<Diff> newDiffList; QList<Diff> newDiffList;
newDiffList.reserve(diffList.count()); newDiffList.reserve(diffList.count());
for (Diff diff : diffList) { for (const Diff &diff : diffList) {
QString text; QString text;
for (QChar c : diff.text) { for (QChar c : diff.text) {
const int idx = static_cast<ushort>(c.unicode()); const int idx = static_cast<ushort>(c.unicode());
text += lines.value(idx); text += lines.value(idx);
} }
diff.text = text; newDiffList.append({diff.command, text});
newDiffList.append(diff);
} }
return newDiffList; return newDiffList;
} }

View File

@@ -467,7 +467,7 @@ void FileSystemWatcher::slotDirectoryChanged(const QString &path)
toReadd.removeOne(rejected); toReadd.removeOne(rejected);
// If we've successfully added the file, that means it was deleted and replaced. // If we've successfully added the file, that means it was deleted and replaced.
for (const QString &reAdded : toReadd) for (const QString &reAdded : qAsConst(toReadd))
d->fileChanged(reAdded); d->fileChanged(reAdded);
} }
} }

View File

@@ -257,7 +257,7 @@ void InfoBarDisplay::infoBarDestroyed()
void InfoBarDisplay::update() void InfoBarDisplay::update()
{ {
for (QWidget *widget : m_infoWidgets) { for (QWidget *widget : qAsConst(m_infoWidgets)) {
widget->disconnect(this); // We want no destroyed() signal now widget->disconnect(this); // We want no destroyed() signal now
delete widget; delete widget;
} }
@@ -266,7 +266,7 @@ void InfoBarDisplay::update()
if (!m_infoBar) if (!m_infoBar)
return; return;
for (const InfoBarEntry &info : m_infoBar->m_infoBarEntries) { for (const InfoBarEntry &info : qAsConst(m_infoBar->m_infoBarEntries)) {
auto infoWidget = new InfoBarWidget(m_edge); auto infoWidget = new InfoBarWidget(m_edge);
auto hbox = new QHBoxLayout; auto hbox = new QHBoxLayout;

View File

@@ -363,7 +363,7 @@ QStringList MimeType::suffixes() const
MimeDatabasePrivate::instance()->provider()->loadMimeTypePrivate(*d); MimeDatabasePrivate::instance()->provider()->loadMimeTypePrivate(*d);
QStringList result; QStringList result;
for (const QString &pattern : d->globPatterns) { for (const QString &pattern : qAsConst(d->globPatterns)) {
const QString suffix = suffixFromPattern(pattern); const QString suffix = suffixFromPattern(pattern);
if (!suffix.isEmpty()) if (!suffix.isEmpty())
result.append(suffix); result.append(suffix);

View File

@@ -164,7 +164,7 @@ bool PortList::hasMore() const { return !d->ranges.isEmpty(); }
bool PortList::contains(Port port) const bool PortList::contains(Port port) const
{ {
for (const Internal::Range &r : d->ranges) { for (const Internal::Range &r : qAsConst(d->ranges)) {
if (port >= r.first && port <= r.second) if (port >= r.first && port <= r.second)
return true; return true;
} }
@@ -174,7 +174,7 @@ bool PortList::contains(Port port) const
int PortList::count() const int PortList::count() const
{ {
int n = 0; int n = 0;
for (const Internal::Range &r : d->ranges) for (const Internal::Range &r : qAsConst(d->ranges))
n += r.second.number() - r.first.number() + 1; n += r.second.number() - r.first.number() + 1;
return n; return n;
} }
@@ -194,7 +194,7 @@ Port PortList::getNext()
QString PortList::toString() const QString PortList::toString() const
{ {
QString stringRep; QString stringRep;
for (const Internal::Range &range : d->ranges) { for (const Internal::Range &range : qAsConst(d->ranges)) {
stringRep += QString::number(range.first.number()); stringRep += QString::number(range.first.number());
if (range.second != range.first) if (range.second != range.first)
stringRep += QLatin1Char('-') + QString::number(range.second.number()); stringRep += QLatin1Char('-') + QString::number(range.second.number());