Browse Source

TorrentContentModel code clean up

adaptive-webui-19844
Christophe Dumez 13 years ago
parent
commit
45ba858022
  1. 31
      src/torrentcontentmodel.cpp

31
src/torrentcontentmodel.cpp

@ -50,9 +50,12 @@ TorrentContentModel::~TorrentContentModel()
void TorrentContentModel::updateFilesProgress(const std::vector<libtorrent::size_type>& fp) void TorrentContentModel::updateFilesProgress(const std::vector<libtorrent::size_type>& fp)
{ {
emit layoutAboutToBeChanged();
Q_ASSERT(m_filesIndex.size() == (int)fp.size()); Q_ASSERT(m_filesIndex.size() == (int)fp.size());
if (m_filesIndex.size() != (int)fp.size()) return; // XXX: Why is this necessary?
if (m_filesIndex.size() != (int)fp.size())
return;
emit layoutAboutToBeChanged();
for (uint i = 0; i < fp.size(); ++i) { for (uint i = 0; i < fp.size(); ++i) {
m_filesIndex[i]->setProgress(fp[i]); m_filesIndex[i]->setProgress(fp[i]);
} }
@ -61,9 +64,12 @@ void TorrentContentModel::updateFilesProgress(const std::vector<libtorrent::size
void TorrentContentModel::updateFilesPriorities(const std::vector<int>& fprio) void TorrentContentModel::updateFilesPriorities(const std::vector<int>& fprio)
{ {
emit layoutAboutToBeChanged();
Q_ASSERT(m_filesIndex.size() == (int)fprio.size()); Q_ASSERT(m_filesIndex.size() == (int)fprio.size());
if (m_filesIndex.size() != (int)fprio.size()) return; // XXX: Why is this necessary?
if (m_filesIndex.size() != (int)fprio.size())
return;
emit layoutAboutToBeChanged();
for (uint i = 0; i < fprio.size(); ++i) { for (uint i = 0; i < fprio.size(); ++i) {
m_filesIndex[i]->setPriority(fprio[i]); m_filesIndex[i]->setPriority(fprio[i]);
} }
@ -82,8 +88,8 @@ std::vector<int> TorrentContentModel::getFilesPriorities() const
bool TorrentContentModel::allFiltered() const bool TorrentContentModel::allFiltered() const
{ {
for (int i=0; i<m_rootItem->childCount(); ++i) { foreach (const TorrentContentModelItem* fileItem, m_filesIndex) {
if (m_rootItem->child(i)->priority() != prio::IGNORED) if (fileItem->priority() != prio::IGNORED)
return false; return false;
} }
return true; return true;
@ -133,13 +139,13 @@ bool TorrentContentModel::setData(const QModelIndex& index, const QVariant& valu
emit dataChanged(index, index); emit dataChanged(index, index);
return true; return true;
} }
return false; return false;
} }
TorrentContentModelItem::ItemType TorrentContentModel::itemType(const QModelIndex& index) const TorrentContentModelItem::ItemType TorrentContentModel::itemType(const QModelIndex& index) const
{ {
const TorrentContentModelItem *item = static_cast<const TorrentContentModelItem*>(index.internalPointer()); return static_cast<const TorrentContentModelItem*>(index.internalPointer())->itemType();
return item->itemType();
} }
int TorrentContentModel::getFileIndex(const QModelIndex& index) int TorrentContentModel::getFileIndex(const QModelIndex& index)
@ -181,6 +187,7 @@ Qt::ItemFlags TorrentContentModel::flags(const QModelIndex& index) const
if (itemType(index) == TorrentContentModelItem::FolderType) if (itemType(index) == TorrentContentModelItem::FolderType)
return Qt::ItemIsEditable | Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsUserCheckable | Qt::ItemIsTristate; return Qt::ItemIsEditable | Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsUserCheckable | Qt::ItemIsTristate;
return Qt::ItemIsEditable | Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsUserCheckable; return Qt::ItemIsEditable | Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsUserCheckable;
} }
@ -201,22 +208,20 @@ QModelIndex TorrentContentModel::index(int row, int column, const QModelIndex& p
return QModelIndex(); return QModelIndex();
TorrentContentModelFolder* parentItem; TorrentContentModelFolder* parentItem;
if (!parent.isValid()) if (!parent.isValid())
parentItem = m_rootItem; parentItem = m_rootItem;
else else
parentItem = static_cast<TorrentContentModelFolder*>(parent.internalPointer()); parentItem = static_cast<TorrentContentModelFolder*>(parent.internalPointer());
Q_ASSERT(parentItem); Q_ASSERT(parentItem);
if (row >= parentItem->childCount()) if (row >= parentItem->childCount())
return QModelIndex(); return QModelIndex();
TorrentContentModelItem* childItem = parentItem->child(row); TorrentContentModelItem* childItem = parentItem->child(row);
if (childItem) { if (childItem)
return createIndex(row, column, childItem); return createIndex(row, column, childItem);
} else {
return QModelIndex(); return QModelIndex();
} }
}
QModelIndex TorrentContentModel::parent(const QModelIndex& index) const QModelIndex TorrentContentModel::parent(const QModelIndex& index) const
{ {
@ -226,8 +231,8 @@ QModelIndex TorrentContentModel::parent(const QModelIndex& index) const
TorrentContentModelItem* childItem = static_cast<TorrentContentModelItem*>(index.internalPointer()); TorrentContentModelItem* childItem = static_cast<TorrentContentModelItem*>(index.internalPointer());
if (!childItem) if (!childItem)
return QModelIndex(); return QModelIndex();
TorrentContentModelItem *parentItem = childItem->parent();
TorrentContentModelItem *parentItem = childItem->parent();
if (parentItem == m_rootItem) if (parentItem == m_rootItem)
return QModelIndex(); return QModelIndex();

Loading…
Cancel
Save