From 2893b29bbca7a3cf74aeaf53de0bf1213026f40d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C3=A5l=20Hagen?= Date: Mon, 19 Oct 2015 13:57:01 +0200 Subject: [PATCH] (#467) Implemented drag & drop for moving tracks between plots --- .../RicWellLogPlotTrackFeatureImpl.cpp | 29 +++++++++++ .../RicWellLogPlotTrackFeatureImpl.h | 2 + .../ProjectDataModel/RimWellLogPlot.cpp | 7 ++- .../ProjectDataModel/RimWellLogPlotTrack.cpp | 12 +++-- ApplicationCode/UserInterface/RiuDragDrop.cpp | 49 +++++++++++++++++-- ApplicationCode/UserInterface/RiuDragDrop.h | 2 + 6 files changed, 90 insertions(+), 11 deletions(-) diff --git a/ApplicationCode/Commands/WellLogCommands/RicWellLogPlotTrackFeatureImpl.cpp b/ApplicationCode/Commands/WellLogCommands/RicWellLogPlotTrackFeatureImpl.cpp index 81d0d21c4f..3c17fd9cc2 100644 --- a/ApplicationCode/Commands/WellLogCommands/RicWellLogPlotTrackFeatureImpl.cpp +++ b/ApplicationCode/Commands/WellLogCommands/RicWellLogPlotTrackFeatureImpl.cpp @@ -19,9 +19,14 @@ #include "RicWellLogPlotTrackFeatureImpl.h" +#include "RimWellLogPlot.h" #include "RimWellLogPlotTrack.h" #include "RimWellLogPlotCurve.h" +#include "RiuMainWindow.h" + +#include "cafPdmUiTreeView.h" + //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- @@ -44,3 +49,27 @@ void RicWellLogPlotTrackFeatureImpl::moveCurvesToWellLogPlotTrack(RimWellLogPlot wellLogPlotTrack->updateConnectedEditors(); } } + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RicWellLogPlotTrackFeatureImpl::moveTracksToWellLogPlot(RimWellLogPlot* wellLogPlot, const std::vector& tracks) +{ + CVF_ASSERT(wellLogPlot); + + for (size_t tIdx = 0; tIdx < tracks.size(); tIdx++) + { + RimWellLogPlot* oldPlot; + tracks[tIdx]->firstAnchestorOrThisOfType(oldPlot); + if (oldPlot) + { + oldPlot->removeTrack(tracks[tIdx]); + oldPlot->updateConnectedEditors(); + } + + wellLogPlot->addTrack(tracks[tIdx]); + wellLogPlot->updateTracks(); + wellLogPlot->updateConnectedEditors(); + RiuMainWindow::instance()->projectTreeView()->selectAsCurrentItem(tracks[tIdx]); + } +} diff --git a/ApplicationCode/Commands/WellLogCommands/RicWellLogPlotTrackFeatureImpl.h b/ApplicationCode/Commands/WellLogCommands/RicWellLogPlotTrackFeatureImpl.h index d64da6df58..9cf6d9307a 100644 --- a/ApplicationCode/Commands/WellLogCommands/RicWellLogPlotTrackFeatureImpl.h +++ b/ApplicationCode/Commands/WellLogCommands/RicWellLogPlotTrackFeatureImpl.h @@ -21,6 +21,7 @@ #include +class RimWellLogPlot; class RimWellLogPlotTrack; class RimWellLogPlotCurve; @@ -32,4 +33,5 @@ class RicWellLogPlotTrackFeatureImpl public: static void moveCurvesToWellLogPlotTrack(RimWellLogPlotTrack* wellLogPlotTrack, const std::vector& curves); + static void moveTracksToWellLogPlot(RimWellLogPlot* wellLogPlot, const std::vector& tracks); }; diff --git a/ApplicationCode/ProjectDataModel/RimWellLogPlot.cpp b/ApplicationCode/ProjectDataModel/RimWellLogPlot.cpp index eb47271603..74bea0fde9 100644 --- a/ApplicationCode/ProjectDataModel/RimWellLogPlot.cpp +++ b/ApplicationCode/ProjectDataModel/RimWellLogPlot.cpp @@ -170,11 +170,16 @@ caf::PdmFieldHandle* RimWellLogPlot::objectToggleField() void RimWellLogPlot::addTrack(RimWellLogPlotTrack* track) { tracks.push_back(track); - if(m_viewer) + if (m_viewer) { track->recreateViewer(); m_viewer->insertTrackPlot(track->viewer()); } + + for (size_t tIdx = 0; tIdx < tracks.size(); tIdx++) + { + tracks[tIdx]->setDescription(QString("Track %1").arg(tIdx + 1)); + } } //-------------------------------------------------------------------------------------------------- diff --git a/ApplicationCode/ProjectDataModel/RimWellLogPlotTrack.cpp b/ApplicationCode/ProjectDataModel/RimWellLogPlotTrack.cpp index 69bd57a029..bd0724d0d3 100644 --- a/ApplicationCode/ProjectDataModel/RimWellLogPlotTrack.cpp +++ b/ApplicationCode/ProjectDataModel/RimWellLogPlotTrack.cpp @@ -211,12 +211,14 @@ void RimWellLogPlotTrack::loadDataAndUpdate() //-------------------------------------------------------------------------------------------------- void RimWellLogPlotTrack::recreateViewer() { - CVF_ASSERT(m_wellLogTrackPlotWidget == NULL); - - m_wellLogTrackPlotWidget = new RiuWellLogTrackPlot(this); - for (size_t cIdx = 0; cIdx < curves.size(); ++cIdx) + if (m_wellLogTrackPlotWidget == NULL) { - curves[cIdx]->setPlot(this->m_wellLogTrackPlotWidget); + m_wellLogTrackPlotWidget = new RiuWellLogTrackPlot(this); + + for (size_t cIdx = 0; cIdx < curves.size(); ++cIdx) + { + curves[cIdx]->setPlot(this->m_wellLogTrackPlotWidget); + } } } diff --git a/ApplicationCode/UserInterface/RiuDragDrop.cpp b/ApplicationCode/UserInterface/RiuDragDrop.cpp index 6b09aeee00..32be7a7fc9 100644 --- a/ApplicationCode/UserInterface/RiuDragDrop.cpp +++ b/ApplicationCode/UserInterface/RiuDragDrop.cpp @@ -32,6 +32,7 @@ #include "RimWellLogFileChannel.h" #include "RimWellLogPlotTrack.h" #include "RimWellLogPlotCurve.h" +#include "RimWellLogPlot.h" #include "RimWellLogPlotTrack.h" #include "RiuMainWindow.h" @@ -69,6 +70,8 @@ Qt::DropActions RiuDragDrop::supportedDropActions() const //-------------------------------------------------------------------------------------------------- Qt::ItemFlags RiuDragDrop::flags(const QModelIndex &index) const { + Qt::ItemFlags itemflags = 0; + if (index.isValid()) { caf::PdmUiTreeView* uiTreeView = RiuMainWindow::instance()->projectTreeView(); @@ -76,20 +79,22 @@ Qt::ItemFlags RiuDragDrop::flags(const QModelIndex &index) const if (dynamic_cast(uiItem) || dynamic_cast(uiItem) || + dynamic_cast(uiItem) || dynamic_cast(uiItem)) { - return Qt::ItemIsDropEnabled; + itemflags |= Qt::ItemIsDropEnabled; } - else if (dynamic_cast(uiItem) || + + if (dynamic_cast(uiItem) || dynamic_cast(uiItem) || + dynamic_cast(uiItem) || dynamic_cast(uiItem)) { // TODO: Remember to handle reservoir holding the main grid - return Qt::ItemIsDragEnabled; + itemflags |= Qt::ItemIsDragEnabled; } } - Qt::ItemFlags itemflags; return itemflags; } @@ -137,6 +142,13 @@ bool RiuDragDrop::dropMimeData(const QMimeData *data, Qt::DropAction action, int { return handleWellLogPlotTrackDrop(action, objectGroup, wellLogPlotTrack); } + + RimWellLogPlot* wellLogPlot; + objHandle->firstAnchestorOrThisOfType(wellLogPlot); + if (wellLogPlot) + { + return handleWellLogPlotDrop(action, objectGroup, wellLogPlot); + } } return false; @@ -252,7 +264,34 @@ bool RiuDragDrop::handleWellLogPlotTrackDrop(Qt::DropAction action, caf::PdmObje } } } - + } + + return false; +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +bool RiuDragDrop::handleWellLogPlotDrop(Qt::DropAction action, caf::PdmObjectGroup& objectGroup, RimWellLogPlot* wellLogPlot) +{ + std::vector > typedObjects; + objectGroup.objectsByType(&typedObjects); + if (typedObjects.size() > 0) + { + std::vector wellLogPlotTracks; + for (size_t cIdx = 0; cIdx < typedObjects.size(); cIdx++) + { + wellLogPlotTracks.push_back(typedObjects[cIdx]); + } + + if (wellLogPlotTracks.size() > 0) + { + if (action == Qt::CopyAction) + { + RicWellLogPlotTrackFeatureImpl::moveTracksToWellLogPlot(wellLogPlot, wellLogPlotTracks); + return true; + } + } } return false; diff --git a/ApplicationCode/UserInterface/RiuDragDrop.h b/ApplicationCode/UserInterface/RiuDragDrop.h index 6f469d060b..0f4ef81c2a 100644 --- a/ApplicationCode/UserInterface/RiuDragDrop.h +++ b/ApplicationCode/UserInterface/RiuDragDrop.h @@ -23,6 +23,7 @@ class RimIdenticalGridCaseGroup; class RimWellLogPlotTrack; +class RimWellLogPlot; namespace caf { @@ -48,5 +49,6 @@ private: void moveCasesToGridGroup(caf::PdmObjectGroup& objectGroup, RimIdenticalGridCaseGroup* gridCaseGroup); bool handleGridCaseGroupDrop(Qt::DropAction action, caf::PdmObjectGroup& objectGroup, RimIdenticalGridCaseGroup* gridCaseGroup); bool handleWellLogPlotTrackDrop(Qt::DropAction action, caf::PdmObjectGroup& objectGroup, RimWellLogPlotTrack* wellLogPlotTrack); + bool handleWellLogPlotDrop(Qt::DropAction action, caf::PdmObjectGroup& objectGroup, RimWellLogPlot* wellLogPlot); };