add subdirectories recursively
This commit is contained in:
parent
717e131b75
commit
99a2d118c8
6 changed files with 70 additions and 40 deletions
|
|
@ -20,25 +20,7 @@ void NavigationController::init(const QString &rootPath)
|
|||
if(!rootDir.exists()) return;
|
||||
mRootPath = rootPath;
|
||||
|
||||
///@todo recursively do the following for all subdirs
|
||||
auto subDirsNames = rootDir.entryList(QDir::AllDirs);
|
||||
qDebug() << subDirsNames;
|
||||
for(const auto& name : subDirsNames){
|
||||
if(name == "." || name == "..") continue;
|
||||
auto item = new NavigationItemModel(mRootItem);
|
||||
if(!item->setPath(mRootPath + name)) {
|
||||
item->deleteLater();
|
||||
continue;
|
||||
}
|
||||
mRootItem->appendChild(item);
|
||||
|
||||
}
|
||||
// just for testing!
|
||||
auto list = mRootItem->getChildren();
|
||||
for (const auto& elem: list){
|
||||
qDebug() << elem->getImageSource();
|
||||
}
|
||||
// end testing
|
||||
add(mRootPath, mRootItem, true);
|
||||
|
||||
mNavList->setModelItems(mRootItem->getChildren());
|
||||
}
|
||||
|
|
@ -53,3 +35,33 @@ void NavigationController::setContextProperties()
|
|||
{
|
||||
mContext->setContextProperty("navigationList", mNavList);
|
||||
}
|
||||
|
||||
void NavigationController::add(const QString &path, NavigationItemModel *parentItem, bool isCircleDelegate)
|
||||
{
|
||||
///@todo recursively do the following for all subdirs
|
||||
auto dir = QDir(path);
|
||||
if(!dir.exists()) return;
|
||||
|
||||
auto subDirsNames = dir.entryList(QDir::AllDirs);
|
||||
qDebug() << path << subDirsNames;
|
||||
|
||||
for(const auto& name : subDirsNames){
|
||||
if(name == "." || name == "..") continue;
|
||||
auto item = new NavigationItemModel(parentItem);
|
||||
item->setCircleDelegate(isCircleDelegate);
|
||||
if(!item->setPath(path + "/" + name)) {
|
||||
item->deleteLater();
|
||||
continue;
|
||||
}
|
||||
qDebug() << "appending item " << item->getPath();
|
||||
parentItem->appendChild(item);
|
||||
add(item->getPath(), item, false);
|
||||
}
|
||||
|
||||
// just for testing!
|
||||
auto list = parentItem->getChildren();
|
||||
for (const auto& elem: list){
|
||||
qDebug() << elem->getImageSource() << elem->isCircleDelegate();
|
||||
}
|
||||
// end testing
|
||||
}
|
||||
|
|
|
|||
|
|
@ -19,6 +19,7 @@ public:
|
|||
|
||||
private:
|
||||
void setContextProperties();
|
||||
void add(const QString & path, NavigationItemModel* parentItem, bool isCircleDelegate);
|
||||
|
||||
NavigationItemModel* mRootItem;
|
||||
NavigationListModel* mNavList;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue