-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathfrmsearchequipment.cpp
More file actions
239 lines (215 loc) · 7.29 KB
/
frmsearchequipment.cpp
File metadata and controls
239 lines (215 loc) · 7.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
#include "frmsearchequipment.h"
#include "ui_frmsearchequipment.h"
frmSearchEquipment::frmSearchEquipment(QWidget *parent) :
QDialog(parent),
ui(new Ui::frmSearchEquipment)
{
ui->setupUi(this);
InitStyle();
connect(ui->pushButton,SIGNAL(clicked(bool)),this,SLOT(pushButton_clicked()));
connect(ui->btnRegister,SIGNAL(clicked(bool)),this,SLOT(RegisterSlaves()));
connect(ui->btnCancel,SIGNAL(clicked(bool)),this,SLOT(btnCancel()));
connect(ui->btnSelectAll,SIGNAL(clicked(bool)),this,SLOT(btnSelectAll()));
connect(ui->btnSelectChange,SIGNAL(clicked(bool)),this,SLOT(btnSelectChange()));
connect(ui->btnSelectNull,SIGNAL(clicked(bool)),this,SLOT(btnSelectNull()));
//connect(this,SIGNAL(sigShowSlaveList(QList<paraData*>*)),this,SLOT(showSlaveList(QList<paraData*>*)));
}
frmSearchEquipment::~frmSearchEquipment()
{
delete ui;
}
void frmSearchEquipment::InitStyle()
{
//设置窗体标题栏隐藏
this->setWindowFlags(Qt::FramelessWindowHint | Qt::WindowSystemMenuHint | Qt::WindowMinMaxButtonsHint);
location = this->geometry();
max = false;
mousePressed = false;
//设置窗体关闭时自动释放内存
//this->setAttribute(Qt::WA_DeleteOnClose);
//安装事件监听器,让标题栏识别鼠标双击
ui->lab_Title->installEventFilter(this);
IconHelper::Instance()->SetIcon(ui->btnMenu_Close, QChar(0xf00d), 10);
//IconHelper::Instance()->SetIcon(ui->btnMenu_Max, QChar(0xf096), 10);
IconHelper::Instance()->SetIcon(ui->btnMenu_Min, QChar(0xf068), 10);
//IconHelper::Instance()->SetIcon(ui->btnMenu, QChar(0xf0c9), 10);
IconHelper::Instance()->SetIcon(ui->lab_Ico, QChar(0xf015), 12);
ui->tableWidget->setColumnCount(7);
//ui->tableWidget->setRowCount(5);
QStringList header;
header<<"选择"<<"名称"<<"设备型号"<<"版本"<<"序列号"<<"IP地址"<<"联网模式";
ui->tableWidget->setHorizontalHeaderLabels(header);
ui->tableWidget->resizeColumnsToContents();
//ui->tableWidget->horizontalHeader()->setStretchLastSection(true);//自
}
bool frmSearchEquipment::eventFilter(QObject *obj, QEvent *event)
{
if (event->type() == QEvent::MouseButtonDblClick) {
this->on_btnMenu_Max_clicked();
return true;
}
return QObject::eventFilter(obj, event);
}
void frmSearchEquipment::mouseMoveEvent(QMouseEvent *e)
{
if (mousePressed && (e->buttons() && Qt::LeftButton) && !max) {
this->move(e->globalPos() - mousePoint);
e->accept();
}
}
void frmSearchEquipment::mousePressEvent(QMouseEvent *e)
{
if (e->button() == Qt::LeftButton) {
mousePressed = true;
mousePoint = e->globalPos() - this->pos();
e->accept();
}
}
void frmSearchEquipment::mouseReleaseEvent(QMouseEvent *)
{
mousePressed = false;
}
void frmSearchEquipment::on_btnMenu_Close_clicked()
{
this->close();
}
void frmSearchEquipment::on_btnMenu_Max_clicked()
{
if (max) {
this->setGeometry(location);
IconHelper::Instance()->SetIcon(ui->btnMenu_Max, QChar(0xf096), 10);
ui->btnMenu_Max->setToolTip("最大化");
} else {
location = this->geometry();
this->setGeometry(qApp->desktop()->availableGeometry());
IconHelper::Instance()->SetIcon(ui->btnMenu_Max, QChar(0xf079), 10);
ui->btnMenu_Max->setToolTip("还原");
}
max = !max;
}
void frmSearchEquipment::on_btnMenu_Min_clicked()
{
this->showMinimized();
}
void frmSearchEquipment::pushButton_clicked()
{
emit SearchEqument();
}
void frmSearchEquipment::DisplayResult(QList<TreeViewItem*> *registeredList, QList<paraData*> *searchedAll)
{
searchedList = searchedAll;
if(ui->checkBox->checkState() == Qt::Checked)
{
for(int i=0;i<searchedList->count();i++)
{
for(int j=0;j<registeredList->count();j++)
{
if(registeredList->at(j)->mac == searchedAll->at(i)->net.macAddr)
{
searchedAll->removeAt(i);
i--;
break;
}
}
}
}
//emit sigShowSlaveList(searchedList);
showSlaveList(searchedList);
}
void frmSearchEquipment::showSlaveList(QList<paraData*> *searchedList)
{
//删除所有行
int count = ui->tableWidget->rowCount();
for(int i=0;i<count;i++)
{
ui->tableWidget->removeRow(0);
}
//重新设置行数
ui->tableWidget->setRowCount(searchedList->count());
for(int i=0;i<searchedList->count();i++)
{
paraData* pdata = searchedList->at(i);
//插入复选框并居中显示
QCheckBox *ckb = new QCheckBox(ui->tableWidget);
QHBoxLayout *hLayout = new QHBoxLayout(ui->tableWidget);
QWidget *widget = new QWidget(ui->tableWidget);
ckb->setChecked(true);//默认为选中状态
hLayout->addWidget(ckb);
hLayout->setMargin(0); // 必须添加, 否则CheckBox不能正常显示
hLayout->setAlignment(ckb, Qt::AlignCenter);
widget->setLayout(hLayout);
ui->tableWidget->setCellWidget(i,0,widget);
ui->tableWidget->setItem(i,1,new QTableWidgetItem(pdata->name));
ui->tableWidget->setItem(i,2,new QTableWidgetItem(pdata->getSlaveType()));
ui->tableWidget->setItem(i,3,new QTableWidgetItem(pdata->version));
ui->tableWidget->setItem(i,4,new QTableWidgetItem(pdata->net.macAddr));
ui->tableWidget->setItem(i,5,new QTableWidgetItem(pdata->net.ip));
ui->tableWidget->setItem(i,6,new QTableWidgetItem(pdata->net.networkModel?"客户端模式":"服务器模式"));
}
ui->tableWidget->resizeColumnsToContents();
}
void frmSearchEquipment::RegisterSlaves()
{
QList<paraData*> resultList;
resultList.clear();
int rowcount = ui->tableWidget->rowCount();
for(int i=0;i<rowcount;i++)
{
//获取复选框指针
QWidget *widget = (QWidget *)ui->tableWidget->cellWidget(i,0);
QCheckBox *ckb = (QCheckBox *)widget->children().at(1);
if(ckb->isChecked())
{
resultList.append(searchedList->at(i));
}
}
emit registerSlaves(resultList);
this->close();
}
void frmSearchEquipment::btnCancel()
{
this->close();
}
void frmSearchEquipment::btnSelectAll()
{
for(int i=0;i<ui->tableWidget->rowCount();i++)
{
//获取复选框指针
QWidget *widget = (QWidget *)ui->tableWidget->cellWidget(i,0);
QCheckBox *ckb = (QCheckBox *)widget->children().at(1);
if(!ckb->isChecked())
{
ckb->setChecked(true);
}
}
}
void frmSearchEquipment::btnSelectNull()
{
for(int i=0;i<ui->tableWidget->rowCount();i++)
{
//获取复选框指针
QWidget *widget = (QWidget *)ui->tableWidget->cellWidget(i,0);
QCheckBox *ckb = (QCheckBox *)widget->children().at(1);
if(ckb->isChecked())
{
ckb->setChecked(false);
}
}
}
void frmSearchEquipment::btnSelectChange()
{
for(int i=0;i<ui->tableWidget->rowCount();i++)
{
//获取复选框指针
QWidget *widget = (QWidget *)ui->tableWidget->cellWidget(i,0);
QCheckBox *ckb = (QCheckBox *)widget->children().at(1);
if(ckb->isChecked())
{
ckb->setChecked(false);
}
else
{
ckb->setChecked(true);
}
}
}