QVariant RemoteDeckList_TreeModel::data(const QModelIndex &index, int role) const { if (!index.isValid()) return QVariant(); if (index.column() >= 3) return QVariant(); Node *temp = static_cast<Node *>(index.internalPointer()); FileNode *file = dynamic_cast<FileNode *>(temp); if (!file) { DirectoryNode *node = dynamic_cast<DirectoryNode *>(temp); switch (role) { case Qt::DisplayRole: { switch (index.column()) { case 0: return node->getName(); default: return QVariant(); } } case Qt::DecorationRole: return index.column() == 0 ? dirIcon : QVariant(); default: return QVariant(); } } else { switch (role) { case Qt::DisplayRole: { switch (index.column()) { case 0: return file->getName(); case 1: return file->getId(); case 2: return file->getUploadTime(); default: return QVariant(); } } case Qt::DecorationRole: return index.column() == 0 ? fileIcon : QVariant(); case Qt::TextAlignmentRole: return index.column() == 1 ? Qt::AlignRight : Qt::AlignLeft; default: return QVariant(); } } }
RemoteDeckList_TreeModel::FileNode *RemoteDeckList_TreeModel::DirectoryNode::getNodeById(int id) const { for (int i = 0; i < size(); ++i) { DirectoryNode *node = dynamic_cast<DirectoryNode *>(at(i)); if (node) { FileNode *result = node->getNodeById(id); if (result) return result; } else { FileNode *file = dynamic_cast<FileNode *>(at(i)); if (file->getId() == id) return file; } } return 0; }