Wip: Separated cretion of Qwt classes from Rim construction

This needs to be done because MDI window close window deletes the widgets.
We need to be able to recreate all the widgets/qwt objects when needed.
The QwtPlotCurves still crashes on window close/open
This commit is contained in:
Jacob Støren 2015-09-03 14:21:08 +02:00
parent 6a6973f3d4
commit 7b308e514c
5 changed files with 83 additions and 67 deletions

View File

@ -53,9 +53,9 @@ RimWellLogPlot::RimWellLogPlot()
CAF_PDM_InitFieldNoDefault(&windowGeometry, "WindowGeometry", "", "", "", "");
windowGeometry.uiCapability()->setUiHidden(true);
updateViewerWidget();
updateAvailableDepthRange();
m_depthRangeMinimum = HUGE_VAL;
m_depthRangeMaximum = -HUGE_VAL;
}
//--------------------------------------------------------------------------------------------------
@ -74,25 +74,28 @@ void RimWellLogPlot::updateViewerWidget()
{
if (showWindow())
{
bool isViewerCreated = false;
if (!m_viewer)
{
m_viewer = new RiuWellLogPlot(this, RiuMainWindow::instance());
RiuMainWindow::instance()->addViewer(m_viewer, windowGeometry());
isViewerCreated = true;
}
if (m_viewer->parentWidget())
{
m_viewer->parentWidget()->showMaximized();
}
else
{
m_viewer->showMaximized();
recreateTracePlots();
}
RiuMainWindow::instance()->addViewer(m_viewer, windowGeometry());
RiuMainWindow::instance()->setActiveViewer(m_viewer);
updateAxisRanges();
}
else
{
if (m_viewer)
{
windowGeometry = RiuMainWindow::instance()->windowGeometryForViewer(m_viewer);
RiuMainWindow::instance()->removeViewer(m_viewer);
delete m_viewer;
m_viewer = NULL;
}
}
}
@ -103,24 +106,7 @@ void RimWellLogPlot::fieldChangedByUi(const caf::PdmFieldHandle* changedField, c
{
if (changedField == &showWindow)
{
if (newValue == true)
{
updateViewerWidget();
}
else
{
if (m_viewer)
{
if (m_viewer->parentWidget())
{
m_viewer->parentWidget()->hide();
}
else
{
m_viewer->hide();
}
}
}
updateViewerWidget();
}
else if (changedField == &m_minimumVisibleDepth || changedField == &m_maximumVisibleDepth)
{
@ -142,7 +128,11 @@ caf::PdmFieldHandle* RimWellLogPlot::objectToggleField()
void RimWellLogPlot::addTrace(RimWellLogPlotTrace* trace)
{
traces.push_back(trace);
m_viewer->insertTracePlot(trace->viewer());
if(m_viewer)
{
trace->recreateViewer();
m_viewer->insertTracePlot(trace->viewer());
}
}
//--------------------------------------------------------------------------------------------------
@ -187,7 +177,7 @@ void RimWellLogPlot::setDepthRange(double minimumDepth, double maximumDepth)
m_minimumVisibleDepth.uiCapability()->updateConnectedEditors();
m_maximumVisibleDepth.uiCapability()->updateConnectedEditors();
m_viewer->setDepthRange(m_minimumVisibleDepth, m_maximumVisibleDepth);
if(m_viewer) m_viewer->setDepthRange(m_minimumVisibleDepth, m_maximumVisibleDepth);
}
//--------------------------------------------------------------------------------------------------
@ -195,13 +185,13 @@ void RimWellLogPlot::setDepthRange(double minimumDepth, double maximumDepth)
//--------------------------------------------------------------------------------------------------
void RimWellLogPlot::updateAvailableDepthRange()
{
double minDepth = DBL_MAX;
double maxDepth = DBL_MIN;
double minDepth = HUGE_VAL;
double maxDepth = -HUGE_VAL;
for (size_t tIdx = 0; tIdx < traces.size(); tIdx++)
{
double minTraceDepth = DBL_MAX;
double maxTraceDepth = DBL_MIN;
double minTraceDepth = HUGE_VAL;
double maxTraceDepth = -HUGE_VAL;
if (traces[tIdx]->availableDepthRange(&minTraceDepth, &maxTraceDepth))
{
@ -240,29 +230,22 @@ bool RimWellLogPlot::availableDepthRange(double* minimumDepth, double* maximumDe
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimWellLogPlot::visibleDepthRange(double* minimumDepth, double* maximumDepth)
void RimWellLogPlot::visibleDepthRange(double* minimumDepth, double* maximumDepth) const
{
*minimumDepth = m_minimumVisibleDepth;
*maximumDepth = m_maximumVisibleDepth;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimWellLogPlot::initAfterRead()
{
for (size_t tIdx = 0; tIdx < traces.size(); ++tIdx)
{
m_viewer->insertTracePlot(traces[tIdx]->viewer());
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimWellLogPlot::setupBeforeSave()
{
windowGeometry = RiuMainWindow::instance()->windowGeometryForViewer(m_viewer);
if (m_viewer)
{
windowGeometry = RiuMainWindow::instance()->windowGeometryForViewer(m_viewer);
}
}
//--------------------------------------------------------------------------------------------------
@ -270,8 +253,35 @@ void RimWellLogPlot::setupBeforeSave()
//--------------------------------------------------------------------------------------------------
void RimWellLogPlot::loadDataAndUpdate()
{
updateViewerWidget();
for (size_t tIdx = 0; tIdx < traces.size(); ++tIdx)
{
traces[tIdx]->loadDataAndUpdate();
}
updateAvailableDepthRange();
updateAxisRanges();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimWellLogPlot::updateAxisRanges()
{
if (m_viewer) m_viewer->setDepthRange(m_minimumVisibleDepth, m_maximumVisibleDepth);
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimWellLogPlot::recreateTracePlots()
{
CVF_ASSERT(m_viewer);
for (size_t tIdx = 0; tIdx < traces.size(); ++tIdx)
{
traces[tIdx]->recreateViewer();
m_viewer->insertTracePlot(traces[tIdx]->viewer());
}
}

View File

@ -54,17 +54,17 @@ public:
void updateAvailableDepthRange();
bool availableDepthRange(double* minimumDepth, double* maximumDepth);
void visibleDepthRange(double* minimumDepth, double* maximumDepth);
void visibleDepthRange(double* minimumDepth, double* maximumDepth) const;
void updateAxisRanges();
protected:
// Overridden PDM methods
virtual void fieldChangedByUi(const caf::PdmFieldHandle* changedField, const QVariant& oldValue, const QVariant& newValue);
virtual void initAfterRead();
virtual void setupBeforeSave();
private:
void updateViewerWidget();
void recreateTracePlots();
virtual caf::PdmFieldHandle* objectToggleField();

View File

@ -48,8 +48,7 @@ RimWellLogPlotTrace::RimWellLogPlotTrace()
CAF_PDM_InitField(&m_minimumValue, "MinimumValue", -10.0, "Minimum value", "", "", "");
CAF_PDM_InitField(&m_maximumValue, "MaximumValue", 100.0, "Maximum value", "", "", "");
m_viewer = new RiuWellLogTracePlot;
}
//--------------------------------------------------------------------------------------------------
@ -67,7 +66,7 @@ void RimWellLogPlotTrace::fieldChangedByUi(const caf::PdmFieldHandle* changedFie
{
if (changedField == &show)
{
m_viewer->setVisible(show());
if (m_viewer) m_viewer->setVisible(show());
}
else if (changedField == &m_minimumValue || changedField == &m_maximumValue)
{
@ -108,8 +107,8 @@ RiuWellLogTracePlot* RimWellLogPlotTrace::viewer()
//--------------------------------------------------------------------------------------------------
bool RimWellLogPlotTrace::availableDepthRange(double* minimumDepth, double* maximumDepth)
{
double minDepth = DBL_MAX;
double maxDepth = DBL_MIN;
double minDepth = HUGE_VAL;
double maxDepth = -HUGE_VAL;
size_t curveCount = curves.size();
if (curveCount < 1)
@ -121,8 +120,8 @@ bool RimWellLogPlotTrace::availableDepthRange(double* minimumDepth, double* maxi
for (size_t cIdx = 0; cIdx < curveCount; cIdx++)
{
double minCurveDepth = DBL_MAX;
double maxCurveDepth = DBL_MIN;
double minCurveDepth = HUGE_VAL;
double maxCurveDepth = -HUGE_VAL;
if (curves[cIdx]->depthRange(&minCurveDepth, &maxCurveDepth))
{
@ -152,21 +151,26 @@ bool RimWellLogPlotTrace::availableDepthRange(double* minimumDepth, double* maxi
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimWellLogPlotTrace::initAfterRead()
void RimWellLogPlotTrace::loadDataAndUpdate()
{
for(size_t cIdx = 0; cIdx < curves.size(); ++cIdx)
CVF_ASSERT(m_viewer);
for (size_t cIdx = 0; cIdx < curves.size(); ++cIdx)
{
curves[cIdx]->setPlot(this->m_viewer);
curves[cIdx]->updatePlotData();
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimWellLogPlotTrace::loadDataAndUpdate()
void RimWellLogPlotTrace::recreateViewer()
{
CVF_ASSERT(m_viewer == NULL);
m_viewer = new RiuWellLogTracePlot;
for (size_t cIdx = 0; cIdx < curves.size(); ++cIdx)
{
curves[cIdx]->updatePlotData();
curves[cIdx]->setPlot(this->m_viewer);
}
}

View File

@ -44,6 +44,7 @@ public:
void addCurve(RimWellLogPlotCurve* curve);
size_t curveCount() { return curves.size(); }
void recreateViewer();
void loadDataAndUpdate();
bool availableDepthRange(double* minimumDepth, double* maximumDepth);
@ -54,7 +55,6 @@ protected:
// Overridden PDM methods
virtual void fieldChangedByUi(const caf::PdmFieldHandle* changedField, const QVariant& oldValue, const QVariant& newValue);
virtual void initAfterRead();
virtual caf::PdmFieldHandle* objectToggleField();
private:

View File

@ -84,6 +84,8 @@ void RiuWellLogTracePlot::setDefaults()
axisScaleEngine(QwtPlot::yLeft)->setAttribute(QwtScaleEngine::Floating, true);
setAxisScale(QwtPlot::yLeft, 1000, 0);
setAxisScale(QwtPlot::xTop, -10, 100);
setAxisAutoScale(QwtPlot::xTop, true);
}
//--------------------------------------------------------------------------------------------------