# HG changeset patch # User John W. Eaton # Date 1425054252 18000 # Node ID 815db217f6f45077d88830ba7233ceebd2016594 # Parent 60fe3ef12bb0c1ea0a08b52ac9f0db4640286b3d provide autoscale option for Qt plotting (bug #44307) * Canvas.h, Canvas.cc (Canvas::autoAxes): New pure virtual function. (Canvas::canvasAutoAxes): New function. (autoscale_axes): New static function. (Canvas::canvasMouseDoubleClickEvent, Canvas::canvasMousePressEvent): Use it. * Figure.h, Figure.cc (Figure::createFigureToolBarAndMenuBar): Add autoscale button to window. (Figure::autoAxes): New function. * GLCanvas.h, GLCanvas.cc (GLCanvas::autoAxes): New function. diff -r 60fe3ef12bb0 -r 815db217f6f4 libgui/graphics/Canvas.cc --- a/libgui/graphics/Canvas.cc Thu Feb 26 18:57:58 2015 -0600 +++ b/libgui/graphics/Canvas.cc Fri Feb 27 11:24:12 2015 -0500 @@ -199,6 +199,44 @@ } } +static void +autoscale_axes (axes::properties& ap) +{ + ap.clear_zoom_stack (); + + ap.set_xlimmode ("auto"); + ap.set_ylimmode ("auto"); + ap.set_zlimmode ("auto"); +} + +void Canvas::canvasAutoAxes (const graphics_handle& handle) +{ + gh_manager::auto_lock lock; + + graphics_object go = gh_manager::get_object (handle); + + if (go.valid_object ()) + { + figure::properties& fp = Utils::properties
(go); + + graphics_handle ah = fp.get_currentaxes (); + + graphics_object ax = gh_manager::get_object (ah); + + if (ax.valid_object ()) + { + axes::properties& ap = Utils::properties (ax); + + if (ap.handlevisibility_is ("on") && ap.is_visible ()) + { + autoscale_axes (ap); + + redraw (true); + } + } + } +} + void Canvas::canvasPaintEvent (void) { if (! m_redrawBlocked) @@ -397,10 +435,7 @@ axes::properties& ap = Utils::properties (axesObj); - ap.clear_zoom_stack (); - ap.set_xlimmode ("auto"); - ap.set_ylimmode ("auto"); - ap.set_zlimmode ("auto"); + autoscale_axes (ap); } } @@ -573,10 +608,7 @@ axes::properties& ap = Utils::properties (axesObj); - ap.clear_zoom_stack (); - ap.set_xlimmode ("auto"); - ap.set_ylimmode ("auto"); - ap.set_zlimmode ("auto"); + autoscale_axes (ap); } break; diff -r 60fe3ef12bb0 -r 815db217f6f4 libgui/graphics/Canvas.h --- a/libgui/graphics/Canvas.h Thu Feb 26 18:57:58 2015 -0600 +++ b/libgui/graphics/Canvas.h Fri Feb 27 11:24:12 2015 -0500 @@ -67,6 +67,7 @@ virtual void toggleAxes (const graphics_handle& handle) = 0; virtual void toggleGrid (const graphics_handle& handle) = 0; + virtual void autoAxes (const graphics_handle& handle) = 0; protected: virtual void draw (const graphics_handle& handle) = 0; @@ -85,6 +86,7 @@ void canvasToggleAxes (const graphics_handle& handle); void canvasToggleGrid (const graphics_handle& handle); + void canvasAutoAxes (const graphics_handle& handle); void canvasPaintEvent (void); void canvasMouseDoubleClickEvent (QMouseEvent* event); void canvasMouseMoveEvent (QMouseEvent* event); diff -r 60fe3ef12bb0 -r 815db217f6f4 libgui/graphics/Figure.cc --- a/libgui/graphics/Figure.cc Thu Feb 26 18:57:58 2015 -0600 +++ b/libgui/graphics/Figure.cc Fri Feb 27 11:24:12 2015 -0500 @@ -282,6 +282,10 @@ connect (toggle_grid, SIGNAL (triggered (void)), this, SLOT (toggleGrid (void))); + QAction *auto_axes = m_figureToolBar->addAction ("Autoscale"); + connect (auto_axes, SIGNAL (triggered (void)), + this, SLOT (autoAxes (void))); + m_menuBar = new MenuBar (win); win->setMenuBar (m_menuBar); @@ -860,4 +864,12 @@ canvas->toggleGrid (m_handle); } +void Figure::autoAxes (void) +{ + Canvas* canvas = m_container->canvas (m_handle); + + if (canvas) + canvas->autoAxes (m_handle); +} + }; // namespace QtHandles diff -r 60fe3ef12bb0 -r 815db217f6f4 libgui/graphics/Figure.h --- a/libgui/graphics/Figure.h Thu Feb 26 18:57:58 2015 -0600 +++ b/libgui/graphics/Figure.h Fri Feb 27 11:24:12 2015 -0500 @@ -123,6 +123,7 @@ void updateContainer (void); void toggleAxes (void); void toggleGrid (void); + void autoAxes (void); signals: void asyncUpdate (void); diff -r 60fe3ef12bb0 -r 815db217f6f4 libgui/graphics/GLCanvas.cc --- a/libgui/graphics/GLCanvas.cc Thu Feb 26 18:57:58 2015 -0600 +++ b/libgui/graphics/GLCanvas.cc Fri Feb 27 11:24:12 2015 -0500 @@ -70,6 +70,11 @@ canvasToggleGrid (gh); } +void GLCanvas::autoAxes (const graphics_handle& gh) +{ + canvasAutoAxes (gh); +} + graphics_object GLCanvas::selectFromAxes (const graphics_object& ax, const QPoint& pt) { diff -r 60fe3ef12bb0 -r 815db217f6f4 libgui/graphics/GLCanvas.h --- a/libgui/graphics/GLCanvas.h Thu Feb 26 18:57:58 2015 -0600 +++ b/libgui/graphics/GLCanvas.h Fri Feb 27 11:24:12 2015 -0500 @@ -39,6 +39,7 @@ void draw (const graphics_handle& handle); void toggleAxes (const graphics_handle& handle); void toggleGrid (const graphics_handle& handle); + void autoAxes (const graphics_handle& handle); void drawZoomBox (const QPoint& p1, const QPoint& p2); void resize (int /* x */, int /* y */, int /* width */, int /* height */) { }