-
Notifications
You must be signed in to change notification settings - Fork 1
/
dircardproxy.cpp
89 lines (79 loc) · 2.28 KB
/
dircardproxy.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
#include "dircardproxy.h"
#include"DirCard.h"
#include<QVBoxLayout>
#include"ElaCheckBox.h"
DirCardProxy::DirCardProxy(QWidget *parent) : QWidget(parent) {
parentWidget = qobject_cast<QWidget*>(parent);
filesLayout=new QVBoxLayout(this);
}
DirCardProxy::~DirCardProxy() {
cardMap.clear();
}
void DirCardProxy::addDirCard(DirCard *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, &DirCardProxy::onCheckBoxStateChanged);
}
}
void DirCardProxy::addDirCard(QString filename,QString cloudname,quint64 datasize,QString bindtime,int syncStatus,const int &id)
{
DirCard*card=new DirCard(filename,cloudname,datasize,bindtime,syncStatus,id);
if (card && parentWidget && !cardMap.contains(id)) {
cardMap[id] = card;
filesLayout->addWidget(card);
filesLayout->setAlignment(Qt::AlignTop);
}
}
void DirCardProxy::removeDirCard(const int &id) {
if (cardMap.contains(id)) {
DirCard *card = cardMap.take(id);
// 在这里可以从UI中移除card
filesLayout->removeWidget(card);
card->setParent(nullptr);
card->deleteLater();
emit removeCard();
}
}
void DirCardProxy::removeChecked()
{
QMapIterator<int, DirCard*> i(cardMap);
while (i.hasNext())
{
i.next();
int id = i.key();
DirCard *card = i.value();
if(card->ischecked())
removeDirCard(id);
}
emit removeCard();
}
void DirCardProxy::modifyDirCard(quint64 datasize,QString bindtime,int id)
{
QMapIterator<int,DirCard*> i(cardMap);
while(i.hasNext())
{
i.next();
int Id=i.key();
DirCard*card=i.value();
if(Id==id)
{
card->modify(datasize,bindtime);
}
}
}
void DirCardProxy::onCheckBoxStateChanged(int state) {
emit checkBoxToggled(state == Qt::Checked); // 发出信号,参数为复选框是否被勾选
}
void DirCardProxy::removeAll()
{
QMapIterator<int,DirCard*> i(cardMap);
while(i.hasNext())
{
i.next();
int Id=i.key();
DirCard*card=i.value();
removeDirCard(Id);
}
}