#4130 3D Cross Plot: Improve window management

This commit is contained in:
Gaute Lindkvist
2019-02-21 15:42:28 +01:00
parent 7e57ec39ea
commit 760fcaef43
6 changed files with 218 additions and 42 deletions

View File

@@ -17,6 +17,7 @@
/////////////////////////////////////////////////////////////////////////////////
#include "RimGridCrossPlot.h"
#include "RiuGridCrossQwtPlot.h"
#include "RiuQwtPlotTools.h"
#include "RimGridCrossPlotCurveSet.h"
@@ -53,6 +54,15 @@ RimGridCrossPlot::RimGridCrossPlot()
createCurveSet();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RimGridCrossPlot::~RimGridCrossPlot()
{
removeMdiWindowFromMdiArea();
deleteViewWidget();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
@@ -172,7 +182,13 @@ QWidget* RimGridCrossPlot::createViewWidget(QWidget* mainWindowParent)
{
if (!m_qwtPlot)
{
m_qwtPlot = new QwtPlot(QString("Grid Cross Plot"), mainWindowParent);
m_qwtPlot = new RiuGridCrossQwtPlot(this, mainWindowParent);
for (auto curveSet : m_crossPlotCurveSets)
{
curveSet->setParentQwtPlotNoReplot(m_qwtPlot);
}
m_qwtPlot->replot();
}
return m_qwtPlot;
@@ -183,6 +199,7 @@ QWidget* RimGridCrossPlot::createViewWidget(QWidget* mainWindowParent)
//--------------------------------------------------------------------------------------------------
void RimGridCrossPlot::deleteViewWidget()
{
detachAllCurves();
if (m_qwtPlot)
{
m_qwtPlot->deleteLater();
@@ -196,41 +213,17 @@ void RimGridCrossPlot::deleteViewWidget()
void RimGridCrossPlot::onLoadDataAndUpdate()
{
updateMdiWindowVisibility();
CVF_ASSERT(m_qwtPlot);
for (auto curveSet : m_crossPlotCurveSets)
{
curveSet->loadDataAndUpdate(false);
curveSet->setParentQwtPlotNoReplot(m_qwtPlot);
}
performAutoNameUpdate();
updateAllRequiredEditors();
updatePlot();
m_qwtPlot->setAxisAutoScale(QwtPlot::xBottom);
m_qwtPlot->setAxisAutoScale(QwtPlot::yLeft);
m_qwtPlot->setAxisTitle(QwtPlot::xBottom, QwtText(xAxisParameterString()));
m_qwtPlot->setAxisTitle(QwtPlot::yLeft, QwtText(yAxisParameterString()));
RiuQwtPlotTools::setCommonPlotBehaviour(m_qwtPlot);
RiuQwtPlotTools::setDefaultAxes(m_qwtPlot);
if (m_showLegend())
{
// Will be released in plot destructor or when a new legend is set
QwtLegend* legend = new QwtLegend(m_qwtPlot);
auto font = legend->font();
font.setPixelSize(m_legendFontSize());
legend->setFont(font);
m_qwtPlot->insertLegend(legend, QwtPlot::BottomLegend);
}
else
{
m_qwtPlot->insertLegend(nullptr);
}
m_qwtPlot->replot();
m_qwtPlot->show();
this->updateAllRequiredEditors();
}
//--------------------------------------------------------------------------------------------------
@@ -299,6 +292,44 @@ void RimGridCrossPlot::performAutoNameUpdate()
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimGridCrossPlot::updatePlot()
{
if (m_qwtPlot)
{
m_qwtPlot->setAxisAutoScale(QwtPlot::xBottom);
m_qwtPlot->setAxisAutoScale(QwtPlot::yLeft);
m_qwtPlot->setAxisTitle(QwtPlot::xBottom, QwtText(xAxisParameterString()));
m_qwtPlot->setAxisTitle(QwtPlot::yLeft, QwtText(yAxisParameterString()));
RiuQwtPlotTools::setCommonPlotBehaviour(m_qwtPlot);
RiuQwtPlotTools::setDefaultAxes(m_qwtPlot);
for (auto curveSet : m_crossPlotCurveSets)
{
curveSet->setParentQwtPlotNoReplot(m_qwtPlot);
}
if (m_showLegend())
{
// Will be released in plot destructor or when a new legend is set
QwtLegend* legend = new QwtLegend(m_qwtPlot);
auto font = legend->font();
font.setPixelSize(m_legendFontSize());
legend->setFont(font);
m_qwtPlot->insertLegend(legend, QwtPlot::BottomLegend);
}
else
{
m_qwtPlot->insertLegend(nullptr);
}
m_qwtPlot->replot();
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
@@ -341,6 +372,17 @@ QString RimGridCrossPlot::yAxisParameterString() const
return yAxisParams.join(", ");
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimGridCrossPlot::detachAllCurves()
{
for (auto curveSet : m_crossPlotCurveSets())
{
curveSet->detachAllCurves();
}
}
//--------------------------------------------------------------------------------------------------
/// Name Configuration
///

View File

@@ -27,7 +27,7 @@
#include <QPointer>
class RimGridCrossPlotCurveSet;
class QwtPlot;
class RiuGridCrossQwtPlot;
class RimGridCrossPlotNameConfig : public RimNameConfig
{
@@ -47,7 +47,7 @@ class RimGridCrossPlot : public RimViewWindow, public RimNameConfigHolderInterfa
CAF_PDM_HEADER_INIT;
public:
RimGridCrossPlot();
~RimGridCrossPlot() = default;
~RimGridCrossPlot();
RimGridCrossPlotCurveSet* createCurveSet();
int indexOfCurveSet(const RimGridCrossPlotCurveSet* curveSet) const;
@@ -60,6 +60,7 @@ public:
QString createAutoName() const override;
caf::PdmFieldHandle* userDescriptionField() override;
void detachAllCurves();
protected:
QWidget* createViewWidget(QWidget* mainWindowParent) override;
@@ -71,7 +72,7 @@ protected:
bool* useOptionsOnly) override;
void performAutoNameUpdate() override;
void updatePlot();
QString xAxisParameterString() const;
QString yAxisParameterString() const;
@@ -82,7 +83,8 @@ private:
caf::PdmChildArrayField<RimGridCrossPlotCurveSet*> m_crossPlotCurveSets;
QPointer<QwtPlot> m_qwtPlot;
QPointer<RiuGridCrossQwtPlot> m_qwtPlot;
};

View File

@@ -512,18 +512,21 @@ void RimPlotCurve::updateCurveAppearance()
// Make sure the legend lines are long enough to distinguish between line types.
// Standard width in Qwt is 8 which is too short.
// Use 10 and scale this by curve thickness + add space for displaying symbol.
QSize legendIconSize = m_qwtPlotCurve->legendIconSize();
int symbolWidth = 0;
if (symbol)
if (m_curveThickness() > 0)
{
symbolWidth = symbol->boundingRect().size().width() + 2;
}
QSize legendIconSize = m_qwtPlotCurve->legendIconSize();
int width = std::max(10 * m_curveThickness, (symbolWidth * 3) / 2);
legendIconSize.setWidth(width);
m_qwtPlotCurve->setLegendIconSize(legendIconSize);
int symbolWidth = 0;
if (symbol)
{
symbolWidth = symbol->boundingRect().size().width() + 2;
}
int width = std::max(10 * m_curveThickness, (symbolWidth * 3) / 2);
legendIconSize.setWidth(width);
m_qwtPlotCurve->setLegendIconSize(legendIconSize);
}
}
//--------------------------------------------------------------------------------------------------

View File

@@ -36,6 +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}/RiuSummaryQwtPlot.h
${CMAKE_CURRENT_LIST_DIR}/RiuTextDialog.h
${CMAKE_CURRENT_LIST_DIR}/RiuTimeStepChangedHandler.h
@@ -116,6 +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}/RiuSummaryQwtPlot.cpp
${CMAKE_CURRENT_LIST_DIR}/RiuTextDialog.cpp
${CMAKE_CURRENT_LIST_DIR}/RiuTimeStepChangedHandler.cpp
@@ -182,6 +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}/RiuSummaryQwtPlot.h
${CMAKE_CURRENT_LIST_DIR}/RiuTofAccumulatedPhaseFractionsPlot.h
${CMAKE_CURRENT_LIST_DIR}/RiuQwtScalePicker.h

View File

@@ -0,0 +1,73 @@
/////////////////////////////////////////////////////////////////////////////////
//
// 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

@@ -0,0 +1,53 @@
/////////////////////////////////////////////////////////////////////////////////
//
// 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;
};