-
Notifications
You must be signed in to change notification settings - Fork 0
/
widgetdiskclean.cpp
111 lines (91 loc) · 3.71 KB
/
widgetdiskclean.cpp
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
#include "widgetdiskclean.h"
#include "ui_widgetdiskclean.h"
#include <QDebug>
#include <QThread>
#include <QMessageBox>
#include <QTreeWidgetItem>
#include "global.h"
WidgetDiskClean::WidgetDiskClean(QWidget *parent) :
QWidget(parent),
ui(new Ui::WidgetDiskClean)
{
ui->setupUi(this);
ui->treeWidget->setColumnCount(4);
QStringList headers;
headers<<"suffix"<<"name"<<"size"<<"path";
ui->treeWidget->setHeaderLabels(headers);
ui->treeWidget->setColumnWidth(0, 70);
ui->treeWidget->setColumnWidth(1, 220);
ui->treeWidget->setColumnWidth(2, 40);
ui->treeWidget->setColumnWidth(3, 350);
m_pObjDiskClean = new ObjDiskClean();
m_pThread = new QThread();
m_pObjDiskClean->moveToThread(m_pThread);
m_pThread->start();
connect( ui->pushButton_disk_clean, &QPushButton::clicked, m_pObjDiskClean, &ObjDiskClean::clean);
connect( ui->pushButton_disk_scan, &QPushButton::clicked, m_pObjDiskClean, &ObjDiskClean::scan);
connect(m_pObjDiskClean, &ObjDiskClean::sigUpdateCurrentCheckFile, this, &WidgetDiskClean::updateCurrentCheckFile, Qt::QueuedConnection);
connect(m_pObjDiskClean, &ObjDiskClean::sigCleanFinish, this, &WidgetDiskClean::cleanFinish, Qt::QueuedConnection);
//connect(this, &WidgetDiskClean::sigClean, m_pObjDiskClean, &ObjDiskClean::clean, Qt::BlockingQueuedConnection);
//connect(this, &WidgetDiskClean::sigScan, m_pObjDiskClean, &ObjDiskClean::scan, Qt::BlockingQueuedConnection);
}
WidgetDiskClean::~WidgetDiskClean()
{
delete m_pObjDiskClean;
m_pObjDiskClean = NULL;
}
void WidgetDiskClean::updateCurrentCheckFile(bool bClean, QString strFilePath, CleanItem* pItem)
{
ui->label_diskclean_file->setText(strFilePath);
if(!bClean)
{
return;
}
QList<QTreeWidgetItem*> lst = ui->treeWidget->findItems(pItem->m_strName, Qt::MatchFixedString);
QTreeWidgetItem* pTreeItem = NULL;
if(0 == lst.size())
{
//添加新的父节点
QStringList title;
title<<pItem->m_strName<<"1"<<"2"<<"3";
pTreeItem = new QTreeWidgetItem(ui->treeWidget, title);
pTreeItem->setCheckState(0, Qt::Checked);
//给父节点添加checkbox
//QCheckBox* pCheck = new QCheckBox();
//ui->treeWidget->setItemWidget( pTreeItem, 0, pCheck );
//pItem->m_pSuperItem->m_pCheckBox = pCheck;
//在父节点下添加子节点
QStringList listChild;
listChild << ""<<pItem->m_strName<<QString::number(pItem->m_nTotalSizeKb)<<pItem->m_strFilePath;
QTreeWidgetItem *leafChild = new QTreeWidgetItem(pTreeItem, listChild);
pTreeItem->addChild(leafChild);
leafChild->setCheckState(leafChild->childCount(), Qt::Checked);
//给子节点添加checkbox
//QCheckBox* pCheckChild = new QCheckBox();
//ui->treeWidget->setItemWidget( leafChild, 0, pCheck );
//pItem->m_pCheckBox = pCheckChild;
}
else if(1 == lst.size())
{
//添加到父节点下
pTreeItem = lst.at(0);
QStringList list1;
list1 << ""<<pItem->m_strName<<QString::number(pItem->m_nTotalSizeKb)<<pItem->m_strFilePath;
QTreeWidgetItem *leaf1 = new QTreeWidgetItem(pTreeItem, list1);
pTreeItem->addChild(leaf1);
leaf1->setCheckState(leaf1->childCount(), Qt::Checked);
//QCheckBox* pCheck = new QCheckBox();
//ui->treeWidget->setItemWidget( leaf1, 0, pCheck );
//pItem->m_pCheckBox = pCheck;
}
else
{
//有多个节点,异常状态,提示错误
QString strMsg = QString("%s 有多个").arg(pItem->m_strName);
QMessageBox::about(this, Global::s_strExeName, strMsg);
}
}
void WidgetDiskClean::cleanFinish()
{
qDebug()<<"WidgetDiskClean::cleanFinish";
}