| 187 | |
| 188 | |
| 189 | void |
| 190 | NodeGraphicsObject:: |
| 191 | mousePressEvent(QGraphicsSceneMouseEvent * event) |
| 192 | { |
| 193 | if(_locked) return; |
| 194 | |
| 195 | // deselect all other items after this one is selected |
| 196 | if (!isSelected() && event->modifiers() != Qt::ControlModifier) |
| 197 | { |
| 198 | _scene.clearSelection(); |
| 199 | } |
| 200 | |
| 201 | for(PortType portToCheck: {PortType::In, PortType::Out}) |
| 202 | { |
| 203 | NodeGeometry & nodeGeometry = _node.nodeGeometry(); |
| 204 | |
| 205 | // TODO do not pass sceneTransform |
| 206 | int portIndex = nodeGeometry.checkHitScenePoint(portToCheck, |
| 207 | event->scenePos(), |
| 208 | sceneTransform()); |
| 209 | |
| 210 | if (portIndex != INVALID) |
| 211 | { |
| 212 | NodeState const & nodeState = _node.nodeState(); |
| 213 | |
| 214 | std::unordered_map<QUuid, Connection*> connections = |
| 215 | nodeState.connections(portToCheck, portIndex); |
| 216 | |
| 217 | // start dragging existing connection |
| 218 | if (!connections.empty() && portToCheck == PortType::In) |
| 219 | { |
| 220 | auto con = connections.begin()->second; |
| 221 | |
| 222 | NodeConnectionInteraction interaction(_node, *con, _scene); |
| 223 | |
| 224 | interaction.disconnect(portToCheck); |
| 225 | } |
| 226 | else // initialize new Connection |
| 227 | { |
| 228 | if (portToCheck == PortType::Out) |
| 229 | { |
| 230 | const auto outPolicy = _node.nodeDataModel()->portOutConnectionPolicy(portIndex); |
| 231 | if (!connections.empty() && |
| 232 | outPolicy == NodeDataModel::ConnectionPolicy::One) |
| 233 | { |
| 234 | _scene.deleteConnection( *connections.begin()->second ); |
| 235 | } |
| 236 | |
| 237 | // todo add to FlowScene |
| 238 | auto connection = _scene.createConnection(portToCheck, |
| 239 | _node, |
| 240 | portIndex); |
| 241 | |
| 242 | _node.nodeState().setConnection(portToCheck, |
| 243 | portIndex, |
| 244 | *connection); |
| 245 | |
| 246 | connection->connectionGraphicsObject().grabMouse(); |
nothing calls this directly
no test coverage detected