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

Change-Id: I7fb1c012b4e6b0608c5888d58c7752b194baf78b
Reviewed-by: Mahmoud Badri <mahmoud.badri@qt.io>
This commit is contained in:
Alessandro Portale
2021-02-17 17:12:22 +01:00
parent ae5255cebd
commit e2dd9639e5
23 changed files with 60 additions and 60 deletions

View File

@@ -145,7 +145,7 @@ void AssetExporter::exportQml(const Utils::FilePaths &qmlFiles, const Utils::Fil
void AssetExporter::beginExport()
{
for (const Utils::FilePath &p : m_exportFiles) {
for (const Utils::FilePath &p : qAsConst(m_exportFiles)) {
if (m_cancelled)
break;
preprocessQmlFile(p);

View File

@@ -456,7 +456,7 @@ void ActionEditorDialog::fillAndSetTargetItem(const QString &value, bool useDefa
{
if (m_comboBoxType->currentIndex() == ConnectionType::Action) {
m_actionTargetItem->clear();
for (const auto &connection : m_connections) {
for (const auto &connection : qAsConst(m_connections)) {
if (!connection.methods.isEmpty())
m_actionTargetItem->addItem(connection.item);
}
@@ -471,7 +471,7 @@ void ActionEditorDialog::fillAndSetTargetItem(const QString &value, bool useDefa
}
} else { // ConnectionType::Assignment
m_assignmentTargetItem->clear();
for (const auto &connection : m_connections) {
for (const auto &connection : qAsConst(m_connections)) {
if (!connection.properties.isEmpty())
m_assignmentTargetItem->addItem(connection.item);
}
@@ -516,7 +516,7 @@ void ActionEditorDialog::fillAndSetTargetProperty(const QString &value, bool use
if (idx == -1) {
insertAndSetUndefined(m_assignmentTargetProperty);
} else {
for (const auto &property : m_connections[idx].properties)
for (const auto &property : qAsConst(m_connections[idx].properties))
m_assignmentTargetProperty->addItem(property.name, property.type);
if (m_assignmentTargetProperty->findText(value) != -1) {
@@ -537,7 +537,7 @@ void ActionEditorDialog::fillAndSetSourceItem(const QString &value, bool useDefa
const TypeName targetPropertyType = m_assignmentTargetProperty->currentData().value<TypeName>();
if (!targetPropertyType.isEmpty()) {
for (const ConnectionOption &connection : m_connections) {
for (const ConnectionOption &connection : qAsConst(m_connections)) {
if (!connection.containsType(targetPropertyType))
continue;
@@ -545,7 +545,7 @@ void ActionEditorDialog::fillAndSetSourceItem(const QString &value, bool useDefa
}
// Add Constants
for (const SingletonOption &singleton : m_singletons) {
for (const SingletonOption &singleton : qAsConst(m_singletons)) {
if (!singleton.containsType(targetPropertyType))
continue;
@@ -581,7 +581,7 @@ void ActionEditorDialog::fillAndSetSourceProperty(const QString &value,
else
insertAndSetUndefined(m_assignmentSourceProperty);
} else if (targetProperty == "state") {
for (const auto &state : m_states)
for (const auto &state : qAsConst(m_states))
m_assignmentSourceProperty->addItem(state, specificItem);
if (m_assignmentSourceProperty->findText(value) != -1)
@@ -610,7 +610,7 @@ void ActionEditorDialog::fillAndSetSourceProperty(const QString &value,
m_assignmentSourceProperty->addItem("false", specificItem);
specificsEnd = 2;
} else if (targetProperty == "state") {
for (const auto &state : m_states)
for (const auto &state : qAsConst(m_states))
m_assignmentSourceProperty->addItem(state, specificItem);
specificsEnd = m_states.count();
@@ -620,14 +620,14 @@ void ActionEditorDialog::fillAndSetSourceProperty(const QString &value,
m_assignmentSourceProperty->insertSeparator(specificsEnd);
if (sourceItemType == singletonItem) {
for (const auto &property : m_singletons[idx].properties) {
for (const auto &property : qAsConst(m_singletons[idx].properties)) {
if (targetPropertyType.isEmpty() // TODO isEmpty correct?!
|| property.type == targetPropertyType
|| (isNumeric(property.type) && isNumeric(targetPropertyType)))
m_assignmentSourceProperty->addItem(property.name, property.type);
}
} else {
for (const auto &property : m_connections[idx].properties) {
for (const auto &property : qAsConst(m_connections[idx].properties)) {
if (targetPropertyType.isEmpty() // TODO isEmpty correct?!
|| property.type == targetPropertyType
|| (isNumeric(property.type) && isNumeric(targetPropertyType)))

View File

@@ -135,7 +135,7 @@ void BindingEditorDialog::setupComboBoxes()
m_comboBoxItem->clear();
m_comboBoxProperty->clear();
for (const auto &bind : m_bindings)
for (const auto &bind : qAsConst(m_bindings))
m_comboBoxItem->addItem(bind.item);
}

View File

@@ -90,7 +90,7 @@ DesignerActionToolBar *DesignerActionManager::createToolBar(QWidget *parent) con
return l->priority() > r->priority();
});
for (auto *categoryAction : categories) {
for (auto *categoryAction : qAsConst(categories)) {
QList<ActionInterface* > actions = Utils::filtered(designerActions(), [categoryAction](ActionInterface *action) {
return action->category() == categoryAction->menuId();
});
@@ -101,7 +101,7 @@ DesignerActionToolBar *DesignerActionManager::createToolBar(QWidget *parent) con
bool addSeparator = false;
for (auto *action : actions) {
for (auto *action : qAsConst(actions)) {
if ((action->type() == ActionInterface::Action || action->type() == ActionInterface::ToolBarAction)
&& action->action()) {
toolBar->registerAction(action);
@@ -164,7 +164,7 @@ QGraphicsWidget *DesignerActionManager::createFormEditorToolBar(QGraphicsItem *p
layout->setSpacing(0);
toolbar->setLayout(layout);
for (ActionInterface *action : actions) {
for (ActionInterface *action : qAsConst(actions)) {
auto button = new FormEditorToolButton(action->action(), toolbar);
layout->addItem(button);
}
@@ -1490,7 +1490,7 @@ void DesignerActionManager::addCreatorCommand(Core::Command *command, const QByt
QList<QSharedPointer<ActionInterface> > DesignerActionManager::actionsForTargetView(const ActionInterface::TargetView &target)
{
QList<QSharedPointer<ActionInterface> > out;
for (auto interface : m_designerActions)
for (auto interface : qAsConst(m_designerActions))
if (interface->targetView() == target)
out << interface;

View File

@@ -147,7 +147,7 @@ void CurveItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidg
void CurveItem::lockedCallback()
{
for (auto frame : m_keyframes)
for (auto frame : qAsConst(m_keyframes))
frame->setLocked(locked());
setHandleVisibility(!locked());
@@ -381,7 +381,7 @@ void CurveItem::setDirty(bool dirty)
void CurveItem::setHandleVisibility(bool visible)
{
for (auto frame : m_keyframes)
for (auto frame : qAsConst(m_keyframes))
frame->setHandleVisibility(visible);
}
@@ -416,7 +416,7 @@ QRectF CurveItem::setComponentTransform(const QTransform &transform)
{
prepareGeometryChange();
m_transform = transform;
for (auto frame : m_keyframes)
for (auto frame : qAsConst(m_keyframes))
frame->setComponentTransform(transform);
return boundingRect();
@@ -426,7 +426,7 @@ void CurveItem::setStyle(const CurveEditorStyle &style)
{
m_style = style.curveStyle;
for (auto *frame : m_keyframes)
for (auto *frame : qAsConst(m_keyframes))
frame->setStyle(style);
}
@@ -459,7 +459,7 @@ void CurveItem::toggleUnified()
if (m_keyframes.empty())
return;
for (auto *frame : m_keyframes) {
for (auto *frame : qAsConst(m_keyframes)) {
if (frame->selected())
frame->toggleUnified();
}

View File

@@ -216,21 +216,21 @@ void GraphicsScene::reset()
void GraphicsScene::deleteSelectedKeyframes()
{
for (auto *curve : m_curves)
for (auto *curve : qAsConst(m_curves))
curve->deleteSelectedKeyframes();
}
void GraphicsScene::insertKeyframe(double time, bool all)
{
if (!all) {
for (auto *curve : m_curves) {
for (auto *curve : qAsConst(m_curves)) {
if (curve->isUnderMouse())
curve->insertKeyframeByTime(std::round(time));
}
return;
}
for (auto *curve : m_curves)
for (auto *curve : qAsConst(m_curves))
curve->insertKeyframeByTime(std::round(time));
}
@@ -242,7 +242,7 @@ void GraphicsScene::doNotMoveItems(bool val)
void GraphicsScene::removeCurveItem(unsigned int id)
{
CurveItem *tmp = nullptr;
for (auto *curve : m_curves) {
for (auto *curve : qAsConst(m_curves)) {
if (curve->id() == id) {
removeItem(curve);
tmp = curve;
@@ -260,7 +260,7 @@ void GraphicsScene::removeCurveItem(unsigned int id)
void GraphicsScene::addCurveItem(CurveItem *item)
{
for (auto *curve : m_curves) {
for (auto *curve : qAsConst(m_curves)) {
if (curve->id() == item->id()) {
delete item;
return;
@@ -301,7 +301,7 @@ void GraphicsScene::setComponentTransform(const QTransform &transform)
{
QRectF bounds;
for (auto *curve : m_curves)
for (auto *curve : qAsConst(m_curves))
bounds = bounds.united(curve->setComponentTransform(transform));
if (bounds.isNull()) {
@@ -315,7 +315,7 @@ void GraphicsScene::setComponentTransform(const QTransform &transform)
void GraphicsScene::keyframeMoved(KeyframeItem *movedItem, const QPointF &direction)
{
for (auto *curve : m_curves) {
for (auto *curve : qAsConst(m_curves)) {
for (auto *keyframe : curve->keyframes()) {
if (keyframe != movedItem && keyframe->selected())
keyframe->moveKeyframe(direction);
@@ -325,7 +325,7 @@ void GraphicsScene::keyframeMoved(KeyframeItem *movedItem, const QPointF &direct
void GraphicsScene::handleUnderMouse(HandleItem *handle)
{
for (auto *curve : m_curves) {
for (auto *curve : qAsConst(m_curves)) {
for (auto *keyframe : curve->keyframes()) {
if (keyframe->selected())
keyframe->setActivated(handle->isUnderMouse(), handle->slot());
@@ -350,7 +350,7 @@ void GraphicsScene::handleMoved(KeyframeItem *frame,
}
};
for (auto *curve : m_curves) {
for (auto *curve : qAsConst(m_curves)) {
for (auto *keyframe : curve->keyframes()) {
if (keyframe == frame)
moveUnified(keyframe);
@@ -371,7 +371,7 @@ void GraphicsScene::setPinned(uint id, bool pinned)
std::vector<CurveItem *> GraphicsScene::takePinnedItems()
{
std::vector<CurveItem *> out;
for (auto *curve : m_curves) {
for (auto *curve : qAsConst(m_curves)) {
if (curve->pinned())
out.push_back(curve);
}
@@ -392,7 +392,7 @@ void GraphicsScene::mouseMoveEvent(QGraphicsSceneMouseEvent *mouseEvent)
QPointF mouse = mouseEvent->scenePos();
bool hasHandle = false;
for (auto *curve : m_curves) {
for (auto *curve : qAsConst(m_curves)) {
for (auto *handle : curve->handles()) {
bool intersects = handle->contains(mouse);
handle->setIsUnderMouse(intersects);
@@ -402,10 +402,10 @@ void GraphicsScene::mouseMoveEvent(QGraphicsSceneMouseEvent *mouseEvent)
}
if (hasHandle) {
for (auto *curve : m_curves)
for (auto *curve : qAsConst(m_curves))
curve->setIsUnderMouse(false);
} else {
for (auto *curve : m_curves)
for (auto *curve : qAsConst(m_curves))
curve->setIsUnderMouse(curve->contains(mouseEvent->scenePos()));
}
}
@@ -414,7 +414,7 @@ void GraphicsScene::mouseReleaseEvent(QGraphicsSceneMouseEvent *mouseEvent)
{
QGraphicsScene::mouseReleaseEvent(mouseEvent);
for (auto *curve : m_curves) {
for (auto *curve : qAsConst(m_curves)) {
// CurveItems might become invalid after a keyframe-drag operation.
curve->restore();
if (curve->isDirty()) {

View File

@@ -562,7 +562,7 @@ void FormEditorView::changeToCustomTool()
const ModelNode selectedModelNode = selectedModelNodes().constFirst();
for (AbstractCustomTool *customTool : m_customToolList) {
for (AbstractCustomTool *customTool : qAsConst(m_customToolList)) {
if (customTool->wantHandleItem(selectedModelNode) > handlingRank) {
handlingRank = customTool->wantHandleItem(selectedModelNode);
selectedCustomTool = customTool;

View File

@@ -42,13 +42,13 @@ ResizeIndicator::~ResizeIndicator()
void ResizeIndicator::show()
{
for (ResizeController controller : m_itemControllerHash)
for (ResizeController controller : qAsConst(m_itemControllerHash))
controller.show();
}
void ResizeIndicator::hide()
{
for (ResizeController controller : m_itemControllerHash)
for (ResizeController controller : qAsConst(m_itemControllerHash))
controller.hide();
}

View File

@@ -42,13 +42,13 @@ RotationIndicator::~RotationIndicator()
void RotationIndicator::show()
{
for (RotationController controller : m_itemControllerHash)
for (RotationController controller : qAsConst(m_itemControllerHash))
controller.show();
}
void RotationIndicator::hide()
{
for (RotationController controller : m_itemControllerHash)
for (RotationController controller : qAsConst(m_itemControllerHash))
controller.hide();
}

View File

@@ -238,7 +238,7 @@ ItemLibraryAssetImportDialog::ItemLibraryAssetImportDialog(const QStringList &im
this, &ItemLibraryAssetImportDialog::setImportProgress);
addInfo(tr("Select import options and press \"Import\" to import the following files:"));
for (const auto &file : m_quick3DFiles)
for (const auto &file : qAsConst(m_quick3DFiles))
addInfo(file);
QTimer::singleShot(0, [this]() {

View File

@@ -408,7 +408,7 @@ void ItemLibraryAssetImporter::copyImportedFiles()
notifyProgress(0, progressTitle);
int counter = 0;
for (const QString &dirPath : m_overwrittenImports) {
for (const QString &dirPath : qAsConst(m_overwrittenImports)) {
QDir dir(dirPath);
if (dir.exists())
dir.removeRecursively();

View File

@@ -434,7 +434,7 @@ void ItemLibraryWidget::addResources(const QStringList &files)
if (fileNames.isEmpty()) {
QStringList filters;
for (const QString &key : sortedKeys) {
for (const QString &key : qAsConst(sortedKeys)) {
QString str = key + " (";
str.append(map.values(key).join(" "));
str.append(")");
@@ -461,7 +461,7 @@ void ItemLibraryWidget::addResources(const QStringList &files)
QMultiMap<QString, QString> partitionedFileNames;
for (const QString &fileName : fileNames) {
for (const QString &fileName : qAsConst(fileNames)) {
const QString suffix = "*." + QFileInfo(fileName).suffix().toLower();
const QString category = reverseMap.value(suffix);
partitionedFileNames.insert(category, fileName);

View File

@@ -330,7 +330,7 @@ void AlignDistribute::alignObjects(Target target, AlignTo alignTo, const QString
};
view->executeInTransaction("DesignerActionManager|" + operationName, [&]() {
for (const ModelNode &modelNode : selectedNodes) {
for (const ModelNode &modelNode : qAsConst(selectedNodes)) {
QTC_ASSERT(!modelNode.isRootNode(), continue);
if (QmlItemNode::isValidQmlItemNode(modelNode)) {
QmlItemNode qmlItemNode(modelNode);
@@ -455,7 +455,7 @@ void AlignDistribute::distributeObjects(Target target, AlignTo alignTo, const QS
return;
}
for (const ModelNode &modelNode : selectedNodes) {
for (const ModelNode &modelNode : qAsConst(selectedNodes)) {
if (QmlItemNode::isValidQmlItemNode(modelNode)) {
QmlItemNode qmlItemNode(modelNode);
qreal currentPosition;
@@ -494,7 +494,7 @@ void AlignDistribute::distributeObjects(Target target, AlignTo alignTo, const QS
const QByteArray operationName = "distribute" + QVariant::fromValue(target).toByteArray();
view->executeInTransaction("DesignerActionManager|" + operationName, [&]() {
for (const ModelNode &modelNode : selectedNodes) {
for (const ModelNode &modelNode : qAsConst(selectedNodes)) {
QTC_ASSERT(!modelNode.isRootNode(), continue);
if (QmlItemNode::isValidQmlItemNode(modelNode)) {
QmlItemNode qmlItemNode(modelNode);
@@ -590,7 +590,7 @@ void AlignDistribute::distributeSpacing(Dimension dimension,
}
}
for (const ModelNode &modelNode : selectedNodes) {
for (const ModelNode &modelNode : qAsConst(selectedNodes)) {
if (QmlItemNode::isValidQmlItemNode(modelNode)) {
const QmlItemNode qmlItemNode(modelNode);
qreal currentPosition;
@@ -627,7 +627,7 @@ void AlignDistribute::distributeSpacing(Dimension dimension,
: "distributeSpacingVertical";
view->executeInTransaction("DesignerActionManager|" + operationName, [&]() {
for (const ModelNode &modelNode : selectedNodes) {
for (const ModelNode &modelNode : qAsConst(selectedNodes)) {
QTC_ASSERT(!modelNode.isRootNode(), continue);
if (QmlItemNode::isValidQmlItemNode(modelNode)) {
QmlItemNode qmlItemNode(modelNode);

View File

@@ -263,7 +263,7 @@ void PropertyEditorContextObject::changeTypeName(const QString &typeName)
if (!incompatibleProperties.empty()) {
QString detailedText = QString("<b>Incompatible properties:</b><br>");
for (const auto &p : incompatibleProperties)
for (const auto &p : qAsConst(incompatibleProperties))
detailedText.append("- " + QString::fromUtf8(p) + "<br>");
detailedText.chop(QString("<br>").size());
@@ -283,7 +283,7 @@ void PropertyEditorContextObject::changeTypeName(const QString &typeName)
if (msgBox.exec() == QMessageBox::Cancel)
return;
for (auto p : incompatibleProperties)
for (auto p : qAsConst(incompatibleProperties))
selectedNode.removeProperty(p);
}

View File

@@ -206,7 +206,7 @@ bool EasingCurveDialog::apply()
return view->executeInTransaction("EasingCurveDialog::apply", [this](){
auto expression = m_splineEditor->easingCurve().toString();
for (const auto &frame : m_frames)
for (const auto &frame : qAsConst(m_frames))
frame.bindingProperty("easing.bezierCurve").setExpression(expression);
});
}

View File

@@ -254,7 +254,7 @@ std::vector<std::tuple<ModelNode, qreal>> getFramesRelative(const ModelNode &par
if (!sortedByTime.empty()) {
qreal firstTime = getTime(sortedByTime.first());
for (const ModelNode &keyframe : sortedByTime)
for (const ModelNode &keyframe : qAsConst(sortedByTime))
result.emplace_back(keyframe, getTime(keyframe) - firstTime);
}

View File

@@ -561,7 +561,7 @@ void AbstractScrollGraphicsScene::selectKeyframes(const SelectionMode &mode,
void AbstractScrollGraphicsScene::clearSelection()
{
for (auto *keyframe : m_selectedKeyframes)
for (auto *keyframe : qAsConst(m_selectedKeyframes))
if (keyframe)
keyframe->setHighlighted(false);

View File

@@ -150,7 +150,7 @@ void TimelineSelectionTool::reset()
void TimelineSelectionTool::resetHighlights()
{
for (auto *keyframe : m_aboutToSelectBuffer)
for (auto *keyframe : qAsConst(m_aboutToSelectBuffer))
if (scene()->isKeyframeSelected(keyframe))
keyframe->setHighlighted(true);
else

View File

@@ -456,7 +456,7 @@ void TimelineToolBar::resizeEvent(QResizeEvent *event)
int width = 0;
QWidget *spacer = nullptr;
for (auto *object : m_grp) {
for (auto *object : qAsConst(m_grp)) {
if (isSpacer(object))
spacer = qobject_cast<QWidget *>(object);
else

View File

@@ -248,7 +248,7 @@ void ModelToTextMerger::applyChanges()
textModifier->deactivateChangeSignals();
textModifier->startGroup();
for (auto action : m_rewriteActions) {
for (auto action : qAsConst(m_rewriteActions)) {
if (DebugRewriteActions)
qDebug() << "Next rewrite action:" << qPrintable(action->info());

View File

@@ -96,7 +96,7 @@ ViewManager::ViewManager()
ViewManager::~ViewManager()
{
for (const QPointer<AbstractView> &view : d->additionalViews)
for (const QPointer<AbstractView> &view : qAsConst(d->additionalViews))
delete view.data();
}

View File

@@ -150,7 +150,7 @@ DesignModeWidget::DesignModeWidget()
DesignModeWidget::~DesignModeWidget()
{
for (QPointer<QWidget> widget : m_viewWidgets) {
for (QPointer<QWidget> widget : qAsConst(m_viewWidgets)) {
if (widget)
widget.clear();
}
@@ -510,7 +510,7 @@ void DesignModeWidget::aboutToShowWorkspaces()
auto sortedWorkspaces = m_dockManager->workspaces();
Utils::sort(sortedWorkspaces);
for (const auto &workspace : sortedWorkspaces)
for (const auto &workspace : qAsConst(sortedWorkspaces))
{
QAction *action = ag->addAction(workspace);
action->setData(workspace);

View File

@@ -172,7 +172,7 @@ QWidget *FpsLabelAction::createWidget(QWidget *parent)
void FpsLabelAction::refreshFpsLabel(quint16 frames)
{
for (const auto &labelPointer : fpsHandlerLabelList) {
for (const auto &labelPointer : qAsConst(fpsHandlerLabelList)) {
if (labelPointer)
labelPointer->setText(QString("%1 FPS").arg(frames));
}