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
New Developer
djhaggarty
Posts: 10
Registered: ‎03-05-2011
My Device: z10, PlayBook

how can I use a single datamodel to feed a listview, dynamic dropdowns and pickers

I am creating a database app, which is based on the sample quotes app. My sql database  now has data stored in several tables and I have used the groupdatamodel to store and sort all the data I need and it nicely presents some of the data I need in a listview.

 

Now I want to insert new data or modify  data using dynamic dropdowns or pickers, which will get their data selections  from the Listviews groupdatamodel (as I dont really want to have seperate models for each dropdown or picker).

 

My problems are:

1. how do I link say a picker to the groupdatamodel xml file? When I try to link to the model, I get the picker displayed but with no data in the columns. No reported errors. (see below)

 

Container { // dynamic picker
Picker {
id: dynamic
property string myValue: "choose"
title: "apiaryselect"
description: dynamic.myValue

dataModel: XmlDataModel {
source: "asset:///models/apiary.xml"        // this is my groupdatamodel
}// end of dataModel

pickerItemComponents: [
PickerItemComponent {
type: "itemmonth"


Container {
layout: StackLayout {
orientation: LayoutOrientation.LeftToRight
}


Label {
text: pickerItemData.displayname
}
}
}

]

2. Part of my problem is that I cant see the groupdatamodel file - Ive tried searching for it using the Target File System, but it only shows the initial model before its updated with search data. I guess my knowledge of the debugger is limited but can you view a model in the console.log()?.

So where is the GroupDataModel with all the sorted data?? I know sql database needs to be moved to the data directory for read/write access and I can find that ok in the target file system data directory, but I dont know about the xml file. I would ideally like to display the xml file so that I can see it change during debug, but dont know where to locate it.

The GroupDataModel CustomSqlDataSource query comprises the join of three tables from the database so I know the model is pretty big with around 30 columns. Thats why I am keen to see it so that I can check that I am referencing the type: and label: inputs to the picker correctly.

 

In summary, all the data I need can be extracted from the sql database and sorted in the groupdatamodel. I would rather pick off the data I need for dropdowns and pickers from it rather than making repeated calls to the sql, which I guess would slow things down. Am I going about all this the right way?

 

Please use plain text.
Administrator
MSohm
Posts: 14,554
Registered: ‎07-09-2008
My Device: BlackBerry Z30, BlackBerry PlayBook

Re: how can I use a single datamodel to feed a listview, dynamic dropdowns and pickers

Is the XML file you are trying to reference bundled with the application or created during runtime?  Is the GroupDataModel created from reading the XML file or are you feeding data from your SQL database into a GroupDataModel (and then you are looking for an XML file)?

 

If the XML is bundled with the assets for your application you can reference it with a path relative from the location of the QML file with the DropDown.

 

Exampl of QML file in root and myData.xml located in an xml directory in the assets folder.

 

source: "xml/myData.xml"

 

Note that you can't write to the app or assets folder during runtime.

Mark Sohm
BlackBerry Development Advisor

Please refrain from posting new questions in solved threads.
Problem solved? Click the Accept As Solution button.
Found a bug? Report it using Issue Tracker
Please use plain text.
New Developer
djhaggarty
Posts: 10
Registered: ‎03-05-2011
My Device: z10, PlayBook

Re: how can I use a single datamodel to feed a listview, dynamic dropdowns and pickers

Hello Mark

 

I hadn't realised untill now that the model was created at runtime in the quotes example!   I see now that I am feeding data from the sql database into the groupdatamodel, so I guess I am looking for the groupdatamodel file which I'm assuming is an xml file.

So the question is where is that data and how can I call it from other qml files?

 

My listview has 

 

attachedObjects: [

// see ApiaryModel.qml for set up of the GroupDataModel

ApiaryModel {

  Id: apiarymodel

 { ·······

 }

CustomSqlDataSource {

 Id:asyncDataSource

Source: “sql/apiarymodel.db

Query:”·······“

 

The listview works fine so I know the data is there, but I just can't get at it.

 

As you have correctly advised,I have been able to reference an xml file in a dropdown without a problem, so I just need an xml file full of my groupdatamodel data!

 

Please use plain text.
Administrator
MSohm
Posts: 14,554
Registered: ‎07-09-2008
My Device: BlackBerry Z30, BlackBerry PlayBook

Re: how can I use a single datamodel to feed a listview, dynamic dropdowns and pickers

The data for the GroupDataModel is stored in memory, not an XML file.

 

What about going the other direction?  Use the results from your SQL query to build and save an XML file.  Then use the xmls file using the XmlDataModel for each component.

Mark Sohm
BlackBerry Development Advisor

Please refrain from posting new questions in solved threads.
Problem solved? Click the Accept As Solution button.
Found a bug? Report it using Issue Tracker
Please use plain text.
New Developer
djhaggarty
Posts: 10
Registered: ‎03-05-2011
My Device: z10, PlayBook

Re: how can I use a single datamodel to feed a listview, dynamic dropdowns and pickers

Thanks for the clarification regarding the datamodel being in RAM.

I am struggling to find out how to convert a sql query result into a xml file, is there a sqlite query that does this or some other qml / c++ function that I should investigate?

 

Please use plain text.