开源 企业版 高校版 私有云 模力方舟 AI 队友
代码拉取完成,页面将自动刷新
捐赠
捐赠前请先登录
扫描微信二维码支付
取消
支付完成
支付提示
将跳转至支付宝完成支付
确定
取消
1 Star 0 Fork 0

wingsummer/QWTPlot

加入 Gitee
与超过 1400万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
已有帐号? 立即登录
文件
master
分支 (1)
master
master
分支 (1)
master
克隆/下载
克隆/下载
提示
下载代码请复制以下命令到终端执行
为确保你提交的代码身份被 Gitee 正确识别,请执行以下命令完成配置
初次使用 SSH 协议进行代码克隆、推送等操作时,需按下述提示完成 SSH 配置
1 生成 RSA 密钥
2 获取 RSA 公钥内容,并配置到 SSH公钥
在 Gitee 上使用 SVN,请访问 使用指南
使用 HTTPS 协议时,命令行会出现如下账号密码验证步骤。基于安全考虑,Gitee 建议 配置并使用私人令牌 替代登录密码进行克隆、推送等操作
Username for 'https://gitee.com': userName
Password for 'https://userName@gitee.com': # 私人令牌
master
分支 (1)
master
qwtplot
/
plot
/
qwt_plot_curve.cpp
qwtplot
/
plot
/
qwt_plot_curve.cpp
qwt_plot_curve.cpp 33.36 KB
一键复制 编辑 原始数据 按行查看 历史
wingsummer 提交于 2022年11月24日 17:12 +08:00 . first commit
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235
/******************************************************************************
* Qwt Widget Library
* Copyright (C) 1997 Josef Wilgen
* Copyright (C) 2002 Uwe Rathmann
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the Qwt License, Version 1.0
*****************************************************************************/
#include "qwt_plot_curve.h"
#include "qwt_clipper.h"
#include "qwt_graphic.h"
#include "qwt_math.h"
#include "qwt_painter.h"
#include "qwt_plot.h"
#include "qwt_point_data.h"
#include "qwt_point_mapper.h"
#include "qwt_scale_map.h"
#include "qwt_spline_curve_fitter.h"
static inline QRectF qwtIntersectedClipRect(const QRectF &rect,
QPainter *painter) {
QRectF clipRect = rect;
if (painter->hasClipping())
clipRect &= painter->clipBoundingRect();
return clipRect;
}
static void qwtUpdateLegendIconSize(QwtPlotCurve *curve) {
if (curve->symbol() &&
curve->testLegendAttribute(QwtPlotCurve::LegendShowSymbol)) {
QSize sz = curve->symbol()->boundingRect().size();
sz += QSize(2, 2); // margin
if (curve->testLegendAttribute(QwtPlotCurve::LegendShowLine)) {
// Avoid, that the line is completely covered by the symbol
int w = qCeil(1.5 * sz.width());
if (w % 2)
w++;
sz.setWidth(qMax(8, w));
}
curve->setLegendIconSize(sz);
}
}
static int qwtVerifyRange(int size, int &i1, int &i2) {
if (size < 1)
return 0;
i1 = qBound(0, i1, size - 1);
i2 = qBound(0, i2, size - 1);
if (i1 > i2)
qSwap(i1, i2);
return (i2 - i1 + 1);
}
class QwtPlotCurve::PrivateData {
public:
PrivateData()
: style(QwtPlotCurve::Lines), baseline(0.0), symbol(nullptr),
pen(Qt::black), paintAttributes(QwtPlotCurve::ClipPolygons |
QwtPlotCurve::FilterPoints) {
curveFitter = new QwtSplineCurveFitter;
}
~PrivateData() {
delete symbol;
delete curveFitter;
}
QwtPlotCurve::CurveStyle style;
double baseline;
const QwtSymbol *symbol;
QwtCurveFitter *curveFitter;
QPen pen;
QBrush brush;
QwtPlotCurve::CurveAttributes attributes;
QwtPlotCurve::PaintAttributes paintAttributes;
QwtPlotCurve::LegendAttributes legendAttributes;
};
/*!
Constructor
\param title Title of the curve
*/
QwtPlotCurve::QwtPlotCurve(const QwtText &title) : QwtPlotSeriesItem(title) {
init();
}
/*!
Constructor
\param title Title of the curve
*/
QwtPlotCurve::QwtPlotCurve(const QString &title)
: QwtPlotSeriesItem(QwtText(title)) {
init();
}
//! Destructor
QwtPlotCurve::~QwtPlotCurve() { delete m_data; }
//! Initialize internal members
void QwtPlotCurve::init() {
setItemAttribute(QwtPlotItem::Legend);
setItemAttribute(QwtPlotItem::AutoScale);
setRenderHint(QwtPlotCurve::RenderAntialiased);
m_data = new PrivateData;
setData(new QwtPointSeriesData());
setZ(20.0);
}
//! \return QwtPlotItem::Rtti_PlotCurve
int QwtPlotCurve::rtti() const { return QwtPlotItem::Rtti_PlotCurve; }
/*!
Specify an attribute how to draw the curve
\param attribute Paint attribute
\param on On/Off
\sa testPaintAttribute()
*/
void QwtPlotCurve::setPaintAttribute(PaintAttribute attribute, bool on) {
if (on)
m_data->paintAttributes |= attribute;
else
m_data->paintAttributes &= ~attribute;
}
/*!
\return True, when attribute is enabled
\sa setPaintAttribute()
*/
bool QwtPlotCurve::testPaintAttribute(PaintAttribute attribute) const {
return (m_data->paintAttributes & attribute);
}
/*!
Specify an attribute how to draw the legend icon
\param attribute Attribute
\param on On/Off
/sa testLegendAttribute(). legendIcon()
*/
void QwtPlotCurve::setLegendAttribute(LegendAttribute attribute, bool on) {
if (on != testLegendAttribute(attribute)) {
if (on)
m_data->legendAttributes |= attribute;
else
m_data->legendAttributes &= ~attribute;
qwtUpdateLegendIconSize(this);
legendChanged();
}
}
/*!
\return True, when attribute is enabled
\sa setLegendAttribute()
*/
bool QwtPlotCurve::testLegendAttribute(LegendAttribute attribute) const {
return (m_data->legendAttributes & attribute);
}
/*!
Specify the attributes how to draw the legend icon
\param attributes Attributes
/sa setLegendAttribute(). legendIcon()
*/
void QwtPlotCurve::setLegendAttributes(LegendAttributes attributes) {
if (attributes != m_data->legendAttributes) {
m_data->legendAttributes = attributes;
qwtUpdateLegendIconSize(this);
legendChanged();
}
}
/*!
\return Attributes how to draw the legend icon
\sa setLegendAttributes(), testLegendAttribute()
*/
QwtPlotCurve::LegendAttributes QwtPlotCurve::legendAttributes() const {
return m_data->legendAttributes;
}
/*!
Set the curve's drawing style
\param style Curve style
\sa style()
*/
void QwtPlotCurve::setStyle(CurveStyle style) {
if (style != m_data->style) {
m_data->style = style;
legendChanged();
itemChanged();
}
}
/*!
\return Style of the curve
\sa setStyle()
*/
QwtPlotCurve::CurveStyle QwtPlotCurve::style() const { return m_data->style; }
/*!
\brief Assign a symbol
The curve will take the ownership of the symbol, hence the previously
set symbol will be delete by setting a new one. If \p symbol is
\c NULL no symbol will be drawn.
\param symbol Symbol
\sa symbol()
*/
void QwtPlotCurve::setSymbol(QwtSymbol *symbol) {
if (symbol != m_data->symbol) {
delete m_data->symbol;
m_data->symbol = symbol;
qwtUpdateLegendIconSize(this);
legendChanged();
itemChanged();
}
}
/*!
\return Current symbol or NULL, when no symbol has been assigned
\sa setSymbol()
*/
const QwtSymbol *QwtPlotCurve::symbol() const { return m_data->symbol; }
/*!
Build and assign a pen
In Qt5 the default pen width is 1.0 ( 0.0 in Qt4 ) what makes it
non cosmetic ( see QPen::isCosmetic() ). This method has been introduced
to hide this incompatibility.
\param color Pen color
\param width Pen width
\param style Pen style
\sa pen(), brush()
*/
void QwtPlotCurve::setPen(const QColor &color, qreal width,
Qt::PenStyle style) {
setPen(QPen(color, width, style));
}
/*!
Assign a pen
\param pen New pen
\sa pen(), brush()
*/
void QwtPlotCurve::setPen(const QPen &pen) {
if (pen != m_data->pen) {
m_data->pen = pen;
legendChanged();
itemChanged();
}
}
/*!
\return Pen used to draw the lines
\sa setPen(), brush()
*/
const QPen &QwtPlotCurve::pen() const { return m_data->pen; }
/*!
\brief Assign a brush.
In case of brush.style() != QBrush::NoBrush
and style() != QwtPlotCurve::Sticks
the area between the curve and the baseline will be filled.
In case !brush.color().isValid() the area will be filled by
pen.color(). The fill algorithm simply connects the first and the
last curve point to the baseline. So the curve data has to be sorted
(ascending or descending).
\param brush New brush
\sa brush(), setBaseline(), baseline()
*/
void QwtPlotCurve::setBrush(const QBrush &brush) {
if (brush != m_data->brush) {
m_data->brush = brush;
legendChanged();
itemChanged();
}
}
/*!
\return Brush used to fill the area between lines and the baseline
\sa setBrush(), setBaseline(), baseline()
*/
const QBrush &QwtPlotCurve::brush() const { return m_data->brush; }
/*!
Draw an interval of the curve
\param painter Painter
\param xMap Maps x-values into pixel coordinates.
\param yMap Maps y-values into pixel coordinates.
\param canvasRect Contents rectangle of the canvas
\param from Index of the first point to be painted
\param to Index of the last point to be painted. If to < 0 the
curve will be painted to its last point.
\sa drawCurve(), drawSymbols(),
*/
void QwtPlotCurve::drawSeries(QPainter *painter, const QwtScaleMap &xMap,
const QwtScaleMap &yMap, const QRectF &canvasRect,
int from, int to) const {
const size_t numSamples = dataSize();
if (!painter || numSamples <= 0)
return;
if (to < 0)
to = int(numSamples - 1);
if (qwtVerifyRange(int(numSamples), from, to) > 0) {
painter->save();
painter->setPen(m_data->pen);
/*
Qt 4.0.0 is slow when drawing lines, but it's even
slower when the painter has a brush. So we don't
set the brush before we really need it.
*/
drawCurve(painter, m_data->style, xMap, yMap, canvasRect, from, to);
painter->restore();
if (m_data->symbol && (m_data->symbol->style() != QwtSymbol::NoSymbol)) {
painter->save();
drawSymbols(painter, *m_data->symbol, xMap, yMap, canvasRect, from, to);
painter->restore();
}
}
}
/*!
\brief Draw the line part (without symbols) of a curve interval.
\param painter Painter
\param style curve style, see QwtPlotCurve::CurveStyle
\param xMap x map
\param yMap y map
\param canvasRect Contents rectangle of the canvas
\param from index of the first point to be painted
\param to index of the last point to be painted
\sa draw(), drawDots(), drawLines(), drawSteps(), drawSticks()
*/
void QwtPlotCurve::drawCurve(QPainter *painter, int style,
const QwtScaleMap &xMap, const QwtScaleMap &yMap,
const QRectF &canvasRect, int from, int to) const {
switch (style) {
case Lines:
if (testCurveAttribute(Fitted)) {
// we always need the complete
// curve for fitting
from = 0;
to = int(dataSize() - 1);
}
drawLines(painter, xMap, yMap, canvasRect, from, to);
break;
case Sticks:
drawSticks(painter, xMap, yMap, canvasRect, from, to);
break;
case Steps:
drawSteps(painter, xMap, yMap, canvasRect, from, to);
break;
case Dots:
drawDots(painter, xMap, yMap, canvasRect, from, to);
break;
case NoCurve:
default:
break;
}
}
/*!
\brief Draw lines
If the CurveAttribute Fitted is enabled a QwtCurveFitter tries
to interpolate/smooth the curve, before it is painted.
\param painter Painter
\param xMap x map
\param yMap y map
\param canvasRect Contents rectangle of the canvas
\param from index of the first point to be painted
\param to index of the last point to be painted
\sa setCurveAttribute(), setCurveFitter(), draw(),
drawLines(), drawDots(), drawSteps(), drawSticks()
*/
void QwtPlotCurve::drawLines(QPainter *painter, const QwtScaleMap &xMap,
const QwtScaleMap &yMap, const QRectF &canvasRect,
int from, int to) const {
if (from > to)
return;
const bool doFit = (m_data->attributes & Fitted) && m_data->curveFitter;
const bool doAlign = !doFit && QwtPainter::roundingAlignment(painter);
const bool doFill = (m_data->brush.style() != Qt::NoBrush) &&
(m_data->brush.color().alpha() > 0);
QRectF clipRect;
if (m_data->paintAttributes & ClipPolygons) {
clipRect = qwtIntersectedClipRect(canvasRect, painter);
const qreal pw = QwtPainter::effectivePenWidth(painter->pen());
clipRect = clipRect.adjusted(-pw, -pw, pw, pw);
}
QwtPointMapper mapper;
if (doAlign) {
mapper.setFlag(QwtPointMapper::RoundPoints, true);
mapper.setFlag(QwtPointMapper::WeedOutIntermediatePoints,
testPaintAttribute(FilterPointsAggressive));
}
mapper.setFlag(QwtPointMapper::WeedOutPoints,
testPaintAttribute(FilterPoints) ||
testPaintAttribute(FilterPointsAggressive));
mapper.setBoundingRect(canvasRect);
QPolygonF polyline = mapper.toPolygonF(xMap, yMap, data(), from, to);
if (doFill) {
if (doFit) {
// it might be better to extend and draw the curvePath, but for
// the moment we keep an implementation, where we translate the
// path back to a polyline.
polyline = m_data->curveFitter->fitCurve(polyline);
}
if (painter->pen().style() != Qt::NoPen) {
// here we are wasting memory for the filled copy,
// do polygon clipping twice etc .. TODO
QPolygonF filled = polyline;
fillCurve(painter, xMap, yMap, canvasRect, filled);
filled.clear();
if (m_data->paintAttributes & ClipPolygons)
QwtClipper::clipPolygonF(clipRect, polyline, false);
QwtPainter::drawPolyline(painter, polyline);
} else {
fillCurve(painter, xMap, yMap, canvasRect, polyline);
}
} else {
if (testPaintAttribute(ClipPolygons)) {
QwtClipper::clipPolygonF(clipRect, polyline, false);
}
if (doFit) {
if (m_data->curveFitter->mode() == QwtCurveFitter::Path) {
const QPainterPath curvePath =
m_data->curveFitter->fitCurvePath(polyline);
painter->drawPath(curvePath);
} else {
polyline = m_data->curveFitter->fitCurve(polyline);
QwtPainter::drawPolyline(painter, polyline);
}
} else {
QwtPainter::drawPolyline(painter, polyline);
}
}
}
/*!
Draw sticks
\param painter Painter
\param xMap x map
\param yMap y map
\param canvasRect Contents rectangle of the canvas
\param from index of the first point to be painted
\param to index of the last point to be painted
\sa draw(), drawCurve(), drawDots(), drawLines(), drawSteps()
*/
void QwtPlotCurve::drawSticks(QPainter *painter, const QwtScaleMap &xMap,
const QwtScaleMap &yMap, const QRectF &canvasRect,
int from, int to) const {
Q_UNUSED(canvasRect)
painter->save();
painter->setRenderHint(QPainter::Antialiasing, false);
const bool doAlign = QwtPainter::roundingAlignment(painter);
double x0 = xMap.transform(m_data->baseline);
double y0 = yMap.transform(m_data->baseline);
if (doAlign) {
x0 = qRound(x0);
y0 = qRound(y0);
}
const Qt::Orientation o = orientation();
const QwtSeriesData<QPointF> *series = data();
for (int i = from; i <= to; i++) {
const QPointF sample = series->sample(size_t(i));
double xi = xMap.transform(sample.x());
double yi = yMap.transform(sample.y());
if (doAlign) {
xi = qRound(xi);
yi = qRound(yi);
}
if (o == Qt::Horizontal)
QwtPainter::drawLine(painter, x0, yi, xi, yi);
else
QwtPainter::drawLine(painter, xi, y0, xi, yi);
}
painter->restore();
}
/*!
Draw dots
\param painter Painter
\param xMap x map
\param yMap y map
\param canvasRect Contents rectangle of the canvas
\param from index of the first point to be painted
\param to index of the last point to be painted
\sa draw(), drawCurve(), drawSticks(), drawLines(), drawSteps()
*/
void QwtPlotCurve::drawDots(QPainter *painter, const QwtScaleMap &xMap,
const QwtScaleMap &yMap, const QRectF &canvasRect,
int from, int to) const {
const QColor color = painter->pen().color();
if (painter->pen().style() == Qt::NoPen || color.alpha() == 0) {
return;
}
const bool doFill = (m_data->brush.style() != Qt::NoBrush) &&
(m_data->brush.color().alpha() > 0);
const bool doAlign = QwtPainter::roundingAlignment(painter);
QwtPointMapper mapper;
mapper.setBoundingRect(canvasRect);
mapper.setFlag(QwtPointMapper::RoundPoints, doAlign);
if (m_data->paintAttributes & FilterPoints) {
if ((color.alpha() == 255) &&
!(painter->renderHints() & QPainter::Antialiasing)) {
mapper.setFlag(QwtPointMapper::WeedOutPoints, true);
}
}
if (doFill) {
mapper.setFlag(QwtPointMapper::WeedOutPoints, false);
QPolygonF points = mapper.toPolygonF(xMap, yMap, data(), from, to);
QwtPainter::drawPoints(painter, points);
fillCurve(painter, xMap, yMap, canvasRect, points);
} else if (m_data->paintAttributes & ImageBuffer) {
const QImage image = mapper.toImage(
xMap, yMap, data(), from, to, m_data->pen,
painter->testRenderHint(QPainter::Antialiasing), renderThreadCount());
painter->drawImage(canvasRect.toAlignedRect(), image);
} else if (m_data->paintAttributes & MinimizeMemory) {
const QwtSeriesData<QPointF> *series = data();
for (int i = from; i <= to; i++) {
const QPointF sample = series->sample(size_t(i));
double xi = xMap.transform(sample.x());
double yi = yMap.transform(sample.y());
if (doAlign) {
xi = qRound(xi);
yi = qRound(yi);
}
QwtPainter::drawPoint(painter, QPointF(xi, yi));
}
} else {
if (doAlign) {
const QPolygon points = mapper.toPoints(xMap, yMap, data(), from, to);
QwtPainter::drawPoints(painter, points);
} else {
const QPolygonF points = mapper.toPointsF(xMap, yMap, data(), from, to);
QwtPainter::drawPoints(painter, points);
}
}
}
/*!
Draw step function
The direction of the steps depends on Inverted attribute.
\param painter Painter
\param xMap x map
\param yMap y map
\param canvasRect Contents rectangle of the canvas
\param from index of the first point to be painted
\param to index of the last point to be painted
\sa CurveAttribute, setCurveAttribute(),
draw(), drawCurve(), drawDots(), drawLines(), drawSticks()
*/
void QwtPlotCurve::drawSteps(QPainter *painter, const QwtScaleMap &xMap,
const QwtScaleMap &yMap, const QRectF &canvasRect,
int from, int to) const {
const bool doAlign = QwtPainter::roundingAlignment(painter);
QPolygonF polygon(2 * (to - from) + 1);
QPointF *points = polygon.data();
bool inverted = orientation() == Qt::Vertical;
if (m_data->attributes & Inverted)
inverted = !inverted;
const QwtSeriesData<QPointF> *series = data();
int i, ip;
for (i = from, ip = 0; i <= to; i++, ip += 2) {
const QPointF sample = series->sample(size_t(i));
double xi = xMap.transform(sample.x());
double yi = yMap.transform(sample.y());
if (doAlign) {
xi = qRound(xi);
yi = qRound(yi);
}
if (ip > 0) {
const QPointF &p0 = points[ip - 2];
QPointF &p = points[ip - 1];
if (inverted) {
p.rx() = p0.x();
p.ry() = yi;
} else {
p.rx() = xi;
p.ry() = p0.y();
}
}
points[ip].rx() = xi;
points[ip].ry() = yi;
}
if (m_data->paintAttributes & ClipPolygons) {
QRectF clipRect = qwtIntersectedClipRect(canvasRect, painter);
const qreal pw = QwtPainter::effectivePenWidth(painter->pen());
clipRect = clipRect.adjusted(-pw, -pw, pw, pw);
const QPolygonF clipped =
QwtClipper::clippedPolygonF(clipRect, polygon, false);
QwtPainter::drawPolyline(painter, clipped);
} else {
QwtPainter::drawPolyline(painter, polygon);
}
if (m_data->brush.style() != Qt::NoBrush)
fillCurve(painter, xMap, yMap, canvasRect, polygon);
}
/*!
Specify an attribute for drawing the curve
\param attribute Curve attribute
\param on On/Off
/sa testCurveAttribute(), setCurveFitter()
*/
void QwtPlotCurve::setCurveAttribute(CurveAttribute attribute, bool on) {
if (bool(m_data->attributes & attribute) == on)
return;
if (on)
m_data->attributes |= attribute;
else
m_data->attributes &= ~attribute;
itemChanged();
}
/*!
\return true, if attribute is enabled
\sa setCurveAttribute()
*/
bool QwtPlotCurve::testCurveAttribute(CurveAttribute attribute) const {
return m_data->attributes & attribute;
}
/*!
Assign a curve fitter
The curve fitter "smooths" the curve points, when the Fitted
CurveAttribute is set. setCurveFitter(NULL) also disables curve fitting.
The curve fitter operates on the translated points ( = widget coordinates)
to be functional for logarithmic scales. Obviously this is less performant
for fitting algorithms, that reduce the number of points.
For situations, where curve fitting is used to improve the performance
of painting huge series of points it might be better to execute the fitter
on the curve points once and to cache the result in the QwtSeriesData object.
\param curveFitter() Curve fitter
\sa Fitted
*/
void QwtPlotCurve::setCurveFitter(QwtCurveFitter *curveFitter) {
delete m_data->curveFitter;
m_data->curveFitter = curveFitter;
itemChanged();
}
/*!
Get the curve fitter. If curve fitting is disabled NULL is returned.
\return Curve fitter
\sa setCurveFitter(), Fitted
*/
QwtCurveFitter *QwtPlotCurve::curveFitter() const {
return m_data->curveFitter;
}
/*!
Fill the area between the curve and the baseline with
the curve brush
\param painter Painter
\param xMap x map
\param yMap y map
\param canvasRect Contents rectangle of the canvas
\param polygon Polygon - will be modified !
\sa setBrush(), setBaseline(), setStyle()
*/
void QwtPlotCurve::fillCurve(QPainter *painter, const QwtScaleMap &xMap,
const QwtScaleMap &yMap, const QRectF &canvasRect,
QPolygonF &polygon) const {
if (m_data->brush.style() == Qt::NoBrush)
return;
closePolyline(painter, xMap, yMap, polygon);
if (polygon.count() <= 2) // a line can't be filled
return;
QBrush brush = m_data->brush;
if (!brush.color().isValid())
brush.setColor(m_data->pen.color());
if (m_data->paintAttributes & ClipPolygons) {
const QRectF clipRect = qwtIntersectedClipRect(canvasRect, painter);
QwtClipper::clipPolygonF(clipRect, polygon, true);
}
painter->save();
painter->setPen(Qt::NoPen);
painter->setBrush(brush);
QwtPainter::drawPolygon(painter, polygon);
painter->restore();
}
/*!
\brief Complete a polygon to be a closed polygon including the
area between the original polygon and the baseline.
\param painter Painter
\param xMap X map
\param yMap Y map
\param polygon Polygon to be completed
*/
void QwtPlotCurve::closePolyline(QPainter *painter, const QwtScaleMap &xMap,
const QwtScaleMap &yMap,
QPolygonF &polygon) const {
if (polygon.size() < 2)
return;
const bool doAlign = QwtPainter::roundingAlignment(painter);
double baseline = m_data->baseline;
if (orientation() == Qt::Vertical) {
if (yMap.transformation())
baseline = yMap.transformation()->bounded(baseline);
double refY = yMap.transform(baseline);
if (doAlign)
refY = qRound(refY);
polygon += QPointF(polygon.last().x(), refY);
polygon += QPointF(polygon.first().x(), refY);
} else {
if (xMap.transformation())
baseline = xMap.transformation()->bounded(baseline);
double refX = xMap.transform(baseline);
if (doAlign)
refX = qRound(refX);
polygon += QPointF(refX, polygon.last().y());
polygon += QPointF(refX, polygon.first().y());
}
}
/*!
Draw symbols
\param painter Painter
\param symbol Curve symbol
\param xMap x map
\param yMap y map
\param canvasRect Contents rectangle of the canvas
\param from Index of the first point to be painted
\param to Index of the last point to be painted
\sa setSymbol(), drawSeries(), drawCurve()
*/
void QwtPlotCurve::drawSymbols(QPainter *painter, const QwtSymbol &symbol,
const QwtScaleMap &xMap, const QwtScaleMap &yMap,
const QRectF &canvasRect, int from,
int to) const {
QwtPointMapper mapper;
mapper.setFlag(QwtPointMapper::RoundPoints,
QwtPainter::roundingAlignment(painter));
mapper.setFlag(QwtPointMapper::WeedOutPoints,
testPaintAttribute(QwtPlotCurve::FilterPoints));
const QRectF clipRect = qwtIntersectedClipRect(canvasRect, painter);
mapper.setBoundingRect(clipRect);
const int chunkSize = 500;
for (int i = from; i <= to; i += chunkSize) {
const int n = qMin(chunkSize, to - i + 1);
const QPolygonF points = mapper.toPointsF(xMap, yMap, data(), i, i + n - 1);
if (points.size() > 0)
symbol.drawSymbols(painter, points);
}
}
/*!
\brief Set the value of the baseline
The baseline is needed for filling the curve with a brush or
the Sticks drawing style.
The interpretation of the baseline depends on the orientation().
With Qt::Vertical, the baseline is interpreted as a horizontal line
at y = baseline(), with Qt::Horizontal, it is interpreted as a vertical
line at x = baseline().
The default value is 0.0.
\param value Value of the baseline
\sa baseline(), setBrush(), setStyle(),
QwtPlotAbstractSeriesItem::orientation()
*/
void QwtPlotCurve::setBaseline(double value) {
if (!qFuzzyCompare(m_data->baseline, value)) {
m_data->baseline = value;
itemChanged();
}
}
/*!
\return Value of the baseline
\sa setBaseline()
*/
double QwtPlotCurve::baseline() const { return m_data->baseline; }
/*!
Find the closest curve point for a specific position
\param pos Position, where to look for the closest curve point
\param dist If dist != NULL, closestPoint() returns the distance between
the position and the closest curve point
\return Index of the closest curve point, or -1 if none can be found
( f.e when the curve has no points )
\note closestPoint() implements a dumb algorithm, that iterates
over all points
*/
int QwtPlotCurve::closestPoint(const QPointF &pos, double *dist) const {
const size_t numSamples = dataSize();
if (plot() == nullptr || numSamples <= 0)
return -1;
const QwtSeriesData<QPointF> *series = data();
const QwtScaleMap xMap = plot()->canvasMap(xAxis());
const QwtScaleMap yMap = plot()->canvasMap(yAxis());
int index = -1;
double dmin = 1.0e10;
for (uint i = 0; i < numSamples; i++) {
const QPointF sample = series->sample(i);
const double cx = xMap.transform(sample.x()) - pos.x();
const double cy = yMap.transform(sample.y()) - pos.y();
const double f = qwtSqr(cx) + qwtSqr(cy);
if (f < dmin) {
index = int(i);
dmin = f;
}
}
if (dist)
*dist = std::sqrt(dmin);
return index;
}
/*!
\return Icon representing the curve on the legend
\param index Index of the legend entry
( ignored as there is only one )
\param size Icon size
\sa QwtPlotItem::setLegendIconSize(), QwtPlotItem::legendData()
*/
QwtGraphic QwtPlotCurve::legendIcon(int index, const QSizeF &size) const {
Q_UNUSED(index);
if (size.isEmpty())
return QwtGraphic();
QwtGraphic graphic;
graphic.setDefaultSize(size);
graphic.setRenderHint(QwtGraphic::RenderPensUnscaled, true);
QPainter painter(&graphic);
painter.setRenderHint(QPainter::Antialiasing,
testRenderHint(QwtPlotItem::RenderAntialiased));
if (m_data->legendAttributes == 0 ||
m_data->legendAttributes & QwtPlotCurve::LegendShowBrush) {
QBrush brush = m_data->brush;
if (brush.style() == Qt::NoBrush && m_data->legendAttributes == 0) {
if (style() != QwtPlotCurve::NoCurve) {
brush = QBrush(pen().color());
} else if (m_data->symbol &&
(m_data->symbol->style() != QwtSymbol::NoSymbol)) {
brush = QBrush(m_data->symbol->pen().color());
}
}
if (brush.style() != Qt::NoBrush) {
QRectF r(0, 0, size.width(), size.height());
painter.fillRect(r, brush);
}
}
if (m_data->legendAttributes & QwtPlotCurve::LegendShowLine) {
if (pen() != Qt::NoPen) {
QPen pn = pen();
pn.setCapStyle(Qt::FlatCap);
painter.setPen(pn);
const double y = 0.5 * size.height();
QwtPainter::drawLine(&painter, 0.0, y, size.width(), y);
}
}
if (m_data->legendAttributes & QwtPlotCurve::LegendShowSymbol) {
if (m_data->symbol) {
QRectF r(0, 0, size.width(), size.height());
m_data->symbol->drawSymbol(&painter, r);
}
}
return graphic;
}
/*!
Assign a series of points
setSamples() is just a wrapper for setData() without any additional
value - beside that it is easier to find for the developer.
\param data Data
\warning The item takes ownership of the data object, deleting
it when its not used anymore.
*/
void QwtPlotCurve::setSamples(QwtSeriesData<QPointF> *data) { setData(data); }
/*!
Initialize data with an array of points.
\param samples Vector of points
\note QVector is implicitly shared
\note QPolygonF is derived from QVector<QPointF>
*/
void QwtPlotCurve::setSamples(const QVector<QPointF> &samples) {
setData(new QwtPointSeriesData(samples));
}
/*!
\brief Initialize the data by pointing to memory blocks which
are not managed by QwtPlotCurve.
setRawSamples is provided for efficiency.
It is important to keep the pointers
during the lifetime of the underlying QwtCPointerData class.
\param xData pointer to x data
\param yData pointer to y data
\param size size of x and y
\sa QwtCPointerData
*/
void QwtPlotCurve::setRawSamples(const double *xData, const double *yData,
int size) {
setData(new QwtCPointerData<double>(xData, yData, size_t(size)));
}
/*!
\brief Initialize the data by pointing to memory blocks which
are not managed by QwtPlotCurve.
setRawSamples is provided for efficiency.
It is important to keep the pointers
during the lifetime of the underlying QwtCPointerData class.
\param xData pointer to x data
\param yData pointer to y data
\param size size of x and y
\sa QwtCPointerData
*/
void QwtPlotCurve::setRawSamples(const float *xData, const float *yData,
int size) {
setData(new QwtCPointerData<float>(xData, yData, size_t(size)));
}
/*!
\brief Initialize the data by pointing to a memory block which
is not managed by QwtPlotCurve.
The memory contains the y coordinates, while the index is
interpreted as x coordinate.
setRawSamples() is provided for efficiency. It is important to
keep the pointers during the lifetime of the underlying
QwtCPointerValueData class.
\param yData pointer to y data
\param size size of x and y
\sa QwtCPointerData
*/
void QwtPlotCurve::setRawSamples(const double *yData, int size) {
setData(new QwtCPointerValueData<double>(yData, size_t(size)));
}
/*!
\brief Initialize the data by pointing to memory blocks which
are not managed by QwtPlotCurve.
The memory contains the y coordinates, while the index is
interpreted as x coordinate.
setRawSamples() is provided for efficiency. It is important to
keep the pointers during the lifetime of the underlying
QwtCPointerValueData class.
\param yData pointer to y data
\param size size of x and y
\sa QwtCPointerData
*/
void QwtPlotCurve::setRawSamples(const float *yData, int size) {
setData(new QwtCPointerValueData<float>(yData, size_t(size)));
}
/*!
Set data by copying x- and y-values from specified memory blocks.
Contrary to setRawSamples(), this function makes a 'deep copy' of
the data.
\param xData pointer to x values
\param yData pointer to y values
\param size size of xData and yData
\sa QwtPointArrayData
*/
void QwtPlotCurve::setSamples(const double *xData, const double *yData,
int size) {
setData(new QwtPointArrayData<double>(xData, yData, size_t(size)));
}
/*!
Set data by copying x- and y-values from specified memory blocks.
Contrary to setRawSamples(), this function makes a 'deep copy' of
the data.
\param xData pointer to x values
\param yData pointer to y values
\param size size of xData and yData
\sa QwtPointArrayData
*/
void QwtPlotCurve::setSamples(const float *xData, const float *yData,
int size) {
setData(new QwtPointArrayData<float>(xData, yData, size_t(size)));
}
/*!
\brief Initialize data with x- and y-arrays (explicitly shared)
\param xData x data
\param yData y data
\sa QwtPointArrayData
*/
void QwtPlotCurve::setSamples(const QVector<double> &xData,
const QVector<double> &yData) {
setData(new QwtPointArrayData<double>(xData, yData));
}
/*!
\brief Initialize data with x- and y-arrays (explicitly shared)
\param xData x data
\param yData y data
\sa QwtPointArrayData
*/
void QwtPlotCurve::setSamples(const QVector<float> &xData,
const QVector<float> &yData) {
setData(new QwtPointArrayData<float>(xData, yData));
}
/*!
Set data by copying y-values from a specified memory block.
The memory contains the y coordinates, while the index is
interpreted as x coordinate.
\param yData y data
\param size size of yData
\sa QwtValuePointData
*/
void QwtPlotCurve::setSamples(const double *yData, int size) {
setData(new QwtValuePointData<double>(yData, size_t(size)));
}
/*!
Set data by copying y-values from a specified memory block.
The vector contains the y coordinates, while the index is
interpreted as x coordinate.
\param yData y data
\param size size of yData
\sa QwtValuePointData
*/
void QwtPlotCurve::setSamples(const float *yData, int size) {
setData(new QwtValuePointData<float>(yData, size_t(size)));
}
/*!
Initialize data with an array of y values (explicitly shared)
The vector contains the y coordinates, while the index is
the x coordinate.
\param yData y data
\sa QwtValuePointData
*/
void QwtPlotCurve::setSamples(const QVector<double> &yData) {
setData(new QwtValuePointData<double>(yData));
}
/*!
Initialize data with an array of y values (explicitly shared)
The vector contains the y coordinates, while the index is
the x coordinate.
\param yData y data
\sa QwtValuePointData
*/
void QwtPlotCurve::setSamples(const QVector<float> &yData) {
setData(new QwtValuePointData<float>(yData));
}
Loading...
举报
举报成功
我们将于2个工作日内通过站内信反馈结果给你!
请认真填写举报原因,尽可能描述详细。
请选择举报类型
取消
发送
误判申诉

此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。

如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。

取消
提交

简介

本组件是基于 qwt 进行定制得到,只保留部分图表相关模块
暂无标签
LGPL-2.1
使用 LGPL-2.1 开源许可协议
取消

发行版

暂无发行版

贡献者

全部

近期动态

不能加载更多了
编辑仓库简介
简介内容
主页
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C++
1
https://gitee.com/wingsummer/qwtplot.git
git@gitee.com:wingsummer/qwtplot.git
wingsummer
qwtplot
QWTPlot
master
点此查找更多帮助

搜索帮助

评论
仓库举报
回到顶部
登录提示
该操作需登录 Gitee 帐号,请先登录后再操作。
立即登录
没有帐号,去注册

AltStyle によって変換されたページ (->オリジナル) /