mirror of
https://github.com/OPM/ResInsight.git
synced 2025-02-25 18:55:39 -06:00
Merge pull request #8459 from OPM/8458-summary-drop-target
Closes #8458
This commit is contained in:
@@ -30,6 +30,7 @@
|
||||
#include "RimSummaryCalculation.h"
|
||||
#include "RimSummaryCalculationCollection.h"
|
||||
#include "RimSummaryCalculationVariable.h"
|
||||
#include "RimSummaryCase.h"
|
||||
#include "RimSummaryCaseMainCollection.h"
|
||||
#include "RimSummaryCrossPlot.h"
|
||||
#include "RimSummaryCrossPlotCollection.h"
|
||||
@@ -238,3 +239,21 @@ std::pair<std::vector<time_t>, std::vector<double>>
|
||||
|
||||
return { resampler.resampledTimeSteps(), resampler.resampledValues() };
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
RimSummaryCase* RiaSummaryTools::summaryCaseById( int caseId )
|
||||
{
|
||||
auto summaryCases = RimProject::current()->allSummaryCases();
|
||||
|
||||
for ( auto summaryCase : summaryCases )
|
||||
{
|
||||
if ( summaryCase->caseId() == caseId )
|
||||
{
|
||||
return summaryCase;
|
||||
}
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
@@ -69,4 +69,6 @@ public:
|
||||
const std::vector<time_t>& timeSteps,
|
||||
std::vector<double>& values,
|
||||
RiaQDateTimeTools::DateTimePeriod period );
|
||||
|
||||
static RimSummaryCase* summaryCaseById( int caseId );
|
||||
};
|
||||
|
||||
@@ -274,6 +274,21 @@ void RimPlot::updateZoomFromParentPlot()
|
||||
{
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
caf::PdmObject* RimPlot::findPdmObjectFromPlotCurve( const RiuPlotCurve* curve ) const
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RimPlot::handleDroppedObjects( const std::vector<caf::PdmObjectHandle*>& objects )
|
||||
{
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
|
||||
@@ -98,7 +98,8 @@ public:
|
||||
virtual void updateZoomInParentPlot();
|
||||
virtual void updateZoomFromParentPlot();
|
||||
|
||||
virtual caf::PdmObject* findPdmObjectFromPlotCurve( const RiuPlotCurve* curve ) const { return nullptr; };
|
||||
virtual caf::PdmObject* findPdmObjectFromPlotCurve( const RiuPlotCurve* curve ) const;
|
||||
virtual void handleDroppedObjects( const std::vector<caf::PdmObjectHandle*>& objects );
|
||||
|
||||
protected:
|
||||
virtual RiuPlotWidget* doCreatePlotViewWidget( QWidget* parent ) = 0;
|
||||
|
||||
@@ -42,6 +42,7 @@
|
||||
#include "RimPlotAxisLogRangeCalculator.h"
|
||||
#include "RimPlotAxisProperties.h"
|
||||
#include "RimProject.h"
|
||||
#include "RimSummaryAddress.h"
|
||||
#include "RimSummaryCase.h"
|
||||
#include "RimSummaryCurve.h"
|
||||
#include "RimSummaryCurveCollection.h"
|
||||
@@ -1957,6 +1958,41 @@ void RimSummaryPlot::setAsCrossPlot()
|
||||
m_isCrossPlot = true;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RimSummaryPlot::handleDroppedObjects( const std::vector<caf::PdmObjectHandle*>& objects )
|
||||
{
|
||||
for ( auto obj : objects )
|
||||
{
|
||||
auto summaryAdr = dynamic_cast<RimSummaryAddress*>( obj );
|
||||
if ( summaryAdr )
|
||||
{
|
||||
if ( summaryAdr->isEnsemble() )
|
||||
{
|
||||
// TODO: Add drop support for ensemble curves
|
||||
}
|
||||
else
|
||||
{
|
||||
auto summaryCase = RiaSummaryTools::summaryCaseById( summaryAdr->caseId() );
|
||||
if ( summaryCase )
|
||||
{
|
||||
auto* newCurve = new RimSummaryCurve();
|
||||
|
||||
newCurve->setSummaryCaseY( summaryCase );
|
||||
newCurve->setSummaryAddressYAndApplyInterpolation( summaryAdr->address() );
|
||||
|
||||
addCurveNoUpdate( newCurve );
|
||||
|
||||
newCurve->loadDataAndUpdate( true );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
updateConnectedEditors();
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
|
||||
@@ -216,6 +216,7 @@ 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;
|
||||
|
||||
|
||||
@@ -184,6 +184,26 @@ RiuDragDrop::~RiuDragDrop()
|
||||
{
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
std::vector<caf::PdmObjectHandle*> RiuDragDrop::draggedObjectsFromTreeView( caf::PdmUiTreeView* dragSource,
|
||||
const QMimeData* data )
|
||||
{
|
||||
const MimeDataWithIndexes* myMimeData = qobject_cast<const MimeDataWithIndexes*>( data );
|
||||
if ( myMimeData )
|
||||
{
|
||||
caf::PdmObjectGroup draggedObjects;
|
||||
QModelIndexList indices = myMimeData->indexes();
|
||||
|
||||
objectGroupFromModelIndexes( dragSource, &draggedObjects, indices );
|
||||
|
||||
return draggedObjects.objects;
|
||||
}
|
||||
|
||||
return {};
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
@@ -352,7 +372,7 @@ bool RiuDragDrop::dropMimeData( const QMimeData* data, Qt::DropAction action, in
|
||||
if ( myMimeData && dropTargetIndex.isValid() )
|
||||
{
|
||||
QModelIndexList indices = myMimeData->indexes();
|
||||
objectGroupFromModelIndexes( &draggedObjects, indices );
|
||||
objectGroupFromModelIndexes( uiTreeView, &draggedObjects, indices );
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -656,12 +676,13 @@ bool RiuDragDrop::handleSummaryCaseMainCollectionDrop( Qt::DropAction
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RiuDragDrop::objectGroupFromModelIndexes( caf::PdmObjectGroup* objectGroup, const QModelIndexList& indexes )
|
||||
void RiuDragDrop::objectGroupFromModelIndexes( caf::PdmUiTreeView* uiTreeView,
|
||||
caf::PdmObjectGroup* objectGroup,
|
||||
const QModelIndexList& indexes )
|
||||
{
|
||||
CVF_ASSERT( objectGroup );
|
||||
|
||||
objectGroup->objects.clear();
|
||||
caf::PdmUiTreeView* uiTreeView = RiuMainWindow::instance()->projectTreeView();
|
||||
|
||||
for ( int i = 0; i < indexes.size(); i++ )
|
||||
{
|
||||
|
||||
@@ -27,7 +27,8 @@
|
||||
namespace caf
|
||||
{
|
||||
class PdmObjectHandle;
|
||||
}
|
||||
class PdmUiTreeView;
|
||||
} // namespace caf
|
||||
|
||||
class RimMultiPlot;
|
||||
class RimIdenticalGridCaseGroup;
|
||||
@@ -49,6 +50,9 @@ public:
|
||||
RiuDragDrop();
|
||||
~RiuDragDrop() override;
|
||||
|
||||
static std::vector<caf::PdmObjectHandle*> draggedObjectsFromTreeView( caf::PdmUiTreeView* dragSource,
|
||||
const QMimeData* data );
|
||||
|
||||
protected:
|
||||
Qt::DropActions supportedDropActions() const override;
|
||||
Qt::ItemFlags flags( const QModelIndex& index ) const override;
|
||||
@@ -96,7 +100,9 @@ private:
|
||||
caf::PdmObjectGroup& objectGroup,
|
||||
RimSurfaceCollection* surfaceCollection );
|
||||
|
||||
static void objectGroupFromModelIndexes( caf::PdmObjectGroup* objectGroup, const QModelIndexList& indexes );
|
||||
static void objectGroupFromModelIndexes( caf::PdmUiTreeView* uiTreeView,
|
||||
caf::PdmObjectGroup* objectGroup,
|
||||
const QModelIndexList& indexes );
|
||||
static std::vector<caf::PdmPointer<caf::PdmObjectHandle>> objectHandlesFromSelection();
|
||||
|
||||
private:
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
|
||||
@@ -180,6 +180,8 @@ public:
|
||||
protected:
|
||||
void updateOverlayFrameLayout();
|
||||
|
||||
bool handleDragDropEvent( QEvent* event );
|
||||
|
||||
static int defaultMinimumWidth();
|
||||
|
||||
caf::PdmPointer<RimPlot> m_plotDefinition;
|
||||
|
||||
@@ -158,10 +158,9 @@ void RiuQtChartsPlotCurve::detach()
|
||||
line->hide();
|
||||
}
|
||||
|
||||
QtCharts::QScatterSeries* scatter = scatterSeries();
|
||||
if ( scatter )
|
||||
if ( scatterSeries() )
|
||||
{
|
||||
scatter->hide();
|
||||
scatterSeries()->hide();
|
||||
}
|
||||
|
||||
if ( m_plotWidget ) setVisibleInLegend( false );
|
||||
@@ -350,12 +349,10 @@ void RiuQtChartsPlotCurve::setVisibleInLegend( bool isVisibleInLegend )
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
QtCharts::QLineSeries* RiuQtChartsPlotCurve::lineSeries() const
|
||||
{
|
||||
if ( m_lineSeries )
|
||||
return m_lineSeries;
|
||||
else if ( m_plotWidget )
|
||||
return dynamic_cast<QtCharts::QLineSeries*>( m_plotWidget->getLineSeries( this ) );
|
||||
else
|
||||
return nullptr;
|
||||
if ( m_lineSeries ) return m_lineSeries;
|
||||
if ( m_plotWidget ) return dynamic_cast<QtCharts::QLineSeries*>( m_plotWidget->getLineSeries( this ) );
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
@@ -363,12 +360,10 @@ QtCharts::QLineSeries* RiuQtChartsPlotCurve::lineSeries() const
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
QtCharts::QScatterSeries* RiuQtChartsPlotCurve::scatterSeries() const
|
||||
{
|
||||
if ( m_scatterSeries )
|
||||
return m_scatterSeries;
|
||||
else if ( m_plotWidget )
|
||||
return dynamic_cast<QtCharts::QScatterSeries*>( m_plotWidget->getScatterSeries( this ) );
|
||||
else
|
||||
return nullptr;
|
||||
if ( m_scatterSeries ) return m_scatterSeries;
|
||||
if ( m_plotWidget ) return dynamic_cast<QtCharts::QScatterSeries*>( m_plotWidget->getScatterSeries( this ) );
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
|
||||
@@ -62,6 +62,8 @@ RiuQtChartsPlotWidget::RiuQtChartsPlotWidget( RimPlot* plotDefinition, QWidget*
|
||||
QtCharts::QChart* chart = new QtCharts::QChart();
|
||||
chart->layout()->setContentsMargins( 0, 0, 0, 0 );
|
||||
chart->setBackgroundRoundness( 0 );
|
||||
chart->setAcceptDrops( true );
|
||||
chart->installEventFilter( this );
|
||||
|
||||
m_viewer = new RiuQtChartView( nullptr, parent );
|
||||
m_viewer->setChart( chart );
|
||||
@@ -986,6 +988,22 @@ Qt::Orientation RiuQtChartsPlotWidget::orientation( RiaDefines::PlotAxis axis )
|
||||
return Qt::Orientation::Vertical;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RiuQtChartsPlotWidget::dragEnterEvent( QDragEnterEvent* event )
|
||||
{
|
||||
RiuPlotWidget::handleDragDropEvent( event );
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RiuQtChartsPlotWidget::dropEvent( QDropEvent* event )
|
||||
{
|
||||
RiuPlotWidget::handleDragDropEvent( event );
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
@@ -1010,6 +1028,16 @@ void RiuQtChartsPlotWidget::wheelEvent( QWheelEvent* event )
|
||||
event->accept();
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
bool RiuQtChartsPlotWidget::eventFilter( QObject* watched, QEvent* event )
|
||||
{
|
||||
if ( RiuPlotWidget::handleDragDropEvent( event ) ) return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
|
||||
@@ -176,6 +176,7 @@ protected:
|
||||
void resizeEvent( QResizeEvent* event ) override;
|
||||
void keyPressEvent( QKeyEvent* event ) override;
|
||||
void wheelEvent( QWheelEvent* event ) override;
|
||||
bool eventFilter( QObject* watched, QEvent* event ) override;
|
||||
|
||||
void applyPlotTitleToPlot();
|
||||
void applyAxisTitleToPlot( RiaDefines::PlotAxis axis );
|
||||
@@ -190,6 +191,9 @@ protected:
|
||||
QtCharts::QAbstractAxis* plotAxis( RiaDefines::PlotAxis axis ) const;
|
||||
Qt::Orientation orientation( RiaDefines::PlotAxis axis ) const;
|
||||
|
||||
void dragEnterEvent( QDragEnterEvent* event ) override;
|
||||
void dropEvent( QDropEvent* event ) override;
|
||||
|
||||
signals:
|
||||
void plotZoomed();
|
||||
|
||||
|
||||
@@ -79,11 +79,12 @@ RiuQwtPlotWidget::RiuQwtPlotWidget( RimPlot* plotDefinition, QWidget* parent )
|
||||
setLayout( layout );
|
||||
|
||||
m_plot = new QwtPlot( this );
|
||||
m_plot->setAcceptDrops( true );
|
||||
layout->addWidget( m_plot );
|
||||
|
||||
RiuQwtPlotTools::setCommonPlotBehaviour( m_plot );
|
||||
|
||||
m_plot->installEventFilter( m_plot );
|
||||
m_plot->installEventFilter( this );
|
||||
m_plot->canvas()->installEventFilter( this );
|
||||
|
||||
setSizePolicy( QSizePolicy::Preferred, QSizePolicy::Preferred );
|
||||
@@ -171,7 +172,7 @@ void RiuQwtPlotWidget::setAxisFontsAndAlignment( RiaDefines::PlotAxis axis,
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RiuQwtPlotWidget::setAxesFontsAndAlignment( int titleFontSize, int valueFontSize, bool titleBold, int alignment )
|
||||
{
|
||||
for ( auto axisTitlePair : m_axisTitles )
|
||||
for ( const auto& axisTitlePair : m_axisTitles )
|
||||
{
|
||||
setAxisFontsAndAlignment( axisTitlePair.first, titleFontSize, valueFontSize, titleBold, alignment );
|
||||
}
|
||||
@@ -534,6 +535,8 @@ void RiuQwtPlotWidget::updateLegend()
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
bool RiuQwtPlotWidget::eventFilter( QObject* watched, QEvent* event )
|
||||
{
|
||||
if ( RiuPlotWidget::handleDragDropEvent( event ) ) return true;
|
||||
|
||||
QWheelEvent* wheelEvent = dynamic_cast<QWheelEvent*>( event );
|
||||
if ( wheelEvent && watched == m_plot->canvas() )
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user