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
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
12 changed files with 189 additions and 101 deletions

View File

@ -260,30 +260,6 @@ void RimMultiPlot::movePlotsToThis( const std::vector<RimPlot*>& plotsToMove, in
this->updateAllRequiredEditors();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimMultiPlot::insertPlots( const std::vector<RimPlot*>& plots )
{
for ( auto plot : plots )
{
if ( plot )
{
setTickmarkCount( plot, m_majorTickmarkCount() );
m_plots.insert( -1, plot );
if ( m_viewer )
{
plot->createPlotWidget();
m_viewer->insertPlot( plot->plotWidget(), -1 );
}
plot->setShowWindow( true );
plot->updateAfterInsertingIntoMultiPlot();
}
}
onPlotAdditionOrRemoval();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------

View File

@ -77,7 +77,6 @@ public:
void removePlot( RimPlot* plot ) override;
void movePlotsToThis( const std::vector<RimPlot*>& plots, int insertAtPosition );
void insertPlots( const std::vector<RimPlot*>& plots );
void deleteAllPlots() override;
size_t plotCount() const override;

View File

@ -92,7 +92,10 @@ void RimSummaryMultiPlot::addPlot( RimPlot* plot )
{
RimSummaryPlot* sumPlot = dynamic_cast<RimSummaryPlot*>( plot );
CVF_ASSERT( sumPlot != nullptr );
if ( sumPlot ) RimMultiPlot::addPlot( plot );
if ( sumPlot )
{
RimMultiPlot::addPlot( plot );
}
}
//--------------------------------------------------------------------------------------------------
@ -102,7 +105,36 @@ void RimSummaryMultiPlot::insertPlot( RimPlot* plot, size_t index )
{
RimSummaryPlot* sumPlot = dynamic_cast<RimSummaryPlot*>( plot );
CVF_ASSERT( sumPlot != nullptr );
if ( sumPlot ) RimMultiPlot::insertPlot( plot, index );
if ( sumPlot )
{
RimMultiPlot::insertPlot( plot, index );
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimSummaryMultiPlot::addPlot( const std::vector<caf::PdmObjectHandle*>& objects )
{
RimSummaryPlot* plot = new RimSummaryPlot();
plot->enableAutoPlotTitle( true );
addPlot( plot );
plot->handleDroppedObjects( objects );
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimSummaryMultiPlot::removePlot( RimPlot* plot )
{
RimSummaryPlot* sumPlot = dynamic_cast<RimSummaryPlot*>( plot );
CVF_ASSERT( sumPlot != nullptr );
if ( sumPlot )
{
RimMultiPlot::removePlot( plot );
}
}
//--------------------------------------------------------------------------------------------------

View File

@ -24,6 +24,7 @@
#include "cafPdmChildField.h"
#include "cafPdmObject.h"
#include "cafPdmPtrArrayField.h"
#include "cafSignal.h"
#include <vector>
@ -56,11 +57,14 @@ public:
void addPlot( RimPlot* plot ) override;
void insertPlot( RimPlot* plot, size_t index ) override;
void removePlot( RimPlot* plot ) override;
std::vector<caf::PdmFieldHandle*> fieldsToShowInToolbar();
void syncAxisRanges();
void addPlot( const std::vector<caf::PdmObjectHandle*>& objects );
protected:
bool handleGlobalKeyEvent( QKeyEvent* keyEvent ) override;
bool handleGlobalWheelEvent( QWheelEvent* wheelEvent ) override;

View File

@ -94,7 +94,8 @@ CAF_PDM_SOURCE_INIT( RimSummaryPlot, "SummaryPlot" );
///
//--------------------------------------------------------------------------------------------------
RimSummaryPlot::RimSummaryPlot( bool isCrossPlot )
: m_isCrossPlot( isCrossPlot )
: RimPlot()
, m_isCrossPlot( isCrossPlot )
{
CAF_PDM_InitScriptableObject( "Summary Plot", ":/SummaryPlotLight16x16.png", "", "A Summary Plot" );
@ -1972,6 +1973,34 @@ int RimSummaryPlot::handleAddressCollectionDrop( RimSummaryAddressCollection* ad
return newCurves;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
int RimSummaryPlot::handleSummaryAddressDrop( RimSummaryAddress* summaryAddr )
{
int newCurves = 0;
if ( summaryAddr->isEnsemble() )
{
auto ensemble = RiaSummaryTools::ensembleById( summaryAddr->ensembleId() );
if ( ensemble )
{
addNewEnsembleCurveY( summaryAddr->address(), ensemble );
newCurves++;
}
}
else
{
auto summaryCase = RiaSummaryTools::summaryCaseById( summaryAddr->caseId() );
if ( summaryCase )
{
addNewCurveY( summaryAddr->address(), summaryCase );
newCurves++;
}
}
return newCurves;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
@ -1988,26 +2017,10 @@ void RimSummaryPlot::handleDroppedObjects( const std::vector<caf::PdmObjectHandl
continue;
}
auto summaryAdr = dynamic_cast<RimSummaryAddress*>( obj );
if ( summaryAdr )
auto summaryAddr = dynamic_cast<RimSummaryAddress*>( obj );
if ( summaryAddr )
{
if ( summaryAdr->isEnsemble() )
{
auto ensemble = RiaSummaryTools::ensembleById( summaryAdr->ensembleId() );
if ( ensemble )
{
addNewEnsembleCurveY( summaryAdr->address(), ensemble );
newCurves++;
}
continue;
}
auto summaryCase = RiaSummaryTools::summaryCaseById( summaryAdr->caseId() );
if ( summaryCase )
{
addNewCurveY( summaryAdr->address(), summaryCase );
newCurves++;
}
newCurves += handleSummaryAddressDrop( summaryAddr );
continue;
}

View File

@ -30,6 +30,7 @@
#include "RiuSummaryPlot.h"
#include "cafPdmChildArrayField.h"
#include "cafPdmObjectHandle.h"
#include "cafPdmPtrArrayField.h"
#include "cafPdmPtrField.h"
@ -37,10 +38,12 @@
#include <memory>
#include <set>
#include <vector>
class PdmUiTreeOrdering;
class RimAsciiDataCurve;
class RimGridTimeHistoryCurve;
class RimSummaryAddress;
class RimSummaryAddressCollection;
class RimSummaryCase;
class RimSummaryCaseCollection;
@ -199,6 +202,8 @@ public:
bool isDeletable() const override;
void handleDroppedObjects( const std::vector<caf::PdmObjectHandle*>& objects ) override;
private:
RiuPlotWidget* doCreatePlotViewWidget( QWidget* mainWindowParent = nullptr ) override;
@ -226,7 +231,6 @@ protected:
void defineUiTreeOrdering( caf::PdmUiTreeOrdering& uiTreeOrdering, QString uiConfigName = "" ) override;
void defineUiOrdering( QString uiConfigName, caf::PdmUiOrdering& uiOrdering ) override;
void onLoadDataAndUpdate() override;
void handleDroppedObjects( const std::vector<caf::PdmObjectHandle*>& objects ) override;
QImage snapshotWindowContent() override;
@ -278,6 +282,7 @@ private:
int handleSummaryCaseDrop( RimSummaryCase* summaryCase );
int handleAddressCollectionDrop( RimSummaryAddressCollection* addrColl );
int handleSummaryAddressDrop( RimSummaryAddress* summaryAddr );
bool isOnlyWaterCutCurvesVisible( RiuPlotAxis plotAxis );

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;
}