| 245 | } |
| 246 | |
| 247 | bool StructSelectModel::dropMimeData(const QMimeData* data, Qt::DropAction action, int row, |
| 248 | int column, const QModelIndex& parent) |
| 249 | { |
| 250 | (void)column; |
| 251 | |
| 252 | if (action != Qt::CopyAction && action != Qt::MoveAction) |
| 253 | return false; |
| 254 | |
| 255 | if (!data->hasFormat("application/x-structtreenode")) |
| 256 | return false; |
| 257 | |
| 258 | QByteArray bytes = data->data("application/x-structtreenode"); |
| 259 | QDataStream stream(&bytes, QIODevice::ReadOnly); |
| 260 | StructTreeNode* destParentNode = nullptr; |
| 261 | if (!parent.isValid()) |
| 262 | destParentNode = m_rootNode; |
| 263 | else |
| 264 | destParentNode = static_cast<StructTreeNode*>(parent.internalPointer()); |
| 265 | |
| 266 | qulonglong leastDeepNodePtr{}; |
| 267 | stream >> leastDeepNodePtr; |
| 268 | auto* const leastDeepNode{Common::bit_cast<StructTreeNode*, qulonglong>(leastDeepNodePtr)}; |
| 269 | |
| 270 | if (row == -1) |
| 271 | { |
| 272 | if (parent.isValid() && destParentNode->isGroup()) |
| 273 | row = rowCount(parent); |
| 274 | else if (!parent.isValid()) |
| 275 | return false; |
| 276 | } |
| 277 | |
| 278 | // beginMoveRows will cause a segfault if it ends up with doing nothing (so moving one row to the |
| 279 | // same place), but there's also a discrepancy of 1 in the row received / the row given to |
| 280 | // beginMoveRows and the actuall row of the node. This discrepancy has to be reversed before |
| 281 | // checking if we are trying to move the source (using the least deep one to accomodate |
| 282 | // multi-select) to the same place. |
| 283 | int trueRow = (leastDeepNode->getRow() < row) ? (row - 1) : (row); |
| 284 | if (destParentNode == leastDeepNode->getParent() && leastDeepNode->getRow() == trueRow) |
| 285 | return false; |
| 286 | |
| 287 | int count; |
| 288 | stream >> count; |
| 289 | |
| 290 | StructTreeNode* oldParent = leastDeepNode->getParent(); |
| 291 | |
| 292 | QStringList collisions{}; |
| 293 | |
| 294 | for (int i = 0; i < count; ++i) |
| 295 | { |
| 296 | qulonglong nodePtr{}; |
| 297 | stream >> nodePtr; |
| 298 | auto* const srcNode{Common::bit_cast<StructTreeNode*, qulonglong>(nodePtr)}; |
| 299 | |
| 300 | // Since beginMoveRows uses the same row format then the one received, we want to keep that, but |
| 301 | // still use the correct row number for inserting. |
| 302 | int destMoveRow = row; |
| 303 | if (srcNode->getRow() < row && destParentNode == srcNode->getParent()) |
| 304 | --row; |
nothing calls this directly
no test coverage detected