From: asl Date: Wed, 23 Nov 2005 14:04:09 +0000 (+0000) Subject: PAL9764 - names and units aren't displayed in Plot2d X-Git-Tag: BR_3_1_0_deb~46 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=5b4ad9253833dee561a539c97059f6e7862e1f6e;p=modules%2Fgui.git PAL9764 - names and units aren't displayed in Plot2d --- diff --git a/src/Plot2d/Plot2d_Curve.cxx b/src/Plot2d/Plot2d_Curve.cxx index 25ed5ac6d..b4c8e68d9 100755 --- a/src/Plot2d/Plot2d_Curve.cxx +++ b/src/Plot2d/Plot2d_Curve.cxx @@ -54,6 +54,11 @@ Plot2d_Curve& Plot2d_Curve::operator=( const Plot2d_Curve& curve ) return *this; } +QString Plot2d_Curve::getTableTitle() const +{ + return QString(); +} + /*! Sets curve's horizontal title */ diff --git a/src/Plot2d/Plot2d_Curve.h b/src/Plot2d/Plot2d_Curve.h index 703a9cdf0..004d6d761 100755 --- a/src/Plot2d/Plot2d_Curve.h +++ b/src/Plot2d/Plot2d_Curve.h @@ -29,6 +29,8 @@ public: Plot2d_Curve( const Plot2d_Curve& curve ); Plot2d_Curve& operator= ( const Plot2d_Curve& curve ); + virtual QString getTableTitle() const; + void setHorTitle( const QString& title ); QString getHorTitle() const; void setVerTitle( const QString& title ); diff --git a/src/Plot2d/Plot2d_ViewFrame.cxx b/src/Plot2d/Plot2d_ViewFrame.cxx index 82d172176..5b39633bc 100755 --- a/src/Plot2d/Plot2d_ViewFrame.cxx +++ b/src/Plot2d/Plot2d_ViewFrame.cxx @@ -618,6 +618,7 @@ void Plot2d_ViewFrame::displayCurve( Plot2d_Curve* curve, bool update ) myPlot->setCurveStyle( curveKey, QwtCurve::Spline ); myPlot->setCurveData( curveKey, curve->horData(), curve->verData(), curve->nbPoints() ); } + updateTitles(); if ( update ) myPlot->replot(); } @@ -1759,3 +1760,60 @@ void Plot2d_ViewFrame::copyPreferences( Plot2d_ViewFrame* vf ) myYMode = vf->myYMode; mySecondY = vf->mySecondY; } + +/*! + Updates titles according to curves +*/ +#define BRACKETIZE(x) QString( "[ " ) + x + QString( " ]" ) +void Plot2d_ViewFrame::updateTitles() +{ + QIntDictIterator it( myCurves ); + QStringList aXTitles; + QStringList aYTitles; + QStringList aXUnits; + QStringList aYUnits; + QStringList aTables; + int i = 0; + while ( it.current() ) { + // collect titles and units from all curves... + QString xTitle = it.current()->getHorTitle().stripWhiteSpace(); + QString yTitle = it.current()->getVerTitle().stripWhiteSpace(); + QString xUnits = it.current()->getHorUnits().stripWhiteSpace(); + QString yUnits = it.current()->getVerUnits().stripWhiteSpace(); + + aYTitles.append( yTitle ); + if ( aXTitles.find( xTitle ) == aXTitles.end() ) + aXTitles.append( xTitle ); + if ( aXUnits.find( xUnits ) == aXUnits.end() ) + aXUnits.append( xUnits ); + if ( aYUnits.find( yUnits ) == aYUnits.end() ) + aYUnits.append( yUnits ); + + QString aName = it.current()->getTableTitle(); + if( !aName.isEmpty() && aTables.find( aName ) == aTables.end() ) + aTables.append( aName ); + + ++it; + ++i; + } + // ... and update plot 2d view + QString xUnits, yUnits; + if ( aXUnits.count() == 1 && !aXUnits[0].isEmpty() ) + xUnits = BRACKETIZE( aXUnits[0] ); + if ( aYUnits.count() == 1 && !aYUnits[0].isEmpty()) + yUnits = BRACKETIZE( aYUnits[0] ); + QString xTitle, yTitle; + if ( aXTitles.count() == 1 && aXUnits.count() == 1 ) + xTitle = aXTitles[0]; + if ( aYTitles.count() == 1 ) + yTitle = aYTitles[0]; + + if ( !xTitle.isEmpty() && !xUnits.isEmpty() ) + xTitle += " "; + if ( !yTitle.isEmpty() && !yUnits.isEmpty() ) + yTitle += " "; + + setTitle( myXTitleEnabled, xTitle + xUnits, XTitle, true ); + setTitle( myYTitleEnabled, yTitle + yUnits, YTitle, true ); + setTitle( true, aTables.join("; "), MainTitle, true ); +} diff --git a/src/Plot2d/Plot2d_ViewFrame.h b/src/Plot2d/Plot2d_ViewFrame.h index 6cc8ff364..e7d6a753d 100755 --- a/src/Plot2d/Plot2d_ViewFrame.h +++ b/src/Plot2d/Plot2d_ViewFrame.h @@ -95,6 +95,7 @@ protected: int testOperation( const QMouseEvent& ); void readPreferences(); void writePreferences(); + void updateTitles(); QString getInfo( const QPoint& pnt ); virtual void wheelEvent( QWheelEvent* ); diff --git a/src/SPlot2d/SPlot2d_Curve.cxx b/src/SPlot2d/SPlot2d_Curve.cxx index 3a1c8cece..212067fd7 100644 --- a/src/SPlot2d/SPlot2d_Curve.cxx +++ b/src/SPlot2d/SPlot2d_Curve.cxx @@ -59,3 +59,40 @@ SPlot2d_Curve& SPlot2d_Curve::operator=( const SPlot2d_Curve& curve ) return *this; } +Handle(SALOME_InteractiveObject) SPlot2d_Curve::getIO() const +{ + return myIO; +} + +void SPlot2d_Curve::setIO( const Handle(SALOME_InteractiveObject)& io ) +{ + myIO = io; +} + +bool SPlot2d_Curve::hasTableIO() const +{ + return !myTableIO.IsNull(); +} + +Handle(SALOME_InteractiveObject) SPlot2d_Curve::getTableIO() const +{ + return myTableIO; +} + +void SPlot2d_Curve::setTableIO( const Handle(SALOME_InteractiveObject)& io ) +{ + myTableIO = io; +} + +bool SPlot2d_Curve::hasIO() const +{ + return !myIO.IsNull(); +} + +QString SPlot2d_Curve::getTableTitle() const +{ + QString title; + if( hasTableIO() ) + title = getTableIO()->getName(); + return title; +} diff --git a/src/SPlot2d/SPlot2d_Curve.h b/src/SPlot2d/SPlot2d_Curve.h index 28eff47b0..7eaf395a4 100644 --- a/src/SPlot2d/SPlot2d_Curve.h +++ b/src/SPlot2d/SPlot2d_Curve.h @@ -26,13 +26,15 @@ public: SPlot2d_Curve( const SPlot2d_Curve& curve ); SPlot2d_Curve& operator= ( const SPlot2d_Curve& curve ); - virtual bool hasIO() { return !myIO.IsNull(); } - virtual Handle(SALOME_InteractiveObject) getIO() const { return myIO; } - virtual void setIO( const Handle(SALOME_InteractiveObject)& io ) { myIO = io; } + virtual QString getTableTitle() const; - virtual bool hasTableIO() { return !myTableIO.IsNull(); } - virtual Handle(SALOME_InteractiveObject) getTableIO() const { return myTableIO; } - virtual void setTableIO( const Handle(SALOME_InteractiveObject)& io ) { myTableIO = io; } + virtual bool hasIO() const; + virtual Handle(SALOME_InteractiveObject) getIO() const; + virtual void setIO( const Handle(SALOME_InteractiveObject)& ); + + virtual bool hasTableIO() const; + virtual Handle(SALOME_InteractiveObject) getTableIO() const; + virtual void setTableIO( const Handle(SALOME_InteractiveObject)& ); private: Handle(SALOME_InteractiveObject) myIO;