mirror of
https://github.com/OPM/ResInsight.git
synced 2025-02-25 18:55:39 -06:00
#2091 Cross Plot : Improve interface of RiuLineSegmentQwtPlotCurve
Remove duplicate code
This commit is contained in:
@@ -322,11 +322,11 @@ void RimGridTimeHistoryCurve::onLoadDataAndUpdate(bool updateParentPlot)
|
|||||||
std::vector<time_t> dateTimes = timeStepValues();
|
std::vector<time_t> dateTimes = timeStepValues();
|
||||||
if (dateTimes.size() > 0 && dateTimes.size() == values.size())
|
if (dateTimes.size() > 0 && dateTimes.size() == values.size())
|
||||||
{
|
{
|
||||||
m_qwtPlotCurve->setSamplesFromTimeTAndValues(dateTimes, values, isLogCurve);
|
m_qwtPlotCurve->setSamplesFromTimeTAndYValues(dateTimes, values, isLogCurve);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
m_qwtPlotCurve->setSamplesFromTimeTAndValues(std::vector<time_t>(), std::vector<double>(), isLogCurve);
|
m_qwtPlotCurve->setSamplesFromTimeTAndYValues(std::vector<time_t>(), std::vector<double>(), isLogCurve);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -342,11 +342,11 @@ void RimGridTimeHistoryCurve::onLoadDataAndUpdate(bool updateParentPlot)
|
|||||||
times.push_back(timeScale * day);
|
times.push_back(timeScale * day);
|
||||||
}
|
}
|
||||||
|
|
||||||
m_qwtPlotCurve->setSamplesFromTimeAndValues(times, values, isLogCurve);
|
m_qwtPlotCurve->setSamplesFromXValuesAndYValues(times, values, isLogCurve);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
m_qwtPlotCurve->setSamplesFromTimeTAndValues(std::vector<time_t>(), std::vector<double>(), isLogCurve);
|
m_qwtPlotCurve->setSamplesFromTimeTAndYValues(std::vector<time_t>(), std::vector<double>(), isLogCurve);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -145,7 +145,7 @@ void RimAsciiDataCurve::onLoadDataAndUpdate(bool updateParentPlot)
|
|||||||
{
|
{
|
||||||
if (plot->timeAxisProperties()->timeMode() == RimSummaryTimeAxisProperties::DATE)
|
if (plot->timeAxisProperties()->timeMode() == RimSummaryTimeAxisProperties::DATE)
|
||||||
{
|
{
|
||||||
m_qwtPlotCurve->setSamplesFromTimeTAndValues(dateTimes, values, isLogCurve);
|
m_qwtPlotCurve->setSamplesFromTimeTAndYValues(dateTimes, values, isLogCurve);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -161,13 +161,13 @@ void RimAsciiDataCurve::onLoadDataAndUpdate(bool updateParentPlot)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
m_qwtPlotCurve->setSamplesFromTimeAndValues(times, values, isLogCurve);
|
m_qwtPlotCurve->setSamplesFromXValuesAndYValues(times, values, isLogCurve);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
m_qwtPlotCurve->setSamplesFromTimeTAndValues(std::vector<time_t>(), std::vector<double>(), isLogCurve);
|
m_qwtPlotCurve->setSamplesFromTimeTAndYValues(std::vector<time_t>(), std::vector<double>(), isLogCurve);
|
||||||
}
|
}
|
||||||
|
|
||||||
updateZoomInParentPlot();
|
updateZoomInParentPlot();
|
||||||
|
|||||||
@@ -407,7 +407,7 @@ void RimSummaryCurve::onLoadDataAndUpdate(bool updateParentPlot)
|
|||||||
{
|
{
|
||||||
if (plot->timeAxisProperties()->timeMode() == RimSummaryTimeAxisProperties::DATE)
|
if (plot->timeAxisProperties()->timeMode() == RimSummaryTimeAxisProperties::DATE)
|
||||||
{
|
{
|
||||||
m_qwtPlotCurve->setSamplesFromTimeTAndValues(dateTimes, values, isLogCurve);
|
m_qwtPlotCurve->setSamplesFromTimeTAndYValues(dateTimes, values, isLogCurve);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -423,13 +423,13 @@ void RimSummaryCurve::onLoadDataAndUpdate(bool updateParentPlot)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
m_qwtPlotCurve->setSamplesFromTimeAndValues(times, values, isLogCurve);
|
m_qwtPlotCurve->setSamplesFromXValuesAndYValues(times, values, isLogCurve);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
m_qwtPlotCurve->setSamplesFromTimeTAndValues(std::vector<time_t>(), std::vector<double>(), isLogCurve);
|
m_qwtPlotCurve->setSamplesFromTimeTAndYValues(std::vector<time_t>(), std::vector<double>(), isLogCurve);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( updateParentPlot && m_parentQwtPlot)
|
if ( updateParentPlot && m_parentQwtPlot)
|
||||||
|
|||||||
@@ -160,7 +160,7 @@ void RiuFlowCharacteristicsPlot::addCurveWithLargeSymbol(QwtPlot* plot, const QS
|
|||||||
timeHistoryValues.push_back(timeHistoryValue);
|
timeHistoryValues.push_back(timeHistoryValue);
|
||||||
timeHistoryValues.push_back(timeHistoryValue);
|
timeHistoryValues.push_back(timeHistoryValue);
|
||||||
|
|
||||||
curve->setSamplesFromDateAndValues(dateTimes, timeHistoryValues, false);
|
curve->setSamplesFromDatesAndYValues(dateTimes, timeHistoryValues, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
@@ -184,7 +184,7 @@ void RiuFlowCharacteristicsPlot::addFlowCapStorageCapCurve(const QDateTime& date
|
|||||||
CVF_ASSERT(!m_dateToColorMap.empty());
|
CVF_ASSERT(!m_dateToColorMap.empty());
|
||||||
|
|
||||||
RiuLineSegmentQwtPlotCurve* plotCurve = createEmptyCurve(m_flowCapVsStorageCapPlot, dateTime.toString(), m_dateToColorMap[dateTime]);
|
RiuLineSegmentQwtPlotCurve* plotCurve = createEmptyCurve(m_flowCapVsStorageCapPlot, dateTime.toString(), m_dateToColorMap[dateTime]);
|
||||||
plotCurve->setSamplesFromTimeAndValues(xVals, yVals, false);
|
plotCurve->setSamplesFromXValuesAndYValues(xVals, yVals, false);
|
||||||
m_flowCapVsStorageCapPlot->replot();
|
m_flowCapVsStorageCapPlot->replot();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -196,7 +196,7 @@ void RiuFlowCharacteristicsPlot::addSweepEfficiencyCurve(const QDateTime& dateTi
|
|||||||
CVF_ASSERT(!m_dateToColorMap.empty());
|
CVF_ASSERT(!m_dateToColorMap.empty());
|
||||||
|
|
||||||
RiuLineSegmentQwtPlotCurve* plotCurve = createEmptyCurve(m_sweepEffPlot, dateTime.toString(), m_dateToColorMap[dateTime]);
|
RiuLineSegmentQwtPlotCurve* plotCurve = createEmptyCurve(m_sweepEffPlot, dateTime.toString(), m_dateToColorMap[dateTime]);
|
||||||
plotCurve->setSamplesFromTimeAndValues(xVals, yVals, false);
|
plotCurve->setSamplesFromXValuesAndYValues(xVals, yVals, false);
|
||||||
|
|
||||||
m_sweepEffPlot->replot();
|
m_sweepEffPlot->replot();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -51,30 +51,30 @@ RiuLineSegmentQwtPlotCurve::~RiuLineSegmentQwtPlotCurve()
|
|||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
///
|
///
|
||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
void RiuLineSegmentQwtPlotCurve::setSamplesFromDateAndValues(const std::vector<QDateTime>& dateTimes, const std::vector<double>& timeHistoryValues, bool removeNegativeValues)
|
void RiuLineSegmentQwtPlotCurve::setSamplesFromXValuesAndYValues(const std::vector<double>& xValues, const std::vector<double>& yValues, bool removeNegativeValues)
|
||||||
{
|
{
|
||||||
CVF_ASSERT(dateTimes.size() == timeHistoryValues.size());
|
CVF_ASSERT(xValues.size() == yValues.size());
|
||||||
|
|
||||||
QPolygonF points;
|
QPolygonF points;
|
||||||
std::vector< std::pair<size_t, size_t> > filteredIntervals;
|
std::vector< std::pair<size_t, size_t> > filteredIntervals;
|
||||||
{
|
{
|
||||||
std::vector<double> filteredTimeHistoryValues;
|
std::vector<double> filteredYValues;
|
||||||
std::vector<QDateTime> filteredDateTimes;
|
std::vector<double> filteredXValues;
|
||||||
|
|
||||||
{
|
{
|
||||||
std::vector< std::pair<size_t, size_t> > intervalsOfValidValues;
|
std::vector< std::pair<size_t, size_t> > intervalsOfValidValues;
|
||||||
RigCurveDataTools::calculateIntervalsOfValidValues(timeHistoryValues, &intervalsOfValidValues, removeNegativeValues);
|
RigCurveDataTools::calculateIntervalsOfValidValues(yValues, &intervalsOfValidValues, removeNegativeValues);
|
||||||
|
|
||||||
RigCurveDataTools::getValuesByIntervals(timeHistoryValues, intervalsOfValidValues, &filteredTimeHistoryValues);
|
RigCurveDataTools::getValuesByIntervals(yValues, intervalsOfValidValues, &filteredYValues);
|
||||||
RigCurveDataTools::getValuesByIntervals(dateTimes, intervalsOfValidValues, &filteredDateTimes);
|
RigCurveDataTools::getValuesByIntervals(xValues, intervalsOfValidValues, &filteredXValues);
|
||||||
|
|
||||||
RigCurveDataTools::computePolyLineStartStopIndices(intervalsOfValidValues, &filteredIntervals);
|
RigCurveDataTools::computePolyLineStartStopIndices(intervalsOfValidValues, &filteredIntervals);
|
||||||
}
|
}
|
||||||
|
|
||||||
for ( size_t i = 0; i < filteredDateTimes.size(); i++ )
|
points.reserve(static_cast<int>(filteredXValues.size()));
|
||||||
|
for ( size_t i = 0; i < filteredXValues.size(); i++ )
|
||||||
{
|
{
|
||||||
double milliSecSinceEpoch = QwtDate::toDouble(filteredDateTimes[i]);
|
points << QPointF(filteredXValues[i], filteredYValues[i]);
|
||||||
points << QPointF(milliSecSinceEpoch, filteredTimeHistoryValues[i]);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -85,68 +85,17 @@ void RiuLineSegmentQwtPlotCurve::setSamplesFromDateAndValues(const std::vector<Q
|
|||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
///
|
///
|
||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
void RiuLineSegmentQwtPlotCurve::setSamplesFromTimeTAndValues(const std::vector<time_t>& dateTimes, const std::vector<double>& timeHistoryValues, bool removeNegativeValues)
|
void RiuLineSegmentQwtPlotCurve::setSamplesFromDatesAndYValues(const std::vector<QDateTime>& dateTimes, const std::vector<double>& yValues, bool removeNegativeValues)
|
||||||
{
|
{
|
||||||
CVF_ASSERT(dateTimes.size() == timeHistoryValues.size());
|
setSamplesFromXValuesAndYValues(RiuLineSegmentQwtPlotCurve::fromQDateTime(dateTimes), yValues, removeNegativeValues);
|
||||||
|
|
||||||
QPolygonF points;
|
|
||||||
std::vector< std::pair<size_t, size_t> > filteredIntervals;
|
|
||||||
{
|
|
||||||
std::vector<double> filteredTimeHistoryValues;
|
|
||||||
std::vector<time_t> filteredDateTimes;
|
|
||||||
|
|
||||||
{
|
|
||||||
std::vector< std::pair<size_t, size_t> > intervalsOfValidValues;
|
|
||||||
RigCurveDataTools::calculateIntervalsOfValidValues(timeHistoryValues, &intervalsOfValidValues, removeNegativeValues);
|
|
||||||
|
|
||||||
RigCurveDataTools::getValuesByIntervals(timeHistoryValues, intervalsOfValidValues, &filteredTimeHistoryValues);
|
|
||||||
RigCurveDataTools::getValuesByIntervals(dateTimes, intervalsOfValidValues, &filteredDateTimes);
|
|
||||||
|
|
||||||
RigCurveDataTools::computePolyLineStartStopIndices(intervalsOfValidValues, &filteredIntervals);
|
|
||||||
}
|
|
||||||
|
|
||||||
for (size_t i = 0; i < filteredDateTimes.size(); i++)
|
|
||||||
{
|
|
||||||
double milliSecSinceEpoch = filteredDateTimes[i] * 1000; // This is kind of hack, as the c++ standard does not state what time_t is. "Almost always" secs since epoch according to cppreference.com
|
|
||||||
points << QPointF(milliSecSinceEpoch, filteredTimeHistoryValues[i]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
this->setSamples(points);
|
|
||||||
this->setLineSegmentStartStopIndices(filteredIntervals);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
///
|
///
|
||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
void RiuLineSegmentQwtPlotCurve::setSamplesFromTimeAndValues(const std::vector<double>& times, const std::vector<double>& timeHistoryValues, bool removeNegativeValues)
|
void RiuLineSegmentQwtPlotCurve::setSamplesFromTimeTAndYValues(const std::vector<time_t>& dateTimes, const std::vector<double>& yValues, bool removeNegativeValues)
|
||||||
{
|
{
|
||||||
CVF_ASSERT(times.size() == timeHistoryValues.size());
|
setSamplesFromXValuesAndYValues(RiuLineSegmentQwtPlotCurve::fromTime_t(dateTimes), yValues, removeNegativeValues);
|
||||||
|
|
||||||
QPolygonF points;
|
|
||||||
std::vector< std::pair<size_t, size_t> > filteredIntervals;
|
|
||||||
{
|
|
||||||
std::vector<double> filteredTimeHistoryValues;
|
|
||||||
std::vector<double> filteredTimes;
|
|
||||||
|
|
||||||
{
|
|
||||||
std::vector< std::pair<size_t, size_t> > intervalsOfValidValues;
|
|
||||||
RigCurveDataTools::calculateIntervalsOfValidValues(timeHistoryValues, &intervalsOfValidValues, removeNegativeValues);
|
|
||||||
|
|
||||||
RigCurveDataTools::getValuesByIntervals(timeHistoryValues, intervalsOfValidValues, &filteredTimeHistoryValues);
|
|
||||||
RigCurveDataTools::getValuesByIntervals(times, intervalsOfValidValues, &filteredTimes);
|
|
||||||
|
|
||||||
RigCurveDataTools::computePolyLineStartStopIndices(intervalsOfValidValues, &filteredIntervals);
|
|
||||||
}
|
|
||||||
|
|
||||||
for ( size_t i = 0; i < filteredTimes.size(); i++ )
|
|
||||||
{
|
|
||||||
points << QPointF(filteredTimes[i], filteredTimeHistoryValues[i]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
this->setSamples(points);
|
|
||||||
this->setLineSegmentStartStopIndices(filteredIntervals);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
@@ -252,3 +201,44 @@ void RiuLineSegmentQwtPlotCurve::setSymbolSkipPixelDistance(float distance)
|
|||||||
{
|
{
|
||||||
m_symbolSkipPixelDistance = distance >= 0.0f ? distance: 0.0f;
|
m_symbolSkipPixelDistance = distance >= 0.0f ? distance: 0.0f;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
///
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
std::vector<double> RiuLineSegmentQwtPlotCurve::fromQDateTime(const std::vector<QDateTime>& dateTimes)
|
||||||
|
{
|
||||||
|
std::vector<double> doubleValues;
|
||||||
|
|
||||||
|
if (!dateTimes.empty())
|
||||||
|
{
|
||||||
|
doubleValues.reserve(dateTimes.size());
|
||||||
|
|
||||||
|
for (const auto& dt : dateTimes)
|
||||||
|
{
|
||||||
|
doubleValues.push_back(QwtDate::toDouble(dt));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return doubleValues;
|
||||||
|
}
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
///
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
std::vector<double> RiuLineSegmentQwtPlotCurve::fromTime_t(const std::vector<time_t>& timeSteps)
|
||||||
|
{
|
||||||
|
std::vector<double> doubleValues;
|
||||||
|
|
||||||
|
if (!timeSteps.empty())
|
||||||
|
{
|
||||||
|
doubleValues.reserve(timeSteps.size());
|
||||||
|
for (const auto& time : timeSteps)
|
||||||
|
{
|
||||||
|
double milliSecSinceEpoch = time * 1000; // This is kind of hack, as the c++ standard does not state what time_t is. "Almost always" secs since epoch according to cppreference.com
|
||||||
|
|
||||||
|
doubleValues.push_back(milliSecSinceEpoch);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return doubleValues;
|
||||||
|
}
|
||||||
|
|||||||
@@ -47,15 +47,22 @@ public:
|
|||||||
explicit RiuLineSegmentQwtPlotCurve(const QString &title = QString::null);
|
explicit RiuLineSegmentQwtPlotCurve(const QString &title = QString::null);
|
||||||
virtual ~RiuLineSegmentQwtPlotCurve();
|
virtual ~RiuLineSegmentQwtPlotCurve();
|
||||||
|
|
||||||
void setSamplesFromDateAndValues(const std::vector<QDateTime>& dateTimes, const std::vector<double>& timeHistoryValues, bool removeNegativeValues);
|
void setSamplesFromXValuesAndYValues(const std::vector<double>& xValues,
|
||||||
void setSamplesFromTimeTAndValues(const std::vector<time_t>& dateTimes, const std::vector<double>& timeHistoryValues, bool removeNegativeValues);
|
const std::vector<double>& yValues,
|
||||||
void setSamplesFromTimeAndValues(const std::vector<double>& times, const std::vector<double>& timeHistoryValues, bool removeNegativeValues);
|
bool removeNegativeValues);
|
||||||
|
|
||||||
|
void setSamplesFromDatesAndYValues(const std::vector<QDateTime>& dateTimes,
|
||||||
|
const std::vector<double>& yValues,
|
||||||
|
bool removeNegativeValues);
|
||||||
|
|
||||||
|
void setSamplesFromTimeTAndYValues(const std::vector<time_t>& dateTimes,
|
||||||
|
const std::vector<double>& yValues,
|
||||||
|
bool removeNegativeValues);
|
||||||
|
|
||||||
void setLineSegmentStartStopIndices(const std::vector< std::pair<size_t, size_t> >& lineSegmentStartStopIndices);
|
void setLineSegmentStartStopIndices(const std::vector< std::pair<size_t, size_t> >& lineSegmentStartStopIndices);
|
||||||
|
|
||||||
void setSymbolSkipPixelDistance(float distance);
|
void setSymbolSkipPixelDistance(float distance);
|
||||||
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual void drawCurve(QPainter* p, int style,
|
virtual void drawCurve(QPainter* p, int style,
|
||||||
const QwtScaleMap& xMap, const QwtScaleMap& yMap,
|
const QwtScaleMap& xMap, const QwtScaleMap& yMap,
|
||||||
@@ -69,6 +76,10 @@ protected:
|
|||||||
const QRectF &canvasRect,
|
const QRectF &canvasRect,
|
||||||
int from, int to) const override;
|
int from, int to) const override;
|
||||||
|
|
||||||
|
private:
|
||||||
|
static std::vector<double> fromQDateTime(const std::vector<QDateTime>& dateTimes);
|
||||||
|
static std::vector<double> fromTime_t(const std::vector<time_t>& timeSteps);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::vector< std::pair<size_t, size_t> > m_polyLineStartStopIndices;
|
std::vector< std::pair<size_t, size_t> > m_polyLineStartStopIndices;
|
||||||
float m_symbolSkipPixelDistance;
|
float m_symbolSkipPixelDistance;
|
||||||
|
|||||||
@@ -66,7 +66,7 @@ void RiuResultQwtPlot::addCurve(const QString& curveName, const cvf::Color3f& cu
|
|||||||
{
|
{
|
||||||
RiuLineSegmentQwtPlotCurve* plotCurve = new RiuLineSegmentQwtPlotCurve("Curve 1");
|
RiuLineSegmentQwtPlotCurve* plotCurve = new RiuLineSegmentQwtPlotCurve("Curve 1");
|
||||||
|
|
||||||
plotCurve->setSamplesFromDateAndValues(dateTimes, timeHistoryValues, false);
|
plotCurve->setSamplesFromDatesAndYValues(dateTimes, timeHistoryValues, false);
|
||||||
plotCurve->setTitle(curveName);
|
plotCurve->setTitle(curveName);
|
||||||
|
|
||||||
plotCurve->setPen(QPen(QColor(curveColor.rByte(), curveColor.gByte(), curveColor.bByte())));
|
plotCurve->setPen(QPen(QColor(curveColor.rByte(), curveColor.gByte(), curveColor.bByte())));
|
||||||
|
|||||||
Reference in New Issue
Block a user