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)
|
void NavigationController::add(const QString &path, NavigationItemModel *parentItem, bool isCircleDelegate)
|
||||||
{
|
{
|
||||||
///@todo recursively do the following for all subdirs
|
|
||||||
auto dir = QDir(path);
|
auto dir = QDir(path);
|
||||||
if(!dir.exists()) return;
|
if(!dir.exists()) return;
|
||||||
|
|
||||||
|
|
@ -48,12 +47,13 @@ void NavigationController::add(const QString &path, NavigationItemModel *parentI
|
||||||
for(const auto& name : subDirsNames){
|
for(const auto& name : subDirsNames){
|
||||||
if(name == "." || name == "..") continue;
|
if(name == "." || name == "..") continue;
|
||||||
auto item = new NavigationItemModel(parentItem);
|
auto item = new NavigationItemModel(parentItem);
|
||||||
item->setCircleDelegate(isCircleDelegate);
|
|
||||||
if(!item->setPath(path + "/" + name)) {
|
if(!item->setPath(path + "/" + name)) {
|
||||||
item->deleteLater();
|
item->deleteLater();
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
qDebug() << "appending item " << item->getPath();
|
qDebug() << "appending item " << item->getPath();
|
||||||
|
item->setCircleDelegate(isCircleDelegate);
|
||||||
|
connect(item, &NavigationItemModel::clicked, this, &NavigationController::onNavigationRequest);
|
||||||
parentItem->appendChild(item);
|
parentItem->appendChild(item);
|
||||||
add(item->getPath(), item, false);
|
add(item->getPath(), item, false);
|
||||||
}
|
}
|
||||||
|
|
@ -65,3 +65,12 @@ void NavigationController::add(const QString &path, NavigationItemModel *parentI
|
||||||
}
|
}
|
||||||
// end testing
|
// 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;
|
NavigationListModel* mNavList;
|
||||||
QString mRootPath = ".";
|
QString mRootPath = ".";
|
||||||
|
|
||||||
QQmlContext* mContext;
|
QQmlContext* mContext = Q_NULLPTR;
|
||||||
|
|
||||||
|
private slots:
|
||||||
|
void onNavigationRequest();
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // NAVIGATIONCONTROLLER_H
|
#endif // NAVIGATIONCONTROLLER_H
|
||||||
|
|
|
||||||
|
|
@ -55,11 +55,21 @@ void NavigationItemModel::setCircleDelegate(bool value)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool NavigationItemModel::isRoot() const
|
||||||
|
{
|
||||||
|
return mParentItem;
|
||||||
|
}
|
||||||
|
|
||||||
NavigationItemModel *NavigationItemModel::getParentItem()
|
NavigationItemModel *NavigationItemModel::getParentItem()
|
||||||
{
|
{
|
||||||
return mParentItem;
|
return mParentItem;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool NavigationItemModel::hasChildren() const
|
||||||
|
{
|
||||||
|
return !mChildren.isEmpty();
|
||||||
|
}
|
||||||
|
|
||||||
QList<NavigationItemModel *> NavigationItemModel::getChildren()
|
QList<NavigationItemModel *> NavigationItemModel::getChildren()
|
||||||
{
|
{
|
||||||
return mChildren;
|
return mChildren;
|
||||||
|
|
|
||||||
|
|
@ -26,8 +26,11 @@ public:
|
||||||
bool isCircleDelegate() const;
|
bool isCircleDelegate() const;
|
||||||
void setCircleDelegate(bool value);
|
void setCircleDelegate(bool value);
|
||||||
|
|
||||||
|
bool isRoot() const;
|
||||||
NavigationItemModel* getParentItem();
|
NavigationItemModel* getParentItem();
|
||||||
QList<NavigationItemModel*> getChildren();
|
|
||||||
|
bool hasChildren() const;
|
||||||
|
QList<NavigationItemModel *> getChildren();
|
||||||
|
|
||||||
void appendChild(NavigationItemModel* item);
|
void appendChild(NavigationItemModel* item);
|
||||||
void clearChildren();
|
void clearChildren();
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue