refactoring, moving out GraphWidget::modifyRoute

master
dmatetelki 10 years ago
parent 91972ea943
commit 2728f36c25

@ -192,34 +192,40 @@ void GraphWidget::keyPressEvent(QKeyEvent *e)
break; break;
} }
case Qt::Key_Space: { case Qt::Key_Space: {
for (QList<Edge*>::iterator it = m_route.begin(); it != m_route.end(); ++it) modifyRoute();
(*it)->setIsRoute(false); }
default:
QGraphicsView::keyPressEvent(e);
}
}
QList <QGraphicsItem* > selectedItems = scene()->selectedItems(); void GraphWidget::modifyRoute()
if (selectedItems.isEmpty()) {
break; for (QList<Edge*>::iterator it = m_route.begin(); it != m_route.end(); ++it)
(*it)->setIsRoute(false);
QGraphicsItem* selectedItem = selectedItems.first(); QList <QGraphicsItem* > selectedItems = scene()->selectedItems();
Node* selectedNode = dynamic_cast<Node*>(selectedItem); if (selectedItems.isEmpty())
break;
const QPoint global_p = QCursor::pos(); QGraphicsItem* selectedItem = selectedItems.first();
const QPoint widget_p = mapFromGlobal(global_p); Node* selectedNode = dynamic_cast<Node*>(selectedItem);
const QPointF scene_p = mapToScene(widget_p);
QGraphicsItem* item_under_mouse = scene()->itemAt(scene_p); const QPoint global_p = QCursor::pos();
Node* nodeUnderMouse = dynamic_cast<Node*>(item_under_mouse); const QPoint widget_p = mapFromGlobal(global_p);
const QPointF scene_p = mapToScene(widget_p);
if (nodeUnderMouse != 0 && nodeUnderMouse != selectedNode) { QGraphicsItem* item_under_mouse = scene()->itemAt(scene_p);
m_route = calculateShortestRoute(scene(), m_graph, selectedNode, nodeUnderMouse); Node* nodeUnderMouse = dynamic_cast<Node*>(item_under_mouse);
for (QList<Edge*>::iterator it = m_route.begin(); it != m_route.end(); ++it)
(*it)->setIsRoute(true); if (nodeUnderMouse != 0 && nodeUnderMouse != selectedNode) {
} m_route = calculateShortestRoute(scene(), m_graph, selectedNode, nodeUnderMouse);
} for (QList<Edge*>::iterator it = m_route.begin(); it != m_route.end(); ++it)
default: (*it)->setIsRoute(true);
QGraphicsView::keyPressEvent(e); }
}
} }
void GraphWidget::removeEdge(Node* selectedNode, Node* nodeUnderMouse) void GraphWidget::removeEdge(Node* selectedNode, Node* nodeUnderMouse)
{ {
const float2 source_pos = float2FromQPointF(selectedNode->pos()); const float2 source_pos = float2FromQPointF(selectedNode->pos());

@ -38,6 +38,7 @@ private:
void removeNode(Node* selectedNode); void removeNode(Node* selectedNode);
void insertEdge(Node* selectedNode, Node* nodeUnderMouse); void insertEdge(Node* selectedNode, Node* nodeUnderMouse);
void removeEdge(Node* selectedNode, Node* nodeUnderMouse); void removeEdge(Node* selectedNode, Node* nodeUnderMouse);
void modifyRoute();
Graph<float2>* m_graph; Graph<float2>* m_graph;
QPixmap* m_background; QPixmap* m_background;

Loading…
Cancel
Save