#4134 #4124 Refactor RiuSummaryQwtPlot on top of a base RiuQwtPlot class and use this for Cross Plots

* Get a lot of functionality included: zoom, panning, etc.
This commit is contained in:
Gaute Lindkvist
2019-02-25 14:54:36 +01:00
parent 2582e98961
commit 4c026952a1
40 changed files with 980 additions and 669 deletions

View File

@@ -36,7 +36,7 @@ ${CMAKE_CURRENT_LIST_DIR}/RiuRmsNavigation.h
${CMAKE_CURRENT_LIST_DIR}/RiuSelectionChangedHandler.h
${CMAKE_CURRENT_LIST_DIR}/Riu3dSelectionManager.h
${CMAKE_CURRENT_LIST_DIR}/RiuSimpleHistogramWidget.h
${CMAKE_CURRENT_LIST_DIR}/RiuGridCrossQwtPlot.h
${CMAKE_CURRENT_LIST_DIR}/RiuQwtPlot.h
${CMAKE_CURRENT_LIST_DIR}/RiuSummaryQwtPlot.h
${CMAKE_CURRENT_LIST_DIR}/RiuTextDialog.h
${CMAKE_CURRENT_LIST_DIR}/RiuTimeStepChangedHandler.h
@@ -117,7 +117,7 @@ ${CMAKE_CURRENT_LIST_DIR}/RiuRmsNavigation.cpp
${CMAKE_CURRENT_LIST_DIR}/RiuSelectionChangedHandler.cpp
${CMAKE_CURRENT_LIST_DIR}/Riu3dSelectionManager.cpp
${CMAKE_CURRENT_LIST_DIR}/RiuSimpleHistogramWidget.cpp
${CMAKE_CURRENT_LIST_DIR}/RiuGridCrossQwtPlot.cpp
${CMAKE_CURRENT_LIST_DIR}/RiuQwtPlot.cpp
${CMAKE_CURRENT_LIST_DIR}/RiuSummaryQwtPlot.cpp
${CMAKE_CURRENT_LIST_DIR}/RiuTextDialog.cpp
${CMAKE_CURRENT_LIST_DIR}/RiuTimeStepChangedHandler.cpp
@@ -184,7 +184,7 @@ ${CMAKE_CURRENT_LIST_DIR}/RiuTreeViewEventFilter.h
${CMAKE_CURRENT_LIST_DIR}/RiuWellLogPlot.h
${CMAKE_CURRENT_LIST_DIR}/RiuWellLogTrack.h
${CMAKE_CURRENT_LIST_DIR}/RiuRecentFileActionProvider.h
${CMAKE_CURRENT_LIST_DIR}/RiuGridCrossQwtPlot.h
${CMAKE_CURRENT_LIST_DIR}/RiuQwtPlot.h
${CMAKE_CURRENT_LIST_DIR}/RiuSummaryQwtPlot.h
${CMAKE_CURRENT_LIST_DIR}/RiuTofAccumulatedPhaseFractionsPlot.h
${CMAKE_CURRENT_LIST_DIR}/RiuQwtScalePicker.h

View File

