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. New to the forum? Please visit the ‘Getting Started’ link below.
inside custom component

Cascades Development

Reply
Contributor
oddboy
Posts: 31
Registered: ‎05-24-2011
My Carrier: rogers
Accepted Solution

listItemComponent , GroupDataModel and a C++ object

i have a class that returns information about the a set of items.

 
it has 3 Q_PROPERTY's that return a GroupDataModel of QObject* pointers.
 
the QObject returned in the GroupDataModel is simple.  Constructor takes a QString and a bool, properties return them.  For example:
 
foo bar = new foo("item1", true);

QString myText = bar.text;  //myText = "item1"
bool myBool = bar.active;    // myBool = true


 

 
The Q_PROPERTY's are attached to ListView's in QML.
 
the listItemComponent looks like this:
 
listItemComponents: [
                              ListItemComponent {
                                  type: "item"
                                  Container {
                                      layout: StackLayout { orientation : LayoutOrientation.LeftToRight }
                                      ImageView {
                                       preferredWidth: 40
                                       scalingMethod: ScalingMethod.AspectFit
                                       verticalAlignment: VerticalAlignment.Bottom
                                          imageSource: {
                                              if (ListItemData.active) { imageSource = "asset:///images/on.png" ; }
                                              else { imageSource = "asset:///images/off.png" ; }
                                          }
                                      }
                                      Label {
                                          text: ListItemData.text
                                      }
                                      Label {
                                           text: "(" + ListItemData.active + ")"   
                                      }
                                  }
                              }
                          ]

 

 
what's weird is that the Label that displays ListItemData.active (a bool) is always correct.  if the item in question is active (active=true), then the Label displays "true".  likewise if it's disabled (active = false, and the Label displays "false").
 
However the image source is all messed up.  It seems like my if/else - which will display one imageSource if ListItemData.active = true, and a different image if ListItemData.active = false) isn't working, but i can't figure out why.
 
for instance, i might see something like this:
 
-when the app first loads, the display is correct.  the default is to display everything with .active=true and show the "on.png" in the ListView.
-when i unfilter the list to show all items (whether active=true or active=false), then 
--the ImageView might show the on.png, or might show the off.png regardless of the value of ListItemData.active.
--the Label always shows the correct value.
 
Why doesn't my if/else statement work correctly, and why does the ImageView not seem to care above the value of ListItemData.active?
 
Thanks!
 
oddboy
 
Please use plain text.
Developer
Curahee
Posts: 122
Registered: ‎01-12-2013
My Carrier: -

Re: listItemComponent , GroupDataModel and a C++ object

You have imageSource 2 times. One outside the if, one inside the if.

 

imageSource: {
                                              if (ListItemData.active) { imageSource = "asset:///images/on.png" ; }
                                              else { imageSource = "asset:///images/off.png" ; }
                                          }

Try the next line

 

imageSource: "asset:///images/" + (ListItemData.active?"on":"off") + ".png"

 It's a bit shorter and it works for me.

______________________________________________________
Voetbal afgelast in België? Check at AppWorld
Please use plain text.
Developer
laurentC
Posts: 223
Registered: ‎02-05-2010
My Carrier: Bouygues Telecom

Re: listItemComponent , GroupDataModel and a C++ object

I think you can't use if else statement. Try the code below instead :

imageSource: ListItemData.active ? "asset:///images/on.png" : "asset:///images/off.png"

Twitter : @LaurentKP
My apps
Please use plain text.
Developer
Curahee
Posts: 122
Registered: ‎01-12-2013
My Carrier: -

Re: listItemComponent , GroupDataModel and a C++ object

I allready replied to that with the same solution :smileywink:.

______________________________________________________
Voetbal afgelast in België? Check at AppWorld
Please use plain text.
Developer
laurentC
Posts: 223
Registered: ‎02-05-2010
My Carrier: Bouygues Telecom

Re: listItemComponent , GroupDataModel and a C++ object

Oops sorry you're right !
Twitter : @LaurentKP
My apps
Please use plain text.