Results 1 to 7 of 7

Thread: PhotoAlbumViewer - Prevent Data Duplication

  1. #1
    Join Date
    Nov 2015
    Posts
    8
    Qt products
    Qt5
    Platforms
    Unix/X11

    Default PhotoAlbumViewer - Prevent Data Duplication

    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
    Qt Code:
    1. ListModel{
    2. id: photosModel
    3. }
    4. // File dialog for selecting image file from local file system
    5. FileDialog {
    6. id: fileDialog
    7. title: "Choose a folder"
    8. nameFilters: [ "Image files (*.png *.jpg *.jpeg)"]
    9. selectFolder: true
    10. onAccepted: {
    11. mainWindow.editMode = false
    12. photosModel.append({folder: fileDialog.folder + "/"})
    13. }
    14. }
    15.  
    16. function getFolderUrl(){
    17. return fileDialog.fileUrl + "/"
    18. }
    19.  
    20. DelegateModel { id: albumVisualModel; model: photosModel; delegate: AlbumDelegate {} }
    21.  
    22. GridView {
    23. id: albumView; width: parent.width; height: parent.height; cellWidth: 210; cellHeight: 220
    24. model: albumVisualModel.parts.album; visible: albumsShade.opacity != 1.0
    25. }
    To copy to clipboard, switch view to plain text mode 
    AlbumDelegate.qml
    Qt Code:
    1. Item {
    2. Package.name: 'album'
    3. id: albumWrapper; width: 210; height: 220
    4.  
    5. DelegateModel {
    6. id: visualModel; delegate: ImageDelegate { }
    7. model: FilesModel { id: rssModel; folder: mainWindow.getFolderUrl()}
    8. }
    9. ....
    10. }
    To copy to clipboard, switch view to plain text mode 
    Qt Code:
    1. ImageDelegate.qml
    2. .....
    3. Image {
    4. id: originalImage; antialiasing: true; asynchronous: true
    5. source: "image://provider/"+ rssModel.folder +fileName;cache: false;
    6. fillMode: Image.PreserveAspectFit; width: photoWrapper.width; height: photoWrapper.height
    7. }
    8. ....
    9. }
    To copy to clipboard, switch view to plain text mode 
    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 ?
    Last edited by anda_skoa; 12th November 2015 at 08:11. Reason: missing [code] tags

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: PhotoAlbumViewer - Prevent Data Duplication

    You are always refering to the same folder, i.e. mainWindow.getFolderUrl() is used for every instance of FilesModel.

    Cheers,
    _

  3. #3
    Join Date
    Nov 2015
    Posts
    8
    Qt products
    Qt5
    Platforms
    Unix/X11

    Default Re: PhotoAlbumViewer - Prevent Data Duplication

    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

  4. #4
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: PhotoAlbumViewer - Prevent Data Duplication

    Quote Originally Posted by aIsmail View Post
    I tried to make something like that
    Qt Code:
    1. function getFolderUrl(index){
    2. return photosModel.get(index).folder
    3. }
    To copy to clipboard, switch view to plain text mode 
    Any reason for not using the data provided by the model?

    Quote Originally Posted by aIsmail View Post
    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,
    _

  5. #5
    Join Date
    Nov 2015
    Posts
    8
    Qt products
    Qt5
    Platforms
    Unix/X11

    Default Re: PhotoAlbumViewer - Prevent Data Duplication

    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.

  6. #6
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: PhotoAlbumViewer - Prevent Data Duplication

    Quote Originally Posted by aIsmail View Post
    That's actually what I'm doing
    Nope.
    Qt Code:
    1. DelegateModel { id: albumVisualModel; model: photosModel; delegate: AlbumDelegate {} }
    To copy to clipboard, switch view to plain text mode 
    No reference to the model's data inside AlbumDelegate.

    If we assume that AlbumDelegate has a "folder" property
    Qt Code:
    1. DelegateModel { id: albumVisualModel; model: photosModel; delegate: AlbumDelegate { folder: model.folder } }
    To copy to clipboard, switch view to plain text mode 

    Cheers,
    _

  7. #7
    Join Date
    Nov 2015
    Posts
    8
    Qt products
    Qt5
    Platforms
    Unix/X11

    Default Re: PhotoAlbumViewer - Prevent Data Duplication

    Thank You, it's working now, I do appreciate your help

Similar Threads

  1. prevent Window Moving?
    By maybnxtseasn in forum Qt Programming
    Replies: 13
    Last Post: 12th March 2012, 16:40
  2. prevent drop in QTreeWidget
    By GrahamLabdon in forum Newbie
    Replies: 1
    Last Post: 27th May 2011, 20:24
  3. Replies: 1
    Last Post: 17th August 2010, 02:19
  4. How to prevent QListWidget from itemdragging
    By Arthur in forum Qt Programming
    Replies: 6
    Last Post: 17th April 2006, 21:41
  5. Prevent from resizing a QMainWindow
    By Flier in forum Qt Tools
    Replies: 5
    Last Post: 14th April 2006, 17:11

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.