2 Star 24 Fork 5

石桥北/NumOneQt

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
pointcloudwidget.cpp 4.21 KB
一键复制 编辑 原始数据 按行查看 历史
石桥北 提交于 2024-11-18 12:03 . 增加通讯IP设置按钮
#include "PointCloudWidget.h"
PointCloudWidget::PointCloudWidget(QWidget *parent): QWidget{parent}
{
aWebSocketClient = new WeSocketClient(nullptr);
CreateGui();
LinkSignalSlot();
}
void PointCloudWidget::CreateGui()
{
resize(800,600);
this->setStyleSheet("Background:rgb(240,240,240)");
setAttribute(Qt::WA_StyledBackground);//设置背景颜色,缺少此命令将使设置样式失效
//创建并设置总布局
TotalLayout = new QHBoxLayout();
PntsCloudGBox = new QGroupBox();
PntsCloudGBox->setTitle("点云显示");
TotalLayout->addWidget(PntsCloudGBox, 0, 0);
PntsCloudVLyt = new QVBoxLayout(PntsCloudGBox);
PointCloudShow = new PointsDrawWindow(nullptr);
PntsCloudVLyt->addWidget(PointCloudShow, 0, 0);
OperateGBox = new QGroupBox();
OperateGBox->setTitle("操作框");
TotalLayout->addWidget(OperateGBox);
operateVLyt = new QVBoxLayout(OperateGBox);
operateVLyt->addStretch(0);
setIPBtn = new QPushButton("设置WS通讯的IP");
setIPBtn->setToolTip("设置webSocket通讯中对方的IP地址");
operateVLyt->addWidget(setIPBtn);
LoadDatasBtn = new QPushButton("加载并显示数据");
ClearDatasBtn = new QPushButton("清空数据");
operateVLyt->addStretch(0);
operateVLyt->addWidget(LoadDatasBtn);
operateVLyt->addWidget(ClearDatasBtn);
operateVLyt->addStretch(0);
WsconnectedStateLabel = new QLabel("断开连接");
WsconnectedStateLabel->setStyleSheet("Background:rgb(240,100,100);");
WsconnectedStateLabel->setAlignment(Qt::AlignHCenter);
operateVLyt->addWidget(WsconnectedStateLabel);
WebsocketBtnsHLyt = new QHBoxLayout();
operateVLyt->addLayout(WebsocketBtnsHLyt);
WebsocketOpenBtn = new QPushButton("打开websocket");
WebsocketBtnsHLyt->addWidget(WebsocketOpenBtn);
WebsocketCloseBtn = new QPushButton("关闭websocket");
WebsocketBtnsHLyt->addWidget(WebsocketCloseBtn);
SaveDatasBtn = new QPushButton("保存数据");
operateVLyt->addWidget(SaveDatasBtn);
operateVLyt->addStretch(0);
TotalLayout->setStretch(0,3);//setStretch放在addWidget之后起作用
TotalLayout->setStretch(1,1);
this->setLayout(TotalLayout);
}
void PointCloudWidget::LinkSignalSlot()
{
connect(LoadDatasBtn, &QPushButton::clicked, this, [=](){PointCloudShow->LoadPointsFromFile();});
connect(ClearDatasBtn, &QPushButton::clicked, this, [=](){PointCloudShow->ClearDatas();});
connect(aWebSocketClient, &WeSocketClient::SendReceiveMsg, this, &PointCloudWidget::RecieveWsDatas);
connect(aWebSocketClient, &WeSocketClient::SendConnectedState, this, &PointCloudWidget::updateConnState);
connect(setIPBtn, &QPushButton::clicked, this, [=]()
{
aWebSocketClient->setIP(QInputDialog::getText(nullptr, "请输入IP", "IP:", QLineEdit::Normal, QString("192.168.4.1")));
});
connect(WebsocketOpenBtn, &QPushButton::clicked, this, &PointCloudWidget::openws);
connect(WebsocketCloseBtn, &QPushButton::clicked, this, &PointCloudWidget::closews);
connect(SaveDatasBtn, &QPushButton::clicked, this, &PointCloudWidget::savedatas);
}
void PointCloudWidget::RecieveWsDatas(const QString &message)
{
QStringList strs_list = message.split(" ");
if(strs_list.size() == 6)
{
float point_x = strs_list[0].toFloat(),point_y = strs_list[1].toFloat(),point_z = strs_list[2].toFloat();
float color_r = strs_list[3].toFloat(),color_g = strs_list[4].toFloat(),color_b = strs_list[5].toFloat();
PointCloudShow->PushBackPointColor(point_x,point_y,point_z,color_r,color_g,color_b);
}
}
void PointCloudWidget::updateConnState(bool state)
{
if(state)
{
WsconnectedStateLabel->setText("已经连接");
WsconnectedStateLabel->setStyleSheet("Background:rgb(0,240,100);");
}
else
{
WsconnectedStateLabel->setText("断开连接");
WsconnectedStateLabel->setStyleSheet("Background:rgb(240,100,100);");
}
}
void PointCloudWidget::openws()
{
PointCloudShow->ClearDatas();
aWebSocketClient->open();
aWebSocketClient->flush();
}
void PointCloudWidget::closews()
{
aWebSocketClient->close();
}
void PointCloudWidget::savedatas()
{
PointCloudShow->SaveDatas();
}
PointCloudWidget::~PointCloudWidget()
{
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C++
1
https://gitee.com/NorthBridge/num-one-qt.git
[email protected]:NorthBridge/num-one-qt.git
NorthBridge
num-one-qt
NumOneQt
master

搜索帮助