void RemoteDeckList_TreeModel::addFolderToTree(const QString &name, const QList<DeckList_TreeItem *> &folderItems, DirectoryNode *parent) { DirectoryNode *newItem = new DirectoryNode(name, parent); beginInsertRows(nodeToIndex(parent), parent->size(), parent->size()); parent->append(newItem); endInsertRows(); for (int i = 0; i < folderItems.size(); ++i) { DeckList_Directory *subFolder = dynamic_cast<DeckList_Directory *>(folderItems[i]); if (subFolder) addFolderToTree(subFolder, newItem); else addFileToTree(dynamic_cast<DeckList_File *>(folderItems[i]), newItem); } }
// ----------------------------------------------------------------------------- // // ----------------------------------------------------------------------------- void BookmarksModel::addFileToTree(QString& path, QModelIndex& specifiedParent) { path = QDir::toNativeSeparators(path); QFileInfo fi(path); int rowPos = self->rowCount(specifiedParent); self->insertRow(rowPos, specifiedParent); QModelIndex newNameIndex = self->index(rowPos, BookmarksItem::Name, specifiedParent); if (fi.isFile()) { QString name = fi.baseName(); self->setData(newNameIndex, name, Qt::DisplayRole); } else { QDir dir(path); self->setData(newNameIndex, dir.dirName(), Qt::DisplayRole); } if (fi.isFile()) { QModelIndex newPathIndex = self->index(rowPos, BookmarksItem::Path, specifiedParent); self->setData(newPathIndex, path, Qt::DisplayRole); self->setData(newNameIndex, QIcon(":/text.png"), Qt::DecorationRole); } else { self->setData(newNameIndex, QIcon(":/folder_blue.png"), Qt::DecorationRole); QStringList filters; filters << "*.dream3d" << "*.ini" << "*.txt" << "*.json"; QDirIterator iter(path, filters, QDir::AllDirs | QDir::Files | QDir::NoDotAndDotDot); while (iter.hasNext()) { QString nextPath = iter.next(); addFileToTree(nextPath, newNameIndex); } } }