QModelIndex StandardModel::index(int row, int column, const QModelIndex &parent) const { if (parent.isValid() && parent.column() != 0) return QModelIndex(); TreeItem * parentItem = getItem(parent); TreeItemPtr childItem = parentItem->child(row); if (childItem) return createIndex(row, column, childItem.get()); else return QModelIndex(); }
bool ExpandTreeEx::init(Composite& rootNode) { ExpandTreePtr tree = ExpandTreePtr( new ExpandTree("Tree", CoordPercent(0.0f, 0.0f), CoordPercent(0.35f, 1.0f))); std::string homeDir = GetCurrentWorkingDirectory(); for (FileDescription fd : GetDirectoryDescriptionListing(homeDir)) { std::string fileName = GetFileName(fd.fileLocation); if (fileName.length() > 0 && fileName[0] == '.') continue; TreeItemPtr child; if (fd.fileType == FileType::Directory) { child = TreeItemPtr(new TreeItem(fileName, 0xf115, 22)); addDirectory(fd.fileLocation, child.get()); } else { child = TreeItemPtr(new TreeItem(fileName, 0xf016, 18)); child->onExpand = [this,fd](TreeItem* current) { addLeaf(current,fd); }; } tree->addItem(child); } rootNode.add(tree); return true; }