Merge pull request #8459 from OPM/8458-summary-drop-target

Closes #8458
This commit is contained in:
Magne Sjaastad
2022-01-21 14:32:51 +01:00
committed by GitHub
parent b0470d38ee
commit d5b17976ed
16 changed files with 272 additions and 25 deletions

View File

@@ -19,14 +19,23 @@
#include "RiuQwtPlotWidget.h"
#include "RiaGuiApplication.h"
#include "RiaPlotDefines.h"
#include "RiaPlotWindowRedrawScheduler.h"
#include "RimPlot.h"
#include "RimMimeData.h"
#include "RimPlot.h"
#include "RimProject.h"
#include "RiuDragDrop.h"
#include "RiuDraggableOverlayFrame.h"
#include "RiuPlotMainWindow.h"
#include "cafAssert.h"
#include <QDragEnterEvent>
#include <QGraphicsSceneEvent>
#include <algorithm>
#include <limits>
@@ -217,6 +226,80 @@ void RiuPlotWidget::updateOverlayFrameLayout()
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool RiuPlotWidget::handleDragDropEvent( QEvent* event )
{
if ( !event ) return false;
if ( event->type() == QEvent::DragEnter )
{
auto dragEnterEvent = dynamic_cast<QDragEnterEvent*>( event );
if ( dragEnterEvent )
{
dragEnterEvent->acceptProposedAction();
return true;
}
}
const MimeDataWithIndexes* mimeData = nullptr;
if ( event->type() == QEvent::Drop )
{
// These drop events come from Qwt
auto dropEvent = dynamic_cast<QDropEvent*>( event );
if ( dropEvent )
{
mimeData = qobject_cast<const MimeDataWithIndexes*>( dropEvent->mimeData() );
dropEvent->acceptProposedAction();
}
}
if ( event->type() == QEvent::GraphicsSceneDrop )
{
// These drop events come from QtChart
auto dropEvent = dynamic_cast<QGraphicsSceneDragDropEvent*>( event );
if ( dropEvent )
{
mimeData = qobject_cast<const MimeDataWithIndexes*>( dropEvent->mimeData() );
dropEvent->acceptProposedAction();
}
}
if ( mimeData )
{
std::vector<caf::PdmObjectHandle*> objects;
QString mimeType = caf::PdmUiDragDropInterface::mimeTypeForObjectReferenceList();
auto data = mimeData->data( mimeType );
QStringList objectReferences;
QDataStream in( &data, QIODevice::ReadOnly );
in >> objectReferences;
auto proj = RimProject::current();
for ( const auto& objRef : objectReferences )
{
auto obj = caf::PdmReferenceHelper::objectFromReference( proj, objRef );
if ( obj ) objects.push_back( obj );
}
if ( m_plotDefinition )
{
m_plotDefinition->handleDroppedObjects( objects );
}
return true;
}
return false;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------