mirror of
https://github.com/OPM/ResInsight.git
synced 2026-10-13 08:52:14 -05:00
#4243 Grid Cross Plot: Make legend icons black & white when grouping is enabled and set size from font size
This commit is contained in:
1 parent
ee5935aad6
commit
75b0905e26
10 files changed
+113
-6
No files matched your search
@@ -2,6 +2,9 @@
|
|||||||
|
|
||||||
#include "cvfAssert.h"
|
#include "cvfAssert.h"
|
||||||
|
|
||||||
|
#include <QColor>
|
||||||
|
#include <QImage>
|
||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <limits>
|
#include <limits>
|
||||||
|
|
||||||
@@ -113,4 +116,21 @@ void RiaImageTools::distanceTransform2d(std::vector<std::vector<unsigned int>>&
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
///
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
void RiaImageTools::makeGrayScale(QImage& image)
|
||||||
|
{
|
||||||
|
for (int i = 0; i < image.height(); i++)
|
||||||
|
{
|
||||||
|
uchar* scanLine = image.scanLine(i);
|
||||||
|
for (int j = 0; j < image.width(); j++)
|
||||||
|
{
|
||||||
|
QRgb* pixel = reinterpret_cast<QRgb*>(scanLine + j * 4);
|
||||||
|
int gray = qGray(*pixel);
|
||||||
|
int alpha = qAlpha(*pixel);
|
||||||
|
*pixel = QColor(gray, gray, gray, alpha).rgba();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@@ -20,10 +20,13 @@
|
|||||||
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
|
class QImage;
|
||||||
|
|
||||||
class RiaImageTools
|
class RiaImageTools
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
static void distanceTransform2d(std::vector<std::vector<unsigned int>>& image);
|
static void distanceTransform2d(std::vector<std::vector<unsigned int>>& image);
|
||||||
|
static void makeGrayScale(QImage& image);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@@ -448,6 +448,13 @@ void RimGridCrossPlot::fieldChangedByUi(const caf::PdmFieldHandle* changedField,
|
|||||||
const QVariant& oldValue,
|
const QVariant& oldValue,
|
||||||
const QVariant& newValue)
|
const QVariant& newValue)
|
||||||
{
|
{
|
||||||
|
if (changedField == &m_legendFontSize)
|
||||||
|
{
|
||||||
|
for (auto curveSet : m_crossPlotCurveSets)
|
||||||
|
{
|
||||||
|
curveSet->updateLegendIcons();
|
||||||
|
}
|
||||||
|
}
|
||||||
onLoadDataAndUpdate();
|
onLoadDataAndUpdate();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -636,6 +643,14 @@ void RimGridCrossPlot::setYAxisInverted(bool inverted)
|
|||||||
m_yAxisProperties->setAxisInverted(inverted);
|
m_yAxisProperties->setAxisInverted(inverted);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
///
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
int RimGridCrossPlot::legendFontSize() const
|
||||||
|
{
|
||||||
|
return m_legendFontSize;
|
||||||
|
}
|
||||||
|
|
||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
///
|
///
|
||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
|||||||
@@ -78,6 +78,7 @@ public:
|
|||||||
bool isXAxisLogarithmic() const;
|
bool isXAxisLogarithmic() const;
|
||||||
bool isYAxisLogarithmic() const;
|
bool isYAxisLogarithmic() const;
|
||||||
void setYAxisInverted(bool inverted);
|
void setYAxisInverted(bool inverted);
|
||||||
|
int legendFontSize() const;
|
||||||
public:
|
public:
|
||||||
// Rim2dPlotInterface overrides
|
// Rim2dPlotInterface overrides
|
||||||
void updateAxisScaling() override;
|
void updateAxisScaling() override;
|
||||||
|
|||||||
@@ -100,6 +100,25 @@ size_t RimGridCrossPlotCurve::sampleCount() const
|
|||||||
return m_qwtPlotCurve ? m_qwtPlotCurve->dataSize() : 0;
|
return m_qwtPlotCurve ? m_qwtPlotCurve->dataSize() : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
///
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
void RimGridCrossPlotCurve::determineLegendIcon()
|
||||||
|
{
|
||||||
|
RimGridCrossPlot* plot = nullptr;
|
||||||
|
firstAncestorOrThisOfTypeAsserted(plot);
|
||||||
|
int fontSize = plot->legendFontSize();
|
||||||
|
m_qwtPlotCurve->setLegendIconSize(QSize(fontSize, fontSize));
|
||||||
|
}
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
///
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
void RimGridCrossPlotCurve::setBlackAndWhiteLegendIcons(bool blackAndWhite)
|
||||||
|
{
|
||||||
|
m_qwtPlotCurve->setBlackAndWhiteLegendIcon(blackAndWhite);
|
||||||
|
}
|
||||||
|
|
||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
///
|
///
|
||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
|||||||
@@ -46,6 +46,8 @@ public:
|
|||||||
void setCurveAutoAppearance();
|
void setCurveAutoAppearance();
|
||||||
int groupIndex() const;
|
int groupIndex() const;
|
||||||
size_t sampleCount() const;
|
size_t sampleCount() const;
|
||||||
|
void determineLegendIcon();
|
||||||
|
void setBlackAndWhiteLegendIcons(bool blackAndWhite);
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
void determineSymbol();
|
void determineSymbol();
|
||||||
|
|||||||
@@ -463,7 +463,7 @@ void RimGridCrossPlotCurveSet::onLoadDataAndUpdate(bool updateParentPlot)
|
|||||||
|
|
||||||
std::map<int, cvf::UByteArray> timeStepCellVisibilityMap = calculateCellVisibility(eclipseCase);
|
std::map<int, cvf::UByteArray> timeStepCellVisibilityMap = calculateCellVisibility(eclipseCase);
|
||||||
|
|
||||||
updateLegend();
|
updateLegendRange();
|
||||||
|
|
||||||
RigEclipseCrossPlotResult result = RigEclipseCrossPlotDataExtractor::extract(
|
RigEclipseCrossPlotResult result = RigEclipseCrossPlotDataExtractor::extract(
|
||||||
eclipseCase->eclipseCaseData(), m_timeStep(), xAddress, yAddress, m_grouping(), groupAddress, timeStepCellVisibilityMap);
|
eclipseCase->eclipseCaseData(), m_timeStep(), xAddress, yAddress, m_grouping(), groupAddress, timeStepCellVisibilityMap);
|
||||||
@@ -489,6 +489,8 @@ void RimGridCrossPlotCurveSet::onLoadDataAndUpdate(bool updateParentPlot)
|
|||||||
fillCurveDataInExistingCurves(result);
|
fillCurveDataInExistingCurves(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
updateLegendIcons();
|
||||||
|
|
||||||
if (updateParentPlot)
|
if (updateParentPlot)
|
||||||
{
|
{
|
||||||
triggerPlotNameUpdateAndReplot();
|
triggerPlotNameUpdateAndReplot();
|
||||||
@@ -867,7 +869,7 @@ void RimGridCrossPlotCurveSet::fieldChangedByUi(const caf::PdmFieldHandle* chang
|
|||||||
}
|
}
|
||||||
else if (changedField == &m_isChecked)
|
else if (changedField == &m_isChecked)
|
||||||
{
|
{
|
||||||
updateLegend();
|
updateLegendRange();
|
||||||
triggerPlotNameUpdateAndReplot();
|
triggerPlotNameUpdateAndReplot();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -940,7 +942,7 @@ QList<caf::PdmOptionItemInfo> RimGridCrossPlotCurveSet::calculateValueOptions(co
|
|||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
///
|
///
|
||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
void RimGridCrossPlotCurveSet::updateLegend()
|
void RimGridCrossPlotCurveSet::updateLegendRange()
|
||||||
{
|
{
|
||||||
legendConfig()->setTitle(groupParameter());
|
legendConfig()->setTitle(groupParameter());
|
||||||
legendConfig()->disableAllTimeStepsRange(!hasMultipleTimeSteps());
|
legendConfig()->disableAllTimeStepsRange(!hasMultipleTimeSteps());
|
||||||
@@ -999,6 +1001,18 @@ void RimGridCrossPlotCurveSet::updateLegend()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
///
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
void RimGridCrossPlotCurveSet::updateLegendIcons()
|
||||||
|
{
|
||||||
|
for (auto curve : m_crossPlotCurves)
|
||||||
|
{
|
||||||
|
curve->determineLegendIcon();
|
||||||
|
curve->setBlackAndWhiteLegendIcons(groupingEnabled());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
///
|
///
|
||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
|||||||
@@ -118,7 +118,8 @@ public:
|
|||||||
std::map<NameComponents, QString> nameComponents() const;
|
std::map<NameComponents, QString> nameComponents() const;
|
||||||
|
|
||||||
void updateCurveNames(size_t curveSetIndex, size_t curveSetCount);
|
void updateCurveNames(size_t curveSetIndex, size_t curveSetCount);
|
||||||
void updateLegend();
|
void updateLegendRange();
|
||||||
|
void updateLegendIcons();
|
||||||
bool groupingByCategoryResult() const;
|
bool groupingByCategoryResult() const;
|
||||||
bool groupingEnabled() const;
|
bool groupingEnabled() const;
|
||||||
void swapAxisProperties(bool updatePlot);
|
void swapAxisProperties(bool updatePlot);
|
||||||
@@ -133,7 +134,8 @@ public:
|
|||||||
void destroyCurves();
|
void destroyCurves();
|
||||||
|
|
||||||
size_t visibleCurveCount() const;
|
size_t visibleCurveCount() const;
|
||||||
size_t sampleCount() const;
|
size_t sampleCount() const;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void initAfterRead() override;
|
void initAfterRead() override;
|
||||||
void onLoadDataAndUpdate(bool updateParentPlot);
|
void onLoadDataAndUpdate(bool updateParentPlot);
|
||||||
@@ -159,8 +161,9 @@ protected:
|
|||||||
|
|
||||||
bool hasMultipleTimeSteps() const;
|
bool hasMultipleTimeSteps() const;
|
||||||
void filterInvalidCurveValues(RigEclipseCrossPlotResult* result);
|
void filterInvalidCurveValues(RigEclipseCrossPlotResult* result);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
caf::PdmPtrField<RimCase*> m_case;
|
caf::PdmPtrField<RimCase*> m_case;
|
||||||
caf::PdmField<int> m_timeStep;
|
caf::PdmField<int> m_timeStep;
|
||||||
caf::PdmPtrField<RimGridView*> m_cellFilterView;
|
caf::PdmPtrField<RimGridView*> m_cellFilterView;
|
||||||
|
|||||||
@@ -20,6 +20,7 @@
|
|||||||
#include "RiuQwtPlotCurve.h"
|
#include "RiuQwtPlotCurve.h"
|
||||||
|
|
||||||
#include "RiaCurveDataTools.h"
|
#include "RiaCurveDataTools.h"
|
||||||
|
#include "RiaImageTools.h"
|
||||||
#include "RiuQwtSymbol.h"
|
#include "RiuQwtSymbol.h"
|
||||||
|
|
||||||
#include "qwt_symbol.h"
|
#include "qwt_symbol.h"
|
||||||
@@ -59,6 +60,7 @@ RiuQwtPlotCurve::RiuQwtPlotCurve(const QString &title)
|
|||||||
|
|
||||||
m_showErrorBars = true;
|
m_showErrorBars = true;
|
||||||
m_attachedToPlot = nullptr;
|
m_attachedToPlot = nullptr;
|
||||||
|
m_blackAndWhiteLegendIcon = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
@@ -371,6 +373,31 @@ void RiuQwtPlotCurve::setAppearance(LineStyleEnum lineStyle,
|
|||||||
setStyle(curveStyle);
|
setStyle(curveStyle);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
///
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
void RiuQwtPlotCurve::setBlackAndWhiteLegendIcon(bool blackAndWhite)
|
||||||
|
{
|
||||||
|
m_blackAndWhiteLegendIcon = blackAndWhite;
|
||||||
|
}
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
///
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
QwtGraphic RiuQwtPlotCurve::legendIcon(int index, const QSizeF& size) const
|
||||||
|
{
|
||||||
|
QwtGraphic icon = QwtPlotCurve::legendIcon(index, size);
|
||||||
|
if (m_blackAndWhiteLegendIcon)
|
||||||
|
{
|
||||||
|
QImage image = icon.toImage();
|
||||||
|
RiaImageTools::makeGrayScale(image);
|
||||||
|
|
||||||
|
QPainter painter(&icon);
|
||||||
|
painter.drawImage(QPoint(0, 0), image);
|
||||||
|
}
|
||||||
|
return icon;
|
||||||
|
}
|
||||||
|
|
||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
///
|
///
|
||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
|||||||
@@ -113,6 +113,8 @@ public:
|
|||||||
CurveInterpolationEnum interpolationType,
|
CurveInterpolationEnum interpolationType,
|
||||||
int curveThickness,
|
int curveThickness,
|
||||||
const QColor& curveColor);
|
const QColor& curveColor);
|
||||||
|
void setBlackAndWhiteLegendIcon(bool blackAndWhite);
|
||||||
|
QwtGraphic legendIcon(int index, const QSizeF& size) const override;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void drawCurve(QPainter* p, int style,
|
void drawCurve(QPainter* p, int style,
|
||||||
@@ -138,4 +140,5 @@ private:
|
|||||||
bool m_showErrorBars;
|
bool m_showErrorBars;
|
||||||
QwtPlotIntervalCurve* m_errorBars;
|
QwtPlotIntervalCurve* m_errorBars;
|
||||||
QwtPlot* m_attachedToPlot;
|
QwtPlot* m_attachedToPlot;
|
||||||
|
bool m_blackAndWhiteLegendIcon;
|
||||||
};
|
};
|
||||||
Reference in new issue
Block a user