Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Native Development

Reply
Contributor
Posts: 38
Registered: ‎09-06-2013
My Device: BlackBerry Z10
My Carrier: Claro
Accepted Solution

Programmatic XmlDataModel

Hello guys, my idea is to list some images saved on the device over a ListView.

 

For now I can use the QDir::entryList method in order to get the list of images inside a QStringList, I can also build the model.xml file in a "/shared/misc/model" folder but I cannot access it from QML since the "source:" parameter (I guess) reads only the "assets" folder files looking for the custom .xml. 

 

Now as it is a custom model (deppending on which files the user has on the folder) I would like to access it somehow from QML to load it into a ListView.

 

As for now I can create the xml file with 

QFile newFile("accounts/1000/shared/misc/customphotos/modelphotos.xml");

 and it's created OK, now how can I access it?

 

Thanks



_______________________________________________________
If you've been helped click on Like Button, if you've been saved download the app.

Developer of Easy Memes
Developer
Posts: 6,152
Registered: ‎07-05-2012
My Device: Playbook, Dev Alpha C, Z10 LE, Z30
My Carrier: Orange

Re: Programmatic XmlDataModel

If you don't need to share the xml file then store it internal to your app in the data folder.

And source: can take any valid accessible path including the data folder.


If you've been helped click on Like Button, if you've been saved buy the app. :smileyhappy:

Developer of stokLocker, Sympatico and Super Sentences.
Contributor
Posts: 38
Registered: ‎09-06-2013
My Device: BlackBerry Z10
My Carrier: Claro

Re: Programmatic XmlDataModel

Hello, Thanks for your reply...  I got to solve it. Now I have this problem

When the app is listing the items, I can't use the full address to the files i.e.

listItemComponents: 
                [
                    ListItemComponent 
                    {
                        type: "item"
                        ImageView 
                        {
                            imageSource: _dirPaths.em+ListItemData.image
                        }    
                    }
                ]   

 I get the error 

ReferenceError: Can't find variable: _dirPaths

 



_______________________________________________________
If you've been helped click on Like Button, if you've been saved download the app.

Developer of Easy Memes
Developer
Posts: 6,152
Registered: ‎07-05-2012
My Device: Playbook, Dev Alpha C, Z10 LE, Z30
My Carrier: Orange

Re: Programmatic XmlDataModel

Did you get this from a previous piece of code I posted?

 

You need to set and declare _dirPaths within your applicationUI...

 

    // Retrieve the path to the app's working directory for sharing in QML
    QString appDir = QDir::currentPath();
    QDeclarativePropertyMap* dirPaths = new QDeclarativePropertyMap;
    dirPaths->insert("assets", QVariant(QString("file://" + appDir + "/app/native/assets/")));

    QmlDocument *qml = QmlDocument::create("asset:///main.qml")
		.parent(this)
		.property("_dirPaths", dirPaths);

 

 


If you've been helped click on Like Button, if you've been saved buy the app. :smileyhappy:

Developer of stokLocker, Sympatico and Super Sentences.
Contributor
Posts: 38
Registered: ‎09-06-2013
My Device: BlackBerry Z10
My Carrier: Claro

Re: Programmatic XmlDataModel

Well, it's the code from an example. The strange thing is that it appears to be working for the source of the XmlDataModel but not for the imageSource as it reads every item on the .xml file... here is my code 

 

import bb.cascades 1.0

Page {
    
    Container
    {  
        ScrollView 
        {
         	ListView 
            {
                maxHeight: 1200
                dataModel: XmlDataModel 
                {
                    source:  _dirPaths.emmod + "modelimages.xml"   
                
                }
                
                
                layout: GridListLayout 
                {
                    columnCount: 3
                }
                listItemComponents: 
                [
                    ListItemComponent 
                    {
                        type: "item"
                        ImageView 
                        {
                           
                            imageSource: _dirPaths.em+ListItemData.image
                        }    
                    }
                ]   
                
            }//cierra listview
        }//cierra scrollview 
    }//cierra container
}

 



_______________________________________________________
If you've been helped click on Like Button, if you've been saved download the app.

Developer of Easy Memes
Developer
Posts: 6,152
Registered: ‎07-05-2012
My Device: Playbook, Dev Alpha C, Z10 LE, Z30
My Carrier: Orange

Re: Programmatic XmlDataModel

You know they are different right?
One is accessing the element em and the other emmod.

Post where you declare this in applicationui.cpp if you are still stuck after reading the above.

If you've been helped click on Like Button, if you've been saved buy the app. :smileyhappy:

Developer of stokLocker, Sympatico and Super Sentences.
Contributor
Posts: 38
Registered: ‎09-06-2013
My Device: BlackBerry Z10
My Carrier: Claro

Re: Programmatic XmlDataModel

this is in my main function on main.cpp  

 

// Build the path, add it as a context property,
        // and expose it to QML
        QVariantMap dirPaths;
        dirPaths["camera"] = QString::fromLatin1("file://%1/shared/camera/").arg(workDir);
        dirPaths["files"] = QString::fromLatin1("file://%1/shared/photos/").arg(workDir);
        dirPaths["asset"] = QString::fromLatin1("file://%1/app/native/assets/").arg(workDir);
        dirPaths["em"] = QString::fromLatin1("file://%1/shared/misc/easymemes/").arg(workDir);//photos
        dirPaths["emmod"] = QString::fromLatin1("file://%1/shared/misc/easymemes/mod/").arg(workDir);//model

        qml->documentContext()->setContextProperty("_dirPaths", dirPaths);

        AbstractPane *root = qml->createRootObject<AbstractPane>();
        app.setScene(root);

 



_______________________________________________________
If you've been helped click on Like Button, if you've been saved download the app.

Developer of Easy Memes
Developer
Posts: 1,523
Registered: ‎12-18-2012
My Device: Z30, Z10 LE, DevAlpha C, PlayBook

Re: Programmatic XmlDataModel

That's ListView visibility issue. ListItemComponents have different context. A workaround:

 

import bb.cascades 1.0

Page {
    
    Container
    {  
        ScrollView 
        {
         	ListView 
            {
                function getDirPaths() {
                  return _dirPaths
                }

                maxHeight: 1200
                dataModel: XmlDataModel 
                {
                    source:  _dirPaths.emmod + "modelimages.xml"   
                
                }
                
                
                layout: GridListLayout 
                {
                    columnCount: 3
                }
                listItemComponents: 
                [
                    ListItemComponent 
                    {
                        type: "item"
                        ImageView 
                        {
                           
                            imageSource: ListItem.view.getDirPaths().em + ListItemData.image
                        }    
                    }
                ]   
                
            }//cierra listview
        }//cierra scrollview 
    }//cierra container
}

 


Andrey Fidrya, @zmeyc on twitter
Contributor
Posts: 38
Registered: ‎09-06-2013
My Device: BlackBerry Z10
My Carrier: Claro

Re: Programmatic XmlDataModel

Thank you! that was the issue. 

Like :Clap:



_______________________________________________________
If you've been helped click on Like Button, if you've been saved download the app.

Developer of Easy Memes