Changeset 11158 in ntrip for trunk/BNC/qwt/qwt_plot_panner.cpp
- Timestamp:
- Nov 3, 2026, 10:53:35 AM (3 weeks ago)
- File:
-
- 1 edited
-
trunk/BNC/qwt/qwt_plot_panner.cpp (modified) (20 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/BNC/qwt/qwt_plot_panner.cpp
r9383 r11158 1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*-*****************************1 /****************************************************************************** 2 2 * Qwt Widget Library 3 3 * Copyright (C) 1997 Josef Wilgen … … 11 11 #include "qwt_scale_div.h" 12 12 #include "qwt_plot.h" 13 #include "qwt_scale_map.h" 13 14 #include "qwt_painter.h" 15 14 16 #include <qbitmap.h> 15 17 #include <qstyle.h> 16 18 #include <qstyleoption.h> 19 #include <qpainter.h> 17 20 #include <qpainterpath.h> 18 21 22 static QBitmap qwtBorderMask( const QWidget* canvas, const QSize& size ) 23 { 19 24 #if QT_VERSION >= 0x050000 20 #if QT_VERSION < 0x050100 21 #define QWT_USE_WINDOW_HANDLE 1 25 const qreal pixelRatio = QwtPainter::devicePixelRatio( canvas ); 22 26 #endif 23 #endif24 25 #ifdef QWT_USE_WINDOW_HANDLE26 #include <qwindow.h>27 #endif28 29 static QBitmap qwtBorderMask( const QWidget *canvas, const QSize &size )30 {31 #if QT_VERSION >= 0x05000032 qreal pixelRatio = 1.0;33 34 #ifdef QWT_USE_WINDOW_HANDLE35 pixelRatio = canvas->windowHandle()->devicePixelRatio();36 #else37 pixelRatio = canvas->devicePixelRatio();38 #endif39 #endif40 27 41 28 const QRect r( 0, 0, size.width(), size.height() ); … … 44 31 45 32 ( void )QMetaObject::invokeMethod( 46 const_cast< QWidget *>( canvas ), "borderPath", Qt::DirectConnection,33 const_cast< QWidget* >( canvas ), "borderPath", Qt::DirectConnection, 47 34 Q_RETURN_ARG( QPainterPath, borderPath ), Q_ARG( QRect, r ) ); 48 35 … … 53 40 54 41 #if QT_VERSION >= 0x050000 55 QBitmap mask( size * pixelRatio );42 QBitmap mask( size* pixelRatio ); 56 43 mask.setDevicePixelRatio( pixelRatio ); 57 44 #else … … 67 54 68 55 #if QT_VERSION >= 0x050000 69 QImage image( size * pixelRatio, QImage::Format_ARGB32_Premultiplied );56 QImage image( size* pixelRatio, QImage::Format_ARGB32_Premultiplied ); 70 57 image.setDevicePixelRatio( pixelRatio ); 71 58 #else … … 94 81 const QVariant frameWidth = canvas->property( "frameWidth" ); 95 82 96 if ( borderRadius.type() == QVariant::Double 97 && frameWidth.type() == QVariant::Int ) 83 if ( borderRadius.canConvert< double >() && frameWidth.canConvert< int >() ) 98 84 { 99 const double br = borderRadius. toDouble();100 const int fw = frameWidth. toInt();85 const double br = borderRadius.value< double >(); 86 const int fw = frameWidth.value< int >(); 101 87 102 88 if ( br > 0.0 && fw > 0 ) … … 121 107 class QwtPlotPanner::PrivateData 122 108 { 123 public: 109 public: 124 110 PrivateData() 125 111 { 126 for ( int axis = 0; axis < Qwt Plot::axisCnt; axis++ )112 for ( int axis = 0; axis < QwtAxis::AxisPositions; axis++ ) 127 113 isAxisEnabled[axis] = true; 128 114 } 129 115 130 bool isAxisEnabled[Qwt Plot::axisCnt];116 bool isAxisEnabled[QwtAxis::AxisPositions]; 131 117 }; 132 118 133 119 /*! 134 \brief A panner for the canvas of a QwtPlot 135 136 The panner is enabled for all axes 137 138 \param canvas Plot canvas to pan, also the parent object 139 140 \sa setAxisEnabled() 141 */ 142 QwtPlotPanner::QwtPlotPanner( QWidget *canvas ):143 QwtPanner( canvas ) 144 { 145 d_data = new PrivateData();120 \brief A panner for the canvas of a QwtPlot 121 122 The panner is enabled for all axes 123 124 \param canvas Plot canvas to pan, also the parent object 125 126 \sa setAxisEnabled() 127 */ 128 QwtPlotPanner::QwtPlotPanner( QWidget* canvas ) 129 : QwtPanner( canvas ) 130 { 131 m_data = new PrivateData(); 146 132 147 133 connect( this, SIGNAL(panned(int,int)), … … 152 138 QwtPlotPanner::~QwtPlotPanner() 153 139 { 154 delete d_data;140 delete m_data; 155 141 } 156 142 … … 161 147 result of panning. All other axes will remain unchanged. 162 148 163 \param axis Axis, see QwtPlot::Axis149 \param axisId Axis id 164 150 \param on On/Off 165 151 166 152 \sa isAxisEnabled(), moveCanvas() 167 */ 168 void QwtPlotPanner::setAxisEnabled( int axis, bool on )169 { 170 if ( axis >= 0 && axis < QwtPlot::axisCnt)171 d_data->isAxisEnabled[axis] = on;153 */ 154 void QwtPlotPanner::setAxisEnabled( QwtAxisId axisId, bool on ) 155 { 156 if ( QwtAxis::isValid( axisId ) ) 157 m_data->isAxisEnabled[axisId] = on; 172 158 } 173 159 … … 175 161 Test if an axis is enabled 176 162 177 \param axis Axis, see QwtPlot::Axis163 \param axisId Axis 178 164 \return True, if the axis is enabled 179 165 180 166 \sa setAxisEnabled(), moveCanvas() 181 */ 182 bool QwtPlotPanner::isAxisEnabled( int axis) const183 { 184 if ( axis >= 0 && axis < QwtPlot::axisCnt)185 return d_data->isAxisEnabled[axis];167 */ 168 bool QwtPlotPanner::isAxisEnabled( QwtAxisId axisId ) const 169 { 170 if ( QwtAxis::isValid( axisId ) ) 171 return m_data->isAxisEnabled[axisId]; 186 172 187 173 return true; … … 189 175 190 176 //! Return observed plot canvas 191 QWidget *QwtPlotPanner::canvas()177 QWidget* QwtPlotPanner::canvas() 192 178 { 193 179 return parentWidget(); … … 195 181 196 182 //! Return Observed plot canvas 197 const QWidget *QwtPlotPanner::canvas() const183 const QWidget* QwtPlotPanner::canvas() const 198 184 { 199 185 return parentWidget(); … … 201 187 202 188 //! Return plot widget, containing the observed plot canvas 203 QwtPlot *QwtPlotPanner::plot()204 { 205 QWidget *w = canvas();189 QwtPlot* QwtPlotPanner::plot() 190 { 191 QWidget* w = canvas(); 206 192 if ( w ) 207 193 w = w->parentWidget(); 208 194 209 return qobject_cast<QwtPlot *>( w );195 return qobject_cast< QwtPlot* >( w ); 210 196 } 211 197 212 198 //! Return plot widget, containing the observed plot canvas 213 const QwtPlot *QwtPlotPanner::plot() const214 { 215 const QWidget *w = canvas();199 const QwtPlot* QwtPlotPanner::plot() const 200 { 201 const QWidget* w = canvas(); 216 202 if ( w ) 217 203 w = w->parentWidget(); 218 204 219 return qobject_cast<const QwtPlot *>( w );205 return qobject_cast< const QwtPlot* >( w ); 220 206 } 221 207 … … 227 213 228 214 \sa QwtPanner::panned() 229 */ 215 */ 230 216 void QwtPlotPanner::moveCanvas( int dx, int dy ) 231 217 { … … 233 219 return; 234 220 235 QwtPlot *plot = this->plot();221 QwtPlot* plot = this->plot(); 236 222 if ( plot == NULL ) 237 223 return; … … 240 226 plot->setAutoReplot( false ); 241 227 242 for ( int axis = 0; axis < QwtPlot::axisCnt; axis++ ) 243 { 244 if ( !d_data->isAxisEnabled[axis] ) 245 continue; 246 247 const QwtScaleMap map = plot->canvasMap( axis ); 248 249 const double p1 = map.transform( plot->axisScaleDiv( axis ).lowerBound() ); 250 const double p2 = map.transform( plot->axisScaleDiv( axis ).upperBound() ); 251 252 double d1, d2; 253 if ( axis == QwtPlot::xBottom || axis == QwtPlot::xTop ) 228 for ( int axisPos = 0; axisPos < QwtAxis::AxisPositions; axisPos++ ) 229 { 254 230 { 255 d1 = map.invTransform( p1 - dx ); 256 d2 = map.invTransform( p2 - dx ); 231 const QwtAxisId axisId( axisPos ); 232 233 if ( !m_data->isAxisEnabled[axisId] ) 234 continue; 235 236 const QwtScaleMap map = plot->canvasMap( axisId ); 237 238 const double p1 = map.transform( plot->axisScaleDiv( axisId ).lowerBound() ); 239 const double p2 = map.transform( plot->axisScaleDiv( axisId ).upperBound() ); 240 241 double d1, d2; 242 if ( QwtAxis::isXAxis( axisPos ) ) 243 { 244 d1 = map.invTransform( p1 - dx ); 245 d2 = map.invTransform( p2 - dx ); 246 } 247 else 248 { 249 d1 = map.invTransform( p1 - dy ); 250 d2 = map.invTransform( p2 - dy ); 251 } 252 253 plot->setAxisScale( axisId, d1, d2 ); 257 254 } 258 else259 {260 d1 = map.invTransform( p1 - dy );261 d2 = map.invTransform( p2 - dy );262 }263 264 plot->setAxisScale( axis, d1, d2 );265 255 } 266 256 … … 274 264 \return Mask as bitmap 275 265 \sa QwtPlotCanvas::borderPath() 276 */ 266 */ 277 267 QBitmap QwtPlotPanner::contentsMask() const 278 268 { … … 288 278 QPixmap QwtPlotPanner::grab() const 289 279 { 290 const QWidget *cv = canvas();280 const QWidget* cv = canvas(); 291 281 if ( cv && cv->inherits( "QGLWidget" ) ) 292 282 { … … 297 287 298 288 QPainter painter( &pm ); 299 const_cast<QwtPlot *>( plot() )->drawCanvas( &painter );289 const_cast< QwtPlot* >( plot() )->drawCanvas( &painter ); 300 290 301 291 return pm; … … 305 295 } 306 296 297 #include "moc_qwt_plot_panner.cpp"
Note:
See TracChangeset
for help on using the changeset viewer.
