mirror of
https://github.com/OPM/ResInsight.git
synced 2025-02-10 07:26:03 -06:00
#2091 Cross Plot : Improve interface of RiuLineSegmentQwtPlotCurve
Remove duplicate code
This commit is contained in:
parent
baa9a47b92
commit
0502b95d86
@ -322,11 +322,11 @@ void RimGridTimeHistoryCurve::onLoadDataAndUpdate(bool updateParentPlot)
|
||||
std::vector<time_t> dateTimes = timeStepValues();
|
||||
if (dateTimes.size() > 0 && dateTimes.size() == values.size())
|
||||
{
|
||||
m_qwtPlotCurve->setSamplesFromTimeTAndValues(dateTimes, values, isLogCurve);
|
||||
m_qwtPlotCurve->setSamplesFromTimeTAndYValues(dateTimes, values, isLogCurve);
|
||||
}
|
||||
else
|
||||
{
|
||||
m_qwtPlotCurve->setSamplesFromTimeTAndValues(std::vector<time_t>(), std::vector<double>(), isLogCurve);
|
||||
m_qwtPlotCurve->setSamplesFromTimeTAndYValues(std::vector<time_t>(), std::vector<double>(), isLogCurve);
|
||||
}
|
||||
}
|
||||
else
|
||||
@ -342,11 +342,11 @@ void RimGridTimeHistoryCurve::onLoadDataAndUpdate(bool updateParentPlot)
|
||||
times.push_back(timeScale * day);
|
||||
}
|
||||
|
||||
m_qwtPlotCurve->setSamplesFromTimeAndValues(times, values, isLogCurve);
|
||||
m_qwtPlotCurve->setSamplesFromXValuesAndYValues(times, values, isLogCurve);
|
||||
}
|
||||
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)
|
||||
{
|
||||
m_qwtPlotCurve->setSamplesFromTimeTAndValues(dateTimes, values, isLogCurve);
|
||||
m_qwtPlotCurve->setSamplesFromTimeTAndYValues(dateTimes, values, isLogCurve);
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -161,13 +161,13 @@ void RimAsciiDataCurve::onLoadDataAndUpdate(bool updateParentPlot)
|
||||
}
|
||||
}
|
||||
|
||||
m_qwtPlotCurve->setSamplesFromTimeAndValues(times, values, isLogCurve);
|
||||
m_qwtPlotCurve->setSamplesFromXValuesAndYValues(times, values, isLogCurve);
|
||||
}
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
m_qwtPlotCurve->setSamplesFromTimeTAndValues(std::vector<time_t>(), std::vector<double>(), isLogCurve);
|
||||
m_qwtPlotCurve->setSamplesFromTimeTAndYValues(std::vector<time_t>(), std::vector<double>(), isLogCurve);
|
||||
}
|
||||
|
||||
updateZoomInParentPlot();
|
||||
|
@ -407,7 +407,7 @@ void RimSummaryCurve::onLoadDataAndUpdate(bool updateParentPlot)
|
||||
{
|
||||
if (plot->timeAxisProperties()->timeMode() == RimSummaryTimeAxisProperties::DATE)
|
||||
{
|
||||
m_qwtPlotCurve->setSamplesFromTimeTAndValues(dateTimes, values, isLogCurve);
|
||||
m_qwtPlotCurve->setSamplesFromTimeTAndYValues(dateTimes, values, isLogCurve);
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -423,13 +423,13 @@ void RimSummaryCurve::onLoadDataAndUpdate(bool updateParentPlot)
|
||||
}
|
||||
}
|
||||
|
||||
m_qwtPlotCurve->setSamplesFromTimeAndValues(times, values, isLogCurve);
|
||||
m_qwtPlotCurve->setSamplesFromXValuesAndYValues(times, values, isLogCurve);
|
||||
}
|
||||
|
||||
}
|
||||
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)
|
||||
|
@ -160,7 +160,7 @@ void RiuFlowCharacteristicsPlot::addCurveWithLargeSymbol(QwtPlot* plot, const QS
|
||||
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());
|
||||
|
||||
RiuLineSegmentQwtPlotCurve* plotCurve = createEmptyCurve(m_flowCapVsStorageCapPlot, dateTime.toString(), m_dateToColorMap[dateTime]);
|
||||
plotCurve->setSamplesFromTimeAndValues(xVals, yVals, false);
|
||||
plotCurve->setSamplesFromXValuesAndYValues(xVals, yVals, false);
|
||||
m_flowCapVsStorageCapPlot->replot();
|
||||
}
|
||||
|
||||
@ -196,7 +196,7 @@ void RiuFlowCharacteristicsPlot::addSweepEfficiencyCurve(const QDateTime& dateTi
|
||||
CVF_ASSERT(!m_dateToColorMap.empty());
|
||||
|
||||
RiuLineSegmentQwtPlotCurve* plotCurve = createEmptyCurve(m_sweepEffPlot, dateTime.toString(), m_dateToColorMap[dateTime]);
|
||||
plotCurve->setSamplesFromTimeAndValues(xVals, yVals, false);
|
||||
plotCurve->setSamplesFromXValuesAndYValues(xVals, yVals, false);
|
||||
|
||||
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;
|
||||
std::vector< std::pair<size_t, size_t> > filteredIntervals;
|
||||
{
|
||||
std::vector<double> filteredTimeHistoryValues;
|
||||
std::vector<QDateTime> filteredDateTimes;
|
||||
std::vector<double> filteredYValues;
|
||||
std::vector<double> filteredXValues;
|
||||
|
||||
{
|
||||
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(dateTimes, intervalsOfValidValues, &filteredDateTimes);
|
||||
RigCurveDataTools::getValuesByIntervals(yValues, intervalsOfValidValues, &filteredYValues);
|
||||
RigCurveDataTools::getValuesByIntervals(xValues, intervalsOfValidValues, &filteredXValues);
|
||||
|
||||
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(milliSecSinceEpoch, filteredTimeHistoryValues[i]);
|
||||
points << QPointF(filteredXValues[i], filteredYValues[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());
|
||||
|
||||
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);
|
||||
setSamplesFromXValuesAndYValues(RiuLineSegmentQwtPlotCurve::fromQDateTime(dateTimes), yValues, removeNegativeValues);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
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());
|
||||
|
||||
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);
|
||||
setSamplesFromXValuesAndYValues(RiuLineSegmentQwtPlotCurve::fromTime_t(dateTimes), yValues, removeNegativeValues);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
@ -252,3 +201,44 @@ void RiuLineSegmentQwtPlotCurve::setSymbolSkipPixelDistance(float distance)
|
||||
{
|
||||
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);
|
||||
virtual ~RiuLineSegmentQwtPlotCurve();
|
||||
|
||||
void setSamplesFromDateAndValues(const std::vector<QDateTime>& dateTimes, const std::vector<double>& timeHistoryValues, bool removeNegativeValues);
|
||||
void setSamplesFromTimeTAndValues(const std::vector<time_t>& dateTimes, const std::vector<double>& timeHistoryValues, bool removeNegativeValues);
|
||||
void setSamplesFromTimeAndValues(const std::vector<double>& times, const std::vector<double>& timeHistoryValues, bool removeNegativeValues);
|
||||
void setSamplesFromXValuesAndYValues(const std::vector<double>& xValues,
|
||||
const std::vector<double>& yValues,
|
||||
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 setSymbolSkipPixelDistance(float distance);
|
||||
|
||||
|
||||
protected:
|
||||
virtual void drawCurve(QPainter* p, int style,
|
||||
const QwtScaleMap& xMap, const QwtScaleMap& yMap,
|
||||
@ -69,6 +76,10 @@ protected:
|
||||
const QRectF &canvasRect,
|
||||
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:
|
||||
std::vector< std::pair<size_t, size_t> > m_polyLineStartStopIndices;
|
||||
float m_symbolSkipPixelDistance;
|
||||
|
@ -66,7 +66,7 @@ void RiuResultQwtPlot::addCurve(const QString& curveName, const cvf::Color3f& cu
|
||||
{
|
||||
RiuLineSegmentQwtPlotCurve* plotCurve = new RiuLineSegmentQwtPlotCurve("Curve 1");
|
||||
|
||||
plotCurve->setSamplesFromDateAndValues(dateTimes, timeHistoryValues, false);
|
||||
plotCurve->setSamplesFromDatesAndYValues(dateTimes, timeHistoryValues, false);
|
||||
plotCurve->setTitle(curveName);
|
||||
|
||||
plotCurve->setPen(QPen(QColor(curveColor.rByte(), curveColor.gByte(), curveColor.bByte())));
|
||||
|
Loading…
Reference in New Issue
Block a user