diff --git a/ApplicationCode/ProjectDataModel/GridCrossPlots/RimGridCrossPlotCurveSet.cpp b/ApplicationCode/ProjectDataModel/GridCrossPlots/RimGridCrossPlotCurveSet.cpp index d2426a1b29..6031afcab9 100644 --- a/ApplicationCode/ProjectDataModel/GridCrossPlots/RimGridCrossPlotCurveSet.cpp +++ b/ApplicationCode/ProjectDataModel/GridCrossPlots/RimGridCrossPlotCurveSet.cpp @@ -652,7 +652,7 @@ QList RimGridCrossPlotCurveSet::calculateValueOptions(co else if (fieldNeedingOptions == &m_grouping) { std::set validOptions = { NO_GROUPING, GROUP_BY_TIME, GROUP_BY_FORMATION, GROUP_BY_RESULT }; - if (m_timeStep() != -1 || !(m_xAxisProperty->hasDynamicResult() || m_yAxisProperty->hasDynamicResult())) + if (!hasMultipleTimeSteps()) { validOptions.erase(GROUP_BY_TIME); } @@ -678,6 +678,7 @@ QList RimGridCrossPlotCurveSet::calculateValueOptions(co void RimGridCrossPlotCurveSet::updateLegend() { legendConfig()->setTitle(groupParameter()); + legendConfig()->disableAllTimeStepsRange(!hasMultipleTimeSteps()); RimGridCrossPlot* parent; this->firstAncestorOrThisOfTypeAsserted(parent); @@ -889,6 +890,15 @@ void RimGridCrossPlotCurveSet::defineUiTreeOrdering(caf::PdmUiTreeOrdering& uiTr uiTreeOrdering.skipRemainingChildren(true); } +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +bool RimGridCrossPlotCurveSet::hasMultipleTimeSteps() const +{ + return m_timeStep() == -1 && (m_xAxisProperty->hasDynamicResult() || m_yAxisProperty->hasDynamicResult()); + +} + CAF_PDM_SOURCE_INIT(RimGridCrossPlotCurveSetNameConfig, "RimGridCrossPlotCurveSetNameConfig"); //-------------------------------------------------------------------------------------------------- diff --git a/ApplicationCode/ProjectDataModel/GridCrossPlots/RimGridCrossPlotCurveSet.h b/ApplicationCode/ProjectDataModel/GridCrossPlots/RimGridCrossPlotCurveSet.h index c41ce5cd43..dc99632759 100644 --- a/ApplicationCode/ProjectDataModel/GridCrossPlots/RimGridCrossPlotCurveSet.h +++ b/ApplicationCode/ProjectDataModel/GridCrossPlots/RimGridCrossPlotCurveSet.h @@ -134,6 +134,7 @@ protected: void defineUiTreeOrdering(caf::PdmUiTreeOrdering& uiTreeOrdering, QString uiConfigName = "") override; + bool hasMultipleTimeSteps() const; private: caf::PdmPtrField m_case; caf::PdmField m_timeStep; diff --git a/ApplicationCode/UserInterface/RiuGridCrossQwtPlot.cpp b/ApplicationCode/UserInterface/RiuGridCrossQwtPlot.cpp index f7250912e5..09b0029870 100644 --- a/ApplicationCode/UserInterface/RiuGridCrossQwtPlot.cpp +++ b/ApplicationCode/UserInterface/RiuGridCrossQwtPlot.cpp @@ -26,6 +26,8 @@ #include "cafTitledOverlayFrame.h" +#include + //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- @@ -37,18 +39,18 @@ RiuGridCrossQwtPlot::RiuGridCrossQwtPlot(RimViewWindow* ownerViewWindow, QWidget //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- -void RiuGridCrossQwtPlot::addOrUpdateCurveSetLegend(RimGridCrossPlotCurveSet* curveSetToShowLegendFor) +void RiuGridCrossQwtPlot::addOrUpdateCurveSetLegend(RimGridCrossPlotCurveSet* curveSet) { RiuCvfOverlayItemWidget* overlayWidget = nullptr; - auto it = m_legendWidgets.find(curveSetToShowLegendFor); + auto it = m_legendWidgets.find(curveSet); if (it == m_legendWidgets.end() || it->second == nullptr) { overlayWidget = new RiuCvfOverlayItemWidget(this); new RiuWidgetDragger(overlayWidget); - m_legendWidgets[curveSetToShowLegendFor] = overlayWidget; + m_legendWidgets[curveSet] = overlayWidget; } else { @@ -57,12 +59,11 @@ void RiuGridCrossQwtPlot::addOrUpdateCurveSetLegend(RimGridCrossPlotCurveSet* cu if (overlayWidget) { - caf::TitledOverlayFrame* overlayItem = curveSetToShowLegendFor->legendConfig()->titledOverlayFrame(); - overlayItem->setRenderSize(overlayItem->preferredSize()); + caf::TitledOverlayFrame* overlayItem = curveSet->legendConfig()->titledOverlayFrame(); + resizeOverlayItemToFitPlot(overlayItem); + overlayWidget->updateFromOverlayItem(overlayItem); - overlayWidget->updateFromOverlayItem(curveSetToShowLegendFor->legendConfig()->titledOverlayFrame()); } - this->updateLegendLayout(); } @@ -138,3 +139,64 @@ void RiuGridCrossQwtPlot::updateLegendLayout() } } } + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RiuGridCrossQwtPlot::resizeEvent(QResizeEvent* e) +{ + QwtPlot::resizeEvent(e); + + RimGridCrossPlot* crossPlot = dynamic_cast(ownerPlotDefinition()); + if (!crossPlot) return; + + bool anyLegendResized = false; + + for (RimGridCrossPlotCurveSet* curveSet : crossPlot->curveSets()) + { + if (!curveSet->isChecked() || !curveSet->legendConfig()->showLegend()) continue; + + auto pairIt = m_legendWidgets.find(curveSet); + if (pairIt != m_legendWidgets.end()) + { + RiuCvfOverlayItemWidget* overlayWidget = pairIt->second; + if (overlayWidget->isVisible()) + { + caf::TitledOverlayFrame* overlayItem = curveSet->legendConfig()->titledOverlayFrame(); + if (resizeOverlayItemToFitPlot(overlayItem)) + { + anyLegendResized = true; + overlayWidget->updateFromOverlayItem(overlayItem); + } + } + } + } + if (anyLegendResized) + { + updateLegendLayout(); + } +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +bool RiuGridCrossQwtPlot::resizeOverlayItemToFitPlot(caf::TitledOverlayFrame* overlayItem) +{ + QSize plotSize = this->canvas()->contentsRect().size(); + cvf::Vec2ui legendSize = overlayItem->preferredSize(); + + bool sizeAltered = false; + + if (plotSize.width() > 0 && (double) legendSize.x() > 0.9 * plotSize.width()) + { + legendSize.x() = (plotSize.width() * 9) / 10; + sizeAltered = true; + } + if (plotSize.height() > 0 && (double) legendSize.y() > 0.9 * plotSize.height()) + { + legendSize.y() = (plotSize.height() * 9) / 10; + sizeAltered = true; + } + overlayItem->setRenderSize(legendSize); + return sizeAltered; +} diff --git a/ApplicationCode/UserInterface/RiuGridCrossQwtPlot.h b/ApplicationCode/UserInterface/RiuGridCrossQwtPlot.h index eb9926d37a..1bf75a85fe 100644 --- a/ApplicationCode/UserInterface/RiuGridCrossQwtPlot.h +++ b/ApplicationCode/UserInterface/RiuGridCrossQwtPlot.h @@ -28,6 +28,10 @@ class RimGridCrossPlotCurveSet; class RiuCvfOverlayItemWidget; +namespace caf +{ +class TitledOverlayFrame; +} //================================================================================================== // // @@ -46,7 +50,8 @@ public: protected: void updateLayout() override; void updateLegendLayout(); - + void resizeEvent(QResizeEvent *e) override; + bool resizeOverlayItemToFitPlot(caf::TitledOverlayFrame* overlayItem); private: std::map, QPointer> m_legendWidgets; }; diff --git a/ApplicationCode/UserInterface/RiuQwtSymbol.cpp b/ApplicationCode/UserInterface/RiuQwtSymbol.cpp index b3c14750db..52f8d5eafb 100644 --- a/ApplicationCode/UserInterface/RiuQwtSymbol.cpp +++ b/ApplicationCode/UserInterface/RiuQwtSymbol.cpp @@ -184,7 +184,9 @@ RiuQwtSymbol::PointSymbolEnum RiuQwtSymbol::cycledFilledSymbolStyle(int indexLev { std::vector contrastingSymbols = { - SYMBOL_ELLIPSE, SYMBOL_RECT }; + SYMBOL_ELLIPSE, SYMBOL_RECT, SYMBOL_DIAMOND, SYMBOL_DOWN_TRIANGLE, SYMBOL_UP_TRIANGLE, + SYMBOL_LEFT_TRIANGLE, SYMBOL_RIGHT_TRIANGLE, SYMBOL_STAR2 + }; return contrastingSymbols[indexLevel % (int)contrastingSymbols.size()]; }