-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprotreeitem.cpp
More file actions
89 lines (79 loc) · 2.43 KB
/
protreeitem.cpp
File metadata and controls
89 lines (79 loc) · 2.43 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
#include "protreeitem.h"
#include "const.h"
ProTreeItem::ProTreeItem(QTreeWidget* view, const QString &name, const QString &path ,int type)
:QTreeWidgetItem(view,type),path(path),name(name),root(this),preItem(nullptr),nextItem(nullptr)
{
}
ProTreeItem::ProTreeItem(QTreeWidgetItem *parent, const QString & name, const QString & path,
QTreeWidgetItem* root, int type)
:QTreeWidgetItem(parent,type),path(path),name(name),root(root),preItem(nullptr),nextItem(nullptr)
{
}
const QString ProTreeItem::GetPath()
{
return path;
}
QTreeWidgetItem *ProTreeItem::GetRoot()
{
return root;
}
void ProTreeItem::SetPreItem(QTreeWidgetItem *item)
{
preItem = item;
}
void ProTreeItem::SetNextItem(QTreeWidgetItem *item)
{
nextItem = item;
}
ProTreeItem *ProTreeItem::GetPreItem()
{
return dynamic_cast<ProTreeItem *>(preItem);
}
ProTreeItem *ProTreeItem::GetNextItem()
{
return dynamic_cast<ProTreeItem *>(nextItem);
}
ProTreeItem *ProTreeItem::GetLastPicChild()
{
if(this->type() == TreeItemPic)
return nullptr;
int childCount = this->childCount();
if(childCount == 0)
return nullptr;
for(int i = childCount - 1; i>=0; i--){
QTreeWidgetItem *lastchild = this->child(i);
ProTreeItem *lastTreeItem = dynamic_cast<ProTreeItem *>(lastchild);
int itemType = lastTreeItem->type();
if(itemType == TreeItemPic)
return lastTreeItem;
lastchild = lastTreeItem->GetLastPicChild();
if(!lastchild){
continue;
}
lastTreeItem = dynamic_cast<ProTreeItem *>(lastchild);
return lastTreeItem;
}
return nullptr;
}
ProTreeItem *ProTreeItem::GetFirstPicChild()
{
if(this->type() == TreeItemPic)
return nullptr;
int childCount = this->childCount();
if(childCount == 0)
return nullptr;
for(int i = 0; i < childCount-1; i++){
QTreeWidgetItem *firstChild = this->child(i);
ProTreeItem *firstTreeItem = dynamic_cast<ProTreeItem *>(firstChild);
int itemType = firstTreeItem->type();
if(itemType == TreeItemPic)
return firstTreeItem;
firstChild = firstTreeItem->GetFirstPicChild();
if(!firstChild){
continue;
}
firstTreeItem = dynamic_cast<ProTreeItem *>(firstChild);
return firstTreeItem;
}
return nullptr;
}