mirror of
https://github.com/OPM/ResInsight.git
synced 2025-02-25 18:55:39 -06:00
(#467) Refactoring - added helper class to simplify the drag & drop code
This commit is contained in:
parent
36f2229b5b
commit
8a3c2c4c38
@ -43,6 +43,41 @@
|
|||||||
#include <QAbstractItemModel>
|
#include <QAbstractItemModel>
|
||||||
#include <QModelIndex>
|
#include <QModelIndex>
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
///
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
template <typename T>
|
||||||
|
class RiuTypedObjectsFromObjectGroupGetter
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
RiuTypedObjectsFromObjectGroupGetter(caf::PdmObjectGroup& objectGroup)
|
||||||
|
{
|
||||||
|
objectGroup.objectsByType(&m_typedObjects);
|
||||||
|
}
|
||||||
|
|
||||||
|
static std::vector<T*> typedObjectsFromGroup(caf::PdmObjectGroup& objectGroup)
|
||||||
|
{
|
||||||
|
RiuTypedObjectsFromObjectGroupGetter<T> typedObjectsGetter(objectGroup);
|
||||||
|
return typedObjectsGetter.typedObjects();
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
std::vector<T*> typedObjects()
|
||||||
|
{
|
||||||
|
std::vector<T*> typedObjectsVec;
|
||||||
|
for (size_t i = 0; i < m_typedObjects.size(); i++)
|
||||||
|
{
|
||||||
|
typedObjectsVec.push_back(m_typedObjects[i].p());
|
||||||
|
}
|
||||||
|
|
||||||
|
return typedObjectsVec;
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
std::vector<caf::PdmPointer<T> > m_typedObjects;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
///
|
///
|
||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
@ -222,17 +257,7 @@ bool RiuDragDrop::handleGridCaseGroupDrop(Qt::DropAction action, caf::PdmObjectG
|
|||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
bool RiuDragDrop::handleWellLogPlotTrackDrop(Qt::DropAction action, caf::PdmObjectGroup& objectGroup, RimWellLogPlotTrack* wellLogPlotTrack)
|
bool RiuDragDrop::handleWellLogPlotTrackDrop(Qt::DropAction action, caf::PdmObjectGroup& objectGroup, RimWellLogPlotTrack* wellLogPlotTrack)
|
||||||
{
|
{
|
||||||
{
|
std::vector<RimWellLogFileChannel*> wellLogFileChannels = RiuTypedObjectsFromObjectGroupGetter<RimWellLogFileChannel>::typedObjectsFromGroup(objectGroup);
|
||||||
std::vector<caf::PdmPointer<RimWellLogFileChannel> > typedObjects;
|
|
||||||
objectGroup.objectsByType(&typedObjects);
|
|
||||||
if (typedObjects.size() > 0)
|
|
||||||
{
|
|
||||||
std::vector<RimWellLogFileChannel*> wellLogFileChannels;
|
|
||||||
for (size_t cIdx = 0; cIdx < typedObjects.size(); cIdx++)
|
|
||||||
{
|
|
||||||
wellLogFileChannels.push_back(typedObjects[cIdx]);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (wellLogFileChannels.size() > 0)
|
if (wellLogFileChannels.size() > 0)
|
||||||
{
|
{
|
||||||
if (action == Qt::CopyAction)
|
if (action == Qt::CopyAction)
|
||||||
@ -241,20 +266,8 @@ bool RiuDragDrop::handleWellLogPlotTrackDrop(Qt::DropAction action, caf::PdmObje
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
{
|
|
||||||
std::vector<caf::PdmPointer<RimWellLogPlotCurve> > typedObjects;
|
|
||||||
objectGroup.objectsByType(&typedObjects);
|
|
||||||
if (typedObjects.size() > 0)
|
|
||||||
{
|
|
||||||
std::vector<RimWellLogPlotCurve*> wellLogPlotCurves;
|
|
||||||
for (size_t cIdx = 0; cIdx < typedObjects.size(); cIdx++)
|
|
||||||
{
|
|
||||||
wellLogPlotCurves.push_back(typedObjects[cIdx]);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
std::vector<RimWellLogPlotCurve*> wellLogPlotCurves = RiuTypedObjectsFromObjectGroupGetter<RimWellLogPlotCurve>::typedObjectsFromGroup(objectGroup);
|
||||||
if (wellLogPlotCurves.size() > 0)
|
if (wellLogPlotCurves.size() > 0)
|
||||||
{
|
{
|
||||||
if (action == Qt::CopyAction)
|
if (action == Qt::CopyAction)
|
||||||
@ -263,8 +276,6 @@ bool RiuDragDrop::handleWellLogPlotTrackDrop(Qt::DropAction action, caf::PdmObje
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -274,16 +285,7 @@ bool RiuDragDrop::handleWellLogPlotTrackDrop(Qt::DropAction action, caf::PdmObje
|
|||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
bool RiuDragDrop::handleWellLogPlotDrop(Qt::DropAction action, caf::PdmObjectGroup& objectGroup, RimWellLogPlot* wellLogPlot)
|
bool RiuDragDrop::handleWellLogPlotDrop(Qt::DropAction action, caf::PdmObjectGroup& objectGroup, RimWellLogPlot* wellLogPlot)
|
||||||
{
|
{
|
||||||
std::vector<caf::PdmPointer<RimWellLogPlotTrack> > typedObjects;
|
std::vector<RimWellLogPlotTrack*> wellLogPlotTracks = RiuTypedObjectsFromObjectGroupGetter<RimWellLogPlotTrack>::typedObjectsFromGroup(objectGroup);
|
||||||
objectGroup.objectsByType(&typedObjects);
|
|
||||||
if (typedObjects.size() > 0)
|
|
||||||
{
|
|
||||||
std::vector<RimWellLogPlotTrack*> wellLogPlotTracks;
|
|
||||||
for (size_t cIdx = 0; cIdx < typedObjects.size(); cIdx++)
|
|
||||||
{
|
|
||||||
wellLogPlotTracks.push_back(typedObjects[cIdx]);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (wellLogPlotTracks.size() > 0)
|
if (wellLogPlotTracks.size() > 0)
|
||||||
{
|
{
|
||||||
if (action == Qt::CopyAction)
|
if (action == Qt::CopyAction)
|
||||||
@ -292,7 +294,6 @@ bool RiuDragDrop::handleWellLogPlotDrop(Qt::DropAction action, caf::PdmObjectGro
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user