Changeset 11158 in ntrip for trunk/BNC/qwt/qwt_symbol.cpp
- Timestamp:
- Nov 3, 2026, 10:53:35 AM (3 weeks ago)
- File:
-
- 1 edited
-
trunk/BNC/qwt/qwt_symbol.cpp (modified) (66 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/BNC/qwt/qwt_symbol.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_painter.h" 12 12 #include "qwt_graphic.h" 13 #include <qapplication.h> 13 #include "qwt_math.h" 14 14 15 #include <qpainter.h> 15 16 #include <qpainterpath.h> 16 17 #include <qpixmap.h> 17 18 #include <qpaintengine.h> 18 #include <qmath.h>19 19 #ifndef QWT_NO_SVG 20 20 #include <qsvgrenderer.h> … … 32 32 } 33 33 34 static QwtGraphic qwtPathGraphic( const QPainterPath &path,35 const QPen &pen, const QBrush& brush )34 static QwtGraphic qwtPathGraphic( const QPainterPath& path, 35 const QPen& pen, const QBrush& brush ) 36 36 { 37 37 QwtGraphic graphic; … … 48 48 49 49 static inline QRectF qwtScaledBoundingRect( 50 const QwtGraphic &graphic, const QSizeF size )50 const QwtGraphic& graphic, const QSizeF size ) 51 51 { 52 52 QSizeF scaledSize = size; … … 67 67 } 68 68 69 static inline void qwtDrawPixmapSymbols( QPainter *painter,70 const QPointF *points, int numPoints, const QwtSymbol&symbol )69 static inline void qwtDrawPixmapSymbols( QPainter* painter, 70 const QPointF* points, int numPoints, const QwtSymbol& symbol ) 71 71 { 72 72 QSize size = symbol.size(); … … 102 102 #ifndef QWT_NO_SVG 103 103 104 static inline void qwtDrawSvgSymbols( QPainter *painter,105 const QPointF *points, int numPoints,106 QSvgRenderer *renderer, const QwtSymbol&symbol )104 static inline void qwtDrawSvgSymbols( QPainter* painter, 105 const QPointF* points, int numPoints, 106 QSvgRenderer* renderer, const QwtSymbol& symbol ) 107 107 { 108 108 if ( renderer == NULL || !renderer->isValid() ) … … 139 139 #endif 140 140 141 static inline void qwtDrawGraphicSymbols( QPainter *painter,142 const QPointF *points, int numPoints, const QwtGraphic&graphic,143 const QwtSymbol &symbol )141 static inline void qwtDrawGraphicSymbols( QPainter* painter, 142 const QPointF* points, int numPoints, const QwtGraphic& graphic, 143 const QwtSymbol& symbol ) 144 144 { 145 145 const QRectF pointRect = graphic.controlPointRect(); … … 178 178 } 179 179 180 static inline void qwtDrawEllipseSymbols( QPainter *painter,181 const QPointF *points, int numPoints, const QwtSymbol&symbol )180 static inline void qwtDrawEllipseSymbols( QPainter* painter, 181 const QPointF* points, int numPoints, const QwtSymbol& symbol ) 182 182 { 183 183 painter->setBrush( symbol.brush() ); … … 220 220 } 221 221 222 static inline void qwtDrawRectSymbols( QPainter *painter,223 const QPointF *points, int numPoints, const QwtSymbol&symbol )222 static inline void qwtDrawRectSymbols( QPainter* painter, 223 const QPointF* points, int numPoints, const QwtSymbol& symbol ) 224 224 { 225 225 const QSize size = symbol.size(); … … 265 265 } 266 266 267 static inline void qwtDrawDiamondSymbols( QPainter *painter,268 const QPointF *points, int numPoints, const QwtSymbol&symbol )267 static inline void qwtDrawDiamondSymbols( QPainter* painter, 268 const QPointF* points, int numPoints, const QwtSymbol& symbol ) 269 269 { 270 270 const QSize size = symbol.size(); … … 300 300 for ( int i = 0; i < numPoints; i++ ) 301 301 { 302 const QPointF &pos = points[i];302 const QPointF& pos = points[i]; 303 303 304 304 const double x1 = pos.x() - 0.5 * size.width(); … … 319 319 320 320 static inline void qwtDrawTriangleSymbols( 321 QPainter *painter, QwtTriangle::Type type,322 const QPointF *points, int numPoints,323 const QwtSymbol &symbol )321 QPainter* painter, QwtTriangle::Type type, 322 const QPointF* points, int numPoints, 323 const QwtSymbol& symbol ) 324 324 { 325 325 const QSize size = symbol.size(); … … 338 338 if ( doAlign ) 339 339 { 340 sw2 = qFloor( sw2 );341 sh2 = qFloor( sh2 );340 sw2 = std::floor( sw2 ); 341 sh2 = std::floor( sh2 ); 342 342 } 343 343 344 344 QPolygonF triangle( 3 ); 345 QPointF *trianglePoints = triangle.data();345 QPointF* trianglePoints = triangle.data(); 346 346 347 347 for ( int i = 0; i < numPoints; i++ ) 348 348 { 349 const QPointF &pos = points[i];349 const QPointF& pos = points[i]; 350 350 351 351 double x = pos.x(); … … 423 423 424 424 static inline void qwtDrawLineSymbols( 425 QPainter *painter, int orientations,426 const QPointF *points, int numPoints, const QwtSymbol&symbol )425 QPainter* painter, int orientations, 426 const QPointF* points, int numPoints, const QwtSymbol& symbol ) 427 427 { 428 428 const QSize size = symbol.size(); … … 442 442 if ( QwtPainter::roundingAlignment( painter ) ) 443 443 { 444 const int sw = qFloor( size.width() ); 445 const int sh = qFloor( size.height() ); 444 const int sw = qwtFloor( size.width() ); 445 const int sh = qwtFloor( size.height() ); 446 446 const int sw2 = size.width() / 2; 447 447 const int sh2 = size.height() / 2; … … 492 492 } 493 493 494 static inline void qwtDrawXCrossSymbols( QPainter *painter,495 const QPointF *points, int numPoints, const QwtSymbol&symbol )494 static inline void qwtDrawXCrossSymbols( QPainter* painter, 495 const QPointF* points, int numPoints, const QwtSymbol& symbol ) 496 496 { 497 497 const QSize size = symbol.size(); … … 516 516 for ( int i = 0; i < numPoints; i++ ) 517 517 { 518 const QPointF &pos = points[i];518 const QPointF& pos = points[i]; 519 519 520 520 const int x = qRound( pos.x() ); … … 539 539 for ( int i = 0; i < numPoints; i++ ) 540 540 { 541 const QPointF &pos = points[i];541 const QPointF& pos = points[i]; 542 542 543 543 const double x1 = pos.x() - sw2; … … 552 552 } 553 553 554 static inline void qwtDrawStar1Symbols( QPainter *painter,555 const QPointF *points, int numPoints, const QwtSymbol&symbol )554 static inline void qwtDrawStar1Symbols( QPainter* painter, 555 const QPointF* points, int numPoints, const QwtSymbol& symbol ) 556 556 { 557 557 const QSize size = symbol.size(); … … 575 575 QwtPainter::drawLine( painter, 576 576 qRound( r.left() + d1 ), qRound( r.bottom() - d1 ), 577 qRound( r .right() - d1), qRound( r.top() + d1 ) );577 qRound( r.right() - d1), qRound( r.top() + d1 ) ); 578 578 579 579 const QPoint c = r.center(); … … 596 596 597 597 const QPointF c = r.center(); 598 const double d1 = r.width() / 2.0 * ( 1.0 - sqrt1_2 );598 const double d1 = r.width() / 2.0 * ( 1.0 - sqrt1_2 ); 599 599 600 600 QwtPainter::drawLine( painter, … … 614 614 } 615 615 616 static inline void qwtDrawStar2Symbols( QPainter *painter,617 const QPointF *points, int numPoints, const QwtSymbol&symbol )616 static inline void qwtDrawStar2Symbols( QPainter* painter, 617 const QPointF* points, int numPoints, const QwtSymbol& symbol ) 618 618 { 619 619 QPen pen = symbol.pen(); … … 631 631 632 632 QPolygonF star( 12 ); 633 QPointF *starPoints = star.data();633 QPointF* starPoints = star.data(); 634 634 635 635 const bool doAlign = QwtPainter::roundingAlignment( painter ); … … 705 705 } 706 706 707 static inline void qwtDrawHexagonSymbols( QPainter *painter,708 const QPointF *points, int numPoints, const QwtSymbol&symbol )707 static inline void qwtDrawHexagonSymbols( QPainter* painter, 708 const QPointF* points, int numPoints, const QwtSymbol& symbol ) 709 709 { 710 710 painter->setBrush( symbol.brush() ); … … 717 717 718 718 QPolygonF hexaPolygon( 6 ); 719 QPointF *hexaPoints = hexaPolygon.data();719 QPointF* hexaPoints = hexaPolygon.data(); 720 720 721 721 const bool doAlign = QwtPainter::roundingAlignment( painter ); … … 735 735 if ( doAlign ) 736 736 { 737 x1 = qCeil( x1 );738 y1 = qCeil( y1 );737 x1 = std::ceil( x1 ); 738 y1 = std::ceil( y1 ); 739 739 } 740 740 … … 770 770 class QwtSymbol::PrivateData 771 771 { 772 public: 773 PrivateData( QwtSymbol::Style st, const QBrush &br,774 const QPen &pn, const QSize&sz ):775 style( st ) ,776 size( sz ) ,777 brush( br ) ,778 pen( pn ) ,779 isPinPointEnabled( false ) 772 public: 773 PrivateData( QwtSymbol::Style st, const QBrush& br, 774 const QPen& pn, const QSize& sz ) 775 : style( st ) 776 , size( sz ) 777 , brush( br ) 778 , pen( pn ) 779 , isPinPointEnabled( false ) 780 780 { 781 781 cache.policy = QwtSymbol::AutoCache; … … 822 822 struct SVG 823 823 { 824 QSvgRenderer *renderer;824 QSvgRenderer* renderer; 825 825 } svg; 826 826 #endif … … 835 835 836 836 /*! 837 Default Constructor 838 \param style Symbol Style 839 840 The symbol is constructed with gray interior, 841 black outline with zero width, no size and style 'NoSymbol'. 842 */ 837 Default Constructor 838 \param style Symbol Style 839 840 The symbol is constructed with gray interior, 841 black outline with zero width, no size and style 'NoSymbol'. 842 */ 843 843 QwtSymbol::QwtSymbol( Style style ) 844 844 { 845 d_data = new PrivateData( style, QBrush( Qt::gray ),845 m_data = new PrivateData( style, QBrush( Qt::gray ), 846 846 QPen( Qt::black, 0 ), QSize() ); 847 847 } 848 848 849 849 /*! 850 \brief Constructor 851 \param style Symbol Style 852 \param brush brush to fill the interior 853 \param pen outline pen 854 \param size size 855 856 \sa setStyle(), setBrush(), setPen(), setSize() 857 */ 858 QwtSymbol::QwtSymbol( QwtSymbol::Style style, const QBrush &brush,859 const QPen &pen, const QSize&size )860 { 861 d_data = new PrivateData( style, brush, pen, size );862 } 863 864 /*! 865 \brief Constructor 866 867 The symbol gets initialized by a painter path. The style is 868 set to QwtSymbol::Path, the size is set to empty ( the path 869 is displayed unscaled ). 870 871 \param path painter path 872 \param brush brush to fill the interior 873 \param pen outline pen 874 875 \sa setPath(), setBrush(), setPen(), setSize() 876 */ 877 878 QwtSymbol::QwtSymbol( const QPainterPath &path,879 const QBrush &brush, const QPen&pen )880 { 881 d_data = new PrivateData( QwtSymbol::Path, brush, pen, QSize() );850 \brief Constructor 851 \param style Symbol Style 852 \param brush brush to fill the interior 853 \param pen outline pen 854 \param size size 855 856 \sa setStyle(), setBrush(), setPen(), setSize() 857 */ 858 QwtSymbol::QwtSymbol( QwtSymbol::Style style, const QBrush& brush, 859 const QPen& pen, const QSize& size ) 860 { 861 m_data = new PrivateData( style, brush, pen, size ); 862 } 863 864 /*! 865 \brief Constructor 866 867 The symbol gets initialized by a painter path. The style is 868 set to QwtSymbol::Path, the size is set to empty ( the path 869 is displayed unscaled ). 870 871 \param path painter path 872 \param brush brush to fill the interior 873 \param pen outline pen 874 875 \sa setPath(), setBrush(), setPen(), setSize() 876 */ 877 878 QwtSymbol::QwtSymbol( const QPainterPath& path, 879 const QBrush& brush, const QPen& pen ) 880 { 881 m_data = new PrivateData( QwtSymbol::Path, brush, pen, QSize() ); 882 882 setPath( path ); 883 883 } … … 886 886 QwtSymbol::~QwtSymbol() 887 887 { 888 delete d_data;889 } 890 891 /*! 892 Change the cache policy 893 894 The default policy is AutoCache 895 896 \param policy Cache policy 897 \sa CachePolicy, cachePolicy() 898 */ 888 delete m_data; 889 } 890 891 /*! 892 Change the cache policy 893 894 The default policy is AutoCache 895 896 \param policy Cache policy 897 \sa CachePolicy, cachePolicy() 898 */ 899 899 void QwtSymbol::setCachePolicy( 900 900 QwtSymbol::CachePolicy policy ) 901 901 { 902 if ( d_data->cache.policy != policy )903 { 904 d_data->cache.policy = policy;902 if ( m_data->cache.policy != policy ) 903 { 904 m_data->cache.policy = policy; 905 905 invalidateCache(); 906 906 } … … 908 908 909 909 /*! 910 \return Cache policy 911 \sa CachePolicy, setCachePolicy() 912 */ 910 \return Cache policy 911 \sa CachePolicy, setCachePolicy() 912 */ 913 913 QwtSymbol::CachePolicy QwtSymbol::cachePolicy() const 914 914 { 915 return d_data->cache.policy;916 } 917 918 /*! 919 \brief Set a painter path as symbol 920 921 The symbol is represented by a painter path, where the 922 origin ( 0, 0 ) of the path coordinate system is mapped to 923 the position of the symbol. 924 925 When the symbol has valid size the painter path gets scaled 926 to fit into the size. Otherwise the symbol size depends on 927 the bounding rectangle of the path. 928 929 \par Example 915 return m_data->cache.policy; 916 } 917 918 /*! 919 \brief Set a painter path as symbol 920 921 The symbol is represented by a painter path, where the 922 origin ( 0, 0 ) of the path coordinate system is mapped to 923 the position of the symbol. 924 925 When the symbol has valid size the painter path gets scaled 926 to fit into the size. Otherwise the symbol size depends on 927 the bounding rectangle of the path. 928 929 \par Example 930 930 The following code defines a symbol drawing an arrow: 931 931 932 932 \code 933 #include <qwt_symbol.h>933 #include <qwt_symbol.h> 934 934 935 935 QwtSymbol *symbol = new QwtSymbol(); … … 958 958 setSize( 10, 14 ); 959 959 \endcode 960 \endpar 961 962 \param path Painter path 963 964 \note The style is implicitely set to QwtSymbol::Path. 965 \sa path(), setSize() 966 */ 967 void QwtSymbol::setPath( const QPainterPath &path ) 968 { 969 d_data->style = QwtSymbol::Path; 970 d_data->path.path = path; 971 d_data->path.graphic.reset(); 960 961 \param path Painter path 962 963 \note The style is implicitly set to QwtSymbol::Path. 964 \sa path(), setSize() 965 */ 966 void QwtSymbol::setPath( const QPainterPath& path ) 967 { 968 m_data->style = QwtSymbol::Path; 969 m_data->path.path = path; 970 m_data->path.graphic.reset(); 972 971 } 973 972 … … 975 974 \return Painter path for displaying the symbol 976 975 \sa setPath() 977 */ 978 const QPainterPath &QwtSymbol::path() const979 { 980 return d_data->path.path;981 } 982 983 /*! 984 Set a pixmap as symbol 985 986 \param pixmap Pixmap 987 988 \sa pixmap(), setGraphic() 989 990 \note the style() is set to QwtSymbol::Pixmap 991 \note brush() and pen() have no effect 992 */ 993 void QwtSymbol::setPixmap( const QPixmap &pixmap )994 { 995 d_data->style = QwtSymbol::Pixmap;996 d_data->pixmap.pixmap = pixmap;997 } 998 999 /*! 1000 \return Assigned pixmap 1001 \sa setPixmap() 1002 */ 1003 const QPixmap &QwtSymbol::pixmap() const1004 { 1005 return d_data->pixmap.pixmap;1006 } 1007 1008 /*! 1009 Set a graphic as symbol 1010 1011 \param graphic Graphic 1012 1013 \sa graphic(), setPixmap() 1014 1015 \note the style() is set to QwtSymbol::Graphic 1016 \note brush() and pen() have no effect 1017 */ 1018 void QwtSymbol::setGraphic( const QwtGraphic &graphic )1019 { 1020 d_data->style = QwtSymbol::Graphic;1021 d_data->graphic.graphic = graphic;1022 } 1023 1024 /*! 1025 \return Assigned graphic 1026 \sa setGraphic() 1027 */ 1028 const QwtGraphic &QwtSymbol::graphic() const1029 { 1030 return d_data->graphic.graphic;976 */ 977 const QPainterPath& QwtSymbol::path() const 978 { 979 return m_data->path.path; 980 } 981 982 /*! 983 Set a pixmap as symbol 984 985 \param pixmap Pixmap 986 987 \sa pixmap(), setGraphic() 988 989 \note the style() is set to QwtSymbol::Pixmap 990 \note brush() and pen() have no effect 991 */ 992 void QwtSymbol::setPixmap( const QPixmap& pixmap ) 993 { 994 m_data->style = QwtSymbol::Pixmap; 995 m_data->pixmap.pixmap = pixmap; 996 } 997 998 /*! 999 \return Assigned pixmap 1000 \sa setPixmap() 1001 */ 1002 const QPixmap& QwtSymbol::pixmap() const 1003 { 1004 return m_data->pixmap.pixmap; 1005 } 1006 1007 /*! 1008 Set a graphic as symbol 1009 1010 \param graphic Graphic 1011 1012 \sa graphic(), setPixmap() 1013 1014 \note the style() is set to QwtSymbol::Graphic 1015 \note brush() and pen() have no effect 1016 */ 1017 void QwtSymbol::setGraphic( const QwtGraphic& graphic ) 1018 { 1019 m_data->style = QwtSymbol::Graphic; 1020 m_data->graphic.graphic = graphic; 1021 } 1022 1023 /*! 1024 \return Assigned graphic 1025 \sa setGraphic() 1026 */ 1027 const QwtGraphic& QwtSymbol::graphic() const 1028 { 1029 return m_data->graphic.graphic; 1031 1030 } 1032 1031 … … 1034 1033 1035 1034 /*! 1036 Set a SVG icon as symbol 1037 1038 \param svgDocument SVG icon 1039 1040 \sa setGraphic(), setPixmap() 1041 1042 \note the style() is set to QwtSymbol::SvgDocument 1043 \note brush() and pen() have no effect 1044 */ 1045 void QwtSymbol::setSvgDocument( const QByteArray &svgDocument )1046 { 1047 d_data->style = QwtSymbol::SvgDocument;1048 if ( d_data->svg.renderer == NULL )1049 d_data->svg.renderer = new QSvgRenderer();1050 1051 d_data->svg.renderer->load( svgDocument );1035 Set a SVG icon as symbol 1036 1037 \param svgDocument SVG icon 1038 1039 \sa setGraphic(), setPixmap() 1040 1041 \note the style() is set to QwtSymbol::SvgDocument 1042 \note brush() and pen() have no effect 1043 */ 1044 void QwtSymbol::setSvgDocument( const QByteArray& svgDocument ) 1045 { 1046 m_data->style = QwtSymbol::SvgDocument; 1047 if ( m_data->svg.renderer == NULL ) 1048 m_data->svg.renderer = new QSvgRenderer(); 1049 1050 m_data->svg.renderer->load( svgDocument ); 1052 1051 } 1053 1052 … … 1055 1054 1056 1055 /*! 1057 \brief Specify the symbol's size 1058 1059 If the 'h' parameter is left out or less than 0, 1060 and the 'w' parameter is greater than or equal to 0, 1061 the symbol size will be set to (w,w). 1062 1063 \param width Width 1064 \param height Height (defaults to -1) 1065 1066 \sa size() 1067 */ 1056 \brief Specify the symbol's size 1057 1058 If the 'h' parameter is left out or less than 0, 1059 and the 'w' parameter is greater than or equal to 0, 1060 the symbol size will be set to (w,w). 1061 1062 \param width Width 1063 \param height Height (defaults to -1) 1064 1065 \sa size() 1066 */ 1068 1067 void QwtSymbol::setSize( int width, int height ) 1069 1068 { … … 1079 1078 1080 1079 \sa size() 1081 */ 1082 void QwtSymbol::setSize( const QSize &size )1083 { 1084 if ( size.isValid() && size != d_data->size )1085 { 1086 d_data->size = size;1080 */ 1081 void QwtSymbol::setSize( const QSize& size ) 1082 { 1083 if ( size.isValid() && size != m_data->size ) 1084 { 1085 m_data->size = size; 1087 1086 invalidateCache(); 1088 1087 } … … 1092 1091 \return Size 1093 1092 \sa setSize() 1094 */ 1093 */ 1095 1094 const QSize& QwtSymbol::size() const 1096 1095 { 1097 return d_data->size;1098 } 1099 1100 /*! 1101 \brief Assign a brush 1102 1103 The brush is used to draw the interior of the symbol. 1104 \param brush Brush 1105 1106 \sa brush() 1107 */ 1108 void QwtSymbol::setBrush( const QBrush &brush )1109 { 1110 if ( brush != d_data->brush )1111 { 1112 d_data->brush = brush;1096 return m_data->size; 1097 } 1098 1099 /*! 1100 \brief Assign a brush 1101 1102 The brush is used to draw the interior of the symbol. 1103 \param brush Brush 1104 1105 \sa brush() 1106 */ 1107 void QwtSymbol::setBrush( const QBrush& brush ) 1108 { 1109 if ( brush != m_data->brush ) 1110 { 1111 m_data->brush = brush; 1113 1112 invalidateCache(); 1114 1113 1115 if ( d_data->style == QwtSymbol::Path )1116 d_data->path.graphic.reset();1117 } 1118 } 1119 1120 /*! 1121 \return Brush 1122 \sa setBrush() 1123 */ 1114 if ( m_data->style == QwtSymbol::Path ) 1115 m_data->path.graphic.reset(); 1116 } 1117 } 1118 1119 /*! 1120 \return Brush 1121 \sa setBrush() 1122 */ 1124 1123 const QBrush& QwtSymbol::brush() const 1125 1124 { 1126 return d_data->brush;1127 } 1128 1129 /*! 1130 Build and assign a pen 1131 1132 In Qt5 the default pen width is 1.0 ( 0.0 in Qt4 ) 1133 what makes it non cosmetic ( see QPen::isCosmetic() ). 1134 This method has been introduced to hide this incompatibility. 1135 1136 \param color Pen color 1137 \param width Pen width 1138 \param style Pen style 1139 1140 \sa pen(), brush() 1141 */ 1142 void QwtSymbol::setPen( const QColor &color,1125 return m_data->brush; 1126 } 1127 1128 /*! 1129 Build and assign a pen 1130 1131 In Qt5 the default pen width is 1.0 ( 0.0 in Qt4 ) 1132 what makes it non cosmetic ( see QPen::isCosmetic() ). 1133 This method has been introduced to hide this incompatibility. 1134 1135 \param color Pen color 1136 \param width Pen width 1137 \param style Pen style 1138 1139 \sa pen(), brush() 1140 */ 1141 void QwtSymbol::setPen( const QColor& color, 1143 1142 qreal width, Qt::PenStyle style ) 1144 1143 { … … 1147 1146 1148 1147 /*! 1149 Assign a pen 1150 1151 The pen is used to draw the symbol's outline. 1152 1153 \param pen Pen 1154 \sa pen(), setBrush() 1155 */ 1156 void QwtSymbol::setPen( const QPen &pen )1157 { 1158 if ( pen != d_data->pen )1159 { 1160 d_data->pen = pen;1148 Assign a pen 1149 1150 The pen is used to draw the symbol's outline. 1151 1152 \param pen Pen 1153 \sa pen(), setBrush() 1154 */ 1155 void QwtSymbol::setPen( const QPen& pen ) 1156 { 1157 if ( pen != m_data->pen ) 1158 { 1159 m_data->pen = pen; 1161 1160 invalidateCache(); 1162 1161 1163 if ( d_data->style == QwtSymbol::Path )1164 d_data->path.graphic.reset();1165 } 1166 } 1167 1168 /*! 1169 \return Pen 1170 \sa setPen(), brush() 1171 */ 1162 if ( m_data->style == QwtSymbol::Path ) 1163 m_data->path.graphic.reset(); 1164 } 1165 } 1166 1167 /*! 1168 \return Pen 1169 \sa setPen(), brush() 1170 */ 1172 1171 const QPen& QwtSymbol::pen() const 1173 1172 { 1174 return d_data->pen;1175 } 1176 1177 /*! 1178 \brief Set the color of the symbol 1179 1180 Change the color of the brush for symbol types with a filled area. 1181 For all other symbol types the color will be assigned to the pen. 1182 1183 \param color Color 1184 1185 \sa setBrush(), setPen(), brush(), pen() 1186 */ 1187 void QwtSymbol::setColor( const QColor &color )1188 { 1189 switch ( d_data->style )1173 return m_data->pen; 1174 } 1175 1176 /*! 1177 \brief Set the color of the symbol 1178 1179 Change the color of the brush for symbol types with a filled area. 1180 For all other symbol types the color will be assigned to the pen. 1181 1182 \param color Color 1183 1184 \sa setBrush(), setPen(), brush(), pen() 1185 */ 1186 void QwtSymbol::setColor( const QColor& color ) 1187 { 1188 switch ( m_data->style ) 1190 1189 { 1191 1190 case QwtSymbol::Ellipse: … … 1200 1199 case QwtSymbol::Hexagon: 1201 1200 { 1202 if ( d_data->brush.color() != color )1201 if ( m_data->brush.color() != color ) 1203 1202 { 1204 d_data->brush.setColor( color );1203 m_data->brush.setColor( color ); 1205 1204 invalidateCache(); 1206 1205 } … … 1213 1212 case QwtSymbol::Star1: 1214 1213 { 1215 if ( d_data->pen.color() != color )1214 if ( m_data->pen.color() != color ) 1216 1215 { 1217 d_data->pen.setColor( color );1216 m_data->pen.setColor( color ); 1218 1217 invalidateCache(); 1219 1218 } … … 1222 1221 default: 1223 1222 { 1224 if ( d_data->brush.color() != color ||1225 d_data->pen.color() != color )1223 if ( m_data->brush.color() != color || 1224 m_data->pen.color() != color ) 1226 1225 { 1227 1226 invalidateCache(); 1228 1227 } 1229 1228 1230 d_data->brush.setColor( color );1231 d_data->pen.setColor( color );1232 } 1233 } 1234 } 1235 1236 /*! 1237 \brief Set and enable a pin point 1238 1239 The position of a complex symbol is not always aligned to its center 1240 ( f.e an arrow, where the peak points to a position ). The pin point 1241 defines the position inside of a Pixmap, Graphic, SvgDocument 1242 or PainterPath symbol where the represented point has to 1243 be aligned to. 1244 1245 \param pos Position 1246 \param enable En/Disable the pin point alignment 1247 1248 \sa pinPoint(), setPinPointEnabled() 1249 */ 1250 void QwtSymbol::setPinPoint( const QPointF &pos, bool enable )1251 { 1252 if ( d_data->pinPoint != pos )1253 { 1254 d_data->pinPoint = pos;1255 if ( d_data->isPinPointEnabled )1229 m_data->brush.setColor( color ); 1230 m_data->pen.setColor( color ); 1231 } 1232 } 1233 } 1234 1235 /*! 1236 \brief Set and enable a pin point 1237 1238 The position of a complex symbol is not always aligned to its center 1239 ( f.e an arrow, where the peak points to a position ). The pin point 1240 defines the position inside of a Pixmap, Graphic, SvgDocument 1241 or PainterPath symbol where the represented point has to 1242 be aligned to. 1243 1244 \param pos Position 1245 \param enable En/Disable the pin point alignment 1246 1247 \sa pinPoint(), setPinPointEnabled() 1248 */ 1249 void QwtSymbol::setPinPoint( const QPointF& pos, bool enable ) 1250 { 1251 if ( m_data->pinPoint != pos ) 1252 { 1253 m_data->pinPoint = pos; 1254 if ( m_data->isPinPointEnabled ) 1256 1255 { 1257 1256 invalidateCache(); … … 1263 1262 1264 1263 /*! 1265 \return Pin point 1266 \sa setPinPoint(), setPinPointEnabled() 1264 \return Pin point 1265 \sa setPinPoint(), setPinPointEnabled() 1267 1266 */ 1268 1267 QPointF QwtSymbol::pinPoint() const 1269 1268 { 1270 return d_data->pinPoint;1271 } 1272 1273 /*! 1274 En/Disable the pin point alignment 1275 1276 \param on Enabled, when on is true 1277 \sa setPinPoint(), isPinPointEnabled() 1269 return m_data->pinPoint; 1270 } 1271 1272 /*! 1273 En/Disable the pin point alignment 1274 1275 \param on Enabled, when on is true 1276 \sa setPinPoint(), isPinPointEnabled() 1278 1277 */ 1279 1278 void QwtSymbol::setPinPointEnabled( bool on ) 1280 1279 { 1281 if ( d_data->isPinPointEnabled != on )1282 { 1283 d_data->isPinPointEnabled = on;1280 if ( m_data->isPinPointEnabled != on ) 1281 { 1282 m_data->isPinPointEnabled = on; 1284 1283 invalidateCache(); 1285 1284 } … … 1287 1286 1288 1287 /*! 1289 \return True, when the pin point translation is enabled 1290 \sa setPinPoint(), setPinPointEnabled() 1288 \return True, when the pin point translation is enabled 1289 \sa setPinPoint(), setPinPointEnabled() 1291 1290 */ 1292 1291 bool QwtSymbol::isPinPointEnabled() const 1293 1292 { 1294 return d_data->isPinPointEnabled;1295 } 1296 1297 /*! 1298 Render an array of symbols 1299 1300 Painting several symbols is more effective than drawing symbols 1301 one by one, as a couple of layout calculations and setting of pen/brush 1302 can be done once for the complete array. 1303 1304 \param painter Painter 1305 \param points Array of points 1306 \param numPoints Number of points 1307 */ 1308 void QwtSymbol::drawSymbols( QPainter *painter,1309 const QPointF *points, int numPoints ) const1293 return m_data->isPinPointEnabled; 1294 } 1295 1296 /*! 1297 Render an array of symbols 1298 1299 Painting several symbols is more effective than drawing symbols 1300 one by one, as a couple of layout calculations and setting of pen/brush 1301 can be done once for the complete array. 1302 1303 \param painter Painter 1304 \param points Array of points 1305 \param numPoints Number of points 1306 */ 1307 void QwtSymbol::drawSymbols( QPainter* painter, 1308 const QPointF* points, int numPoints ) const 1310 1309 { 1311 1310 if ( numPoints <= 0 ) … … 1320 1319 !painter->transform().isScaling() ) 1321 1320 { 1322 if ( d_data->cache.policy == QwtSymbol::Cache )1321 if ( m_data->cache.policy == QwtSymbol::Cache ) 1323 1322 { 1324 1323 useCache = true; 1325 1324 } 1326 else if ( d_data->cache.policy == QwtSymbol::AutoCache )1327 { 1328 if( painter->paintEngine()->type()== QPaintEngine::Raster)1325 else if ( m_data->cache.policy == QwtSymbol::AutoCache ) 1326 { 1327 switch( painter->paintEngine()->type() ) 1329 1328 { 1330 useCache = true; 1331 } 1332 else 1333 { 1334 switch( d_data->style ) 1329 case QPaintEngine::OpenGL: 1330 case QPaintEngine::OpenGL2: 1335 1331 { 1336 case QwtSymbol::XCross: 1337 case QwtSymbol::HLine: 1338 case QwtSymbol::VLine: 1339 case QwtSymbol::Cross: 1340 break; 1341 1342 case QwtSymbol::Pixmap: 1332 // using a FBO as cache ? 1333 useCache = false; 1334 break; 1335 } 1336 case QPaintEngine::OpenVG: 1337 case QPaintEngine::SVG: 1338 case QPaintEngine::Pdf: 1339 case QPaintEngine::Picture: 1340 { 1341 // vector graphics 1342 useCache = false; 1343 break; 1344 } 1345 case QPaintEngine::X11: 1346 { 1347 switch( m_data->style ) 1343 1348 { 1344 if ( !d_data->size.isEmpty() && 1345 d_data->size != d_data->pixmap.pixmap.size() ) 1349 case QwtSymbol::XCross: 1350 case QwtSymbol::HLine: 1351 case QwtSymbol::VLine: 1352 case QwtSymbol::Cross: 1346 1353 { 1347 useCache = true; 1354 // for the very simple shapes using vector graphics is 1355 // usually faster. 1356 1357 useCache = false; 1358 break; 1348 1359 } 1349 break; 1360 1361 case QwtSymbol::Pixmap: 1362 { 1363 if ( m_data->size.isEmpty() || 1364 m_data->size == m_data->pixmap.pixmap.size() ) 1365 { 1366 // no need to have a pixmap cache for a pixmap 1367 // of the same size 1368 1369 useCache = false; 1370 } 1371 break; 1372 } 1373 default: 1374 break; 1350 1375 } 1351 default: 1352 useCache = true; 1376 break; 1377 } 1378 default: 1379 { 1380 useCache = true; 1353 1381 } 1354 1382 } … … 1360 1388 const QRect br = boundingRect(); 1361 1389 1362 if ( d_data->cache.pixmap.isNull() )1363 { 1364 d_data->cache.pixmap = QwtPainter::backingStore( NULL, br.size() );1365 d_data->cache.pixmap.fill( Qt::transparent );1366 1367 QPainter p( & d_data->cache.pixmap );1390 if ( m_data->cache.pixmap.isNull() ) 1391 { 1392 m_data->cache.pixmap = QwtPainter::backingStore( NULL, br.size() ); 1393 m_data->cache.pixmap.fill( Qt::transparent ); 1394 1395 QPainter p( &m_data->cache.pixmap ); 1368 1396 p.setRenderHints( painter->renderHints() ); 1369 1397 p.translate( -br.topLeft() ); 1370 1398 1371 const QPointF pos; 1399 const QPointF pos( 0.0, 0.0 ); 1372 1400 renderSymbols( &p, &pos, 1 ); 1373 1401 } … … 1381 1409 const int top = qRound( points[i].y() ) + dy; 1382 1410 1383 painter->drawPixmap( left, top, d_data->cache.pixmap );1411 painter->drawPixmap( left, top, m_data->cache.pixmap ); 1384 1412 } 1385 1413 } … … 1393 1421 1394 1422 /*! 1395 \brief Draw the symbol into a rectangle 1396 1397 The symbol is painted centered and scaled into the target rectangle. 1398 It is always painted uncached and the pin point is ignored. 1399 1400 This method is primarily intended for drawing a symbol to 1401 the legend. 1402 1403 \param painter Painter 1404 \param rect Target rectangle for the symbol 1405 */ 1406 void QwtSymbol::drawSymbol( QPainter *painter, const QRectF&rect ) const1407 { 1408 if ( d_data->style == QwtSymbol::NoSymbol )1423 \brief Draw the symbol into a rectangle 1424 1425 The symbol is painted centered and scaled into the target rectangle. 1426 It is always painted uncached and the pin point is ignored. 1427 1428 This method is primarily intended for drawing a symbol to 1429 the legend. 1430 1431 \param painter Painter 1432 \param rect Target rectangle for the symbol 1433 */ 1434 void QwtSymbol::drawSymbol( QPainter* painter, const QRectF& rect ) const 1435 { 1436 if ( m_data->style == QwtSymbol::NoSymbol ) 1409 1437 return; 1410 1438 1411 if ( d_data->style == QwtSymbol::Graphic )1412 { 1413 d_data->graphic.graphic.render(1439 if ( m_data->style == QwtSymbol::Graphic ) 1440 { 1441 m_data->graphic.graphic.render( 1414 1442 painter, rect, Qt::KeepAspectRatio ); 1415 1443 } 1416 else if ( d_data->style == QwtSymbol::Path )1417 { 1418 if ( d_data->path.graphic.isNull() )1419 { 1420 d_data->path.graphic = qwtPathGraphic(1421 d_data->path.path,d_data->pen,d_data->brush );1422 } 1423 1424 d_data->path.graphic.render(1444 else if ( m_data->style == QwtSymbol::Path ) 1445 { 1446 if ( m_data->path.graphic.isNull() ) 1447 { 1448 m_data->path.graphic = qwtPathGraphic( 1449 m_data->path.path, m_data->pen, m_data->brush ); 1450 } 1451 1452 m_data->path.graphic.render( 1425 1453 painter, rect, Qt::KeepAspectRatio ); 1426 1454 return; 1427 1455 } 1428 else if ( d_data->style == QwtSymbol::SvgDocument )1456 else if ( m_data->style == QwtSymbol::SvgDocument ) 1429 1457 { 1430 1458 #ifndef QWT_NO_SVG 1431 if ( d_data->svg.renderer )1459 if ( m_data->svg.renderer ) 1432 1460 { 1433 1461 QRectF scaledRect; 1434 1462 1435 QSizeF sz = d_data->svg.renderer->viewBoxF().size();1463 QSizeF sz = m_data->svg.renderer->viewBoxF().size(); 1436 1464 if ( !sz.isEmpty() ) 1437 1465 { … … 1445 1473 } 1446 1474 1447 d_data->svg.renderer->render(1475 m_data->svg.renderer->render( 1448 1476 painter, scaledRect ); 1449 1477 } … … 1464 1492 painter->scale( ratio, ratio ); 1465 1493 1466 const bool isPinPointEnabled = d_data->isPinPointEnabled;1467 d_data->isPinPointEnabled = false;1494 const bool isPinPointEnabled = m_data->isPinPointEnabled; 1495 m_data->isPinPointEnabled = false; 1468 1496 1469 1497 const QPointF pos; 1470 1498 renderSymbols( painter, &pos, 1 ); 1471 1499 1472 d_data->isPinPointEnabled = isPinPointEnabled;1500 m_data->isPinPointEnabled = isPinPointEnabled; 1473 1501 1474 1502 painter->restore(); … … 1477 1505 1478 1506 /*! 1479 Render the symbol to series of points 1480 1481 \param painter Qt painter 1482 \param points Positions of the symbols 1483 \param numPoints Number of points 1484 */ 1485 void QwtSymbol::renderSymbols( QPainter *painter,1486 const QPointF *points, int numPoints ) const1487 { 1488 switch ( d_data->style )1507 Render the symbol to series of points 1508 1509 \param painter Qt painter 1510 \param points Positions of the symbols 1511 \param numPoints Number of points 1512 */ 1513 void QwtSymbol::renderSymbols( QPainter* painter, 1514 const QPointF* points, int numPoints ) const 1515 { 1516 switch ( m_data->style ) 1489 1517 { 1490 1518 case QwtSymbol::Ellipse: … … 1568 1596 case QwtSymbol::Path: 1569 1597 { 1570 if ( d_data->path.graphic.isNull() )1598 if ( m_data->path.graphic.isNull() ) 1571 1599 { 1572 d_data->path.graphic = qwtPathGraphic(d_data->path.path,1573 d_data->pen,d_data->brush );1600 m_data->path.graphic = qwtPathGraphic( m_data->path.path, 1601 m_data->pen, m_data->brush ); 1574 1602 } 1575 1603 1576 1604 qwtDrawGraphicSymbols( painter, points, numPoints, 1577 d_data->path.graphic, *this );1605 m_data->path.graphic, *this ); 1578 1606 break; 1579 1607 } … … 1586 1614 { 1587 1615 qwtDrawGraphicSymbols( painter, points, numPoints, 1588 d_data->graphic.graphic, *this );1616 m_data->graphic.graphic, *this ); 1589 1617 break; 1590 1618 } … … 1593 1621 #ifndef QWT_NO_SVG 1594 1622 qwtDrawSvgSymbols( painter, points, numPoints, 1595 d_data->svg.renderer, *this );1623 m_data->svg.renderer, *this ); 1596 1624 #endif 1597 1625 break; … … 1602 1630 1603 1631 /*! 1604 Calculate the bounding rectangle for a symbol 1605 at position (0,0). 1606 1607 \return Bounding rectangle 1632 Calculate the bounding rectangle for a symbol 1633 at position (0,0). 1634 1635 \return Bounding rectangle 1608 1636 */ 1609 1637 QRect QwtSymbol::boundingRect() const … … 1613 1641 bool pinPointTranslation = false; 1614 1642 1615 switch ( d_data->style )1643 switch ( m_data->style ) 1616 1644 { 1617 1645 case QwtSymbol::Ellipse: … … 1620 1648 { 1621 1649 qreal pw = 0.0; 1622 if ( d_data->pen.style() != Qt::NoPen )1623 pw = qMax( d_data->pen.widthF(), qreal( 1.0 ));1624 1625 rect.setSize( d_data->size + QSizeF( pw, pw ) );1650 if ( m_data->pen.style() != Qt::NoPen ) 1651 pw = QwtPainter::effectivePenWidth( m_data->pen ); 1652 1653 rect.setSize( m_data->size + QSizeF( pw, pw ) ); 1626 1654 rect.moveCenter( QPointF( 0.0, 0.0 ) ); 1627 1655 … … 1639 1667 { 1640 1668 qreal pw = 0.0; 1641 if ( d_data->pen.style() != Qt::NoPen )1642 pw = qMax( d_data->pen.widthF(), qreal( 1.0 ));1643 1644 rect.setSize( d_data->size + QSizeF( 2 * pw, 2 * pw ) );1669 if ( m_data->pen.style() != Qt::NoPen ) 1670 pw = QwtPainter::effectivePenWidth( m_data->pen ); 1671 1672 rect.setSize( m_data->size + QSizeF( 2 * pw, 2 * pw ) ); 1645 1673 rect.moveCenter( QPointF( 0.0, 0.0 ) ); 1646 1674 break; … … 1648 1676 case QwtSymbol::Path: 1649 1677 { 1650 if ( d_data->path.graphic.isNull() )1678 if ( m_data->path.graphic.isNull() ) 1651 1679 { 1652 d_data->path.graphic = qwtPathGraphic(1653 d_data->path.path,d_data->pen,d_data->brush );1680 m_data->path.graphic = qwtPathGraphic( 1681 m_data->path.path, m_data->pen, m_data->brush ); 1654 1682 } 1655 1683 1656 1684 rect = qwtScaledBoundingRect( 1657 d_data->path.graphic,d_data->size );1685 m_data->path.graphic, m_data->size ); 1658 1686 pinPointTranslation = true; 1659 1687 … … 1662 1690 case QwtSymbol::Pixmap: 1663 1691 { 1664 if ( d_data->size.isEmpty() )1665 rect.setSize( d_data->pixmap.pixmap.size() );1692 if ( m_data->size.isEmpty() ) 1693 rect.setSize( m_data->pixmap.pixmap.size() ); 1666 1694 else 1667 rect.setSize( d_data->size );1695 rect.setSize( m_data->size ); 1668 1696 1669 1697 pinPointTranslation = true; … … 1674 1702 { 1675 1703 rect = qwtScaledBoundingRect( 1676 d_data->graphic.graphic,d_data->size );1704 m_data->graphic.graphic, m_data->size ); 1677 1705 pinPointTranslation = true; 1678 1706 … … 1682 1710 case QwtSymbol::SvgDocument: 1683 1711 { 1684 if ( d_data->svg.renderer )1685 rect = d_data->svg.renderer->viewBoxF();1686 1687 if ( d_data->size.isValid() && !rect.isEmpty() )1712 if ( m_data->svg.renderer ) 1713 rect = m_data->svg.renderer->viewBoxF(); 1714 1715 if ( m_data->size.isValid() && !rect.isEmpty() ) 1688 1716 { 1689 1717 QSizeF sz = rect.size(); 1690 1718 1691 const double sx = d_data->size.width() / sz.width();1692 const double sy = d_data->size.height() / sz.height();1719 const double sx = m_data->size.width() / sz.width(); 1720 const double sy = m_data->size.height() / sz.height(); 1693 1721 1694 1722 QTransform transform; … … 1703 1731 default: 1704 1732 { 1705 rect.setSize( d_data->size );1733 rect.setSize( m_data->size ); 1706 1734 rect.moveCenter( QPointF( 0.0, 0.0 ) ); 1707 1735 } … … 1711 1739 { 1712 1740 QPointF pinPoint( 0.0, 0.0 ); 1713 if ( d_data->isPinPointEnabled )1714 pinPoint = rect.center() - d_data->pinPoint;1741 if ( m_data->isPinPointEnabled ) 1742 pinPoint = rect.center() - m_data->pinPoint; 1715 1743 1716 1744 rect.moveCenter( pinPoint ); … … 1718 1746 1719 1747 QRect r; 1720 r.setLeft( qFloor( rect.left() ) ); 1721 r.setTop( qFloor( rect.top() ) ); 1722 r.setRight( qCeil( rect.right() ) ); 1723 r.setBottom( qCeil( rect.bottom() ) ); 1724 1725 if ( d_data->style != QwtSymbol::Pixmap )1748 r.setLeft( qwtFloor( rect.left() ) ); 1749 r.setTop( qwtFloor( rect.top() ) ); 1750 r.setRight( qwtCeil( rect.right() ) ); 1751 r.setBottom( qwtCeil( rect.bottom() ) ); 1752 1753 if ( m_data->style != QwtSymbol::Pixmap ) 1726 1754 r.adjust( -1, -1, 1, 1 ); // for antialiasing 1727 1755 … … 1730 1758 1731 1759 /*! 1732 Invalidate the cached symbol pixmap 1733 1734 The symbol invalidates its cache, whenever an attribute is changed 1735 that has an effect ob how to display a symbol. In case of derived 1736 classes with individual styles ( >= QwtSymbol::UserStyle ) it 1737 might be necessary to call invalidateCache() for attributes 1738 that are relevant for this style. 1739 1740 \sa CachePolicy, setCachePolicy(), drawSymbols() 1760 Invalidate the cached symbol pixmap 1761 1762 The symbol invalidates its cache, whenever an attribute is changed 1763 that has an effect ob how to display a symbol. In case of derived 1764 classes with individual styles ( >= QwtSymbol::UserStyle ) it 1765 might be necessary to call invalidateCache() for attributes 1766 that are relevant for this style. 1767 1768 \sa CachePolicy, setCachePolicy(), drawSymbols() 1741 1769 */ 1742 1770 void QwtSymbol::invalidateCache() 1743 1771 { 1744 if ( ! d_data->cache.pixmap.isNull() )1745 d_data->cache.pixmap = QPixmap();1746 } 1747 1748 /*! 1749 Specify the symbol style 1750 1751 \param style Style 1752 \sa style() 1753 */ 1772 if ( !m_data->cache.pixmap.isNull() ) 1773 m_data->cache.pixmap = QPixmap(); 1774 } 1775 1776 /*! 1777 Specify the symbol style 1778 1779 \param style Style 1780 \sa style() 1781 */ 1754 1782 void QwtSymbol::setStyle( QwtSymbol::Style style ) 1755 1783 { 1756 if ( d_data->style != style )1757 { 1758 d_data->style = style;1784 if ( m_data->style != style ) 1785 { 1786 m_data->style = style; 1759 1787 invalidateCache(); 1760 1788 } … … 1762 1790 1763 1791 /*! 1764 \return Current symbol style 1765 \sa setStyle() 1766 */ 1792 \return Current symbol style 1793 \sa setStyle() 1794 */ 1767 1795 QwtSymbol::Style QwtSymbol::style() const 1768 1796 { 1769 return d_data->style;1770 } 1797 return m_data->style; 1798 }
Note:
See TracChangeset
for help on using the changeset viewer.
