mirror of
https://github.com/OPM/ResInsight.git
synced 2025-02-25 18:55:39 -06:00
#4184 Resize legend if it becomes larger than plot area.
This commit is contained in:
parent
804a196ce3
commit
6f1ed595b5
@ -652,7 +652,7 @@ QList<caf::PdmOptionItemInfo> RimGridCrossPlotCurveSet::calculateValueOptions(co
|
||||
else if (fieldNeedingOptions == &m_grouping)
|
||||
{
|
||||
std::set<RigGridCrossPlotCurveGrouping> 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<caf::PdmOptionItemInfo> 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");
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
|
@ -134,6 +134,7 @@ protected:
|
||||
|
||||
void defineUiTreeOrdering(caf::PdmUiTreeOrdering& uiTreeOrdering, QString uiConfigName = "") override;
|
||||
|
||||
bool hasMultipleTimeSteps() const;
|
||||
private:
|
||||
caf::PdmPtrField<RimCase*> m_case;
|
||||
caf::PdmField<int> m_timeStep;
|
||||
|
@ -26,6 +26,8 @@
|
||||
|
||||
#include "cafTitledOverlayFrame.h"
|
||||
|
||||
#include <QResizeEvent>
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
@ -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<RimGridCrossPlot*>(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;
|
||||
}
|
||||
|
@ -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<caf::PdmPointer<RimGridCrossPlotCurveSet>, QPointer<RiuCvfOverlayItemWidget>> m_legendWidgets;
|
||||
};
|
||||
|
@ -184,7 +184,9 @@ RiuQwtSymbol::PointSymbolEnum RiuQwtSymbol::cycledFilledSymbolStyle(int indexLev
|
||||
{
|
||||
std::vector<PointSymbolEnum> 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()];
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user