-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfileitem.cpp
More file actions
40 lines (33 loc) · 856 Bytes
/
fileitem.cpp
File metadata and controls
40 lines (33 loc) · 856 Bytes
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
#include "fileitem.h"
FileItem::FileItem(const QString &name, const QString &path, qint64 size,
const QDateTime &modified, bool isDir)
: m_name(name)
, m_path(path)
, m_size(size)
, m_modified(modified)
, m_isDirectory(isDir)
, m_cachedTotalSize(0)
, m_totalSizeCached(false)
{
}
FileItem::~FileItem()
{
m_children.clear();
}
void FileItem::addChild(std::shared_ptr<FileItem> child)
{
m_children.append(child);
m_totalSizeCached = false;
}
qint64 FileItem::totalSize() const
{
if (m_totalSizeCached)
return m_cachedTotalSize;
qint64 total = m_size;
for (const auto &child : m_children) {
total += child->totalSize();
}
const_cast<FileItem*>(this)->m_cachedTotalSize = total;
const_cast<FileItem*>(this)->m_totalSizeCached = true;
return total;
}