开源 企业版 高校版 私有云 模力方舟 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.cpp
qwtplot
/
plot
/
qwt_plot.cpp
qwt_plot.cpp 27.49 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
/******************************************************************************
* 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.h"
#include "qwt_legend.h"
#include "qwt_legend_data.h"
#include "qwt_math.h"
#include "qwt_plot_canvas.h"
#include "qwt_plot_dict.h"
#include "qwt_plot_layout.h"
#include "qwt_scale_engine.h"
#include "qwt_scale_map.h"
#include "qwt_scale_widget.h"
#include "qwt_text_label.h"
#include <qapplication.h>
#include <qcoreevent.h>
#include <qpainter.h>
#include <qpointer.h>
static inline void qwtEnableLegendItems(QwtPlot *plot, bool on) {
// gcc seems to have problems with const char sig[] in combination with
// certain options
const char *sig = SIGNAL(legendDataChanged(QVariant, QList<QwtLegendData>));
const char *slot = SLOT(updateLegendItems(QVariant, QList<QwtLegendData>));
if (on)
QObject::connect(plot, sig, plot, slot);
else
QObject::disconnect(plot, sig, plot, slot);
}
static void qwtSetTabOrder(QWidget *first, QWidget *second, bool withChildren) {
QList<QWidget *> tabChain;
tabChain += first;
tabChain += second;
if (withChildren) {
QList<QWidget *> children = second->findChildren<QWidget *>();
QWidget *w = second->nextInFocusChain();
while (children.contains(w)) {
children.removeAll(w);
tabChain += w;
w = w->nextInFocusChain();
}
}
for (int i = 0; i < tabChain.size() - 1; i++) {
QWidget *from = tabChain[i];
QWidget *to = tabChain[i + 1];
const Qt::FocusPolicy policy1 = from->focusPolicy();
const Qt::FocusPolicy policy2 = to->focusPolicy();
QWidget *proxy1 = from->focusProxy();
QWidget *proxy2 = to->focusProxy();
from->setFocusPolicy(Qt::TabFocus);
from->setFocusProxy(nullptr);
to->setFocusPolicy(Qt::TabFocus);
to->setFocusProxy(nullptr);
QWidget::setTabOrder(from, to);
from->setFocusPolicy(policy1);
from->setFocusProxy(proxy1);
to->setFocusPolicy(policy2);
to->setFocusProxy(proxy2);
}
}
class QwtPlot::PrivateData {
public:
QPointer<QwtTextLabel> titleLabel;
QPointer<QwtTextLabel> footerLabel;
QPointer<QWidget> canvas;
QPointer<QwtAbstractLegend> legend;
QwtPlotLayout *layout;
bool autoReplot;
};
/*!
\brief Constructor
\param parent Parent widget
*/
QwtPlot::QwtPlot(QWidget *parent) : QFrame(parent) { initPlot(QwtText()); }
/*!
\brief Constructor
\param title Title text
\param parent Parent widget
*/
QwtPlot::QwtPlot(const QwtText &title, QWidget *parent) : QFrame(parent) {
initPlot(title);
}
//! Destructor
QwtPlot::~QwtPlot() {
setAutoReplot(false);
detachItems(QwtPlotItem::Rtti_PlotItem, autoDelete());
delete m_data->layout;
deleteAxesData();
delete m_data;
}
/*!
\brief Initializes a QwtPlot instance
\param title Title text
*/
void QwtPlot::initPlot(const QwtText &title) {
m_data = new PrivateData;
m_data->layout = new QwtPlotLayout;
m_data->autoReplot = false;
// title
m_data->titleLabel = new QwtTextLabel(this);
m_data->titleLabel->setObjectName("QwtPlotTitle");
m_data->titleLabel->setFont(QFont(fontInfo().family(), 14, QFont::Bold));
QwtText text(title);
text.setRenderFlags(Qt::AlignCenter | Qt::TextWordWrap);
m_data->titleLabel->setText(text);
// footer
m_data->footerLabel = new QwtTextLabel(this);
m_data->footerLabel->setObjectName("QwtPlotFooter");
QwtText footer;
footer.setRenderFlags(Qt::AlignCenter | Qt::TextWordWrap);
m_data->footerLabel->setText(footer);
// legend
m_data->legend = nullptr;
// axes
initAxesData();
// canvas
m_data->canvas = new QwtPlotCanvas(this);
m_data->canvas->setObjectName("QwtPlotCanvas");
m_data->canvas->installEventFilter(this);
setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding);
resize(200, 200);
using namespace QwtAxis;
QList<QWidget *> focusChain;
focusChain << this << m_data->titleLabel << axisWidget(XTop)
<< axisWidget(YLeft) << m_data->canvas << axisWidget(YRight)
<< axisWidget(XBottom) << m_data->footerLabel;
for (int i = 0; i < focusChain.size() - 1; i++)
qwtSetTabOrder(focusChain[i], focusChain[i + 1], false);
qwtEnableLegendItems(this, true);
}
/*!
\brief Set the drawing canvas of the plot widget
QwtPlot invokes methods of the canvas as meta methods ( see QMetaObject ).
In opposite to using conventional C++ techniques like virtual methods
they allow to use canvas implementations that are derived from
QWidget or QGLWidget.
The following meta methods could be implemented:
- replot()
When the canvas doesn't offer a replot method, QwtPlot calls
update() instead.
- borderPath()
The border path is necessary to clip the content of the canvas
When the canvas doesn't have any special border ( f.e rounded corners )
it is o.k. not to implement this method.
The default canvas is a QwtPlotCanvas
\param canvas Canvas Widget
\sa canvas()
*/
void QwtPlot::setCanvas(QWidget *canvas) {
if (canvas == m_data->canvas)
return;
delete m_data->canvas;
m_data->canvas = canvas;
if (canvas) {
canvas->setParent(this);
canvas->installEventFilter(this);
if (isVisible())
canvas->show();
}
}
/*!
\brief Adds handling of layout requests
\param event Event
\return See QFrame::event()
*/
bool QwtPlot::event(QEvent *event) {
bool ok = QFrame::event(event);
switch (event->type()) {
case QEvent::LayoutRequest:
updateLayout();
break;
case QEvent::PolishRequest:
replot();
break;
default:;
}
return ok;
}
/*!
\brief Event filter
The plot handles the following events for the canvas:
- QEvent::Resize
The canvas margins might depend on its size
- QEvent::ContentsRectChange
The layout needs to be recalculated
\param object Object to be filtered
\param event Event
\return See QFrame::eventFilter()
\sa updateCanvasMargins(), updateLayout()
*/
bool QwtPlot::eventFilter(QObject *object, QEvent *event) {
if (object == m_data->canvas) {
if (event->type() == QEvent::Resize) {
updateCanvasMargins();
} else if (event->type() == QEvent::ContentsRectChange) {
updateLayout();
}
}
return QFrame::eventFilter(object, event);
}
//! Replots the plot if autoReplot() is \c true.
void QwtPlot::autoRefresh() {
if (m_data->autoReplot)
replot();
}
/*!
\brief Set or reset the autoReplot option
If the autoReplot option is set, the plot will be
updated implicitly by manipulating member functions.
Since this may be time-consuming, it is recommended
to leave this option switched off and call replot()
explicitly if necessary.
The autoReplot option is set to false by default, which
means that the user has to call replot() in order to make
changes visible.
\param tf \c true or \c false. Defaults to \c true.
\sa replot()
*/
void QwtPlot::setAutoReplot(bool tf) { m_data->autoReplot = tf; }
/*!
\return true if the autoReplot option is set.
\sa setAutoReplot()
*/
bool QwtPlot::autoReplot() const { return m_data->autoReplot; }
/*!
Change the plot's title
\param title New title
*/
void QwtPlot::setTitle(const QString &title) {
if (title != m_data->titleLabel->text().text()) {
m_data->titleLabel->setText(title);
updateLayout();
}
}
/*!
Change the plot's title
\param title New title
*/
void QwtPlot::setTitle(const QwtText &title) {
if (title != m_data->titleLabel->text()) {
m_data->titleLabel->setText(title);
updateLayout();
}
}
//! \return Title of the plot
QwtText QwtPlot::title() const { return m_data->titleLabel->text(); }
//! \return Title label widget.
QwtTextLabel *QwtPlot::titleLabel() { return m_data->titleLabel; }
//! \return Title label widget.
const QwtTextLabel *QwtPlot::titleLabel() const { return m_data->titleLabel; }
/*!
Change the text the footer
\param text New text of the footer
*/
void QwtPlot::setFooter(const QString &text) {
if (text != m_data->footerLabel->text().text()) {
m_data->footerLabel->setText(text);
updateLayout();
}
}
/*!
Change the text the footer
\param text New text of the footer
*/
void QwtPlot::setFooter(const QwtText &text) {
if (text != m_data->footerLabel->text()) {
m_data->footerLabel->setText(text);
updateLayout();
}
}
//! \return Text of the footer
QwtText QwtPlot::footer() const { return m_data->footerLabel->text(); }
//! \return Footer label widget.
QwtTextLabel *QwtPlot::footerLabel() { return m_data->footerLabel; }
//! \return Footer label widget.
const QwtTextLabel *QwtPlot::footerLabel() const { return m_data->footerLabel; }
/*!
\brief Assign a new plot layout
\param layout Layout()
\sa plotLayout()
*/
void QwtPlot::setPlotLayout(QwtPlotLayout *layout) {
if (layout != m_data->layout) {
delete m_data->layout;
m_data->layout = layout;
updateLayout();
}
}
//! \return the plot's layout
QwtPlotLayout *QwtPlot::plotLayout() { return m_data->layout; }
//! \return the plot's layout
const QwtPlotLayout *QwtPlot::plotLayout() const { return m_data->layout; }
/*!
\return the plot's legend
\sa insertLegend()
*/
QwtAbstractLegend *QwtPlot::legend() { return m_data->legend; }
/*!
\return the plot's legend
\sa insertLegend()
*/
const QwtAbstractLegend *QwtPlot::legend() const { return m_data->legend; }
/*!
\return the plot's canvas
*/
QWidget *QwtPlot::canvas() { return m_data->canvas; }
/*!
\return the plot's canvas
*/
const QWidget *QwtPlot::canvas() const { return m_data->canvas; }
/*!
\return Size hint for the plot widget
\sa minimumSizeHint()
*/
QSize QwtPlot::sizeHint() const {
int dw = 0;
int dh = 0;
for (int axisPos = 0; axisPos < QwtAxis::AxisPositions; axisPos++) {
{
const QwtAxisId axisId(axisPos);
if (isAxisVisible(axisId)) {
const int niceDist = 40;
const QwtScaleWidget *scaleWidget = axisWidget(axisId);
const QwtScaleDiv &scaleDiv = scaleWidget->scaleDraw()->scaleDiv();
const int majCnt = scaleDiv.ticks(QwtScaleDiv::MajorTick).count();
const QSize hint = scaleWidget->minimumSizeHint();
if (QwtAxis::isYAxis(axisPos)) {
const int hDiff = (majCnt - 1) * niceDist - hint.height();
dh = qMax(dh, hDiff);
} else {
const int wDiff = (majCnt - 1) * niceDist - hint.width();
dw = qMax(dw, wDiff);
}
}
}
}
return minimumSizeHint() + QSize(dw, dh);
}
/*!
\brief Return a minimum size hint
*/
QSize QwtPlot::minimumSizeHint() const {
QSize hint = m_data->layout->minimumSizeHint(this);
hint += QSize(2 * frameWidth(), 2 * frameWidth());
return hint;
}
/*!
Resize and update internal layout
\param e Resize event
*/
void QwtPlot::resizeEvent(QResizeEvent *e) {
QFrame::resizeEvent(e);
updateLayout();
}
/*!
\brief Redraw the plot
If the autoReplot option is not set (which is the default)
or if any curves are attached to raw data, the plot has to
be refreshed explicitly in order to make changes visible.
\sa updateAxes(), setAutoReplot()
*/
void QwtPlot::replot() {
bool doAutoReplot = autoReplot();
setAutoReplot(false);
updateAxes();
/*
Maybe the layout needs to be updated, because of changed
axes labels. We need to process them here before painting
to avoid that scales and canvas get out of sync.
*/
QApplication::sendPostedEvents(this, QEvent::LayoutRequest);
if (m_data->canvas) {
const bool ok = QMetaObject::invokeMethod(m_data->canvas, "replot",
Qt::DirectConnection);
if (!ok) {
// fallback, when canvas has no a replot method
m_data->canvas->update(m_data->canvas->contentsRect());
}
}
setAutoReplot(doAutoReplot);
}
/*!
\brief Adjust plot content to its current size.
\sa resizeEvent()
*/
void QwtPlot::updateLayout() {
QwtPlotLayout *layout = m_data->layout;
layout->activate(this, contentsRect());
const QRect titleRect = layout->titleRect().toRect();
const QRect footerRect = layout->footerRect().toRect();
const QRect legendRect = layout->legendRect().toRect();
const QRect canvasRect = layout->canvasRect().toRect();
// resize and show the visible widgets
if (!m_data->titleLabel->text().isEmpty()) {
m_data->titleLabel->setGeometry(titleRect);
if (!m_data->titleLabel->isVisibleTo(this))
m_data->titleLabel->show();
} else
m_data->titleLabel->hide();
if (!m_data->footerLabel->text().isEmpty()) {
m_data->footerLabel->setGeometry(footerRect);
if (!m_data->footerLabel->isVisibleTo(this))
m_data->footerLabel->show();
} else {
m_data->footerLabel->hide();
}
for (int axisPos = 0; axisPos < QwtAxis::AxisPositions; axisPos++) {
{
const QwtAxisId axisId(axisPos);
QwtScaleWidget *scaleWidget = axisWidget(axisId);
if (isAxisVisible(axisId)) {
const QRect scaleRect = layout->scaleRect(axisId).toRect();
if (scaleRect != scaleWidget->geometry()) {
scaleWidget->setGeometry(scaleRect);
int startDist, endDist;
scaleWidget->getBorderDistHint(startDist, endDist);
scaleWidget->setBorderDist(startDist, endDist);
}
if (!scaleWidget->isVisibleTo(this))
scaleWidget->show();
} else {
scaleWidget->hide();
}
}
}
if (m_data->legend) {
if (m_data->legend->isEmpty()) {
m_data->legend->hide();
} else {
m_data->legend->setGeometry(legendRect);
m_data->legend->show();
}
}
m_data->canvas->setGeometry(canvasRect);
}
/*!
\brief Calculate the canvas margins
\param maps QwtAxis::AxisCount maps, mapping between plot and paint device
coordinates \param canvasRect Bounding rectangle where to paint \param left
Return parameter for the left margin \param top Return parameter for the top
margin \param right Return parameter for the right margin \param bottom
Return parameter for the bottom margin
Plot items might indicate, that they need some extra space
at the borders of the canvas by the QwtPlotItem::Margins flag.
updateCanvasMargins(), QwtPlotItem::getCanvasMarginHint()
*/
void QwtPlot::getCanvasMarginsHint(const QwtScaleMap maps[],
const QRectF &canvasRect, double &left,
double &top, double &right,
double &bottom) const {
left = top = right = bottom = -1.0;
const QwtPlotItemList &itmList = itemList();
for (QwtPlotItemIterator it = itmList.begin(); it != itmList.end(); ++it) {
const QwtPlotItem *item = *it;
if (item->testItemAttribute(QwtPlotItem::Margins)) {
using namespace QwtAxis;
double m[AxisPositions];
item->getCanvasMarginHint(maps[item->xAxis()], maps[item->yAxis()],
canvasRect, m[YLeft], m[XTop], m[YRight],
m[XBottom]);
left = qMax(left, m[YLeft]);
top = qMax(top, m[XTop]);
right = qMax(right, m[YRight]);
bottom = qMax(bottom, m[XBottom]);
}
}
}
/*!
\brief Update the canvas margins
Plot items might indicate, that they need some extra space
at the borders of the canvas by the QwtPlotItem::Margins flag.
getCanvasMarginsHint(), QwtPlotItem::getCanvasMarginHint()
*/
void QwtPlot::updateCanvasMargins() {
using namespace QwtAxis;
QwtScaleMap maps[AxisPositions];
for (int axisId = 0; axisId < AxisPositions; axisId++)
maps[axisId] = canvasMap(axisId);
double margins[AxisPositions];
getCanvasMarginsHint(maps, canvas()->contentsRect(), margins[YLeft],
margins[XTop], margins[YRight], margins[XBottom]);
bool doUpdate = false;
for (int axisPos = 0; axisPos < AxisPositions; axisPos++) {
if (margins[axisPos] >= 0.0) {
const int m = qCeil(margins[axisPos]);
plotLayout()->setCanvasMargin(m, axisPos);
doUpdate = true;
}
}
if (doUpdate)
updateLayout();
}
/*!
Redraw the canvas.
\param painter Painter used for drawing
\warning drawCanvas calls drawItems what is also used
for printing. Applications that like to add individual
plot items better overload drawItems()
\sa drawItems()
*/
void QwtPlot::drawCanvas(QPainter *painter) {
QwtScaleMap maps[QwtAxis::AxisPositions];
for (int axisPos = 0; axisPos < QwtAxis::AxisPositions; axisPos++)
maps[axisPos] = canvasMap(axisPos);
drawItems(painter, m_data->canvas->contentsRect(), maps);
}
/*!
Redraw the canvas items.
\param painter Painter used for drawing
\param canvasRect Bounding rectangle where to paint
\param maps QwtAxis::AxisCount maps, mapping between plot and paint device
coordinates
\note Usually canvasRect is contentsRect() of the plot canvas.
Due to a bug in Qt this rectangle might be wrong for certain
frame styles ( f.e QFrame::Box ) and it might be necessary to
fix the margins manually using QWidget::setContentsMargins()
*/
void QwtPlot::drawItems(QPainter *painter, const QRectF &canvasRect,
const QwtScaleMap maps[QwtAxis::AxisPositions]) const {
const QwtPlotItemList &itmList = itemList();
for (QwtPlotItemIterator it = itmList.begin(); it != itmList.end(); ++it) {
QwtPlotItem *item = *it;
if (item && item->isVisible()) {
const QwtAxisId xAxis = item->xAxis();
const QwtAxisId yAxis = item->yAxis();
painter->save();
painter->setRenderHint(
QPainter::Antialiasing,
item->testRenderHint(QwtPlotItem::RenderAntialiased));
#if QT_VERSION < 0x050100
painter->setRenderHint(
QPainter::HighQualityAntialiasing,
item->testRenderHint(QwtPlotItem::RenderAntialiased));
#endif
item->draw(painter, maps[xAxis], maps[yAxis], canvasRect);
painter->restore();
}
}
}
/*!
\param axisId Axis
\return Map for the axis on the canvas. With this map pixel coordinates can
translated to plot coordinates and vice versa.
\sa QwtScaleMap, transform(), invTransform()
*/
QwtScaleMap QwtPlot::canvasMap(QwtAxisId axisId) const {
QwtScaleMap map;
if (!m_data->canvas)
return map;
map.setTransformation(axisScaleEngine(axisId)->transformation());
const QwtScaleDiv &sd = axisScaleDiv(axisId);
map.setScaleInterval(sd.lowerBound(), sd.upperBound());
if (isAxisVisible(axisId)) {
const QwtScaleWidget *s = axisWidget(axisId);
if (QwtAxis::isYAxis(axisId)) {
double y = s->y() + s->startBorderDist() - m_data->canvas->y();
double h = s->height() - s->startBorderDist() - s->endBorderDist();
map.setPaintInterval(y + h, y);
} else {
double x = s->x() + s->startBorderDist() - m_data->canvas->x();
double w = s->width() - s->startBorderDist() - s->endBorderDist();
map.setPaintInterval(x, x + w);
}
} else {
using namespace QwtAxis;
const QRect &canvasRect = m_data->canvas->contentsRect();
if (isYAxis(axisId)) {
int top = 0;
if (!plotLayout()->alignCanvasToScale(XTop))
top = plotLayout()->canvasMargin(XTop);
int bottom = 0;
if (!plotLayout()->alignCanvasToScale(XBottom))
bottom = plotLayout()->canvasMargin(XBottom);
map.setPaintInterval(canvasRect.bottom() - bottom,
canvasRect.top() + top);
} else {
int left = 0;
if (!plotLayout()->alignCanvasToScale(YLeft))
left = plotLayout()->canvasMargin(YLeft);
int right = 0;
if (!plotLayout()->alignCanvasToScale(YRight))
right = plotLayout()->canvasMargin(YRight);
map.setPaintInterval(canvasRect.left() + left,
canvasRect.right() - right);
}
}
return map;
}
/*!
\brief Change the background of the plotting area
Sets brush to QPalette::Window of all color groups of
the palette of the canvas. Using canvas()->setPalette()
is a more powerful way to set these colors.
\param brush New background brush
\sa canvasBackground()
*/
void QwtPlot::setCanvasBackground(const QBrush &brush) {
QPalette pal = m_data->canvas->palette();
pal.setBrush(QPalette::Window, brush);
canvas()->setPalette(pal);
}
/*!
Nothing else than: canvas()->palette().brush(
QPalette::Normal, QPalette::Window);
\return Background brush of the plotting area.
\sa setCanvasBackground()
*/
QBrush QwtPlot::canvasBackground() const {
return canvas()->palette().brush(QPalette::Normal, QPalette::Window);
}
/*!
\brief Insert a legend
If the position legend is \c QwtPlot::LeftLegend or \c QwtPlot::RightLegend
the legend will be organized in one column from top to down.
Otherwise the legend items will be placed in a table
with a best fit number of columns from left to right.
insertLegend() will set the plot widget as parent for the legend.
The legend will be deleted in the destructor of the plot or when
another legend is inserted.
Legends, that are not inserted into the layout of the plot widget
need to connect to the legendDataChanged() signal. Calling updateLegend()
initiates this signal for an initial update. When the application code
wants to implement its own layout this also needs to be done for
rendering plots to a document ( see QwtPlotRenderer ).
\param legend Legend
\param pos The legend's position. For top/left position the number
of columns will be limited to 1, otherwise it will be set to
unlimited.
\param ratio Ratio between legend and the bounding rectangle
of title, canvas and axes. The legend will be shrunk
if it would need more space than the given ratio.
The ratio is limited to ]0.0 .. 1.0]. In case of <= 0.0
it will be reset to the default ratio.
The default vertical/horizontal ratio is 0.33/0.5.
\sa legend(), QwtPlotLayout::legendPosition(),
QwtPlotLayout::setLegendPosition()
*/
void QwtPlot::insertLegend(QwtAbstractLegend *legend,
QwtPlot::LegendPosition pos, double ratio) {
m_data->layout->setLegendPosition(pos, ratio);
if (legend != m_data->legend) {
if (m_data->legend && m_data->legend->parent() == this)
delete m_data->legend;
m_data->legend = legend;
if (m_data->legend) {
connect(this, SIGNAL(legendDataChanged(QVariant, QList<QwtLegendData>)),
m_data->legend,
SLOT(updateLegend(QVariant, QList<QwtLegendData>)));
if (m_data->legend->parent() != this)
m_data->legend->setParent(this);
qwtEnableLegendItems(this, false);
updateLegend();
qwtEnableLegendItems(this, true);
QwtLegend *lgd = qobject_cast<QwtLegend *>(legend);
if (lgd) {
switch (m_data->layout->legendPosition()) {
case LeftLegend:
case RightLegend: {
if (lgd->maxColumns() == 0)
lgd->setMaxColumns(1); // 1 column: align vertical
break;
}
case TopLegend:
case BottomLegend: {
lgd->setMaxColumns(0); // unlimited
break;
}
}
}
QWidget *previousInChain = nullptr;
switch (m_data->layout->legendPosition()) {
case LeftLegend: {
const QwtAxisId axisId(QwtAxis::XTop);
previousInChain = axisWidget(axisId);
break;
}
case TopLegend: {
previousInChain = this;
break;
}
case RightLegend: {
const QwtAxisId axisId(QwtAxis::YRight);
previousInChain = axisWidget(axisId);
break;
}
case BottomLegend: {
previousInChain = footerLabel();
break;
}
}
if (previousInChain)
qwtSetTabOrder(previousInChain, legend, true);
}
}
updateLayout();
}
/*!
Emit legendDataChanged() for all plot item
\sa QwtPlotItem::legendData(), legendDataChanged()
*/
void QwtPlot::updateLegend() {
const QwtPlotItemList &itmList = itemList();
for (QwtPlotItemIterator it = itmList.begin(); it != itmList.end(); ++it) {
updateLegend(*it);
}
}
/*!
Emit legendDataChanged() for a plot item
\param plotItem Plot item
\sa QwtPlotItem::legendData(), legendDataChanged()
*/
void QwtPlot::updateLegend(const QwtPlotItem *plotItem) {
if (plotItem == nullptr)
return;
QList<QwtLegendData> legendData;
if (plotItem->testItemAttribute(QwtPlotItem::Legend))
legendData = plotItem->legendData();
const QVariant itemInfo = itemToInfo(const_cast<QwtPlotItem *>(plotItem));
Q_EMIT legendDataChanged(itemInfo, legendData);
}
/*!
\brief Update all plot items interested in legend attributes
Call QwtPlotItem::updateLegend(), when the QwtPlotItem::LegendInterest
flag is set.
\param itemInfo Info about the plot item
\param legendData Entries to be displayed for the plot item ( usually 1 )
\sa QwtPlotItem::LegendInterest,
QwtPlotLegendItem, QwtPlotItem::updateLegend()
*/
void QwtPlot::updateLegendItems(const QVariant &itemInfo,
const QList<QwtLegendData> &legendData) {
QwtPlotItem *plotItem = infoToItem(itemInfo);
if (plotItem) {
const QwtPlotItemList &itmList = itemList();
for (QwtPlotItemIterator it = itmList.begin(); it != itmList.end(); ++it) {
QwtPlotItem *item = *it;
if (item->testItemInterest(QwtPlotItem::LegendInterest))
item->updateLegend(plotItem, legendData);
}
}
}
/*!
\brief Attach/Detach a plot item
\param plotItem Plot item
\param on When true attach the item, otherwise detach it
*/
void QwtPlot::attachItem(QwtPlotItem *plotItem, bool on) {
if (plotItem->testItemInterest(QwtPlotItem::LegendInterest)) {
// plotItem is some sort of legend
const QwtPlotItemList &itmList = itemList();
for (QwtPlotItemIterator it = itmList.begin(); it != itmList.end(); ++it) {
QwtPlotItem *item = *it;
QList<QwtLegendData> legendData;
if (on && item->testItemAttribute(QwtPlotItem::Legend)) {
legendData = item->legendData();
plotItem->updateLegend(item, legendData);
}
}
}
if (on)
insertItem(plotItem);
else
removeItem(plotItem);
Q_EMIT itemAttached(plotItem, on);
if (plotItem->testItemAttribute(QwtPlotItem::Legend)) {
// the item wants to be represented on the legend
if (on) {
updateLegend(plotItem);
} else {
const QVariant itemInfo = itemToInfo(plotItem);
Q_EMIT legendDataChanged(itemInfo, QList<QwtLegendData>());
}
}
autoRefresh();
}
/*!
\brief Build an information, that can be used to identify
a plot item on the legend.
The default implementation simply wraps the plot item
into a QVariant object. When overloading itemToInfo()
usually infoToItem() needs to reimplemeted too.
\param plotItem Plot item
\return Plot item embedded in a QVariant
\sa infoToItem()
*/
QVariant QwtPlot::itemToInfo(QwtPlotItem *plotItem) const {
return QVariant::fromValue(plotItem);
}
/*!
\brief Identify the plot item according to an item info object,
that has bee generated from itemToInfo().
The default implementation simply tries to unwrap a QwtPlotItem
pointer:
\code
if ( itemInfo.canConvert<QwtPlotItem *>() )
return qvariant_cast<QwtPlotItem *>( itemInfo );
\endcode
\param itemInfo Plot item
\return A plot item, when successful, otherwise a NULL pointer.
\sa itemToInfo()
*/
QwtPlotItem *QwtPlot::infoToItem(const QVariant &itemInfo) const {
if (itemInfo.canConvert<QwtPlotItem *>())
return qvariant_cast<QwtPlotItem *>(itemInfo);
return nullptr;
}
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 によって変換されたページ (->オリジナル) /