99 lines
2.1 KiB
C++
99 lines
2.1 KiB
C++
#pragma once
|
|
|
|
#include <QWidget>
|
|
#include <QList>
|
|
#include "TcpSocket.h"
|
|
#include "ui_Connect.h"
|
|
|
|
///
|
|
///通信协议
|
|
///
|
|
enum PROTOCOL
|
|
{
|
|
Error,
|
|
Login,
|
|
LoginSuccess,
|
|
LoginFailed,
|
|
ReadOrders,
|
|
ReadUsers,
|
|
FollowBet,
|
|
Logout
|
|
};
|
|
|
|
class Connect : public QWidget
|
|
{
|
|
Q_OBJECT
|
|
|
|
public:
|
|
Connect(QWidget *parent = nullptr);
|
|
~Connect();
|
|
private:
|
|
// 在 Connect 类中添加一个枚举表示连接状态
|
|
enum ServerState {
|
|
Disconnected, // 断开
|
|
Connected, // 已连接但未登录
|
|
LoggedIn // 已登录
|
|
};
|
|
// 客户端列表
|
|
QList<TcpSocket*> m_clients;
|
|
// 请求读取订单定时器
|
|
QTimer* m_timer;
|
|
// TCP连接状态检查定时器
|
|
QTimer* m_tcpCheckTimer;
|
|
signals:
|
|
// 连接状态改变信号
|
|
void signalStateChange(int);
|
|
// 收到注单信号
|
|
void signalUpdateOrders(QList<QMap<QString, QString>>);
|
|
// 收到用户列表信号
|
|
void signalUpdateUsers(QList<QMap<QString, QString>>);
|
|
// 更新读取订单次数信号
|
|
void signalReadOrdersTimes();
|
|
// 更新读取订单数量信号
|
|
void signalReadOrdersCount(int count);
|
|
|
|
public slots:
|
|
// 槽函数 -> 连接
|
|
void slotConnect();
|
|
// 槽函数 -> 断开连接
|
|
void slotDisconnect();
|
|
// 槽函数 -> 已连接
|
|
void slotOnConnected();
|
|
// 槽函数 -> 已断开
|
|
void slotOnDisconnected();
|
|
// 槽函数 -> 重连
|
|
void handleError(QAbstractSocket::SocketError socketError);
|
|
// 槽函数 -> 按日期接收
|
|
void slotDateRecv(qintptr socketDecriptor, QByteArray data);
|
|
// 槽函数 -> 更新订单
|
|
void slotUpdateOrders();
|
|
|
|
// 更新状态
|
|
void updateState();
|
|
// 同步连接状态
|
|
void syncConnectionState();
|
|
// 槽函数 -> 开始
|
|
void slotStart();
|
|
// 槽函数 -> 停止
|
|
void slotStop();
|
|
// 槽函数 -> 刷新会员列表
|
|
void slotFlushAccount();
|
|
|
|
|
|
// 槽函数 -> 发送跟单成功数据(防止重复派单)
|
|
void slotFollowBet(QMap<QString, QString> order);
|
|
|
|
|
|
private:
|
|
// 窗口关闭事件
|
|
void closeEvent(QCloseEvent* event);
|
|
// 解析协议类型
|
|
PROTOCOL ProtocolType(QString data);
|
|
private:
|
|
// 添加这两个槽函数
|
|
void updateReadCount(int row, int count);
|
|
void updateReadTimes(int row, int times);
|
|
private:
|
|
Ui::ConnectClass ui;
|
|
};
|