-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprotreethead.cpp
More file actions
115 lines (106 loc) · 3.96 KB
/
protreethead.cpp
File metadata and controls
115 lines (106 loc) · 3.96 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
#include "protreethead.h"
#include <QDir>
#include <QtDebug>
#include "protreeitem.h"
#include "const.h"
ProTreeThead::ProTreeThead(const QString &srcPath,
const QString &distPath,
QTreeWidgetItem *parentItem,
int fileCount, QTreeWidget *self,
QTreeWidgetItem *root, QObject *parent)
:QThread(parent),srcPath(srcPath),distPath(distPath),fileCount(fileCount)
,parentItem(parentItem),self(self),root(root),bstop(false)
{
}
ProTreeThead::~ProTreeThead()
{
}
void ProTreeThead::run()
{
CreateProTree(srcPath,distPath,parentItem,fileCount,self,root);
if(bstop){
return;
}
emit SigFinishProgress(fileCount);
}
void ProTreeThead::CreateProTree(const QString &srcPath,
const QString &distPath,
QTreeWidgetItem *parentItem,
int fileCount, QTreeWidget *self,
QTreeWidgetItem *root, QTreeWidgetItem *preItem)
{
if(bstop){
return;
}
bool needCopy = true;
if(srcPath == distPath){
needCopy = false;
}
QDir importDir(srcPath);
QStringList nameFilters;
importDir.setFilter(QDir::Dirs | QDir::Files | QDir::NoDotAndDotDot);
importDir.setSorting(QDir::Name);
QFileInfoList list = importDir.entryInfoList();
for(int i = 0;i < list.size();i++){
if(bstop){
return;
}
QFileInfo fileInfo = list.at(i);
bool bIsDir = fileInfo.isDir();
if(bIsDir){
//文件夹处理
if(bstop)
return;
fileCount++;
emit SigUpdateProgress(fileCount);
QDir distDir(distPath);
QString subDistPath = distDir.absoluteFilePath(fileInfo.fileName());
QDir subDistDir(subDistPath);
if(!subDistDir.exists()){
bool ok = subDistDir.mkpath(subDistPath);
if(!ok)
continue;
}
ProTreeItem *item = new ProTreeItem(parentItem,fileInfo.fileName(),subDistPath
,root,TreeItemDir);
item->setData(0,Qt::DisplayRole,fileInfo.fileName());
item->setData(0,Qt::DecorationRole,QIcon(":/icon/dir.png"));
item->setData(0,Qt::ToolTipRole,subDistPath);
qDebug()<<"item->setData(0,Qt::DecorationRole";
CreateProTree(fileInfo.absoluteFilePath(),subDistPath,item,fileCount,self,root,preItem);
}else{
if(bstop)
return;
//取出完整文件后缀
const QString &suffix = fileInfo.completeSuffix();
if(suffix != "png" && suffix != "jpeg" && suffix != "jpg"){
continue;
}
fileCount ++;
emit SigUpdateProgress(fileCount);
if(!needCopy){
continue;
}
QDir distDir(distPath);
QString distFilePath = distDir.absoluteFilePath(fileInfo.fileName());
if(!QFile::copy(fileInfo.absoluteFilePath(),distFilePath)){
continue;
}
ProTreeItem *item = new ProTreeItem(parentItem,fileInfo.fileName(),
distPath,root,TreeItemPic);
item->setData(0,Qt::DisplayRole,fileInfo.fileName());
item->setData(0,Qt::DecorationRole,QIcon(":/icon/pic.png"));
item->setData(0,Qt::ToolTipRole,distFilePath);
if(preItem){
ProTreeItem *preProItem = dynamic_cast<ProTreeItem *>(preItem);
preProItem->SetNextItem(item);
}
item->SetPreItem(preItem);
preItem = item;
}
}
}
void ProTreeThead::SlotCancelProgress()
{
this->bstop = true;
}