Changeset 8127 in ntrip for trunk/BNC/qwtpolar/qwt_polar_plot.cpp
- Timestamp:
- May 10, 2017, 3:20:54 PM (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/BNC/qwtpolar/qwt_polar_plot.cpp
r4272 r8127 16 16 #include <qwt_round_scale_draw.h> 17 17 #include <qwt_legend.h> 18 #include <qwt_legend_item.h>19 18 #include <qwt_dyngrid_layout.h> 20 19 #include <qpointer.h> … … 35 34 public: 36 35 ScaleData(): 36 isValid( false ), 37 37 scaleEngine( NULL ) 38 38 { … … 53 53 int maxMinor; 54 54 55 bool isValid; 56 55 57 QwtScaleDiv scaleDiv; 56 58 QwtScaleEngine *scaleEngine; … … 70 72 QPointer<QwtTextLabel> titleLabel; 71 73 QPointer<QwtPolarCanvas> canvas; 72 QPointer<Qwt Legend> legend;74 QPointer<QwtAbstractLegend> legend; 73 75 double azimuthOrigin; 74 76 … … 183 185 QwtPolarLayout::setLegendPosition() 184 186 */ 185 void QwtPolarPlot::insertLegend( Qwt Legend *legend,187 void QwtPolarPlot::insertLegend( QwtAbstractLegend *legend, 186 188 QwtPolarPlot::LegendPosition pos, double ratio ) 187 189 { 188 190 d_data->layout->setLegendPosition( pos, ratio ); 191 189 192 if ( legend != d_data->legend ) 190 193 { … … 196 199 if ( d_data->legend ) 197 200 { 198 if ( pos != ExternalLegend ) 201 connect( this, 202 SIGNAL( legendDataChanged( 203 const QVariant &, const QList<QwtLegendData> & ) ), 204 d_data->legend, 205 SLOT( updateLegend( 206 const QVariant &, const QList<QwtLegendData> & ) ) 207 ); 208 209 if ( d_data->legend->parent() != this ) 210 d_data->legend->setParent( this ); 211 212 updateLegend(); 213 214 QwtLegend *lgd = qobject_cast<QwtLegend *>( legend ); 215 if ( lgd ) 199 216 { 200 if ( d_data->legend->parent() != this ) 201 d_data->legend->setParent( this ); 202 } 203 204 const QwtPolarItemList& itmList = itemList(); 205 for ( QwtPolarItemIterator it = itmList.begin(); 206 it != itmList.end(); ++it ) 207 { 208 ( *it )->updateLegend( d_data->legend ); 209 } 210 211 QwtDynGridLayout *tl = qobject_cast<QwtDynGridLayout *>( 212 d_data->legend->contentsWidget()->layout() ); 213 214 if ( tl ) 215 { 216 switch( d_data->layout->legendPosition() ) 217 switch ( d_data->layout->legendPosition() ) 217 218 { 218 219 case LeftLegend: 219 220 case RightLegend: 220 tl->setMaxCols( 1 ); // 1 column: align vertical 221 { 222 if ( lgd->maxColumns() == 0 ) 223 lgd->setMaxColumns( 1 ); // 1 column: align vertical 221 224 break; 222 225 } 223 226 case TopLegend: 224 227 case BottomLegend: 225 tl->setMaxCols( 0 ); // unlimited 228 { 229 lgd->setMaxColumns( 0 ); // unlimited 226 230 break; 227 228 case ExternalLegend:231 } 232 default: 229 233 break; 230 234 } 231 235 } 232 } 233 } 236 237 } 238 } 239 234 240 updateLayout(); 241 } 242 243 /*! 244 Emit legendDataChanged() for all plot item 245 246 \sa QwtPlotItem::legendData(), legendDataChanged() 247 */ 248 void QwtPolarPlot::updateLegend() 249 { 250 const QwtPolarItemList& itmList = itemList(); 251 for ( QwtPolarItemIterator it = itmList.begin(); 252 it != itmList.end(); ++it ) 253 { 254 updateLegend( *it ); 255 } 256 } 257 258 /*! 259 Emit legendDataChanged() for a plot item 260 261 \param plotItem Plot item 262 \sa QwtPlotItem::legendData(), legendDataChanged() 263 */ 264 void QwtPolarPlot::updateLegend( const QwtPolarItem *plotItem ) 265 { 266 if ( plotItem == NULL ) 267 return; 268 269 QList<QwtLegendData> legendData; 270 271 if ( plotItem->testItemAttribute( QwtPolarItem::Legend ) ) 272 legendData = plotItem->legendData(); 273 274 const QVariant itemInfo = itemToInfo( const_cast< QwtPolarItem *>( plotItem) ); 275 Q_EMIT legendDataChanged( itemInfo, legendData ); 235 276 } 236 277 … … 239 280 \sa insertLegend() 240 281 */ 241 Qwt Legend *QwtPolarPlot::legend()282 QwtAbstractLegend *QwtPolarPlot::legend() 242 283 { 243 284 return d_data->legend; … … 248 289 \sa insertLegend() 249 290 */ 250 const Qwt Legend *QwtPolarPlot::legend() const291 const QwtAbstractLegend *QwtPolarPlot::legend() const 251 292 { 252 293 return d_data->legend; 253 }254 255 /*!256 Called internally when the legend has been clicked on.257 Emits a legendClicked() signal.258 */259 void QwtPolarPlot::legendItemClicked()260 {261 if ( d_data->legend && sender()->isWidgetType() )262 {263 QwtPolarItem *plotItem = static_cast< QwtPolarItem* >(264 d_data->legend->find( qobject_cast<const QWidget *>( sender() ) ) );265 if ( plotItem )266 Q_EMIT legendClicked( plotItem );267 }268 }269 270 /*!271 Called internally when the legend has been checked272 Emits a legendClicked() signal.273 */274 void QwtPolarPlot::legendItemChecked( bool on )275 {276 if ( d_data->legend && sender()->isWidgetType() )277 {278 QwtPolarItem *plotItem = static_cast< QwtPolarItem* >(279 d_data->legend->find( qobject_cast<const QWidget *>( sender() ) ) );280 if ( plotItem )281 Q_EMIT legendChecked( plotItem, on );282 }283 294 } 284 295 … … 389 400 return; 390 401 391 if ( maxMinor < 0 ) 392 maxMinor = 0; 393 if ( maxMinor > 100 ) 394 maxMinor = 100; 402 maxMinor = qBound( 0, maxMinor, 100 ); 395 403 396 404 ScaleData &scaleData = d_data->scaleData[scaleId]; … … 399 407 { 400 408 scaleData.maxMinor = maxMinor; 401 scaleData. scaleDiv.invalidate();409 scaleData.isValid = false; 402 410 autoRefresh(); 403 411 } … … 429 437 return; 430 438 431 if ( maxMajor < 1 ) 432 maxMajor = 1; 433 if ( maxMajor > 1000 ) 434 maxMajor = 10000; 439 maxMajor = qBound( 1, maxMajor, 10000 ); 435 440 436 441 ScaleData &scaleData = d_data->scaleData[scaleId]; … … 438 443 { 439 444 scaleData.maxMajor = maxMajor; 440 scaleData. scaleDiv.invalidate();445 scaleData.isValid = false; 441 446 autoRefresh(); 442 447 } … … 477 482 scaleData.scaleEngine = scaleEngine; 478 483 479 scaleData. scaleDiv.invalidate();484 scaleData.isValid = false; 480 485 481 486 autoRefresh(); … … 527 532 ScaleData &scaleData = d_data->scaleData[scaleId]; 528 533 529 scaleData. scaleDiv.invalidate();534 scaleData.isValid = false; 530 535 531 536 scaleData.minValue = min; … … 551 556 552 557 scaleData.scaleDiv = scaleDiv; 558 scaleData.isValid = true; 553 559 scaleData.doAutoScale = false; 554 560 … … 732 738 { 733 739 map.setPaintInterval( d_data->azimuthOrigin, 734 d_data->azimuthOrigin + M_2PI );740 d_data->azimuthOrigin + 2 * M_PI ); 735 741 } 736 742 else … … 820 826 scaleData.maxMajor = 8; 821 827 828 scaleData.isValid = false; 829 822 830 scaleData.scaleEngine = new QwtLinearScaleEngine; 823 scaleData.scaleDiv.invalidate();824 831 } 825 832 d_data->zoomFactor = 1.0; … … 858 865 } 859 866 860 if ( d_data->legend && 861 d_data->layout->legendPosition() != ExternalLegend ) 862 { 863 if ( d_data->legend->itemCount() > 0 ) 864 { 865 d_data->legend->setGeometry( d_data->layout->legendRect().toRect() ); 867 if ( d_data->legend ) 868 { 869 if ( d_data->legend->isEmpty() ) 870 { 871 d_data->legend->hide(); 872 } 873 else 874 { 875 const QRectF legendRect = d_data->layout->legendRect(); 876 d_data->legend->setGeometry( legendRect.toRect() ); 866 877 d_data->legend->show(); 867 878 } 868 else869 d_data->legend->hide();870 879 } 871 880 … … 1054 1063 d.scaleEngine->autoScale( d.maxMajor, 1055 1064 minValue, maxValue, stepSize ); 1056 d. scaleDiv.invalidate();1057 } 1058 1059 if ( !d. scaleDiv.isValid())1065 d.isValid = false; 1066 } 1067 1068 if ( !d.isValid ) 1060 1069 { 1061 1070 d.scaleDiv = d.scaleEngine->divideScale( 1062 1071 minValue, maxValue, d.maxMajor, d.maxMinor, stepSize ); 1072 d.isValid = true; 1063 1073 } 1064 1074 … … 1270 1280 return d_data->layout; 1271 1281 } 1282 1283 /*! 1284 \brief Attach/Detach a plot item 1285 1286 \param plotItem Plot item 1287 \param on When true attach the item, otherwise detach it 1288 */ 1289 void QwtPolarPlot::attachItem( QwtPolarItem *plotItem, bool on ) 1290 { 1291 if ( on ) 1292 insertItem( plotItem ); 1293 else 1294 removeItem( plotItem ); 1295 1296 Q_EMIT itemAttached( plotItem, on ); 1297 1298 if ( plotItem->testItemAttribute( QwtPolarItem::Legend ) ) 1299 { 1300 // the item wants to be represented on the legend 1301 1302 if ( on ) 1303 { 1304 updateLegend( plotItem ); 1305 } 1306 else 1307 { 1308 const QVariant itemInfo = itemToInfo( plotItem ); 1309 Q_EMIT legendDataChanged( itemInfo, QList<QwtLegendData>() ); 1310 } 1311 } 1312 1313 if ( autoReplot() ) 1314 update(); 1315 } 1316 1317 /*! 1318 \brief Build an information, that can be used to identify 1319 a plot item on the legend. 1320 1321 The default implementation simply wraps the plot item 1322 into a QVariant object. When overloading itemToInfo() 1323 usually infoToItem() needs to reimplemeted too. 1324 1325 \code 1326 QVariant itemInfo; 1327 qVariantSetValue( itemInfo, plotItem ); 1328 \endcode 1329 1330 \param plotItem Plot item 1331 \sa infoToItem() 1332 */ 1333 QVariant QwtPolarPlot::itemToInfo( QwtPolarItem *plotItem ) const 1334 { 1335 QVariant itemInfo; 1336 qVariantSetValue( itemInfo, plotItem ); 1337 1338 return itemInfo; 1339 } 1340 1341 /*! 1342 \brief Identify the plot item according to an item info object, 1343 that has bee generated from itemToInfo(). 1344 1345 The default implementation simply tries to unwrap a QwtPlotItem 1346 pointer: 1347 1348 \code 1349 if ( itemInfo.canConvert<QwtPlotItem *>() ) 1350 return qvariant_cast<QwtPlotItem *>( itemInfo ); 1351 \endcode 1352 \param itemInfo Plot item 1353 \return A plot item, when successful, otherwise a NULL pointer. 1354 \sa itemToInfo() 1355 */ 1356 QwtPolarItem *QwtPolarPlot::infoToItem( const QVariant &itemInfo ) const 1357 { 1358 if ( itemInfo.canConvert<QwtPolarItem *>() ) 1359 return qvariant_cast<QwtPolarItem *>( itemInfo ); 1360 1361 return NULL; 1362 }
Note:
See TracChangeset
for help on using the changeset viewer.