更新代码

This commit is contained in:
feiyangqingyun
2022-04-30 18:17:25 +08:00
parent 293a8d9c40
commit 7bed44d9c0
10 changed files with 62 additions and 58 deletions

View File

@@ -13,6 +13,9 @@ DeviceButton::DeviceButton(QWidget *parent) : QWidget(parent)
buttonStyle = ButtonStyle_Police; buttonStyle = ButtonStyle_Police;
buttonColor = ButtonColor_Green; buttonColor = ButtonColor_Green;
isPressed = false;
lastPoint = QPoint();
type = "police"; type = "police";
imgName = QString(":/image/devicebutton/devicebutton_green_%1.png").arg(type); imgName = QString(":/image/devicebutton/devicebutton_green_%1.png").arg(type);
isDark = false; isDark = false;
@@ -79,29 +82,26 @@ void DeviceButton::paintEvent(QPaintEvent *)
bool DeviceButton::eventFilter(QObject *watched, QEvent *event) bool DeviceButton::eventFilter(QObject *watched, QEvent *event)
{ {
if (canMove) { //识别鼠标 按下+移动+松开+双击 等事件
static QPoint lastPoint; QMouseEvent *mouseEvent = static_cast<QMouseEvent *>(event);
static bool isPressed = false;
if (event->type() == QEvent::MouseButtonPress) { if (event->type() == QEvent::MouseButtonPress) {
QMouseEvent *e = static_cast<QMouseEvent *>(event); //限定鼠标左键
if (this->rect().contains(e->pos()) && (e->button() == Qt::LeftButton)) { if (mouseEvent->button() == Qt::LeftButton) {
lastPoint = e->pos(); lastPoint = mouseEvent->pos();
isPressed = true; isPressed = true;
emit clicked();
return true;
} }
} else if (event->type() == QEvent::MouseMove && isPressed) { } else if (event->type() == QEvent::MouseMove) {
QMouseEvent *e = static_cast<QMouseEvent *>(event); //允许拖动并且鼠标按下准备拖动
int dx = e->pos().x() - lastPoint.x(); if (canMove && isPressed) {
int dy = e->pos().y() - lastPoint.y(); int dx = mouseEvent->pos().x() - lastPoint.x();
int dy = mouseEvent->pos().y() - lastPoint.y();
this->move(this->x() + dx, this->y() + dy); this->move(this->x() + dx, this->y() + dy);
return true; return true;
} else if (event->type() == QEvent::MouseButtonRelease && isPressed) { }
} else if (event->type() == QEvent::MouseButtonRelease) {
isPressed = false; isPressed = false;
}
}
if (event->type() == QEvent::MouseButtonPress) {
emit clicked();
} else if (event->type() == QEvent::MouseButtonDblClick) { } else if (event->type() == QEvent::MouseButtonDblClick) {
emit doubleClicked(); emit doubleClicked();
} }

View File

@@ -65,6 +65,9 @@ private:
ButtonStyle buttonStyle; //按钮样式 ButtonStyle buttonStyle; //按钮样式
ButtonColor buttonColor; //按钮颜色 ButtonColor buttonColor; //按钮颜色
bool isPressed; //鼠标是否按下
QPoint lastPoint; //鼠标按下最后坐标
QString type; //图片末尾类型 QString type; //图片末尾类型
QString imgName; //背景图片名称 QString imgName; //背景图片名称
bool isDark; //是否加深报警 bool isDark; //是否加深报警
@@ -94,6 +97,7 @@ public Q_SLOTS:
void setButtonColor(const ButtonColor &buttonColor); void setButtonColor(const ButtonColor &buttonColor);
Q_SIGNALS: Q_SIGNALS:
//鼠标单击双击事件
void clicked(); void clicked();
void doubleClicked(); void doubleClicked();
}; };

View File

