124 lines
3.0 KiB
C++
124 lines
3.0 KiB
C++
#include "mycustomplot.h"
|
|
#include "CallManage.h"
|
|
|
|
MyCustomPlot::MyCustomPlot(QWidget *parent, int indexID) :
|
|
QCustomPlot(parent)
|
|
{
|
|
m_indexID =indexID;
|
|
m_indexLine = 0;
|
|
|
|
setObjectName("MyCustomPlot");
|
|
//this->setOpenGl(true);
|
|
|
|
// // 隐藏 x 轴背景
|
|
// xAxis->setBasePen(Qt::NoPen);
|
|
// xAxis->setTickPen(Qt::NoPen);
|
|
// xAxis->setSubTickPen(Qt::NoPen);
|
|
// // 隐藏 y 轴背景
|
|
// yAxis->setBasePen(Qt::NoPen);
|
|
// yAxis->setTickPen(Qt::NoPen);
|
|
// yAxis->setSubTickPen(Qt::NoPen);
|
|
|
|
|
|
xAxis->setTickLabels(false);
|
|
yAxis->setTickLabels(false);
|
|
//
|
|
xAxis2->setTickLabels(false);
|
|
yAxis2->setTickLabels(false);
|
|
|
|
//legend->setVisible(false);
|
|
|
|
// make bottom and left axes transfer their ranges to top and right axes:
|
|
connect(xAxis, SIGNAL(rangeChanged(QCPRange)), xAxis2, SLOT(setRange(QCPRange)));
|
|
connect(yAxis, SIGNAL(rangeChanged(QCPRange)), yAxis2, SLOT(setRange(QCPRange)));
|
|
}
|
|
|
|
void MyCustomPlot::init(QString strName, QVector<double> xx, QVector<double> yy0)
|
|
{
|
|
|
|
}
|
|
|
|
void MyCustomPlot::mousePressEvent(QMouseEvent *event)
|
|
{
|
|
//qDebug() << "mousePress";
|
|
QCustomPlot::mousePressEvent(event);
|
|
}
|
|
|
|
//槽函数,选中曲线
|
|
void MyCustomPlot::s_LineClicked(int index)
|
|
{
|
|
qDebug() << "s_LineClicked";
|
|
|
|
//全部取消选中
|
|
deselectAll();
|
|
|
|
//重新选中
|
|
QCPGraph *graph = this->graph(index);
|
|
if (graph)
|
|
{
|
|
//qDebug() << "s_LineClicked graph";
|
|
graph->setSelection(QCPDataSelection(graph->data()->dataRange()));
|
|
|
|
QCPPlottableLegendItem *item = legend->itemWithPlottable(graph);
|
|
if (item)
|
|
{
|
|
//qDebug() << "s_LineClicked item";
|
|
//仅显示当前被选中的曲线
|
|
item->setSelected(true);
|
|
replot();
|
|
}
|
|
}
|
|
}
|
|
|
|
void MyCustomPlot::contextMenuEvent(QContextMenuEvent *event)
|
|
{
|
|
QMenu menu(this);
|
|
QAction *resetAction = menu.addAction("复位");
|
|
connect(resetAction, &QAction::triggered, this, &MyCustomPlot::onResetZoom);
|
|
|
|
if (selectedGraphs().size() > 0)//选中曲线
|
|
{
|
|
menu.addAction("删除选中曲线", this, SLOT(removeSelectedGraph()));
|
|
}
|
|
|
|
menu.exec(event->globalPos());
|
|
}
|
|
|
|
void MyCustomPlot::onResetZoom()
|
|
{
|
|
//rescaleAxes();
|
|
//x,y互换
|
|
yAxis->setRange(m_iX1, m_iX2);
|
|
xAxis->setRange(m_iY1, m_iY2);
|
|
//
|
|
replot();
|
|
}
|
|
|
|
void MyCustomPlot::removeSelectedGraph()
|
|
{
|
|
if (selectedGraphs().size() > 0)
|
|
{
|
|
QString strLineName = selectedGraphs().first()->name();
|
|
qDebug() << "removeSelectedGraph name=" << strLineName;
|
|
|
|
removeGraph(selectedGraphs().first());
|
|
replot();
|
|
|
|
emit CallManage::getInstance()->sig_DelCurve(m_indexID, strLineName);
|
|
}
|
|
}
|
|
|
|
void MyCustomPlot::removeSelectedGraphByTitle()
|
|
{
|
|
if (selectedGraphs().size() > 0)
|
|
{
|
|
QString strLineName = selectedGraphs().first()->name();
|
|
qDebug() << "removeSelectedGraph name=" << strLineName;
|
|
|
|
removeGraph(selectedGraphs().first());
|
|
replot();
|
|
|
|
emit CallManage::getInstance()->sig_DelCurve(m_indexID, strLineName);
|
|
}
|
|
}
|