ryxeo-webphotoalbum-git / mymodelitem.cpp @ 71c02254
Historique | Voir | Annoter | Télécharger (5,05 ko)
1 |
/****************************************************************************
|
---|---|
2 |
* This file is part of qtFM, a simple, fast file manager.
|
3 |
* Copyright (C) 2010,2011 Wittfella
|
4 |
*
|
5 |
* This file is a local adaptation for RyXeo TagFile System
|
6 |
* Copyright (C) 2012 Eric Seigne <eric.seigne@ryxeo.com>
|
7 |
*
|
8 |
* This program is free software; you can redistribute it and/or modify
|
9 |
* it under the terms of the GNU General Public License as published by
|
10 |
* the Free Software Foundation; either version 2 of the License, or
|
11 |
* (at your option) any later version.
|
12 |
*
|
13 |
* This program is distributed in the hope that it will be useful,
|
14 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
15 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
16 |
* GNU General Public License for more details.
|
17 |
*
|
18 |
* You should have received a copy of the GNU General Public License
|
19 |
* along with this program. If not, see <http://www.gnu.org/licenses/>
|
20 |
*
|
21 |
* Contact e-mail: wittfella@qtfm.org
|
22 |
*
|
23 |
****************************************************************************/
|
24 |
|
25 |
#include "mymodelitem.h" |
26 |
#include <QtGui> |
27 |
|
28 |
|
29 |
//---------------------------------------------------------------------------------------
|
30 |
myModelItem::myModelItem(const QFileInfo& fileInfo, myModelItem* parent)
|
31 |
{ |
32 |
mParent = parent; |
33 |
mFileInfo = fileInfo; |
34 |
walked = false;
|
35 |
dirty = false;
|
36 |
|
37 |
if(parent)
|
38 |
{ |
39 |
parent->addChild(this);
|
40 |
mAbsFilePath = fileInfo.filePath(); |
41 |
} |
42 |
else
|
43 |
{ |
44 |
walked = true;
|
45 |
mAbsFilePath = "";
|
46 |
} |
47 |
} |
48 |
|
49 |
//---------------------------------------------------------------------------------------
|
50 |
myModelItem::~myModelItem() |
51 |
{ |
52 |
qDeleteAll(mChildren); |
53 |
} |
54 |
|
55 |
//---------------------------------------------------------------------------------------
|
56 |
myModelItem* myModelItem::childAt(int position)
|
57 |
{ |
58 |
return mChildren.value(position,0); |
59 |
} |
60 |
|
61 |
//---------------------------------------------------------------------------------------
|
62 |
int myModelItem::childCount() const |
63 |
{ |
64 |
if(walked) return mChildren.count(); |
65 |
return 1; |
66 |
} |
67 |
|
68 |
//---------------------------------------------------------------------------------------
|
69 |
bool myModelItem::hasChild(QString fileName)
|
70 |
{ |
71 |
foreach(myModelItem * item, mChildren) |
72 |
if(item->fileName() == fileName) return true; |
73 |
|
74 |
return false; |
75 |
} |
76 |
|
77 |
//---------------------------------------------------------------------------------------
|
78 |
int myModelItem::childNumber() const |
79 |
{ |
80 |
if(mParent)
|
81 |
{ |
82 |
return mParent->mChildren.indexOf(const_cast<myModelItem*>(this)); |
83 |
} |
84 |
|
85 |
return 0; |
86 |
} |
87 |
|
88 |
//---------------------------------------------------------------------------------------
|
89 |
QList<myModelItem*> myModelItem::children() |
90 |
{ |
91 |
return mChildren;
|
92 |
} |
93 |
|
94 |
//---------------------------------------------------------------------------------------
|
95 |
myModelItem* myModelItem::parent() |
96 |
{ |
97 |
return mParent;
|
98 |
} |
99 |
|
100 |
//---------------------------------------------------------------------------------------
|
101 |
QString myModelItem::absoluteFilePath()const
|
102 |
{ |
103 |
return mAbsFilePath;
|
104 |
} |
105 |
|
106 |
//---------------------------------------------------------------------------------------
|
107 |
QString myModelItem::fileName() const
|
108 |
{ |
109 |
if(mAbsFilePath == "/") return "/"; |
110 |
else return mFileInfo.fileName(); |
111 |
|
112 |
} |
113 |
|
114 |
//---------------------------------------------------------------------------------------
|
115 |
QFileInfo myModelItem::fileInfo() const
|
116 |
{ |
117 |
return mFileInfo;
|
118 |
} |
119 |
|
120 |
//---------------------------------------------------------------------------------------
|
121 |
void myModelItem::refreshFileInfo()
|
122 |
{ |
123 |
mFileInfo.refresh(); |
124 |
} |
125 |
|
126 |
//---------------------------------------------------------------------------------------
|
127 |
void myModelItem::addChild(myModelItem *child)
|
128 |
{ |
129 |
if(!mChildren.contains(child))
|
130 |
{ |
131 |
mChildren.append(child); |
132 |
} |
133 |
} |
134 |
|
135 |
//---------------------------------------------------------------------------------------
|
136 |
void myModelItem::removeChild(myModelItem *child)
|
137 |
{ |
138 |
mChildren.removeOne(child); |
139 |
delete child;
|
140 |
} |
141 |
|
142 |
//---------------------------------------------------------------------------------------
|
143 |
void myModelItem::clearAll()
|
144 |
{ |
145 |
foreach(myModelItem *child, mChildren) |
146 |
delete child;
|
147 |
mChildren.clear(); |
148 |
walked = 0;
|
149 |
} |
150 |
|
151 |
//---------------------------------------------------------------------------------------
|
152 |
void myModelItem::changeName(QString newName)
|
153 |
{ |
154 |
mAbsFilePath = mParent->absoluteFilePath() + SEPARATOR + newName; |
155 |
mFileInfo.setFile(mAbsFilePath); |
156 |
clearAll(); |
157 |
} |
158 |
|
159 |
//---------------------------------------------------------------------------------------
|
160 |
myModelItem* myModelItem::matchPath(const QStringList& path, int startIndex) |
161 |
{ |
162 |
QStringList temp = path; |
163 |
temp.replace(0,"/"); |
164 |
temp.removeAll("");
|
165 |
|
166 |
if(walked == 0) //not populated yet |
167 |
{ |
168 |
walked = true;
|
169 |
} |
170 |
|
171 |
foreach(myModelItem* child, mChildren) |
172 |
{ |
173 |
QString match = temp.at(startIndex); |
174 |
|
175 |
if(child->fileName() == match)
|
176 |
{ |
177 |
if(startIndex + 1 == temp.count()) return child; |
178 |
else return child->matchPath(path,startIndex + 1); |
179 |
} |
180 |
} |
181 |
|
182 |
return 0; |
183 |
} |
184 |
|
185 |
//---------------------------------------------------------------------------------------
|
186 |
|
187 |
|