mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-07-22 22:21:09 -04:00
added RsCollectionModel to RsCollectionDialog (unfiished)
This commit is contained in:
parent
eb0ef1e39b
commit
eae4fe86aa
7 changed files with 208 additions and 146 deletions
|
@ -2,6 +2,10 @@
|
|||
|
||||
#include "RsCollectionModel.h"
|
||||
|
||||
RsCollectionModel::RsCollectionModel(const RsCollection& col, QObject *parent)
|
||||
: QAbstractItemModel(parent),mCollection(col)
|
||||
{}
|
||||
|
||||
// Indernal Id is always a quintptr_t (basically a uint with the size of a pointer). Depending on the
|
||||
// architecture, the pointer may have 4 or 8 bytes. We use the low-level bit for type (0=dir, 1=file) and
|
||||
// the remaining bits for the index (which will be accordingly understood as a FileIndex or a DirIndex)
|
||||
|
@ -35,6 +39,21 @@ int RsCollectionModel::rowCount(const QModelIndex& parent) const
|
|||
return mCollection.fileTree().directoryData(i.index).subdirs.size() + mCollection.fileTree().directoryData(i.index).subfiles.size();
|
||||
}
|
||||
|
||||
bool RsCollectionModel::hasChildren(const QModelIndex & parent) const
|
||||
{
|
||||
if(!parent.isValid())
|
||||
return mCollection.fileTree().root();
|
||||
|
||||
EntryIndex i;
|
||||
if(!convertInternalIdToIndex(parent.internalId(),i))
|
||||
return 0;
|
||||
|
||||
if(i.is_file)
|
||||
return false;
|
||||
else
|
||||
return mCollection.fileTree().directoryData(i.index).subdirs.size() + mCollection.fileTree().directoryData(i.index).subfiles.size() > 0;
|
||||
}
|
||||
|
||||
int RsCollectionModel::columnCount(const QModelIndex&) const
|
||||
{
|
||||
return 4;
|
||||
|
@ -180,8 +199,47 @@ QVariant RsCollectionModel::decorationRole(const EntryIndex& i,int col) const
|
|||
return QVariant();
|
||||
}
|
||||
|
||||
|
||||
|
||||
void RsCollectionModel::preMods()
|
||||
{
|
||||
mUpdating = true;
|
||||
emit layoutAboutToBeChanged();
|
||||
}
|
||||
void RsCollectionModel::postMods()
|
||||
{
|
||||
// update all the local structures
|
||||
|
||||
mDirParents.clear();
|
||||
mFileParents.clear();
|
||||
mDirSizes.clear();
|
||||
|
||||
uint64_t s;
|
||||
recursUpdateLocalStructures(mCollection.fileTree().root(),s);
|
||||
|
||||
mUpdating = false;
|
||||
emit layoutChanged();
|
||||
}
|
||||
|
||||
void RsCollectionModel::recursUpdateLocalStructures(RsFileTree::DirIndex dir_index,uint64_t& total_size)
|
||||
{
|
||||
total_size = 0;
|
||||
|
||||
const auto& dd(mCollection.fileTree().directoryData(dir_index));
|
||||
|
||||
for(uint32_t i=0;i<dd.subfiles.size();++i)
|
||||
{
|
||||
total_size += mCollection.fileTree().fileData(dd.subfiles[i]).size;
|
||||
mFileParents[dd.subfiles[i]] = dir_index;
|
||||
}
|
||||
|
||||
for(uint32_t i=0;i<dd.subdirs.size();++i)
|
||||
{
|
||||
uint64_t ss;
|
||||
recursUpdateLocalStructures(dd.subdirs[i],ss);
|
||||
total_size += ss;
|
||||
mDirParents[dd.subdirs[i]] = dir_index;
|
||||
}
|
||||
mDirSizes[dir_index] = total_size;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue