2017-03-16 02:23:27 -05:00
|
|
|
/////////////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// 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 "RiuSummaryQwtPlot.h"
|
|
|
|
|
|
|
|
#include "RiaApplication.h"
|
|
|
|
|
|
|
|
#include "RimContextCommandBuilder.h"
|
2017-09-27 01:12:01 -05:00
|
|
|
#include "RimProject.h"
|
2017-03-16 02:23:27 -05:00
|
|
|
#include "RimSummaryCurve.h"
|
2017-12-04 01:26:23 -06:00
|
|
|
#include "RimSummaryCurveCollection.h"
|
2017-03-16 02:23:27 -05:00
|
|
|
#include "RimSummaryPlot.h"
|
|
|
|
|
2018-02-27 08:53:33 -06:00
|
|
|
#include "RiuPlotMainWindowTools.h"
|
2017-03-27 03:38:26 -05:00
|
|
|
#include "RiuQwtCurvePointTracker.h"
|
2017-09-21 08:12:03 -05:00
|
|
|
#include "RiuQwtPlotWheelZoomer.h"
|
|
|
|
#include "RiuQwtPlotZoomer.h"
|
|
|
|
#include "RiuQwtScalePicker.h"
|
2017-03-16 02:23:27 -05:00
|
|
|
|
|
|
|
#include "cafSelectionManager.h"
|
2017-11-18 18:12:39 -06:00
|
|
|
#include "cafCmdFeatureMenuBuilder.h"
|
2017-03-16 02:23:27 -05:00
|
|
|
|
2017-03-27 03:38:26 -05:00
|
|
|
#include "qwt_date_scale_draw.h"
|
2017-09-21 08:12:03 -05:00
|
|
|
#include "qwt_date_scale_engine.h"
|
2017-03-16 02:23:27 -05:00
|
|
|
#include "qwt_legend.h"
|
|
|
|
#include "qwt_plot_curve.h"
|
|
|
|
#include "qwt_plot_grid.h"
|
|
|
|
#include "qwt_plot_layout.h"
|
2017-09-21 08:12:03 -05:00
|
|
|
#include "qwt_plot_magnifier.h"
|
2017-03-16 02:23:27 -05:00
|
|
|
#include "qwt_plot_panner.h"
|
|
|
|
#include "qwt_plot_zoomer.h"
|
|
|
|
#include "qwt_scale_engine.h"
|
|
|
|
|
|
|
|
#include <QEvent>
|
|
|
|
#include <QMenu>
|
|
|
|
#include <QWheelEvent>
|
|
|
|
|
2017-03-16 02:56:53 -05:00
|
|
|
|
2018-04-18 08:58:49 -05:00
|
|
|
#include "RiuWidgetDragger.h"
|
|
|
|
#include "RiuCvfOverlayItemWidget.h"
|
2018-04-19 07:00:00 -05:00
|
|
|
#include "RimEnsembleCurveSet.h"
|
2018-04-18 08:58:49 -05:00
|
|
|
#include "RimRegularLegendConfig.h"
|
|
|
|
#include "cafTitledOverlayFrame.h"
|
2018-04-20 12:30:12 -05:00
|
|
|
#include "RimEnsembleCurveSetCollection.h"
|
2018-05-08 05:52:33 -05:00
|
|
|
#include "RimMainPlotCollection.h"
|
|
|
|
#include "RimSummaryPlotCollection.h"
|
|
|
|
#include "RimSummaryCase.h"
|
2018-05-11 03:34:09 -05:00
|
|
|
#include "RiuRimQwtPlotCurve.h"
|
|
|
|
#include "RimSummaryCurve.h"
|
2018-04-18 08:58:49 -05:00
|
|
|
|
2019-01-10 09:16:49 -06:00
|
|
|
#include <cfloat>
|
2018-04-20 12:38:21 -05:00
|
|
|
|
2018-05-08 05:52:33 -05:00
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
class EnsembleCurveInfoTextProvider : public IPlotCurveInfoTextProvider
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2018-10-18 12:45:57 -05:00
|
|
|
QString curveInfoText(QwtPlotCurve* curve) override
|
2018-05-08 05:52:33 -05:00
|
|
|
{
|
2018-05-11 03:34:09 -05:00
|
|
|
RiuRimQwtPlotCurve* riuCurve = dynamic_cast<RiuRimQwtPlotCurve*>(curve);
|
2018-05-08 05:52:33 -05:00
|
|
|
RimSummaryCurve* sumCurve = nullptr;
|
2018-05-11 03:34:09 -05:00
|
|
|
if (riuCurve)
|
2018-05-08 05:52:33 -05:00
|
|
|
{
|
2018-05-11 03:34:09 -05:00
|
|
|
sumCurve = dynamic_cast<RimSummaryCurve*>(riuCurve->ownerRimCurve());
|
2018-05-08 05:52:33 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
return sumCurve && sumCurve->summaryCaseY() ? sumCurve->summaryCaseY()->caseName() : "";
|
|
|
|
}
|
|
|
|
};
|
|
|
|
static EnsembleCurveInfoTextProvider ensembleCurveInfoTextProvider;
|
|
|
|
|
2017-03-16 02:23:27 -05:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
RiuSummaryQwtPlot::RiuSummaryQwtPlot(RimSummaryPlot* plotDefinition, QWidget* parent) : QwtPlot(parent)
|
|
|
|
{
|
|
|
|
Q_ASSERT(plotDefinition);
|
|
|
|
m_plotDefinition = plotDefinition;
|
|
|
|
|
|
|
|
setDefaults();
|
|
|
|
|
|
|
|
// LeftButton for the zooming
|
2017-03-31 09:27:05 -05:00
|
|
|
m_zoomerLeft = new RiuQwtPlotZoomer(canvas());
|
2017-03-16 02:23:27 -05:00
|
|
|
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
|
2017-03-31 09:27:05 -05:00
|
|
|
m_zoomerRight = new RiuQwtPlotZoomer(canvas());
|
2017-03-16 02:23:27 -05:00
|
|
|
m_zoomerRight->setAxis(xTop, yRight);
|
|
|
|
m_zoomerRight->setTrackerMode(QwtPicker::AlwaysOff);
|
|
|
|
m_zoomerRight->initMousePattern(1);
|
|
|
|
|
2017-03-27 09:45:00 -05:00
|
|
|
// 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()));
|
2017-03-16 02:23:27 -05:00
|
|
|
|
|
|
|
RiuQwtScalePicker* scalePicker = new RiuQwtScalePicker(this);
|
|
|
|
connect(scalePicker, SIGNAL(clicked(int, double)), this, SLOT(onAxisClicked(int, double)));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
RiuSummaryQwtPlot::~RiuSummaryQwtPlot()
|
|
|
|
{
|
|
|
|
if (m_plotDefinition)
|
|
|
|
{
|
|
|
|
m_plotDefinition->detachAllCurves();
|
|
|
|
m_plotDefinition->handleMdiWindowClosed();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
RimSummaryPlot* RiuSummaryQwtPlot::ownerPlotDefinition()
|
|
|
|
{
|
|
|
|
return m_plotDefinition;
|
|
|
|
}
|
|
|
|
|
2017-03-31 02:17:49 -05:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
RimViewWindow* RiuSummaryQwtPlot::ownerViewWindow() const
|
|
|
|
{
|
|
|
|
return m_plotDefinition;
|
|
|
|
}
|
|
|
|
|
2017-03-16 02:23:27 -05:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
void RiuSummaryQwtPlot::currentVisibleWindow(QwtInterval* leftAxis, QwtInterval* rightAxis, QwtInterval* timeAxis) const
|
|
|
|
{
|
|
|
|
*leftAxis = axisScaleDiv(yLeft).interval();
|
|
|
|
*rightAxis = axisScaleDiv(yRight).interval();
|
|
|
|
*timeAxis = axisScaleDiv(xBottom).interval();
|
|
|
|
}
|
|
|
|
|
2018-04-20 12:30:12 -05:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
void RiuSummaryQwtPlot::updateEnsembleLegendLayout()
|
|
|
|
{
|
|
|
|
const int spacing = 5;
|
2018-04-20 12:57:40 -05:00
|
|
|
int startMarginX = this->canvas()->pos().x() + spacing;
|
|
|
|
int startMarginY = this->canvas()->pos().y() + spacing;
|
2018-04-20 12:30:12 -05:00
|
|
|
|
|
|
|
int xpos = startMarginX;
|
|
|
|
int ypos = startMarginY;
|
|
|
|
int maxColumnWidth = 0;
|
|
|
|
|
2018-05-10 14:29:55 -05:00
|
|
|
if (!ownerPlotDefinition() || !ownerPlotDefinition()->ensembleCurveSetCollection()) return;
|
2018-04-23 04:07:15 -05:00
|
|
|
|
2018-05-10 14:29:55 -05:00
|
|
|
for (RimEnsembleCurveSet * curveSet : ownerPlotDefinition()->ensembleCurveSetCollection()->curveSets())
|
2018-04-20 12:30:12 -05:00
|
|
|
{
|
|
|
|
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());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-16 02:23:27 -05:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
2018-04-18 08:58:49 -05:00
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2018-04-19 07:00:00 -05:00
|
|
|
void RiuSummaryQwtPlot::addOrUpdateEnsembleCurveSetLegend(RimEnsembleCurveSet * curveSetToShowLegendFor)
|
2018-04-18 08:58:49 -05:00
|
|
|
{
|
|
|
|
RiuCvfOverlayItemWidget* overlayWidget = nullptr;
|
|
|
|
|
|
|
|
auto it = m_ensembleLegendWidgets.find(curveSetToShowLegendFor);
|
|
|
|
if (it == m_ensembleLegendWidgets.end() || it->second == nullptr)
|
|
|
|
{
|
|
|
|
overlayWidget = new RiuCvfOverlayItemWidget(this);
|
2018-04-20 12:30:12 -05:00
|
|
|
|
2018-04-18 08:58:49 -05:00
|
|
|
new RiuWidgetDragger(overlayWidget);
|
|
|
|
|
|
|
|
m_ensembleLegendWidgets[curveSetToShowLegendFor] = overlayWidget;
|
2018-04-20 12:30:12 -05:00
|
|
|
|
2018-04-18 08:58:49 -05:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
overlayWidget = it->second;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( overlayWidget )
|
|
|
|
{
|
2018-04-20 09:58:00 -05:00
|
|
|
caf::TitledOverlayFrame* overlyItem = curveSetToShowLegendFor->legendConfig()->titledOverlayFrame();
|
|
|
|
overlyItem->setRenderSize(overlyItem->preferredSize());
|
|
|
|
|
2018-04-18 08:58:49 -05:00
|
|
|
overlayWidget->updateFromOverlyItem(curveSetToShowLegendFor->legendConfig()->titledOverlayFrame());
|
|
|
|
overlayWidget->show();
|
|
|
|
}
|
2018-04-20 12:30:12 -05:00
|
|
|
|
|
|
|
this->updateEnsembleLegendLayout();
|
2018-04-18 08:58:49 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2018-04-19 07:00:00 -05:00
|
|
|
void RiuSummaryQwtPlot::removeEnsembleCurveSetLegend(RimEnsembleCurveSet * curveSetToShowLegendFor)
|
2018-04-18 08:58:49 -05:00
|
|
|
{
|
|
|
|
auto it = m_ensembleLegendWidgets.find(curveSetToShowLegendFor);
|
|
|
|
if ( it != m_ensembleLegendWidgets.end() )
|
|
|
|
{
|
|
|
|
if ( it->second != nullptr ) it->second->deleteLater();
|
|
|
|
|
|
|
|
m_ensembleLegendWidgets.erase(it);
|
|
|
|
}
|
2018-04-20 12:30:12 -05:00
|
|
|
|
|
|
|
this->updateEnsembleLegendLayout();
|
2018-04-18 08:58:49 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2017-03-16 02:23:27 -05:00
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
QSize RiuSummaryQwtPlot::minimumSizeHint() const
|
|
|
|
{
|
|
|
|
return QSize(0, 100);
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
void RiuSummaryQwtPlot::contextMenuEvent(QContextMenuEvent* event)
|
|
|
|
{
|
2017-03-16 02:38:34 -05:00
|
|
|
QMenu menu;
|
2017-11-18 18:12:39 -06:00
|
|
|
caf::CmdFeatureMenuBuilder menuBuilder;
|
2017-03-16 02:38:34 -05:00
|
|
|
|
|
|
|
caf::SelectionManager::instance()->setSelectedItem(ownerPlotDefinition());
|
|
|
|
|
2017-11-18 18:12:39 -06:00
|
|
|
menuBuilder << "RicShowPlotDataFeature";
|
2017-03-16 02:38:34 -05:00
|
|
|
|
2017-11-18 18:12:39 -06:00
|
|
|
menuBuilder.appendToMenu(&menu);
|
2017-03-16 02:38:34 -05:00
|
|
|
|
|
|
|
if (menu.actions().size() > 0)
|
|
|
|
{
|
|
|
|
menu.exec(event->globalPos());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-11-24 11:13:43 -06:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
void RiuSummaryQwtPlot::keyPressEvent(QKeyEvent* keyEvent)
|
|
|
|
{
|
2017-12-04 01:26:23 -06:00
|
|
|
if (m_plotDefinition && m_plotDefinition->summaryCurveCollection())
|
2017-11-24 11:13:43 -06:00
|
|
|
{
|
2017-12-04 01:26:23 -06:00
|
|
|
RimSummaryCurveCollection* curveColl = m_plotDefinition->summaryCurveCollection();
|
|
|
|
curveColl->handleKeyPressEvent(keyEvent);
|
2017-11-24 11:13:43 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-16 02:23:27 -05:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
QSize RiuSummaryQwtPlot::sizeHint() const
|
|
|
|
{
|
|
|
|
return QSize(0, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
void RiuSummaryQwtPlot::setDefaults()
|
|
|
|
{
|
2017-03-27 09:47:59 -05:00
|
|
|
setCommonPlotBehaviour(this);
|
|
|
|
|
|
|
|
enableAxis(QwtPlot::xBottom, true);
|
|
|
|
enableAxis(QwtPlot::yLeft, true);
|
|
|
|
enableAxis(QwtPlot::xTop, false);
|
|
|
|
enableAxis(QwtPlot::yRight, false);
|
|
|
|
|
|
|
|
useDateBasedTimeAxis();
|
|
|
|
|
|
|
|
setAxisMaxMinor(QwtPlot::xBottom, 2);
|
|
|
|
setAxisMaxMinor(QwtPlot::yLeft, 3);
|
|
|
|
|
|
|
|
// 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)
|
|
|
|
{
|
|
|
|
// Plot background and frame look
|
|
|
|
|
|
|
|
QPalette newPalette(plot->palette());
|
2017-03-16 02:23:27 -05:00
|
|
|
newPalette.setColor(QPalette::Background, Qt::white);
|
2017-03-27 09:47:59 -05:00
|
|
|
plot->setPalette(newPalette);
|
2017-03-16 02:23:27 -05:00
|
|
|
|
2017-03-27 09:47:59 -05:00
|
|
|
plot->setAutoFillBackground(true);
|
|
|
|
plot->setCanvasBackground(Qt::white);
|
2017-03-16 02:23:27 -05:00
|
|
|
|
2017-03-27 09:47:59 -05:00
|
|
|
QFrame* canvasFrame = dynamic_cast<QFrame*>(plot->canvas());
|
2017-03-16 02:23:27 -05:00
|
|
|
if (canvasFrame)
|
|
|
|
{
|
|
|
|
canvasFrame->setFrameShape(QFrame::NoFrame);
|
|
|
|
}
|
|
|
|
|
2017-03-27 09:47:59 -05:00
|
|
|
// Grid
|
2017-03-16 02:23:27 -05:00
|
|
|
|
2017-03-27 09:47:59 -05:00
|
|
|
QwtPlotGrid* grid = new QwtPlotGrid;
|
|
|
|
grid->attach(plot);
|
2017-03-16 02:23:27 -05:00
|
|
|
QPen gridPen(Qt::SolidLine);
|
|
|
|
gridPen.setColor(Qt::lightGray);
|
2017-03-27 09:47:59 -05:00
|
|
|
grid->setPen(gridPen);
|
2017-03-16 02:23:27 -05:00
|
|
|
|
2017-03-27 09:47:59 -05:00
|
|
|
// Axis number font
|
|
|
|
QFont axisFont = plot->axisFont(QwtPlot::xBottom);
|
|
|
|
axisFont.setPixelSize(11);
|
2017-03-16 02:23:27 -05:00
|
|
|
|
2017-03-27 09:47:59 -05:00
|
|
|
plot->setAxisFont(QwtPlot::xBottom, axisFont);
|
|
|
|
plot->setAxisFont(QwtPlot::xTop, axisFont);
|
|
|
|
plot->setAxisFont(QwtPlot::yLeft, axisFont);
|
|
|
|
plot->setAxisFont(QwtPlot::yRight, axisFont);
|
2017-03-16 02:23:27 -05:00
|
|
|
|
2017-03-27 09:47:59 -05:00
|
|
|
// Axis title font
|
|
|
|
QwtText axisTitle = plot->axisTitle(QwtPlot::xBottom);
|
|
|
|
QFont axisTitleFont = axisTitle.font();
|
|
|
|
axisTitleFont.setPixelSize(11);
|
|
|
|
axisTitleFont.setBold(false);
|
|
|
|
axisTitle.setFont(axisTitleFont);
|
|
|
|
axisTitle.setRenderFlags(Qt::AlignRight);
|
2017-03-16 02:23:27 -05:00
|
|
|
|
2017-03-27 09:47:59 -05:00
|
|
|
plot->setAxisTitle(QwtPlot::xBottom, axisTitle);
|
|
|
|
plot->setAxisTitle(QwtPlot::xTop, axisTitle);
|
|
|
|
plot->setAxisTitle(QwtPlot::yLeft, axisTitle);
|
|
|
|
plot->setAxisTitle(QwtPlot::yRight, axisTitle);
|
2017-03-16 02:23:27 -05:00
|
|
|
|
2018-09-05 04:04:42 -05:00
|
|
|
// Set a focus policy to allow it taking key press events.
|
|
|
|
// This is not strictly necessary since this widget inherit QwtPlot
|
|
|
|
// which already has a focus policy.
|
|
|
|
// However, for completeness we still do it here.
|
|
|
|
plot->setFocusPolicy(Qt::WheelFocus);
|
2017-03-16 02:23:27 -05:00
|
|
|
|
2018-09-05 04:04:42 -05:00
|
|
|
// Enable mousetracking and event filter
|
2017-03-27 09:47:59 -05:00
|
|
|
plot->canvas()->setMouseTracking(true);
|
|
|
|
plot->canvas()->installEventFilter(plot);
|
|
|
|
plot->plotLayout()->setAlignCanvasToScales(true);
|
2017-03-16 02:23:27 -05:00
|
|
|
|
2018-05-08 05:52:33 -05:00
|
|
|
new RiuQwtCurvePointTracker(plot, true, &ensembleCurveInfoTextProvider);
|
2017-03-16 02:23:27 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
void RiuSummaryQwtPlot::useDateBasedTimeAxis()
|
2017-03-27 09:47:59 -05:00
|
|
|
{
|
|
|
|
enableDateBasedBottomXAxis(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
void RiuSummaryQwtPlot::enableDateBasedBottomXAxis(QwtPlot* plot)
|
2017-03-16 02:23:27 -05:00
|
|
|
{
|
|
|
|
QwtDateScaleDraw* scaleDraw = new QwtDateScaleDraw(Qt::UTC);
|
|
|
|
scaleDraw->setDateFormat(QwtDate::Year, QString("dd-MM-yyyy"));
|
|
|
|
|
|
|
|
QwtDateScaleEngine* scaleEngine = new QwtDateScaleEngine(Qt::UTC);
|
2017-03-27 09:47:59 -05:00
|
|
|
plot->setAxisScaleEngine(QwtPlot::xBottom, scaleEngine);
|
|
|
|
plot->setAxisScaleDraw(QwtPlot::xBottom, scaleDraw);
|
2017-03-16 02:23:27 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2018-04-20 12:57:40 -05:00
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
void RiuSummaryQwtPlot::updateLayout()
|
|
|
|
{
|
|
|
|
QwtPlot::updateLayout();
|
|
|
|
updateEnsembleLegendLayout();
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2017-03-16 02:23:27 -05:00
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
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)
|
|
|
|
{
|
2018-02-18 11:56:43 -06:00
|
|
|
QwtPlotCurve* closestCurve = nullptr;
|
2017-03-16 02:23:27 -05:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-08-02 12:22:03 -05:00
|
|
|
if (closestCurve && distMin < 20)
|
2017-03-16 02:23:27 -05:00
|
|
|
{
|
2018-04-20 05:30:59 -05:00
|
|
|
caf::PdmObject* selectedPlotObject = m_plotDefinition->findRimPlotObjectFromQwtCurve(closestCurve);
|
2017-09-27 01:12:01 -05:00
|
|
|
|
2018-08-02 12:22:03 -05:00
|
|
|
if (selectedPlotObject)
|
2017-03-16 02:23:27 -05:00
|
|
|
{
|
2018-08-02 12:22:03 -05:00
|
|
|
RimProject* proj = nullptr;
|
|
|
|
selectedPlotObject->firstAncestorOrThisOfType(proj);
|
|
|
|
|
|
|
|
if (proj)
|
|
|
|
{
|
|
|
|
RiuPlotMainWindowTools::showPlotMainWindow();
|
|
|
|
RiuPlotMainWindowTools::selectAsCurrentItem(selectedPlotObject);
|
|
|
|
}
|
2017-03-16 02:23:27 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2018-08-02 12:22:03 -05:00
|
|
|
///
|
2017-03-16 02:23:27 -05:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
void RiuSummaryQwtPlot::onZoomedSlot()
|
|
|
|
{
|
2017-03-19 02:45:29 -05:00
|
|
|
m_plotDefinition->updateZoomWindowFromQwt();
|
2017-03-16 02:23:27 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
void RiuSummaryQwtPlot::onAxisClicked(int axis, double value)
|
|
|
|
{
|
|
|
|
if (!m_plotDefinition) return;
|
|
|
|
|
|
|
|
m_plotDefinition->selectAxisInPropertyEditor(axis);
|
|
|
|
}
|