#5536 Move orientation argument.

Testplot code moved to separate method.
This commit is contained in:
Jacob Støren 2020-02-17 11:11:27 +01:00
parent e9f8cf8105
commit 1f109d0ee2
4 changed files with 72 additions and 62 deletions

View File

@ -320,8 +320,33 @@ void RimAnalysisPlot::onLoadDataAndUpdate()
if ( m_plotWidget )
{
RiuGroupedBarChartBuilder chartBuilder( Qt::Horizontal );
RiuGroupedBarChartBuilder chartBuilder;
buildTestPlot( chartBuilder );
chartBuilder.addBarChartToPlot( m_plotWidget, Qt::Horizontal );
if ( m_showPlotLegends && m_plotWidget->legend() == nullptr )
{
QwtLegend* legend = new QwtLegend( m_plotWidget );
m_plotWidget->insertLegend( legend, QwtPlot::RightLegend );
}
else
{
m_plotWidget->insertLegend( nullptr );
}
m_plotWidget->updateLegend();
}
this->updateAxes();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimAnalysisPlot::buildTestPlot( RiuGroupedBarChartBuilder& chartBuilder )
{
chartBuilder.addBarEntry( "T1_The_red_Fox", "", "", std::numeric_limits<double>::infinity(), "R1", "", 0.4 );
chartBuilder.addBarEntry( "T1_The_red_Fox", "", "", std::numeric_limits<double>::infinity(), "R2", "", 0.45 );
chartBuilder.addBarEntry( "T1_The_red_Fox", "W1", "", std::numeric_limits<double>::infinity(), "R1", "", 0.5 );
@ -366,22 +391,4 @@ void RimAnalysisPlot::onLoadDataAndUpdate()
chartBuilder.addBarEntry( "", "", "", 2.0, "", "D", 2.0 );
chartBuilder.addBarEntry( "", "", "", 1.6, "", "E", 1.6 );
chartBuilder.addBarEntry( "", "", "", 2.4, "", "F", -2.4 );
chartBuilder.addBarChartToPlot( m_plotWidget );
if ( m_showPlotLegends && m_plotWidget->legend() == nullptr )
{
QwtLegend* legend = new QwtLegend( m_plotWidget );
m_plotWidget->insertLegend( legend, QwtPlot::RightLegend );
}
else
{
m_plotWidget->insertLegend( nullptr );
}
// m_plotWidget->setLegendFontSize( m_legendFontSize() );
m_plotWidget->updateLegend();
}
this->updateAxes();
}

View File

@ -24,6 +24,7 @@
class RiuSummaryQwtPlot;
class RimAnalysisPlotDataEntry;
class RiuGroupedBarChartBuilder;
//==================================================================================================
///
@ -106,6 +107,8 @@ private:
void defineUiOrdering( QString uiConfigName, caf::PdmUiOrdering& uiOrdering ) override;
void onLoadDataAndUpdate() override;
void buildTestPlot( RiuGroupedBarChartBuilder& chartBuilder );
private:
QPointer<RiuQwtPlotWidget> m_plotWidget;

View File

@ -185,10 +185,7 @@ protected:
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RiuGroupedBarChartBuilder::RiuGroupedBarChartBuilder( Qt::Orientation orientation )
: m_orientation( orientation )
{
}
RiuGroupedBarChartBuilder::RiuGroupedBarChartBuilder() {}
//--------------------------------------------------------------------------------------------------
///
@ -208,7 +205,7 @@ void RiuGroupedBarChartBuilder::addBarEntry( const QString& majorTickText,
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RiuGroupedBarChartBuilder::addBarChartToPlot( QwtPlot* plot )
void RiuGroupedBarChartBuilder::addBarChartToPlot( QwtPlot* plot, Qt::Orientation orientation )
{
const double majGroupSpacing = 1.6;
const double midGroupSpacing = 0.5;
@ -384,14 +381,15 @@ void RiuGroupedBarChartBuilder::addBarChartToPlot( QwtPlot* plot )
addQwtBarChart( plot,
legendToBarPointsPair.second,
legendToBarPointsPair.first,
RiaColorTables::summaryCurveDefaultPaletteColors().cycledQColor( idx ) );
RiaColorTables::summaryCurveDefaultPaletteColors().cycledQColor( idx ),
orientation );
idx++;
}
// Set up the axis to contain group texts and tick marks
{
QwtPlot::Axis axis = QwtPlot::xBottom;
if ( m_orientation == Qt::Horizontal )
if ( orientation == Qt::Horizontal )
{
axis = QwtPlot::yLeft;
}
@ -402,7 +400,7 @@ void RiuGroupedBarChartBuilder::addBarChartToPlot( QwtPlot* plot )
if ( midTickPositions.size() ) groupAxisScaleDiv.setTicks( QwtScaleDiv::MediumTick, midTickPositions );
if ( minTickPositions.size() ) groupAxisScaleDiv.setTicks( QwtScaleDiv::MinorTick, minTickPositions );
if ( m_orientation == Qt::Horizontal )
if ( orientation == Qt::Horizontal )
{
groupAxisScaleDiv.invert();
}
@ -417,7 +415,7 @@ void RiuGroupedBarChartBuilder::addBarChartToPlot( QwtPlot* plot )
// Add texts on the bars inside the plot
{
QwtScaleDraw::Alignment alignment = QwtScaleDraw::TopScale;
if ( m_orientation == Qt::Horizontal )
if ( orientation == Qt::Horizontal )
{
alignment = QwtScaleDraw::RightScale;
}
@ -432,7 +430,7 @@ void RiuGroupedBarChartBuilder::addBarChartToPlot( QwtPlot* plot )
}
barTextScaleDiv.setTicks( QwtScaleDiv::MinorTick, onBarTickPositions );
if ( m_orientation == Qt::Horizontal )
if ( orientation == Qt::Horizontal )
{
barTextScaleDiv.invert();
}
@ -455,7 +453,8 @@ void RiuGroupedBarChartBuilder::addBarChartToPlot( QwtPlot* plot )
void RiuGroupedBarChartBuilder::addQwtBarChart( QwtPlot* plot,
const QVector<QPointF>& posAndValue,
const QString& legendText,
const QColor& barColor )
const QColor& barColor,
Qt::Orientation orientation )
{
QPalette palette;
palette.setColor( QPalette::Window, barColor );
@ -472,7 +471,7 @@ void RiuGroupedBarChartBuilder::addQwtBarChart( QwtPlot* plot,
barChart->setLayoutPolicy( QwtPlotAbstractBarChart::ScaleSamplesToAxes );
barChart->setLayoutHint( 1.0 );
barChart->setSymbol( barStyle );
barChart->setOrientation( m_orientation );
barChart->setOrientation( orientation );
barChart->attach( plot );
}

View File

@ -32,7 +32,7 @@ class QColor;
class RiuGroupedBarChartBuilder
{
public:
RiuGroupedBarChartBuilder( Qt::Orientation orientation );
RiuGroupedBarChartBuilder();
void addBarEntry( const QString& majorTickText,
const QString& midTickText,
@ -42,7 +42,7 @@ public:
const QString& barText,
const double value );
void addBarChartToPlot( QwtPlot* plot );
void addBarChartToPlot( QwtPlot* plot, Qt::Orientation orientation );
private:
double midPoint( double v1, double v2 )
@ -53,7 +53,8 @@ private:
void addQwtBarChart( QwtPlot* plot,
const QVector<QPointF>& posAndValue,
const QString& legendText,
const QColor& barColor );
const QColor& barColor,
Qt::Orientation orientation );
struct BarEntry
{