qt/LedOK/mdevicemanager.cpp
2022-01-20 10:08:17 +08:00

477 lines
20 KiB
C++
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#include "mdevicemanager.h"
#include "ui_mdevicemanager.h"
#include "communication/network.h"
#include "wDevicesManager/specialdlg.h"
#include "LoUIClass/x_uimsgboxok.h"
#include <QHeaderView>
#include <QAction>
#include <QItemSelectionModel>
#include <QScreen>
//设备管理响应页面
mDeviceManager::mDeviceManager(QWidget *parent) :
QWidget(parent),
ui(new Ui::mDeviceManager)
{
setAttribute(Qt::WA_DeleteOnClose);
ui->setupUi(this);
pNetComm = new NetComm(this);
p_globaNetComm=pNetComm;
QStyledItemDelegate* itemDelegate = new QStyledItemDelegate();
m_headerItem = new QTreeWidgetItem();
ui->label_2->setVisible(false);
ui->label_4->setVisible(false);
ui->label_5->setVisible(false);
ui->label_5->setVisible(false);
ui->label_6->setVisible(false);
ui->label_7->setVisible(false);
ui->label_8->setVisible(false);
ui->label_9->setVisible(false);
ui->label_10->setVisible(false);
ui->label_11->setVisible(false);
ui->nDeviceNumOnline->setVisible(false);
ui->nDeviceNumUnlogin->setVisible(false);
ui->nDeviceNumOffline->setVisible(false);
QAction *search = new QAction(ui->txtSearch);
search->setIcon(QIcon(":/res/ProgramManager/bnSearch.png"));
ui->txtSearch->addAction(search, QLineEdit::LeadingPosition);
ui->txtSearch->setClearButtonEnabled(true);
ui->txtSearch->setProperty("ssType", "progManageTool");
ui->txtSearch->setProperty("ssName", "searchProg");
//qss中使用设置按钮刷新指定ip的样式
ui->bnFlashArea ->setProperty("ssType", tr("devManager"));
ui->bnFlashArea ->setProperty("ssName", tr("devFlash"));
ui->bnFlashArrow->setProperty("ssType", tr("devManager"));
ui->bnFlashArrow->setProperty("ssName", tr("devFlashSpeciallyIP"));
itemDelegate->setObjectName(tr("bnFlashArrowItem"));
ui->bnFlashArrow->setItemDelegate(itemDelegate);
//ui->bnFlashArrow->activated()
refreshLable();
m_headerItem->setTextAlignment(1, Qt::AlignHCenter | Qt::AlignVCenter);
for(int i=2; i<ENUM_DEVICEHEADE_END; i++) {
m_headerItem->setTextAlignment(i, Qt::AlignCenter);
}
// ui->wDeviceList->setProperty("ssType", "Toplist");
ui->wDeviceList->setHeaderItem(m_headerItem);
ui->wDeviceList->header()->setSectionResizeMode(ENUM_DEVICEHEADE_CHECK, QHeaderView::Fixed);
ui->wDeviceList->header()->setSectionResizeMode(ENUM_DEVICEHEADE_ONLINE, QHeaderView::Fixed);
ui->wDeviceList->header()->setSectionResizeMode(ENUM_DEVICEHEADE_SCREEN_ID, QHeaderView::Stretch);
ui->wDeviceList->header()->setSectionResizeMode(ENUM_DEVICEHEADE_SCREEN_IP, QHeaderView::Stretch);
ui->wDeviceList->header()->setSectionResizeMode(ENUM_DEVICEHEADE_SCREEN_SIZE, QHeaderView::Stretch);
ui->wDeviceList->header()->setSectionResizeMode(ENUM_DEVICEHEADE_REMARK_NAME, QHeaderView::Stretch);
ui->wDeviceList->header()->setSectionResizeMode(ENUM_DEVICEHEADE_BRIGHTNESS, QHeaderView::Stretch);
ui->wDeviceList->header()->setSectionResizeMode(ENUM_DEVICEHEADE_POWER, QHeaderView::Stretch);
ui->wDeviceList->header()->setSectionResizeMode(ENUM_DEVICEHEADE_PASSWORD, QHeaderView::Fixed);
ui->wDeviceList->header()->setSectionResizeMode(ENUM_DEVICEHEADE_MORE_INFO, QHeaderView::Fixed);
ui->wDeviceList->header()->setSectionResizeMode(ENUM_DEVICEHEADE_PIC_READBACK, QHeaderView::Fixed);
ui->wDeviceList->header()->setStretchLastSection(false);
ui->wDeviceList->setColumnWidth(ENUM_DEVICEHEADE_CHECK, 62);
ui->wDeviceList->setColumnWidth(ENUM_DEVICEHEADE_ONLINE, 52);
ui->wDeviceList->setColumnWidth(ENUM_DEVICEHEADE_PASSWORD, 72);
ui->wDeviceList->setColumnWidth(ENUM_DEVICEHEADE_MORE_INFO, 72);
ui->wDeviceList->setColumnWidth(ENUM_DEVICEHEADE_PIC_READBACK, 72);
// connect(ui->bnFlashArea, SIGNAL(clicked()), pNetComm, SLOT(RestoreLedCardIpByUdpCmd()));
connect(ui->bnFlashArea, SIGNAL(clicked()), this, SLOT(OnRefreshButtonPro()));
connect(ui->bnFlashArea, SIGNAL(clicked()), pNetComm, SLOT(CheckControllersInLanByUdp2222Cmd()));
connect(ui->bnFlashArrow,SIGNAL(activated(int)),this,SLOT(onSpecialIpPro()));
//ui->bnFlashArrow->currentIndexChanged(1);
/// ui->bnFlashArrow->activated()
connect(ui->wDeviceList, SIGNAL(sigCheckStateChanged(int)), this, SLOT(onCheckStateChanged(int)));
// connect(ui->wDeviceList, SIGNAL(itemSelectionChanged()), this, SLOT(onSelectionChanged()));
// ui->wDeviceList->setSelectionBehavior(QAbstractItemView::SelectItems);
ui->wDeviceList->setSelectionMode(QAbstractItemView::SingleSelection);
//ui->wDeviceList->setSelectionModel(QAbstractItemView::SingleSelection);
//连接信号和设备管理界面槽行数
connect(pNetComm,SIGNAL(addLedCard(LedCard *)),this,SLOT(onAddLedCard(LedCard *)));
connect(pNetComm,SIGNAL(ClearHeartbeatFlagByUdp(LedCard *)),this,SLOT(onClearHeartbeatFlagByUdp(LedCard *)));
// connect(pNetComm,SIGNAL(LedCardChanged(LedCard *)),this,SLOT(onLedCardChanged(LedCard *)));
connect(pNetComm,SIGNAL(sigwDeviceItemHttpPost(LedCard *)),this,SLOT(onsigwDeviceItemHttpPost(LedCard *)));
connect(ui->txtSearch,SIGNAL(textChanged(const QString &)),this,SLOT(FilterProgram(const QString &)));
connect(this,SIGNAL(sigShowDevicesInfoOrControlWidget(int)),this,SLOT(ShowDevicesInfoOrControlWidget(int)));
// connect(this,SIGNAL(sigShowDevicesInfoOrControlWidget(int)),this,SLOT(ShowDevicesInfoOrControlWidget(int)));
//开始轮训查找局域网内的控制卡
pNetComm->StartUpdCheck();
ui->wDeviceList->hideColumn(0);
ui->wDeviceList->HideHeaderCheckBox(true);
}
mDeviceManager::~mDeviceManager(){
pNetComm->StopAllCheck();
delete pNetComm;
delete ui;
}
int mDeviceManager::GetScreenWidth() {
QRect screenRect = QGuiApplication::primaryScreen()->availableVirtualGeometry();
return screenRect.width();
}
void mDeviceManager::ShowDevicesInfoOrControlWidget(int index)
{
int iDeviceListWidth=340;
m_intIndexFlagOfInfoOrControl=index;
if(index==ENUM_MAIN_TOOL_DEVICESMANAGER)//设备信息列表页面
{ ui->wDeviceList->hideColumn(0);
ui->wDeviceList->HideHeaderCheckBox(true);
if(m_wDeviceSetting!=nullptr)
{
for(int j=ENUM_DEVICEHEADE_SCREEN_SIZE;j<ENUM_DEVICEHEADE_END;j++)
ui->wDeviceList->showColumn(j);
int iParentWidgetWidth=parentWidget()->width();
ui->wDeviceList->resize(iParentWidgetWidth,ui->wDeviceList->size().height());
ui->wDeviceList->setMaximumWidth(GetScreenWidth());
m_wDeviceSetting->hide();
m_pDevicesControlWidget->hide();
}
}
else if(index==ENUM_MAIN_TOOL_DEVICESCONTROL)//终端控制页面
{
ui->wDeviceList->showColumn(0);
ui->wDeviceList->HideHeaderCheckBox(false);
if(m_wDeviceSetting==nullptr)
{
m_wDeviceSetting = new mDeviceSetting(this);
m_wDeviceSetting->setFixedHeight(120);
m_wDeviceSetting->setStyleSheet("background-color: rgba(255,255,255,0.5)");
for(int j=ENUM_DEVICEHEADE_SCREEN_SIZE;j<ENUM_DEVICEHEADE_END;j++)
ui->wDeviceList->hideColumn(j);
ui->verticalLayout_6->addWidget(m_wDeviceSetting);
GetSelectDeviceNum();
m_pDevicesControlWidget=new DevicesControllWidget(this,&SelectedLedCardList);
ui->verticalLayout_6->addWidget(m_pDevicesControlWidget);
m_pDevicesControlWidget->setStyleSheet("background-color: rgba(255,255,255,0.5)");
// m_pDevicesControlWidget->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Expanding);
// m_wDeviceSetting->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Expanding);
ui->wDeviceList->resize(iDeviceListWidth,ui->wDeviceList->size().height());
ui->wDeviceList->setMaximumWidth(iDeviceListWidth);
}
else {
m_wDeviceSetting->setFixedHeight(120);
for(int j=ENUM_DEVICEHEADE_SCREEN_SIZE;j<ENUM_DEVICEHEADE_END;j++)
ui->wDeviceList->hideColumn(j);
ui->wDeviceList->resize(iDeviceListWidth,ui->wDeviceList->size().height());
ui->wDeviceList->setMaximumWidth(iDeviceListWidth);
// m_pDevicesControlWidget->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Expanding);
// m_wDeviceSetting->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Expanding);
m_wDeviceSetting->show();
m_pDevicesControlWidget->show();
}
GetSelectDeviceNum();
emit sigSelectedDeviceList(&SelectedLedCardList);
}
int cnt = ui->wDeviceList->topLevelItemCount();
if(cnt>0)//切换到终点管理页面是刷新列表中控制卡的状态参数
for(int i=0; i<cnt; i++) {
static_cast<wDevicesItem*>(ui->wDeviceList->topLevelItem(i))->SetMainTabWidgetIndex(m_intIndexFlagOfInfoOrControl);
}
}
//基类虚函数,子类重绘函数
void mDeviceManager::paintEvent(QPaintEvent *event)
{
Q_UNUSED(event);
QStyleOption opt;
opt.init(this);
QPainter p(this);
style()->drawPrimitive(QStyle::PE_Widget, &opt, &p, this);
}
//切换语言,实时刷新翻译标签
void mDeviceManager::refreshLable()
{
ui->bnFlashArea->setText(tr("Refresh","Refresh"));
ui->bnFlashArrow->setItemText(0,tr("Specify IP"));
ui->label_5->setText(tr("Online"));
ui->label_3->setText(tr("All"));
ui->label_10->setText(tr("Unlogin"));
ui->label_11->setText(tr("Offline"));
m_headerItem->setData(ENUM_DEVICEHEADE_CHECK, 0, "");
m_headerItem->setData(ENUM_DEVICEHEADE_ONLINE, 0, tr("Online"));
m_headerItem->setData(ENUM_DEVICEHEADE_SCREEN_ID, 0, tr("Screen ID"));
m_headerItem->setData(ENUM_DEVICEHEADE_SCREEN_IP, 0, tr("Screen IP"));
m_headerItem->setData(ENUM_DEVICEHEADE_SCREEN_SIZE, 0, tr("Screen Size"));
m_headerItem->setData(ENUM_DEVICEHEADE_REMARK_NAME, 0, tr("Remark Name"));
m_headerItem->setData(ENUM_DEVICEHEADE_PIC_READBACK, 0, tr("readback pic"));
m_headerItem->setData(ENUM_DEVICEHEADE_BRIGHTNESS, 0, tr("Cur Brightness"));
m_headerItem->setData(ENUM_DEVICEHEADE_POWER, 0, tr("Power Status"));
m_headerItem->setData(ENUM_DEVICEHEADE_PASSWORD, 0, tr("Security"));
m_headerItem->setData(ENUM_DEVICEHEADE_MORE_INFO, 0, tr("More Info"));
for(int i=0;i<m_pwDeviceItemList.count();i++)
{
m_pwDeviceItemList.at(i)->refreshLable();
}
if(m_wDeviceSetting!=nullptr)
{
m_wDeviceSetting->refreshLable();
}
emit sigChangeLanguage();
}
void mDeviceManager::onClearHeartbeatFlagByUdp(LedCard *p)
{
int cnt = ui->wDeviceList->topLevelItemCount();
for(int i=0; i<cnt; i++) {
QString strTempCardId=static_cast<wDevicesItem*>(ui->wDeviceList->topLevelItem(i))->GetLedCardId();
if(strTempCardId == p->m_strCardId) {
static_cast<wDevicesItem*>(ui->wDeviceList->topLevelItem(i))->onClearHeartbeatFlagByUdp();
break;
}
}
}
void mDeviceManager::OnStopAllItemPostHeartBeat(bool b)
{
int cnt = ui->wDeviceList->topLevelItemCount();
if(cnt>0 && b==true)//切换到终点管理页面是刷新列表中控制卡的状态参数
for(int i=0; i<cnt; i++) {
static_cast<wDevicesItem*>(ui->wDeviceList->topLevelItem(i))->OnStopAllItemPostHeartBeat(b);
}
OnRefreshDevicesListStatusInfo();
}
void mDeviceManager::onAddLedCard(LedCard *p)
{
qDebug() << " SLOT onAddLedCard FUNC:" << p->m_strCardId;
int iExistFlg=0;
int cnt = ui->wDeviceList->topLevelItemCount();
for(int i=0; i<cnt; i++) {
QString strTempCardId=static_cast<wDevicesItem*>(ui->wDeviceList->topLevelItem(i))->GetLedCardId();
if(strTempCardId == p->m_strCardId) {
iExistFlg=1;
static_cast<wDevicesItem*>(ui->wDeviceList->topLevelItem(i))->ChangeHttpGetResponsePro(p);
break;
}
}
if(iExistFlg==0)
{
m_pwDeviceItemList.append(new wDevicesItem( p, ui->wDeviceList,this));
ui->nDeviceNum->setValue(ui->wDeviceList->topLevelItemCount());
}
}
void mDeviceManager::onsigwDeviceItemHttpPost(LedCard *p)
{
qDebug() << " SLOT onsigwDeviceItemHttpPost FUNC:" << p->m_strCardId;
int cnt = ui->wDeviceList->topLevelItemCount();
for(int i=0; i<cnt; i++) {
QString strTempCardId=static_cast<wDevicesItem*>(ui->wDeviceList->topLevelItem(i))->GetLedCardId();
if(strTempCardId == p->m_strCardId) {
static_cast<wDevicesItem*>(ui->wDeviceList->topLevelItem(i))->DeviceItemHttpPost();
break;
}
}
}
void mDeviceManager::OnRefreshDevicesListStatusInfo()
{
int cnt = ui->wDeviceList->topLevelItemCount();
for(int i=0; i<cnt; i++) {
static_cast<wDevicesItem*>(ui->wDeviceList->topLevelItem(i))->DeviceItemHttpPost();
}
}
void mDeviceManager::OnRefreshButtonPro()
{
pNetComm->StopUpdCheck();
pNetComm->ClearAllLedcardList();
ui->wDeviceList->onCheckAll(false);
ui->wDeviceList->clear();
ui->nDeviceNum->setValue(0);
m_pwDeviceItemList.clear();
pNetComm->StartUpdCheck();
}
//void mDeviceManager::onLedCardChanged(LedCard * p)
//{
// int cnt = ui->wDeviceList->topLevelItemCount();
// QStringList selectProgramlist;
// for(int i=0; i<cnt; i++) {
// QString strTempCardId=static_cast<wDevicesItem*>(ui->wDeviceList->topLevelItem(i))->GetLedCardId();
// if(strTempCardId == p->m_strCardId) {
// static_cast<wDevicesItem*>(ui->wDeviceList->topLevelItem(i))->ChangeHttpGetResponsePro(p);
// break;
// }
// }
// qDebug() << " SLOT onLedCardChanged FUNC:" << p->m_strCardId;
//}
void mDeviceManager::onSpecialIpPro()
{
SpecialDlg *pDlg =new SpecialDlg(this,this->pNetComm);
pNetComm->OnStartUdpTimer(false);
connect(pDlg, SIGNAL(sigGetSpecialIp(LedCard *)), this, SLOT(OnSpecialGetLedcardIp(LedCard *)));//显示正在保存提示对话框
pDlg->exec();
pNetComm->OnStartUdpTimer(true);
}
void mDeviceManager::OnSpecialGetLedcardIp(LedCard *p)
{
qDebug()<<"OnSpecialGetLedcardIp="<<p->m_strCardId;
int cnt = ui->wDeviceList->topLevelItemCount();
for(int i=0; i<cnt; i++) {
QString strTempCardId=static_cast<wDevicesItem*>(ui->wDeviceList->topLevelItem(i))->GetLedCardId();
if(strTempCardId == p->m_strCardId) {
static_cast<wDevicesItem*>(ui->wDeviceList->topLevelItem(i))->setCheckState(0,Qt::CheckState::Checked);
break;
}
}
}
void mDeviceManager::FilterProgram(const QString &strtemp)
{
if (strtemp.isEmpty()) //显示全部
{
for (int i = 0; i< ui->wDeviceList->topLevelItemCount(); ++i)
{
QTreeWidgetItem* topItem = ui->wDeviceList->topLevelItem(i);
ui->wDeviceList->setRowHidden(i,ui->wDeviceList->indexFromItem(topItem->parent()),false);
}
}
else
{
QList<QTreeWidgetItem*> resultList = ui->wDeviceList->findItems(strtemp, Qt::MatchContains,ENUM_DEVICEHEADE_SCREEN_ID); //搜索结果
if (resultList.size() > 0)
{
//QMessageBox::warning(this, "Export", QString(resultList.size()));
for (int i = 0; i< ui->wDeviceList->topLevelItemCount(); ++i)
{
QTreeWidgetItem* topItem = ui->wDeviceList->topLevelItem(i);
if (resultList.contains(topItem))
ui->wDeviceList->setRowHidden(i,ui->wDeviceList->indexFromItem(topItem->parent()),false); //显示匹配的结果
else
ui->wDeviceList->setRowHidden(i,ui->wDeviceList->indexFromItem(topItem->parent()),true); //隐藏不匹配的结果
}
}
else {
//QMessageBox::warning(this, "Export", "FilterProgram");
QList<QTreeWidgetItem*> resultList1 = ui->wDeviceList->findItems(strtemp, Qt::MatchContains,ENUM_DEVICEHEADE_REMARK_NAME); //搜索结果
if (resultList1.size() > 0)
{
//QMessageBox::warning(this, "Export", QString(resultList.size()));
for (int i = 0; i< ui->wDeviceList->topLevelItemCount(); ++i)
{
QTreeWidgetItem* topItem = ui->wDeviceList->topLevelItem(i);
if (resultList1.contains(topItem))
ui->wDeviceList->setRowHidden(i,ui->wDeviceList->indexFromItem(topItem->parent()),false); //显示匹配的结果
else
ui->wDeviceList->setRowHidden(i,ui->wDeviceList->indexFromItem(topItem->parent()),true); //隐藏不匹配的结果
}
}
else {
QList<QTreeWidgetItem*> resultList2 = ui->wDeviceList->findItems(strtemp, Qt::MatchContains,ENUM_DEVICEHEADE_SCREEN_IP); //搜索结果
if (resultList2.size() > 0)
{
//QMessageBox::warning(this, "Export", QString(resultList.size()));
for (int i = 0; i< ui->wDeviceList->topLevelItemCount(); ++i)
{
QTreeWidgetItem* topItem = ui->wDeviceList->topLevelItem(i);
if (resultList2.contains(topItem))
ui->wDeviceList->setRowHidden(i,ui->wDeviceList->indexFromItem(topItem->parent()),false); //显示匹配的结果
else
ui->wDeviceList->setRowHidden(i,ui->wDeviceList->indexFromItem(topItem->parent()),true); //隐藏不匹配的结果
}
}
else {
for (int i = 0; i< ui->wDeviceList->topLevelItemCount(); ++i)
{
QTreeWidgetItem* topItem = ui->wDeviceList->topLevelItem(i);
ui->wDeviceList->setRowHidden(i,ui->wDeviceList->indexFromItem(topItem->parent()),true); //隐藏不匹配的结果
}
}
}
}
}
}
void mDeviceManager::onSwitchControlWidget(int index)
{
if(m_pDevicesControlWidget!=nullptr)
m_pDevicesControlWidget->SwitchControlWidget(index);
}
void mDeviceManager::OnControlTcpSend(int iProgramIndex)
{
int cnt = ui->wDeviceList->topLevelItemCount();
QList<wDevicesItem*> list;
int iSelectCount=0;
for(int i=0; i<cnt; i++) {
if(ui->wDeviceList->topLevelItem(i)->checkState(0) == Qt::Checked) {
iSelectCount++;
wDevicesItem *item = static_cast<wDevicesItem*>(ui->wDeviceList->topLevelItem(i));
//item->HttpPostByTypeJsonObject(json);
item->OnControlTcpSend(iProgramIndex);
//QString strCardId=item->GetLedCardId();
// m_pDevicesControlWidget->OnOutputInfo(strCardId+":"+tr("Anycast")+"->"+tr("Success"));
}
}
}
void mDeviceManager::OnControlSendJson(QJsonObject &json,QString strFanYi)
{
int cnt = ui->wDeviceList->topLevelItemCount();
QList<wDevicesItem*> list;
int iSelectCount=0;
for(int i=0; i<cnt; i++) {
if(ui->wDeviceList->topLevelItem(i)->checkState(0) == Qt::Checked) {
iSelectCount++;
wDevicesItem *item = static_cast<wDevicesItem*>(ui->wDeviceList->topLevelItem(i));
item->HttpPostByTypeJsonObject(json);
QString strCardId=item->GetLedCardId();
m_pDevicesControlWidget->OnOutputInfo(strCardId+":"+tr("send")+"->"+strFanYi);
}
}
}
int mDeviceManager::GetSelectDeviceNum()
{
int cnt = ui->wDeviceList->topLevelItemCount();
int iSelectCount=0;
SelectedLedCardList.clear();
for(int i=0; i<cnt; i++) {
if(ui->wDeviceList->topLevelItem(i)->checkState(0) == Qt::Checked) {
iSelectCount++;
wDevicesItem *item = static_cast<wDevicesItem*>(ui->wDeviceList->topLevelItem(i));
SelectedLedCardList.append(item->GetLedCardPoint());
}
}
return iSelectCount;
}
void mDeviceManager::OnOutputInfo(QString strInfo)
{
if(m_intIndexFlagOfInfoOrControl==ENUM_MAIN_TOOL_DEVICESCONTROL)
if(m_pDevicesControlWidget!=nullptr)
m_pDevicesControlWidget->OnOutputInfo(strInfo);
}
void mDeviceManager::onCheckStateChanged(int f)
{
Q_UNUSED(f);
if(m_intIndexFlagOfInfoOrControl==ENUM_MAIN_TOOL_DEVICESCONTROL)
{
GetSelectDeviceNum();
emit sigSelectedDeviceList(&SelectedLedCardList);
}
}