- int res = QMessageBox::question(0, tr("Merge buffers permanently?"),
- tr("Do you want to merge the buffer \"%1\" permanently into buffer \"%2\"?\n This cannot be reversed!").arg(Client::networkModel()->bufferName(bufferId2)).arg(Client::networkModel()->bufferName(bufferId1)),
- QMessageBox::Yes|QMessageBox::No, QMessageBox::No);
+ // If the source and target are the same buffer, this was an aborted rearrangement
+ if (bufferId1 == bufferId2)
+ return TreeViewTouch::dropEvent(event);
+
+ // Get index of buffer that was being dragged
+ QModelIndex index2 = Client::networkModel()->bufferIndex(bufferId2);
+
+ // If the buffer being dragged is a channel and we're still joined to it, treat this as a rearrangement
+ // This prevents us from being joined to a channel with no associated UI elements
+ if (index2.data(NetworkModel::BufferTypeRole) == BufferInfo::ChannelBuffer && index2.data(NetworkModel::ItemActiveRole) == true)
+ return TreeViewTouch::dropEvent(event);
+
+ // If the source buffer is not mergeable(AKA not a Channel and not a Query), try rearranging instead
+ if (index2.data(NetworkModel::BufferTypeRole) != BufferInfo::ChannelBuffer
+ && index2.data(NetworkModel::BufferTypeRole) != BufferInfo::QueryBuffer)
+ return TreeViewTouch::dropEvent(event);
+
+ // If the target buffer is not mergeable(AKA not a Channel and not a Query), try rearranging instead
+ if (index.data(NetworkModel::BufferTypeRole) != BufferInfo::ChannelBuffer
+ && index.data(NetworkModel::BufferTypeRole) != BufferInfo::QueryBuffer)
+ return TreeViewTouch::dropEvent(event);
+
+ // Confirm that the user really wants to merge the buffers before doing so
+ int res = QMessageBox::question(nullptr,
+ tr("Merge buffers permanently?"),
+ tr("Do you want to merge the buffer \"%1\" permanently into buffer \"%2\"?\n This cannot be reversed!")
+ .arg(Client::networkModel()->bufferName(bufferId2))
+ .arg(Client::networkModel()->bufferName(bufferId1)),
+ QMessageBox::Yes | QMessageBox::No,
+ QMessageBox::No);