move subtree with shift

master
Denes Matetelki 14 years ago
parent 1e56b29ae2
commit fe8983fce9

@ -281,6 +281,19 @@ void GraphWidget::keyPressEvent(QKeyEvent *event)
else if (event->key() == Qt::Key_Right) m_activeNode->moveBy(20, 0);
contentChanged();
}
else if (event->modifiers() & Qt::ControlModifier &&
event->modifiers() & Qt::ShiftModifier)
{
QList <Node *> nodeList = m_activeNode->subtree();
foreach(Node *node, nodeList)
{
if (event->key() == Qt::Key_Up) node->moveBy(0, -20);
else if (event->key() == Qt::Key_Down) node->moveBy(0, 20);
else if (event->key() == Qt::Key_Left) node->moveBy(-20, 0);
else if (event->key() == Qt::Key_Right) node->moveBy(20, 0);
contentChanged();
}
}
else // move scene
{
QGraphicsView::keyPressEvent(event);

@ -308,6 +308,38 @@ Edge * Node::edgeTo(const Node *node) const
return 0;
}
QList<Node *> Node::subtree() const
{
/** @note QList crashes if modified while traversal,
* QMutableListIterator lacks push_back
*/
std::list<Node *> list;
list.push_back(const_cast<Node *>(this));
// inorder
for(std::list<Node *>::const_iterator it = list.begin();
it != list.end();
it++)
{
QList<Edge *> edges = (*it)->edgesFrom();
if (!edges.empty())
{
foreach(Edge *edge, edges)
{
if (!edge->secondary())
{
list.push_back( edge->destNode() != this ?
edge->destNode():
edge->sourceNode());
}
}
}
}
return QList<Node *>::fromStdList(list);
}
void Node::paint(QPainter *painter,
const QStyleOptionGraphicsItem *option,
QWidget *w)

@ -42,6 +42,7 @@ public:
QList<Edge *> edgesFrom(const bool &excludeSecondaries = true) const;
QList<Edge *> edgesToThis(const bool &excludeSecondaries = true) const;
Edge * edgeTo(const Node* node) const;
QList<Node *> subtree() const;
protected:

Loading…
Cancel
Save