diff --git a/ApplicationCode/UserInterface/RiuDragDrop.cpp b/ApplicationCode/UserInterface/RiuDragDrop.cpp index e5fa3f7e45..170ad5270d 100644 --- a/ApplicationCode/UserInterface/RiuDragDrop.cpp +++ b/ApplicationCode/UserInterface/RiuDragDrop.cpp @@ -38,6 +38,8 @@ #include "RiuMainWindow.h" #include "cafPdmUiTreeView.h" +#include "cafSelectionManager.h" +#include "cafPdmUiItem.h" #include #include @@ -103,6 +105,7 @@ private: //-------------------------------------------------------------------------------------------------- RiuDragDrop::RiuDragDrop() { + m_proposedAction = Qt::MoveAction; } //-------------------------------------------------------------------------------------------------- @@ -117,18 +120,19 @@ RiuDragDrop::~RiuDragDrop() //-------------------------------------------------------------------------------------------------- Qt::DropActions RiuDragDrop::supportedDropActions() const { -// if (RiuTypedObjectsFromObjectGroupGetter::containsTypedObjects(m_dragItems)) -// { -// return Qt::CopyAction | Qt::MoveAction; -// } -// else if (RiuTypedObjectsFromObjectGroupGetter::containsTypedObjects(m_dragItems)) -// { -// return Qt::CopyAction; -// } -// -// return Qt::MoveAction; + // Keep drag items so that we can determine allowed actions while dragging + m_dragItems = objectHandlesFromSelection(); - return Qt::CopyAction | Qt::MoveAction; + if (RiuTypedPdmObjects::containsTypedObjects(m_dragItems)) + { + return Qt::CopyAction | Qt::MoveAction; + } + else if (RiuTypedPdmObjects::containsTypedObjects(m_dragItems)) + { + return Qt::CopyAction; + } + + return Qt::MoveAction; } //-------------------------------------------------------------------------------------------------- @@ -159,37 +163,49 @@ Qt::ItemFlags RiuDragDrop::flags(const QModelIndex &index) const itemflags |= Qt::ItemIsDropEnabled; } } - else if (dynamic_cast(uiItem)) + else if (m_proposedAction == Qt::MoveAction) { - if (RiuTypedPdmObjects::containsTypedObjects(m_dragItems)) + if (dynamic_cast(uiItem)) { - itemflags |= Qt::ItemIsDropEnabled; + if (RiuTypedPdmObjects::containsTypedObjects(m_dragItems)) + { + itemflags |= Qt::ItemIsDropEnabled; + } + } + else if (dynamic_cast(uiItem)) + { + if (RiuTypedPdmObjects::containsTypedObjects(m_dragItems)) + { + itemflags |= Qt::ItemIsDropEnabled; + } + else if (RiuTypedPdmObjects::containsTypedObjects(m_dragItems)) + { + itemflags |= Qt::ItemIsDropEnabled; + } + } + else if (dynamic_cast(uiItem)) + { + if (RiuTypedPdmObjects::containsTypedObjects(m_dragItems)) + { + itemflags |= Qt::ItemIsDropEnabled; + } } } - else if (dynamic_cast(uiItem)) + else if (m_proposedAction == Qt::CopyAction) { - if (RiuTypedPdmObjects::containsTypedObjects(m_dragItems)) + if (dynamic_cast(uiItem)) { - itemflags |= Qt::ItemIsDropEnabled; + if (RiuTypedPdmObjects::containsTypedObjects(m_dragItems)) + { + itemflags |= Qt::ItemIsDropEnabled; + } } - else if (RiuTypedPdmObjects::containsTypedObjects(m_dragItems)) + else if (dynamic_cast(uiItem)) { - itemflags |= Qt::ItemIsDropEnabled; - } - else if (RiuTypedPdmObjects::containsTypedObjects(m_dragItems)) - { - itemflags |= Qt::ItemIsDropEnabled; - } - } - else if (dynamic_cast(uiItem)) - { - if (RiuTypedPdmObjects::containsTypedObjects(m_dragItems)) - { - itemflags |= Qt::ItemIsDropEnabled; - } - else if (RiuTypedPdmObjects::containsTypedObjects(m_dragItems)) - { - itemflags |= Qt::ItemIsDropEnabled; + if (RiuTypedPdmObjects::containsTypedObjects(m_dragItems)) + { + itemflags |= Qt::ItemIsDropEnabled; + } } } } @@ -250,10 +266,7 @@ QMimeData* RiuDragDrop::mimeData(const QModelIndexList &indexes) const { MimeDataWithIndexes* myObj = new MimeDataWithIndexes(); myObj->setIndexes(indexes); - - // Keep drag items so that we can determine allowed actions while dragging - m_dragItems = objectHandles(indexes); - + return myObj; } @@ -390,20 +403,25 @@ void RiuDragDrop::objectGroupFromModelIndexes(caf::PdmObjectGroup* objectGroup, //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- -std::vector > RiuDragDrop::objectHandles(const QModelIndexList& indexes) +std::vector > RiuDragDrop::objectHandlesFromSelection() { - std::vector > objectHandlesVec; - caf::PdmUiTreeView* uiTreeView = RiuMainWindow::instance()->projectTreeView(); + std::vector selection; + caf::SelectionManager::instance()->objectsByType(&selection); - for (int i = 0; i < indexes.size(); i++) + std::vector > objectHandles; + + for (size_t sIdx = 0; sIdx < selection.size(); sIdx++) { - caf::PdmUiItem* uiItem = uiTreeView->uiItemFromModelIndex(indexes[i]); - caf::PdmObjectHandle* objHandle = dynamic_cast(uiItem); - if (objHandle) - { - objectHandlesVec.push_back(objHandle); - } + objectHandles.push_back(selection[sIdx]); } - return objectHandlesVec; + return objectHandles; +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RiuDragDrop::setProposedAction(Qt::DropAction action) +{ + m_proposedAction = action; } diff --git a/ApplicationCode/UserInterface/RiuDragDrop.h b/ApplicationCode/UserInterface/RiuDragDrop.h index 8a74d7b3a4..c9d12da5a5 100644 --- a/ApplicationCode/UserInterface/RiuDragDrop.h +++ b/ApplicationCode/UserInterface/RiuDragDrop.h @@ -49,6 +49,7 @@ public: virtual QMimeData* mimeData(const QModelIndexList &indexes) const; virtual QStringList mimeTypes() const; virtual void endDrag(); + virtual void setProposedAction(Qt::DropAction action); private: void moveCasesToGridGroup(caf::PdmObjectGroup& objectGroup, RimIdenticalGridCaseGroup* gridCaseGroup); @@ -57,9 +58,10 @@ private: bool handleWellLogPlotDrop(Qt::DropAction action, caf::PdmObjectGroup& objectGroup, RimWellLogPlot* wellLogPlot); static void objectGroupFromModelIndexes(caf::PdmObjectGroup* objectGroup, const QModelIndexList &indexes); - static std::vector > objectHandles(const QModelIndexList &indexes); + static std::vector > objectHandlesFromSelection(); private: mutable std::vector > m_dragItems; + Qt::DropAction m_proposedAction; };