Skip to content

Commit

Permalink
#1742 Clean resizer maxZ management.
Browse files Browse the repository at this point in the history
Remove very low quality code in Graph::updateMinMaxZ()
Remove Graph::maxChildsZ(), Graph::maxChildsZ()

Signed-off-by: cneben <[email protected]>
  • Loading branch information
cneben committed Aug 31, 2024
1 parent c9eb619 commit 9feb3ef
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 66 deletions.
18 changes: 8 additions & 10 deletions src/GraphView.qml
Original file line number Diff line number Diff line change
Expand Up @@ -342,11 +342,12 @@ Qan.AbstractGraphView {
Qt.binding(() => { return nodeResizer.target ? nodeResizer.target.visible && nodeResizer.target.resizable :
false; })

nodeResizer.z = graph.maxZ + 15 // We want resizer to stay on top of selection item and ports.
console.error(`graph.maxZ=${graph.maxZ} node.item.z=${node.item.z} nodeResizer.z=${nodeResizer.z}`)
console.error(`node.item.parent=${node.item.parent}`)
console.error(`node.item.parent.z=${node.item.parent.z}`)
nodeRightResizer.z = nodeBottomResizer.z = graph.maxZ + 15
nodeResizer.z = 200005 // Resizer must stay on top of selection item and ports, 200k is QuickQanava max maxZ
// FIXME #1742
// console.error(`graph.maxZ=${graph.maxZ} node.item.z=${node.item.z} nodeResizer.z=${nodeResizer.z}`)
// console.error(`node.item.parent=${node.item.parent}`)
// console.error(`node.item.parent.z=${node.item.parent.z}`)
nodeRightResizer.z = nodeBottomResizer.z = 200005

nodeResizer.preserveRatio = (node.item.ratio > 0.)
if (node.item.ratio > 0.) {
Expand Down Expand Up @@ -390,12 +391,9 @@ Qan.AbstractGraphView {
group.item.resizable; // And if group is resizeable
})

groupResizer.z = graph.maxZ + 12 // We want resizer to stay on top of selection item and ports.
/*console.error(`graph.maxZ=${graph.maxZ} group.item.z=${group.item.z} groupResizer.z=${groupResizer.z}`)
console.error(`group.item.container=${group.item.container}`)
console.error(`group.item.parent.z=${group.item.parent.z}`)*/
groupResizer.z = 200005 // Resizer must stay on top of selection item and ports, 200k is QuickQanava max maxZ
groupResizer.preserveRatio = false
groupRightResizer.z = groupBottomResizer.z = graph.maxZ + 12
groupRightResizer.z = groupBottomResizer.z = 200005
groupRightResizer.preserveRatio = groupBottomResizer.preserveRatio = false
} else {
groupResizer.target = groupResizer.targetContent = null
Expand Down
73 changes: 29 additions & 44 deletions src/qanGraph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1838,13 +1838,7 @@ void Graph::sendToFront(QQuickItem* item)
const auto groupParentItem = groupItem->parentItem();
if (groupParentItem == nullptr)
continue; // Should not happen, a group necessary have a parent item.
if (groupParentItem == graphContainerItem) { // 2.2.1 We have root group, use global graph maxZ property
groupItem->setZ(nextMaxZ());
} else {
const auto maxZ = maxChildsZ(groupParentItem); // 2.2.2
updateMaxZ(maxZ + 1.);
groupItem->setZ(maxZ + 1.);
}
groupItem->setZ(nextMaxZ());
} // For all group items
}
}
Expand All @@ -1864,16 +1858,38 @@ void Graph::sendToBack(QQuickItem* item)

