From 991b201a6f695d25747b5893d52a5656eff15974 Mon Sep 17 00:00:00 2001 From: mikfire Date: Fri, 30 Dec 2022 15:02:37 -0500 Subject: [PATCH] Drag and drop works The login in BtTreeView::mimeData was broken. As we always set itsa, the std::optional variable would have never been false. This resulted in setting the mime type to `application/x-brewtarget-folder` for anything that wasn't a Recipe, Style or Folder. Since the tables are configured to only accept `application/x-brewtarget-ingredient`, they wouldn't accept the drop. To fix it, I changed all the tests around. We test for Recipe, Style and Equipment; then we test for Folder; then we test to not be Water. That sets all of the mime types correct. I also added an `application/x-brewtarget-water` in case I ever want to get clever. --- src/BtTreeView.cpp | 16 +++++++++++----- ui/mainWindow.ui | 20 +++++++++----------- 2 files changed, 20 insertions(+), 16 deletions(-) diff --git a/src/BtTreeView.cpp b/src/BtTreeView.cpp index 2323db9c4..97f7b6791 100644 --- a/src/BtTreeView.cpp +++ b/src/BtTreeView.cpp @@ -266,16 +266,22 @@ QMimeData * BtTreeView::mimeData(QModelIndexList indexes) { stream << static_cast(*itemType) << id << name; } - if (!itsa) { - // Everything other than folders get dropped on the ingredients pane - name = "application/x-brewtarget-ingredient"; - } else if (*itsa == BtTreeItem::Type::RECIPE || *itsa == BtTreeItem::Type::STYLE || *itsa == BtTreeItem::Type::EQUIPMENT) { + if (*itsa == BtTreeItem::Type::RECIPE || *itsa == BtTreeItem::Type::STYLE || *itsa == BtTreeItem::Type::EQUIPMENT) { // Recipes, equipment and styles get dropped on the recipe pane name = "application/x-brewtarget-recipe"; - } else { + } + else if ( *itsa == BtTreeItem::Type::FOLDER ) { // folders will be handled by themselves. name = "application/x-brewtarget-folder"; } + else if ( *itsa != BtTreeItem::Type::WATER ) { + // Everything other than folders get dropped on the ingredients pane + name = "application/x-brewtarget-ingredient"; + } + else { + // This isn't used yet, but maybe some day I will fix that + name = "application/x-brewtarget-water"; + } QMimeData * mimeData = new QMimeData(); mimeData->setData(name, encodedData); diff --git a/ui/mainWindow.ui b/ui/mainWindow.ui index 77d5e0444..b5f628871 100644 --- a/ui/mainWindow.ui +++ b/ui/mainWindow.ui @@ -259,8 +259,8 @@ 0 0 - 849 - 462 + 853 + 437 @@ -1114,8 +1114,8 @@ 0 0 - 849 - 324 + 853 + 356 @@ -1155,6 +1155,9 @@ Qt::CustomContextMenu + + true + @@ -1667,7 +1670,7 @@ 0 0 1200 - 24 + 20 @@ -1880,7 +1883,7 @@ Ctrl+T - + :/images/printer.png:/images/printer.png @@ -2193,11 +2196,6 @@ (PreviousScaleInfo) - - BtGenericEdit - QLineEdit -
BtLineEdit.h
-
BtPercentageEdit QLineEdit