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
|
id: container
|
||||||
|
|
||||||
property var model
|
property var model
|
||||||
property bool isCircle : true
|
|
||||||
property alias imageSource: contentImage.source
|
property alias imageSource: contentImage.source
|
||||||
|
|
||||||
width: 100
|
width: 100
|
||||||
height: width
|
height: width
|
||||||
radius: isCircle ? width/2 : 0
|
radius: model.pIsCircleDelegate ? width/2 : 0
|
||||||
color: "blue"
|
color: "blue"
|
||||||
|
|
||||||
Image{
|
Image{
|
||||||
|
|
|
||||||
|
|
@ -20,25 +20,7 @@ void NavigationController::init(const QString &rootPath)
|
||||||
if(!rootDir.exists()) return;
|
if(!rootDir.exists()) return;
|
||||||
mRootPath = rootPath;
|
mRootPath = rootPath;
|
||||||
|
|
||||||
///@todo recursively do the following for all subdirs
|
add(mRootPath, mRootItem, true);
|
||||||
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
|
|
||||||
|
|
||||||
mNavList->setModelItems(mRootItem->getChildren());
|
mNavList->setModelItems(mRootItem->getChildren());
|
||||||
}
|
}
|
||||||
|
|
@ -53,3 +35,33 @@ void NavigationController::setContextProperties()
|
||||||
{
|
{
|
||||||
mContext->setContextProperty("navigationList", mNavList);
|
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:
|
private:
|
||||||
void setContextProperties();
|
void setContextProperties();
|
||||||
|
void add(const QString & path, NavigationItemModel* parentItem, bool isCircleDelegate);
|
||||||
|
|
||||||
NavigationItemModel* mRootItem;
|
NavigationItemModel* mRootItem;
|
||||||
NavigationListModel* mNavList;
|
NavigationListModel* mNavList;
|
||||||
|
|
|
||||||
|
|
@ -29,24 +29,23 @@ Window {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
MyScrollView{
|
// MyScrollView{
|
||||||
anchors.left: parent.left
|
// anchors.left: parent.left
|
||||||
anchors.right: parent.right
|
// anchors.right: parent.right
|
||||||
anchors.top: circleList.bottom
|
// anchors.top: circleList.bottom
|
||||||
anchors.margins: 20
|
// anchors.margins: 20
|
||||||
|
|
||||||
flickableItem.interactive: true
|
// flickableItem.interactive: true
|
||||||
contentItem:
|
// contentItem:
|
||||||
ListView{
|
// ListView{
|
||||||
model: 20
|
// model: 20
|
||||||
anchors.fill: parent
|
// anchors.fill: parent
|
||||||
spacing: 10
|
// spacing: 10
|
||||||
orientation: ListView.Horizontal
|
// orientation: ListView.Horizontal
|
||||||
delegate:
|
// delegate:
|
||||||
NavigationListDelegate{
|
// NavigationListDelegate{
|
||||||
id: test
|
// id: test
|
||||||
isCircle: false
|
// }
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -42,6 +42,19 @@ bool NavigationItemModel::setPath(const QString &path)
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool NavigationItemModel::isCircleDelegate() const
|
||||||
|
{
|
||||||
|
return mIsCircleDelegate;
|
||||||
|
}
|
||||||
|
|
||||||
|
void NavigationItemModel::setCircleDelegate(bool value)
|
||||||
|
{
|
||||||
|
if(value != mIsCircleDelegate){
|
||||||
|
mIsCircleDelegate = value;
|
||||||
|
emit isCircleDelegateChanged();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
NavigationItemModel *NavigationItemModel::getParentItem()
|
NavigationItemModel *NavigationItemModel::getParentItem()
|
||||||
{
|
{
|
||||||
return mParentItem;
|
return mParentItem;
|
||||||
|
|
|
||||||
|
|
@ -8,8 +8,10 @@ class NavigationItemModel : public QObject
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
Q_PROPERTY(QString pImageSource READ getImageSource NOTIFY imageSourceChanged)
|
Q_PROPERTY(QString pImageSource READ getImageSource NOTIFY imageSourceChanged)
|
||||||
|
Q_PROPERTY(bool pIsCircleDelegate READ isCircleDelegate NOTIFY isCircleDelegateChanged)
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
|
void isCircleDelegateChanged();
|
||||||
void imageSourceChanged();
|
void imageSourceChanged();
|
||||||
void clicked();
|
void clicked();
|
||||||
|
|
||||||
|
|
@ -21,6 +23,9 @@ public:
|
||||||
QString getPath() const;
|
QString getPath() const;
|
||||||
bool setPath(const QString & path);
|
bool setPath(const QString & path);
|
||||||
|
|
||||||
|
bool isCircleDelegate() const;
|
||||||
|
void setCircleDelegate(bool value);
|
||||||
|
|
||||||
NavigationItemModel* getParentItem();
|
NavigationItemModel* getParentItem();
|
||||||
QList<NavigationItemModel*> getChildren();
|
QList<NavigationItemModel*> getChildren();
|
||||||
|
|
||||||
|
|
@ -32,6 +37,7 @@ public:
|
||||||
private:
|
private:
|
||||||
QString mPath = QString("");
|
QString mPath = QString("");
|
||||||
QString mImageSource;
|
QString mImageSource;
|
||||||
|
bool mIsCircleDelegate = false;
|
||||||
|
|
||||||
QList<NavigationItemModel*> mChildren = QList<NavigationItemModel*>();
|
QList<NavigationItemModel*> mChildren = QList<NavigationItemModel*>();
|
||||||
NavigationItemModel* mParentItem = nullptr;
|
NavigationItemModel* mParentItem = nullptr;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue