Made RiuQwtPlotWidget axis operations much more general

This commit is contained in:
Gaute Lindkvist
2019-10-25 10:53:12 +02:00
parent 0e9cda8e84
commit edead9e3af
9 changed files with 157 additions and 196 deletions

View File

@@ -374,7 +374,7 @@ void RimWellLogExtractionCurve::onLoadDataAndUpdate( bool updateParentPlot )
RiuQwtPlotWidget* viewer = wellLogTrack->viewer(); RiuQwtPlotWidget* viewer = wellLogTrack->viewer();
if ( viewer ) if ( viewer )
{ {
viewer->setYTitle( "PL/" + wellLogPlot->depthAxisTitle() ); viewer->setAxisTitleText( QwtPlot::yLeft, "PL/" + wellLogPlot->depthAxisTitle() );
} }
} }

View File

@@ -649,6 +649,11 @@ void RimWellLogPlot::initAfterRead()
{ {
m_nameConfig->setCustomName( m_description() ); m_nameConfig->setCustomName( m_description() );
} }
if ( m_depthAxisGridVisibility() == AXIS_GRID_MINOR )
{
m_depthAxisGridVisibility = AXIS_GRID_MAJOR_AND_MINOR;
}
} }
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------

View File

@@ -58,9 +58,10 @@ public:
enum AxisGridVisibility enum AxisGridVisibility
{ {
AXIS_GRID_NONE, AXIS_GRID_NONE = 0x00,
AXIS_GRID_MAJOR, AXIS_GRID_MAJOR = 0x01,
AXIS_GRID_MAJOR_AND_MINOR AXIS_GRID_MINOR = 0x02,
AXIS_GRID_MAJOR_AND_MINOR = 0x03
}; };
typedef caf::AppEnum<AxisGridVisibility> AxisGridEnum; typedef caf::AppEnum<AxisGridVisibility> AxisGridEnum;

View File

@@ -464,19 +464,19 @@ void RimWellLogRftCurve::onLoadDataAndUpdate( bool updateParentPlot )
{ {
if ( m_derivedMDSource == NO_SOURCE ) if ( m_derivedMDSource == NO_SOURCE )
{ {
viewer->setYTitle( "TVDMSL" ); viewer->setAxisTitleText( QwtPlot::yLeft, "TVDMSL" );
} }
else if ( m_derivedMDSource == PSEUDO_LENGTH ) else if ( m_derivedMDSource == PSEUDO_LENGTH )
{ {
viewer->setYTitle( "PL/" + wellLogPlot->depthAxisTitle() ); viewer->setAxisTitleText( QwtPlot::yLeft, "PL/" + wellLogPlot->depthAxisTitle() );
} }
else if ( m_derivedMDSource == WELL_PATH ) else if ( m_derivedMDSource == WELL_PATH )
{ {
viewer->setYTitle( "WELL/" + wellLogPlot->depthAxisTitle() ); viewer->setAxisTitleText( QwtPlot::yLeft, "WELL/" + wellLogPlot->depthAxisTitle() );
} }
else else
{ {
viewer->setYTitle( "OBS/" + wellLogPlot->depthAxisTitle() ); viewer->setAxisTitleText( QwtPlot::yLeft, "OBS/" + wellLogPlot->depthAxisTitle() );
} }
} }
} }

View File

@@ -478,7 +478,7 @@ void RimWellLogTrack::updateXZoom()
componentRangeMin = -1.5; componentRangeMin = -1.5;
} }
m_plotWidget->setXRange( componentRangeMin, componentRangeMax, QwtPlot::xBottom ); m_plotWidget->setAxisRange( QwtPlot::xBottom, componentRangeMin, componentRangeMax );
} }
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
@@ -488,7 +488,7 @@ void RimWellLogTrack::updateYZoom()
{ {
if ( !m_plotWidget ) return; if ( !m_plotWidget ) return;
m_plotWidget->setYRange( m_visibleYRangeMin(), m_visibleYRangeMax() ); m_plotWidget->setAxisRange( QwtPlot::yLeft, m_visibleYRangeMin(), m_visibleYRangeMax() );
} }
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
@@ -520,8 +520,8 @@ void RimWellLogTrack::fieldChangedByUi( const caf::PdmFieldHandle* changedField,
{ {
if ( m_plotWidget ) if ( m_plotWidget )
{ {
m_majorTickInterval = m_plotWidget->getCurrentMajorTickInterval(); m_majorTickInterval = m_plotWidget->majorTickInterval( QwtPlot::xTop );
m_minorTickInterval = m_plotWidget->getCurrentMinorTickInterval(); m_minorTickInterval = m_plotWidget->minorTickInterval( QwtPlot::xTop );
} }
m_majorTickInterval.uiCapability()->setUiHidden( !m_explicitTickIntervals() ); m_majorTickInterval.uiCapability()->setUiHidden( !m_explicitTickIntervals() );
m_minorTickInterval.uiCapability()->setUiHidden( !m_explicitTickIntervals() ); m_minorTickInterval.uiCapability()->setUiHidden( !m_explicitTickIntervals() );
@@ -693,7 +693,8 @@ void RimWellLogTrack::updateXAxisAndGridTickIntervals()
if ( m_explicitTickIntervals ) if ( m_explicitTickIntervals )
{ {
m_plotWidget->setMajorAndMinorTickIntervals( m_majorTickInterval(), m_plotWidget->setMajorAndMinorTickIntervals( QwtPlot::xTop,
m_majorTickInterval(),
m_minorTickInterval(), m_minorTickInterval(),
m_visibleXRangeMin(), m_visibleXRangeMin(),
m_visibleXRangeMax() ); m_visibleXRangeMax() );
@@ -725,36 +726,20 @@ void RimWellLogTrack::updateXAxisAndGridTickIntervals()
minorTickIntervals = 10; minorTickIntervals = 10;
break; break;
} }
m_plotWidget->setAutoTickIntervalCounts( majorTickIntervals, minorTickIntervals ); m_plotWidget->setAutoTickIntervalCounts( QwtPlot::xTop, majorTickIntervals, minorTickIntervals );
m_plotWidget->setXRange( m_visibleXRangeMin, m_visibleXRangeMax ); m_plotWidget->setAxisRange( QwtPlot::xTop, m_visibleXRangeMin, m_visibleXRangeMax );
} }
switch ( m_xAxisGridVisibility() ) m_plotWidget->enableGridLines( QwtPlot::xTop,
{ m_xAxisGridVisibility() & RimWellLogPlot::AXIS_GRID_MAJOR,
case RimWellLogPlot::AXIS_GRID_NONE: m_xAxisGridVisibility() & RimWellLogPlot::AXIS_GRID_MINOR );
m_plotWidget->enableXGridLines( false, false );
break;
case RimWellLogPlot::AXIS_GRID_MAJOR:
m_plotWidget->enableXGridLines( true, false );
break;
case RimWellLogPlot::AXIS_GRID_MAJOR_AND_MINOR:
m_plotWidget->enableXGridLines( true, true );
break;
}
RimWellLogPlot* plot = nullptr; RimWellLogPlot* plot = nullptr;
this->firstAncestorOrThisOfTypeAsserted( plot ); this->firstAncestorOrThisOfTypeAsserted( plot );
switch ( plot->depthAxisGridLinesEnabled() )
{ m_plotWidget->enableGridLines( QwtPlot::yLeft,
case RimWellLogPlot::AXIS_GRID_NONE: plot->depthAxisGridLinesEnabled() & RimWellLogPlot::AXIS_GRID_MAJOR,
m_plotWidget->enableYGridLines( false, false ); plot->depthAxisGridLinesEnabled() & RimWellLogPlot::AXIS_GRID_MINOR );
break;
case RimWellLogPlot::AXIS_GRID_MAJOR:
m_plotWidget->enableYGridLines( true, false );
break;
case RimWellLogPlot::AXIS_GRID_MAJOR_AND_MINOR:
m_plotWidget->enableYGridLines( true, true );
break;
}
m_plotWidget->scheduleReplot(); m_plotWidget->scheduleReplot();
} }
@@ -857,7 +842,7 @@ bool RimWellLogTrack::hasCustomFontSizes( RiaDefines::FontSettingType fontSettin
{ {
if ( fontSettingType == RiaDefines::PLOT_FONT && m_plotWidget ) if ( fontSettingType == RiaDefines::PLOT_FONT && m_plotWidget )
{ {
return defaultFontSize != m_plotWidget->fontSize(); return defaultFontSize != m_plotWidget->axisTitleFontSize( QwtPlot::xTop );
} }
return false; return false;
} }
@@ -872,9 +857,10 @@ bool RimWellLogTrack::applyFontSize( RiaDefines::FontSettingType fontSettingType
{ {
if ( fontSettingType == RiaDefines::PLOT_FONT && m_plotWidget ) if ( fontSettingType == RiaDefines::PLOT_FONT && m_plotWidget )
{ {
if ( oldFontSize == m_plotWidget->fontSize() || forceChange ) if ( oldFontSize == m_plotWidget->axisTitleFontSize( QwtPlot::xTop ) || forceChange )
{ {
m_plotWidget->setFontSize( fontSize ); m_plotWidget->setAxisFontsAndAlignment( QwtPlot::xTop, fontSize, fontSize );
m_plotWidget->setAxisFontsAndAlignment( QwtPlot::yLeft, fontSize, fontSize );
return true; return true;
} }
} }
@@ -1121,8 +1107,8 @@ void RimWellLogTrack::loadDataAndUpdate()
if ( wellLogPlot && m_plotWidget ) if ( wellLogPlot && m_plotWidget )
{ {
m_plotWidget->setXTitle( m_xAxisTitle ); m_plotWidget->setAxisTitleText( QwtPlot::yLeft, m_xAxisTitle );
m_plotWidget->setYTitle( wellLogPlot->depthAxisTitle() ); m_plotWidget->setAxisTitleText( QwtPlot::yLeft, wellLogPlot->depthAxisTitle() );
} }
for ( size_t cIdx = 0; cIdx < m_curves.size(); ++cIdx ) for ( size_t cIdx = 0; cIdx < m_curves.size(); ++cIdx )
@@ -1678,6 +1664,11 @@ void RimWellLogTrack::initAfterRead()
m_regionAnnotationType = RiuPlotAnnotationTool::FORMATION_ANNOTATIONS; m_regionAnnotationType = RiuPlotAnnotationTool::FORMATION_ANNOTATIONS;
m_regionAnnotationDisplay = RiuPlotAnnotationTool::DARK_LINES; m_regionAnnotationDisplay = RiuPlotAnnotationTool::DARK_LINES;
} }
if ( m_xAxisGridVisibility() == RimWellLogPlot::AXIS_GRID_MINOR )
{
m_xAxisGridVisibility = RimWellLogPlot::AXIS_GRID_MAJOR_AND_MINOR;
}
} }
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------

View File

@@ -1078,36 +1078,21 @@ void RimSummaryPlot::updateTimeAxis()
m_plotWidget->enableAxis( QwtPlot::xBottom, true ); m_plotWidget->enableAxis( QwtPlot::xBottom, true );
{ {
QString axisTitle; QString axisTitle = m_timeAxisProperties->title();
if ( m_timeAxisProperties->showTitle ) axisTitle = m_timeAxisProperties->title();
QwtText timeAxisTitle = m_plotWidget->axisTitle( QwtPlot::xBottom ); Qt::AlignmentFlag alignment = Qt::AlignCenter;
if ( m_timeAxisProperties->titlePosition() == RimPlotAxisPropertiesInterface::AXIS_TITLE_END )
QFont font = timeAxisTitle.font();
font.setBold( true );
font.setPointSize( m_timeAxisProperties->titleFontSize() );
timeAxisTitle.setFont( font );
timeAxisTitle.setText( axisTitle );
switch ( m_timeAxisProperties->titlePosition() )
{ {
case RimSummaryTimeAxisProperties::AXIS_TITLE_CENTER: alignment = Qt::AlignRight;
timeAxisTitle.setRenderFlags( Qt::AlignCenter );
break;
case RimSummaryTimeAxisProperties::AXIS_TITLE_END:
timeAxisTitle.setRenderFlags( Qt::AlignRight );
break;
} }
m_plotWidget->setAxisTitle( QwtPlot::xBottom, timeAxisTitle ); m_plotWidget->setAxisFontsAndAlignment( QwtPlot::xBottom,
} m_timeAxisProperties->titleFontSize(),
m_timeAxisProperties->valuesFontSize(),
{ true,
QFont timeAxisFont = m_plotWidget->axisFont( QwtPlot::xBottom ); alignment );
timeAxisFont.setBold( false ); m_plotWidget->setAxisTitleText( QwtPlot::xBottom, m_timeAxisProperties->title() );
timeAxisFont.setPointSize( m_timeAxisProperties->valuesFontSize() ); m_plotWidget->setAxisTitleEnabled( QwtPlot::xBottom, m_timeAxisProperties->showTitle );
m_plotWidget->setAxisFont( QwtPlot::xBottom, timeAxisFont );
} }
} }

View File

@@ -611,8 +611,8 @@ void RiuGridPlotWindow::reinsertPlotWidgetsAndScrollbar()
legends[visibleIndex]->hide(); legends[visibleIndex]->hide();
} }
plotWidgets[visibleIndex]->setYAxisLabelsAndTicksEnabled( column == 0 ); plotWidgets[visibleIndex]->setAxisLabelsAndTicksEnabled( QwtPlot::yLeft, column == 0 );
plotWidgets[visibleIndex]->setYTitleEnabled( column == 0 ); plotWidgets[visibleIndex]->setAxisTitleEnabled( QwtPlot::yLeft, column == 0 );
plotWidgets[visibleIndex]->show(); plotWidgets[visibleIndex]->show();

View File

@@ -92,14 +92,11 @@ bool RiuQwtPlotWidget::isChecked() const
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
/// ///
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
int RiuQwtPlotWidget::fontSize() const int RiuQwtPlotWidget::axisTitleFontSize( QwtPlot::Axis axis ) const
{ {
for ( int axisId = 0; axisId < QwtPlot::axisCnt; ++axisId ) if ( this->axisEnabled( axis ) )
{ {
if ( this->axisEnabled( axisId ) ) return this->axisFont( axis ).pointSize();
{
return this->axisFont( axisId ).pointSize();
}
} }
return -1; return -1;
} }
@@ -107,31 +104,36 @@ int RiuQwtPlotWidget::fontSize() const
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
/// ///
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
void RiuQwtPlotWidget::setFontSize( int fontSize ) int RiuQwtPlotWidget::axisValueFontSize( QwtPlot::Axis axis ) const
{
if ( this->axisEnabled( axis ) )
{
return this->axisTitle( axis ).font().pointSize();
}
return -1;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RiuQwtPlotWidget::setAxisFontsAndAlignment(
QwtPlot::Axis axis, int titleFontSize, int valueFontSize, bool titleBold, Qt::AlignmentFlag alignment )
{ {
// Axis number font // Axis number font
QFont axisFont = this->axisFont( QwtPlot::xBottom ); QFont axisFont = this->axisFont( axis );
axisFont.setPointSize( fontSize ); axisFont.setPointSize( valueFontSize );
axisFont.setBold( false );
setAxisFont( QwtPlot::xBottom, axisFont ); this->setAxisFont( axis, axisFont );
setAxisFont( QwtPlot::xTop, axisFont );
setAxisFont( QwtPlot::yLeft, axisFont );
setAxisFont( QwtPlot::yRight, axisFont );
// Axis title font // Axis title font
std::vector<QwtPlot::Axis> axes = { QwtPlot::xBottom, QwtPlot::xTop, QwtPlot::yLeft, QwtPlot::yRight }; QwtText axisTitle = this->axisTitle( axis );
QFont axisTitleFont = axisTitle.font();
axisTitleFont.setPointSize( titleFontSize );
axisTitleFont.setBold( titleBold );
axisTitle.setFont( axisTitleFont );
axisTitle.setRenderFlags( alignment );
for ( QwtPlot::Axis axis : axes ) setAxisTitle( axis, axisTitle );
{
QwtText axisTitle = this->axisTitle( axis );
QFont axisTitleFont = axisTitle.font();
axisTitleFont.setPointSize( fontSize );
axisTitleFont.setBold( false );
axisTitle.setFont( axisTitleFont );
axisTitle.setRenderFlags( Qt::AlignRight );
setAxisTitle( axis, axisTitle );
}
} }
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
@@ -169,10 +171,12 @@ void RiuQwtPlotWidget::setEnabledAxes( const std::set<QwtPlot::Axis> enabledAxes
axisScaleDraw( axis )->enableComponent( QwtAbstractScaleDraw::Backbone, false ); axisScaleDraw( axis )->enableComponent( QwtAbstractScaleDraw::Backbone, false );
axisWidget( axis )->setMargin( 0 ); axisWidget( axis )->setMargin( 0 );
m_axisTitlesEnabled[axis] = true;
} }
else else
{ {
enableAxis( axis, false ); enableAxis( axis, false );
m_axisTitlesEnabled[axis] = false;
} }
} }
} }
@@ -180,32 +184,26 @@ void RiuQwtPlotWidget::setEnabledAxes( const std::set<QwtPlot::Axis> enabledAxes
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
/// ///
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
void RiuQwtPlotWidget::setXTitle( const QString& title ) void RiuQwtPlotWidget::setAxisTitleText( QwtPlot::Axis axis, const QString& title )
{ {
QwtText axisTitleX = axisTitle( QwtPlot::xTop ); m_axisTitles[axis] = title;
if ( title != axisTitleX.text() )
QwtText axisTitleText = axisTitle( axis );
if ( title != axisTitleText.text() )
{ {
axisTitleX.setText( title ); axisTitleText.setText( title );
setAxisTitle( QwtPlot::xTop, axisTitleX ); setAxisTitle( axis, axisTitleText );
} }
applyAxisTitleToQwt( axis );
} }
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
/// ///
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
void RiuQwtPlotWidget::setYTitle( const QString& title ) void RiuQwtPlotWidget::setAxisTitleEnabled( QwtPlot::Axis axis, bool enable )
{ {
m_yAxisTitle = title; m_axisTitlesEnabled[axis] = enable;
applyYTitleToQwt(); applyAxisTitleToQwt( axis );
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RiuQwtPlotWidget::setYTitleEnabled( bool enable )
{
m_yAxisTitleEnabled = enable;
applyYTitleToQwt();
} }
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
@@ -219,24 +217,16 @@ QwtInterval RiuQwtPlotWidget::axisRange( QwtPlot::Axis axis )
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
/// ///
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
void RiuQwtPlotWidget::setXRange( double min, double max, QwtPlot::Axis axis ) void RiuQwtPlotWidget::setAxisRange( QwtPlot::Axis axis, double min, double max )
{ {
setAxisScale( axis, min, max ); // Note: Especially the Y-axis may be inverted
} if ( axisScaleEngine( axis )->testAttribute( QwtScaleEngine::Inverted ) )
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RiuQwtPlotWidget::setYRange( double min, double max )
{
// Note: Y-axis may be inverted
if ( axisScaleEngine( QwtPlot::yLeft )->testAttribute( QwtScaleEngine::Inverted ) )
{ {
setAxisScale( QwtPlot::yLeft, max, min ); setAxisScale( axis, max, min );
} }
else else
{ {
setAxisScale( QwtPlot::yLeft, min, max ); setAxisScale( axis, min, max );
} }
} }
@@ -251,24 +241,33 @@ void RiuQwtPlotWidget::setAxisInverted( QwtPlot::Axis axis )
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
/// ///
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
void RiuQwtPlotWidget::setYAxisLabelsAndTicksEnabled( bool enable ) void RiuQwtPlotWidget::setAxisLabelsAndTicksEnabled( QwtPlot::Axis axis, bool enable )
{ {
this->axisScaleDraw( QwtPlot::yLeft )->enableComponent( QwtAbstractScaleDraw::Ticks, enable ); this->axisScaleDraw( axis )->enableComponent( QwtAbstractScaleDraw::Ticks, enable );
this->axisScaleDraw( QwtPlot::yLeft )->enableComponent( QwtAbstractScaleDraw::Labels, enable ); this->axisScaleDraw( axis )->enableComponent( QwtAbstractScaleDraw::Labels, enable );
} }
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
/// ///
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
void RiuQwtPlotWidget::enableXGridLines( bool majorGridLines, bool minorGridLines ) void RiuQwtPlotWidget::enableGridLines( QwtPlot::Axis axis, bool majorGridLines, bool minorGridLines )
{ {
QwtPlotItemList plotItems = this->itemList( QwtPlotItem::Rtti_PlotGrid ); QwtPlotItemList plotItems = this->itemList( QwtPlotItem::Rtti_PlotGrid );
for ( QwtPlotItem* plotItem : plotItems ) for ( QwtPlotItem* plotItem : plotItems )
{ {
QwtPlotGrid* grid = static_cast<QwtPlotGrid*>( plotItem ); QwtPlotGrid* grid = static_cast<QwtPlotGrid*>( plotItem );
grid->setXAxis( QwtPlot::xTop ); if ( axis == QwtPlot::xTop || axis == QwtPlot::xBottom )
grid->enableX( majorGridLines ); {
grid->enableXMin( minorGridLines ); grid->setXAxis( axis );
grid->enableX( majorGridLines );
grid->enableXMin( minorGridLines );
}
else
{
grid->setYAxis( axis );
grid->enableY( majorGridLines );
grid->enableYMin( minorGridLines );
}
grid->setMajorPen( Qt::lightGray, 1.0, Qt::SolidLine ); grid->setMajorPen( Qt::lightGray, 1.0, Qt::SolidLine );
grid->setMinorPen( Qt::lightGray, 1.0, Qt::DashLine ); grid->setMinorPen( Qt::lightGray, 1.0, Qt::DashLine );
} }
@@ -277,28 +276,8 @@ void RiuQwtPlotWidget::enableXGridLines( bool majorGridLines, bool minorGridLine
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
/// ///
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
void RiuQwtPlotWidget::enableYGridLines( bool majorGridLines, bool minorGridLines ) void RiuQwtPlotWidget::setMajorAndMinorTickIntervals(
{ QwtPlot::Axis axis, double majorTickInterval, double minorTickInterval, double minValue, double maxValue )
QwtPlotItemList plotItems = this->itemList( QwtPlotItem::Rtti_PlotGrid );
for ( QwtPlotItem* plotItem : plotItems )
{
QwtPlotGrid* grid = static_cast<QwtPlotGrid*>( plotItem );
grid->setYAxis( QwtPlot::yLeft );
grid->enableY( majorGridLines );
grid->enableYMin( minorGridLines );
grid->setMajorPen( Qt::lightGray, 1.0, Qt::SolidLine );
grid->setMinorPen( Qt::lightGray, 1.0, Qt::DashLine );
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RiuQwtPlotWidget::setMajorAndMinorTickIntervals( double majorTickInterval,
double minorTickInterval,
double minValue,
double maxValue,
QwtPlot::Axis axis /*= QwtPlot::xTop */ )
{ {
RiuQwtLinearScaleEngine* scaleEngine = dynamic_cast<RiuQwtLinearScaleEngine*>( this->axisScaleEngine( axis ) ); RiuQwtLinearScaleEngine* scaleEngine = dynamic_cast<RiuQwtLinearScaleEngine*>( this->axisScaleEngine( axis ) );
if ( scaleEngine ) if ( scaleEngine )
@@ -315,9 +294,9 @@ void RiuQwtPlotWidget::setMajorAndMinorTickIntervals( double majorTickInt
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
/// ///
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
void RiuQwtPlotWidget::setAutoTickIntervalCounts( int maxMajorTickIntervalCount, void RiuQwtPlotWidget::setAutoTickIntervalCounts( QwtPlot::Axis axis,
int maxMinorTickIntervalCount, int maxMajorTickIntervalCount,
QwtPlot::Axis axis ) int maxMinorTickIntervalCount )
{ {
this->setAxisMaxMajor( axis, maxMajorTickIntervalCount ); this->setAxisMaxMajor( axis, maxMajorTickIntervalCount );
this->setAxisMaxMinor( axis, maxMinorTickIntervalCount ); this->setAxisMaxMinor( axis, maxMinorTickIntervalCount );
@@ -329,9 +308,9 @@ void RiuQwtPlotWidget::setAutoTickIntervalCounts( int maxMajorTickInte
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
/// ///
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
double RiuQwtPlotWidget::getCurrentMajorTickInterval() const double RiuQwtPlotWidget::majorTickInterval( QwtPlot::Axis axis ) const
{ {
QwtScaleDiv scaleDiv = this->axisScaleDiv( QwtPlot::xTop ); QwtScaleDiv scaleDiv = this->axisScaleDiv( axis );
QList<double> majorTicks = scaleDiv.ticks( QwtScaleDiv::MajorTick ); QList<double> majorTicks = scaleDiv.ticks( QwtScaleDiv::MajorTick );
if ( majorTicks.size() < 2 ) return 0.0; if ( majorTicks.size() < 2 ) return 0.0;
@@ -341,7 +320,7 @@ double RiuQwtPlotWidget::getCurrentMajorTickInterval() const
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
/// ///
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
double RiuQwtPlotWidget::getCurrentMinorTickInterval() const double RiuQwtPlotWidget::minorTickInterval( QwtPlot::Axis axis ) const
{ {
QwtScaleDiv scaleDiv = this->axisScaleDiv( QwtPlot::xTop ); QwtScaleDiv scaleDiv = this->axisScaleDiv( QwtPlot::xTop );
QList<double> minorTicks = scaleDiv.ticks( QwtScaleDiv::MinorTick ); QList<double> minorTicks = scaleDiv.ticks( QwtScaleDiv::MinorTick );
@@ -584,15 +563,18 @@ void RiuQwtPlotWidget::hideEvent( QHideEvent* event )
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
/// ///
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
void RiuQwtPlotWidget::applyYTitleToQwt() void RiuQwtPlotWidget::applyAxisTitleToQwt( QwtPlot::Axis axis )
{ {
QString titleToApply = m_yAxisTitleEnabled ? m_yAxisTitle : QString( "" ); QString titleToApply = m_axisTitlesEnabled[axis] ? m_axisTitles[axis] : QString( "" );
QwtText axisTitleY = axisTitle( QwtPlot::yLeft ); QwtText axisTitle = this->axisTitle( QwtPlot::yLeft );
if ( titleToApply != axisTitleY.text() ) if ( titleToApply != axisTitle.text() )
{ {
axisTitleY.setText( titleToApply ); axisTitle.setText( titleToApply );
setAxisTitle( QwtPlot::yLeft, axisTitleY ); setAxisTitle( axis, axisTitle );
setMinimumWidth( defaultMinimumWidth() + axisExtent( QwtPlot::yLeft ) ); if ( axis == QwtPlot::yLeft || axis == QwtPlot::yRight )
{
setMinimumWidth( defaultMinimumWidth() + axisExtent( axis ) );
}
} }
} }

View File

@@ -58,36 +58,33 @@ public:
bool isChecked() const; bool isChecked() const;
int fontSize() const; int axisTitleFontSize( QwtPlot::Axis axis ) const;
void setFontSize( int fontSize ); int axisValueFontSize( QwtPlot::Axis axis ) const;
void setAxisFontsAndAlignment( QwtPlot::Axis,
int titleFontSize,
int valueFontSize,
bool titleBold = false,
Qt::AlignmentFlag alignment = Qt::AlignRight );
void setEnabledAxes( const std::set<QwtPlot::Axis> enabledAxes ); void setEnabledAxes( const std::set<QwtPlot::Axis> enabledAxes );
void setXTitle( const QString& title ); void setAxisTitleText( QwtPlot::Axis axis, const QString& title );
void setYTitle( const QString& title ); void setAxisTitleEnabled( QwtPlot::Axis axis, bool enable );
void setYTitleEnabled( bool enable );
QwtInterval axisRange( QwtPlot::Axis axis ); QwtInterval axisRange( QwtPlot::Axis axis );
void setXRange( double min, double max, QwtPlot::Axis axis = QwtPlot::xTop ); void setAxisRange( QwtPlot::Axis axis, double min, double max );
void setYRange( double min, double max );
void setAxisInverted( QwtPlot::Axis axis ); void setAxisInverted( QwtPlot::Axis axis );
void setYAxisLabelsAndTicksEnabled( bool enable ); void setAxisLabelsAndTicksEnabled( QwtPlot::Axis axis, bool enable );
void enableXGridLines( bool majorGridLines, bool minorGridLines ); void enableGridLines( QwtPlot::Axis axis, bool majorGridLines, bool minorGridLines );
void enableYGridLines( bool majorGridLines, bool minorGridLines );
void setMajorAndMinorTickIntervals( double majorTickInterval, void setMajorAndMinorTickIntervals(
double minorTickInterval, QwtPlot::Axis axis, double majorTickInterval, double minorTickInterval, double minValue, double maxValue );
double minValue, void setAutoTickIntervalCounts( QwtPlot::Axis axis, int maxMajorTickIntervalCount, int maxMinorTickIntervalCount );
double maxValue, double majorTickInterval( QwtPlot::Axis axis ) const;
QwtPlot::Axis axis = QwtPlot::xTop ); double minorTickInterval( QwtPlot::Axis axis ) const;
void setAutoTickIntervalCounts( int maxMajorTickIntervalCount,
int maxMinorTickIntervalCount,
QwtPlot::Axis axis = QwtPlot::xTop );
double getCurrentMajorTickInterval() const;
double getCurrentMinorTickInterval() const;
int axisExtent( QwtPlot::Axis axis ) const; int axisExtent( QwtPlot::Axis axis ) const;
@@ -107,7 +104,7 @@ protected:
bool eventFilter( QObject* watched, QEvent* event ) override; bool eventFilter( QObject* watched, QEvent* event ) override;
void hideEvent( QHideEvent* event ) override; void hideEvent( QHideEvent* event ) override;
void applyYTitleToQwt(); void applyAxisTitleToQwt( QwtPlot::Axis axis );
virtual void selectPoint( QwtPlotCurve* curve, int pointNumber ); virtual void selectPoint( QwtPlotCurve* curve, int pointNumber );
virtual void clearPointSelection(); virtual void clearPointSelection();
@@ -126,11 +123,11 @@ private:
void onAxisSelected( QwtScaleWidget* scale, bool toggleItemInSelection ); void onAxisSelected( QwtScaleWidget* scale, bool toggleItemInSelection );
private: private:
caf::PdmPointer<caf::PdmObject> m_plotOwner; caf::PdmPointer<caf::PdmObject> m_plotOwner;
QPoint m_clickPosition; QPoint m_clickPosition;
QString m_yAxisTitle; std::map<QwtPlot::Axis, QString> m_axisTitles;
bool m_yAxisTitleEnabled; std::map<QwtPlot::Axis, bool> m_axisTitlesEnabled;
QPointer<QwtPlotPicker> m_plotPicker; QPointer<QwtPlotPicker> m_plotPicker;
struct CurveColors struct CurveColors
{ {