diff --git a/ApplicationCode/CMakeLists.txt b/ApplicationCode/CMakeLists.txt index 7b9433a062..bba86d77ae 100644 --- a/ApplicationCode/CMakeLists.txt +++ b/ApplicationCode/CMakeLists.txt @@ -91,6 +91,8 @@ set( USER_INTERFACE_FILES UserInterface/RiuProjectPropertyView.cpp UserInterface/RiuResultQwtPlot.h UserInterface/RiuResultQwtPlot.cpp + UserInterface/RiuSummaryQwtPlot.h + UserInterface/RiuSummaryQwtPlot.cpp UserInterface/RiuSelectionManager.h UserInterface/RiuSelectionManager.cpp UserInterface/RiuSelectionColors.h diff --git a/ApplicationCode/ProjectDataModel/RimEclipseView.cpp b/ApplicationCode/ProjectDataModel/RimEclipseView.cpp index c3cd15b896..dd5e600cfe 100644 --- a/ApplicationCode/ProjectDataModel/RimEclipseView.cpp +++ b/ApplicationCode/ProjectDataModel/RimEclipseView.cpp @@ -210,7 +210,7 @@ void RimEclipseView::fieldChangedByUi(const caf::PdmFieldHandle* changedField, c { if (m_viewer) { - windowGeometry = RiuMainWindow::instance()->windowGeometryForViewer(m_viewer->layoutWidget()); + this->setMdiWindowGeometry( RiuMainWindow::instance()->windowGeometryForViewer(m_viewer->layoutWidget())); RiuMainWindow::instance()->removeViewer(m_viewer->layoutWidget()); delete m_viewer; diff --git a/ApplicationCode/ProjectDataModel/RimGeoMechView.cpp b/ApplicationCode/ProjectDataModel/RimGeoMechView.cpp index d3aaf1366a..5a8f529710 100644 --- a/ApplicationCode/ProjectDataModel/RimGeoMechView.cpp +++ b/ApplicationCode/ProjectDataModel/RimGeoMechView.cpp @@ -500,7 +500,7 @@ void RimGeoMechView::fieldChangedByUi(const caf::PdmFieldHandle* changedField, c { if (m_viewer) { - windowGeometry = RiuMainWindow::instance()->windowGeometryForViewer(m_viewer->layoutWidget()); + this->setMdiWindowGeometry( RiuMainWindow::instance()->windowGeometryForViewer(m_viewer->layoutWidget())); RiuMainWindow::instance()->removeViewer(m_viewer->layoutWidget()); delete m_viewer; diff --git a/ApplicationCode/ProjectDataModel/RimSummaryCurve.cpp b/ApplicationCode/ProjectDataModel/RimSummaryCurve.cpp index 15dc4c013c..29eba5448f 100644 --- a/ApplicationCode/ProjectDataModel/RimSummaryCurve.cpp +++ b/ApplicationCode/ProjectDataModel/RimSummaryCurve.cpp @@ -25,7 +25,7 @@ #include "RimProject.h" #include "RimSummaryPlot.h" #include "RimSummaryPlotCollection.h" -#include "RiuResultQwtPlot.h" +#include "RiuSummaryQwtPlot.h" #include "cafPdmUiComboBoxEditor.h" #include "cafPdmUiListEditor.h" diff --git a/ApplicationCode/ProjectDataModel/RimSummaryPlot.cpp b/ApplicationCode/ProjectDataModel/RimSummaryPlot.cpp index a1e2b88ae3..b271fb65a0 100644 --- a/ApplicationCode/ProjectDataModel/RimSummaryPlot.cpp +++ b/ApplicationCode/ProjectDataModel/RimSummaryPlot.cpp @@ -21,7 +21,7 @@ #include "RimSummaryCurve.h" #include "RimSummaryPlotCollection.h" -#include "RiuResultQwtPlot.h" +#include "RiuSummaryQwtPlot.h" #include "RiuSelectionColors.h" #include "cvfBase.h" @@ -31,14 +31,14 @@ #include "RiuMainWindow.h" -CAF_PDM_SOURCE_INIT(RimSummaryPlot, "GraphPlot"); +CAF_PDM_SOURCE_INIT(RimSummaryPlot, "SummaryPlot"); //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- RimSummaryPlot::RimSummaryPlot() { - CAF_PDM_InitObject("Graph", ":/WellLogPlot16x16.png", "", ""); + CAF_PDM_InitObject("Summary Plot", ":/WellLogPlot16x16.png", "", ""); CAF_PDM_InitField(&m_showWindow, "ShowWindow", true, "Show Summary Plot", "", "", ""); m_showWindow.uiCapability()->setUiHidden(true); @@ -53,6 +53,8 @@ RimSummaryPlot::RimSummaryPlot() //-------------------------------------------------------------------------------------------------- RimSummaryPlot::~RimSummaryPlot() { + RiuMainWindow::instance()->removeViewer(m_qwtPlot); + deletePlotWidget(); m_curves.deleteAllChildObjects(); @@ -70,12 +72,21 @@ void RimSummaryPlot::deletePlotWidget() } } + //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- -RiuResultQwtPlot* RimSummaryPlot::viewer() +void RimSummaryPlot::handleViewerDeletion() { - return m_qwtPlot; + m_showWindow = false; + + if (m_qwtPlot) + { + detachAllCurves(); + } + + uiCapability()->updateUiIconFromToggleField(); + updateConnectedEditors(); } //-------------------------------------------------------------------------------------------------- @@ -113,6 +124,17 @@ void RimSummaryPlot::fieldChangedByUi(const caf::PdmFieldHandle* changedField, c } } +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RimSummaryPlot::setupBeforeSave() +{ + if (m_qwtPlot) + { + this->setMdiWindowGeometry(RiuMainWindow::instance()->windowGeometryForViewer(m_qwtPlot)); + } +} + //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- @@ -147,14 +169,14 @@ void RimSummaryPlot::updateViewerWidget() { if (!m_qwtPlot) { - m_qwtPlot = new RiuResultQwtPlot(RiuMainWindow::instance()); + m_qwtPlot = new RiuSummaryQwtPlot(this, RiuMainWindow::instance()); for (size_t cIdx = 0; cIdx < m_curves.size(); ++cIdx ) { m_curves[cIdx]->setParentQwtPlot(m_qwtPlot); } - RiuMainWindow::instance()->addViewer(m_qwtPlot, std::vector()); + RiuMainWindow::instance()->addViewer(m_qwtPlot, this->mdiWindowGeometry()); RiuMainWindow::instance()->setActiveViewer(m_qwtPlot); } @@ -165,14 +187,12 @@ void RimSummaryPlot::updateViewerWidget() { if (m_qwtPlot) { - //windowGeometry = RiuMainWindow::instance()->windowGeometryForViewer(m_viewer); + this->setMdiWindowGeometry( RiuMainWindow::instance()->windowGeometryForViewer(m_qwtPlot)); RiuMainWindow::instance()->removeViewer(m_qwtPlot); detachAllCurves(); - delete m_qwtPlot; - m_qwtPlot = NULL; - + deletePlotWidget(); } } } diff --git a/ApplicationCode/ProjectDataModel/RimSummaryPlot.h b/ApplicationCode/ProjectDataModel/RimSummaryPlot.h index 2699d2ef66..fadcc3e1e9 100644 --- a/ApplicationCode/ProjectDataModel/RimSummaryPlot.h +++ b/ApplicationCode/ProjectDataModel/RimSummaryPlot.h @@ -28,7 +28,7 @@ #include "RimViewWindow.h" -class RiuResultQwtPlot; +class RiuSummaryQwtPlot; class RimSummaryCurve; //================================================================================================== @@ -44,29 +44,25 @@ public: virtual ~RimSummaryPlot(); void setDescription(const QString& description); - void loadDataAndUpdate(); - RiuResultQwtPlot* viewer(); void addCurve(RimSummaryCurve* curve); - - + void loadDataAndUpdate(); + void handleViewerDeletion(); protected: // Overridden PDM methods virtual caf::PdmFieldHandle* objectToggleField() { return &m_showWindow; } 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; private: void updateViewerWidget(); - void detachAllCurves(); - - void deletePlotWidget(); - - caf::PdmChildArrayField m_curves; + void deletePlotWidget(); caf::PdmField m_showWindow; caf::PdmField m_userName; + caf::PdmChildArrayField m_curves; - QPointer m_qwtPlot; + QPointer m_qwtPlot; }; diff --git a/ApplicationCode/ProjectDataModel/RimSummaryPlotCollection.cpp b/ApplicationCode/ProjectDataModel/RimSummaryPlotCollection.cpp index 4f87f6b1cc..c1b323b8f8 100644 --- a/ApplicationCode/ProjectDataModel/RimSummaryPlotCollection.cpp +++ b/ApplicationCode/ProjectDataModel/RimSummaryPlotCollection.cpp @@ -31,7 +31,7 @@ #include "RiuMainWindow.h" -CAF_PDM_SOURCE_INIT(RimSummaryPlotCollection, "RimGraphPlotCollection"); +CAF_PDM_SOURCE_INIT(RimSummaryPlotCollection, "SummaryPlotCollection"); //-------------------------------------------------------------------------------------------------- /// diff --git a/ApplicationCode/ProjectDataModel/RimView.cpp b/ApplicationCode/ProjectDataModel/RimView.cpp index 4249bf4b1f..e4e046c0c7 100644 --- a/ApplicationCode/ProjectDataModel/RimView.cpp +++ b/ApplicationCode/ProjectDataModel/RimView.cpp @@ -109,8 +109,6 @@ RimView::RimView(void) CAF_PDM_InitField(&m_disableLighting, "DisableLighting", false, "Disable Results Lighting", "", "Disable light model for scalar result colors", ""); - CAF_PDM_InitFieldNoDefault(&windowGeometry, "WindowGeometry", "", "", "", ""); - windowGeometry.uiCapability()->setUiHidden(true); CAF_PDM_InitFieldNoDefault(&m_rangeFilterCollection, "RangeFilters", "Range Filters", "", "", ""); m_rangeFilterCollection.uiCapability()->setUiHidden(true); @@ -205,7 +203,7 @@ void RimView::updateViewerWidget() m_viewer = new RiuViewer(glFormat, NULL); m_viewer->setOwnerReservoirView(this); - RiuMainWindow::instance()->addViewer(m_viewer->layoutWidget(), windowGeometry()); + RiuMainWindow::instance()->addViewer(m_viewer->layoutWidget(), mdiWindowGeometry()); m_viewer->setMinNearPlaneDistance(10); this->resetLegendsInViewer(); @@ -341,8 +339,8 @@ void RimView::setupBeforeSave() hasUserRequestedAnimation = m_viewer->isAnimationActive(); // JJS: This is not conceptually correct. The variable is updated as we go, and store the user intentions. But I guess that in practice... cameraPosition = m_viewer->mainCamera()->viewMatrix(); - windowGeometry = RiuMainWindow::instance()->windowGeometryForViewer(m_viewer->layoutWidget()); - } + setMdiWindowGeometry(RiuMainWindow::instance()->windowGeometryForViewer(m_viewer->layoutWidget())); + } } //-------------------------------------------------------------------------------------------------- diff --git a/ApplicationCode/ProjectDataModel/RimView.h b/ApplicationCode/ProjectDataModel/RimView.h index f47cb15fda..3734ef3e9c 100644 --- a/ApplicationCode/ProjectDataModel/RimView.h +++ b/ApplicationCode/ProjectDataModel/RimView.h @@ -93,7 +93,6 @@ public: void setOverrideRangeFilterCollection(RimCellRangeFilterCollection* rfc); void replaceRangeFilterCollectionWithOverride(); - caf::PdmField< std::vector > windowGeometry; caf::PdmChildField crossSectionCollection; diff --git a/ApplicationCode/ProjectDataModel/RimViewWindow.cpp b/ApplicationCode/ProjectDataModel/RimViewWindow.cpp index 5a41e52fbd..e6ad01b047 100644 --- a/ApplicationCode/ProjectDataModel/RimViewWindow.cpp +++ b/ApplicationCode/ProjectDataModel/RimViewWindow.cpp @@ -8,6 +8,8 @@ CAF_PDM_XML_ABSTRACT_SOURCE_INIT(RimViewWindow, "ViewWindow"); // Do not use. Ab //-------------------------------------------------------------------------------------------------- RimViewWindow::RimViewWindow(void) { + CAF_PDM_InitFieldNoDefault(&m_windowGeometry, "WindowGeometry", "", "", "", ""); + m_windowGeometry.uiCapability()->setUiHidden(true); } @@ -27,4 +29,40 @@ void RimViewWindow::setViewWidget(QWidget* viewWidget) m_viewWidget = viewWidget; } +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RimViewWindow::setMdiWindowGeometry(const RimMdiWindowGeometry& windowGeometry) +{ + std::vector geom; + geom.clear(); + if (windowGeometry.isValid()) + { + geom.push_back(windowGeometry.x); + geom.push_back(windowGeometry.y); + geom.push_back(windowGeometry.width); + geom.push_back(windowGeometry.height); + geom.push_back(windowGeometry.isMaximized); + } + m_windowGeometry.setValue(geom); +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +RimMdiWindowGeometry RimViewWindow::mdiWindowGeometry() +{ + + RimMdiWindowGeometry wg; + if (m_windowGeometry.value().size() == 5) + { + wg.x = m_windowGeometry.value()[0]; + wg.y = m_windowGeometry.value()[1]; + wg.width = m_windowGeometry.value()[2]; + wg.height = m_windowGeometry.value()[3]; + wg.isMaximized = m_windowGeometry.value()[4]; + } + + return wg; +} diff --git a/ApplicationCode/ProjectDataModel/RimViewWindow.h b/ApplicationCode/ProjectDataModel/RimViewWindow.h index 5eb2f2ec1f..617fbd54e2 100644 --- a/ApplicationCode/ProjectDataModel/RimViewWindow.h +++ b/ApplicationCode/ProjectDataModel/RimViewWindow.h @@ -22,6 +22,18 @@ #include "cafPdmField.h" #include "QPointer" +struct RimMdiWindowGeometry +{ + RimMdiWindowGeometry() : x(0), y(0), width(-1), height(-1) {} + bool isValid() const { return (width >= 0 && height >= 0);} + + int x; + int y; + int width; + int height; + bool isMaximized; +}; + class RimViewWindow : public caf::PdmObject { CAF_PDM_HEADER_INIT; @@ -29,19 +41,20 @@ public: RimViewWindow(void); virtual ~RimViewWindow(void); + void setMdiWindowGeometry(const RimMdiWindowGeometry& windowGeometry); + RimMdiWindowGeometry mdiWindowGeometry(); protected: - void setViewWidget(QWidget* viewWidget); + void setViewWidget(QWidget* viewWidget); // Possible abilities of this class - //caf::PdmField< std::vector > windowGeometry; //virtual QImage snapshotWindowContent() = 0; //caf::PdmField name; //caf::PdmField showWindow; - private: - QPointer m_viewWidget; + caf::PdmField< std::vector > m_windowGeometry; + QPointer m_viewWidget; }; diff --git a/ApplicationCode/ProjectDataModel/RimWellLogPlot.cpp b/ApplicationCode/ProjectDataModel/RimWellLogPlot.cpp index d0b49819fb..9232f5d72d 100644 --- a/ApplicationCode/ProjectDataModel/RimWellLogPlot.cpp +++ b/ApplicationCode/ProjectDataModel/RimWellLogPlot.cpp @@ -76,9 +76,6 @@ RimWellLogPlot::RimWellLogPlot() CAF_PDM_InitFieldNoDefault(&m_tracks, "Tracks", "", "", "", ""); m_tracks.uiCapability()->setUiHidden(true); - CAF_PDM_InitFieldNoDefault(&windowGeometry, "WindowGeometry", "", "", "", ""); - windowGeometry.uiCapability()->setUiHidden(true); - m_minAvailableDepth = HUGE_VAL; m_maxAvailableDepth = -HUGE_VAL; } @@ -109,7 +106,7 @@ void RimWellLogPlot::updateViewerWidget() recreateTrackPlots(); - RiuMainWindow::instance()->addViewer(m_viewer, windowGeometry()); + RiuMainWindow::instance()->addViewer(m_viewer, this->mdiWindowGeometry()); RiuMainWindow::instance()->setActiveViewer(m_viewer); } @@ -119,7 +116,7 @@ void RimWellLogPlot::updateViewerWidget() { if (m_viewer) { - windowGeometry = RiuMainWindow::instance()->windowGeometryForViewer(m_viewer); + this->setMdiWindowGeometry( RiuMainWindow::instance()->windowGeometryForViewer(m_viewer)); RiuMainWindow::instance()->removeViewer(m_viewer); detachAllCurves(); @@ -368,7 +365,7 @@ void RimWellLogPlot::setupBeforeSave() { if (m_viewer) { - windowGeometry = RiuMainWindow::instance()->windowGeometryForViewer(m_viewer); + this->setMdiWindowGeometry( RiuMainWindow::instance()->windowGeometryForViewer(m_viewer)); } } diff --git a/ApplicationCode/ProjectDataModel/RimWellLogPlot.h b/ApplicationCode/ProjectDataModel/RimWellLogPlot.h index 5fe4f83a85..29e6339d97 100644 --- a/ApplicationCode/ProjectDataModel/RimWellLogPlot.h +++ b/ApplicationCode/ProjectDataModel/RimWellLogPlot.h @@ -61,8 +61,6 @@ public: QString depthPlotTitle() const; - caf::PdmField< std::vector > windowGeometry; - void addTrack(RimWellLogTrack* track); void insertTrack(RimWellLogTrack* track, size_t index); size_t trackCount() { return m_tracks.size();} diff --git a/ApplicationCode/UserInterface/RiuMainWindow.cpp b/ApplicationCode/UserInterface/RiuMainWindow.cpp index cc6283c46b..5d6f44af6c 100644 --- a/ApplicationCode/UserInterface/RiuMainWindow.cpp +++ b/ApplicationCode/UserInterface/RiuMainWindow.cpp @@ -49,8 +49,10 @@ #include "RimReservoirCellResultsStorage.h" #include "RimTools.h" #include "RimTreeViewStateSerializer.h" +#include "RimViewWindow.h" #include "RimWellLogPlot.h" #include "RimWellLogPlotCollection.h" +#include "RimSummaryPlot.h" #include "RimWellPathImport.h" #include "RiuDragDrop.h" @@ -59,6 +61,7 @@ #include "RiuProjectPropertyView.h" #include "RiuResultInfoPanel.h" #include "RiuResultQwtPlot.h" +#include "RiuSummaryQwtPlot.h" #include "RiuTreeViewEventFilter.h" #include "RiuViewer.h" #include "RiuWellImportWizard.h" @@ -1216,16 +1219,21 @@ protected: QWidget* mainWidget = widget(); RiuWellLogPlot* wellLogPlot = dynamic_cast(mainWidget); + RiuSummaryQwtPlot* summaryPlot = dynamic_cast(mainWidget); if (wellLogPlot) { - wellLogPlot->ownerPlotDefinition()->windowGeometry = RiuMainWindow::instance()->windowGeometryForWidget(this); + wellLogPlot->ownerPlotDefinition()->setMdiWindowGeometry(RiuMainWindow::instance()->windowGeometryForWidget(this)); + } + else if (summaryPlot) + { + summaryPlot->ownerPlotDefinition()->setMdiWindowGeometry(RiuMainWindow::instance()->windowGeometryForWidget(this)); } else { RiuViewer* viewer = mainWidget->findChild(); if (viewer) { - viewer->ownerReservoirView()->windowGeometry = RiuMainWindow::instance()->windowGeometryForWidget(this); + viewer->ownerReservoirView()->setMdiWindowGeometry(RiuMainWindow::instance()->windowGeometryForWidget(this)); } } @@ -1236,7 +1244,7 @@ protected: //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- -void RiuMainWindow::addViewer(QWidget* viewer, const std::vector& windowsGeometry) +void RiuMainWindow::addViewer(QWidget* viewer, const RimMdiWindowGeometry& windowsGeometry) { RiuMdiSubWindow* subWin = new RiuMdiSubWindow(m_mdiArea); subWin->setAttribute(Qt::WA_DeleteOnClose); // Make sure the contained widget is destroyed when the MDI window is closed @@ -1246,15 +1254,12 @@ void RiuMainWindow::addViewer(QWidget* viewer, const std::vector& windowsGe QPoint subWindowPos(-1, -1); bool initialStateMaximized = false; - if (windowsGeometry.size() == 5) + if (windowsGeometry.isValid()) { - subWindowPos = QPoint(windowsGeometry[0], windowsGeometry[1]); - subWindowSize = QSize(windowsGeometry[2], windowsGeometry[3]); + subWindowPos = QPoint(windowsGeometry.x, windowsGeometry.y); + subWindowSize = QSize(windowsGeometry.width, windowsGeometry.height); - if (windowsGeometry[4] > 0) - { - initialStateMaximized = true; - } + initialStateMaximized = windowsGeometry.isMaximized; } else { @@ -2214,7 +2219,7 @@ void RiuMainWindow::customMenuRequested(const QPoint& pos) //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- -std::vector RiuMainWindow::windowGeometryForViewer(QWidget* viewer) +RimMdiWindowGeometry RiuMainWindow::windowGeometryForViewer(QWidget* viewer) { QMdiSubWindow* mdiWindow = findMdiSubWindow(viewer); if (mdiWindow) @@ -2222,24 +2227,24 @@ std::vector RiuMainWindow::windowGeometryForViewer(QWidget* viewer) return windowGeometryForWidget(mdiWindow); } - std::vector geo; + RimMdiWindowGeometry geo; return geo; } //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- -std::vector RiuMainWindow::windowGeometryForWidget(QWidget* widget) +RimMdiWindowGeometry RiuMainWindow::windowGeometryForWidget(QWidget* widget) { - std::vector geo; + RimMdiWindowGeometry geo; if (widget) { - geo.push_back(widget->pos().x()); - geo.push_back(widget->pos().y()); - geo.push_back(widget->size().width()); - geo.push_back(widget->size().height()); - geo.push_back(widget->isMaximized()); + geo.x = widget->pos().x(); + geo.y = widget->pos().y(); + geo.width = widget->size().width(); + geo.height = widget->size().height(); + geo.isMaximized = widget->isMaximized(); } return geo; diff --git a/ApplicationCode/UserInterface/RiuMainWindow.h b/ApplicationCode/UserInterface/RiuMainWindow.h index b6dbb8fc6c..dcf6cf0647 100644 --- a/ApplicationCode/UserInterface/RiuMainWindow.h +++ b/ApplicationCode/UserInterface/RiuMainWindow.h @@ -43,6 +43,7 @@ class RiuResultInfoPanel; class RiuViewer; class RiuWellLogPlot; class RiuResultQwtPlot; +struct RimMdiWindowGeometry; namespace caf { @@ -78,7 +79,7 @@ public: void cleanupGuiBeforeProjectClose(); void removeViewer( QWidget* viewer ); - void addViewer(QWidget* viewer, const std::vector& windowsGeometry); + void addViewer(QWidget* viewer, const RimMdiWindowGeometry& windowsGeometry); void setActiveViewer(QWidget* subWindow); void setResultInfo(const QString& info) const; @@ -106,8 +107,8 @@ public: void addRecentFiles(const QString& file); void removeRecentFiles(const QString& file); - std::vector windowGeometryForViewer(QWidget* viewer); - std::vector windowGeometryForWidget(QWidget* widget); + RimMdiWindowGeometry windowGeometryForViewer(QWidget* viewer); + RimMdiWindowGeometry windowGeometryForWidget(QWidget* widget); void tileWindows(); bool isAnyMdiSubWindowVisible(); diff --git a/ApplicationCode/UserInterface/RiuSummaryQwtPlot.cpp b/ApplicationCode/UserInterface/RiuSummaryQwtPlot.cpp new file mode 100644 index 0000000000..bc65460c82 --- /dev/null +++ b/ApplicationCode/UserInterface/RiuSummaryQwtPlot.cpp @@ -0,0 +1,126 @@ +///////////////////////////////////////////////////////////////////////////////// +// +// 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 +// for more details. +// +///////////////////////////////////////////////////////////////////////////////// + +#include "RiuSummaryQwtPlot.h" +#include "RimSummaryPlot.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_scale_engine.h" + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +RiuSummaryQwtPlot::RiuSummaryQwtPlot(RimSummaryPlot* plotDefinition, QWidget* parent) : QwtPlot(parent) +{ + Q_ASSERT(plotDefinition); + m_plotDefinition = plotDefinition; + + m_grid = new QwtPlotGrid; + m_grid->attach(this); + + setDefaults(); +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +RiuSummaryQwtPlot::~RiuSummaryQwtPlot() +{ + m_grid->detach(); + delete m_grid; + + if (m_plotDefinition) + { + m_plotDefinition->handleViewerDeletion(); + } +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +RimSummaryPlot* RiuSummaryQwtPlot::ownerPlotDefinition() +{ + return m_plotDefinition; +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RiuSummaryQwtPlot::setDefaults() +{ + QPalette newPalette(palette()); + newPalette.setColor(QPalette::Background, Qt::white); + setPalette(newPalette); + + setAutoFillBackground(true); + setCanvasBackground(Qt::white); + + QFrame* canvasFrame = dynamic_cast(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); + + 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); + + QFont xAxisFont = axisFont(QwtPlot::xBottom); + xAxisFont.setPixelSize(9); + setAxisFont(QwtPlot::xBottom, xAxisFont); + + QFont yAxisFont = axisFont(QwtPlot::yLeft); + yAxisFont.setPixelSize(9); + setAxisFont(QwtPlot::yLeft, yAxisFont); + + QwtText axisTitleY = axisTitle(QwtPlot::yLeft); + QFont yAxisTitleFont = axisTitleY.font(); + yAxisTitleFont.setPixelSize(9); + 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); +} diff --git a/ApplicationCode/UserInterface/RiuSummaryQwtPlot.h b/ApplicationCode/UserInterface/RiuSummaryQwtPlot.h new file mode 100644 index 0000000000..bddd1650ad --- /dev/null +++ b/ApplicationCode/UserInterface/RiuSummaryQwtPlot.h @@ -0,0 +1,51 @@ +///////////////////////////////////////////////////////////////////////////////// +// +// 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 +// for more details. +// +///////////////////////////////////////////////////////////////////////////////// + +#pragma once + +#include "qwt_plot.h" +#include "cafPdmPointer.h" + +class QwtPlotCurve; +class QwtPlotGrid; + +class RimSummaryPlot; + +//================================================================================================== +// +// +// +//================================================================================================== +class RiuSummaryQwtPlot : public QwtPlot +{ +public: + RiuSummaryQwtPlot(RimSummaryPlot* plotDefinition, QWidget* parent = NULL); + virtual ~RiuSummaryQwtPlot(); + + RimSummaryPlot* ownerPlotDefinition(); + +private: + void setDefaults(); + +private: + QwtPlotGrid* m_grid; + caf::PdmPointer m_plotDefinition; +}; + + +