add subdirectories recursively
This commit is contained in:
parent
717e131b75
commit
99a2d118c8
6 changed files with 70 additions and 40 deletions
|
|
@ -5,12 +5,11 @@ Rectangle{
|
|||
id: container
|
||||
|
||||
property var model
|
||||
property bool isCircle : true
|
||||
property alias imageSource: contentImage.source
|
||||
|
||||
width: 100
|
||||
height: width
|
||||
radius: isCircle ? width/2 : 0
|
||||
radius: model.pIsCircleDelegate ? width/2 : 0
|
||||
color: "blue"
|
||||
|
||||
Image{
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -29,24 +29,23 @@ Window {
|
|||
}
|
||||
}
|
||||
}
|
||||
MyScrollView{
|
||||
anchors.left: parent.left
|
||||
anchors.right: parent.right
|
||||
anchors.top: circleList.bottom
|
||||
anchors.margins: 20
|
||||
// MyScrollView{
|
||||
// anchors.left: parent.left
|
||||
// anchors.right: parent.right
|
||||
// anchors.top: circleList.bottom
|
||||
// anchors.margins: 20
|
||||
|
||||
flickableItem.interactive: true
|
||||
contentItem:
|
||||
ListView{
|
||||
model: 20
|
||||
anchors.fill: parent
|
||||
spacing: 10
|
||||
orientation: ListView.Horizontal
|
||||
delegate:
|
||||
NavigationListDelegate{
|
||||
id: test
|
||||
isCircle: false
|
||||
}
|
||||
}
|
||||
}
|
||||
// flickableItem.interactive: true
|
||||
// contentItem:
|
||||
// ListView{
|
||||
// model: 20
|
||||
// anchors.fill: parent
|
||||
// spacing: 10
|
||||
// orientation: ListView.Horizontal
|
||||
// delegate:
|
||||
// NavigationListDelegate{
|
||||
// id: test
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
}
|
||||
|
|
|
|||
|
|
@ -42,6 +42,19 @@ bool NavigationItemModel::setPath(const QString &path)
|
|||
return true;
|
||||
}
|
||||
|
||||
bool NavigationItemModel::isCircleDelegate() const
|
||||
{
|
||||
return mIsCircleDelegate;
|
||||
}
|
||||
|
||||
void NavigationItemModel::setCircleDelegate(bool value)
|
||||
{
|
||||
if(value != mIsCircleDelegate){
|
||||
mIsCircleDelegate = value;
|
||||
emit isCircleDelegateChanged();
|
||||
}
|
||||
}
|
||||
|
||||
NavigationItemModel *NavigationItemModel::getParentItem()
|
||||
{
|
||||
return mParentItem;
|
||||
|
|
|
|||
|
|
@ -8,8 +8,10 @@ class NavigationItemModel : public QObject
|
|||
Q_OBJECT
|
||||
|
||||
Q_PROPERTY(QString pImageSource READ getImageSource NOTIFY imageSourceChanged)
|
||||
Q_PROPERTY(bool pIsCircleDelegate READ isCircleDelegate NOTIFY isCircleDelegateChanged)
|
||||
|
||||
signals:
|
||||
void isCircleDelegateChanged();
|
||||
void imageSourceChanged();
|
||||
void clicked();
|
||||
|
||||
|
|
@ -21,6 +23,9 @@ public:
|
|||
QString getPath() const;
|
||||
bool setPath(const QString & path);
|
||||
|
||||
bool isCircleDelegate() const;
|
||||
void setCircleDelegate(bool value);
|
||||
|
||||
NavigationItemModel* getParentItem();
|
||||
QList<NavigationItemModel*> getChildren();
|
||||
|
||||
|
|
@ -32,6 +37,7 @@ public:
|
|||
private:
|
||||
QString mPath = QString("");
|
||||
QString mImageSource;
|
||||
bool mIsCircleDelegate = false;
|
||||
|
||||
QList<NavigationItemModel*> mChildren = QList<NavigationItemModel*>();
|
||||
NavigationItemModel* mParentItem = nullptr;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue