Summary Multiplot: drag/drop updates (#8692)

Drag'n'drop improvements - accept drops in empty multiplot areas to create new plots
This commit is contained in:
jonjenssen
2022-03-15 15:57:15 +01:00
committed by GitHub
parent 72ff44071d
commit 75a3d3d8f1
12 changed files with 189 additions and 101 deletions

View File

@@ -33,6 +33,7 @@
#include "RimMimeData.h"
#include "RimMultiPlot.h"
#include "RimPlot.h"
#include "RimProject.h"
#include "RimSummaryAddress.h"
#include "RimSummaryAddressCollection.h"
#include "RimSummaryCase.h"
@@ -57,6 +58,8 @@
#include "cafSelectionManager.h"
#include <QAbstractItemModel>
#include <QDropEvent>
#include <QGraphicsSceneEvent>
#include <QModelIndex>
//--------------------------------------------------------------------------------------------------
@@ -764,3 +767,60 @@ bool RiuDragDrop::handleSurfaceCollectionDrop( Qt::DropAction action,
return true;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool RiuDragDrop::handleGenericDropEvent( QEvent* event, std::vector<caf::PdmObjectHandle*>& droppedObjects )
{
if ( !event ) return false;
const MimeDataWithIndexes* mimeData = nullptr;
Qt::KeyboardModifiers keyModifiers;
if ( event->type() == QEvent::Drop )
{
// These drop events come from Qwt
auto dropEvent = static_cast<QDropEvent*>( event );
if ( dropEvent )
{
mimeData = qobject_cast<const MimeDataWithIndexes*>( dropEvent->mimeData() );
keyModifiers = dropEvent->keyboardModifiers();
dropEvent->acceptProposedAction();
}
}
else if ( event->type() == QEvent::GraphicsSceneDrop )
{
// These drop events come from QtChart
auto dropEvent = static_cast<QGraphicsSceneDragDropEvent*>( event );
if ( dropEvent )
{
mimeData = qobject_cast<const MimeDataWithIndexes*>( dropEvent->mimeData() );
dropEvent->acceptProposedAction();
}
}
if ( mimeData )
{
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 ) droppedObjects.push_back( obj );
}
return true;
}
return false;
}

View File

@@ -40,6 +40,7 @@ class RimSurfaceCollection;
class RimWellLogPlot;
class RimWellLogTrack;
class RimWellLogCurve;
class QEvent;
//--------------------------------------------------------------------------------------------------
///
@@ -53,6 +54,8 @@ public:
static std::vector<caf::PdmObjectHandle*> draggedObjectsFromTreeView( caf::PdmUiTreeView* dragSource,
const QMimeData* data );
static bool handleGenericDropEvent( QEvent* event, std::vector<caf::PdmObjectHandle*>& droppedObjects );
protected:
Qt::DropActions supportedDropActions() const override;
Qt::ItemFlags flags( const QModelIndex& index ) const override;

View File

@@ -23,8 +23,10 @@
#include "RimContextCommandBuilder.h"
#include "RimMultiPlot.h"
#include "RimSummaryMultiPlot.h"
#include "RimWellLogTrack.h"
#include "RiuDragDrop.h"
#include "RiuMainWindow.h"
#include "RiuMultiPlotPage.h"
#include "RiuPlotMainWindow.h"
@@ -125,6 +127,7 @@ RiuMultiPlotBook::RiuMultiPlotBook( RimMultiPlot* plotDefinition, QWidget* paren
this->setSizePolicy( QSizePolicy::Preferred, QSizePolicy::MinimumExpanding );
setFocusPolicy( Qt::StrongFocus );
setAcceptDrops( true );
QSize pageSize = m_plotDefinition->pageLayout().fullRectPixels( RiaGuiApplication::applicationResolution() ).size();
applyPagePreviewBookSize( pageSize.width() );
@@ -590,9 +593,9 @@ void RiuMultiPlotBook::applyLook()
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RiuMultiPlotBook::changeCurrentPage( int pageDiff )
void RiuMultiPlotBook::changeCurrentPage( int pageNumber )
{
m_currentPageIndex += pageDiff;
m_currentPageIndex = pageNumber;
if ( m_currentPageIndex >= (int)m_pages.size() ) m_currentPageIndex = (int)m_pages.size() - 1;
if ( m_currentPageIndex < 0 ) m_currentPageIndex = 0;
if ( !m_pages.isEmpty() ) m_scrollArea->ensureWidgetVisible( m_pages[m_currentPageIndex] );
@@ -603,7 +606,7 @@ void RiuMultiPlotBook::changeCurrentPage( int pageDiff )
//--------------------------------------------------------------------------------------------------
void RiuMultiPlotBook::goToNextPage()
{
changeCurrentPage( 1 );
changeCurrentPage( m_currentPageIndex + 1 );
}
//--------------------------------------------------------------------------------------------------
@@ -611,5 +614,38 @@ void RiuMultiPlotBook::goToNextPage()
//--------------------------------------------------------------------------------------------------
void RiuMultiPlotBook::goToPrevPage()
{
changeCurrentPage( -1 );
changeCurrentPage( m_currentPageIndex - 1 );
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RiuMultiPlotBook::goToLastPage()
{
changeCurrentPage( m_pages.size() - 1 );
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RiuMultiPlotBook::dragEnterEvent( QDragEnterEvent* event )
{
event->acceptProposedAction();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RiuMultiPlotBook::dropEvent( QDropEvent* event )
{
std::vector<caf::PdmObjectHandle*> objects;
if ( RiuDragDrop::handleGenericDropEvent( event, objects ) )
{
RimSummaryMultiPlot* multiPlot = dynamic_cast<RimSummaryMultiPlot*>( m_plotDefinition.p() );
if ( multiPlot )
{
multiPlot->addPlot( objects );
}
}
}

View File

@@ -88,6 +88,7 @@ public:
void goToNextPage();
void goToPrevPage();
void goToLastPage();
protected:
void contextMenuEvent( QContextMenuEvent* ) override;
@@ -104,6 +105,9 @@ protected:
QList<QPointer<RiuPlotWidget>> visiblePlotWidgets() const;
void dragEnterEvent( QDragEnterEvent* event ) override;
void dropEvent( QDropEvent* event ) override;
private:
void deleteAllPages();
void createPages();
@@ -111,7 +115,7 @@ private:
RiuMultiPlotPage* createPage();
void applyLook();
void changeCurrentPage( int pageDiff );
void changeCurrentPage( int pageNumber );
private slots:
virtual void performUpdate();

View File

@@ -100,6 +100,7 @@ RiuMultiPlotPage::RiuMultiPlotPage( RimPlotWindow* plotDefinition, QWidget* pare
new RiuPlotObjectPicker( m_plotTitle, m_plotDefinition );
setFocusPolicy( Qt::StrongFocus );
setAcceptDrops( true );
this->setObjectName( QString( "%1" ).arg( reinterpret_cast<uint64_t>( this ) ) );

View File

@@ -244,56 +244,11 @@ bool RiuPlotWidget::handleDragDropEvent( QEvent* event )
}
}
const MimeDataWithIndexes* mimeData = nullptr;
std::vector<caf::PdmObjectHandle*> objects;
if ( event->type() == QEvent::Drop )
if ( RiuDragDrop::handleGenericDropEvent( event, objects ) )
{
// 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 );
}
if ( m_plotDefinition ) m_plotDefinition->handleDroppedObjects( objects );
return true;
}