-
Notifications
You must be signed in to change notification settings - Fork 1
/
filecardproxy.cpp
93 lines (83 loc) · 2.45 KB
/
filecardproxy.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
#include "filecardproxy.h"
#include"FileCard.h"
#include<QVBoxLayout>
#include"ElaCheckBox.h"
FileCardProxy::FileCardProxy(QWidget *parent) : QWidget(parent) {
parentWidget = qobject_cast<QWidget*>(parent);
filesLayout=new QVBoxLayout(this);
}
FileCardProxy::~FileCardProxy() {
cardMap.clear();
}
void FileCardProxy::addFileCard(FileCard *card, const int &id) {
if (card && parentWidget && !cardMap.contains(id)) {
cardMap[id] = card;
filesLayout->addWidget(card);
filesLayout->setAlignment(Qt::AlignTop);
connect(card->getCheckBox(), &ElaCheckBox::stateChanged, this, &FileCardProxy::onCheckBoxStateChanged);
}
}
void FileCardProxy::addFileCard(QString filename,quint64 datasize,double speed,int progress,int syncStatus,const int &id)
{
FileCard*card=new FileCard(filename,datasize,speed,progress,syncStatus,id);
if (card && parentWidget && !cardMap.contains(id)) {
cardMap[id] = card;
filesLayout->addWidget(card);
filesLayout->setAlignment(Qt::AlignTop);
connect(card->getCheckBox(), &ElaCheckBox::stateChanged, this, &FileCardProxy::onCheckBoxStateChanged);
}
}
void FileCardProxy::removeFileCard(const int &id) {
if (cardMap.contains(id)) {
FileCard *card = cardMap.take(id);
card->processing(100);
// 在这里可以从UI中移除card
filesLayout->removeWidget(card);
card->setParent(nullptr);
card->deleteLater();
emit removeCard();
}
}
void FileCardProxy::modify(quint64 totalsize,quint64 currentsize,int Id)
{
if(cardMap.find(Id)==cardMap.end())
return;
auto thisCard=cardMap[Id];
thisCard->modify(totalsize,currentsize);
}
void FileCardProxy::processing(int p,int Id)
{
QMapIterator<int,FileCard*> i(cardMap);
while(i.hasNext())
{
i.next();
int id=i.key();
FileCard*card=i.value();
if(id==Id)
card->processing(p);
}
}
int FileCardProxy::totalprogress()
{
int total=0;
int x=0;
QMapIterator<int,FileCard*> i(cardMap);
while(i.hasNext())
{
i.next();
int id=i.key();
FileCard*card=i.value();
total+=card->progress;
x++;
}
int progress;
if(x!=0)
progress=total/x;
else
progress=0;
return progress;
}
void FileCardProxy::onCheckBoxStateChanged(int state)
{
emit checkBoxToggled(state == Qt::Checked); // 发出信号,参数为复选框是否被勾选
}