Commit 74386b9c authored by Alex Diev's avatar Alex Diev
Browse files

Merge branch 'dengof_#168' into 'master'

Relayout interfaces on connection creation

See merge request esa/taste3!215
parents 61285c88 f1f304f1
Pipeline #1572 failed with stage
......@@ -251,6 +251,9 @@ private:
QList<QGraphicsItem *> sceneItems(const QGraphicsScene *scene, Qt::SortOrder order)
{
if (!scene)
return {};
IfaceItemFlagsWorkaround iwa(scene);
return scene->items(order);
}
......@@ -258,6 +261,9 @@ QList<QGraphicsItem *> sceneItems(const QGraphicsScene *scene, Qt::SortOrder ord
QList<QGraphicsItem *> sceneItems(const QGraphicsScene *scene, const QPointF &pos, Qt::ItemSelectionMode mode,
Qt::SortOrder order, const QTransform &deviceTransform)
{
if (!scene)
return {};
IfaceItemFlagsWorkaround iwa(scene);
return scene->items(pos, mode, order, deviceTransform);
}
......@@ -265,6 +271,9 @@ QList<QGraphicsItem *> sceneItems(const QGraphicsScene *scene, const QPointF &po
QList<QGraphicsItem *> sceneItems(const QGraphicsScene *scene, const QRectF &rect, Qt::ItemSelectionMode mode,
Qt::SortOrder order, const QTransform &deviceTransform)
{
if (!scene)
return {};
IfaceItemFlagsWorkaround iwa(scene);
return scene->items(rect, mode, order, deviceTransform);
}
......@@ -272,6 +281,9 @@ QList<QGraphicsItem *> sceneItems(const QGraphicsScene *scene, const QRectF &rec
QList<QGraphicsItem *> sceneItems(const QGraphicsScene *scene, const QPolygonF &polygon, Qt::ItemSelectionMode mode,
Qt::SortOrder order, const QTransform &deviceTransform)
{
if (!scene)
return {};
IfaceItemFlagsWorkaround iwa(scene);
return scene->items(polygon, mode, order, deviceTransform);
}
......@@ -279,6 +291,9 @@ QList<QGraphicsItem *> sceneItems(const QGraphicsScene *scene, const QPolygonF &
QList<QGraphicsItem *> sceneItems(const QGraphicsScene *scene, const QPainterPath &path, Qt::ItemSelectionMode mode,
Qt::SortOrder order, const QTransform &deviceTransform)
{
if (!scene)
return {};
IfaceItemFlagsWorkaround iwa(scene);
return scene->items(path, mode, order, deviceTransform);
}
......@@ -286,25 +301,33 @@ QList<QGraphicsItem *> sceneItems(const QGraphicsScene *scene, const QPainterPat
QList<QGraphicsItem *> sceneItems(const QGraphicsScene *scene, qreal x, qreal y, qreal w, qreal h,
Qt::ItemSelectionMode mode, Qt::SortOrder order, const QTransform &deviceTransform)
{
if (!scene)
return {};
IfaceItemFlagsWorkaround iwa(scene);
return scene->items(x, y, w, h, mode, order, deviceTransform);
}
QGraphicsItem *sceneItemAt(const QGraphicsScene *scene, const QPointF &pos, const QTransform &deviceTransform)
{
if (!scene)
return {};
IfaceItemFlagsWorkaround iwa(scene);
return scene->itemAt(pos, deviceTransform);
}
QGraphicsItem *sceneItemAt(const QGraphicsScene *scene, qreal x, qreal y, const QTransform &deviceTransform)
{
if (!scene)
return {};
IfaceItemFlagsWorkaround iwa(scene);
return scene->itemAt(x, y, deviceTransform);
}
QGraphicsItem *nearestItem(const QGraphicsScene *scene, const QPointF &pos, const QList<int> &acceptableTypes)
{
for (QGraphicsItem *item : sceneItems(scene, pos)) {
if (acceptableTypes.contains(item->type()))
return item;
......
......@@ -441,12 +441,12 @@ AADLInterfaceGraphicsItem *AADLConnectionGraphicsItem::startItem() const
AADLFunctionGraphicsItem *AADLConnectionGraphicsItem::sourceItem() const
{
return qgraphicsitem_cast<AADLFunctionGraphicsItem *>(m_startItem ? m_startItem->targetItem() : nullptr);
return m_startItem ? m_startItem->targetItem() : nullptr;
}
AADLFunctionGraphicsItem *AADLConnectionGraphicsItem::targetItem() const
{
return qgraphicsitem_cast<AADLFunctionGraphicsItem *>(m_endItem ? m_endItem->targetItem() : nullptr);
return m_endItem ? m_endItem->targetItem() : nullptr;
}
QList<QVariantList> AADLConnectionGraphicsItem::prepareChangeCoordinatesCommandParams() const
......@@ -698,5 +698,21 @@ void AADLConnectionGraphicsItem::updateRelatedEdgePoint(const AADLFunctionGraphi
setPoints(points);
}
QVariant AADLConnectionGraphicsItem::itemChange(QGraphicsItem::GraphicsItemChange change, const QVariant &value)
{
switch (change) {
case QGraphicsItem::ItemSceneHasChanged: {
if (auto scene = value.value<QGraphicsScene *>())
for (auto fn : { sourceItem(), targetItem() })
if (fn)
fn->instantLayoutUpdate();
break;
}
default:
break;
}
return InteractiveObject::itemChange(change, value);
}
} // namespace aadl
} // namespace taste3
......@@ -83,6 +83,7 @@ protected:
void onManualMoveFinish(GripPoint *gp, const QPointF &pressedAt, const QPointF &releasedAt) override;
virtual ColorManager::HandledColors handledColorType() const override;
QVariant itemChange(QGraphicsItem::GraphicsItemChange change, const QVariant &value) override;
protected Q_SLOTS:
virtual void colorSchemeUpdated() override;
......
......@@ -118,6 +118,8 @@ void AADLFunctionGraphicsItem::rebuildLayout()
AADLFunctionTypeGraphicsItem::rebuildLayout();
colorSchemeUpdated();
QMetaObject::invokeMethod(this, "syncConnectionEndpoints", Qt::QueuedConnection);
}
void AADLFunctionGraphicsItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
......@@ -403,5 +405,15 @@ QString AADLFunctionGraphicsItem::prepareTooltip() const
return joinNonEmpty({ title, prototype, ris, pis }, QStringLiteral("<br>"));
}
void AADLFunctionGraphicsItem::syncConnectionEndpoints()
{
// TODO: update only connections affected by iface relayouting
for (auto item : childItems())
if (item->type() == AADLInterfaceGraphicsItem::Type)
if (auto iface = qgraphicsitem_cast<AADLInterfaceGraphicsItem *>(item))
for (AADLConnectionGraphicsItem *connection : iface->connectionItems())
connection->updateRelatedEdgePoint(this);
}
} // namespace aadl
} // namespace taste3
......@@ -62,6 +62,8 @@ protected:
void doAutoLayout();
Q_INVOKABLE void syncConnectionEndpoints();
protected Q_SLOTS:
void updateNestedItems();
void colorSchemeUpdated() override;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment