mirror of
https://github.com/OPM/ResInsight.git
synced 2025-02-25 18:55:39 -06:00
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:
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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 );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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 ) ) );
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user