mirror of
https://github.com/OPM/ResInsight.git
synced 2025-02-09 23:16:00 -06: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:
parent
ee5935aad6
commit
75b0905e26
@ -2,6 +2,9 @@
|
||||
|
||||
#include "cvfAssert.h"
|
||||
|
||||
#include <QColor>
|
||||
#include <QImage>
|
||||
|
||||
#include <algorithm>
|
||||
#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>
|
||||
|
||||
class QImage;
|
||||
|
||||
class RiaImageTools
|
||||
{
|
||||
public:
|
||||
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& newValue)
|
||||
{
|
||||
if (changedField == &m_legendFontSize)
|
||||
{
|
||||
for (auto curveSet : m_crossPlotCurveSets)
|
||||
{
|
||||
curveSet->updateLegendIcons();
|
||||
}
|
||||
}
|
||||
onLoadDataAndUpdate();
|
||||
}
|
||||
|
||||
@ -636,6 +643,14 @@ void RimGridCrossPlot::setYAxisInverted(bool inverted)
|
||||
m_yAxisProperties->setAxisInverted(inverted);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
int RimGridCrossPlot::legendFontSize() const
|
||||
{
|
||||
return m_legendFontSize;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
|
@ -78,6 +78,7 @@ public:
|
||||
bool isXAxisLogarithmic() const;
|
||||
bool isYAxisLogarithmic() const;
|
||||
void setYAxisInverted(bool inverted);
|
||||
int legendFontSize() const;
|
||||
public:
|
||||
// Rim2dPlotInterface overrides
|
||||
void updateAxisScaling() override;
|
||||
|
@ -100,6 +100,25 @@ size_t RimGridCrossPlotCurve::sampleCount() const
|
||||
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();
|
||||
int groupIndex() const;
|
||||
size_t sampleCount() const;
|
||||
void determineLegendIcon();
|
||||
void setBlackAndWhiteLegendIcons(bool blackAndWhite);
|
||||
protected:
|
||||
|
||||
void determineSymbol();
|
||||
|
@ -463,7 +463,7 @@ void RimGridCrossPlotCurveSet::onLoadDataAndUpdate(bool updateParentPlot)
|
||||
|
||||
std::map<int, cvf::UByteArray> timeStepCellVisibilityMap = calculateCellVisibility(eclipseCase);
|
||||
|
||||
updateLegend();
|
||||
updateLegendRange();
|
||||
|
||||
RigEclipseCrossPlotResult result = RigEclipseCrossPlotDataExtractor::extract(
|
||||
eclipseCase->eclipseCaseData(), m_timeStep(), xAddress, yAddress, m_grouping(), groupAddress, timeStepCellVisibilityMap);
|
||||
@ -489,6 +489,8 @@ void RimGridCrossPlotCurveSet::onLoadDataAndUpdate(bool updateParentPlot)
|
||||
fillCurveDataInExistingCurves(result);
|
||||
}
|
||||
|
||||
updateLegendIcons();
|
||||
|
||||
if (updateParentPlot)
|
||||
{
|
||||
triggerPlotNameUpdateAndReplot();
|
||||
@ -867,7 +869,7 @@ void RimGridCrossPlotCurveSet::fieldChangedByUi(const caf::PdmFieldHandle* chang
|
||||
}
|
||||
else if (changedField == &m_isChecked)
|
||||
{
|
||||
updateLegend();
|
||||
updateLegendRange();
|
||||
triggerPlotNameUpdateAndReplot();
|
||||
}
|
||||
}
|
||||
@ -940,7 +942,7 @@ QList<caf::PdmOptionItemInfo> RimGridCrossPlotCurveSet::calculateValueOptions(co
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RimGridCrossPlotCurveSet::updateLegend()
|
||||
void RimGridCrossPlotCurveSet::updateLegendRange()
|
||||
{
|
||||
legendConfig()->setTitle(groupParameter());
|
||||
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;
|
||||
|
||||
void updateCurveNames(size_t curveSetIndex, size_t curveSetCount);
|
||||
void updateLegend();
|
||||
void updateLegendRange();
|
||||
void updateLegendIcons();
|
||||
bool groupingByCategoryResult() const;
|
||||
bool groupingEnabled() const;
|
||||
void swapAxisProperties(bool updatePlot);
|
||||
@ -133,7 +134,8 @@ public:
|
||||
void destroyCurves();
|
||||
|
||||
size_t visibleCurveCount() const;
|
||||
size_t sampleCount() const;
|
||||
size_t sampleCount() const;
|
||||
|
||||
protected:
|
||||
void initAfterRead() override;
|
||||
void onLoadDataAndUpdate(bool updateParentPlot);
|
||||
@ -159,8 +161,9 @@ protected:
|
||||
|
||||
bool hasMultipleTimeSteps() const;
|
||||
void filterInvalidCurveValues(RigEclipseCrossPlotResult* result);
|
||||
|
||||
private:
|
||||
|
||||
|
||||
caf::PdmPtrField<RimCase*> m_case;
|
||||
caf::PdmField<int> m_timeStep;
|
||||
caf::PdmPtrField<RimGridView*> m_cellFilterView;
|
||||
|
@ -20,6 +20,7 @@
|
||||
#include "RiuQwtPlotCurve.h"
|
||||
|
||||
#include "RiaCurveDataTools.h"
|
||||
#include "RiaImageTools.h"
|
||||
#include "RiuQwtSymbol.h"
|
||||
|
||||
#include "qwt_symbol.h"
|
||||
@ -59,6 +60,7 @@ RiuQwtPlotCurve::RiuQwtPlotCurve(const QString &title)
|
||||
|
||||
m_showErrorBars = true;
|
||||
m_attachedToPlot = nullptr;
|
||||
m_blackAndWhiteLegendIcon = false;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
@ -371,6 +373,31 @@ void RiuQwtPlotCurve::setAppearance(LineStyleEnum lineStyle,
|
||||
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,
|
||||
int curveThickness,
|
||||
const QColor& curveColor);
|
||||
void setBlackAndWhiteLegendIcon(bool blackAndWhite);
|
||||
QwtGraphic legendIcon(int index, const QSizeF& size) const override;
|
||||
|
||||
protected:
|
||||
void drawCurve(QPainter* p, int style,
|
||||
@ -138,4 +140,5 @@ private:
|
||||
bool m_showErrorBars;
|
||||
QwtPlotIntervalCurve* m_errorBars;
|
||||
QwtPlot* m_attachedToPlot;
|
||||
bool m_blackAndWhiteLegendIcon;
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user