| 229 | } |
| 230 | |
| 231 | bool ModListByPriorityProxy::canDropMimeData(const QMimeData* data, |
| 232 | Qt::DropAction action, int row, int column, |
| 233 | const QModelIndex& parent) const |
| 234 | { |
| 235 | ModListDropInfo dropInfo(data, m_core); |
| 236 | |
| 237 | if (!dropInfo.isValid() || dropInfo.isLocalFileDrop()) { |
| 238 | return QAbstractProxyModel::canDropMimeData(data, action, row, column, parent); |
| 239 | } |
| 240 | |
| 241 | if (dropInfo.isModDrop()) { |
| 242 | bool hasSeparator = false; |
| 243 | unsigned int firstRowIndex = -1; |
| 244 | |
| 245 | int firstRowPriority = Profile::MaximumPriority; |
| 246 | for (auto sourceRow : dropInfo.rows()) { |
| 247 | hasSeparator = hasSeparator || ModInfo::getByIndex(sourceRow)->isSeparator(); |
| 248 | if (m_sortOrder == Qt::AscendingOrder && |
| 249 | m_profile->getModPriority(sourceRow) < firstRowPriority || |
| 250 | m_sortOrder == Qt::DescendingOrder && |
| 251 | m_profile->getModPriority(sourceRow) > firstRowPriority) { |
| 252 | firstRowIndex = sourceRow; |
| 253 | firstRowPriority = m_profile->getModPriority(sourceRow); |
| 254 | } |
| 255 | } |
| 256 | |
| 257 | bool firstRowSeparator = |
| 258 | firstRowIndex != -1 && ModInfo::getByIndex(firstRowIndex)->isSeparator(); |
| 259 | |
| 260 | // row = -1 and valid parent means we're dropping onto an item, we don't want to |
| 261 | // drop separators onto items or items into their own separator |
| 262 | if (row == -1 && parent.isValid()) { |
| 263 | auto* parentItem = static_cast<TreeItem*>(parent.internalPointer()); |
| 264 | if (hasSeparator) { |
| 265 | return !parentItem->mod->isSeparator(); |
| 266 | } |
| 267 | |
| 268 | for (auto row : dropInfo.rows()) { |
| 269 | auto it = m_IndexToItem.find(row); |
| 270 | if (it != m_IndexToItem.end() && it->second->parent == parentItem) { |
| 271 | return false; |
| 272 | } |
| 273 | } |
| 274 | } |
| 275 | |
| 276 | // first row is a separator, we can drop it anywhere |
| 277 | if (firstRowSeparator) { |
| 278 | return QAbstractProxyModel::canDropMimeData(data, action, row, column, parent); |
| 279 | } |
| 280 | } |
| 281 | |
| 282 | // the row may be outside of the children list if we insert at the end |
| 283 | if (!parent.isValid() && row >= m_Root.children.size()) { |
| 284 | return false; |
| 285 | } |
| 286 | |
| 287 | return QAbstractProxyModel::canDropMimeData(data, action, row, column, parent); |
| 288 | } |
nothing calls this directly
no test coverage detected