void Graph::updateMinMaxZ() noexcept
{
const auto maxZ = maxChildsZ(getContainerItem());
setMaxZ(maxZ);
const auto minZ = minChildsZ(getContainerItem());
setMaxZ(minZ);
{
auto maxZIt = std::max_element(get_nodes().cbegin(), get_nodes().cend(),
[](const auto a, const auto b) {
return a->getItem() != nullptr &&
b->getItem() != nullptr &&
a->getItem()->z() < b->getItem()->z();
});

const auto maxZ = maxZIt != get_nodes().end() &&
(*maxZIt)->getItem() != nullptr ? (*maxZIt)->getItem()->z() : 0.;
setMaxZ(maxZ);
}

{
auto minZIt = std::min_element(get_nodes().cbegin(), get_nodes().cend(),
[](const auto a, const auto b) {
return a->getItem() != nullptr &&
b->getItem() != nullptr &&
a->getItem()->z() < b->getItem()->z();
});

const auto minZ = minZIt != get_nodes().end() &&
(*minZIt)->getItem() != nullptr ? (*minZIt)->getItem()->z() : 0.;

setMinZ(minZ);
}
}

qreal Graph::getMaxZ() const noexcept { return _maxZ; }
void Graph::setMaxZ(const qreal maxZ) noexcept
{
_maxZ = maxZ;
_maxZ = std::min(200000., maxZ);
emit maxZChanged();
}

Expand All @@ -1890,26 +1906,10 @@ void Graph::updateMaxZ(const qreal z) noexcept
setMaxZ(z);
}

auto Graph::maxChildsZ(const QQuickItem* item) noexcept -> qreal {
if (item == nullptr)
return 0.;
qreal maxZ = std::numeric_limits<qreal>::lowest();
bool hasChild = false;
const auto childs = item->childItems();
for (const auto childItem : qAsConst(childs)) {
if (childItem != nullptr) {
hasChild = true;
maxZ = std::max(maxZ, childItem->z());
}
}
return hasChild ? maxZ : 0.;
};


qreal Graph::getMinZ() const noexcept { return _minZ; }
void Graph::setMinZ(const qreal minZ) noexcept
{
_minZ = minZ;
_minZ = std::max(-200000., minZ);
emit minZChanged();
}

Expand All @@ -1925,21 +1925,6 @@ void Graph::updateMinZ(const qreal z) noexcept
if (z < _minZ)
setMinZ(z);
}

auto Graph::minChildsZ(const QQuickItem* item) noexcept -> qreal {
if (item == nullptr)
return 0.;
qreal minZ = std::numeric_limits<qreal>::infinity();
bool hasChild = false;
const auto childs = item->childItems();
for (const auto childItem : qAsConst(childs)) {
if (childItem != nullptr) {
hasChild = true;
minZ = std::min(minZ, childItem->z());
}
}
return hasChild ? minZ : 0.;
};
//-----------------------------------------------------------------------------


Expand Down
12 changes: 0 additions & 12 deletions src/qanGraph.h
Original file line number Diff line number Diff line change
Expand Up @@ -1047,12 +1047,6 @@ class Graph : public gtpo::graph<QQuickItem, qan::Node, qan::Group, qan::Edge>
//! Update maximum z value if \c z is greater than actual \c maxZ value.
Q_INVOKABLE void updateMaxZ(const qreal z) noexcept;

protected:
/*! \brief Utility to find a QQuickItem maximum z value of \c item childs.
* \return 0. if there is no child, maximum child z value otherwise.
*/
static auto maxChildsZ(const QQuickItem* item) noexcept -> qreal;

public:
//! \brief Minimum global z for nodes and groups (ie bottom-less item).
Q_PROPERTY(qreal minZ READ getMinZ WRITE setMinZ NOTIFY minZChanged FINAL)
Expand All @@ -1068,12 +1062,6 @@ class Graph : public gtpo::graph<QQuickItem, qan::Node, qan::Group, qan::Edge>
qreal nextMinZ() noexcept;
//! Update minimum z value if \c z is less than actual \c minZ value.
Q_INVOKABLE void updateMinZ(const qreal z) noexcept;

protected:
/*! \brief Utility to find a QQuickItem minimum z value of \c item childs.
* \return 0. if there is no child, minimum child z value otherwise.
*/
static auto minChildsZ(const QQuickItem* item) noexcept -> qreal;
//@}
//-------------------------------------------------------------------------

Expand Down

0 comments on commit 9feb3ef

Please sign in to comment.