show child list on click
This commit is contained in:
parent
99a2d118c8
commit
0b9e8fa067
4 changed files with 29 additions and 4 deletions
|
|
@ -38,7 +38,6 @@ void NavigationController::setContextProperties()
|
|||
|
||||
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;
|
||||
|
||||
|
|
@ -48,12 +47,13 @@ void NavigationController::add(const QString &path, NavigationItemModel *parentI
|
|||
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();
|
||||
item->setCircleDelegate(isCircleDelegate);
|
||||
connect(item, &NavigationItemModel::clicked, this, &NavigationController::onNavigationRequest);
|
||||
parentItem->appendChild(item);
|
||||
add(item->getPath(), item, false);
|
||||
}
|
||||
|
|
@ -65,3 +65,12 @@ void NavigationController::add(const QString &path, NavigationItemModel *parentI
|
|||
}
|
||||
// end testing
|
||||
}
|
||||
|
||||
void NavigationController::onNavigationRequest()
|
||||
{
|
||||
auto item = qobject_cast<NavigationItemModel*>(QObject::sender());
|
||||
if(!item) return;
|
||||
|
||||
if(item->hasChildren())
|
||||
mNavList->setModelItems(item->getChildren());
|
||||
}
|
||||
|
|
|
|||
|
|
@ -25,7 +25,10 @@ private:
|
|||
NavigationListModel* mNavList;
|
||||
QString mRootPath = ".";
|
||||
|
||||
QQmlContext* mContext;
|
||||
QQmlContext* mContext = Q_NULLPTR;
|
||||
|
||||
private slots:
|
||||
void onNavigationRequest();
|
||||
};
|
||||
|
||||
#endif // NAVIGATIONCONTROLLER_H
|
||||
|
|
|
|||
|
|
@ -55,11 +55,21 @@ void NavigationItemModel::setCircleDelegate(bool value)
|
|||
}
|
||||
}
|
||||
|
||||
bool NavigationItemModel::isRoot() const
|
||||
{
|
||||
return mParentItem;
|
||||
}
|
||||
|
||||
NavigationItemModel *NavigationItemModel::getParentItem()
|
||||
{
|
||||
return mParentItem;
|
||||
}
|
||||
|
||||
bool NavigationItemModel::hasChildren() const
|
||||
{
|
||||
return !mChildren.isEmpty();
|
||||
}
|
||||
|
||||
QList<NavigationItemModel *> NavigationItemModel::getChildren()
|
||||
{
|
||||
return mChildren;
|
||||
|
|
|
|||
|
|
@ -26,7 +26,10 @@ public:
|
|||
bool isCircleDelegate() const;
|
||||
void setCircleDelegate(bool value);
|
||||
|
||||
bool isRoot() const;
|
||||
NavigationItemModel* getParentItem();
|
||||
|
||||
bool hasChildren() const;
|
||||
QList<NavigationItemModel *> getChildren();
|
||||
|
||||
void appendChild(NavigationItemModel* item);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue