PDA

View Full Version : PhotoAlbumViewer - Prevent Data Duplication



aIsmail
12th November 2015, 08:29
I was extending one of qt examples, it's simply loading images from local disk, then show them in albums view ..
I make something like this,

main.qml


ListModel{
id: photosModel
}
// File dialog for selecting image file from local file system
FileDialog {
id: fileDialog
title: "Choose a folder"
nameFilters: [ "Image files (*.png *.jpg *.jpeg)"]
selectFolder: true
onAccepted: {
mainWindow.editMode = false
photosModel.append({folder: fileDialog.folder + "/"})
}
}

function getFolderUrl(){
return fileDialog.fileUrl + "/"
}

DelegateModel { id: albumVisualModel; model: photosModel; delegate: AlbumDelegate {} }

GridView {
id: albumView; width: parent.width; height: parent.height; cellWidth: 210; cellHeight: 220
model: albumVisualModel.parts.album; visible: albumsShade.opacity != 1.0
}

AlbumDelegate.qml


Item {
Package.name: 'album'
id: albumWrapper; width: 210; height: 220

DelegateModel {
id: visualModel; delegate: ImageDelegate { }
model: FilesModel { id: rssModel; folder: mainWindow.getFolderUrl()}
}
....
}



ImageDelegate.qml
.....
Image {
id: originalImage; antialiasing: true; asynchronous: true
source: "image://provider/"+ rssModel.folder +fileName;cache: false;
fillMode: Image.PreserveAspectFit; width: photoWrapper.width; height: photoWrapper.height
}
....
}

The main problem is that when I load more than one folder I got all folders point to the same url, any help in this ?

anda_skoa
12th November 2015, 09:16
You are always refering to the same folder, i.e. mainWindow.getFolderUrl() is used for every instance of FilesModel.

Cheers,
_

aIsmail
13th November 2015, 03:08
I tried to make something like that
function getFolderUrl(index){
return photosModel.get(index).folder
}

but it failed also, what do you think ? I was thinking it's about making ListModel of FolderListModel, but is that possible ?
Thanks

anda_skoa
13th November 2015, 09:55
I tried to make something like that


function getFolderUrl(index){
return photosModel.get(index).folder
}


Any reason for not using the data provided by the model?



I was thinking it's about making ListModel of FolderListModel, but is that possible ?

Well, that would be different, right?
Your model contains a set of directories, a FolderListModel provides the content of a single directory.

Cheers,
_

aIsmail
13th November 2015, 15:10
That's actually what I'm doing, I have ListModel that contains all ULs, and passes these urls one by one to FolderListModel to get the content of this URL, but actually it always points to the same directory, which is the last added directory.
I need each object keep its url content.

anda_skoa
13th November 2015, 16:27
That's actually what I'm doing

Nope.


DelegateModel { id: albumVisualModel; model: photosModel; delegate: AlbumDelegate {} }

No reference to the model's data inside AlbumDelegate.

If we assume that AlbumDelegate has a "folder" property


DelegateModel { id: albumVisualModel; model: photosModel; delegate: AlbumDelegate { folder: model.folder } }


Cheers,
_

aIsmail
13th November 2015, 23:38
Thank You, it's working now, I do appreciate your help :D