forked from qt-creator/qt-creator
ModelingLib: Replace foreach with range-based for loops
Change-Id: I3e51c9477b6995ec06b119fb4518a53aa1d71ec9 Reviewed-by: hjk <hjk@qt.io> Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
This commit is contained in:
@@ -55,7 +55,7 @@ TextScanner::~TextScanner()
|
|||||||
void TextScanner::setKeywords(const QList<QPair<QString, int>> &keywords)
|
void TextScanner::setKeywords(const QList<QPair<QString, int>> &keywords)
|
||||||
{
|
{
|
||||||
d->m_keywordToSubtypeMap.clear();
|
d->m_keywordToSubtypeMap.clear();
|
||||||
foreach (const DefTuple &tuple, keywords)
|
for (const DefTuple &tuple : keywords)
|
||||||
d->m_keywordToSubtypeMap.insert(tuple.first.toLower(), tuple.second);
|
d->m_keywordToSubtypeMap.insert(tuple.first.toLower(), tuple.second);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -65,13 +65,13 @@ void TextScanner::setOperators(const QList<QPair<QString, int>> &operators)
|
|||||||
d->m_maxOperatorLength = 0;
|
d->m_maxOperatorLength = 0;
|
||||||
d->m_operatorFirstCharsSet.clear();
|
d->m_operatorFirstCharsSet.clear();
|
||||||
d->m_operatorCharsSet.clear();
|
d->m_operatorCharsSet.clear();
|
||||||
foreach (const DefTuple &tuple, operators) {
|
for (const DefTuple &tuple : operators) {
|
||||||
QString op = tuple.first;
|
const QString op = tuple.first;
|
||||||
d->m_operatorToSubtypeMap.insert(op, tuple.second);
|
d->m_operatorToSubtypeMap.insert(op, tuple.second);
|
||||||
if (op.length() > d->m_maxOperatorLength)
|
if (op.length() > d->m_maxOperatorLength)
|
||||||
d->m_maxOperatorLength = op.length();
|
d->m_maxOperatorLength = op.length();
|
||||||
d->m_operatorFirstCharsSet.insert(op.at(0));
|
d->m_operatorFirstCharsSet.insert(op.at(0));
|
||||||
foreach (const QChar ch, op)
|
for (const QChar ch : op)
|
||||||
d->m_operatorCharsSet.insert(ch);
|
d->m_operatorCharsSet.insert(ch);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -97,7 +97,7 @@ public:
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
// join other elements into this command
|
// join other elements into this command
|
||||||
foreach (const DElement *otherElement, otherUpdateCommand->m_clonedElements) {
|
for (const DElement *otherElement : std::as_const(otherUpdateCommand->m_clonedElements)) {
|
||||||
if (!m_clonedElements.contains(otherElement->uid())) {
|
if (!m_clonedElements.contains(otherElement->uid())) {
|
||||||
DCloneVisitor visitor;
|
DCloneVisitor visitor;
|
||||||
otherElement->accept(&visitor);
|
otherElement->accept(&visitor);
|
||||||
@@ -127,7 +127,7 @@ private:
|
|||||||
{
|
{
|
||||||
DiagramController *diagramController = this->diagramController();
|
DiagramController *diagramController = this->diagramController();
|
||||||
MDiagram *diagram = this->diagram();
|
MDiagram *diagram = this->diagram();
|
||||||
foreach (DElement *clonedElement, m_clonedElements) {
|
for (DElement *clonedElement : std::as_const(m_clonedElements)) {
|
||||||
DElement *activeElement = diagramController->findElement(clonedElement->uid(), diagram);
|
DElement *activeElement = diagramController->findElement(clonedElement->uid(), diagram);
|
||||||
QMT_ASSERT(activeElement, return);
|
QMT_ASSERT(activeElement, return);
|
||||||
int row = diagram->diagramElements().indexOf(activeElement);
|
int row = diagram->diagramElements().indexOf(activeElement);
|
||||||
@@ -163,7 +163,7 @@ protected:
|
|||||||
|
|
||||||
~AbstractAddRemCommand() override
|
~AbstractAddRemCommand() override
|
||||||
{
|
{
|
||||||
foreach (const Clone &clone, m_clonedElements)
|
for (const Clone &clone : std::as_const(m_clonedElements))
|
||||||
delete clone.m_clonedElement;
|
delete clone.m_clonedElement;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -450,7 +450,8 @@ DContainer DiagramController::copyElements(const DSelection &diagramSelection, c
|
|||||||
|
|
||||||
DReferences simplifiedSelection = simplify(diagramSelection, diagram);
|
DReferences simplifiedSelection = simplify(diagramSelection, diagram);
|
||||||
DContainer copiedElements;
|
DContainer copiedElements;
|
||||||
foreach (const DElement *element, simplifiedSelection.elements()) {
|
const QList<DElement *> elements = simplifiedSelection.elements();
|
||||||
|
for (const DElement *element : elements) {
|
||||||
DCloneDeepVisitor visitor;
|
DCloneDeepVisitor visitor;
|
||||||
element->accept(&visitor);
|
element->accept(&visitor);
|
||||||
DElement *clonedElement = visitor.cloned();
|
DElement *clonedElement = visitor.cloned();
|
||||||
@@ -466,7 +467,8 @@ void DiagramController::pasteElements(const DReferences &diagramContainer, MDiag
|
|||||||
// clone all elements and renew their keys
|
// clone all elements and renew their keys
|
||||||
QHash<Uid, Uid> renewedKeys;
|
QHash<Uid, Uid> renewedKeys;
|
||||||
QList<DElement *> clonedElements;
|
QList<DElement *> clonedElements;
|
||||||
foreach (const DElement *element, diagramContainer.elements()) {
|
const QList<DElement *> elements = diagramContainer.elements();
|
||||||
|
for (const DElement *element : elements) {
|
||||||
if (!isDelegatedElementOnDiagram(element, diagram)) {
|
if (!isDelegatedElementOnDiagram(element, diagram)) {
|
||||||
DCloneDeepVisitor visitor;
|
DCloneDeepVisitor visitor;
|
||||||
element->accept(&visitor);
|
element->accept(&visitor);
|
||||||
@@ -476,7 +478,7 @@ void DiagramController::pasteElements(const DReferences &diagramContainer, MDiag
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
// fix all keys referencing between pasting elements
|
// fix all keys referencing between pasting elements
|
||||||
foreach(DElement *clonedElement, clonedElements) {
|
for (DElement *clonedElement : std::as_const(clonedElements)) {
|
||||||
auto relation = dynamic_cast<DRelation *>(clonedElement);
|
auto relation = dynamic_cast<DRelation *>(clonedElement);
|
||||||
if (relation)
|
if (relation)
|
||||||
updateRelationKeys(relation, renewedKeys);
|
updateRelationKeys(relation, renewedKeys);
|
||||||
@@ -485,7 +487,7 @@ void DiagramController::pasteElements(const DReferences &diagramContainer, MDiag
|
|||||||
m_undoController->beginMergeSequence(tr("Paste"));
|
m_undoController->beginMergeSequence(tr("Paste"));
|
||||||
// insert all elements
|
// insert all elements
|
||||||
bool added = false;
|
bool added = false;
|
||||||
foreach (DElement *clonedElement, clonedElements) {
|
for (DElement *clonedElement : std::as_const(clonedElements)) {
|
||||||
if (!dynamic_cast<DRelation *>(clonedElement)) {
|
if (!dynamic_cast<DRelation *>(clonedElement)) {
|
||||||
int row = diagram->diagramElements().size();
|
int row = diagram->diagramElements().size();
|
||||||
emit beginInsertElement(row, diagram);
|
emit beginInsertElement(row, diagram);
|
||||||
@@ -499,7 +501,7 @@ void DiagramController::pasteElements(const DReferences &diagramContainer, MDiag
|
|||||||
added = true;
|
added = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
foreach (DElement *clonedElement, clonedElements) {
|
for (DElement *clonedElement : std::as_const(clonedElements)) {
|
||||||
auto clonedRelation = dynamic_cast<DRelation *>(clonedElement);
|
auto clonedRelation = dynamic_cast<DRelation *>(clonedElement);
|
||||||
if (clonedRelation && areRelationEndsOnDiagram(clonedRelation, diagram)) {
|
if (clonedRelation && areRelationEndsOnDiagram(clonedRelation, diagram)) {
|
||||||
int row = diagram->diagramElements().size();
|
int row = diagram->diagramElements().size();
|
||||||
@@ -567,14 +569,15 @@ void DiagramController::onEndUpdateObject(int row, const MObject *parent)
|
|||||||
MObject *modelObject = m_modelController->object(row, parent);
|
MObject *modelObject = m_modelController->object(row, parent);
|
||||||
QMT_ASSERT(modelObject, return);
|
QMT_ASSERT(modelObject, return);
|
||||||
auto modelPackage = dynamic_cast<MPackage *>(modelObject);
|
auto modelPackage = dynamic_cast<MPackage *>(modelObject);
|
||||||
foreach (MDiagram *diagram, m_allDiagrams) {
|
for (MDiagram *diagram : std::as_const(m_allDiagrams)) {
|
||||||
DObject *object = findDelegate<DObject>(modelObject, diagram);
|
DObject *object = findDelegate<DObject>(modelObject, diagram);
|
||||||
if (object) {
|
if (object) {
|
||||||
updateElementFromModel(object, diagram, true);
|
updateElementFromModel(object, diagram, true);
|
||||||
}
|
}
|
||||||
if (modelPackage) {
|
if (modelPackage) {
|
||||||
// update each element that has the updated object as its owner (for context changes)
|
// update each element that has the updated object as its owner (for context changes)
|
||||||
foreach (DElement *diagramElement, diagram->diagramElements()) {
|
const QList<DElement *> elements = diagram->diagramElements();
|
||||||
|
for (DElement *diagramElement : elements) {
|
||||||
if (diagramElement->modelUid().isValid()) {
|
if (diagramElement->modelUid().isValid()) {
|
||||||
MObject *mobject = m_modelController->findObject(diagramElement->modelUid());
|
MObject *mobject = m_modelController->findObject(diagramElement->modelUid());
|
||||||
if (mobject && mobject->owner() == modelPackage)
|
if (mobject && mobject->owner() == modelPackage)
|
||||||
@@ -634,7 +637,8 @@ void DiagramController::onEndMoveObject(int row, const MObject *owner)
|
|||||||
auto modelDiagram = dynamic_cast<MDiagram *>(modelObject);
|
auto modelDiagram = dynamic_cast<MDiagram *>(modelObject);
|
||||||
if (modelDiagram) {
|
if (modelDiagram) {
|
||||||
emit beginResetDiagram(modelDiagram);
|
emit beginResetDiagram(modelDiagram);
|
||||||
foreach (DElement *diagramElement, modelDiagram->diagramElements())
|
const QList<DElement *> elements = modelDiagram->diagramElements();
|
||||||
|
for (DElement *diagramElement : elements)
|
||||||
updateElementFromModel(diagramElement, modelDiagram, false);
|
updateElementFromModel(diagramElement, modelDiagram, false);
|
||||||
emit endResetDiagram(modelDiagram);
|
emit endResetDiagram(modelDiagram);
|
||||||
}
|
}
|
||||||
@@ -652,7 +656,7 @@ void DiagramController::onBeginUpdateRelation(int row, const MObject *owner)
|
|||||||
void DiagramController::onEndUpdateRelation(int row, const MObject *owner)
|
void DiagramController::onEndUpdateRelation(int row, const MObject *owner)
|
||||||
{
|
{
|
||||||
MRelation *modelRelation = owner->relations().at(row);
|
MRelation *modelRelation = owner->relations().at(row);
|
||||||
foreach (MDiagram *diagram, m_allDiagrams) {
|
for (MDiagram *diagram : std::as_const(m_allDiagrams)) {
|
||||||
DRelation *relation = findDelegate<DRelation>(modelRelation, diagram);
|
DRelation *relation = findDelegate<DRelation>(modelRelation, diagram);
|
||||||
if (relation) {
|
if (relation) {
|
||||||
updateElementFromModel(relation, diagram, true);
|
updateElementFromModel(relation, diagram, true);
|
||||||
@@ -699,7 +703,8 @@ void DiagramController::deleteElements(const DSelection &diagramSelection, MDiag
|
|||||||
if (m_undoController)
|
if (m_undoController)
|
||||||
m_undoController->beginMergeSequence(commandLabel);
|
m_undoController->beginMergeSequence(commandLabel);
|
||||||
bool removed = false;
|
bool removed = false;
|
||||||
foreach (DElement *element, simplifiedSelection.elements()) {
|
const QList<DElement *> elements = simplifiedSelection.elements();
|
||||||
|
for (DElement *element : elements) {
|
||||||
// element may have been deleted indirectly by predecessor element in loop
|
// element may have been deleted indirectly by predecessor element in loop
|
||||||
if ((element = findElement(element->uid(), diagram))) {
|
if ((element = findElement(element->uid(), diagram))) {
|
||||||
removeRelations(element, diagram);
|
removeRelations(element, diagram);
|
||||||
@@ -724,7 +729,7 @@ void DiagramController::deleteElements(const DSelection &diagramSelection, MDiag
|
|||||||
|
|
||||||
DElement *DiagramController::findElementOnAnyDiagram(const Uid &uid)
|
DElement *DiagramController::findElementOnAnyDiagram(const Uid &uid)
|
||||||
{
|
{
|
||||||
foreach (MDiagram *diagram, m_allDiagrams) {
|
for (MDiagram *diagram : std::as_const(m_allDiagrams)) {
|
||||||
DElement *element = findElement(uid, diagram);
|
DElement *element = findElement(uid, diagram);
|
||||||
if (element)
|
if (element)
|
||||||
return element;
|
return element;
|
||||||
@@ -734,7 +739,7 @@ DElement *DiagramController::findElementOnAnyDiagram(const Uid &uid)
|
|||||||
|
|
||||||
void DiagramController::removeObjects(MObject *modelObject)
|
void DiagramController::removeObjects(MObject *modelObject)
|
||||||
{
|
{
|
||||||
foreach (MDiagram *diagram, m_allDiagrams) {
|
for (MDiagram *diagram : std::as_const(m_allDiagrams)) {
|
||||||
DElement *diagramElement = findDelegate(modelObject, diagram);
|
DElement *diagramElement = findDelegate(modelObject, diagram);
|
||||||
if (diagramElement)
|
if (diagramElement)
|
||||||
removeElement(diagramElement, diagram);
|
removeElement(diagramElement, diagram);
|
||||||
@@ -764,7 +769,7 @@ void DiagramController::removeObjects(MObject *modelObject)
|
|||||||
|
|
||||||
void DiagramController::removeRelations(MRelation *modelRelation)
|
void DiagramController::removeRelations(MRelation *modelRelation)
|
||||||
{
|
{
|
||||||
foreach (MDiagram *diagram, m_allDiagrams) {
|
for (MDiagram *diagram : std::as_const(m_allDiagrams)) {
|
||||||
DElement *diagramElement = findDelegate(modelRelation, diagram);
|
DElement *diagramElement = findDelegate(modelRelation, diagram);
|
||||||
if (diagramElement)
|
if (diagramElement)
|
||||||
removeElement(diagramElement, diagram);
|
removeElement(diagramElement, diagram);
|
||||||
@@ -776,7 +781,8 @@ void DiagramController::removeRelations(DElement *element, MDiagram *diagram)
|
|||||||
{
|
{
|
||||||
auto diagramObject = dynamic_cast<DObject *>(element);
|
auto diagramObject = dynamic_cast<DObject *>(element);
|
||||||
if (diagramObject) {
|
if (diagramObject) {
|
||||||
foreach (DElement *diagramElement, diagram->diagramElements()) {
|
const QList<DElement *> elements = diagram->diagramElements();
|
||||||
|
for (DElement *diagramElement : elements) {
|
||||||
if (auto diagramRelation = dynamic_cast<DRelation *>(diagramElement)) {
|
if (auto diagramRelation = dynamic_cast<DRelation *>(diagramElement)) {
|
||||||
if (diagramRelation->endAUid() == diagramObject->uid()
|
if (diagramRelation->endAUid() == diagramObject->uid()
|
||||||
|| diagramRelation->endBUid() == diagramObject->uid()) {
|
|| diagramRelation->endBUid() == diagramObject->uid()) {
|
||||||
@@ -851,7 +857,8 @@ void DiagramController::diagramModified(MDiagram *diagram)
|
|||||||
DReferences DiagramController::simplify(const DSelection &diagramSelection, const MDiagram *diagram)
|
DReferences DiagramController::simplify(const DSelection &diagramSelection, const MDiagram *diagram)
|
||||||
{
|
{
|
||||||
DReferences references;
|
DReferences references;
|
||||||
foreach (const DSelection::Index &index, diagramSelection.indices()) {
|
const QList<DSelection::Index> indices = diagramSelection.indices();
|
||||||
|
for (const DSelection::Index &index : indices) {
|
||||||
DElement *element = findElement(index.elementKey(), diagram);
|
DElement *element = findElement(index.elementKey(), diagram);
|
||||||
if (element)
|
if (element)
|
||||||
references.append(element);
|
references.append(element);
|
||||||
@@ -898,7 +905,7 @@ void DiagramController::verifyDiagramsIntegrity()
|
|||||||
m_modelController->rootPackage()->accept(&visitor);
|
m_modelController->rootPackage()->accept(&visitor);
|
||||||
}
|
}
|
||||||
QMT_ASSERT(allDiagrams == m_allDiagrams, return);
|
QMT_ASSERT(allDiagrams == m_allDiagrams, return);
|
||||||
foreach (const MDiagram *diagram, allDiagrams)
|
for (MDiagram *diagram : std::as_const(m_allDiagrams))
|
||||||
verifyDiagramIntegrity(diagram);
|
verifyDiagramIntegrity(diagram);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -906,7 +913,8 @@ void DiagramController::verifyDiagramsIntegrity()
|
|||||||
void DiagramController::verifyDiagramIntegrity(const MDiagram *diagram)
|
void DiagramController::verifyDiagramIntegrity(const MDiagram *diagram)
|
||||||
{
|
{
|
||||||
QHash<Uid, const DElement *> delementsMap;
|
QHash<Uid, const DElement *> delementsMap;
|
||||||
foreach (const DElement *delement, diagram->diagramElements()) {
|
const QList<DElement *> elements = diagram->diagramElements();
|
||||||
|
for (const DElement *delement : elements) {
|
||||||
delementsMap.insert(delement->uid(), delement);
|
delementsMap.insert(delement->uid(), delement);
|
||||||
if (dynamic_cast<const DObject *>(delement) || dynamic_cast<const DRelation *>(delement)) {
|
if (dynamic_cast<const DObject *>(delement) || dynamic_cast<const DRelation *>(delement)) {
|
||||||
QMT_ASSERT(delement->modelUid().isValid(), return);
|
QMT_ASSERT(delement->modelUid().isValid(), return);
|
||||||
@@ -921,7 +929,7 @@ void DiagramController::verifyDiagramIntegrity(const MDiagram *diagram)
|
|||||||
QMT_ASSERT(!delement->modelUid().isValid(), return);
|
QMT_ASSERT(!delement->modelUid().isValid(), return);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
foreach (const DElement *delement, diagram->diagramElements()) {
|
for (const DElement *delement : elements) {
|
||||||
if (const DRelation *drelation = dynamic_cast<const DRelation *>(delement)) {
|
if (const DRelation *drelation = dynamic_cast<const DRelation *>(delement)) {
|
||||||
QMT_ASSERT(drelation->endAUid().isValid(), return);
|
QMT_ASSERT(drelation->endAUid().isValid(), return);
|
||||||
QMT_ASSERT(delementsMap.contains(drelation->endAUid()), return);
|
QMT_ASSERT(delementsMap.contains(drelation->endAUid()), return);
|
||||||
|
@@ -184,7 +184,8 @@ bool DiagramSceneModel::hasSelection() const
|
|||||||
bool DiagramSceneModel::hasMultiObjectsSelection() const
|
bool DiagramSceneModel::hasMultiObjectsSelection() const
|
||||||
{
|
{
|
||||||
int count = 0;
|
int count = 0;
|
||||||
foreach (QGraphicsItem *item, m_graphicsScene->selectedItems()) {
|
const QList<QGraphicsItem *> items = m_graphicsScene->selectedItems();
|
||||||
|
for (QGraphicsItem *item : items) {
|
||||||
DElement *element = m_itemToElementMap.value(item);
|
DElement *element = m_itemToElementMap.value(item);
|
||||||
QMT_CHECK(element);
|
QMT_CHECK(element);
|
||||||
if (dynamic_cast<DObject *>(element)) {
|
if (dynamic_cast<DObject *>(element)) {
|
||||||
@@ -199,7 +200,8 @@ bool DiagramSceneModel::hasMultiObjectsSelection() const
|
|||||||
DSelection DiagramSceneModel::selectedElements() const
|
DSelection DiagramSceneModel::selectedElements() const
|
||||||
{
|
{
|
||||||
DSelection selection;
|
DSelection selection;
|
||||||
foreach (QGraphicsItem *item, m_graphicsScene->selectedItems()) {
|
const QList<QGraphicsItem *> items = m_graphicsScene->selectedItems();
|
||||||
|
for (QGraphicsItem *item : items) {
|
||||||
DElement *element = m_itemToElementMap.value(item);
|
DElement *element = m_itemToElementMap.value(item);
|
||||||
QMT_ASSERT(element, return selection);
|
QMT_ASSERT(element, return selection);
|
||||||
selection.append(element->uid(), m_diagram->uid());
|
selection.append(element->uid(), m_diagram->uid());
|
||||||
@@ -210,8 +212,8 @@ DSelection DiagramSceneModel::selectedElements() const
|
|||||||
DElement *DiagramSceneModel::findTopmostElement(const QPointF &scenePos) const
|
DElement *DiagramSceneModel::findTopmostElement(const QPointF &scenePos) const
|
||||||
{
|
{
|
||||||
// fetch affected items from scene in correct drawing order to find topmost element
|
// fetch affected items from scene in correct drawing order to find topmost element
|
||||||
QList<QGraphicsItem *> items = m_graphicsScene->items(scenePos);
|
const QList<QGraphicsItem *> items = m_graphicsScene->items(scenePos);
|
||||||
foreach (QGraphicsItem *item, items) {
|
for (QGraphicsItem *item : items) {
|
||||||
if (m_graphicsItems.contains(item))
|
if (m_graphicsItems.contains(item))
|
||||||
return m_itemToElementMap.value(item);
|
return m_itemToElementMap.value(item);
|
||||||
}
|
}
|
||||||
@@ -273,7 +275,8 @@ bool DiagramSceneModel::isInFrontOf(const QGraphicsItem *frontItem, const QGraph
|
|||||||
|
|
||||||
// shortcut for usual case of root items
|
// shortcut for usual case of root items
|
||||||
if (!frontItem->parentItem() && !backItem->parentItem()) {
|
if (!frontItem->parentItem() && !backItem->parentItem()) {
|
||||||
foreach (const QGraphicsItem *item, m_graphicsScene->items()) {
|
const QList<QGraphicsItem *> items = m_graphicsScene->items();
|
||||||
|
for (const QGraphicsItem *item : items) {
|
||||||
if (item == frontItem)
|
if (item == frontItem)
|
||||||
return true;
|
return true;
|
||||||
else if (item == backItem)
|
else if (item == backItem)
|
||||||
@@ -329,7 +332,7 @@ bool DiagramSceneModel::isInFrontOf(const QGraphicsItem *frontItem, const QGraph
|
|||||||
children = frontStack.at(frontIndex + 1)->childItems();
|
children = frontStack.at(frontIndex + 1)->childItems();
|
||||||
else
|
else
|
||||||
children = m_graphicsScene->items(Qt::AscendingOrder);
|
children = m_graphicsScene->items(Qt::AscendingOrder);
|
||||||
foreach (const QGraphicsItem *item, children) {
|
for (const QGraphicsItem *item : std::as_const(children)) {
|
||||||
if (item == frontItem)
|
if (item == frontItem)
|
||||||
return false;
|
return false;
|
||||||
else if (item == backItem)
|
else if (item == backItem)
|
||||||
@@ -343,14 +346,14 @@ bool DiagramSceneModel::isInFrontOf(const QGraphicsItem *frontItem, const QGraph
|
|||||||
|
|
||||||
void DiagramSceneModel::selectAllElements()
|
void DiagramSceneModel::selectAllElements()
|
||||||
{
|
{
|
||||||
foreach (QGraphicsItem *item, m_graphicsItems)
|
for (QGraphicsItem *item : std::as_const(m_graphicsItems))
|
||||||
item->setSelected(true);
|
item->setSelected(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
void DiagramSceneModel::selectElement(DElement *element)
|
void DiagramSceneModel::selectElement(DElement *element)
|
||||||
{
|
{
|
||||||
QGraphicsItem *selectItem = m_elementToItemMap.value(element);
|
QGraphicsItem *selectItem = m_elementToItemMap.value(element);
|
||||||
foreach (QGraphicsItem *item, m_selectedItems) {
|
for (QGraphicsItem *item : std::as_const(m_selectedItems)) {
|
||||||
if (item != selectItem)
|
if (item != selectItem)
|
||||||
item->setSelected(false);
|
item->setSelected(false);
|
||||||
}
|
}
|
||||||
@@ -504,7 +507,7 @@ void DiagramSceneModel::selectItem(QGraphicsItem *item, bool multiSelect)
|
|||||||
{
|
{
|
||||||
if (!multiSelect) {
|
if (!multiSelect) {
|
||||||
if (!item->isSelected()) {
|
if (!item->isSelected()) {
|
||||||
foreach (QGraphicsItem *selectedItem, m_selectedItems) {
|
for (QGraphicsItem *selectedItem : std::as_const(m_selectedItems)) {
|
||||||
if (selectedItem != item)
|
if (selectedItem != item)
|
||||||
selectedItem->setSelected(false);
|
selectedItem->setSelected(false);
|
||||||
}
|
}
|
||||||
@@ -520,11 +523,11 @@ void DiagramSceneModel::moveSelectedItems(QGraphicsItem *grabbedItem, const QPoi
|
|||||||
Q_UNUSED(grabbedItem)
|
Q_UNUSED(grabbedItem)
|
||||||
|
|
||||||
if (delta != QPointF(0.0, 0.0)) {
|
if (delta != QPointF(0.0, 0.0)) {
|
||||||
foreach (QGraphicsItem *item, m_selectedItems) {
|
for (QGraphicsItem *item : std::as_const(m_selectedItems)) {
|
||||||
if (auto moveable = dynamic_cast<IMoveable *>(item))
|
if (auto moveable = dynamic_cast<IMoveable *>(item))
|
||||||
moveable->moveDelta(delta);
|
moveable->moveDelta(delta);
|
||||||
}
|
}
|
||||||
foreach (QGraphicsItem *item, m_secondarySelectedItems) {
|
for (QGraphicsItem *item : std::as_const(m_secondarySelectedItems)) {
|
||||||
if (auto moveable = dynamic_cast<IMoveable *>(item))
|
if (auto moveable = dynamic_cast<IMoveable *>(item))
|
||||||
moveable->moveDelta(delta);
|
moveable->moveDelta(delta);
|
||||||
}
|
}
|
||||||
@@ -533,11 +536,11 @@ void DiagramSceneModel::moveSelectedItems(QGraphicsItem *grabbedItem, const QPoi
|
|||||||
|
|
||||||
void DiagramSceneModel::alignSelectedItemsPositionOnRaster()
|
void DiagramSceneModel::alignSelectedItemsPositionOnRaster()
|
||||||
{
|
{
|
||||||
foreach (QGraphicsItem *item, m_selectedItems) {
|
for (QGraphicsItem *item : std::as_const(m_selectedItems)) {
|
||||||
if (auto moveable = dynamic_cast<IMoveable *>(item))
|
if (auto moveable = dynamic_cast<IMoveable *>(item))
|
||||||
moveable->alignItemPositionToRaster(RASTER_WIDTH, RASTER_HEIGHT);
|
moveable->alignItemPositionToRaster(RASTER_WIDTH, RASTER_HEIGHT);
|
||||||
}
|
}
|
||||||
foreach (QGraphicsItem *item, m_secondarySelectedItems) {
|
for (QGraphicsItem *item : std::as_const(m_secondarySelectedItems)) {
|
||||||
if (auto moveable = dynamic_cast<IMoveable *>(item))
|
if (auto moveable = dynamic_cast<IMoveable *>(item))
|
||||||
moveable->alignItemPositionToRaster(RASTER_WIDTH, RASTER_HEIGHT);
|
moveable->alignItemPositionToRaster(RASTER_WIDTH, RASTER_HEIGHT);
|
||||||
}
|
}
|
||||||
@@ -563,7 +566,7 @@ QList<QGraphicsItem *> DiagramSceneModel::collectCollidingObjectItems(const QGra
|
|||||||
|
|
||||||
switch (collidingMode) {
|
switch (collidingMode) {
|
||||||
case CollidingInnerItems:
|
case CollidingInnerItems:
|
||||||
foreach (QGraphicsItem *candidate, m_graphicsItems) {
|
for (QGraphicsItem *candidate : std::as_const(m_graphicsItems)) {
|
||||||
if (auto candidateResizable = dynamic_cast<const IResizable *>(candidate)) {
|
if (auto candidateResizable = dynamic_cast<const IResizable *>(candidate)) {
|
||||||
QRectF candidateRect = candidateResizable->rect();
|
QRectF candidateRect = candidateResizable->rect();
|
||||||
candidateRect.translate(candidateResizable->pos());
|
candidateRect.translate(candidateResizable->pos());
|
||||||
@@ -575,7 +578,7 @@ QList<QGraphicsItem *> DiagramSceneModel::collectCollidingObjectItems(const QGra
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case CollidingItems:
|
case CollidingItems:
|
||||||
foreach (QGraphicsItem *candidate, m_graphicsItems) {
|
for (QGraphicsItem *candidate : std::as_const(m_graphicsItems)) {
|
||||||
if (auto candidateResizable = dynamic_cast<const IResizable *>(candidate)) {
|
if (auto candidateResizable = dynamic_cast<const IResizable *>(candidate)) {
|
||||||
QRectF candidateRect = candidateResizable->rect();
|
QRectF candidateRect = candidateResizable->rect();
|
||||||
candidateRect.translate(candidateResizable->pos());
|
candidateRect.translate(candidateResizable->pos());
|
||||||
@@ -587,7 +590,7 @@ QList<QGraphicsItem *> DiagramSceneModel::collectCollidingObjectItems(const QGra
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case CollidingOuterItems:
|
case CollidingOuterItems:
|
||||||
foreach (QGraphicsItem *candidate, m_graphicsItems) {
|
for (QGraphicsItem *candidate : std::as_const(m_graphicsItems)) {
|
||||||
if (auto candidateResizable = dynamic_cast<const IResizable *>(candidate)) {
|
if (auto candidateResizable = dynamic_cast<const IResizable *>(candidate)) {
|
||||||
QRectF candidateRect = candidateResizable->rect();
|
QRectF candidateRect = candidateResizable->rect();
|
||||||
candidateRect.translate(candidateResizable->pos());
|
candidateRect.translate(candidateResizable->pos());
|
||||||
@@ -638,14 +641,15 @@ void DiagramSceneModel::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
|
|||||||
|
|
||||||
void DiagramSceneModel::mouseMoveEventReparenting(QGraphicsSceneMouseEvent *event)
|
void DiagramSceneModel::mouseMoveEventReparenting(QGraphicsSceneMouseEvent *event)
|
||||||
{
|
{
|
||||||
|
const QList<QGraphicsView *> views = m_graphicsScene->views();
|
||||||
if (event->modifiers() & Qt::AltModifier) {
|
if (event->modifiers() & Qt::AltModifier) {
|
||||||
// TODO show move cursor only if elements can be moved to underlaying element
|
// TODO show move cursor only if elements can be moved to underlaying element
|
||||||
foreach (QGraphicsView *view, m_graphicsScene->views()) {
|
for (QGraphicsView *view : views) {
|
||||||
// TODO find a better cursor that signals "move to this package"
|
// TODO find a better cursor that signals "move to this package"
|
||||||
view->setCursor(QCursor(Qt::OpenHandCursor));
|
view->setCursor(QCursor(Qt::OpenHandCursor));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
foreach (QGraphicsView *view, m_graphicsScene->views())
|
for (QGraphicsView *view : views)
|
||||||
view->unsetCursor();
|
view->unsetCursor();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -662,8 +666,8 @@ void DiagramSceneModel::mouseReleaseEventReparenting(QGraphicsSceneMouseEvent *e
|
|||||||
ModelController *modelController = diagramController()->modelController();
|
ModelController *modelController = diagramController()->modelController();
|
||||||
MPackage *newOwner = nullptr;
|
MPackage *newOwner = nullptr;
|
||||||
QSet<QGraphicsItem *> selectedItemSet = Utils::toSet(m_graphicsScene->selectedItems());
|
QSet<QGraphicsItem *> selectedItemSet = Utils::toSet(m_graphicsScene->selectedItems());
|
||||||
QList<QGraphicsItem *> itemsUnderMouse = m_graphicsScene->items(event->scenePos());
|
const QList<QGraphicsItem *> itemsUnderMouse = m_graphicsScene->items(event->scenePos());
|
||||||
foreach (QGraphicsItem *item, itemsUnderMouse) {
|
for (QGraphicsItem *item : itemsUnderMouse) {
|
||||||
if (!selectedItemSet.contains(item)) {
|
if (!selectedItemSet.contains(item)) {
|
||||||
// the item may be any graphics item not matching to a DElement
|
// the item may be any graphics item not matching to a DElement
|
||||||
DElement *element = m_itemToElementMap.value(item);
|
DElement *element = m_itemToElementMap.value(item);
|
||||||
@@ -674,7 +678,8 @@ void DiagramSceneModel::mouseReleaseEventReparenting(QGraphicsSceneMouseEvent *e
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (newOwner) {
|
if (newOwner) {
|
||||||
foreach (QGraphicsItem *item, m_graphicsScene->selectedItems()) {
|
const QList<QGraphicsItem *> items = m_graphicsScene->selectedItems();
|
||||||
|
for (QGraphicsItem *item : items) {
|
||||||
DElement *element = m_itemToElementMap.value(item);
|
DElement *element = m_itemToElementMap.value(item);
|
||||||
QMT_ASSERT(element, return);
|
QMT_ASSERT(element, return);
|
||||||
if (element->modelUid().isValid()) {
|
if (element->modelUid().isValid()) {
|
||||||
@@ -687,7 +692,8 @@ void DiagramSceneModel::mouseReleaseEventReparenting(QGraphicsSceneMouseEvent *e
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
foreach (QGraphicsView *view, m_graphicsScene->views())
|
const QList<QGraphicsView *> views = m_graphicsScene->views();
|
||||||
|
for (QGraphicsView *view : views)
|
||||||
view->unsetCursor();
|
view->unsetCursor();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -715,7 +721,8 @@ void DiagramSceneModel::onEndResetDiagram(const MDiagram *diagram)
|
|||||||
if (diagram == m_diagram) {
|
if (diagram == m_diagram) {
|
||||||
QMT_CHECK(m_graphicsItems.size() == 0);
|
QMT_CHECK(m_graphicsItems.size() == 0);
|
||||||
// create all items and update graphics item from element initially
|
// create all items and update graphics item from element initially
|
||||||
foreach (DElement *element, diagram->diagramElements()) {
|
const QList<DElement *> elements = diagram->diagramElements();
|
||||||
|
for (DElement *element : elements) {
|
||||||
QGraphicsItem *item = createGraphicsItem(element);
|
QGraphicsItem *item = createGraphicsItem(element);
|
||||||
m_graphicsItems.append(item);
|
m_graphicsItems.append(item);
|
||||||
updateGraphicsItem(item, element);
|
updateGraphicsItem(item, element);
|
||||||
@@ -723,7 +730,7 @@ void DiagramSceneModel::onEndResetDiagram(const MDiagram *diagram)
|
|||||||
// invalidate scene
|
// invalidate scene
|
||||||
m_graphicsScene->invalidate();
|
m_graphicsScene->invalidate();
|
||||||
// update graphics items again so every item gets a correct list of colliding items
|
// update graphics items again so every item gets a correct list of colliding items
|
||||||
foreach (DElement *element, diagram->diagramElements())
|
for (DElement *element : elements)
|
||||||
updateGraphicsItem(m_elementToItemMap.value(element), element);
|
updateGraphicsItem(m_elementToItemMap.value(element), element);
|
||||||
recalcSceneRectSize();
|
recalcSceneRectSize();
|
||||||
}
|
}
|
||||||
@@ -820,16 +827,16 @@ void DiagramSceneModel::onSelectionChanged()
|
|||||||
bool selectionChanged = false;
|
bool selectionChanged = false;
|
||||||
|
|
||||||
// collect and update all primary selected items (selected by user)
|
// collect and update all primary selected items (selected by user)
|
||||||
QSet<QGraphicsItem *> newSelectedItems = Utils::toSet(m_graphicsScene->selectedItems());
|
const QSet<QGraphicsItem *> newSelectedItems = Utils::toSet(m_graphicsScene->selectedItems());
|
||||||
updateFocusItem(newSelectedItems);
|
updateFocusItem(newSelectedItems);
|
||||||
foreach (QGraphicsItem *item, m_selectedItems) {
|
for (QGraphicsItem *item : std::as_const(m_selectedItems)) {
|
||||||
if (!newSelectedItems.contains(item)) {
|
if (!newSelectedItems.contains(item)) {
|
||||||
DElement *element = m_itemToElementMap.value(item);
|
DElement *element = m_itemToElementMap.value(item);
|
||||||
updateGraphicsItem(item, element);
|
updateGraphicsItem(item, element);
|
||||||
selectionChanged = true;
|
selectionChanged = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
foreach (QGraphicsItem *item, newSelectedItems) {
|
for (QGraphicsItem *item : newSelectedItems) {
|
||||||
if (!m_selectedItems.contains(item)) {
|
if (!m_selectedItems.contains(item)) {
|
||||||
DElement *element = m_itemToElementMap.value(item);
|
DElement *element = m_itemToElementMap.value(item);
|
||||||
updateGraphicsItem(item, element);
|
updateGraphicsItem(item, element);
|
||||||
@@ -842,8 +849,9 @@ void DiagramSceneModel::onSelectionChanged()
|
|||||||
QSet<QGraphicsItem *> newSecondarySelectedItems;
|
QSet<QGraphicsItem *> newSecondarySelectedItems;
|
||||||
|
|
||||||
// select all contained objects secondarily
|
// select all contained objects secondarily
|
||||||
foreach (QGraphicsItem *selectedItem, m_selectedItems) {
|
for (QGraphicsItem *selectedItem : std::as_const(m_secondarySelectedItems)) {
|
||||||
foreach (QGraphicsItem *item, collectCollidingObjectItems(selectedItem, CollidingInnerItems)) {
|
const QList<QGraphicsItem *> items = collectCollidingObjectItems(selectedItem, CollidingInnerItems);
|
||||||
|
for (QGraphicsItem *item : items) {
|
||||||
if (!item->isSelected() && dynamic_cast<ISelectable *>(item)
|
if (!item->isSelected() && dynamic_cast<ISelectable *>(item)
|
||||||
&& item->collidesWithItem(selectedItem, Qt::ContainsItemBoundingRect)
|
&& item->collidesWithItem(selectedItem, Qt::ContainsItemBoundingRect)
|
||||||
&& isInFrontOf(item, selectedItem)) {
|
&& isInFrontOf(item, selectedItem)) {
|
||||||
@@ -875,7 +883,8 @@ void DiagramSceneModel::onSelectionChanged()
|
|||||||
|
|
||||||
|
|
||||||
// select all relations where both ends are primary or secondary selected
|
// select all relations where both ends are primary or secondary selected
|
||||||
foreach (DElement *element, m_diagram->diagramElements()) {
|
const QList<DElement *> elements = m_diagram->diagramElements();
|
||||||
|
for (DElement *element : elements) {
|
||||||
auto relation = dynamic_cast<DRelation *>(element);
|
auto relation = dynamic_cast<DRelation *>(element);
|
||||||
if (relation) {
|
if (relation) {
|
||||||
QGraphicsItem *relationItem = m_elementToItemMap.value(relation);
|
QGraphicsItem *relationItem = m_elementToItemMap.value(relation);
|
||||||
@@ -897,7 +906,7 @@ void DiagramSceneModel::onSelectionChanged()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach (QGraphicsItem *item, m_secondarySelectedItems) {
|
for (QGraphicsItem *item : std::as_const(m_secondarySelectedItems)) {
|
||||||
if (!newSecondarySelectedItems.contains(item)) {
|
if (!newSecondarySelectedItems.contains(item)) {
|
||||||
auto selectable = dynamic_cast<ISelectable *>(item);
|
auto selectable = dynamic_cast<ISelectable *>(item);
|
||||||
QMT_ASSERT(selectable, return);
|
QMT_ASSERT(selectable, return);
|
||||||
@@ -905,7 +914,7 @@ void DiagramSceneModel::onSelectionChanged()
|
|||||||
selectionChanged = true;
|
selectionChanged = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
foreach (QGraphicsItem *item, newSecondarySelectedItems) {
|
for (QGraphicsItem *item : std::as_const(newSecondarySelectedItems)) {
|
||||||
if (!m_secondarySelectedItems.contains(item)) {
|
if (!m_secondarySelectedItems.contains(item)) {
|
||||||
auto selectable = dynamic_cast<ISelectable *>(item);
|
auto selectable = dynamic_cast<ISelectable *>(item);
|
||||||
QMT_ASSERT(selectable, return);
|
QMT_ASSERT(selectable, return);
|
||||||
@@ -959,7 +968,7 @@ void DiagramSceneModel::saveSelectionStatusBeforeExport(bool exportSelectedEleme
|
|||||||
|
|
||||||
// Selections would also render to the clipboard
|
// Selections would also render to the clipboard
|
||||||
m_graphicsScene->clearSelection();
|
m_graphicsScene->clearSelection();
|
||||||
foreach (QGraphicsItem *item, m_graphicsItems) {
|
for (QGraphicsItem *item : std::as_const(m_graphicsItems)) {
|
||||||
if (IEditable *editItem = dynamic_cast<IEditable *>(item)) {
|
if (IEditable *editItem = dynamic_cast<IEditable *>(item)) {
|
||||||
if (editItem->isEditing()) {
|
if (editItem->isEditing()) {
|
||||||
status->m_editItem = editItem;
|
status->m_editItem = editItem;
|
||||||
@@ -969,7 +978,7 @@ void DiagramSceneModel::saveSelectionStatusBeforeExport(bool exportSelectedEleme
|
|||||||
}
|
}
|
||||||
removeExtraSceneItems();
|
removeExtraSceneItems();
|
||||||
|
|
||||||
foreach (QGraphicsItem *item, m_graphicsItems) {
|
for (QGraphicsItem *item : std::as_const(m_graphicsItems)) {
|
||||||
if (!exportSelectedElements
|
if (!exportSelectedElements
|
||||||
|| status->m_selectedItems.contains(item)
|
|| status->m_selectedItems.contains(item)
|
||||||
|| status->m_secondarySelectedItems.contains(item)) {
|
|| status->m_secondarySelectedItems.contains(item)) {
|
||||||
@@ -997,13 +1006,13 @@ void DiagramSceneModel::restoreSelectedStatusAfterExport(const DiagramSceneModel
|
|||||||
{
|
{
|
||||||
if (status.m_exportSelectedElements) {
|
if (status.m_exportSelectedElements) {
|
||||||
// TODO once an annotation item had focus the call to show() will give it focus again. Bug in Qt?
|
// TODO once an annotation item had focus the call to show() will give it focus again. Bug in Qt?
|
||||||
foreach (QGraphicsItem *item, m_graphicsItems)
|
for (QGraphicsItem *item : std::as_const(m_graphicsItems))
|
||||||
item->show();
|
item->show();
|
||||||
}
|
}
|
||||||
|
|
||||||
addExtraSceneItems();
|
addExtraSceneItems();
|
||||||
|
|
||||||
foreach (QGraphicsItem *item, status.m_selectedItems)
|
for (QGraphicsItem *item : std::as_const(status.m_selectedItems))
|
||||||
item->setSelected(true);
|
item->setSelected(true);
|
||||||
|
|
||||||
// reset focus item
|
// reset focus item
|
||||||
|
@@ -55,7 +55,7 @@ public:
|
|||||||
|
|
||||||
bool contains(const Uid &uid) const
|
bool contains(const Uid &uid) const
|
||||||
{
|
{
|
||||||
foreach (const Handle<T> &handle, m_handleList) {
|
for (const Handle<T> &handle : std::as_const(m_handleList)) {
|
||||||
if (handle.uid() == uid)
|
if (handle.uid() == uid)
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -70,7 +70,7 @@ public:
|
|||||||
|
|
||||||
T *find(const Uid &uid) const
|
T *find(const Uid &uid) const
|
||||||
{
|
{
|
||||||
foreach (const Handle<T> &handle, m_handleList) {
|
for (const Handle<T> &handle : std::as_const(m_handleList)) {
|
||||||
if (handle.uid() == uid)
|
if (handle.uid() == uid)
|
||||||
return handle.target();
|
return handle.target();
|
||||||
}
|
}
|
||||||
@@ -92,7 +92,7 @@ public:
|
|||||||
int indexOf(const Uid &uid) const
|
int indexOf(const Uid &uid) const
|
||||||
{
|
{
|
||||||
int index = 0;
|
int index = 0;
|
||||||
foreach (const Handle<T> &handle, m_handleList) {
|
for (const Handle<T> &handle : std::as_const(m_handleList)) {
|
||||||
if (handle.uid() == uid)
|
if (handle.uid() == uid)
|
||||||
return index;
|
return index;
|
||||||
++index;
|
++index;
|
||||||
@@ -123,7 +123,7 @@ public:
|
|||||||
void reset()
|
void reset()
|
||||||
{
|
{
|
||||||
if (m_takesOwnership) {
|
if (m_takesOwnership) {
|
||||||
foreach (const Handle<T> &handle, m_handleList)
|
for (const Handle<T> &handle : std::as_const(m_handleList))
|
||||||
delete handle.target();
|
delete handle.target();
|
||||||
}
|
}
|
||||||
m_handleList.clear();
|
m_handleList.clear();
|
||||||
|
@@ -274,7 +274,7 @@ PropertiesView::MView::~MView()
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
void PropertiesView::MView::update(QList<MElement *> &modelElements)
|
void PropertiesView::MView::update(const QList<MElement *> &modelElements)
|
||||||
{
|
{
|
||||||
QMT_ASSERT(modelElements.size() > 0, return);
|
QMT_ASSERT(modelElements.size() > 0, return);
|
||||||
|
|
||||||
@@ -284,7 +284,7 @@ void PropertiesView::MView::update(QList<MElement *> &modelElements)
|
|||||||
modelElements.at(0)->accept(this);
|
modelElements.at(0)->accept(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
void PropertiesView::MView::update(QList<DElement *> &diagramElements, MDiagram *diagram)
|
void PropertiesView::MView::update(const QList<DElement *> &diagramElements, MDiagram *diagram)
|
||||||
{
|
{
|
||||||
QMT_ASSERT(diagramElements.size() > 0, return);
|
QMT_ASSERT(diagramElements.size() > 0, return);
|
||||||
QMT_ASSERT(diagram, return);
|
QMT_ASSERT(diagram, return);
|
||||||
@@ -292,7 +292,7 @@ void PropertiesView::MView::update(QList<DElement *> &diagramElements, MDiagram
|
|||||||
m_diagramElements = diagramElements;
|
m_diagramElements = diagramElements;
|
||||||
m_diagram = diagram;
|
m_diagram = diagram;
|
||||||
m_modelElements.clear();
|
m_modelElements.clear();
|
||||||
foreach (DElement *delement, diagramElements) {
|
for (DElement *delement : diagramElements) {
|
||||||
bool appendedMelement = false;
|
bool appendedMelement = false;
|
||||||
if (delement->modelUid().isValid()) {
|
if (delement->modelUid().isValid()) {
|
||||||
MElement *melement = m_propertiesView->modelController()->findElement(delement->modelUid());
|
MElement *melement = m_propertiesView->modelController()->findElement(delement->modelUid());
|
||||||
@@ -1181,11 +1181,11 @@ void PropertiesView::MView::onParseClassMembers()
|
|||||||
m_classMembersEdit->reparse();
|
m_classMembersEdit->reparse();
|
||||||
}
|
}
|
||||||
|
|
||||||
void PropertiesView::MView::onClassMembersChanged(QList<MClassMember> &classMembers)
|
void PropertiesView::MView::onClassMembersChanged(const QList<MClassMember> &classMembers)
|
||||||
{
|
{
|
||||||
QSet<Uid> showMembers;
|
QSet<Uid> showMembers;
|
||||||
if (!classMembers.isEmpty()) {
|
if (!classMembers.isEmpty()) {
|
||||||
foreach (MElement *element, m_modelElements) {
|
for (MElement *element : std::as_const(m_modelElements)) {
|
||||||
MClass *klass = dynamic_cast<MClass *>(element);
|
MClass *klass = dynamic_cast<MClass *>(element);
|
||||||
if (klass && klass->members().isEmpty())
|
if (klass && klass->members().isEmpty())
|
||||||
showMembers.insert(klass->uid());
|
showMembers.insert(klass->uid());
|
||||||
@@ -1193,7 +1193,7 @@ void PropertiesView::MView::onClassMembersChanged(QList<MClassMember> &classMemb
|
|||||||
}
|
}
|
||||||
assignModelElement<MClass, QList<MClassMember>>(m_modelElements, SelectionSingle, classMembers,
|
assignModelElement<MClass, QList<MClassMember>>(m_modelElements, SelectionSingle, classMembers,
|
||||||
&MClass::members, &MClass::setMembers);
|
&MClass::members, &MClass::setMembers);
|
||||||
foreach (DElement *element, m_diagramElements) {
|
for (DElement *element : std::as_const(m_diagramElements)) {
|
||||||
if (showMembers.contains(element->modelUid())) {
|
if (showMembers.contains(element->modelUid())) {
|
||||||
assignModelElement<DClass, bool>(QList<DElement *>({element}), SelectionSingle, true,
|
assignModelElement<DClass, bool>(QList<DElement *>({element}), SelectionSingle, true,
|
||||||
&DClass::showAllMembers, &DClass::setShowAllMembers);
|
&DClass::showAllMembers, &DClass::setShowAllMembers);
|
||||||
@@ -1571,7 +1571,8 @@ void PropertiesView::MView::setEndBName(const QString &endBName)
|
|||||||
QList<QString> PropertiesView::MView::splitTemplateParameters(const QString &templateParameters)
|
QList<QString> PropertiesView::MView::splitTemplateParameters(const QString &templateParameters)
|
||||||
{
|
{
|
||||||
QList<QString> templateParametersList;
|
QList<QString> templateParametersList;
|
||||||
foreach (const QString ¶meter, templateParameters.split(QLatin1Char(','))) {
|
const QStringList parameters = templateParameters.split(QLatin1Char(','));
|
||||||
|
for (const QString ¶meter : parameters) {
|
||||||
const QString &p = parameter.trimmed();
|
const QString &p = parameter.trimmed();
|
||||||
if (!p.isEmpty())
|
if (!p.isEmpty())
|
||||||
templateParametersList.append(p);
|
templateParametersList.append(p);
|
||||||
@@ -1583,7 +1584,7 @@ QString PropertiesView::MView::formatTemplateParameters(const QList<QString> &te
|
|||||||
{
|
{
|
||||||
QString templateParamters;
|
QString templateParamters;
|
||||||
bool first = true;
|
bool first = true;
|
||||||
foreach (const QString ¶meter, templateParametersList) {
|
for (const QString ¶meter : templateParametersList) {
|
||||||
if (!first)
|
if (!first)
|
||||||
templateParamters += ", ";
|
templateParamters += ", ";
|
||||||
templateParamters += parameter;
|
templateParamters += parameter;
|
||||||
@@ -1596,7 +1597,7 @@ template<class T, class V>
|
|||||||
QList<T *> PropertiesView::MView::filter(const QList<V *> &elements)
|
QList<T *> PropertiesView::MView::filter(const QList<V *> &elements)
|
||||||
{
|
{
|
||||||
QList<T *> filtered;
|
QList<T *> filtered;
|
||||||
foreach (V *element, elements) {
|
for (V *element : elements) {
|
||||||
auto t = dynamic_cast<T *>(element);
|
auto t = dynamic_cast<T *>(element);
|
||||||
if (t)
|
if (t)
|
||||||
filtered.append(t);
|
filtered.append(t);
|
||||||
@@ -1607,11 +1608,11 @@ QList<T *> PropertiesView::MView::filter(const QList<V *> &elements)
|
|||||||
template<class T, class V, class BASE>
|
template<class T, class V, class BASE>
|
||||||
bool PropertiesView::MView::haveSameValue(const QList<BASE *> &baseElements, V (T::*getter)() const, V *value)
|
bool PropertiesView::MView::haveSameValue(const QList<BASE *> &baseElements, V (T::*getter)() const, V *value)
|
||||||
{
|
{
|
||||||
QList<T *> elements = filter<T>(baseElements);
|
const QList<T *> elements = filter<T>(baseElements);
|
||||||
QMT_CHECK(!elements.isEmpty());
|
QMT_CHECK(!elements.isEmpty());
|
||||||
V candidate = V(); // avoid warning of reading uninitialized variable
|
V candidate = V(); // avoid warning of reading uninitialized variable
|
||||||
bool haveCandidate = false;
|
bool haveCandidate = false;
|
||||||
foreach (T *element, elements) {
|
for (T *element : elements) {
|
||||||
if (!haveCandidate) {
|
if (!haveCandidate) {
|
||||||
candidate = ((*element).*getter)();
|
candidate = ((*element).*getter)();
|
||||||
haveCandidate = true;
|
haveCandidate = true;
|
||||||
@@ -1632,9 +1633,9 @@ template<class T, class V, class BASE>
|
|||||||
void PropertiesView::MView::assignModelElement(const QList<BASE *> &baseElements, SelectionType selectionType,
|
void PropertiesView::MView::assignModelElement(const QList<BASE *> &baseElements, SelectionType selectionType,
|
||||||
const V &value, V (T::*getter)() const, void (T::*setter)(const V &))
|
const V &value, V (T::*getter)() const, void (T::*setter)(const V &))
|
||||||
{
|
{
|
||||||
QList<T *> elements = filter<T>(baseElements);
|
const QList<T *> elements = filter<T>(baseElements);
|
||||||
if ((selectionType == SelectionSingle && elements.size() == 1) || selectionType == SelectionMulti) {
|
if ((selectionType == SelectionSingle && elements.size() == 1) || selectionType == SelectionMulti) {
|
||||||
foreach (T *element, elements) {
|
for (T *element : elements) {
|
||||||
if (value != ((*element).*getter)()) {
|
if (value != ((*element).*getter)()) {
|
||||||
m_propertiesView->beginUpdate(element);
|
m_propertiesView->beginUpdate(element);
|
||||||
((*element).*setter)(value);
|
((*element).*setter)(value);
|
||||||
@@ -1648,9 +1649,9 @@ template<class T, class V, class BASE>
|
|||||||
void PropertiesView::MView::assignModelElement(const QList<BASE *> &baseElements, SelectionType selectionType,
|
void PropertiesView::MView::assignModelElement(const QList<BASE *> &baseElements, SelectionType selectionType,
|
||||||
const V &value, V (T::*getter)() const, void (T::*setter)(V))
|
const V &value, V (T::*getter)() const, void (T::*setter)(V))
|
||||||
{
|
{
|
||||||
QList<T *> elements = filter<T>(baseElements);
|
const QList<T *> elements = filter<T>(baseElements);
|
||||||
if ((selectionType == SelectionSingle && elements.size() == 1) || selectionType == SelectionMulti) {
|
if ((selectionType == SelectionSingle && elements.size() == 1) || selectionType == SelectionMulti) {
|
||||||
foreach (T *element, elements) {
|
for (T *element : elements) {
|
||||||
if (value != ((*element).*getter)()) {
|
if (value != ((*element).*getter)()) {
|
||||||
m_propertiesView->beginUpdate(element);
|
m_propertiesView->beginUpdate(element);
|
||||||
((*element).*setter)(value);
|
((*element).*setter)(value);
|
||||||
@@ -1666,9 +1667,9 @@ void PropertiesView::MView::assignEmbeddedModelElement(const QList<BASE *> &base
|
|||||||
void (T::*setter)(const E &),
|
void (T::*setter)(const E &),
|
||||||
V (E::*vGetter)() const, void (E::*vSetter)(const V &))
|
V (E::*vGetter)() const, void (E::*vSetter)(const V &))
|
||||||
{
|
{
|
||||||
QList<T *> elements = filter<T>(baseElements);
|
const QList<T *> elements = filter<T>(baseElements);
|
||||||
if ((selectionType == SelectionSingle && elements.size() == 1) || selectionType == SelectionMulti) {
|
if ((selectionType == SelectionSingle && elements.size() == 1) || selectionType == SelectionMulti) {
|
||||||
foreach (T *element, elements) {
|
for (T *element : elements) {
|
||||||
E embedded = ((*element).*getter)();
|
E embedded = ((*element).*getter)();
|
||||||
if (value != (embedded.*vGetter)()) {
|
if (value != (embedded.*vGetter)()) {
|
||||||
m_propertiesView->beginUpdate(element);
|
m_propertiesView->beginUpdate(element);
|
||||||
@@ -1686,9 +1687,9 @@ void PropertiesView::MView::assignEmbeddedModelElement(const QList<BASE *> &base
|
|||||||
void (T::*setter)(const E &),
|
void (T::*setter)(const E &),
|
||||||
V (E::*vGetter)() const, void (E::*vSetter)(V))
|
V (E::*vGetter)() const, void (E::*vSetter)(V))
|
||||||
{
|
{
|
||||||
QList<T *> elements = filter<T>(baseElements);
|
const QList<T *> elements = filter<T>(baseElements);
|
||||||
if ((selectionType == SelectionSingle && elements.size() == 1) || selectionType == SelectionMulti) {
|
if ((selectionType == SelectionSingle && elements.size() == 1) || selectionType == SelectionMulti) {
|
||||||
foreach (T *element, elements) {
|
for (T *element : elements) {
|
||||||
E embedded = ((*element).*getter)();
|
E embedded = ((*element).*getter)();
|
||||||
if (value != (embedded.*vGetter)()) {
|
if (value != (embedded.*vGetter)()) {
|
||||||
m_propertiesView->beginUpdate(element);
|
m_propertiesView->beginUpdate(element);
|
||||||
|
@@ -74,8 +74,8 @@ public:
|
|||||||
void visitDBoundary(const DBoundary *boundary) override;
|
void visitDBoundary(const DBoundary *boundary) override;
|
||||||
void visitDSwimlane(const DSwimlane *swimlane) override;
|
void visitDSwimlane(const DSwimlane *swimlane) override;
|
||||||
|
|
||||||
void update(QList<MElement *> &modelElements);
|
void update(const QList<MElement *> &modelElements);
|
||||||
void update(QList<DElement *> &diagramElements, MDiagram *diagram);
|
void update(const QList<DElement *> &diagramElements, MDiagram *diagram);
|
||||||
void edit();
|
void edit();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
@@ -85,7 +85,7 @@ protected:
|
|||||||
void onTemplateParametersChanged(const QString &templateParameters);
|
void onTemplateParametersChanged(const QString &templateParameters);
|
||||||
void onClassMembersStatusChanged(bool valid);
|
void onClassMembersStatusChanged(bool valid);
|
||||||
void onParseClassMembers();
|
void onParseClassMembers();
|
||||||
void onClassMembersChanged(QList<MClassMember> &classMembers);
|
void onClassMembersChanged(const QList<MClassMember> &classMembers);
|
||||||
void onItemVarietyChanged(const QString &variety);
|
void onItemVarietyChanged(const QString &variety);
|
||||||
void onRelationNameChanged(const QString &name);
|
void onRelationNameChanged(const QString &name);
|
||||||
void onDependencyDirectionChanged(int directionIndex);
|
void onDependencyDirectionChanged(int directionIndex);
|
||||||
|
@@ -104,7 +104,7 @@ QList<Toolbar> StereotypeController::findToolbars(const QString &elementType) co
|
|||||||
QList<QString> StereotypeController::knownStereotypes(StereotypeIcon::Element stereotypeElement) const
|
QList<QString> StereotypeController::knownStereotypes(StereotypeIcon::Element stereotypeElement) const
|
||||||
{
|
{
|
||||||
QSet<QString> stereotypes;
|
QSet<QString> stereotypes;
|
||||||
foreach (const StereotypeIcon &icon, d->m_iconIdToStereotypeIconsMap) {
|
for (const StereotypeIcon &icon : d->m_iconIdToStereotypeIconsMap) {
|
||||||
if (icon.elements().isEmpty() || icon.elements().contains(stereotypeElement))
|
if (icon.elements().isEmpty() || icon.elements().contains(stereotypeElement))
|
||||||
stereotypes += icon.stereotypes();
|
stereotypes += icon.stereotypes();
|
||||||
}
|
}
|
||||||
@@ -116,7 +116,7 @@ QList<QString> StereotypeController::knownStereotypes(StereotypeIcon::Element st
|
|||||||
QString StereotypeController::findStereotypeIconId(StereotypeIcon::Element element,
|
QString StereotypeController::findStereotypeIconId(StereotypeIcon::Element element,
|
||||||
const QList<QString> &stereotypes) const
|
const QList<QString> &stereotypes) const
|
||||||
{
|
{
|
||||||
foreach (const QString &stereotype, stereotypes) {
|
for (const QString &stereotype : stereotypes) {
|
||||||
auto it = d->m_stereotypeToIconIdMap.constFind({element, stereotype});
|
auto it = d->m_stereotypeToIconIdMap.constFind({element, stereotype});
|
||||||
if (it != d->m_stereotypeToIconIdMap.constEnd())
|
if (it != d->m_stereotypeToIconIdMap.constEnd())
|
||||||
return it.value();
|
return it.value();
|
||||||
@@ -133,7 +133,8 @@ QList<QString> StereotypeController::filterStereotypesByIconId(const QString &st
|
|||||||
if (!d->m_iconIdToStereotypeIconsMap.contains(stereotypeIconId))
|
if (!d->m_iconIdToStereotypeIconsMap.contains(stereotypeIconId))
|
||||||
return stereotypes;
|
return stereotypes;
|
||||||
QList<QString> filteredStereotypes = stereotypes;
|
QList<QString> filteredStereotypes = stereotypes;
|
||||||
foreach (const QString &stereotype, d->m_iconIdToStereotypeIconsMap.value(stereotypeIconId).stereotypes())
|
const QSet<QString> stereotypeList = d->m_iconIdToStereotypeIconsMap.value(stereotypeIconId).stereotypes();
|
||||||
|
for (const QString &stereotype : stereotypeList)
|
||||||
filteredStereotypes.removeAll(stereotype);
|
filteredStereotypes.removeAll(stereotype);
|
||||||
return filteredStereotypes;
|
return filteredStereotypes;
|
||||||
}
|
}
|
||||||
@@ -233,11 +234,14 @@ QIcon StereotypeController::createIcon(StereotypeIcon::Element element, const QL
|
|||||||
void StereotypeController::addStereotypeIcon(const StereotypeIcon &stereotypeIcon)
|
void StereotypeController::addStereotypeIcon(const StereotypeIcon &stereotypeIcon)
|
||||||
{
|
{
|
||||||
if (stereotypeIcon.elements().isEmpty()) {
|
if (stereotypeIcon.elements().isEmpty()) {
|
||||||
foreach (const QString &stereotype, stereotypeIcon.stereotypes())
|
const QSet<QString> stereotypes = stereotypeIcon.stereotypes();
|
||||||
|
for (const QString &stereotype : stereotypes)
|
||||||
d->m_stereotypeToIconIdMap.insert({StereotypeIcon::ElementAny, stereotype}, stereotypeIcon.id());
|
d->m_stereotypeToIconIdMap.insert({StereotypeIcon::ElementAny, stereotype}, stereotypeIcon.id());
|
||||||
} else {
|
} else {
|
||||||
foreach (StereotypeIcon::Element element, stereotypeIcon.elements()) {
|
const QSet<StereotypeIcon::Element> elements = stereotypeIcon.elements();
|
||||||
foreach (const QString &stereotype, stereotypeIcon.stereotypes())
|
for (StereotypeIcon::Element element : elements) {
|
||||||
|
const QSet<QString> stereotypes = stereotypeIcon.stereotypes();
|
||||||
|
for (const QString &stereotype : stereotypes)
|
||||||
d->m_stereotypeToIconIdMap.insert({element, stereotype}, stereotypeIcon.id());
|
d->m_stereotypeToIconIdMap.insert({element, stereotype}, stereotypeIcon.id());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -262,7 +262,8 @@ const Style *DefaultStyleEngine::applyObjectStyle(const Style *baseStyle, const
|
|||||||
DObject::VisualPrimaryRole styledVisualPrimaryRole = styledObject.objectVisuals().visualPrimaryRole();
|
DObject::VisualPrimaryRole styledVisualPrimaryRole = styledObject.objectVisuals().visualPrimaryRole();
|
||||||
DObject::VisualSecondaryRole styledVisualSecondaryRole = styledObject.objectVisuals().visualSecondaryRole();
|
DObject::VisualSecondaryRole styledVisualSecondaryRole = styledObject.objectVisuals().visualSecondaryRole();
|
||||||
QHash<int, DepthProperties> depths;
|
QHash<int, DepthProperties> depths;
|
||||||
foreach (const DObject *collidingObject, styledObject.collidingObjects()) {
|
const QList<const DObject *> collidingObjectList = styledObject.collidingObjects();
|
||||||
|
for (const DObject *collidingObject : collidingObjectList) {
|
||||||
int collidingDepth = collidingObject->depth();
|
int collidingDepth = collidingObject->depth();
|
||||||
if (collidingDepth < styledObject.object()->depth()) {
|
if (collidingDepth < styledObject.object()->depth()) {
|
||||||
ElementType collidingElementType = objectType(collidingObject);
|
ElementType collidingElementType = objectType(collidingObject);
|
||||||
@@ -297,7 +298,7 @@ const Style *DefaultStyleEngine::applyObjectStyle(const Style *baseStyle, const
|
|||||||
int depth = 0;
|
int depth = 0;
|
||||||
if (!depths.isEmpty()) {
|
if (!depths.isEmpty()) {
|
||||||
const QList<int> keys = Utils::sorted(depths.keys());
|
const QList<int> keys = Utils::sorted(depths.keys());
|
||||||
foreach (int d, keys) {
|
for (int d : keys) {
|
||||||
DepthProperties properties = depths.value(d);
|
DepthProperties properties = depths.value(d);
|
||||||
if (properties.m_elementType == elementType
|
if (properties.m_elementType == elementType
|
||||||
&& areStackingRoles(properties.m_visualPrimaryRole, properties.m_visualSecondaryRole,
|
&& areStackingRoles(properties.m_visualPrimaryRole, properties.m_visualSecondaryRole,
|
||||||
|
@@ -18,7 +18,7 @@ template<class Archive, class T>
|
|||||||
inline void save(Archive &archive, const QList<T> &list, const Parameters &)
|
inline void save(Archive &archive, const QList<T> &list, const Parameters &)
|
||||||
{
|
{
|
||||||
archive << tag("qlist");
|
archive << tag("qlist");
|
||||||
foreach (const T &t, list)
|
for (const T &t : list)
|
||||||
archive << attr("item", t);
|
archive << attr("item", t);
|
||||||
archive << end;
|
archive << end;
|
||||||
}
|
}
|
||||||
@@ -28,10 +28,10 @@ inline void save(Archive &archive, const QList<T *> &list, const Parameters &par
|
|||||||
{
|
{
|
||||||
archive << tag("qlist");
|
archive << tag("qlist");
|
||||||
if (parameters.hasFlag(ENFORCE_REFERENCED_ITEMS)) {
|
if (parameters.hasFlag(ENFORCE_REFERENCED_ITEMS)) {
|
||||||
foreach (const T *t, list)
|
for (const T *t : list)
|
||||||
archive << ref("item", t);
|
archive << ref("item", t);
|
||||||
} else {
|
} else {
|
||||||
foreach (const T *t, list)
|
for (const T *t : list)
|
||||||
archive << attr("item", t);
|
archive << attr("item", t);
|
||||||
}
|
}
|
||||||
archive << end;
|
archive << end;
|
||||||
@@ -68,7 +68,7 @@ template<class Archive, class T>
|
|||||||
inline void save(Archive &archive, const QSet<T> &set, const Parameters &)
|
inline void save(Archive &archive, const QSet<T> &set, const Parameters &)
|
||||||
{
|
{
|
||||||
archive << tag("qset");
|
archive << tag("qset");
|
||||||
foreach (const T &t, set)
|
for (const T &t : set)
|
||||||
archive << attr("item", t);
|
archive << attr("item", t);
|
||||||
archive << end;
|
archive << end;
|
||||||
}
|
}
|
||||||
@@ -78,10 +78,10 @@ inline void save(Archive &archive, const QSet<T *> &set, const Parameters ¶m
|
|||||||
{
|
{
|
||||||
archive << tag("qset");
|
archive << tag("qset");
|
||||||
if (parameters.hasFlag(ENFORCE_REFERENCED_ITEMS)) {
|
if (parameters.hasFlag(ENFORCE_REFERENCED_ITEMS)) {
|
||||||
foreach (const T *t, set)
|
for (const T *t : set)
|
||||||
archive << ref("item", t);
|
archive << ref("item", t);
|
||||||
} else {
|
} else {
|
||||||
foreach (const T *t, set)
|
for (const T *t : set)
|
||||||
archive << attr("item", t);
|
archive << attr("item", t);
|
||||||
}
|
}
|
||||||
archive << end;
|
archive << end;
|
||||||
|
Reference in New Issue
Block a user