#1105 Stripped down basic infrastructure code

This commit is contained in:
Magne Sjaastad
2017-01-13 09:50:43 +01:00
parent 96396eed10
commit 0cbdcd587d
8 changed files with 99 additions and 561 deletions

View File

@@ -30,10 +30,12 @@ CAF_PDM_SOURCE_INIT(RimFlowPlotCollection, "FlowPlotCollection");
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
RimFlowPlotCollection::RimFlowPlotCollection() RimFlowPlotCollection::RimFlowPlotCollection()
{ {
CAF_PDM_InitObject("Flow Diagnosis Plots", ":/WellLogPlots16x16.png", "", ""); CAF_PDM_InitObject("Flow Diagnostics Plots", ":/newIcon16x16.png", "", "");
CAF_PDM_InitFieldNoDefault(&flowPlots, "WellLogPlots", "", "", "", ""); CAF_PDM_InitFieldNoDefault(&flowPlots, "FlowPlots", "", "", "", "");
flowPlots.uiCapability()->setUiHidden(true); flowPlots.uiCapability()->setUiHidden(true);
flowPlots.push_back(new RimWellAllocationPlot);
} }
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------

View File

@@ -19,11 +19,9 @@
#include "RimWellAllocationPlot.h" #include "RimWellAllocationPlot.h"
#include "RiaApplication.h" #include "RiaApplication.h"
#include "RimEclipseWell.h"
#include "RiuMainPlotWindow.h" #include "RiuMainPlotWindow.h"
#include "RiuWellAllocationPlot.h" #include "RiuWellAllocationPlot.h"
#include "qwt_plot_renderer.h"
CAF_PDM_SOURCE_INIT(RimWellAllocationPlot, "WellAllocationPlot"); CAF_PDM_SOURCE_INIT(RimWellAllocationPlot, "WellAllocationPlot");
@@ -34,13 +32,14 @@ CAF_PDM_SOURCE_INIT(RimWellAllocationPlot, "WellAllocationPlot");
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
RimWellAllocationPlot::RimWellAllocationPlot() RimWellAllocationPlot::RimWellAllocationPlot()
{ {
CAF_PDM_InitObject("Well Allocation Plot", ":/SummaryPlot16x16.png", "", ""); CAF_PDM_InitObject("Well Allocation Plot", ":/newIcon16x16.png", "", "");
CAF_PDM_InitField(&m_showWindow, "ShowWindow", true, "Show Summary Plot", "", "", ""); CAF_PDM_InitField(&m_showWindow, "ShowWindow", true, "Show Flow Diagnostics Plot", "", "", "");
m_showWindow.uiCapability()->setUiHidden(true); m_showWindow.uiCapability()->setUiHidden(true);
CAF_PDM_InitField(&m_userName, "PlotDescription", QString("Summary Plot"), "Name", "", "", ""); CAF_PDM_InitField(&m_userName, "PlotDescription", QString("Flow Diagnostics Plot"), "Name", "", "", "");
CAF_PDM_InitField(&m_showPlotTitle, "ShowPlotTitle", true, "Show Plot Title", "", "", ""); CAF_PDM_InitField(&m_showPlotTitle, "ShowPlotTitle", true, "Show Plot Title", "", "", "");
CAF_PDM_InitFieldNoDefault(&m_simulationWell, "SimulationWell", "Simulation Well", "", "", "");
} }
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
@@ -50,7 +49,7 @@ RimWellAllocationPlot::~RimWellAllocationPlot()
{ {
if (RiaApplication::instance()->mainPlotWindow()) if (RiaApplication::instance()->mainPlotWindow())
{ {
RiaApplication::instance()->mainPlotWindow()->removeViewer(m_qwtPlot); RiaApplication::instance()->mainPlotWindow()->removeViewer(m_wellAllocationPlot);
} }
deletePlotWidget(); deletePlotWidget();
@@ -59,21 +58,25 @@ RimWellAllocationPlot::~RimWellAllocationPlot()
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
/// ///
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
void RimWellAllocationPlot::deletePlotWidget() void RimWellAllocationPlot::setSimulationWell(RimEclipseWell* simWell)
{ {
if (m_qwtPlot) m_simulationWell = simWell;
{
m_qwtPlot->deleteLater(); setDescription(simWell->name());
m_qwtPlot = NULL;
} updateViewerWidget();
} }
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
/// ///
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
void RimWellAllocationPlot::updateAxes() void RimWellAllocationPlot::deletePlotWidget()
{ {
updateZoomInQwt(); if (m_wellAllocationPlot)
{
m_wellAllocationPlot->deleteLater();
m_wellAllocationPlot = nullptr;
}
} }
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
@@ -81,9 +84,15 @@ void RimWellAllocationPlot::updateAxes()
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
QWidget* RimWellAllocationPlot::viewWidget() QWidget* RimWellAllocationPlot::viewWidget()
{ {
return m_qwtPlot; return m_wellAllocationPlot;
} }
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimWellAllocationPlot::zoomAll()
{
}
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
/// ///
@@ -92,41 +101,18 @@ void RimWellAllocationPlot::handleViewerDeletion()
{ {
m_showWindow = false; m_showWindow = false;
if (m_qwtPlot)
{
detachAllCurves();
}
uiCapability()->updateUiIconFromToggleField(); uiCapability()->updateUiIconFromToggleField();
updateConnectedEditors(); updateConnectedEditors();
} }
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimWellAllocationPlot::zoomAll()
{
}
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
/// ///
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
void RimWellAllocationPlot::fieldChangedByUi(const caf::PdmFieldHandle* changedField, const QVariant& oldValue, const QVariant& newValue) void RimWellAllocationPlot::fieldChangedByUi(const caf::PdmFieldHandle* changedField, const QVariant& oldValue, const QVariant& newValue)
{ {
if (changedField == &m_showWindow) if (changedField == &m_showWindow)
{
if (m_showWindow)
{
loadDataAndUpdate();
}
else
{ {
updateViewerWidget(); updateViewerWidget();
}
uiCapability()->updateUiIconFromToggleField(); uiCapability()->updateUiIconFromToggleField();
} }
@@ -142,9 +128,9 @@ void RimWellAllocationPlot::fieldChangedByUi(const caf::PdmFieldHandle* changedF
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
void RimWellAllocationPlot::setupBeforeSave() void RimWellAllocationPlot::setupBeforeSave()
{ {
if (m_qwtPlot && RiaApplication::instance()->mainPlotWindow()) if (m_wellAllocationPlot && RiaApplication::instance()->mainPlotWindow())
{ {
this->setMdiWindowGeometry(RiaApplication::instance()->mainPlotWindow()->windowGeometryForViewer(m_qwtPlot)); this->setMdiWindowGeometry(RiaApplication::instance()->mainPlotWindow()->windowGeometryForViewer(m_wellAllocationPlot));
} }
} }
@@ -155,60 +141,11 @@ QImage RimWellAllocationPlot::snapshotWindowContent()
{ {
QImage image; QImage image;
if (m_qwtPlot) // TODO
{
image = QImage(m_qwtPlot->size(), QImage::Format_ARGB32);
image.fill(QColor(Qt::white).rgb());
QPainter painter(&image);
QRectF rect(0, 0, m_qwtPlot->size().width(), m_qwtPlot->size().height());
QwtPlotRenderer plotRenderer;
plotRenderer.render(m_qwtPlot, &painter, rect);
}
return image; return image;
} }
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimWellAllocationPlot::defineUiTreeOrdering(caf::PdmUiTreeOrdering& uiTreeOrdering, QString uiConfigName /*= ""*/)
{
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimWellAllocationPlot::loadDataAndUpdate()
{
updateViewerWidget();
// for (RimSummaryCurveFilter* curveFilter : m_curveFilters)
// {
// curveFilter->loadDataAndUpdate();
// }
//
// for (RimSummaryCurve* curve : m_curves)
// {
// curve->loadDataAndUpdate();
// }
this->updateAxes();
updateZoomInQwt();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimWellAllocationPlot::updateZoomInQwt()
{
if (!m_qwtPlot) return;
zoomAll();
}
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
/// ///
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
@@ -235,34 +172,23 @@ void RimWellAllocationPlot::updateViewerWidget()
if (m_showWindow()) if (m_showWindow())
{ {
if (!m_qwtPlot) if (!m_wellAllocationPlot)
{ {
m_qwtPlot = new RiuWellAllocationPlot(this, mainPlotWindow); m_wellAllocationPlot = new RiuWellAllocationPlot(this, mainPlotWindow);
// for (RimSummaryCurveFilter* curveFilter : m_curveFilters) mainPlotWindow->addViewer(m_wellAllocationPlot, this->mdiWindowGeometry());
// { mainPlotWindow->setActiveViewer(m_wellAllocationPlot);
// curveFilter->setParentQwtPlot(m_qwtPlot);
// }
//
// for (RimSummaryCurve* curve : m_curves)
// {
// curve->setParentQwtPlot(m_qwtPlot);
// }
mainPlotWindow->addViewer(m_qwtPlot, this->mdiWindowGeometry());
mainPlotWindow->setActiveViewer(m_qwtPlot);
} }
updateViewerWidgetWindowTitle(); updateViewerWidgetWindowTitle();
} }
else else
{ {
if (m_qwtPlot) if (m_wellAllocationPlot)
{ {
this->setMdiWindowGeometry(mainPlotWindow->windowGeometryForViewer(m_qwtPlot)); this->setMdiWindowGeometry(mainPlotWindow->windowGeometryForViewer(m_wellAllocationPlot));
mainPlotWindow->removeViewer(m_qwtPlot); mainPlotWindow->removeViewer(m_wellAllocationPlot);
detachAllCurves();
deletePlotWidget(); deletePlotWidget();
} }
@@ -274,34 +200,18 @@ void RimWellAllocationPlot::updateViewerWidget()
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
void RimWellAllocationPlot::updateViewerWidgetWindowTitle() void RimWellAllocationPlot::updateViewerWidgetWindowTitle()
{ {
if (m_qwtPlot) if (m_wellAllocationPlot)
{ {
m_qwtPlot->setWindowTitle(m_userName); m_wellAllocationPlot->setWindowTitle(m_userName);
if (m_showPlotTitle) if (m_showPlotTitle)
{ {
m_qwtPlot->setTitle(m_userName); m_wellAllocationPlot->setTitle(m_userName);
} }
else else
{ {
m_qwtPlot->setTitle(""); m_wellAllocationPlot->setTitle("");
} }
} }
} }
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimWellAllocationPlot::detachAllCurves()
{
// for (RimSummaryCurveFilter* curveFilter : m_curveFilters)
// {
// curveFilter->detachQwtCurves();
// }
//
// for (RimSummaryCurve* curve : m_curves)
// {
// curve->detachQwtCurve();
// }
}

View File

@@ -18,15 +18,17 @@
#pragma once #pragma once
#include "cafPdmObject.h"
#include "cafPdmField.h"
#include "RimViewWindow.h" #include "RimViewWindow.h"
#include "cafPdmField.h"
#include "cafPdmObject.h"
#include "cafPdmPtrField.h"
#include <QPointer> #include <QPointer>
class RiuWellAllocationPlot; class RiuWellAllocationPlot;
class QwtInterval; class RimEclipseWell;
//================================================================================================== //==================================================================================================
@@ -41,21 +43,15 @@ public:
RimWellAllocationPlot(); RimWellAllocationPlot();
virtual ~RimWellAllocationPlot(); virtual ~RimWellAllocationPlot();
void setSimulationWell(RimEclipseWell* simWell);
void setDescription(const QString& description); void setDescription(const QString& description);
QString description() const; QString description() const;
void loadDataAndUpdate();
void handleViewerDeletion(); void handleViewerDeletion();
void updateCaseNameHasChanged();
void updateAxes();
virtual void zoomAll() override;
void updateZoomInQwt();
void disableAutoZoom();
virtual QWidget* viewWidget() override; virtual QWidget* viewWidget() override;
virtual void zoomAll() override;
protected: protected:
// Overridden PDM methods // Overridden PDM methods
@@ -63,23 +59,21 @@ protected:
virtual caf::PdmFieldHandle* userDescriptionField() { return &m_userName; } virtual caf::PdmFieldHandle* userDescriptionField() { return &m_userName; }
virtual void fieldChangedByUi(const caf::PdmFieldHandle* changedField, const QVariant& oldValue, const QVariant& newValue) override; virtual void fieldChangedByUi(const caf::PdmFieldHandle* changedField, const QVariant& oldValue, const QVariant& newValue) override;
virtual void setupBeforeSave() override; virtual void setupBeforeSave() override;
virtual void defineUiTreeOrdering(caf::PdmUiTreeOrdering& uiTreeOrdering, QString uiConfigName = "") override;
virtual QImage snapshotWindowContent() override; virtual QImage snapshotWindowContent() override;
private: private:
void updateViewerWidget(); void updateViewerWidget();
void updateViewerWidgetWindowTitle(); void updateViewerWidgetWindowTitle();
void detachAllCurves();
void deletePlotWidget(); void deletePlotWidget();
private: private:
caf::PdmField<bool> m_showWindow; caf::PdmField<bool> m_showWindow;
caf::PdmField<bool> m_showPlotTitle; caf::PdmField<bool> m_showPlotTitle;
caf::PdmField<QString> m_userName; caf::PdmField<QString> m_userName;
QPointer<RiuWellAllocationPlot> m_qwtPlot; caf::PdmPtrField<RimEclipseWell*> m_simulationWell;
QPointer<RiuWellAllocationPlot> m_wellAllocationPlot;
}; };

View File

@@ -19,6 +19,7 @@
#include "RimMainPlotCollection.h" #include "RimMainPlotCollection.h"
#include "RimFlowPlotCollection.h"
#include "RimProject.h" #include "RimProject.h"
#include "RimSummaryPlotCollection.h" #include "RimSummaryPlotCollection.h"
#include "RimWellLogPlotCollection.h" #include "RimWellLogPlotCollection.h"
@@ -44,8 +45,12 @@ RimMainPlotCollection::RimMainPlotCollection()
CAF_PDM_InitFieldNoDefault(&m_summaryPlotCollection, "SummaryPlotCollection", "Summary Plots", "", "", ""); CAF_PDM_InitFieldNoDefault(&m_summaryPlotCollection, "SummaryPlotCollection", "Summary Plots", "", "", "");
m_summaryPlotCollection.uiCapability()->setUiHidden(true); m_summaryPlotCollection.uiCapability()->setUiHidden(true);
CAF_PDM_InitFieldNoDefault(&m_flowPlotCollection, "FlowPlotCollection", "Flow Diagnostics Plots", "", "", "");
m_flowPlotCollection.uiCapability()->setUiHidden(true);
m_wellLogPlotCollection = new RimWellLogPlotCollection(); m_wellLogPlotCollection = new RimWellLogPlotCollection();
m_summaryPlotCollection = new RimSummaryPlotCollection(); m_summaryPlotCollection = new RimSummaryPlotCollection();
m_flowPlotCollection = new RimFlowPlotCollection();
//m_plotMainWindow = NULL; //m_plotMainWindow = NULL;
//m_plotManagerMainWindow = NULL; //m_plotManagerMainWindow = NULL;
@@ -58,6 +63,7 @@ RimMainPlotCollection::~RimMainPlotCollection()
{ {
if (m_wellLogPlotCollection()) delete m_wellLogPlotCollection(); if (m_wellLogPlotCollection()) delete m_wellLogPlotCollection();
if (m_summaryPlotCollection()) delete m_summaryPlotCollection(); if (m_summaryPlotCollection()) delete m_summaryPlotCollection();
if (m_flowPlotCollection()) delete m_flowPlotCollection();
//m_plotManagerMainWindow->close(); //m_plotManagerMainWindow->close();
//m_plotManagerMainWindow->deleteLater(); //m_plotManagerMainWindow->deleteLater();
@@ -148,6 +154,24 @@ RimSummaryPlotCollection* RimMainPlotCollection::summaryPlotCollection()
return m_summaryPlotCollection(); return m_summaryPlotCollection();
} }
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RimFlowPlotCollection* RimMainPlotCollection::flowPlotCollection()
{
return m_flowPlotCollection();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimMainPlotCollection::deleteAllContainedObjects()
{
m_wellLogPlotCollection()->wellLogPlots.deleteAllChildObjects();
m_summaryPlotCollection()->m_summaryPlots.deleteAllChildObjects();
m_flowPlotCollection()->flowPlots.deleteAllChildObjects();
}
#if 0 #if 0
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
/// ///

View File

@@ -32,6 +32,7 @@ class RimSummaryPlotCollection;
class RimSummaryPlot; class RimSummaryPlot;
class RifReaderEclipseSummary; class RifReaderEclipseSummary;
class RimEclipseResultCase; class RimEclipseResultCase;
class RimFlowPlotCollection;
//================================================================================================== //==================================================================================================
@@ -47,6 +48,9 @@ public:
RimWellLogPlotCollection* wellLogPlotCollection(); RimWellLogPlotCollection* wellLogPlotCollection();
RimSummaryPlotCollection* summaryPlotCollection(); RimSummaryPlotCollection* summaryPlotCollection();
RimFlowPlotCollection* flowPlotCollection();
void deleteAllContainedObjects();
#if 0 #if 0
// Separate Window stuff // Separate Window stuff
@@ -78,6 +82,7 @@ protected:
caf::PdmChildField<RimWellLogPlotCollection*> m_wellLogPlotCollection; caf::PdmChildField<RimWellLogPlotCollection*> m_wellLogPlotCollection;
caf::PdmChildField<RimSummaryPlotCollection*> m_summaryPlotCollection; caf::PdmChildField<RimSummaryPlotCollection*> m_summaryPlotCollection;
caf::PdmChildField<RimFlowPlotCollection*> m_flowPlotCollection;
caf::PdmField<bool> show; caf::PdmField<bool> show;
}; };

View File

@@ -33,6 +33,7 @@
#include "RimContextCommandBuilder.h" #include "RimContextCommandBuilder.h"
#include "RimEclipseCase.h" #include "RimEclipseCase.h"
#include "RimEclipseCaseCollection.h" #include "RimEclipseCaseCollection.h"
#include "RimFlowPlotCollection.h"
#include "RimFormationNamesCollection.h" #include "RimFormationNamesCollection.h"
#include "RimGeoMechCase.h" #include "RimGeoMechCase.h"
#include "RimGeoMechModels.h" #include "RimGeoMechModels.h"
@@ -161,14 +162,9 @@ RimProject::~RimProject(void)
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
void RimProject::close() void RimProject::close()
{ {
if (mainPlotCollection() && mainPlotCollection()->wellLogPlotCollection()) if (mainPlotCollection())
{ {
mainPlotCollection()->wellLogPlotCollection()->wellLogPlots.deleteAllChildObjects(); mainPlotCollection()->deleteAllContainedObjects();
}
if (mainPlotCollection() && mainPlotCollection()->summaryPlotCollection())
{
mainPlotCollection()->summaryPlotCollection()->m_summaryPlots.deleteAllChildObjects();
} }
oilFields.deleteAllChildObjects(); oilFields.deleteAllChildObjects();
@@ -810,10 +806,16 @@ void RimProject::defineUiTreeOrdering(caf::PdmUiTreeOrdering& uiTreeOrdering, QS
{ {
uiTreeOrdering.add(mainPlotCollection->wellLogPlotCollection()); uiTreeOrdering.add(mainPlotCollection->wellLogPlotCollection());
} }
if (mainPlotCollection->summaryPlotCollection()) if (mainPlotCollection->summaryPlotCollection())
{ {
uiTreeOrdering.add(mainPlotCollection->summaryPlotCollection()); uiTreeOrdering.add(mainPlotCollection->summaryPlotCollection());
} }
if (mainPlotCollection->flowPlotCollection())
{
uiTreeOrdering.add(mainPlotCollection->flowPlotCollection());
}
} }
} }
else else

View File

@@ -23,76 +23,17 @@
#include "RimWellAllocationPlot.h" #include "RimWellAllocationPlot.h"
#include "RiuMainPlotWindow.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_marker.h"
#include "qwt_plot_panner.h"
#include "qwt_plot_picker.h"
#include "qwt_plot_zoomer.h"
#include "qwt_scale_engine.h"
#include "qwt_symbol.h"
#include <QEvent>
#include <QWheelEvent>
#include <float.h>
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
/// ///
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
RiuWellAllocationPlot::RiuWellAllocationPlot(RimWellAllocationPlot* plotDefinition, QWidget* parent) : QwtPlot(parent) RiuWellAllocationPlot::RiuWellAllocationPlot(RimWellAllocationPlot* plotDefinition, QWidget* parent)
: QwtPlot(parent)
{ {
Q_ASSERT(plotDefinition); Q_ASSERT(plotDefinition);
m_plotDefinition = plotDefinition; m_plotDefinition = plotDefinition;
m_grid = new QwtPlotGrid;
m_grid->attach(this);
setDefaults();
// LeftButton for the zooming
m_zoomerLeft = new QwtPlotZoomer(canvas());
m_zoomerLeft->setRubberBandPen(QColor(Qt::black));
m_zoomerLeft->setTrackerMode(QwtPicker::AlwaysOff);
m_zoomerLeft->setTrackerPen(QColor(Qt::black));
m_zoomerLeft->initMousePattern(1);
// MidButton for the panning
QwtPlotPanner* panner = new QwtPlotPanner(canvas());
panner->setMouseButton(Qt::MidButton);
connect(m_zoomerLeft, SIGNAL(zoomed(const QRectF &)), SLOT(onZoomedSlot()));
connect(panner, SIGNAL(panned(int, int)), SLOT(onZoomedSlot()));
// Attach a zoomer for the right axis
m_zoomerRight = new QwtPlotZoomer(canvas());
m_zoomerRight->setAxis(xTop, yRight);
m_zoomerRight->setTrackerMode(QwtPicker::AlwaysOff);
m_zoomerRight->initMousePattern(1);
RiuQwtScalePicker* scalePicker = new RiuQwtScalePicker(this);
connect(scalePicker, SIGNAL(clicked(int, double)), this, SLOT(onAxisClicked(int, double)));
// Create a plot picker to display values next to mouse cursor
// m_plotPicker = new RiuQwtPlotPicker(this->canvas());
// m_plotPicker->setTrackerMode(QwtPicker::AlwaysOn);
//
// m_plotMarker = new QwtPlotMarker;
//
// // QwtPlotMarker takes ownership of the symbol, it is deleted in destructor of QwtPlotMarker
// QwtSymbol* mySymbol = new QwtSymbol(QwtSymbol::Ellipse, Qt::NoBrush, QPen(Qt::black, 2.0), QSize(12, 12));
// m_plotMarker->setSymbol(mySymbol);
} }
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
@@ -100,16 +41,10 @@ RiuWellAllocationPlot::RiuWellAllocationPlot(RimWellAllocationPlot* plotDefiniti
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
RiuWellAllocationPlot::~RiuWellAllocationPlot() RiuWellAllocationPlot::~RiuWellAllocationPlot()
{ {
m_grid->detach();
delete m_grid;
if (m_plotDefinition) if (m_plotDefinition)
{ {
m_plotDefinition->handleViewerDeletion(); m_plotDefinition->handleViewerDeletion();
} }
// m_plotMarker->detach();
// delete m_plotMarker;
} }
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
@@ -120,42 +55,6 @@ RimWellAllocationPlot* RiuWellAllocationPlot::ownerPlotDefinition()
return m_plotDefinition; return m_plotDefinition;
} }
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RiuWellAllocationPlot::currentVisibleWindow(QwtInterval* leftAxis, QwtInterval* rightAxis, QwtInterval* timeAxis) const
{
*leftAxis = axisScaleDiv(yLeft).interval();
*rightAxis = axisScaleDiv(yRight).interval();
*timeAxis = axisScaleDiv(xBottom).interval();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RiuWellAllocationPlot::setZoomWindow(const QwtInterval& leftAxis, const QwtInterval& rightAxis, const QwtInterval& timeAxis)
{
{
QRectF zoomWindow;
zoomWindow.setLeft(timeAxis.minValue());
zoomWindow.setRight(timeAxis.maxValue());
zoomWindow.setTop(leftAxis.maxValue());
zoomWindow.setBottom(leftAxis.minValue());
m_zoomerLeft->zoom(zoomWindow);
}
{
QRectF zoomWindow;
zoomWindow.setLeft(timeAxis.minValue());
zoomWindow.setRight(timeAxis.maxValue());
zoomWindow.setTop(rightAxis.maxValue());
zoomWindow.setBottom(rightAxis.minValue());
m_zoomerRight->zoom(zoomWindow);
}
}
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
/// ///
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
@@ -172,272 +71,10 @@ QSize RiuWellAllocationPlot::sizeHint() const
return QSize(0, 0); return QSize(0, 0);
} }
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
QPointF RiuWellAllocationPlot::closestCurvePoint(const QPoint& cursorPosition, QString* valueString, QString* timeString, int* yAxis) const
{
QPointF samplePoint;
QwtPlotCurve* closestCurve = nullptr;
double distMin = DBL_MAX;
int closestPointSampleIndex = -1;
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;
int candidateSampleIndex = candidateCurve->closestPoint(cursorPosition, &dist);
if (dist < distMin)
{
closestCurve = candidateCurve;
distMin = dist;
closestPointSampleIndex = candidateSampleIndex;
}
}
}
if (closestCurve && distMin < 50)
{
samplePoint = closestCurve->sample(closestPointSampleIndex);
if (yAxis) *yAxis = closestCurve->yAxis();
}
if (timeString)
{
const QwtScaleDraw* timeAxisScaleDraw = axisScaleDraw(QwtPlot::xBottom);
if (timeAxisScaleDraw)
{
*timeString = timeAxisScaleDraw->label(samplePoint.x()).text();
}
}
if (valueString && closestCurve)
{
const QwtScaleDraw* yAxisScaleDraw = axisScaleDraw(closestCurve->yAxis());
if (yAxisScaleDraw)
{
*valueString = yAxisScaleDraw->label(samplePoint.y()).text();
}
}
return samplePoint;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RiuWellAllocationPlot::updateClosestCurvePointMarker(const QPointF& closestPoint, int yAxis)
{
// bool replotRequired = false;
//
// if (!closestPoint.isNull())
// {
// if (!m_plotMarker->plot())
// {
// m_plotMarker->attach(this);
//
// replotRequired = true;
// }
//
// if (m_plotMarker->value() != closestPoint)
// {
// m_plotMarker->setValue(closestPoint.x(), closestPoint.y());
//
// // Set y-axis to be able to support more than one y-axis. Default y-axis is left axis.
// // TODO : Should use a color or other visual indicator to show what axis the curve relates to
// m_plotMarker->setYAxis(yAxis);
//
// replotRequired = true;
// }
// }
// else
// {
// if (m_plotMarker->plot())
// {
// m_plotMarker->detach();
//
// replotRequired = true;
// }
// }
//
// if (replotRequired) this->replot();
}
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
/// ///
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
void RiuWellAllocationPlot::setDefaults() void RiuWellAllocationPlot::setDefaults()
{ {
QPalette newPalette(palette());
newPalette.setColor(QPalette::Background, Qt::white);
setPalette(newPalette);
setAutoFillBackground(true);
setCanvasBackground(Qt::white);
QFrame* canvasFrame = dynamic_cast<QFrame*>(canvas());
if (canvasFrame)
{
canvasFrame->setFrameShape(QFrame::NoFrame);
}
canvas()->setMouseTracking(true);
canvas()->installEventFilter(this);
QPen gridPen(Qt::SolidLine);
gridPen.setColor(Qt::lightGray);
m_grid->setPen(gridPen);
enableAxis(QwtPlot::xBottom, true);
enableAxis(QwtPlot::yLeft, true);
enableAxis(QwtPlot::xTop, false);
enableAxis(QwtPlot::yRight, false);
plotLayout()->setAlignCanvasToScales(true);
useDateBasedTimeAxis();
QFont xAxisFont = axisFont(QwtPlot::xBottom);
xAxisFont.setPixelSize(11);
setAxisFont(QwtPlot::xBottom, xAxisFont);
setAxisMaxMinor(QwtPlot::xBottom, 2);
QFont yAxisFont = axisFont(QwtPlot::yLeft);
yAxisFont.setPixelSize(11);
setAxisFont(QwtPlot::yLeft, yAxisFont);
setAxisMaxMinor(QwtPlot::yLeft, 3);
QwtText axisTitleY = axisTitle(QwtPlot::yLeft);
QFont yAxisTitleFont = axisTitleY.font();
yAxisTitleFont.setPixelSize(11);
yAxisTitleFont.setBold(false);
axisTitleY.setFont(yAxisTitleFont);
axisTitleY.setRenderFlags(Qt::AlignRight);
setAxisTitle(QwtPlot::yLeft, axisTitleY);
QwtLegend* legend = new QwtLegend(this);
// The legend will be deleted in the destructor of the plot or when
// another legend is inserted.
this->insertLegend(legend, BottomLegend);
} }
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RiuWellAllocationPlot::useDateBasedTimeAxis()
{
QwtDateScaleDraw* scaleDraw = new QwtDateScaleDraw(Qt::UTC);
scaleDraw->setDateFormat(QwtDate::Year, QString("dd-MM-yyyy"));
QwtDateScaleEngine* scaleEngine = new QwtDateScaleEngine(Qt::UTC);
setAxisScaleEngine(QwtPlot::xBottom, scaleEngine);
setAxisScaleDraw(QwtPlot::xBottom, scaleDraw);
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RiuWellAllocationPlot::useTimeBasedTimeAxis()
{
setAxisScaleEngine(QwtPlot::xBottom, new QwtLinearScaleEngine());
setAxisScaleDraw(QwtPlot::xBottom, new QwtScaleDraw());
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool RiuWellAllocationPlot::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 RiuWellAllocationPlot::leaveEvent(QEvent *)
{
// if (m_plotMarker->plot())
// {
// m_plotMarker->detach();
//
// replot();
// }
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RiuWellAllocationPlot::selectClosestCurve(const QPoint& pos)
{
// QwtPlotCurve* closestCurve = NULL;
// 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)
// {
// RimSummaryCurve* selectedCurve = m_plotDefinition->findRimCurveFromQwtCurve(closestCurve);
// if (selectedCurve)
// {
// RiaApplication::instance()->getOrCreateAndShowMainPlotWindow()->selectAsCurrentItem(selectedCurve);
// }
// }
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RiuWellAllocationPlot::onZoomedSlot()
{
QwtInterval left, right, time;
currentVisibleWindow(&left, &right, &time);
this->setZoomWindow(left, right, time);
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RiuWellAllocationPlot::onAxisClicked(int axis, double value)
{
if (!m_plotDefinition) return;
// m_plotDefinition->selectAxisInPropertyEditor(axis);
}

View File

@@ -19,16 +19,11 @@
#pragma once #pragma once
#include "qwt_plot.h" #include "qwt_plot.h"
#include "cafPdmPointer.h" #include "cafPdmPointer.h"
#include <QPointer> #include <QPointer>
class QwtPlotCurve;
class QwtPlotGrid;
class QwtPlotZoomer;
class QwtInterval;
class QwtPicker;
class QwtPlotMarker;
class RimWellAllocationPlot; class RimWellAllocationPlot;
@@ -46,45 +41,14 @@ public:
RimWellAllocationPlot* ownerPlotDefinition(); RimWellAllocationPlot* ownerPlotDefinition();
void useDateBasedTimeAxis();
void useTimeBasedTimeAxis();
void currentVisibleWindow(QwtInterval* leftAxis,
QwtInterval* rightAxis,
QwtInterval* timeAxis) const;
void setZoomWindow(const QwtInterval& leftAxis,
const QwtInterval& rightAxis,
const QwtInterval& timeAxis);
protected: protected:
virtual bool eventFilter(QObject* watched, QEvent* event) override;
virtual void leaveEvent(QEvent *) override;
virtual QSize sizeHint() const override; virtual QSize sizeHint() const override;
virtual QSize minimumSizeHint() const override; virtual QSize minimumSizeHint() const override;
private: private:
friend class RiuQwtPlotPicker;
QPointF closestCurvePoint(const QPoint& pos, QString* valueString, QString* timeString, int* yAxis) const;
void updateClosestCurvePointMarker(const QPointF& pos, int yAxis);
void setDefaults(); void setDefaults();
void selectClosestCurve(const QPoint& pos);
void showToolTip(const QPoint& pos);
private slots:
void onZoomedSlot();
void onAxisClicked(int axis, double value);
private: private:
QwtPlotGrid* m_grid;
// QwtPicker* m_plotPicker;
// QwtPlotMarker* m_plotMarker;
caf::PdmPointer<RimWellAllocationPlot> m_plotDefinition; caf::PdmPointer<RimWellAllocationPlot> m_plotDefinition;
QPointer<QwtPlotZoomer> m_zoomerLeft;
QPointer<QwtPlotZoomer> m_zoomerRight;
}; };