更新代码
This commit is contained in:
@@ -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) {
|
if (mouseEvent->button() == Qt::LeftButton) {
|
||||||
QMouseEvent *e = static_cast<QMouseEvent *>(event);
|
lastPoint = mouseEvent->pos();
|
||||||
if (this->rect().contains(e->pos()) && (e->button() == Qt::LeftButton)) {
|
isPressed = true;
|
||||||
lastPoint = e->pos();
|
emit clicked();
|
||||||
isPressed = true;
|
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) {
|
|
||||||
isPressed = false;
|
|
||||||
}
|
}
|
||||||
}
|
} else if (event->type() == QEvent::MouseButtonRelease) {
|
||||||
|
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();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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();
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -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 平方二次元
|
||||||

|

|
||||||
|
|
||||||
### 2.2 简单曲线图
|
### 2.2 简单曲线图
|
||||||

|

|
||||||
|
|
||||||
### 2.3 正弦散点图
|
### 2.3 正弦散点图
|
||||||

|

|
||||||
|
|
||||||
### 2.4 数据点样式
|
### 2.4 数据点样式
|
||||||

|

|
||||||
|
|
||||||
### 2.5 数据点图片
|
### 2.5 数据点图片
|
||||||

|

|
||||||
|
|
||||||
### 2.6 曲线条样式
|
### 2.6 曲线条样式
|
||||||

|

|
||||||
|
|
||||||
### 2.7 日期数据图
|
### 2.7 日期数据图
|
||||||

|

|
||||||
|
|
||||||
### 2.8 纹理画刷图
|
### 2.8 纹理画刷图
|
||||||

|

|
||||||
|
|
||||||
### 2.9 双坐标曲线
|
### 2.9 双坐标曲线
|
||||||

|

|
||||||
|
|
||||||
### 2.10 对数曲线图
|
### 2.10 对数曲线图
|
||||||

|

|
||||||
|
|
||||||
### 2.11 动态正弦图
|
### 2.11 动态正弦图
|
||||||

|

|
||||||
|
|
||||||
### 2.12 环形曲线图
|
### 2.12 环形曲线图
|
||||||

|

|
||||||
|
|
||||||
### 2.13 垂直柱状图
|
### 2.13 垂直柱状图
|
||||||

|

|
||||||
|
|
||||||
### 2.14 箱形盒须图
|
### 2.14 箱形盒须图
|
||||||

|

|
||||||
|
|
||||||
### 2.15 静态指示线
|
### 2.15 静态指示线
|
||||||

|

|
||||||
|
|
||||||
### 2.16 动态指示线
|
### 2.16 动态指示线
|
||||||

|

|
||||||
|
|
||||||
### 2.17 曲线样式图
|
### 2.17 曲线样式图
|
||||||

|

|
||||||
|
|
||||||
### 2.18 高级坐标轴
|
### 2.18 高级坐标轴
|
||||||

|

|
||||||
|
|
||||||
### 2.19 颜色热力图
|
### 2.19 颜色热力图
|
||||||

|

|
||||||
|
|
||||||
### 2.20 金融曲线图
|
### 2.20 金融曲线图
|
||||||

|

|
||||||
|
|
||||||
### 2.21 南丁格尔图
|
### 2.21 南丁格尔图
|
||||||

|

|
||||||
|
|
||||||
### 2.22 坐标轴指示
|
### 2.22 坐标轴指示
|
||||||

|

|
||||||
|
|
||||||
### 2.23 相互作用图
|
### 2.23 相互作用图
|
||||||

|

|
||||||
|
|
||||||
### 2.24 滚动条曲线
|
### 2.24 滚动条曲线
|
||||||

|

|
||||||
|
|
||||||
### 2.25 多坐标轴图
|
### 2.25 多坐标轴图
|
||||||

|

|
||||||
@@ -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)
|
||||||
|
|||||||
@@ -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)
|
||||||
|
|||||||
@@ -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
|
||||||
|
|||||||
@@ -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);
|
||||||
|
|||||||
@@ -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);
|
||||||
|
|||||||
@@ -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);
|
||||||
|
|||||||
Reference in New Issue
Block a user