forked from qt-creator/qt-creator
ScXMLEditor: Remove foreach / Q_FOREACH usage
Task-number: QTCREATORBUG-27464 Change-Id: Ic439470b7c23022fee6acbf0cdaba7760309edb0 Reviewed-by: <github-actions-qt-creator@cristianadam.eu> Reviewed-by: Alessandro Portale <alessandro.portale@qt.io>
This commit is contained in:
@@ -67,7 +67,7 @@ GraphicsScene::~GraphicsScene()
|
||||
void GraphicsScene::unselectAll()
|
||||
{
|
||||
const QList<QGraphicsItem*> selectedItems = this->selectedItems();
|
||||
foreach (QGraphicsItem *it, selectedItems)
|
||||
for (QGraphicsItem *it : selectedItems)
|
||||
it->setSelected(false);
|
||||
if (m_document)
|
||||
m_document->setCurrentTag(nullptr);
|
||||
@@ -75,20 +75,20 @@ void GraphicsScene::unselectAll()
|
||||
|
||||
void GraphicsScene::unhighlightAll()
|
||||
{
|
||||
foreach (BaseItem *it, m_baseItems)
|
||||
for (BaseItem *it : qAsConst(m_baseItems))
|
||||
it->setHighlight(false);
|
||||
}
|
||||
|
||||
void GraphicsScene::highlightItems(const QVector<ScxmlTag*> &lstIds)
|
||||
{
|
||||
foreach (BaseItem *it, m_baseItems)
|
||||
for (BaseItem *it : qAsConst(m_baseItems))
|
||||
it->setHighlight(lstIds.contains(it->tag()));
|
||||
}
|
||||
|
||||
QRectF GraphicsScene::selectedBoundingRect() const
|
||||
{
|
||||
QRectF r;
|
||||
foreach (BaseItem *item, m_baseItems) {
|
||||
for (BaseItem *item : qAsConst(m_baseItems)) {
|
||||
if (item->isSelected())
|
||||
r = r.united(item->sceneBoundingRect());
|
||||
}
|
||||
@@ -98,7 +98,7 @@ QRectF GraphicsScene::selectedBoundingRect() const
|
||||
qreal GraphicsScene::selectedMaxWidth() const
|
||||
{
|
||||
qreal maxw = 0;
|
||||
foreach (BaseItem *item, m_baseItems) {
|
||||
for (BaseItem *item : qAsConst(m_baseItems)) {
|
||||
if (item->isSelected() && item->type() >= InitialStateType)
|
||||
maxw = qMax(maxw, item->sceneBoundingRect().width());
|
||||
}
|
||||
@@ -108,7 +108,7 @@ qreal GraphicsScene::selectedMaxWidth() const
|
||||
qreal GraphicsScene::selectedMaxHeight() const
|
||||
{
|
||||
qreal maxh = 0;
|
||||
foreach (BaseItem *item, m_baseItems) {
|
||||
for (BaseItem *item : qAsConst(m_baseItems)) {
|
||||
if (item->isSelected() && item->type() >= InitialStateType)
|
||||
maxh = qMax(maxh, item->sceneBoundingRect().height());
|
||||
}
|
||||
@@ -124,37 +124,37 @@ void GraphicsScene::alignStates(int alignType)
|
||||
if (r.isValid()) {
|
||||
switch (alignType) {
|
||||
case ActionAlignLeft:
|
||||
foreach (BaseItem *item, m_baseItems) {
|
||||
for (BaseItem *item : qAsConst(m_baseItems)) {
|
||||
if (item->isSelected() && item->type() >= InitialStateType)
|
||||
item->moveStateBy(r.left() - item->sceneBoundingRect().left(), 0);
|
||||
}
|
||||
break;
|
||||
case ActionAlignRight:
|
||||
foreach (BaseItem *item, m_baseItems) {
|
||||
for (BaseItem *item : qAsConst(m_baseItems)) {
|
||||
if (item->isSelected() && item->type() >= InitialStateType)
|
||||
item->moveStateBy(r.right() - item->sceneBoundingRect().right(), 0);
|
||||
}
|
||||
break;
|
||||
case ActionAlignTop:
|
||||
foreach (BaseItem *item, m_baseItems) {
|
||||
for (BaseItem *item : qAsConst(m_baseItems)) {
|
||||
if (item->isSelected() && item->type() >= InitialStateType)
|
||||
item->moveStateBy(0, r.top() - item->sceneBoundingRect().top());
|
||||
}
|
||||
break;
|
||||
case ActionAlignBottom:
|
||||
foreach (BaseItem *item, m_baseItems) {
|
||||
for (BaseItem *item : qAsConst(m_baseItems)) {
|
||||
if (item->isSelected() && item->type() >= InitialStateType)
|
||||
item->moveStateBy(0, r.bottom() - item->sceneBoundingRect().bottom());
|
||||
}
|
||||
break;
|
||||
case ActionAlignHorizontal:
|
||||
foreach (BaseItem *item, m_baseItems) {
|
||||
for (BaseItem *item : qAsConst(m_baseItems)) {
|
||||
if (item->isSelected() && item->type() >= InitialStateType)
|
||||
item->moveStateBy(0, r.center().y() - item->sceneBoundingRect().center().y());
|
||||
}
|
||||
break;
|
||||
case ActionAlignVertical:
|
||||
foreach (BaseItem *item, m_baseItems) {
|
||||
for (BaseItem *item : qAsConst(m_baseItems)) {
|
||||
if (item->isSelected() && item->type() >= InitialStateType)
|
||||
item->moveStateBy(r.center().x() - item->sceneBoundingRect().center().x(), 0);
|
||||
}
|
||||
@@ -175,7 +175,7 @@ void GraphicsScene::adjustStates(int adjustType)
|
||||
qreal maxw = selectedMaxWidth();
|
||||
qreal maxh = selectedMaxHeight();
|
||||
|
||||
foreach (BaseItem *item, m_baseItems) {
|
||||
for (BaseItem *item : qAsConst(m_baseItems)) {
|
||||
if (item->isSelected() && item->type() >= InitialStateType) {
|
||||
QRectF rr = item->boundingRect();
|
||||
if ((adjustType == ActionAdjustWidth || adjustType == ActionAdjustSize) && !qFuzzyCompare(rr.width(), maxw))
|
||||
@@ -223,7 +223,7 @@ void GraphicsScene::copy()
|
||||
QVector<ScxmlTag*> tags;
|
||||
if (m_document->currentTag()->tagType() == Scxml) {
|
||||
QVector<BaseItem*> items;
|
||||
foreach (BaseItem *item, m_baseItems) {
|
||||
for (BaseItem *item : qAsConst(m_baseItems)) {
|
||||
if (!item->parentItem())
|
||||
items << item;
|
||||
}
|
||||
@@ -241,9 +241,9 @@ void GraphicsScene::copy()
|
||||
mime->setText(QLatin1String(result));
|
||||
mime->setData("StateChartEditor/StateData", result);
|
||||
QStringList strTypes;
|
||||
foreach (const ScxmlTag *tag, tags) {
|
||||
for (const ScxmlTag *tag : qAsConst(tags))
|
||||
strTypes << tag->tagName(false);
|
||||
}
|
||||
|
||||
mime->setData("StateChartEditor/CopiedTagTypes", strTypes.join(",").toLocal8Bit());
|
||||
mime->setData("StateChartEditor/CopiedMinPos", QString::fromLatin1("%1:%2").arg(minPos.x()).arg(minPos.y()).toLocal8Bit());
|
||||
QGuiApplication::clipboard()->setMimeData(mime);
|
||||
@@ -267,7 +267,7 @@ void GraphicsScene::paste(const QPointF &targetPos)
|
||||
QPointF startPos(targetPos);
|
||||
|
||||
BaseItem *targetItem = nullptr;
|
||||
foreach (BaseItem *item, m_baseItems) {
|
||||
for (BaseItem *item : qAsConst(m_baseItems)) {
|
||||
if (item->isSelected() && item->type() >= StateType) {
|
||||
targetItem = item;
|
||||
break;
|
||||
@@ -296,7 +296,7 @@ void GraphicsScene::paste(const QPointF &targetPos)
|
||||
|
||||
void GraphicsScene::setEditorInfo(const QString &key, const QString &value)
|
||||
{
|
||||
foreach (BaseItem *item, m_baseItems) {
|
||||
for (BaseItem *item : qAsConst(m_baseItems)) {
|
||||
if (item->isSelected() && item->type() >= TransitionType)
|
||||
item->setEditorInfo(key, value);
|
||||
}
|
||||
@@ -371,7 +371,7 @@ void GraphicsScene::runLayoutToSelectedStates()
|
||||
m_document->undoStack()->beginMacro(tr("Re-layout"));
|
||||
|
||||
QVector<BaseItem*> selectedItems;
|
||||
foreach (BaseItem *node, m_baseItems) {
|
||||
for (BaseItem *node : qAsConst(m_baseItems)) {
|
||||
if (node->isSelected()) {
|
||||
int index = 0;
|
||||
for (int i = 0; i < selectedItems.count(); ++i) {
|
||||
@@ -391,22 +391,20 @@ void GraphicsScene::runLayoutToSelectedStates()
|
||||
// Layout scene items if necessary
|
||||
if (selectedItems.isEmpty()) {
|
||||
QList<QGraphicsItem*> sceneItems;
|
||||
foreach (BaseItem *item, m_baseItems) {
|
||||
for (BaseItem *item : qAsConst(m_baseItems)) {
|
||||
if (item->type() >= InitialStateType && !item->parentItem())
|
||||
sceneItems << item;
|
||||
}
|
||||
SceneUtils::layout(sceneItems);
|
||||
|
||||
foreach (QGraphicsItem *item, sceneItems) {
|
||||
for (QGraphicsItem *item : qAsConst(sceneItems))
|
||||
if (item->type() >= StateType)
|
||||
static_cast<StateItem*>(item)->shrink();
|
||||
}
|
||||
}
|
||||
|
||||
// Update properties
|
||||
foreach (BaseItem *node, selectedItems) {
|
||||
for (BaseItem *node : qAsConst(selectedItems))
|
||||
node->updateUIProperties();
|
||||
}
|
||||
|
||||
m_document->undoStack()->endMacro();
|
||||
}
|
||||
@@ -417,31 +415,31 @@ void GraphicsScene::runAutomaticLayout()
|
||||
|
||||
// 1. Find max depth
|
||||
int maxDepth = 0;
|
||||
foreach (BaseItem *node, m_baseItems) {
|
||||
for (BaseItem *node : qAsConst(m_baseItems)) {
|
||||
maxDepth = qMax(maxDepth, node->depth());
|
||||
node->setBlockUpdates(true);
|
||||
}
|
||||
|
||||
// 2. Layout every depth-level separately
|
||||
for (int d = (maxDepth + 1); d--;) {
|
||||
foreach (BaseItem *node, m_baseItems)
|
||||
for (BaseItem *node : qAsConst(m_baseItems))
|
||||
node->doLayout(d);
|
||||
}
|
||||
|
||||
// 3. Layout scene items
|
||||
QList<QGraphicsItem*> sceneItems;
|
||||
foreach (BaseItem *item, m_baseItems) {
|
||||
for (BaseItem *item : qAsConst(m_baseItems)) {
|
||||
if (item->type() >= InitialStateType && !item->parentItem())
|
||||
sceneItems << item;
|
||||
}
|
||||
SceneUtils::layout(sceneItems);
|
||||
|
||||
foreach (QGraphicsItem *item, sceneItems) {
|
||||
for (QGraphicsItem *item : qAsConst(sceneItems)) {
|
||||
if (item->type() >= StateType)
|
||||
static_cast<StateItem*>(item)->shrink();
|
||||
}
|
||||
|
||||
foreach (BaseItem *node, m_baseItems) {
|
||||
for (BaseItem *node : qAsConst(m_baseItems)) {
|
||||
node->updateUIProperties();
|
||||
node->setBlockUpdates(false);
|
||||
}
|
||||
@@ -468,21 +466,21 @@ void GraphicsScene::endTagChange(ScxmlDocument::TagChange change, ScxmlTag *tag,
|
||||
|
||||
switch (change) {
|
||||
case ScxmlDocument::TagAttributesChanged: {
|
||||
foreach (BaseItem *item, m_baseItems) {
|
||||
for (BaseItem *item : qAsConst(m_baseItems)) {
|
||||
if (item->tag() == tag)
|
||||
item->updateAttributes();
|
||||
}
|
||||
break;
|
||||
}
|
||||
case ScxmlDocument::TagEditorInfoChanged: {
|
||||
foreach (BaseItem *item, m_baseItems) {
|
||||
for (BaseItem *item : qAsConst(m_baseItems)) {
|
||||
if (item->tag() == tag)
|
||||
item->updateEditorInfo();
|
||||
}
|
||||
break;
|
||||
}
|
||||
case ScxmlDocument::TagCurrentChanged: {
|
||||
foreach (BaseItem *item, m_baseItems) {
|
||||
for (BaseItem *item : qAsConst(m_baseItems)) {
|
||||
if (!item->isSelected() && item->tag() == tag)
|
||||
item->setSelected(true);
|
||||
}
|
||||
@@ -725,7 +723,7 @@ BaseItem *GraphicsScene::findItem(const ScxmlTag *tag) const
|
||||
if (!tag)
|
||||
return nullptr;
|
||||
|
||||
foreach (BaseItem *it, m_baseItems) {
|
||||
for (BaseItem *it : qAsConst(m_baseItems)) {
|
||||
if (it->tag() == tag)
|
||||
return it;
|
||||
}
|
||||
@@ -738,7 +736,7 @@ void GraphicsScene::removeItems(const ScxmlTag *tag)
|
||||
if (tag) {
|
||||
// Find right items
|
||||
QVector<BaseItem*> items;
|
||||
foreach (BaseItem *it, m_baseItems) {
|
||||
for (BaseItem *it : qAsConst(m_baseItems)) {
|
||||
if (it->tag() == tag)
|
||||
items << it;
|
||||
}
|
||||
@@ -764,7 +762,7 @@ QPair<bool, bool> GraphicsScene::checkSnapToItem(BaseItem *item, const QPointF &
|
||||
qreal diffY = 8;
|
||||
qreal diffYdX = 2000;
|
||||
|
||||
foreach (BaseItem *it, m_baseItems) {
|
||||
for (BaseItem *it : qAsConst(m_baseItems)) {
|
||||
if (!it->isSelected() && it != item && it->parentItem() == parentItem && it->type() >= InitialStateType) {
|
||||
QPointF c = it->sceneCenter();
|
||||
qreal dX = qAbs(c.x() - p.x());
|
||||
@@ -802,7 +800,7 @@ void GraphicsScene::selectionChanged(bool para)
|
||||
int baseCount = 0;
|
||||
int stateTypeCount = 0;
|
||||
|
||||
foreach (BaseItem *item, m_baseItems) {
|
||||
for (BaseItem *item : qAsConst(m_baseItems)) {
|
||||
if (item->isSelected()) {
|
||||
if (item->type() >= TransitionType)
|
||||
baseCount++;
|
||||
@@ -848,22 +846,20 @@ void GraphicsScene::removeWarningItem(WarningItem *item)
|
||||
void GraphicsScene::warningVisibilityChanged(int type, WarningItem *item)
|
||||
{
|
||||
if (!m_autoLayoutRunning && !m_initializing) {
|
||||
foreach (WarningItem *it, m_allWarnings) {
|
||||
for (WarningItem *it : qAsConst(m_allWarnings))
|
||||
if (it != item && (type == 0 || it->type() == type))
|
||||
it->check();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ScxmlTag *GraphicsScene::tagByWarning(const ScxmlEditor::OutputPane::Warning *w) const
|
||||
{
|
||||
ScxmlTag *tag = nullptr;
|
||||
foreach (WarningItem *it, m_allWarnings) {
|
||||
for (WarningItem *it : qAsConst(m_allWarnings))
|
||||
if (it->warning() == w) {
|
||||
tag = it->tag();
|
||||
break;
|
||||
}
|
||||
}
|
||||
return tag;
|
||||
}
|
||||
|
||||
@@ -921,7 +917,7 @@ void GraphicsScene::removeChild(BaseItem *item)
|
||||
|
||||
void GraphicsScene::checkItemsVisibility(double scaleFactor)
|
||||
{
|
||||
foreach (BaseItem *item, m_baseItems) {
|
||||
for (BaseItem *item : qAsConst(m_baseItems)) {
|
||||
item->checkVisibility(scaleFactor);
|
||||
}
|
||||
}
|
||||
@@ -930,7 +926,7 @@ void GraphicsScene::checkInitialState()
|
||||
{
|
||||
if (m_document) {
|
||||
QList<QGraphicsItem*> sceneItems;
|
||||
foreach (BaseItem *item, m_baseItems) {
|
||||
for (BaseItem *item : qAsConst(m_baseItems)) {
|
||||
if (item->type() >= InitialStateType && !item->parentItem())
|
||||
sceneItems << item;
|
||||
}
|
||||
@@ -944,14 +940,14 @@ void GraphicsScene::checkInitialState()
|
||||
|
||||
void GraphicsScene::clearAllTags()
|
||||
{
|
||||
foreach (BaseItem *it, m_baseItems) {
|
||||
for (BaseItem *it : qAsConst(m_baseItems)) {
|
||||
it->setTag(nullptr);
|
||||
}
|
||||
}
|
||||
|
||||
void GraphicsScene::setBlockUpdates(bool block)
|
||||
{
|
||||
foreach (BaseItem *it, m_baseItems) {
|
||||
for (BaseItem *it : qAsConst(m_baseItems)) {
|
||||
it->setBlockUpdates(block);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user