From f0206222bf7c74244b7da5fed9357b0a1db4c857 Mon Sep 17 00:00:00 2001 From: epa Date: Thu, 7 Dec 2006 12:37:28 +0000 Subject: [PATCH] Add automatic fitall in plot2d after edit the cutlines --- src/Plot2d/Plot2d_ViewFrame.cxx | 34 ++++++++++++++++++++++++++++++++- src/Plot2d/Plot2d_ViewFrame.h | 11 +++++++++++ 2 files changed, 44 insertions(+), 1 deletion(-) diff --git a/src/Plot2d/Plot2d_ViewFrame.cxx b/src/Plot2d/Plot2d_ViewFrame.cxx index 00ba07afa..55b805bfc 100755 --- a/src/Plot2d/Plot2d_ViewFrame.cxx +++ b/src/Plot2d/Plot2d_ViewFrame.cxx @@ -41,6 +41,7 @@ #include #include #include +#include #include #include @@ -54,6 +55,8 @@ #define DEFAULT_MARKER_SIZE 9 // default marker size #define MIN_RECT_SIZE 11 // min sensibility area size +#define FITALL_EVENT ( QEvent::User + 9999 ) + const char* imageZoomCursor[] = { "32 32 3 1", ". c None", @@ -787,6 +790,13 @@ void Plot2d_ViewFrame::updateLegend( const Plot2d_Prs* prs ) */ void Plot2d_ViewFrame::fitAll() { + // Postpone fitAll operation until QwtPlot geometry + // has been fully defined + if ( !myPlot->polished() ){ + QApplication::postEvent( this, new QCustomEvent( FITALL_EVENT ) ); + return; + } + QwtDiMap xMap1 = myPlot->canvasMap( QwtPlot::xBottom ); myPlot->setAxisAutoScale( QwtPlot::yLeft ); @@ -1588,7 +1598,8 @@ bool Plot2d_ViewFrame::isYLogEnabled() const Constructor */ Plot2d_Plot2d::Plot2d_Plot2d( QWidget* parent ) - : QwtPlot( parent ) + : QwtPlot( parent ), + myIsPolished( false ) { // outline enableOutline( true ); @@ -1768,6 +1779,16 @@ bool Plot2d_Plot2d::existMarker( const QwtSymbol::Style typeMarker, const QColor return false; } +/*! + Sets the flag saying that QwtPlot geometry has been fully defined. +*/ +void Plot2d_Plot2d::polish() +{ + QwtPlot::polish(); + myIsPolished = true; +} + + /*! Creates presentation of object Default implementation is empty @@ -2048,3 +2069,14 @@ void Plot2d_ViewFrame::onZoomOut() { this->incrementalZoom( -INCREMENT_FOR_OP, -INCREMENT_FOR_OP ); } + +/*! + Schedules a FitAll operation by putting it to the application's + event queue. This ensures that other important events (show, resize, etc.) + are processed first. +*/ +void Plot2d_ViewFrame::customEvent( QCustomEvent* ce ) +{ + if ( ce->type() == FITALL_EVENT ) + fitAll(); +} diff --git a/src/Plot2d/Plot2d_ViewFrame.h b/src/Plot2d/Plot2d_ViewFrame.h index 6a6aaf171..108cbd957 100755 --- a/src/Plot2d/Plot2d_ViewFrame.h +++ b/src/Plot2d/Plot2d_ViewFrame.h @@ -25,6 +25,7 @@ class Plot2d_Plot2d; class Plot2d_Prs; +class QCustomEvent; typedef QIntDict CurveDict; @@ -148,6 +149,9 @@ public slots: void onZoomIn(); void onZoomOut(); +protected: + virtual void customEvent( QCustomEvent* ); + protected slots: void plotMousePressed( const QMouseEvent& ); void plotMouseMoved( const QMouseEvent& ); @@ -183,6 +187,7 @@ protected: class Plot2d_Plot2d : public QwtPlot { + Q_OBJECT public: Plot2d_Plot2d( QWidget* parent ); @@ -199,11 +204,17 @@ public: virtual QSizePolicy sizePolicy() const; virtual QSize minimumSizeHint() const; + bool polished() const { return myIsPolished; } + +public slots: + virtual void polish(); + protected: bool existMarker( const QwtSymbol::Style typeMarker, const QColor& color, const Qt::PenStyle typeLine ); protected: QValueList myColors; + bool myIsPolished; }; #endif -- 2.39.2