| 840 | } |
| 841 | |
| 842 | QMimeData* CurveTreeView::createDragMimeData(Qt::MouseButton button) const { |
| 843 | const std::vector<QString> names = selectedCurveNamesForDrag(); |
| 844 | |
| 845 | // The catalog payload must carry EVERY selected item, not just the row under |
| 846 | // the cursor when the drag began. Object/image topics come from the recursive |
| 847 | // catalog walk; scalar curves (whose catalog key is their own name) are added |
| 848 | // from `names`, which also folds in a cross-view selection supplied by a drag |
| 849 | // selection provider. |
| 850 | QStringList catalog_keys; |
| 851 | for (const QString& key : selectedCatalogKeysRecursive()) { |
| 852 | catalog_keys.push_back(key); |
| 853 | } |
| 854 | for (const QString& name : names) { |
| 855 | catalog_keys.push_back(name); |
| 856 | } |
| 857 | catalog_keys.removeDuplicates(); |
| 858 | |
| 859 | // Left-button drag → add curve(s) to a plot; right-button drag of exactly two |
| 860 | // curves → XY scatter plot. Anything else is not a drag we initiate. |
| 861 | const bool left_add = button == Qt::LeftButton; |
| 862 | const bool right_xy = button == Qt::RightButton && names.size() == 2; |
| 863 | if ((!left_add && !right_xy) || (names.empty() && catalog_keys.empty())) { |
| 864 | return nullptr; |
| 865 | } |
| 866 | |
| 867 | QByteArray encoded; |
| 868 | QDataStream stream(&encoded, QIODevice::WriteOnly); |
| 869 | for (const QString& name : names) { |
| 870 | stream << name; |
| 871 | } |
| 872 | |
| 873 | auto* mime_data = new QMimeData(); |
| 874 | // Plot-widget and placeholder drop sites match on these mime keys exactly. |
| 875 | if (!catalog_keys.empty()) { |
| 876 | mime_data->setData(catalogItemsMimeType(), encodeCatalogKeys(catalog_keys)); |
| 877 | } |
| 878 | if (left_add && !names.empty()) { |
| 879 | mime_data->setData(QStringLiteral("curveslist/add_curve"), encoded); |
| 880 | } else if (right_xy) { |
| 881 | mime_data->setData(newXyAxisMimeType(), encoded); |
| 882 | } |
| 883 | return mime_data; |
| 884 | } |
| 885 | |
| 886 | void CurveTreeView::mouseReleaseEvent(QMouseEvent* event) { |
| 887 | if (suppress_next_release_) { |