Qwt User's Guide: qwt_polar_magnifier.cpp Source File

Qwt User's Guide 6.3.0

Loading...
Searching...
No Matches
qwt_polar_magnifier.cpp
1/******************************************************************************
2 * QwtPolar Widget Library
3 * Copyright (C) 2008 Uwe Rathmann
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the Qwt License, Version 1.0
7 *****************************************************************************/
8
9#include "qwt_polar_magnifier.h"
10#include "qwt_polar_plot.h"
11#include "qwt_polar_canvas.h"
12#include "qwt_scale_div.h"
13#include "qwt_point_polar.h"
14
15#include <qevent.h>
16
17class QwtPolarMagnifier::PrivateData
18{
19 public:
20 PrivateData()
21 : unzoomKey( Qt::Key_Home )
22 , unzoomKeyModifiers( Qt::NoModifier )
23 {
24 }
25
26 int unzoomKey;
27 int unzoomKeyModifiers;
28};
29
34QwtPolarMagnifier::QwtPolarMagnifier( QwtPolarCanvas* canvas )
35 : QwtMagnifier( canvas )
36{
37 m_data = new PrivateData();
38}
39
41QwtPolarMagnifier::~QwtPolarMagnifier()
42{
43 delete m_data;
44}
45
54 void QwtPolarMagnifier::setUnzoomKey( int key, int modifiers )
55{
56 m_data->unzoomKey = key;
57 m_data->unzoomKeyModifiers = modifiers;
58}
59
67 void QwtPolarMagnifier::getUnzoomKey( int& key, int& modifiers ) const
68{
69 key = m_data->unzoomKey;
70 modifiers = m_data->unzoomKeyModifiers;
71}
72
74 QwtPolarCanvas* QwtPolarMagnifier::canvas()
75{
76 return qobject_cast< QwtPolarCanvas* >( parent() );
77}
78
80 const QwtPolarCanvas* QwtPolarMagnifier::canvas() const
81{
82 return qobject_cast< QwtPolarCanvas* >( parent() );
83}
84
86 QwtPolarPlot* QwtPolarMagnifier::plot()
87{
88 QwtPolarCanvas* c = canvas();
89 if ( c )
90 return c->plot();
91
92 return NULL;
93}
94
96 const QwtPolarPlot* QwtPolarMagnifier::plot() const
97{
98 const QwtPolarCanvas* c = canvas();
99 if ( c )
100 return c->plot();
101
102 return NULL;
103}
104
110 void QwtPolarMagnifier::widgetKeyPressEvent( QKeyEvent* event )
111{
112 const int key = event->key();
113 const int state = event->modifiers();
114
115 if ( key == m_data->unzoomKey &&
116 state == m_data->unzoomKeyModifiers )
117 {
118 unzoom();
119 return;
120 }
121
122 QwtMagnifier::widgetKeyPressEvent( event );
123}
124
129 void QwtPolarMagnifier::rescale( double factor )
130{
131 factor = qAbs( factor );
132 if ( factor == 1.0 || factor == 0.0 )
133 return;
134
135 QwtPolarPlot* plt = plot();
136 if ( plt == NULL )
137 return;
138
139 QwtPointPolar zoomPos;
140 double newZoomFactor = plt->zoomFactor() * factor;
141
142 if ( newZoomFactor >= 1.0 )
143 newZoomFactor = 1.0;
144 else
145 zoomPos = plt->zoomPos();
146
147 const bool autoReplot = plt->autoReplot();
148 plt->setAutoReplot( false );
149
150 plt->zoom( zoomPos, newZoomFactor );
151
152 plt->setAutoReplot( autoReplot );
153 plt->replot();
154}
155
157 void QwtPolarMagnifier::unzoom()
158{
159 QwtPolarPlot* plt = plot();
160
161 const bool autoReplot = plt->autoReplot();
162 plt->setAutoReplot( false );
163
164 plt->unzoom();
165
166 plt->setAutoReplot( autoReplot );
167 plt->replot();
168}
169
170#include "moc_qwt_polar_magnifier.cpp"
QwtMagnifier
QwtMagnifier provides zooming, by magnifying in steps.
Definition qwt_magnifier.h:28
QwtMagnifier::widgetKeyPressEvent
virtual void widgetKeyPressEvent(QKeyEvent *)
Definition qwt_magnifier.cpp:473
QwtPointPolar
A point in polar coordinates.
Definition qwt_point_polar.h:29
QwtPolarCanvas
Canvas of a QwtPolarPlot.
Definition qwt_polar_canvas.h:28
QwtPolarCanvas::plot
QwtPolarPlot * plot()
Definition qwt_polar_canvas.cpp:97
QwtPolarMagnifier::widgetKeyPressEvent
virtual void widgetKeyPressEvent(QKeyEvent *) override
Definition qwt_polar_magnifier.cpp:110
QwtPolarMagnifier::getUnzoomKey
void getUnzoomKey(int &key, int &modifiers) const
Definition qwt_polar_magnifier.cpp:67
QwtPolarMagnifier::unzoom
void unzoom()
Unzoom the plot widget.
Definition qwt_polar_magnifier.cpp:157
QwtPolarMagnifier::setUnzoomKey
void setUnzoomKey(int key, int modifiers)
Definition qwt_polar_magnifier.cpp:54
QwtPolarMagnifier::rescale
virtual void rescale(double factor) override
Definition qwt_polar_magnifier.cpp:129
QwtPolarMagnifier::plot
QwtPolarPlot * plot()
Definition qwt_polar_magnifier.cpp:86
QwtPolarMagnifier::canvas
QwtPolarCanvas * canvas()
Definition qwt_polar_magnifier.cpp:74
QwtPolarMagnifier::QwtPolarMagnifier
QwtPolarMagnifier(QwtPolarCanvas *)
Definition qwt_polar_magnifier.cpp:34
QwtPolarMagnifier::~QwtPolarMagnifier
virtual ~QwtPolarMagnifier()
Destructor.
Definition qwt_polar_magnifier.cpp:41
QwtPolarPlot
A plotting widget, displaying a polar coordinate system.
Definition qwt_polar_plot.h:47
QwtPolarPlot::zoomPos
QwtPointPolar zoomPos() const
Definition qwt_polar_plot.cpp:682
QwtPolarPlot::unzoom
void unzoom()
Definition qwt_polar_plot.cpp:668
QwtPolarPlot::replot
virtual void replot()
Redraw the plot.
Definition qwt_polar_plot.cpp:899
QwtPolarPlot::zoom
void zoom(const QwtPointPolar &, double factor)
Translate and in/decrease the zoom factor.
Definition qwt_polar_plot.cpp:651
QwtPolarPlot::zoomFactor
double zoomFactor() const
Definition qwt_polar_plot.cpp:691
QwtPolarPlot::autoReplot
bool autoReplot() const
Definition qwt_polar_plot.cpp:348
QwtPolarPlot::setAutoReplot
void setAutoReplot(bool tf=true)
Set or reset the autoReplot option.
Definition qwt_polar_plot.cpp:342