From 100e7d3e036fdd2c8f51c4420499c9271d49b50d Mon Sep 17 00:00:00 2001 From: sln Date: Wed, 7 Nov 2007 14:31:44 +0000 Subject: [PATCH] New methods for correct updating ofg titles defined by user through "Settings" dialog --- src/Plot2d/Plot2d_ViewFrame.cxx | 120 +++++++++++++++++--------------- src/Plot2d/Plot2d_ViewFrame.h | 22 +++--- 2 files changed, 74 insertions(+), 68 deletions(-) diff --git a/src/Plot2d/Plot2d_ViewFrame.cxx b/src/Plot2d/Plot2d_ViewFrame.cxx index 01d9eb0b1..ba6048eca 100755 --- a/src/Plot2d/Plot2d_ViewFrame.cxx +++ b/src/Plot2d/Plot2d_ViewFrame.cxx @@ -16,6 +16,7 @@ // // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com // + #include "Plot2d_ViewFrame.h" #include "Plot2d_Prs.h" @@ -32,7 +33,7 @@ #include "SUIT_ResourceMgr.h" #include "SUIT_Application.h" -#include "qapplication.h" +#include #include #include #include @@ -56,8 +57,9 @@ #define DEFAULT_MARKER_SIZE 9 // default marker size #define MIN_RECT_SIZE 11 // min sensibility area size -#define X11_COORD_MIN -16384 -#define X11_COORD_MAX 16384 +#define X11_COORD_MIN -16384 + +#define X11_COORD_MAX 16384 const char* imageZoomCursor[] = { "32 32 3 1", @@ -139,10 +141,9 @@ QString Plot2d_ViewFrame::myPrefTitle = ""; QString Plot2d_ViewFrame::myPrefXTitle = ""; QString Plot2d_ViewFrame::myPrefYTitle = ""; -bool Plot2d_ViewFrame::myTitleAutoGeneration = true; -bool Plot2d_ViewFrame::myXTitleAutoGeneration = true; -bool Plot2d_ViewFrame::myYTitleAutoGeneration = true; - +bool Plot2d_ViewFrame::myPrefTitleChangedByUser = false; +bool Plot2d_ViewFrame::myXPrefTitleChangedByUser = false; +bool Plot2d_ViewFrame::myYPrefTitleChangedByUser = false; /*! Constructor @@ -161,7 +162,9 @@ Plot2d_ViewFrame::Plot2d_ViewFrame( QWidget* parent, const QString& title ) myXGridMinorEnabled( false ), myYGridMinorEnabled( false ), myY2GridMinorEnabled( false ), myXGridMaxMajor( 8 ), myYGridMaxMajor( 8 ), myY2GridMaxMajor( 8 ), myXGridMaxMinor( 5 ), myYGridMaxMinor( 5 ), myY2GridMaxMinor( 5 ), - myXMode( 0 ), myYMode( 0 ), mySecondY( false ) + myXMode( 0 ), myYMode( 0 ), mySecondY( false ), + myTitleAutoUpdate( true ), myXTitleAutoUpdate( true ), myYTitleAutoUpdate( true ), + myTitleChangedByUser( false ), myXTitleChangedByUser( false ), myYTitleChangedByUser( false ) { /* Plot 2d View */ QVBoxLayout* aLayout = new QVBoxLayout( this ); @@ -399,12 +402,21 @@ void Plot2d_ViewFrame::writePreferences() resMgr->setValue( "Plot2d", "VerScaleMode", myYMode ); - if ( !myTitleAutoGeneration ) + if ( myTitleChangedByUser ) + { myPrefTitle = myTitle; - if ( !myXTitleAutoGeneration ) + myPrefTitleChangedByUser = true; + } + if ( myXTitleChangedByUser ) + { myPrefXTitle = myXTitle; - if ( !myYTitleAutoGeneration ) + myXPrefTitleChangedByUser = true; + } + if ( myYTitleChangedByUser ) + { myPrefYTitle = myYTitle; + myYPrefTitleChangedByUser = true; + } } /*! @@ -1018,18 +1030,14 @@ void Plot2d_ViewFrame::onSettings() bool isTileChanged = dlg->getXTitle() != myXTitle; setTitle( dlg->isXTitleEnabled(), dlg->getXTitle(), XTitle, false ); if ( isTileChanged ) - { - myXTitleAutoGeneration = false; - emit titleChangedByUser( XTitle ); - } + myXTitleChangedByUser = true; + // vertical left axis title isTileChanged = dlg->getYTitle() != myYTitle; setTitle( dlg->isYTitleEnabled(), dlg->getYTitle(), YTitle, false ); if ( isTileChanged ) - { - myYTitleAutoGeneration = false; - emit titleChangedByUser( YTitle ); - } + myYTitleChangedByUser = true; + if (mySecondY) // vertical right axis title setTitle( dlg->isY2TitleEnabled(), dlg->getY2Title(), Y2Title, false ); @@ -1037,10 +1045,8 @@ void Plot2d_ViewFrame::onSettings() isTileChanged = dlg->getMainTitle() != myTitle; setTitle( dlg->isMainTitleEnabled(), dlg->getMainTitle(), MainTitle, true ); if ( isTileChanged ) - { - myTitleAutoGeneration = false; - emit titleChangedByUser( MainTitle ); - } + myTitleChangedByUser = true; + // curve type if ( myCurveType != dlg->getCurveType() ) { setCurveType( dlg->getCurveType(), false ); @@ -2187,11 +2193,11 @@ void Plot2d_ViewFrame::updateTitles() if ( !yTitle.isEmpty() && !yUnits.isEmpty() ) yTitle += " "; - if ( myXTitleAutoGeneration ) + if ( !isTitleChangedByUser( XTitle ) && myXTitleAutoUpdate ) setTitle( myXTitleEnabled, xTitle + xUnits, XTitle, true ); - if ( myYTitleAutoGeneration ) + if ( !isTitleChangedByUser( YTitle ) && myYTitleAutoUpdate ) setTitle( myYTitleEnabled, yTitle + yUnits, YTitle, true ); - if ( myTitleAutoGeneration ) + if ( !isTitleChangedByUser( MainTitle ) && myTitleAutoUpdate ) setTitle( true, aTables.join("; "), MainTitle, true ); } @@ -2371,62 +2377,62 @@ void Plot2d_ViewFrame::onZoomOut() this->incrementalZoom( -INCREMENT_FOR_OP, -INCREMENT_FOR_OP ); } -/*! - Specifies whether plot title must be generated automatically using curves titles -*/ -void Plot2d_ViewFrame::setTitleAutoGeneration( const bool toGenerate, const bool update ) -{ - setTitleAutoGeneration( toGenerate, MainTitle, update ); -} - /*! Verifies whether plot title must be generated automatically using curves titles */ -bool Plot2d_ViewFrame::getTitleAutoGeneration() +bool Plot2d_ViewFrame::isTitleChangedByUser( const ObjectType type ) { - return myTitleAutoGeneration; + switch ( type ) + { + case MainTitle: + return myPrefTitleChangedByUser || myTitleChangedByUser; + case XTitle: + return myXPrefTitleChangedByUser || myXTitleChangedByUser; + case YTitle: + return myYPrefTitleChangedByUser || myYTitleChangedByUser; + default: + return false; + } } /*! - Specifies whether plot title must be generated automatically using curves titles + Sets flag for automatic updates of titles in accordance with current set of curves + ( updateTitles method). You should call setAutoUpdateTitle( ObjType, false ) + if your application set titles itself and they can not be updated automatically. + By default titles are updated automatically. */ -void Plot2d_ViewFrame::setTitleAutoGeneration( const bool toGenerate, - const ObjectType type, - const bool update ) + +void Plot2d_ViewFrame::setAutoUpdateTitle( const ObjectType type, const bool upd ) { - switch ( type ) + switch ( type ) { case MainTitle: - myTitleAutoGeneration = toGenerate; - break; + myTitleAutoUpdate = upd; case XTitle: - myXTitleAutoGeneration = toGenerate; - break; + myXTitleAutoUpdate = upd; case YTitle: - myYTitleAutoGeneration = toGenerate; - break; + myYTitleAutoUpdate = upd; default: - return; + break; } - if ( update ) - updateTitles(); } /*! - Verifies whether plot title must be generated automatically using curves titles + Gets flag for automatic updates of titles in accordance with current set of curves + ( updateTitles method) */ -bool Plot2d_ViewFrame::getTitleAutoGeneration( const ObjectType type ) +bool Plot2d_ViewFrame::getAutoUpdateTitle( const ObjectType type ) const { - switch ( type ) + switch ( type ) { case MainTitle: - return myTitleAutoGeneration; + return myTitleAutoUpdate; case XTitle: - return myXTitleAutoGeneration; + return myXTitleAutoUpdate; case YTitle: - return myYTitleAutoGeneration; + return myYTitleAutoUpdate; default: - return false; + return true; } } diff --git a/src/Plot2d/Plot2d_ViewFrame.h b/src/Plot2d/Plot2d_ViewFrame.h index 932a47794..1c8c2596f 100755 --- a/src/Plot2d/Plot2d_ViewFrame.h +++ b/src/Plot2d/Plot2d_ViewFrame.h @@ -58,8 +58,6 @@ public: void updateTitles(); void setTitle( const QString& title ); QString getTitle() const { return myTitle; } - void setTitleAutoGeneration( const bool toGenerate, const bool update = true ); - bool getTitleAutoGeneration(); void displayCurve( Plot2d_Curve* curve, bool update = false ); void displayCurves( const curveList& curves, bool update = false ); void eraseCurve ( Plot2d_Curve* curve, bool update = false ); @@ -101,10 +99,8 @@ public: bool y2MinorEnabled, const int y2MinorMax, bool update = true ); void setTitle( bool enabled, const QString& title, ObjectType type, bool update = true ); QString getTitle( ObjectType type ) const; - void setTitleAutoGeneration( const bool toGenerate, - const ObjectType type, - const bool update = true ); - static bool getTitleAutoGeneration( const ObjectType type ); + + bool isTitleChangedByUser( const ObjectType type ); void setFont( const QFont& font, ObjectType type, bool update = true ); void setHorScaleMode( const int mode, bool update = true ); @@ -130,6 +126,9 @@ public: void incrementalPan ( const int incrX, const int incrY ); void incrementalZoom( const int incrX, const int incrY ); + void setAutoUpdateTitle( const ObjectType type, const bool upd ); + bool getAutoUpdateTitle( const ObjectType type ) const; + protected: int testOperation( const QMouseEvent& ); void readPreferences(); @@ -169,8 +168,6 @@ signals: void curveDisplayed( Plot2d_Curve* ); void curveErased( Plot2d_Curve* ); - void titleChangedByUser( const int theObjectType ); - protected: Plot2d_Plot2d* myPlot; int myOperation; @@ -191,14 +188,17 @@ protected: int myXMode, myYMode; double myXDistance, myYDistance, myYDistance2; bool mySecondY; + + bool myTitleAutoUpdate, myXTitleAutoUpdate, myYTitleAutoUpdate; + bool myTitleChangedByUser, myXTitleChangedByUser, myYTitleChangedByUser; static QString myPrefTitle; static QString myPrefXTitle; static QString myPrefYTitle; - static bool myTitleAutoGeneration; - static bool myXTitleAutoGeneration; - static bool myYTitleAutoGeneration; + static bool myPrefTitleChangedByUser; + static bool myXPrefTitleChangedByUser; + static bool myYPrefTitleChangedByUser; }; class Plot2d_Plot2d : public QwtPlot -- 2.39.2