Skip to content

Commit 13274ae

Browse files
atrosinenkoadeas31
authored andcommitted
OMEdit: drawing-related optimizations
QGraphicsScene::items() sorts its items on each invocation, so avoid using it in cases such as scene()->items().contains(...). Drop unused mpResizerRectangle.
1 parent f6e91d0 commit 13274ae

File tree

4 files changed

+6
-26
lines changed

4 files changed

+6
-26
lines changed

OMEdit/OMEdit/OMEditGUI/Component/Component.cpp

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -452,14 +452,6 @@ Component::Component(QString name, LibraryTreeItem *pLibraryTreeItem, QString an
452452
mIsInheritedComponent = false;
453453
mComponentType = Component::Root;
454454
mTransformationString = StringHandler::getPlacementAnnotation(annotation);
455-
// Construct the temporary polygon that is used when scaling
456-
mpResizerRectangle = new QGraphicsRectItem;
457-
mpResizerRectangle->setZValue(-5000); // set to a very low value
458-
mpGraphicsView->addItem(mpResizerRectangle);
459-
QPen pen;
460-
pen.setStyle(Qt::DotLine);
461-
pen.setColor(Qt::transparent);
462-
mpResizerRectangle->setPen(pen);
463455
setOldScenePosition(QPointF(0, 0));
464456
setOldPosition(QPointF(0, 0));
465457
setComponentFlags(true);
@@ -534,7 +526,6 @@ Component::Component(LibraryTreeItem *pLibraryTreeItem, Component *pParentCompon
534526
mIsInheritedComponent = mpParentComponent->isInheritedComponent();
535527
mComponentType = Component::Extend;
536528
mTransformationString = "";
537-
mpResizerRectangle = 0;
538529
createNonExistingComponent();
539530
mpDefaultComponentRectangle = 0;
540531
mpDefaultComponentText = 0;
@@ -570,7 +561,6 @@ Component::Component(Component *pComponent, Component *pParentComponent, Compone
570561
mTransformationString = mpReferenceComponent->getTransformationString();
571562
mDialogAnnotation = mpReferenceComponent->getDialogAnnotation();
572563
mChoicesAnnotation = mpReferenceComponent->getChoicesAnnotation();
573-
mpResizerRectangle = 0;
574564
createNonExistingComponent();
575565
mpDefaultComponentRectangle = 0;
576566
mpDefaultComponentText = 0;
@@ -613,14 +603,6 @@ Component::Component(Component *pComponent, GraphicsView *pGraphicsView)
613603
mTransformationString = mpReferenceComponent->getTransformationString();
614604
mDialogAnnotation = mpReferenceComponent->getDialogAnnotation();
615605
mChoicesAnnotation = mpReferenceComponent->getChoicesAnnotation();
616-
//Construct the temporary polygon that is used when scaling
617-
mpResizerRectangle = new QGraphicsRectItem;
618-
mpResizerRectangle->setZValue(5000); // set to a very high value
619-
mpGraphicsView->addItem(mpResizerRectangle);
620-
QPen pen;
621-
pen.setStyle(Qt::DotLine);
622-
pen.setColor(Qt::transparent);
623-
mpResizerRectangle->setPen(pen);
624606
setOldScenePosition(QPointF(0, 0));
625607
setOldPosition(QPointF(0, 0));
626608
setComponentFlags(true);
@@ -669,7 +651,6 @@ Component::Component(ComponentInfo *pComponentInfo, Component *pParentComponent)
669651
mTransformationString = "";
670652
mDialogAnnotation.clear();
671653
mChoicesAnnotation.clear();
672-
mpResizerRectangle = 0;
673654
createNonExistingComponent();
674655
createDefaultComponent();
675656
mpStateComponentRectangle = 0;
@@ -2561,9 +2542,6 @@ void Component::prepareResizeComponent(ResizerItem *pResizerItem)
25612542
mTransformationStartPosition = topRight;
25622543
mPivotPoint = bottomLeft;
25632544
}
2564-
mpResizerRectangle->setRect(boundingRect()); //Sets the current item to the temporary rect
2565-
mpResizerRectangle->setTransform(transform()); //Set the same matrix of this item to the temporary item
2566-
mpResizerRectangle->setPos(pos());
25672545
}
25682546

25692547
/*!
@@ -2607,7 +2585,6 @@ void Component::resizeComponent(QPointF newPosition)
26072585
QTransform tmpTransform = QTransform().translate(pivot.x(), pivot.y()).rotate(0)
26082586
.scale(mXFactor, mYFactor)
26092587
.translate(-pivot.x(), -pivot.y());
2610-
mpResizerRectangle->setTransform(mTransform * tmpTransform); //Multiplies the previous transform * the temporary
26112588
setTransform(mTransform * tmpTransform);
26122589
// set the final resize on component.
26132590
QPointF extent1, extent2;

OMEdit/OMEdit/OMEditGUI/Component/Component.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,6 @@ class Component : public QObject, public QGraphicsItem
270270
QStringList mDialogAnnotation;
271271
QStringList mChoicesAnnotation;
272272
QString mParameterValue;
273-
QGraphicsRectItem *mpResizerRectangle;
274273
LineAnnotation *mpNonExistingComponentLine;
275274
RectangleAnnotation *mpDefaultComponentRectangle;
276275
TextAnnotation *mpDefaultComponentText;

OMEdit/OMEdit/OMEditGUI/Modeling/ModelWidgetContainer.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1492,7 +1492,8 @@ bool GraphicsView::hasAnnotation()
14921492
*/
14931493
void GraphicsView::addItem(QGraphicsItem *pGraphicsItem)
14941494
{
1495-
if (!scene()->items().contains(pGraphicsItem)) {
1495+
if (!mAllItems.contains(pGraphicsItem)) {
1496+
mAllItems.insert(pGraphicsItem);
14961497
scene()->addItem(pGraphicsItem);
14971498
}
14981499
}
@@ -1504,7 +1505,8 @@ void GraphicsView::addItem(QGraphicsItem *pGraphicsItem)
15041505
*/
15051506
void GraphicsView::removeItem(QGraphicsItem *pGraphicsItem)
15061507
{
1507-
if (scene()->items().contains(pGraphicsItem)) {
1508+
if (mAllItems.contains(pGraphicsItem)) {
1509+
mAllItems.remove(pGraphicsItem);
15081510
scene()->removeItem(pGraphicsItem);
15091511
}
15101512
}

OMEdit/OMEdit/OMEditGUI/Modeling/ModelWidgetContainer.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,8 @@ class GraphicsView : public QGraphicsView
138138
QAction *mpFlipVerticalAction;
139139
QAction *mpSetInitialStateAction;
140140
QAction *mpCancelTransitionAction;
141+
// scene->items().contains(...) involves sorting on each items() call, avoid it
142+
QSet<QGraphicsItem*> mAllItems;
141143
public:
142144
GraphicsView(StringHandler::ViewType viewType, ModelWidget *pModelWidget, bool visualizationView = false);
143145
CoOrdinateSystem mCoOrdinateSystem;

0 commit comments

Comments
 (0)