Edit rules
This commit is contained in:
parent
fb176a40b0
commit
7d4804a7f8
4 changed files with 74 additions and 5 deletions
|
|
@ -466,7 +466,8 @@ void WarpGraphModel::refreshFromClient() {
|
|||
if (savedIt != m_savedPositions.end()) {
|
||||
m_positions.emplace(qtId, savedIt->second);
|
||||
} else {
|
||||
m_positions.emplace(qtId, nextPosition(nodeIt->second));
|
||||
QPointF candidate = nextPosition(nodeIt->second);
|
||||
m_positions.emplace(qtId, findNonOverlappingPosition(candidate, nodeIt->second));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -698,6 +699,40 @@ QPointF WarpGraphModel::nextPosition(const WarpNodeData &data) {
|
|||
return pos;
|
||||
}
|
||||
|
||||
QPointF WarpGraphModel::findNonOverlappingPosition(QPointF candidate,
|
||||
const WarpNodeData &data) const {
|
||||
QSizeF newSize(estimateNodeSize(data));
|
||||
constexpr int kMaxAttempts = 50;
|
||||
|
||||
for (int attempt = 0; attempt < kMaxAttempts; ++attempt) {
|
||||
QRectF newRect(candidate, newSize);
|
||||
bool overlaps = false;
|
||||
for (const auto &[existingId, existingPos] : m_positions) {
|
||||
auto nodeIt = m_nodes.find(existingId);
|
||||
if (nodeIt == m_nodes.end())
|
||||
continue;
|
||||
QSizeF existingSize;
|
||||
auto sizeIt = m_sizes.find(existingId);
|
||||
if (sizeIt != m_sizes.end()) {
|
||||
existingSize = QSizeF(sizeIt->second);
|
||||
} else {
|
||||
existingSize = QSizeF(estimateNodeSize(nodeIt->second));
|
||||
}
|
||||
QRectF existingRect(existingPos, existingSize);
|
||||
QRectF padded = existingRect.adjusted(-kHorizontalGap / 2, -kVerticalGap / 2,
|
||||
kHorizontalGap / 2, kVerticalGap / 2);
|
||||
if (newRect.intersects(padded)) {
|
||||
candidate.setY(existingRect.bottom() + kVerticalGap);
|
||||
overlaps = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!overlaps)
|
||||
break;
|
||||
}
|
||||
return candidate;
|
||||
}
|
||||
|
||||
bool WarpGraphModel::isGhost(QtNodes::NodeId nodeId) const {
|
||||
return m_ghostNodes.find(nodeId) != m_ghostNodes.end();
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue