forked from paceholder/nodeeditor
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlocateNode.cpp
More file actions
42 lines (30 loc) · 1.2 KB
/
locateNode.cpp
File metadata and controls
42 lines (30 loc) · 1.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#include "locateNode.hpp"
#include "NodeGraphicsObject.hpp"
#include <QtCore/QList>
#include <QtWidgets/QGraphicsScene>
namespace QtNodes {
NodeGraphicsObject *locateNodeAt(QPointF scenePoint,
QGraphicsScene &scene,
QTransform const &viewTransform)
{
// items under cursor
QList<QGraphicsItem *> items = scene.items(scenePoint,
Qt::IntersectsItemShape,
Qt::DescendingOrder,
viewTransform);
// items convertable to NodeGraphicsObject
std::vector<QGraphicsItem *> filteredItems;
std::copy_if(items.begin(),
items.end(),
std::back_inserter(filteredItems),
[](QGraphicsItem *item) {
return (qgraphicsitem_cast<NodeGraphicsObject *>(item) != nullptr);
});
NodeGraphicsObject *node = nullptr;
if (!filteredItems.empty()) {
QGraphicsItem *graphicsItem = filteredItems.front();
node = dynamic_cast<NodeGraphicsObject *>(graphicsItem);
}
return node;
}
} // namespace QtNodes