@@ -26,7 +26,7 @@
#include "RiuQwtPlotWheelZoomer.h"
#include "RiuQwtPlotZoomer.h"
#include "RiuResultQwtPlot.h"
#include "RiuSummaryQwtPlot.h"
#include "RiuQwtPlotTools.h"
#include "cvfBase.h"
#include "cvfColor3.h"
@@ -73,18 +73,18 @@ RiuFlowCharacteristicsPlot::RiuFlowCharacteristicsPlot(RimFlowCharacteristicsPlo
mainLayout->addWidget(m_flowCapVsStorageCapPlot, 1, 0);
mainLayout->addWidget(m_sweepEffPlot, 1, 1);
RiuSummaryQwtPlot::setCommonPlotBehaviour(m_lorenzPlot);
RiuQwtPlotTools::setCommonPlotBehaviour(m_lorenzPlot);
new RiuQwtPlotWheelZoomer(m_lorenzPlot);
addWindowZoom(m_lorenzPlot);
RiuSummaryQwtPlot::enableDateBasedBottomXAxis(m_lorenzPlot);
RiuQwtPlotTools::enableDateBasedBottomXAxis(m_lorenzPlot);
m_lorenzPlot->setTitle("Lorenz Coefficient");
RiuSummaryQwtPlot::setCommonPlotBehaviour(m_sweepEffPlot);
RiuQwtPlotTools::setCommonPlotBehaviour(m_sweepEffPlot);
new RiuQwtPlotWheelZoomer(m_sweepEffPlot);
addWindowZoom(m_sweepEffPlot);
m_sweepEffPlot->setTitle("Sweep Efficiency");
RiuSummaryQwtPlot::setCommonPlotBehaviour(m_flowCapVsStorageCapPlot);
RiuQwtPlotTools::setCommonPlotBehaviour(m_flowCapVsStorageCapPlot);
new RiuQwtPlotWheelZoomer(m_flowCapVsStorageCapPlot);
addWindowZoom(m_flowCapVsStorageCapPlot);
m_flowCapVsStorageCapPlot->setTitle("Flow Capacity vs Storage Capacity");

View File

@@ -1,73 +0,0 @@
/////////////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2019- Equinor ASA
//
// ResInsight is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// ResInsight is distributed in the hope that it will be useful, but WITHOUT ANY
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
// FITNESS FOR A PARTICULAR PURPOSE.
//
// See the GNU General Public License at <http://www.gnu.org/licenses/gpl.html>
// for more details.
//
/////////////////////////////////////////////////////////////////////////////////
#include "RiuGridCrossQwtPlot.h"
#include "RimGridCrossPlot.h"
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RiuGridCrossQwtPlot::RiuGridCrossQwtPlot(RimGridCrossPlot* plotDefinition, QWidget* parent /*= nullptr*/)
{
Q_ASSERT(plotDefinition);
m_plotDefinition = plotDefinition;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RiuGridCrossQwtPlot::~RiuGridCrossQwtPlot()
{
if (m_plotDefinition)
{
m_plotDefinition->detachAllCurves();
m_plotDefinition->handleMdiWindowClosed();
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RimGridCrossPlot* RiuGridCrossQwtPlot::ownerPlotDefinition()
{
return m_plotDefinition;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RimViewWindow* RiuGridCrossQwtPlot::ownerViewWindow() const
{
return m_plotDefinition;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
QSize RiuGridCrossQwtPlot::sizeHint() const
{
return QSize(0, 0);
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
QSize RiuGridCrossQwtPlot::minimumSizeHint() const
{
return QSize(0, 100);
}

View File

@@ -1,53 +0,0 @@
/////////////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2019- Equinor ASA
//
// ResInsight is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// ResInsight is distributed in the hope that it will be useful, but WITHOUT ANY
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
// FITNESS FOR A PARTICULAR PURPOSE.
//
// See the GNU General Public License at <http://www.gnu.org/licenses/gpl.html>
// for more details.
//
/////////////////////////////////////////////////////////////////////////////////
#pragma once
#include "RiuInterfaceToViewWindow.h"
#include "cafPdmPointer.h"
#include "qwt_plot.h"
#include <QPointer>
class RimGridCrossPlot;
//==================================================================================================
//
//
//
//==================================================================================================
class RiuGridCrossQwtPlot : public QwtPlot, public RiuInterfaceToViewWindow
{
Q_OBJECT;
public:
RiuGridCrossQwtPlot(RimGridCrossPlot* plotDefinition, QWidget* parent = nullptr);
~RiuGridCrossQwtPlot() override;
RimGridCrossPlot* ownerPlotDefinition();
RimViewWindow* ownerViewWindow() const override;
protected:
QSize sizeHint() const override;
QSize minimumSizeHint() const override;
private:
caf::PdmPointer<RimGridCrossPlot> m_plotDefinition;
};

View File

@@ -26,7 +26,6 @@
#include "RiuPlotMainWindow.h"
#include "RiuMainWindow.h"
#include "RiuSummaryQwtPlot.h"
#include "RiuViewer.h"
#include "RiuWellLogPlot.h"

View File

@@ -21,7 +21,7 @@
#include "RiaColorTables.h"
#include "Riu3dSelectionManager.h"
#include "RiuSummaryQwtPlot.h"
#include "RiuQwtPlotTools.h"
#include "RigFemPart.h"
#include "RigFemPartCollection.h"
@@ -66,7 +66,7 @@ RiuMohrsCirclePlot::RiuMohrsCirclePlot(QWidget* parent)
, m_sourceGeoMechViewOfLastPlot(nullptr)
, m_scheduleUpdateAxisScaleTimer(nullptr)
{
RiuSummaryQwtPlot::setCommonPlotBehaviour(this);
RiuQwtPlotTools::setCommonPlotBehaviour(this);
enableAxis(QwtPlot::xBottom, true);
enableAxis(QwtPlot::yLeft, true);

View File

@@ -36,7 +36,6 @@
#include "RiuDragDrop.h"
#include "RiuMdiSubWindow.h"
#include "RiuSummaryQwtPlot.h"
#include "RiuToolTipMenu.h"
#include "RiuTreeViewEventFilter.h"
#include "RiuWellAllocationPlot.h"

View File

@@ -18,7 +18,6 @@
#include "RiuPvtPlotPanel.h"
#include "RiuPvtPlotUpdater.h"
#include "RiuSummaryQwtPlot.h"
#include "RigFlowDiagSolverInterface.h"

View File

@@ -0,0 +1,217 @@
/////////////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2016- Statoil ASA
//
// ResInsight is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// ResInsight is distributed in the hope that it will be useful, but WITHOUT ANY
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
// FITNESS FOR A PARTICULAR PURPOSE.
//
// See the GNU General Public License at <http://www.gnu.org/licenses/gpl.html>
// for more details.
//
/////////////////////////////////////////////////////////////////////////////////
#include "RiuQwtPlot.h"
#include "RimProject.h"
#include "RiuPlotMainWindowTools.h"
#include "RiuQwtCurvePointTracker.h"
#include "RiuQwtPlotTools.h"
#include "RiuQwtPlotWheelZoomer.h"
#include "RiuQwtPlotZoomer.h"
#include "RiuQwtScalePicker.h"
#include "qwt_date_scale_draw.h"
#include "qwt_date_scale_engine.h"
#include "qwt_legend.h"
#include "qwt_plot_curve.h"
#include "qwt_plot_grid.h"
#include "qwt_plot_layout.h"
#include "qwt_plot_magnifier.h"
#include "qwt_plot_panner.h"
#include "qwt_plot_zoomer.h"
#include "qwt_scale_engine.h"
#include <QEvent>
#include <QMenu>
#include <QWheelEvent>
#include <cfloat>
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RiuQwtPlot::RiuQwtPlot(RimViewWindow* viewWindow, QWidget* parent) : QwtPlot(parent)
{
Q_ASSERT(viewWindow);
m_ownerViewWindow = viewWindow;
// LeftButton for the zooming
m_zoomerLeft = new RiuQwtPlotZoomer(canvas());
m_zoomerLeft->setRubberBandPen(QColor(Qt::black));
m_zoomerLeft->setTrackerMode(QwtPicker::AlwaysOff);
m_zoomerLeft->setTrackerPen(QColor(Qt::black));
m_zoomerLeft->initMousePattern(1);
// Attach a zoomer for the right axis
m_zoomerRight = new RiuQwtPlotZoomer(canvas());
m_zoomerRight->setAxis(xTop, yRight);
m_zoomerRight->setTrackerMode(QwtPicker::AlwaysOff);
m_zoomerRight->initMousePattern(1);
// MidButton for the panning
QwtPlotPanner* panner = new QwtPlotPanner(canvas());
panner->setMouseButton(Qt::MidButton);
auto wheelZoomer = new RiuQwtPlotWheelZoomer(this);
connect(wheelZoomer, SIGNAL(zoomUpdated()), SLOT(onZoomedSlot()));
connect(m_zoomerLeft, SIGNAL(zoomed( const QRectF & )), SLOT(onZoomedSlot()));
connect(panner, SIGNAL(panned( int , int )), SLOT(onZoomedSlot()));
RiuQwtScalePicker* scalePicker = new RiuQwtScalePicker(this);
connect(scalePicker, SIGNAL(clicked(int, double)), this, SLOT(onAxisClicked(int, double)));
RiuQwtPlotTools::setCommonPlotBehaviour(this);
RiuQwtPlotTools::setDefaultAxes(this);
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RiuQwtPlot::~RiuQwtPlot()
{
if (ownerPlotDefinition())
{
ownerPlotDefinition()->detachAllCurves();
}
if (ownerViewWindow())
{
ownerViewWindow()->handleMdiWindowClosed();
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RimRiuQwtPlotOwnerInterface* RiuQwtPlot::ownerPlotDefinition() const
{
RimRiuQwtPlotOwnerInterface* plotDefinition = dynamic_cast<RimRiuQwtPlotOwnerInterface*>(ownerViewWindow());
return plotDefinition;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RimViewWindow* RiuQwtPlot::ownerViewWindow() const
{
return m_ownerViewWindow;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
QSize RiuQwtPlot::minimumSizeHint() const
{
return QSize(0, 100);
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
QSize RiuQwtPlot::sizeHint() const
{
return QSize(0, 0);
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
QwtInterval RiuQwtPlot::currentAxisRange(QwtPlot::Axis axis)
{
return axisScaleDiv(axis).interval();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool RiuQwtPlot::eventFilter(QObject* watched, QEvent* event)
{
if(watched == canvas())
{
QMouseEvent* mouseEvent = dynamic_cast<QMouseEvent*>(event);
if(mouseEvent)
{
if(mouseEvent->button() == Qt::LeftButton && mouseEvent->type() == QMouseEvent::MouseButtonRelease)
{
selectClosestCurve(mouseEvent->pos());
}
}
}
return QwtPlot::eventFilter(watched, event);
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RiuQwtPlot::selectClosestCurve(const QPoint& pos)
{
QwtPlotCurve* closestCurve = nullptr;
double distMin = DBL_MAX;
const QwtPlotItemList& itmList = itemList();
for(QwtPlotItemIterator it = itmList.begin(); it != itmList.end(); it++)
{
if((*it)->rtti() == QwtPlotItem::Rtti_PlotCurve)
{
QwtPlotCurve* candidateCurve = static_cast<QwtPlotCurve*>(*it);
double dist = DBL_MAX;
candidateCurve->closestPoint(pos, &dist);
if(dist < distMin)
{
closestCurve = candidateCurve;
distMin = dist;
}
}
}
if (closestCurve && distMin < 20)
{
caf::PdmObject* selectedPlotObject = ownerPlotDefinition()->findRimPlotObjectFromQwtCurve(closestCurve);
if (selectedPlotObject)
{
RimProject* proj = nullptr;
selectedPlotObject->firstAncestorOrThisOfType(proj);
if (proj)
{
RiuPlotMainWindowTools::showPlotMainWindow();
RiuPlotMainWindowTools::selectAsCurrentItem(selectedPlotObject);
}
}
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RiuQwtPlot::onZoomedSlot()
{
ownerPlotDefinition()->updateZoomWindowFromQwt();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RiuQwtPlot::onAxisClicked(int axis, double value)
{
ownerPlotDefinition()->selectAxisInPropertyEditor(axis);
}

View File

@@ -0,0 +1,76 @@
/////////////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2016- Statoil ASA
//
// ResInsight is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// ResInsight is distributed in the hope that it will be useful, but WITHOUT ANY
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
// FITNESS FOR A PARTICULAR PURPOSE.
//
// See the GNU General Public License at <http://www.gnu.org/licenses/gpl.html>
// for more details.
//
/////////////////////////////////////////////////////////////////////////////////
#pragma once
#include "RiuInterfaceToViewWindow.h"
#include "RimRiuQwtPlotOwnerInterface.h"
#include "cafPdmPointer.h"
#include "qwt_plot.h"
#include <QPointer>
class QwtPlotCurve;
class QwtPlotGrid;
class QwtPlotZoomer;
class QwtInterval;
class QwtPicker;
class QwtPlotMarker;
class QwtScaleWidget;
//==================================================================================================
//
//
//
//==================================================================================================
class RiuQwtPlot : public QwtPlot, public RiuInterfaceToViewWindow
{
Q_OBJECT;
public:
RiuQwtPlot(RimViewWindow* viewWindow, QWidget* parent = nullptr);
~RiuQwtPlot() override;
RimRiuQwtPlotOwnerInterface* ownerPlotDefinition() const;
RimViewWindow* ownerViewWindow() const override;
QwtInterval currentAxisRange(QwtPlot::Axis axis);
protected:
bool eventFilter(QObject* watched, QEvent* event) override;
QSize sizeHint() const override;
QSize minimumSizeHint() const override;
private:
void selectClosestCurve(const QPoint& pos);
private slots:
void onZoomedSlot( );
void onAxisClicked(int axis, double value);
private:
caf::PdmPointer<RimViewWindow> m_ownerViewWindow;
QPointer<QwtPlotZoomer> m_zoomerLeft;
QPointer<QwtPlotZoomer> m_zoomerRight;
};

View File

@@ -17,6 +17,8 @@
/////////////////////////////////////////////////////////////////////////////////
#include "RiuQwtPlotTools.h"
#include "qwt_date_scale_draw.h"
#include "qwt_date_scale_engine.h"
#include "qwt_plot.h"
#include "qwt_plot_grid.h"
#include "qwt_plot_layout.h"
@@ -100,3 +102,16 @@ void RiuQwtPlotTools::setDefaultAxes(QwtPlot* plot)
plot->setAxisMaxMinor(QwtPlot::xBottom, 2);
plot->setAxisMaxMinor(QwtPlot::yLeft, 3);
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RiuQwtPlotTools::enableDateBasedBottomXAxis(QwtPlot* plot)
{
QwtDateScaleDraw* scaleDraw = new QwtDateScaleDraw(Qt::UTC);
scaleDraw->setDateFormat(QwtDate::Year, QString("dd-MM-yyyy"));
QwtDateScaleEngine* scaleEngine = new QwtDateScaleEngine(Qt::UTC);
plot->setAxisScaleEngine(QwtPlot::xBottom, scaleEngine);
plot->setAxisScaleDraw(QwtPlot::xBottom, scaleDraw);
}

View File

@@ -24,5 +24,6 @@ class RiuQwtPlotTools
public:
static void setCommonPlotBehaviour(QwtPlot* plot);
static void setDefaultAxes(QwtPlot* plot);
static void enableDateBasedBottomXAxis(QwtPlot* plot);
};

View File

@@ -18,8 +18,8 @@
#include "RiuRelativePermeabilityPlotPanel.h"
#include "RiuRelativePermeabilityPlotUpdater.h"
#include "RiuSummaryQwtPlot.h"
#include "RiuQwtPlotCurve.h"
#include "RiuQwtPlotTools.h"
#include "RiuTextDialog.h"
#include "RiaCurveDataTools.h"
@@ -154,7 +154,7 @@ RiuRelativePermeabilityPlotPanel::~RiuRelativePermeabilityPlotPanel()
//--------------------------------------------------------------------------------------------------
void RiuRelativePermeabilityPlotPanel::setPlotDefaults(QwtPlot* plot)
{
RiuSummaryQwtPlot::setCommonPlotBehaviour(plot);
RiuQwtPlotTools::setCommonPlotBehaviour(plot);
{
QwtText plotTitle = plot->title();

View File

@@ -26,7 +26,7 @@
#include "RimCase.h"
#include "RiuQwtPlotCurve.h"
#include "RiuSummaryQwtPlot.h"
#include "RiuQwtPlotTools.h"
#include "RiuTextDialog.h"
#include "cafCmdFeatureMenuBuilder.h"
@@ -173,14 +173,14 @@ void RiuResultQwtPlot::contextMenuEvent(QContextMenuEvent* event)
//--------------------------------------------------------------------------------------------------
void RiuResultQwtPlot::setDefaults()
{
RiuSummaryQwtPlot::setCommonPlotBehaviour(this);
RiuQwtPlotTools::setCommonPlotBehaviour(this);
enableAxis(QwtPlot::xBottom, true);
enableAxis(QwtPlot::yLeft, true);
enableAxis(QwtPlot::xTop, false);
enableAxis(QwtPlot::yRight, false);
RiuSummaryQwtPlot::enableDateBasedBottomXAxis(this);
RiuQwtPlotTools::enableDateBasedBottomXAxis(this);
setAxisMaxMinor(QwtPlot::xBottom, 2);
setAxisMaxMinor(QwtPlot::yLeft, 3);

View File

@@ -1,85 +1,80 @@
/////////////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2016- Statoil ASA
//
// Copyright (C) 2019- Equinor ASA
//
// ResInsight is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
//
// ResInsight is distributed in the hope that it will be useful, but WITHOUT ANY
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
// FITNESS FOR A PARTICULAR PURPOSE.
//
// See the GNU General Public License at <http://www.gnu.org/licenses/gpl.html>
//
// See the GNU General Public License at <http://www.gnu.org/licenses/gpl.html>
// for more details.
//
/////////////////////////////////////////////////////////////////////////////////
#include "RiuSummaryQwtPlot.h"
#include "RiaApplication.h"
#include "RimContextCommandBuilder.h"
#include "RimProject.h"
#include "RimEnsembleCurveSet.h"
#include "RimEnsembleCurveSetCollection.h"
#include "RimMainPlotCollection.h"
#include "RimRegularLegendConfig.h"
#include "RimSummaryCase.h"
#include "RimSummaryCurve.h"
#include "RimSummaryCurveCollection.h"
#include "RimSummaryPlot.h"
#include "RimSummaryPlotCollection.h"
#include "RiuPlotMainWindowTools.h"
#include "RiuCvfOverlayItemWidget.h"
#include "RiuQwtCurvePointTracker.h"
#include "RiuRimQwtPlotCurve.h"
#include "RiuWidgetDragger.h"
#include "RiuPlotMainWindowTools.h"
#include "RiuQwtPlotZoomer.h"
#include "RiuQwtPlotTools.h"
#include "RiuQwtPlotWheelZoomer.h"
#include "RiuQwtPlotZoomer.h"
#include "RiuQwtScalePicker.h"
#include "cafSelectionManager.h"
#include "cafCmdFeatureMenuBuilder.h"
#include "RimProject.h"
#include "qwt_date_scale_draw.h"
#include "qwt_date_scale_engine.h"
#include "cafCmdFeatureMenuBuilder.h"
#include "cafSelectionManager.h"
#include "cafTitledOverlayFrame.h"
#include "qwt_interval.h"
#include "qwt_legend.h"
#include "qwt_plot_curve.h"
#include "qwt_plot_grid.h"
#include "qwt_plot_layout.h"
#include "qwt_plot_magnifier.h"
#include "qwt_plot_panner.h"
#include "qwt_plot_zoomer.h"
#include "qwt_date_scale_draw.h"
#include "qwt_date_scale_engine.h"
#include "qwt_scale_div.h"
#include "qwt_scale_draw.h"
#include "qwt_scale_engine.h"
#include <QEvent>
#include <QMenu>
#include <QMouseEvent>
#include <QWheelEvent>
#include "RiuWidgetDragger.h"
#include "RiuCvfOverlayItemWidget.h"
#include "RimEnsembleCurveSet.h"
#include "RimRegularLegendConfig.h"
#include "cafTitledOverlayFrame.h"
#include "RimEnsembleCurveSetCollection.h"
#include "RimMainPlotCollection.h"
#include "RimSummaryPlotCollection.h"
#include "RimSummaryCase.h"
#include "RiuRimQwtPlotCurve.h"
#include "RimSummaryCurve.h"
#include <cfloat>
//--------------------------------------------------------------------------------------------------
///
///
//--------------------------------------------------------------------------------------------------
class EnsembleCurveInfoTextProvider : public IPlotCurveInfoTextProvider
{
public:
//--------------------------------------------------------------------------------------------------
///
///
//--------------------------------------------------------------------------------------------------
QString curveInfoText(QwtPlotCurve* curve) override
{
RiuRimQwtPlotCurve* riuCurve = dynamic_cast<RiuRimQwtPlotCurve*>(curve);
RimSummaryCurve* sumCurve = nullptr;
RiuRimQwtPlotCurve* riuCurve = dynamic_cast<RiuRimQwtPlotCurve*>(curve);
RimSummaryCurve* sumCurve = nullptr;
if (riuCurve)
{
sumCurve = dynamic_cast<RimSummaryCurve*>(riuCurve->ownerRimCurve());
@@ -91,161 +86,76 @@ public:
static EnsembleCurveInfoTextProvider ensembleCurveInfoTextProvider;
//--------------------------------------------------------------------------------------------------
///
///
//--------------------------------------------------------------------------------------------------
RiuSummaryQwtPlot::RiuSummaryQwtPlot(RimSummaryPlot* plotDefinition, QWidget* parent) : QwtPlot(parent)
RiuSummaryQwtPlot::RiuSummaryQwtPlot(RimViewWindow* viewWindow, QWidget* parent /*= nullptr*/)
: RiuQwtPlot(viewWindow, parent)
{
Q_ASSERT(plotDefinition);
m_plotDefinition = plotDefinition;
setDefaults();
// LeftButton for the zooming
m_zoomerLeft = new RiuQwtPlotZoomer(canvas());
m_zoomerLeft->setRubberBandPen(QColor(Qt::black));
m_zoomerLeft->setTrackerMode(QwtPicker::AlwaysOff);
m_zoomerLeft->setTrackerPen(QColor(Qt::black));
m_zoomerLeft->initMousePattern(1);
// Attach a zoomer for the right axis
m_zoomerRight = new RiuQwtPlotZoomer(canvas());
m_zoomerRight->setAxis(xTop, yRight);
m_zoomerRight->setTrackerMode(QwtPicker::AlwaysOff);
m_zoomerRight->initMousePattern(1);
// MidButton for the panning
QwtPlotPanner* panner = new QwtPlotPanner(canvas());
panner->setMouseButton(Qt::MidButton);
auto wheelZoomer = new RiuQwtPlotWheelZoomer(this);
connect(wheelZoomer, SIGNAL(zoomUpdated()), SLOT(onZoomedSlot()));
connect(m_zoomerLeft, SIGNAL(zoomed( const QRectF & )), SLOT(onZoomedSlot()));
connect(panner, SIGNAL(panned( int , int )), SLOT(onZoomedSlot()));
RiuQwtScalePicker* scalePicker = new RiuQwtScalePicker(this);
connect(scalePicker, SIGNAL(clicked(int, double)), this, SLOT(onAxisClicked(int, double)));
new RiuQwtCurvePointTracker(this, true, &ensembleCurveInfoTextProvider);
}
//--------------------------------------------------------------------------------------------------
///
///
//--------------------------------------------------------------------------------------------------
RiuSummaryQwtPlot::~RiuSummaryQwtPlot()
void RiuSummaryQwtPlot::useDateBasedTimeAxis()
{
if (m_plotDefinition)
RiuQwtPlotTools::enableDateBasedBottomXAxis(this);
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RiuSummaryQwtPlot::useTimeBasedTimeAxis()
{
setAxisScaleEngine(QwtPlot::xBottom, new QwtLinearScaleEngine());
setAxisScaleDraw(QwtPlot::xBottom, new QwtScaleDraw());
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RiuSummaryQwtPlot::addOrUpdateEnsembleCurveSetLegend(RimEnsembleCurveSet* curveSetToShowLegendFor)
{
RiuCvfOverlayItemWidget* overlayWidget = nullptr;
auto it = m_ensembleLegendWidgets.find(curveSetToShowLegendFor);
if (it == m_ensembleLegendWidgets.end() || it->second == nullptr)
{
m_plotDefinition->detachAllCurves();
m_plotDefinition->handleMdiWindowClosed();
overlayWidget = new RiuCvfOverlayItemWidget(this);
new RiuWidgetDragger(overlayWidget);
m_ensembleLegendWidgets[curveSetToShowLegendFor] = overlayWidget;
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RimSummaryPlot* RiuSummaryQwtPlot::ownerPlotDefinition()
{
return m_plotDefinition;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RimViewWindow* RiuSummaryQwtPlot::ownerViewWindow() const
{
return m_plotDefinition;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RiuSummaryQwtPlot::currentVisibleWindow(QwtInterval* leftAxis, QwtInterval* rightAxis, QwtInterval* timeAxis) const
{
*leftAxis = axisScaleDiv(yLeft).interval();
*rightAxis = axisScaleDiv(yRight).interval();
*timeAxis = axisScaleDiv(xBottom).interval();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RiuSummaryQwtPlot::updateEnsembleLegendLayout()
{
const int spacing = 5;
int startMarginX = this->canvas()->pos().x() + spacing;
int startMarginY = this->canvas()->pos().y() + spacing;
int xpos = startMarginX;
int ypos = startMarginY;
int maxColumnWidth = 0;
if (!ownerPlotDefinition() || !ownerPlotDefinition()->ensembleCurveSetCollection()) return;
for (RimEnsembleCurveSet * curveSet : ownerPlotDefinition()->ensembleCurveSetCollection()->curveSets())
else
{
auto pairIt = m_ensembleLegendWidgets.find(curveSet);
if (pairIt != m_ensembleLegendWidgets.end())
{
if (ypos + pairIt->second->height() + spacing > this->canvas()->height())
{
xpos += spacing + maxColumnWidth;
ypos = startMarginY;
maxColumnWidth = 0;
}
RiuCvfOverlayItemWidget* overlayWidget = pairIt->second;
overlayWidget->move(xpos, ypos);
ypos += pairIt->second->height() + spacing;
maxColumnWidth = std::max(maxColumnWidth, pairIt->second->width());
}
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RiuSummaryQwtPlot::addOrUpdateEnsembleCurveSetLegend(RimEnsembleCurveSet * curveSetToShowLegendFor)
{
RiuCvfOverlayItemWidget* overlayWidget = nullptr;
auto it = m_ensembleLegendWidgets.find(curveSetToShowLegendFor);
if (it == m_ensembleLegendWidgets.end() || it->second == nullptr)
{
overlayWidget = new RiuCvfOverlayItemWidget(this);
new RiuWidgetDragger(overlayWidget);
m_ensembleLegendWidgets[curveSetToShowLegendFor] = overlayWidget;
}
else
{
overlayWidget = it->second;
}
}
if ( overlayWidget )
{
caf::TitledOverlayFrame* overlyItem = curveSetToShowLegendFor->legendConfig()->titledOverlayFrame();
overlyItem->setRenderSize(overlyItem->preferredSize());
if (overlayWidget)
{
caf::TitledOverlayFrame* overlyItem = curveSetToShowLegendFor->legendConfig()->titledOverlayFrame();
overlyItem->setRenderSize(overlyItem->preferredSize());
overlayWidget->updateFromOverlyItem(curveSetToShowLegendFor->legendConfig()->titledOverlayFrame());
overlayWidget->show();
}
overlayWidget->updateFromOverlyItem(curveSetToShowLegendFor->legendConfig()->titledOverlayFrame());
overlayWidget->show();
}
this->updateEnsembleLegendLayout();
this->updateEnsembleLegendLayout();
}
//--------------------------------------------------------------------------------------------------
///
///
//--------------------------------------------------------------------------------------------------
void RiuSummaryQwtPlot::removeEnsembleCurveSetLegend(RimEnsembleCurveSet * curveSetToShowLegendFor)
void RiuSummaryQwtPlot::removeEnsembleCurveSetLegend(RimEnsembleCurveSet* curveSetToShowLegendFor)
{
auto it = m_ensembleLegendWidgets.find(curveSetToShowLegendFor);
if ( it != m_ensembleLegendWidgets.end() )
if (it != m_ensembleLegendWidgets.end())
{
if ( it->second != nullptr ) it->second->deleteLater();
if (it->second != nullptr) it->second->deleteLater();
m_ensembleLegendWidgets.erase(it);
}
@@ -253,22 +163,28 @@ void RiuSummaryQwtPlot::removeEnsembleCurveSetLegend(RimEnsembleCurveSet * curve
}
//--------------------------------------------------------------------------------------------------
///
///
//--------------------------------------------------------------------------------------------------
QSize RiuSummaryQwtPlot::minimumSizeHint() const
void RiuSummaryQwtPlot::keyPressEvent(QKeyEvent* keyEvent)
{
return QSize(0, 100);
RimSummaryPlot* summaryPlot = dynamic_cast<RimSummaryPlot*>(ownerPlotDefinition());
if (summaryPlot && summaryPlot->summaryCurveCollection())
{
RimSummaryCurveCollection* curveColl = summaryPlot->summaryCurveCollection();
curveColl->handleKeyPressEvent(keyEvent);
}
}
//--------------------------------------------------------------------------------------------------
///
///
//--------------------------------------------------------------------------------------------------
void RiuSummaryQwtPlot::contextMenuEvent(QContextMenuEvent* event)
{
QMenu menu;
QMenu menu;
caf::CmdFeatureMenuBuilder menuBuilder;
caf::SelectionManager::instance()->setSelectedItem(ownerPlotDefinition());
caf::SelectionManager::instance()->setSelectedItem(ownerViewWindow());
menuBuilder << "RicShowPlotDataFeature";
@@ -281,71 +197,20 @@ void RiuSummaryQwtPlot::contextMenuEvent(QContextMenuEvent* event)
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RiuSummaryQwtPlot::keyPressEvent(QKeyEvent* keyEvent)
{
if (m_plotDefinition && m_plotDefinition->summaryCurveCollection())
{
RimSummaryCurveCollection* curveColl = m_plotDefinition->summaryCurveCollection();
curveColl->handleKeyPressEvent(keyEvent);
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
QSize RiuSummaryQwtPlot::sizeHint() const
{
return QSize(0, 0);
}
//--------------------------------------------------------------------------------------------------
///
///
//--------------------------------------------------------------------------------------------------
void RiuSummaryQwtPlot::setDefaults()
{
setCommonPlotBehaviour(this);
RiuQwtPlotTools::setDefaultAxes(this);
useDateBasedTimeAxis();
// The legend will be deleted in the destructor of the plot or when
// The legend will be deleted in the destructor of the plot or when
// another legend is inserted.
QwtLegend* legend = new QwtLegend(this);
this->insertLegend(legend, BottomLegend);
}
void RiuSummaryQwtPlot::setCommonPlotBehaviour(QwtPlot* plot)
{
RiuQwtPlotTools::setCommonPlotBehaviour(plot);
new RiuQwtCurvePointTracker(plot, true, &ensembleCurveInfoTextProvider);
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RiuSummaryQwtPlot::useDateBasedTimeAxis()
{
enableDateBasedBottomXAxis(this);
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RiuSummaryQwtPlot::enableDateBasedBottomXAxis(QwtPlot* plot)
{
QwtDateScaleDraw* scaleDraw = new QwtDateScaleDraw(Qt::UTC);
scaleDraw->setDateFormat(QwtDate::Year, QString("dd-MM-yyyy"));
QwtDateScaleEngine* scaleEngine = new QwtDateScaleEngine(Qt::UTC);
plot->setAxisScaleEngine(QwtPlot::xBottom, scaleEngine);
plot->setAxisScaleDraw(QwtPlot::xBottom, scaleDraw);
}
//--------------------------------------------------------------------------------------------------
///
///
//--------------------------------------------------------------------------------------------------
void RiuSummaryQwtPlot::updateLayout()
{
@@ -353,91 +218,40 @@ void RiuSummaryQwtPlot::updateLayout()
updateEnsembleLegendLayout();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RiuSummaryQwtPlot::useTimeBasedTimeAxis()
{
setAxisScaleEngine(QwtPlot::xBottom, new QwtLinearScaleEngine());
setAxisScaleDraw(QwtPlot::xBottom, new QwtScaleDraw());
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool RiuSummaryQwtPlot::eventFilter(QObject* watched, QEvent* event)
{
if(watched == canvas())
{
QMouseEvent* mouseEvent = dynamic_cast<QMouseEvent*>(event);
if(mouseEvent)
{
if(mouseEvent->button() == Qt::LeftButton && mouseEvent->type() == QMouseEvent::MouseButtonRelease)
{
selectClosestCurve(mouseEvent->pos());
}
}
}
return QwtPlot::eventFilter(watched, event);
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RiuSummaryQwtPlot::selectClosestCurve(const QPoint& pos)
{
QwtPlotCurve* closestCurve = nullptr;
double distMin = DBL_MAX;
const QwtPlotItemList& itmList = itemList();
for(QwtPlotItemIterator it = itmList.begin(); it != itmList.end(); it++)
{
if((*it)->rtti() == QwtPlotItem::Rtti_PlotCurve)
{
QwtPlotCurve* candidateCurve = static_cast<QwtPlotCurve*>(*it);
double dist = DBL_MAX;
candidateCurve->closestPoint(pos, &dist);
if(dist < distMin)
{
closestCurve = candidateCurve;
distMin = dist;
}
}
}
if (closestCurve && distMin < 20)
{
caf::PdmObject* selectedPlotObject = m_plotDefinition->findRimPlotObjectFromQwtCurve(closestCurve);
if (selectedPlotObject)
{
RimProject* proj = nullptr;
selectedPlotObject->firstAncestorOrThisOfType(proj);
if (proj)
{
RiuPlotMainWindowTools::showPlotMainWindow();
RiuPlotMainWindowTools::selectAsCurrentItem(selectedPlotObject);
}
}
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RiuSummaryQwtPlot::onZoomedSlot()
void RiuSummaryQwtPlot::updateEnsembleLegendLayout()
{
m_plotDefinition->updateZoomWindowFromQwt();
}
const int spacing = 5;
int startMarginX = this->canvas()->pos().x() + spacing;
int startMarginY = this->canvas()->pos().y() + spacing;
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RiuSummaryQwtPlot::onAxisClicked(int axis, double value)
{
if (!m_plotDefinition) return;
int xpos = startMarginX;
int ypos = startMarginY;
int maxColumnWidth = 0;
m_plotDefinition->selectAxisInPropertyEditor(axis);
RimSummaryPlot* summaryPlot = dynamic_cast<RimSummaryPlot*>(ownerPlotDefinition());
if (!summaryPlot || !summaryPlot->ensembleCurveSetCollection()) return;
for (RimEnsembleCurveSet* curveSet : summaryPlot->ensembleCurveSetCollection()->curveSets())
{
auto pairIt = m_ensembleLegendWidgets.find(curveSet);
if (pairIt != m_ensembleLegendWidgets.end())
{
if (ypos + pairIt->second->height() + spacing > this->canvas()->height())
{
xpos += spacing + maxColumnWidth;
ypos = startMarginY;
maxColumnWidth = 0;
}
RiuCvfOverlayItemWidget* overlayWidget = pairIt->second;
overlayWidget->move(xpos, ypos);
ypos += pairIt->second->height() + spacing;
maxColumnWidth = std::max(maxColumnWidth, pairIt->second->width());
}
}
}

View File

@@ -1,17 +1,17 @@
/////////////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2016- Statoil ASA
//
// Copyright (C) 2019- Equinor ASA
//
// ResInsight is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
//
// ResInsight is distributed in the hope that it will be useful, but WITHOUT ANY
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
// FITNESS FOR A PARTICULAR PURPOSE.
//
// See the GNU General Public License at <http://www.gnu.org/licenses/gpl.html>
//
// See the GNU General Public License at <http://www.gnu.org/licenses/gpl.html>
// for more details.
//
/////////////////////////////////////////////////////////////////////////////////
@@ -19,6 +19,7 @@
#pragma once
#include "RiuInterfaceToViewWindow.h"
#include "RiuQwtPlot.h"
#include "cafPdmPointer.h"
@@ -26,72 +27,39 @@
#include <QPointer>
class QwtPlotCurve;
class QwtPlotGrid;
class QwtPlotZoomer;
class QwtInterval;
class QwtPicker;
class QwtPlotMarker;
class QwtScaleWidget;
class RiuCvfOverlayItemWidget;
class QwtPlotZoomer;
class RimGridCrossPlot;
class RimSummaryPlot;
class RimEnsembleCurveSet;
class RiuCvfOverlayItemWidget;
//==================================================================================================
//
//
//
//==================================================================================================
class RiuSummaryQwtPlot : public QwtPlot, public RiuInterfaceToViewWindow
class RiuSummaryQwtPlot : public RiuQwtPlot
{
Q_OBJECT;
public:
RiuSummaryQwtPlot(RimSummaryPlot* plotDefinition, QWidget* parent = nullptr);
~RiuSummaryQwtPlot() override;
RiuSummaryQwtPlot(RimViewWindow* ownerViewWindow, QWidget* parent = nullptr);
RimSummaryPlot* ownerPlotDefinition();
RimViewWindow* ownerViewWindow() const override;
void useDateBasedTimeAxis();
void useTimeBasedTimeAxis();
void useDateBasedTimeAxis();
void useTimeBasedTimeAxis();
void currentVisibleWindow(QwtInterval* leftAxis,
QwtInterval* rightAxis,
QwtInterval* timeAxis) const;
void addOrUpdateEnsembleCurveSetLegend(RimEnsembleCurveSet * curveSetToShowLegendFor);
void removeEnsembleCurveSetLegend(RimEnsembleCurveSet * curveSetToShowLegendFor);
static void setCommonPlotBehaviour(QwtPlot* plot);
static void enableDateBasedBottomXAxis(QwtPlot* plot);
void addOrUpdateEnsembleCurveSetLegend(RimEnsembleCurveSet* curveSetToShowLegendFor);
void removeEnsembleCurveSetLegend(RimEnsembleCurveSet* curveSetToShowLegendFor);
protected:
bool eventFilter(QObject* watched, QEvent* event) override;
void keyPressEvent(QKeyEvent *) override;
QSize sizeHint() const override;
QSize minimumSizeHint() const override;
void contextMenuEvent(QContextMenuEvent *) override;
void updateLayout() override;
void keyPressEvent(QKeyEvent*) override;
void contextMenuEvent(QContextMenuEvent*) override;
void setDefaults();
void updateLayout() override;
private:
void setDefaults();
void selectClosestCurve(const QPoint& pos);
void updateEnsembleLegendLayout();
private slots:
void onZoomedSlot( );
void onAxisClicked(int axis, double value);
private:
caf::PdmPointer<RimSummaryPlot> m_plotDefinition;
QPointer<QwtPlotZoomer> m_zoomerLeft;
QPointer<QwtPlotZoomer> m_zoomerRight;
std::map< caf::PdmPointer<RimEnsembleCurveSet>, QPointer<RiuCvfOverlayItemWidget> > m_ensembleLegendWidgets;
void updateEnsembleLegendLayout();
std::map<caf::PdmPointer<RimEnsembleCurveSet>, QPointer<RiuCvfOverlayItemWidget>> m_ensembleLegendWidgets;
};

View File

@@ -27,6 +27,7 @@
#include "RiuPlotMainWindowTools.h"
#include "RiuQwtCurvePointTracker.h"
#include "RiuQwtPlotTools.h"
#include "RiuQwtLinearScaleEngine.h"
@@ -46,7 +47,6 @@
#include <QWheelEvent>
#include <cfloat>
#include "RiuSummaryQwtPlot.h"
#define RIU_SCROLLWHEEL_ZOOMFACTOR 1.1
#define RIU_SCROLLWHEEL_PANFACTOR 0.1
@@ -77,7 +77,7 @@ RiuWellLogTrack::~RiuWellLogTrack()
//--------------------------------------------------------------------------------------------------
void RiuWellLogTrack::setDefaults()
{
RiuSummaryQwtPlot::setCommonPlotBehaviour(this);
RiuQwtPlotTools::setCommonPlotBehaviour(this);
enableAxis(QwtPlot::xTop, true);
enableAxis(QwtPlot::yLeft, true);