@@ -1,6 +1,6 @@
按照国际惯例先吹吹牛QCustomPlot这个开源图表组件作者绝对是全宇宙Qt领域的天花板设计的极其巧妙和精美各种情况都考虑到了将每个功能细分到不同的类每个类负责管理自己的绘制和各种属性参数等虽然代码量不多但是又极具拓展性当时阅读完代码的时候我直接跪了8个小时膝盖现在还是红的。作者的实力至少是八星斗圣级别只要一个巴掌就能把斗宗干趴下。 按照国际惯例先吹吹牛QCustomPlot这个开源图表组件作者绝对是全宇宙Qt领域的天花板设计的极其巧妙和精美各种情况都考虑到了将每个功能细分到不同的类每个类负责管理自己的绘制和各种属性参数等虽然代码量不多但是又极具拓展性当时阅读完代码的时候我直接跪了8个小时膝盖现在还是红的。作者的实力至少是八星斗圣级别只要一个巴掌就能把斗宗干趴下。
**网页版本:[https://feiyangqingyun.github.io/qwidgetdemo/qcustomplotdemo/](https://feiyangqingyun.github.io/qwidgetdemo/qcustomplotdemo/)** **网页版本:[https://feiyangqingyun.gitee.io/qwidgetdemo/qcustomplotdemo/](https://feiyangqingyun.gitee.io/qwidgetdemo/qcustomplotdemo/)**
## 一、功能特点 ## 一、功能特点
1. 同时支持多个版本比如1.3、2.0、2.1。 1. 同时支持多个版本比如1.3、2.0、2.1。
@@ -14,76 +14,76 @@
## 二、功能模块 ## 二、功能模块
### 2.1 平方二次元 ### 2.1 平方二次元
![avatar](https://github.com/feiyangqingyun/QWidgetDemo/raw/master/third/qcustomplotdemo/snap/1.jpg) ![avatar](https://gitee.com/feiyangqingyun/QWidgetDemo/raw/master/third/qcustomplotdemo/snap/1.jpg)
### 2.2 简单曲线图 ### 2.2 简单曲线图
![avatar](https://github.com/feiyangqingyun/QWidgetDemo/raw/master/third/qcustomplotdemo/snap/2.jpg) ![avatar](https://gitee.com/feiyangqingyun/QWidgetDemo/raw/master/third/qcustomplotdemo/snap/2.jpg)
### 2.3 正弦散点图 ### 2.3 正弦散点图
![avatar](https://github.com/feiyangqingyun/QWidgetDemo/raw/master/third/qcustomplotdemo/snap/3.jpg) ![avatar](https://gitee.com/feiyangqingyun/QWidgetDemo/raw/master/third/qcustomplotdemo/snap/3.jpg)
### 2.4 数据点样式 ### 2.4 数据点样式
![avatar](https://github.com/feiyangqingyun/QWidgetDemo/raw/master/third/qcustomplotdemo/snap/4.jpg) ![avatar](https://gitee.com/feiyangqingyun/QWidgetDemo/raw/master/third/qcustomplotdemo/snap/4.jpg)
### 2.5 数据点图片 ### 2.5 数据点图片
![avatar](https://github.com/feiyangqingyun/QWidgetDemo/raw/master/third/qcustomplotdemo/snap/5.jpg) ![avatar](https://gitee.com/feiyangqingyun/QWidgetDemo/raw/master/third/qcustomplotdemo/snap/5.jpg)
### 2.6 曲线条样式 ### 2.6 曲线条样式
![avatar](https://github.com/feiyangqingyun/QWidgetDemo/raw/master/third/qcustomplotdemo/snap/6.jpg) ![avatar](https://gitee.com/feiyangqingyun/QWidgetDemo/raw/master/third/qcustomplotdemo/snap/6.jpg)
### 2.7 日期数据图 ### 2.7 日期数据图
![avatar](https://github.com/feiyangqingyun/QWidgetDemo/raw/master/third/qcustomplotdemo/snap/7.jpg) ![avatar](https://gitee.com/feiyangqingyun/QWidgetDemo/raw/master/third/qcustomplotdemo/snap/7.jpg)
### 2.8 纹理画刷图 ### 2.8 纹理画刷图
![avatar](https://github.com/feiyangqingyun/QWidgetDemo/raw/master/third/qcustomplotdemo/snap/8.jpg) ![avatar](https://gitee.com/feiyangqingyun/QWidgetDemo/raw/master/third/qcustomplotdemo/snap/8.jpg)
### 2.9 双坐标曲线 ### 2.9 双坐标曲线
![avatar](https://github.com/feiyangqingyun/QWidgetDemo/raw/master/third/qcustomplotdemo/snap/9.jpg) ![avatar](https://gitee.com/feiyangqingyun/QWidgetDemo/raw/master/third/qcustomplotdemo/snap/9.jpg)
### 2.10 对数曲线图 ### 2.10 对数曲线图
![avatar](https://github.com/feiyangqingyun/QWidgetDemo/raw/master/third/qcustomplotdemo/snap/10.jpg) ![avatar](https://gitee.com/feiyangqingyun/QWidgetDemo/raw/master/third/qcustomplotdemo/snap/10.jpg)
### 2.11 动态正弦图 ### 2.11 动态正弦图
![avatar](https://github.com/feiyangqingyun/QWidgetDemo/raw/master/third/qcustomplotdemo/snap/11.jpg) ![avatar](https://gitee.com/feiyangqingyun/QWidgetDemo/raw/master/third/qcustomplotdemo/snap/11.jpg)
### 2.12 环形曲线图 ### 2.12 环形曲线图
![avatar](https://github.com/feiyangqingyun/QWidgetDemo/raw/master/third/qcustomplotdemo/snap/12.jpg) ![avatar](https://gitee.com/feiyangqingyun/QWidgetDemo/raw/master/third/qcustomplotdemo/snap/12.jpg)
### 2.13 垂直柱状图 ### 2.13 垂直柱状图
![avatar](https://github.com/feiyangqingyun/QWidgetDemo/raw/master/third/qcustomplotdemo/snap/13.jpg) ![avatar](https://gitee.com/feiyangqingyun/QWidgetDemo/raw/master/third/qcustomplotdemo/snap/13.jpg)
### 2.14 箱形盒须图 ### 2.14 箱形盒须图
![avatar](https://github.com/feiyangqingyun/QWidgetDemo/raw/master/third/qcustomplotdemo/snap/14.jpg) ![avatar](https://gitee.com/feiyangqingyun/QWidgetDemo/raw/master/third/qcustomplotdemo/snap/14.jpg)
### 2.15 静态指示线 ### 2.15 静态指示线
![avatar](https://github.com/feiyangqingyun/QWidgetDemo/raw/master/third/qcustomplotdemo/snap/15.jpg) ![avatar](https://gitee.com/feiyangqingyun/QWidgetDemo/raw/master/third/qcustomplotdemo/snap/15.jpg)
### 2.16 动态指示线 ### 2.16 动态指示线
![avatar](https://github.com/feiyangqingyun/QWidgetDemo/raw/master/third/qcustomplotdemo/snap/16.jpg) ![avatar](https://gitee.com/feiyangqingyun/QWidgetDemo/raw/master/third/qcustomplotdemo/snap/16.jpg)
### 2.17 曲线样式图 ### 2.17 曲线样式图
![avatar](https://github.com/feiyangqingyun/QWidgetDemo/raw/master/third/qcustomplotdemo/snap/17.jpg) ![avatar](https://gitee.com/feiyangqingyun/QWidgetDemo/raw/master/third/qcustomplotdemo/snap/17.jpg)
### 2.18 高级坐标轴 ### 2.18 高级坐标轴
![avatar](https://github.com/feiyangqingyun/QWidgetDemo/raw/master/third/qcustomplotdemo/snap/18.jpg) ![avatar](https://gitee.com/feiyangqingyun/QWidgetDemo/raw/master/third/qcustomplotdemo/snap/18.jpg)
### 2.19 颜色热力图 ### 2.19 颜色热力图
![avatar](https://github.com/feiyangqingyun/QWidgetDemo/raw/master/third/qcustomplotdemo/snap/19.jpg) ![avatar](https://gitee.com/feiyangqingyun/QWidgetDemo/raw/master/third/qcustomplotdemo/snap/19.jpg)
### 2.20 金融曲线图 ### 2.20 金融曲线图
![avatar](https://github.com/feiyangqingyun/QWidgetDemo/raw/master/third/qcustomplotdemo/snap/20.jpg) ![avatar](https://gitee.com/feiyangqingyun/QWidgetDemo/raw/master/third/qcustomplotdemo/snap/20.jpg)
### 2.21 南丁格尔图 ### 2.21 南丁格尔图
![avatar](https://github.com/feiyangqingyun/QWidgetDemo/raw/master/third/qcustomplotdemo/snap/21.jpg) ![avatar](https://gitee.com/feiyangqingyun/QWidgetDemo/raw/master/third/qcustomplotdemo/snap/21.jpg)
### 2.22 坐标轴指示 ### 2.22 坐标轴指示
![avatar](https://github.com/feiyangqingyun/QWidgetDemo/raw/master/third/qcustomplotdemo/snap/22.jpg) ![avatar](https://gitee.com/feiyangqingyun/QWidgetDemo/raw/master/third/qcustomplotdemo/snap/22.jpg)
### 2.23 相互作用图 ### 2.23 相互作用图
![avatar](https://github.com/feiyangqingyun/QWidgetDemo/raw/master/third/qcustomplotdemo/snap/23.jpg) ![avatar](https://gitee.com/feiyangqingyun/QWidgetDemo/raw/master/third/qcustomplotdemo/snap/23.jpg)
### 2.24 滚动条曲线 ### 2.24 滚动条曲线
![avatar](https://github.com/feiyangqingyun/QWidgetDemo/raw/master/third/qcustomplotdemo/snap/24.jpg) ![avatar](https://gitee.com/feiyangqingyun/QWidgetDemo/raw/master/third/qcustomplotdemo/snap/24.jpg)
### 2.25 多坐标轴图 ### 2.25 多坐标轴图
![avatar](https://github.com/feiyangqingyun/QWidgetDemo/raw/master/third/qcustomplotdemo/snap/25.jpg) ![avatar](https://gitee.com/feiyangqingyun/QWidgetDemo/raw/master/third/qcustomplotdemo/snap/25.jpg)

View File

@@ -8,13 +8,13 @@ TcpClient1::TcpClient1(QObject *parent) : QTcpSocket(parent)
port = 6907; port = 6907;
deviceID = "SSJC00000001"; deviceID = "SSJC00000001";
connect(this, SIGNAL(disconnected()), this, SLOT(deleteLater()));
connect(this, SIGNAL(readyRead()), this, SLOT(readData()));
#if (QT_VERSION >= QT_VERSION_CHECK(6,0,0)) #if (QT_VERSION >= QT_VERSION_CHECK(6,0,0))
connect(this, SIGNAL(errorOccurred(QAbstractSocket::SocketError)), this, SLOT(deleteLater())); connect(this, SIGNAL(errorOccurred(QAbstractSocket::SocketError)), this, SLOT(deleteLater()));
#else #else
connect(this, SIGNAL(error(QAbstractSocket::SocketError)), this, SLOT(deleteLater())); connect(this, SIGNAL(error(QAbstractSocket::SocketError)), this, SLOT(deleteLater()));
#endif #endif
connect(this, SIGNAL(disconnected()), this, SLOT(deleteLater()));
connect(this, SIGNAL(readyRead()), this, SLOT(readData()));
} }
void TcpClient1::setIP(const QString &ip) void TcpClient1::setIP(const QString &ip)

View File

@@ -8,13 +8,13 @@ TcpClient2::TcpClient2(QObject *parent) : QTcpSocket(parent)
port = 6908; port = 6908;
deviceID = "SSJC00000001"; deviceID = "SSJC00000001";
connect(this, SIGNAL(disconnected()), this, SLOT(deleteLater()));
connect(this, SIGNAL(readyRead()), this, SLOT(readData()));
#if (QT_VERSION >= QT_VERSION_CHECK(6,0,0)) #if (QT_VERSION >= QT_VERSION_CHECK(6,0,0))
connect(this, SIGNAL(errorOccurred(QAbstractSocket::SocketError)), this, SLOT(deleteLater())); connect(this, SIGNAL(errorOccurred(QAbstractSocket::SocketError)), this, SLOT(deleteLater()));
#else #else
connect(this, SIGNAL(error(QAbstractSocket::SocketError)), this, SLOT(deleteLater())); connect(this, SIGNAL(error(QAbstractSocket::SocketError)), this, SLOT(deleteLater()));
#endif #endif
connect(this, SIGNAL(disconnected()), this, SLOT(deleteLater()));
connect(this, SIGNAL(readyRead()), this, SLOT(readData()));
} }
void TcpClient2::setIP(const QString &ip) void TcpClient2::setIP(const QString &ip)

View File

@@ -10,12 +10,12 @@ TcpClient::TcpClient(QTcpSocket *socket, QObject *parent) : QObject(parent)
port = socket->peerPort(); port = socket->peerPort();
connect(socket, SIGNAL(disconnected()), this, SLOT(slot_disconnected())); connect(socket, SIGNAL(disconnected()), this, SLOT(slot_disconnected()));
connect(socket, SIGNAL(readyRead()), this, SLOT(slot_readData()));
#if (QT_VERSION >= QT_VERSION_CHECK(6,0,0)) #if (QT_VERSION >= QT_VERSION_CHECK(6,0,0))
connect(socket, SIGNAL(errorOccurred(QAbstractSocket::SocketError)), this, SLOT(slot_error())); connect(socket, SIGNAL(errorOccurred(QAbstractSocket::SocketError)), this, SLOT(slot_error()));
#else #else
connect(socket, SIGNAL(error(QAbstractSocket::SocketError)), this, SLOT(slot_error())); connect(socket, SIGNAL(error(QAbstractSocket::SocketError)), this, SLOT(slot_error()));
#endif #endif
connect(socket, SIGNAL(readyRead()), this, SLOT(slot_readData()));
} }
QString TcpClient::getIP() const QString TcpClient::getIP() const

View File

@@ -40,12 +40,12 @@ void frmTcpClient::initForm()
socket = new QTcpSocket(this); socket = new QTcpSocket(this);
connect(socket, SIGNAL(connected()), this, SLOT(connected())); connect(socket, SIGNAL(connected()), this, SLOT(connected()));
connect(socket, SIGNAL(disconnected()), this, SLOT(disconnected())); connect(socket, SIGNAL(disconnected()), this, SLOT(disconnected()));
connect(socket, SIGNAL(readyRead()), this, SLOT(readData()));
#if (QT_VERSION >= QT_VERSION_CHECK(6,0,0)) #if (QT_VERSION >= QT_VERSION_CHECK(6,0,0))
connect(socket, SIGNAL(errorOccurred(QAbstractSocket::SocketError)), this, SLOT(error())); connect(socket, SIGNAL(errorOccurred(QAbstractSocket::SocketError)), this, SLOT(error()));
#else #else
connect(socket, SIGNAL(error(QAbstractSocket::SocketError)), this, SLOT(error())); connect(socket, SIGNAL(error(QAbstractSocket::SocketError)), this, SLOT(error()));
#endif #endif
connect(socket, SIGNAL(readyRead()), this, SLOT(readData()));
//定时器发送数据 //定时器发送数据
timer = new QTimer(this); timer = new QTimer(this);

View File

@@ -36,12 +36,12 @@ void frmUdpClient::initForm()
//实例化对象并绑定信号槽 //实例化对象并绑定信号槽
socket = new QUdpSocket(this); socket = new QUdpSocket(this);
connect(socket, SIGNAL(readyRead()), this, SLOT(readData()));
#if (QT_VERSION >= QT_VERSION_CHECK(6,0,0)) #if (QT_VERSION >= QT_VERSION_CHECK(6,0,0))
connect(socket, SIGNAL(errorOccurred(QAbstractSocket::SocketError)), this, SLOT(error())); connect(socket, SIGNAL(errorOccurred(QAbstractSocket::SocketError)), this, SLOT(error()));
#else #else
connect(socket, SIGNAL(error(QAbstractSocket::SocketError)), this, SLOT(error())); connect(socket, SIGNAL(error(QAbstractSocket::SocketError)), this, SLOT(error()));
#endif #endif
connect(socket, SIGNAL(readyRead()), this, SLOT(readData()));
//定时器发送数据 //定时器发送数据
timer = new QTimer(this); timer = new QTimer(this);

View File

@@ -37,12 +37,12 @@ void frmUdpServer::initForm()
//实例化对象并绑定信号槽 //实例化对象并绑定信号槽
socket = new QUdpSocket(this); socket = new QUdpSocket(this);
connect(socket, SIGNAL(readyRead()), this, SLOT(readData()));
#if (QT_VERSION >= QT_VERSION_CHECK(6,0,0)) #if (QT_VERSION >= QT_VERSION_CHECK(6,0,0))
connect(socket, SIGNAL(errorOccurred(QAbstractSocket::SocketError)), this, SLOT(error())); connect(socket, SIGNAL(errorOccurred(QAbstractSocket::SocketError)), this, SLOT(error()));
#else #else
connect(socket, SIGNAL(error(QAbstractSocket::SocketError)), this, SLOT(error())); connect(socket, SIGNAL(error(QAbstractSocket::SocketError)), this, SLOT(error()));
#endif #endif
connect(socket, SIGNAL(readyRead()), this, SLOT(readData()));
//定时器发送数据 //定时器发送数据
timer = new QTimer(this); timer = new QTimer(this);