From 85851d07947b2323ba73ff100d47a5563b6e5673 Mon Sep 17 00:00:00 2001 From: Gaute Lindkvist Date: Mon, 20 Apr 2020 09:35:59 +0200 Subject: [PATCH] Moved Box shape creator to QwtPlotTools for use in correlation matrix --- .../UserInterface/RiuQwtPlotTools.cpp | 46 +++++++++++++---- .../UserInterface/RiuQwtPlotTools.h | 9 ++++ .../RiuWellPathComponentPlotItem.cpp | 49 ++++++------------- .../RiuWellPathComponentPlotItem.h | 7 --- 4 files changed, 61 insertions(+), 50 deletions(-) diff --git a/ApplicationCode/UserInterface/RiuQwtPlotTools.cpp b/ApplicationCode/UserInterface/RiuQwtPlotTools.cpp index 9e0af11a74..79db7c1886 100644 --- a/ApplicationCode/UserInterface/RiuQwtPlotTools.cpp +++ b/ApplicationCode/UserInterface/RiuQwtPlotTools.cpp @@ -25,6 +25,7 @@ #include "qwt_plot.h" #include "qwt_plot_grid.h" #include "qwt_plot_layout.h" +#include "qwt_plot_shapeitem.h" #include "qwt_scale_widget.h" #include @@ -66,7 +67,7 @@ void RiuQwtPlotTools::setCommonPlotBehaviour( QwtPlot* plot ) plot->setAxisFont( QwtPlot::yRight, axisFont ); // Axis title font - std::vector axes = {QwtPlot::xBottom, QwtPlot::xTop, QwtPlot::yLeft, QwtPlot::yRight}; + std::vector axes = { QwtPlot::xBottom, QwtPlot::xTop, QwtPlot::yLeft, QwtPlot::yRight }; for ( QwtPlot::Axis axis : axes ) { @@ -130,14 +131,14 @@ void RiuQwtPlotTools::enableDateBasedBottomXAxis( QwtPlot* { QwtDateScaleDraw* scaleDraw = new QwtDateScaleDraw( Qt::UTC ); - std::set intervals = {QwtDate::Year, - QwtDate::Month, - QwtDate::Week, - QwtDate::Day, - QwtDate::Hour, - QwtDate::Minute, - QwtDate::Second, - QwtDate::Millisecond}; + std::set intervals = { QwtDate::Year, + QwtDate::Month, + QwtDate::Week, + QwtDate::Day, + QwtDate::Hour, + QwtDate::Minute, + QwtDate::Second, + QwtDate::Millisecond }; for ( QwtDate::IntervalType interval : intervals ) { @@ -208,3 +209,30 @@ QString RiuQwtPlotTools::dateTimeFormatForInterval( QwtDate::IntervalType } } } + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +QwtPlotItem* RiuQwtPlotTools::createBoxShape( const QString& label, + double startX, + double endX, + double startY, + double endY, + QColor color, + Qt::BrushStyle brushStyle ) +{ + QwtPlotShapeItem* columnShape = new QwtPlotShapeItem( label ); + QPolygonF polygon; + + polygon.push_back( QPointF( startX, startY ) ); + polygon.push_back( QPointF( endX, startY ) ); + polygon.push_back( QPointF( endX, endY ) ); + polygon.push_back( QPointF( startX, endY ) ); + polygon.push_back( QPointF( startX, startY ) ); + columnShape->setPolygon( polygon ); + columnShape->setXAxis( QwtPlot::xBottom ); + columnShape->setBrush( QBrush( color, brushStyle ) ); + columnShape->setLegendMode( QwtPlotShapeItem::LegendShape ); + columnShape->setLegendIconSize( QSize( 16, 16 ) ); + return columnShape; +} diff --git a/ApplicationCode/UserInterface/RiuQwtPlotTools.h b/ApplicationCode/UserInterface/RiuQwtPlotTools.h index 10493329f8..772e21d061 100644 --- a/ApplicationCode/UserInterface/RiuQwtPlotTools.h +++ b/ApplicationCode/UserInterface/RiuQwtPlotTools.h @@ -21,6 +21,7 @@ #include class QwtPlot; +class QwtPlotItem; class RiuQwtPlotTools { @@ -39,4 +40,12 @@ public: const QString& timeFormat, RiaQDateTimeTools::DateFormatComponents dateComponents, RiaQDateTimeTools::TimeFormatComponents timeComponents ); + + static QwtPlotItem* createBoxShape( const QString& label, + double startX, + double endX, + double startY, + double endY, + QColor color, + Qt::BrushStyle brushStyle = Qt::SolidPattern ); }; diff --git a/ApplicationCode/UserInterface/RiuWellPathComponentPlotItem.cpp b/ApplicationCode/UserInterface/RiuWellPathComponentPlotItem.cpp index 73d9c34763..a196c767b4 100644 --- a/ApplicationCode/UserInterface/RiuWellPathComponentPlotItem.cpp +++ b/ApplicationCode/UserInterface/RiuWellPathComponentPlotItem.cpp @@ -33,6 +33,7 @@ #include "RimWellPathValve.h" #include "RigWellPath.h" +#include "RiuQwtPlotTools.h" #include "qwt_plot.h" #include "qwt_plot_marker.h" @@ -410,65 +411,45 @@ void RiuWellPathComponentPlotItem::addColumnFeature( double startX, cvf::Color4f baseColor, Qt::BrushStyle brushStyle /*= Qt::SolidPattern*/ ) { + QColor baseQColor = RiaColorTools::toQColor( baseColor ); if ( brushStyle != Qt::SolidPattern ) { // If we're doing a special pattern, draw the background in white first over the existing pattern - cvf::Color4f semiTransparentWhite( cvf::Color3f( cvf::Color3::WHITE ), 0.9f ); + QColor semiTransparentWhite( Qt::white ); + semiTransparentWhite.setAlphaF( 0.9f ); QwtPlotItem* backgroundShape = - createColumnShape( startX, endX, startDepth, endDepth, semiTransparentWhite, Qt::SolidPattern ); + RiuQwtPlotTools::createBoxShape( label(), startX, endX, startDepth, endDepth, semiTransparentWhite, Qt::SolidPattern ); m_combinedComponentGroup.addPlotItem( backgroundShape ); - QwtPlotItem* patternShape = createColumnShape( startX, endX, startDepth, endDepth, baseColor, brushStyle ); + QwtPlotItem* patternShape = + RiuQwtPlotTools::createBoxShape( label(), startX, endX, startDepth, endDepth, baseQColor, brushStyle ); m_combinedComponentGroup.addPlotItem( patternShape ); if ( endX >= 0.0 ) { - QwtPlotItem* legendBGShape = createColumnShape( 0.0, 16.0, 0.0, 16.0, semiTransparentWhite, Qt::SolidPattern ); + QwtPlotItem* legendBGShape = + RiuQwtPlotTools::createBoxShape( label(), 0.0, 16.0, 0.0, 16.0, semiTransparentWhite, Qt::SolidPattern ); m_combinedComponentGroup.addLegendItem( legendBGShape ); - QwtPlotItem* legendShape = createColumnShape( 0.0, 16.0, 0.0, 16.0, baseColor, brushStyle ); + QwtPlotItem* legendShape = + RiuQwtPlotTools::createBoxShape( label(), 0.0, 16.0, 0.0, 16.0, baseQColor, brushStyle ); m_combinedComponentGroup.addLegendItem( legendShape ); } } else { - QwtPlotItem* backgroundShape = createColumnShape( startX, endX, startDepth, endDepth, baseColor, Qt::SolidPattern ); + QwtPlotItem* backgroundShape = + RiuQwtPlotTools::createBoxShape( label(), startX, endX, startDepth, endDepth, baseQColor, Qt::SolidPattern ); m_combinedComponentGroup.addPlotItem( backgroundShape ); if ( endX >= 0.0 ) { - QwtPlotItem* legendShape = createColumnShape( 0.0, 16.0, 0.0, 16.0, baseColor, Qt::SolidPattern ); + QwtPlotItem* legendShape = + RiuQwtPlotTools::createBoxShape( label(), 0.0, 16.0, 0.0, 16.0, baseQColor, Qt::SolidPattern ); m_combinedComponentGroup.addLegendItem( legendShape ); } } } -//-------------------------------------------------------------------------------------------------- -/// -//-------------------------------------------------------------------------------------------------- -QwtPlotItem* RiuWellPathComponentPlotItem::createColumnShape( double startX, - double endX, - double startDepth, - double endDepth, - cvf::Color4f baseColor, - Qt::BrushStyle brushStyle ) -{ - QwtPlotShapeItem* columnShape = new QwtPlotShapeItem( label() ); - QPolygonF polygon; - QColor color = RiaColorTools::toQColor( baseColor ); - - polygon.push_back( QPointF( startX, startDepth ) ); - polygon.push_back( QPointF( endX, startDepth ) ); - polygon.push_back( QPointF( endX, endDepth ) ); - polygon.push_back( QPointF( startX, endDepth ) ); - polygon.push_back( QPointF( startX, startDepth ) ); - columnShape->setPolygon( polygon ); - columnShape->setXAxis( QwtPlot::xBottom ); - columnShape->setBrush( QBrush( color, brushStyle ) ); - columnShape->setLegendMode( QwtPlotShapeItem::LegendShape ); - columnShape->setLegendIconSize( QSize( 16, 16 ) ); - return columnShape; -} - //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- diff --git a/ApplicationCode/UserInterface/RiuWellPathComponentPlotItem.h b/ApplicationCode/UserInterface/RiuWellPathComponentPlotItem.h index 41ab0d9834..ec7a452188 100644 --- a/ApplicationCode/UserInterface/RiuWellPathComponentPlotItem.h +++ b/ApplicationCode/UserInterface/RiuWellPathComponentPlotItem.h @@ -107,13 +107,6 @@ private: cvf::Color4f baseColor, Qt::BrushStyle brushStyle = Qt::SolidPattern ); - QwtPlotItem* createColumnShape( double startX, - double endX, - double startDepth, - double endDepth, - cvf::Color4f baseColor, - Qt::BrushStyle brushStyle = Qt::SolidPattern ); - cvf::Color4f componentColor( float alpha = 1.0 ) const; private: