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:
@@ -154,7 +154,7 @@ void Structure::addCheckbox(const QString &name, TagType type)
|
|||||||
void Structure::updateCheckBoxes()
|
void Structure::updateCheckBoxes()
|
||||||
{
|
{
|
||||||
QVector<TagType> visibleTags;
|
QVector<TagType> visibleTags;
|
||||||
foreach (QCheckBox *box, m_checkboxes) {
|
for (QCheckBox *box : qAsConst(m_checkboxes)) {
|
||||||
if (box->isChecked()) {
|
if (box->isChecked()) {
|
||||||
switch (TagType(box->property(Constants::C_SCXMLTAG_TAGTYPE).toInt())) {
|
switch (TagType(box->property(Constants::C_SCXMLTAG_TAGTYPE).toInt())) {
|
||||||
case State:
|
case State:
|
||||||
|
@@ -58,7 +58,7 @@ void WarningModel::clear(bool sendSignal)
|
|||||||
{
|
{
|
||||||
emit modelAboutToBeClear();
|
emit modelAboutToBeClear();
|
||||||
|
|
||||||
foreach (Warning *w, m_warnings)
|
for (Warning *w : qAsConst(m_warnings))
|
||||||
w->disconnect(this);
|
w->disconnect(this);
|
||||||
|
|
||||||
beginResetModel();
|
beginResetModel();
|
||||||
|
@@ -64,19 +64,16 @@ ConnectableItem::~ConnectableItem()
|
|||||||
{
|
{
|
||||||
setBlockUpdates(true);
|
setBlockUpdates(true);
|
||||||
|
|
||||||
foreach (ConnectableItem *item, m_overlappedItems) {
|
for (ConnectableItem *item : qAsConst(m_overlappedItems))
|
||||||
item->removeOverlappingItem(this);
|
item->removeOverlappingItem(this);
|
||||||
}
|
|
||||||
m_overlappedItems.clear();
|
m_overlappedItems.clear();
|
||||||
|
|
||||||
foreach (TransitionItem *transition, m_outputTransitions) {
|
for (TransitionItem *transition : qAsConst(m_outputTransitions))
|
||||||
transition->disconnectItem(this);
|
transition->disconnectItem(this);
|
||||||
}
|
|
||||||
m_outputTransitions.clear();
|
m_outputTransitions.clear();
|
||||||
|
|
||||||
foreach (TransitionItem *transition, m_inputTransitions) {
|
for (TransitionItem *transition : qAsConst(m_inputTransitions))
|
||||||
transition->disconnectItem(this);
|
transition->disconnectItem(this);
|
||||||
}
|
|
||||||
m_inputTransitions.clear();
|
m_inputTransitions.clear();
|
||||||
|
|
||||||
qDeleteAll(m_quickTransitions);
|
qDeleteAll(m_quickTransitions);
|
||||||
@@ -291,7 +288,7 @@ void ConnectableItem::removeInputTransition(TransitionItem *transition)
|
|||||||
|
|
||||||
void ConnectableItem::updateInputTransitions()
|
void ConnectableItem::updateInputTransitions()
|
||||||
{
|
{
|
||||||
foreach (TransitionItem *transition, m_inputTransitions) {
|
for (TransitionItem *transition : qAsConst(m_inputTransitions)) {
|
||||||
transition->updateComponents();
|
transition->updateComponents();
|
||||||
transition->updateUIProperties();
|
transition->updateUIProperties();
|
||||||
}
|
}
|
||||||
@@ -300,7 +297,7 @@ void ConnectableItem::updateInputTransitions()
|
|||||||
|
|
||||||
void ConnectableItem::updateOutputTransitions()
|
void ConnectableItem::updateOutputTransitions()
|
||||||
{
|
{
|
||||||
foreach (TransitionItem *transition, m_outputTransitions) {
|
for (TransitionItem *transition : qAsConst(m_outputTransitions)) {
|
||||||
transition->updateComponents();
|
transition->updateComponents();
|
||||||
transition->updateUIProperties();
|
transition->updateUIProperties();
|
||||||
}
|
}
|
||||||
@@ -313,7 +310,7 @@ void ConnectableItem::updateTransitions(bool allChildren)
|
|||||||
updateInputTransitions();
|
updateInputTransitions();
|
||||||
|
|
||||||
if (allChildren) {
|
if (allChildren) {
|
||||||
foreach (QGraphicsItem *it, childItems()) {
|
for (QGraphicsItem *it : childItems()) {
|
||||||
auto item = static_cast<ConnectableItem*>(it);
|
auto item = static_cast<ConnectableItem*>(it);
|
||||||
if (item && item->type() >= InitialStateType)
|
if (item && item->type() >= InitialStateType)
|
||||||
item->updateTransitions(allChildren);
|
item->updateTransitions(allChildren);
|
||||||
@@ -323,14 +320,15 @@ void ConnectableItem::updateTransitions(bool allChildren)
|
|||||||
|
|
||||||
void ConnectableItem::updateTransitionAttributes(bool allChildren)
|
void ConnectableItem::updateTransitionAttributes(bool allChildren)
|
||||||
{
|
{
|
||||||
foreach (TransitionItem *transition, m_outputTransitions)
|
for (TransitionItem *transition : qAsConst(m_outputTransitions))
|
||||||
transition->updateTarget();
|
transition->updateTarget();
|
||||||
|
|
||||||
foreach (TransitionItem *transition, m_inputTransitions)
|
for (TransitionItem *transition : qAsConst(m_inputTransitions))
|
||||||
transition->updateTarget();
|
transition->updateTarget();
|
||||||
|
|
||||||
if (allChildren) {
|
if (allChildren) {
|
||||||
foreach (QGraphicsItem *it, childItems()) {
|
const QList<QGraphicsItem *> items = childItems();
|
||||||
|
for (QGraphicsItem *it : items) {
|
||||||
auto item = static_cast<ConnectableItem*>(it);
|
auto item = static_cast<ConnectableItem*>(it);
|
||||||
if (item && item->type() >= InitialStateType)
|
if (item && item->type() >= InitialStateType)
|
||||||
item->updateTransitionAttributes(allChildren);
|
item->updateTransitionAttributes(allChildren);
|
||||||
@@ -352,7 +350,7 @@ QPointF ConnectableItem::getInternalPosition(const TransitionItem *transition, T
|
|||||||
|
|
||||||
int ind = 0;
|
int ind = 0;
|
||||||
if (type == TransitionItem::InternalNoTarget) {
|
if (type == TransitionItem::InternalNoTarget) {
|
||||||
foreach (TransitionItem *item, m_outputTransitions) {
|
for (TransitionItem *item : qAsConst(m_outputTransitions)) {
|
||||||
if (item->targetType() == TransitionItem::InternalSameTarget)
|
if (item->targetType() == TransitionItem::InternalSameTarget)
|
||||||
ind++;
|
ind++;
|
||||||
}
|
}
|
||||||
@@ -396,7 +394,8 @@ void ConnectableItem::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
|
|||||||
//Restore old behavior if ctrl & alt modifiers are present
|
//Restore old behavior if ctrl & alt modifiers are present
|
||||||
if (!m_releasedFromParent && !(event->modifiers() & Qt::AltModifier) && !(event->modifiers() & Qt::ControlModifier)) {
|
if (!m_releasedFromParent && !(event->modifiers() & Qt::AltModifier) && !(event->modifiers() & Qt::ControlModifier)) {
|
||||||
releaseFromParent();
|
releaseFromParent();
|
||||||
foreach (QGraphicsItem *it, scene()->selectedItems()) {
|
const QList<QGraphicsItem *> items = scene()->selectedItems();
|
||||||
|
for (QGraphicsItem *it : items) {
|
||||||
if (it->type() >= InitialStateType && it != this) {
|
if (it->type() >= InitialStateType && it != this) {
|
||||||
qgraphicsitem_cast<ConnectableItem*>(it)->releaseFromParent();
|
qgraphicsitem_cast<ConnectableItem*>(it)->releaseFromParent();
|
||||||
}
|
}
|
||||||
@@ -431,7 +430,8 @@ void ConnectableItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
connectToParent(parentItem);
|
connectToParent(parentItem);
|
||||||
foreach (QGraphicsItem *it, scene()->selectedItems()) {
|
const QList<QGraphicsItem *> items = scene()->selectedItems();
|
||||||
|
for (QGraphicsItem *it : items) {
|
||||||
if (it->type() >= InitialStateType && it != this)
|
if (it->type() >= InitialStateType && it != this)
|
||||||
qgraphicsitem_cast<ConnectableItem*>(it)->connectToParent(parentItem);
|
qgraphicsitem_cast<ConnectableItem*>(it)->connectToParent(parentItem);
|
||||||
}
|
}
|
||||||
@@ -582,7 +582,7 @@ void ConnectableItem::updateAttributes()
|
|||||||
{
|
{
|
||||||
BaseItem::updateAttributes();
|
BaseItem::updateAttributes();
|
||||||
|
|
||||||
foreach (TransitionItem *transition, m_inputTransitions) {
|
for (TransitionItem *transition : qAsConst(m_inputTransitions)) {
|
||||||
if (transition->isEndItem(this))
|
if (transition->isEndItem(this))
|
||||||
transition->setTagValue("target", itemId());
|
transition->setTagValue("target", itemId());
|
||||||
}
|
}
|
||||||
@@ -698,13 +698,13 @@ void ConnectableItem::finalizeCreation()
|
|||||||
|
|
||||||
bool ConnectableItem::hasInputTransitions(const ConnectableItem *parentItem, bool checkChildren) const
|
bool ConnectableItem::hasInputTransitions(const ConnectableItem *parentItem, bool checkChildren) const
|
||||||
{
|
{
|
||||||
foreach (const TransitionItem *it, m_inputTransitions) {
|
for (const TransitionItem *it : qAsConst(m_inputTransitions))
|
||||||
if (!SceneUtils::isChild(parentItem, it->connectedItem(this)))
|
if (!SceneUtils::isChild(parentItem, it->connectedItem(this)))
|
||||||
return true;
|
return true;
|
||||||
}
|
|
||||||
|
|
||||||
if (checkChildren) {
|
if (checkChildren) {
|
||||||
foreach (QGraphicsItem *it, childItems()) {
|
const QList<QGraphicsItem *> items = childItems();
|
||||||
|
for (QGraphicsItem *it : items) {
|
||||||
if (it->type() >= InitialStateType) {
|
if (it->type() >= InitialStateType) {
|
||||||
auto item = qgraphicsitem_cast<ConnectableItem*>(it);
|
auto item = qgraphicsitem_cast<ConnectableItem*>(it);
|
||||||
if (item && item->hasInputTransitions(parentItem, checkChildren))
|
if (item && item->hasInputTransitions(parentItem, checkChildren))
|
||||||
@@ -718,13 +718,13 @@ bool ConnectableItem::hasInputTransitions(const ConnectableItem *parentItem, boo
|
|||||||
|
|
||||||
bool ConnectableItem::hasOutputTransitions(const ConnectableItem *parentItem, bool checkChildren) const
|
bool ConnectableItem::hasOutputTransitions(const ConnectableItem *parentItem, bool checkChildren) const
|
||||||
{
|
{
|
||||||
foreach (TransitionItem *it, m_outputTransitions) {
|
for (TransitionItem *it : qAsConst(m_outputTransitions))
|
||||||
if (!SceneUtils::isChild(parentItem, it->connectedItem(this)))
|
if (!SceneUtils::isChild(parentItem, it->connectedItem(this)))
|
||||||
return true;
|
return true;
|
||||||
}
|
|
||||||
|
|
||||||
if (checkChildren) {
|
if (checkChildren) {
|
||||||
foreach (QGraphicsItem *it, childItems()) {
|
const QList<QGraphicsItem *> items = childItems();
|
||||||
|
for (QGraphicsItem *it : items) {
|
||||||
if (it->type() >= InitialStateType) {
|
if (it->type() >= InitialStateType) {
|
||||||
auto item = qgraphicsitem_cast<ConnectableItem*>(it);
|
auto item = qgraphicsitem_cast<ConnectableItem*>(it);
|
||||||
if (item && item->hasOutputTransitions(parentItem, checkChildren))
|
if (item && item->hasOutputTransitions(parentItem, checkChildren))
|
||||||
@@ -755,7 +755,8 @@ void ConnectableItem::removeOverlappingItem(ConnectableItem *item)
|
|||||||
void ConnectableItem::checkOverlapping()
|
void ConnectableItem::checkOverlapping()
|
||||||
{
|
{
|
||||||
QVector<ConnectableItem*> overlappedItems;
|
QVector<ConnectableItem*> overlappedItems;
|
||||||
foreach (QGraphicsItem *it, collidingItems()) {
|
const QList<QGraphicsItem *> items = collidingItems();
|
||||||
|
for (QGraphicsItem *it : items) {
|
||||||
if (it->type() >= InitialStateType && it->parentItem() == parentItem()) {
|
if (it->type() >= InitialStateType && it->parentItem() == parentItem()) {
|
||||||
overlappedItems << qgraphicsitem_cast<ConnectableItem*>(it);
|
overlappedItems << qgraphicsitem_cast<ConnectableItem*>(it);
|
||||||
}
|
}
|
||||||
@@ -770,7 +771,7 @@ void ConnectableItem::checkOverlapping()
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Add new overlapped items
|
// Add new overlapped items
|
||||||
foreach (ConnectableItem *it, overlappedItems) {
|
for (ConnectableItem *it : qAsConst(overlappedItems)) {
|
||||||
if (!m_overlappedItems.contains(it)) {
|
if (!m_overlappedItems.contains(it)) {
|
||||||
m_overlappedItems << it;
|
m_overlappedItems << it;
|
||||||
it->addOverlappingItem(this);
|
it->addOverlappingItem(this);
|
||||||
|
@@ -67,7 +67,7 @@ GraphicsScene::~GraphicsScene()
|
|||||||
void GraphicsScene::unselectAll()
|
void GraphicsScene::unselectAll()
|
||||||
{
|
{
|
||||||
const QList<QGraphicsItem*> selectedItems = this->selectedItems();
|
const QList<QGraphicsItem*> selectedItems = this->selectedItems();
|
||||||
foreach (QGraphicsItem *it, selectedItems)
|
for (QGraphicsItem *it : selectedItems)
|
||||||
it->setSelected(false);
|
it->setSelected(false);
|
||||||
if (m_document)
|
if (m_document)
|
||||||
m_document->setCurrentTag(nullptr);
|
m_document->setCurrentTag(nullptr);
|
||||||
@@ -75,20 +75,20 @@ void GraphicsScene::unselectAll()
|
|||||||
|
|
||||||
void GraphicsScene::unhighlightAll()
|
void GraphicsScene::unhighlightAll()
|
||||||
{
|
{
|
||||||
foreach (BaseItem *it, m_baseItems)
|
for (BaseItem *it : qAsConst(m_baseItems))
|
||||||
it->setHighlight(false);
|
it->setHighlight(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
void GraphicsScene::highlightItems(const QVector<ScxmlTag*> &lstIds)
|
void GraphicsScene::highlightItems(const QVector<ScxmlTag*> &lstIds)
|
||||||
{
|
{
|
||||||
foreach (BaseItem *it, m_baseItems)
|
for (BaseItem *it : qAsConst(m_baseItems))
|
||||||
it->setHighlight(lstIds.contains(it->tag()));
|
it->setHighlight(lstIds.contains(it->tag()));
|
||||||
}
|
}
|
||||||
|
|
||||||
QRectF GraphicsScene::selectedBoundingRect() const
|
QRectF GraphicsScene::selectedBoundingRect() const
|
||||||
{
|
{
|
||||||
QRectF r;
|
QRectF r;
|
||||||
foreach (BaseItem *item, m_baseItems) {
|
for (BaseItem *item : qAsConst(m_baseItems)) {
|
||||||
if (item->isSelected())
|
if (item->isSelected())
|
||||||
r = r.united(item->sceneBoundingRect());
|
r = r.united(item->sceneBoundingRect());
|
||||||
}
|
}
|
||||||
@@ -98,7 +98,7 @@ QRectF GraphicsScene::selectedBoundingRect() const
|
|||||||
qreal GraphicsScene::selectedMaxWidth() const
|
qreal GraphicsScene::selectedMaxWidth() const
|
||||||
{
|
{
|
||||||
qreal maxw = 0;
|
qreal maxw = 0;
|
||||||
foreach (BaseItem *item, m_baseItems) {
|
for (BaseItem *item : qAsConst(m_baseItems)) {
|
||||||
if (item->isSelected() && item->type() >= InitialStateType)
|
if (item->isSelected() && item->type() >= InitialStateType)
|
||||||
maxw = qMax(maxw, item->sceneBoundingRect().width());
|
maxw = qMax(maxw, item->sceneBoundingRect().width());
|
||||||
}
|
}
|
||||||
@@ -108,7 +108,7 @@ qreal GraphicsScene::selectedMaxWidth() const
|
|||||||
qreal GraphicsScene::selectedMaxHeight() const
|
qreal GraphicsScene::selectedMaxHeight() const
|
||||||
{
|
{
|
||||||
qreal maxh = 0;
|
qreal maxh = 0;
|
||||||
foreach (BaseItem *item, m_baseItems) {
|
for (BaseItem *item : qAsConst(m_baseItems)) {
|
||||||
if (item->isSelected() && item->type() >= InitialStateType)
|
if (item->isSelected() && item->type() >= InitialStateType)
|
||||||
maxh = qMax(maxh, item->sceneBoundingRect().height());
|
maxh = qMax(maxh, item->sceneBoundingRect().height());
|
||||||
}
|
}
|
||||||
@@ -124,37 +124,37 @@ void GraphicsScene::alignStates(int alignType)
|
|||||||
if (r.isValid()) {
|
if (r.isValid()) {
|
||||||
switch (alignType) {
|
switch (alignType) {
|
||||||
case ActionAlignLeft:
|
case ActionAlignLeft:
|
||||||
foreach (BaseItem *item, m_baseItems) {
|
for (BaseItem *item : qAsConst(m_baseItems)) {
|
||||||
if (item->isSelected() && item->type() >= InitialStateType)
|
if (item->isSelected() && item->type() >= InitialStateType)
|
||||||
item->moveStateBy(r.left() - item->sceneBoundingRect().left(), 0);
|
item->moveStateBy(r.left() - item->sceneBoundingRect().left(), 0);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case ActionAlignRight:
|
case ActionAlignRight:
|
||||||
foreach (BaseItem *item, m_baseItems) {
|
for (BaseItem *item : qAsConst(m_baseItems)) {
|
||||||
if (item->isSelected() && item->type() >= InitialStateType)
|
if (item->isSelected() && item->type() >= InitialStateType)
|
||||||
item->moveStateBy(r.right() - item->sceneBoundingRect().right(), 0);
|
item->moveStateBy(r.right() - item->sceneBoundingRect().right(), 0);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case ActionAlignTop:
|
case ActionAlignTop:
|
||||||
foreach (BaseItem *item, m_baseItems) {
|
for (BaseItem *item : qAsConst(m_baseItems)) {
|
||||||
if (item->isSelected() && item->type() >= InitialStateType)
|
if (item->isSelected() && item->type() >= InitialStateType)
|
||||||
item->moveStateBy(0, r.top() - item->sceneBoundingRect().top());
|
item->moveStateBy(0, r.top() - item->sceneBoundingRect().top());
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case ActionAlignBottom:
|
case ActionAlignBottom:
|
||||||
foreach (BaseItem *item, m_baseItems) {
|
for (BaseItem *item : qAsConst(m_baseItems)) {
|
||||||
if (item->isSelected() && item->type() >= InitialStateType)
|
if (item->isSelected() && item->type() >= InitialStateType)
|
||||||
item->moveStateBy(0, r.bottom() - item->sceneBoundingRect().bottom());
|
item->moveStateBy(0, r.bottom() - item->sceneBoundingRect().bottom());
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case ActionAlignHorizontal:
|
case ActionAlignHorizontal:
|
||||||
foreach (BaseItem *item, m_baseItems) {
|
for (BaseItem *item : qAsConst(m_baseItems)) {
|
||||||
if (item->isSelected() && item->type() >= InitialStateType)
|
if (item->isSelected() && item->type() >= InitialStateType)
|
||||||
item->moveStateBy(0, r.center().y() - item->sceneBoundingRect().center().y());
|
item->moveStateBy(0, r.center().y() - item->sceneBoundingRect().center().y());
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case ActionAlignVertical:
|
case ActionAlignVertical:
|
||||||
foreach (BaseItem *item, m_baseItems) {
|
for (BaseItem *item : qAsConst(m_baseItems)) {
|
||||||
if (item->isSelected() && item->type() >= InitialStateType)
|
if (item->isSelected() && item->type() >= InitialStateType)
|
||||||
item->moveStateBy(r.center().x() - item->sceneBoundingRect().center().x(), 0);
|
item->moveStateBy(r.center().x() - item->sceneBoundingRect().center().x(), 0);
|
||||||
}
|
}
|
||||||
@@ -175,7 +175,7 @@ void GraphicsScene::adjustStates(int adjustType)
|
|||||||
qreal maxw = selectedMaxWidth();
|
qreal maxw = selectedMaxWidth();
|
||||||
qreal maxh = selectedMaxHeight();
|
qreal maxh = selectedMaxHeight();
|
||||||
|
|
||||||
foreach (BaseItem *item, m_baseItems) {
|
for (BaseItem *item : qAsConst(m_baseItems)) {
|
||||||
if (item->isSelected() && item->type() >= InitialStateType) {
|
if (item->isSelected() && item->type() >= InitialStateType) {
|
||||||
QRectF rr = item->boundingRect();
|
QRectF rr = item->boundingRect();
|
||||||
if ((adjustType == ActionAdjustWidth || adjustType == ActionAdjustSize) && !qFuzzyCompare(rr.width(), maxw))
|
if ((adjustType == ActionAdjustWidth || adjustType == ActionAdjustSize) && !qFuzzyCompare(rr.width(), maxw))
|
||||||
@@ -223,7 +223,7 @@ void GraphicsScene::copy()
|
|||||||
QVector<ScxmlTag*> tags;
|
QVector<ScxmlTag*> tags;
|
||||||
if (m_document->currentTag()->tagType() == Scxml) {
|
if (m_document->currentTag()->tagType() == Scxml) {
|
||||||
QVector<BaseItem*> items;
|
QVector<BaseItem*> items;
|
||||||
foreach (BaseItem *item, m_baseItems) {
|
for (BaseItem *item : qAsConst(m_baseItems)) {
|
||||||
if (!item->parentItem())
|
if (!item->parentItem())
|
||||||
items << item;
|
items << item;
|
||||||
}
|
}
|
||||||
@@ -241,9 +241,9 @@ void GraphicsScene::copy()
|
|||||||
mime->setText(QLatin1String(result));
|
mime->setText(QLatin1String(result));
|
||||||
mime->setData("StateChartEditor/StateData", result);
|
mime->setData("StateChartEditor/StateData", result);
|
||||||
QStringList strTypes;
|
QStringList strTypes;
|
||||||
foreach (const ScxmlTag *tag, tags) {
|
for (const ScxmlTag *tag : qAsConst(tags))
|
||||||
strTypes << tag->tagName(false);
|
strTypes << tag->tagName(false);
|
||||||
}
|
|
||||||
mime->setData("StateChartEditor/CopiedTagTypes", strTypes.join(",").toLocal8Bit());
|
mime->setData("StateChartEditor/CopiedTagTypes", strTypes.join(",").toLocal8Bit());
|
||||||
mime->setData("StateChartEditor/CopiedMinPos", QString::fromLatin1("%1:%2").arg(minPos.x()).arg(minPos.y()).toLocal8Bit());
|
mime->setData("StateChartEditor/CopiedMinPos", QString::fromLatin1("%1:%2").arg(minPos.x()).arg(minPos.y()).toLocal8Bit());
|
||||||
QGuiApplication::clipboard()->setMimeData(mime);
|
QGuiApplication::clipboard()->setMimeData(mime);
|
||||||
@@ -267,7 +267,7 @@ void GraphicsScene::paste(const QPointF &targetPos)
|
|||||||
QPointF startPos(targetPos);
|
QPointF startPos(targetPos);
|
||||||
|
|
||||||
BaseItem *targetItem = nullptr;
|
BaseItem *targetItem = nullptr;
|
||||||
foreach (BaseItem *item, m_baseItems) {
|
for (BaseItem *item : qAsConst(m_baseItems)) {
|
||||||
if (item->isSelected() && item->type() >= StateType) {
|
if (item->isSelected() && item->type() >= StateType) {
|
||||||
targetItem = item;
|
targetItem = item;
|
||||||
break;
|
break;
|
||||||
@@ -296,7 +296,7 @@ void GraphicsScene::paste(const QPointF &targetPos)
|
|||||||
|
|
||||||
void GraphicsScene::setEditorInfo(const QString &key, const QString &value)
|
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)
|
if (item->isSelected() && item->type() >= TransitionType)
|
||||||
item->setEditorInfo(key, value);
|
item->setEditorInfo(key, value);
|
||||||
}
|
}
|
||||||
@@ -371,7 +371,7 @@ void GraphicsScene::runLayoutToSelectedStates()
|
|||||||
m_document->undoStack()->beginMacro(tr("Re-layout"));
|
m_document->undoStack()->beginMacro(tr("Re-layout"));
|
||||||
|
|
||||||
QVector<BaseItem*> selectedItems;
|
QVector<BaseItem*> selectedItems;
|
||||||
foreach (BaseItem *node, m_baseItems) {
|
for (BaseItem *node : qAsConst(m_baseItems)) {
|
||||||
if (node->isSelected()) {
|
if (node->isSelected()) {
|
||||||
int index = 0;
|
int index = 0;
|
||||||
for (int i = 0; i < selectedItems.count(); ++i) {
|
for (int i = 0; i < selectedItems.count(); ++i) {
|
||||||
@@ -391,22 +391,20 @@ void GraphicsScene::runLayoutToSelectedStates()
|
|||||||
// Layout scene items if necessary
|
// Layout scene items if necessary
|
||||||
if (selectedItems.isEmpty()) {
|
if (selectedItems.isEmpty()) {
|
||||||
QList<QGraphicsItem*> sceneItems;
|
QList<QGraphicsItem*> sceneItems;
|
||||||
foreach (BaseItem *item, m_baseItems) {
|
for (BaseItem *item : qAsConst(m_baseItems)) {
|
||||||
if (item->type() >= InitialStateType && !item->parentItem())
|
if (item->type() >= InitialStateType && !item->parentItem())
|
||||||
sceneItems << item;
|
sceneItems << item;
|
||||||
}
|
}
|
||||||
SceneUtils::layout(sceneItems);
|
SceneUtils::layout(sceneItems);
|
||||||
|
|
||||||
foreach (QGraphicsItem *item, sceneItems) {
|
for (QGraphicsItem *item : qAsConst(sceneItems))
|
||||||
if (item->type() >= StateType)
|
if (item->type() >= StateType)
|
||||||
static_cast<StateItem*>(item)->shrink();
|
static_cast<StateItem*>(item)->shrink();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// Update properties
|
// Update properties
|
||||||
foreach (BaseItem *node, selectedItems) {
|
for (BaseItem *node : qAsConst(selectedItems))
|
||||||
node->updateUIProperties();
|
node->updateUIProperties();
|
||||||
}
|
|
||||||
|
|
||||||
m_document->undoStack()->endMacro();
|
m_document->undoStack()->endMacro();
|
||||||
}
|
}
|
||||||
@@ -417,31 +415,31 @@ void GraphicsScene::runAutomaticLayout()
|
|||||||
|
|
||||||
// 1. Find max depth
|
// 1. Find max depth
|
||||||
int maxDepth = 0;
|
int maxDepth = 0;
|
||||||
foreach (BaseItem *node, m_baseItems) {
|
for (BaseItem *node : qAsConst(m_baseItems)) {
|
||||||
maxDepth = qMax(maxDepth, node->depth());
|
maxDepth = qMax(maxDepth, node->depth());
|
||||||
node->setBlockUpdates(true);
|
node->setBlockUpdates(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 2. Layout every depth-level separately
|
// 2. Layout every depth-level separately
|
||||||
for (int d = (maxDepth + 1); d--;) {
|
for (int d = (maxDepth + 1); d--;) {
|
||||||
foreach (BaseItem *node, m_baseItems)
|
for (BaseItem *node : qAsConst(m_baseItems))
|
||||||
node->doLayout(d);
|
node->doLayout(d);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 3. Layout scene items
|
// 3. Layout scene items
|
||||||
QList<QGraphicsItem*> sceneItems;
|
QList<QGraphicsItem*> sceneItems;
|
||||||
foreach (BaseItem *item, m_baseItems) {
|
for (BaseItem *item : qAsConst(m_baseItems)) {
|
||||||
if (item->type() >= InitialStateType && !item->parentItem())
|
if (item->type() >= InitialStateType && !item->parentItem())
|
||||||
sceneItems << item;
|
sceneItems << item;
|
||||||
}
|
}
|
||||||
SceneUtils::layout(sceneItems);
|
SceneUtils::layout(sceneItems);
|
||||||
|
|
||||||
foreach (QGraphicsItem *item, sceneItems) {
|
for (QGraphicsItem *item : qAsConst(sceneItems)) {
|
||||||
if (item->type() >= StateType)
|
if (item->type() >= StateType)
|
||||||
static_cast<StateItem*>(item)->shrink();
|
static_cast<StateItem*>(item)->shrink();
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach (BaseItem *node, m_baseItems) {
|
for (BaseItem *node : qAsConst(m_baseItems)) {
|
||||||
node->updateUIProperties();
|
node->updateUIProperties();
|
||||||
node->setBlockUpdates(false);
|
node->setBlockUpdates(false);
|
||||||
}
|
}
|
||||||
@@ -468,21 +466,21 @@ void GraphicsScene::endTagChange(ScxmlDocument::TagChange change, ScxmlTag *tag,
|
|||||||
|
|
||||||
switch (change) {
|
switch (change) {
|
||||||
case ScxmlDocument::TagAttributesChanged: {
|
case ScxmlDocument::TagAttributesChanged: {
|
||||||
foreach (BaseItem *item, m_baseItems) {
|
for (BaseItem *item : qAsConst(m_baseItems)) {
|
||||||
if (item->tag() == tag)
|
if (item->tag() == tag)
|
||||||
item->updateAttributes();
|
item->updateAttributes();
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case ScxmlDocument::TagEditorInfoChanged: {
|
case ScxmlDocument::TagEditorInfoChanged: {
|
||||||
foreach (BaseItem *item, m_baseItems) {
|
for (BaseItem *item : qAsConst(m_baseItems)) {
|
||||||
if (item->tag() == tag)
|
if (item->tag() == tag)
|
||||||
item->updateEditorInfo();
|
item->updateEditorInfo();
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case ScxmlDocument::TagCurrentChanged: {
|
case ScxmlDocument::TagCurrentChanged: {
|
||||||
foreach (BaseItem *item, m_baseItems) {
|
for (BaseItem *item : qAsConst(m_baseItems)) {
|
||||||
if (!item->isSelected() && item->tag() == tag)
|
if (!item->isSelected() && item->tag() == tag)
|
||||||
item->setSelected(true);
|
item->setSelected(true);
|
||||||
}
|
}
|
||||||
@@ -725,7 +723,7 @@ BaseItem *GraphicsScene::findItem(const ScxmlTag *tag) const
|
|||||||
if (!tag)
|
if (!tag)
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
|
||||||
foreach (BaseItem *it, m_baseItems) {
|
for (BaseItem *it : qAsConst(m_baseItems)) {
|
||||||
if (it->tag() == tag)
|
if (it->tag() == tag)
|
||||||
return it;
|
return it;
|
||||||
}
|
}
|
||||||
@@ -738,7 +736,7 @@ void GraphicsScene::removeItems(const ScxmlTag *tag)
|
|||||||
if (tag) {
|
if (tag) {
|
||||||
// Find right items
|
// Find right items
|
||||||
QVector<BaseItem*> items;
|
QVector<BaseItem*> items;
|
||||||
foreach (BaseItem *it, m_baseItems) {
|
for (BaseItem *it : qAsConst(m_baseItems)) {
|
||||||
if (it->tag() == tag)
|
if (it->tag() == tag)
|
||||||
items << it;
|
items << it;
|
||||||
}
|
}
|
||||||
@@ -764,7 +762,7 @@ QPair<bool, bool> GraphicsScene::checkSnapToItem(BaseItem *item, const QPointF &
|
|||||||
qreal diffY = 8;
|
qreal diffY = 8;
|
||||||
qreal diffYdX = 2000;
|
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) {
|
if (!it->isSelected() && it != item && it->parentItem() == parentItem && it->type() >= InitialStateType) {
|
||||||
QPointF c = it->sceneCenter();
|
QPointF c = it->sceneCenter();
|
||||||
qreal dX = qAbs(c.x() - p.x());
|
qreal dX = qAbs(c.x() - p.x());
|
||||||
@@ -802,7 +800,7 @@ void GraphicsScene::selectionChanged(bool para)
|
|||||||
int baseCount = 0;
|
int baseCount = 0;
|
||||||
int stateTypeCount = 0;
|
int stateTypeCount = 0;
|
||||||
|
|
||||||
foreach (BaseItem *item, m_baseItems) {
|
for (BaseItem *item : qAsConst(m_baseItems)) {
|
||||||
if (item->isSelected()) {
|
if (item->isSelected()) {
|
||||||
if (item->type() >= TransitionType)
|
if (item->type() >= TransitionType)
|
||||||
baseCount++;
|
baseCount++;
|
||||||
@@ -848,22 +846,20 @@ void GraphicsScene::removeWarningItem(WarningItem *item)
|
|||||||
void GraphicsScene::warningVisibilityChanged(int type, WarningItem *item)
|
void GraphicsScene::warningVisibilityChanged(int type, WarningItem *item)
|
||||||
{
|
{
|
||||||
if (!m_autoLayoutRunning && !m_initializing) {
|
if (!m_autoLayoutRunning && !m_initializing) {
|
||||||
foreach (WarningItem *it, m_allWarnings) {
|
for (WarningItem *it : qAsConst(m_allWarnings))
|
||||||
if (it != item && (type == 0 || it->type() == type))
|
if (it != item && (type == 0 || it->type() == type))
|
||||||
it->check();
|
it->check();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
ScxmlTag *GraphicsScene::tagByWarning(const ScxmlEditor::OutputPane::Warning *w) const
|
ScxmlTag *GraphicsScene::tagByWarning(const ScxmlEditor::OutputPane::Warning *w) const
|
||||||
{
|
{
|
||||||
ScxmlTag *tag = nullptr;
|
ScxmlTag *tag = nullptr;
|
||||||
foreach (WarningItem *it, m_allWarnings) {
|
for (WarningItem *it : qAsConst(m_allWarnings))
|
||||||
if (it->warning() == w) {
|
if (it->warning() == w) {
|
||||||
tag = it->tag();
|
tag = it->tag();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
return tag;
|
return tag;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -921,7 +917,7 @@ void GraphicsScene::removeChild(BaseItem *item)
|
|||||||
|
|
||||||
void GraphicsScene::checkItemsVisibility(double scaleFactor)
|
void GraphicsScene::checkItemsVisibility(double scaleFactor)
|
||||||
{
|
{
|
||||||
foreach (BaseItem *item, m_baseItems) {
|
for (BaseItem *item : qAsConst(m_baseItems)) {
|
||||||
item->checkVisibility(scaleFactor);
|
item->checkVisibility(scaleFactor);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -930,7 +926,7 @@ void GraphicsScene::checkInitialState()
|
|||||||
{
|
{
|
||||||
if (m_document) {
|
if (m_document) {
|
||||||
QList<QGraphicsItem*> sceneItems;
|
QList<QGraphicsItem*> sceneItems;
|
||||||
foreach (BaseItem *item, m_baseItems) {
|
for (BaseItem *item : qAsConst(m_baseItems)) {
|
||||||
if (item->type() >= InitialStateType && !item->parentItem())
|
if (item->type() >= InitialStateType && !item->parentItem())
|
||||||
sceneItems << item;
|
sceneItems << item;
|
||||||
}
|
}
|
||||||
@@ -944,14 +940,14 @@ void GraphicsScene::checkInitialState()
|
|||||||
|
|
||||||
void GraphicsScene::clearAllTags()
|
void GraphicsScene::clearAllTags()
|
||||||
{
|
{
|
||||||
foreach (BaseItem *it, m_baseItems) {
|
for (BaseItem *it : qAsConst(m_baseItems)) {
|
||||||
it->setTag(nullptr);
|
it->setTag(nullptr);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void GraphicsScene::setBlockUpdates(bool block)
|
void GraphicsScene::setBlockUpdates(bool block)
|
||||||
{
|
{
|
||||||
foreach (BaseItem *it, m_baseItems) {
|
for (BaseItem *it : qAsConst(m_baseItems)) {
|
||||||
it->setBlockUpdates(block);
|
it->setBlockUpdates(block);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -63,7 +63,8 @@ void ParallelItem::doLayout(int d)
|
|||||||
|
|
||||||
// 1. Find children items
|
// 1. Find children items
|
||||||
QVector<StateItem*> children;
|
QVector<StateItem*> children;
|
||||||
foreach (QGraphicsItem *it, childItems()) {
|
const QList<QGraphicsItem *> items = childItems();
|
||||||
|
for (QGraphicsItem *it : items) {
|
||||||
if (it->type() >= StateType) {
|
if (it->type() >= StateType) {
|
||||||
auto itt = qgraphicsitem_cast<StateItem*>(it);
|
auto itt = qgraphicsitem_cast<StateItem*>(it);
|
||||||
if (itt)
|
if (itt)
|
||||||
@@ -72,17 +73,16 @@ void ParallelItem::doLayout(int d)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 2. Adjust sizes
|
// 2. Adjust sizes
|
||||||
foreach (StateItem *itt, children) {
|
for (StateItem *itt : qAsConst(children))
|
||||||
itt->shrink();
|
itt->shrink();
|
||||||
}
|
|
||||||
|
|
||||||
qreal maxw = 0;
|
qreal maxw = 0;
|
||||||
foreach (StateItem *itt, children) {
|
for (StateItem *itt : qAsConst(children)) {
|
||||||
QRectF rr = itt->boundingRect();
|
QRectF rr = itt->boundingRect();
|
||||||
maxw = qMax(rr.width(), maxw);
|
maxw = qMax(rr.width(), maxw);
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach (StateItem *itt, children) {
|
for (StateItem *itt : qAsConst(children)) {
|
||||||
QRectF rr = itt->boundingRect();
|
QRectF rr = itt->boundingRect();
|
||||||
if (!qFuzzyCompare(rr.width(), maxw))
|
if (!qFuzzyCompare(rr.width(), maxw))
|
||||||
rr.setWidth(maxw);
|
rr.setWidth(maxw);
|
||||||
|
@@ -78,9 +78,9 @@ void SCAttributeItemDelegate::setEditorData(QWidget *editor, const QModelIndex &
|
|||||||
auto combo = qobject_cast<QComboBox*>(editor);
|
auto combo = qobject_cast<QComboBox*>(editor);
|
||||||
if (combo) {
|
if (combo) {
|
||||||
combo->clear();
|
combo->clear();
|
||||||
QStringList values = index.data(DataRole).toString().split(";");
|
const QStringList values = index.data(DataRole).toString().split(";");
|
||||||
|
|
||||||
foreach (QString val, values)
|
for (QString val : values)
|
||||||
combo->addItem(val);
|
combo->addItem(val);
|
||||||
|
|
||||||
combo->setCurrentText(index.data().toString());
|
combo->setCurrentText(index.data().toString());
|
||||||
|
@@ -149,7 +149,7 @@ QVector<ScxmlTag*> findCopyTags(const QVector<BaseItem*> &items, QPointF &minPos
|
|||||||
{
|
{
|
||||||
QPointF pp(0, 0);
|
QPointF pp(0, 0);
|
||||||
QVector<ScxmlTag*> tags;
|
QVector<ScxmlTag*> tags;
|
||||||
foreach (BaseItem *it, items) {
|
for (BaseItem *it : items) {
|
||||||
if (it->type() >= InitialStateType && it->isSelected()) {
|
if (it->type() >= InitialStateType && it->isSelected()) {
|
||||||
BaseItem *parent = it->parentBaseItem();
|
BaseItem *parent = it->parentBaseItem();
|
||||||
BaseItem *lastSelectedParent = it;
|
BaseItem *lastSelectedParent = it;
|
||||||
@@ -181,7 +181,7 @@ QVector<ScxmlTag*> findRemovedTags(const QVector<BaseItem*> &items)
|
|||||||
{
|
{
|
||||||
// Find right tags
|
// Find right tags
|
||||||
QVector<ScxmlTag*> tags;
|
QVector<ScxmlTag*> tags;
|
||||||
foreach (BaseItem *it, items) {
|
for (BaseItem *it : items) {
|
||||||
if (it->isSelected()) {
|
if (it->isSelected()) {
|
||||||
// Find the last selected parent
|
// Find the last selected parent
|
||||||
BaseItem *parent = it->parentBaseItem();
|
BaseItem *parent = it->parentBaseItem();
|
||||||
@@ -207,7 +207,7 @@ void layout(const QList<QGraphicsItem*> &items)
|
|||||||
QList<ConnectableItem*> childItems;
|
QList<ConnectableItem*> childItems;
|
||||||
ConnectableItem *initialItem = nullptr;
|
ConnectableItem *initialItem = nullptr;
|
||||||
ConnectableItem *finalItem = nullptr;
|
ConnectableItem *finalItem = nullptr;
|
||||||
foreach (QGraphicsItem *item, items) {
|
for (QGraphicsItem *item : items) {
|
||||||
auto connectableItem = qgraphicsitem_cast<ConnectableItem*>(item);
|
auto connectableItem = qgraphicsitem_cast<ConnectableItem*>(item);
|
||||||
if (connectableItem) {
|
if (connectableItem) {
|
||||||
if (connectableItem->type() == InitialStateType)
|
if (connectableItem->type() == InitialStateType)
|
||||||
@@ -317,12 +317,16 @@ void layout(const QList<QGraphicsItem*> &items)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Finally set initial and final positions
|
// Finally set initial and final positions
|
||||||
foreach (ConnectableItem *item, childItems) {
|
for (const ConnectableItem *item : qAsConst(childItems)) {
|
||||||
if (item == firstItem)
|
if (item == firstItem)
|
||||||
initialItem->setPos(firstItem->pos() + firstItem->boundingRect().topLeft() - QPointF(50, 50));
|
initialItem->setPos(firstItem->pos() + firstItem->boundingRect().topLeft()
|
||||||
|
- QPointF(50, 50));
|
||||||
else if (item == lastItem) {
|
else if (item == lastItem) {
|
||||||
int angle = startAngle + childItems.indexOf(item) * angleDiff;
|
int angle = startAngle + childItems.indexOf(item) * angleDiff;
|
||||||
QLineF line = QLineF::fromPolar(qMax(lastItem->boundingRect().width() / 2, lastItem->boundingRect().height() / 2) + 20, angle);
|
QLineF line = QLineF::fromPolar(qMax(lastItem->boundingRect().width() / 2,
|
||||||
|
lastItem->boundingRect().height() / 2)
|
||||||
|
+ 20,
|
||||||
|
angle);
|
||||||
finalItem->setPos(lastItem->pos() + lastItem->boundingRect().center() + line.p2());
|
finalItem->setPos(lastItem->pos() + lastItem->boundingRect().center() + line.p2());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -70,18 +70,16 @@ bool hasSiblingStates(T *item)
|
|||||||
if (parentItem) {
|
if (parentItem) {
|
||||||
children = parentItem->childItems();
|
children = parentItem->childItems();
|
||||||
} else if (item->scene()) {
|
} else if (item->scene()) {
|
||||||
foreach (QGraphicsItem *it, item->scene()->items()) {
|
const QList<QGraphicsItem *> items = item->scene()->items();
|
||||||
|
for (QGraphicsItem *it : items)
|
||||||
if (!it->parentItem())
|
if (!it->parentItem())
|
||||||
children << it;
|
children << it;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
foreach (QGraphicsItem *it, children) {
|
for (QGraphicsItem *it : qAsConst(children))
|
||||||
if (it != item && it->type() == item->type()) {
|
if (it != item && it->type() == item->type())
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user