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
Developer
Dredvard
Posts: 160
Registered: ‎01-27-2012
My Device: Playbook
My Carrier: Rogers
Accepted Solution

Subset of checked listview items

I'm having trouble accessing information from my listview from cpp.  Here is my listivew.

 

ListView {
    id: animList
    objectName: "animList"
    dataModel: XmlDataModel {
        source: "models/anims.xml"
    }
    listItemComponents: [
        ListItemComponent {
            type: "listItem"
            AnimItem {
            }
        }
    ]
}

 It uses a cutom item

 

Container {
    property alias checked: animCheckBox.checked
    //    property alias title:  ListItemData.title
    id: toplvl
    layout: StackLayout {
        layoutDirection: LayoutDirection.TopToBottom
    }
    onTouch: {
        if (event.isDown()) {
            checked = ! checked
        }
    }
    Container {
        id: animContainer
        layout: StackLayout {
            layoutDirection: LayoutDirection.LeftToRight
        }
        CheckBox {
            id: animCheckBox
            layoutProperties: DockLayoutProperties {
                verticalAlignment: VerticalAlignment.Center
                horizontalAlignment: HorizontalAlignment.Left
            }
            checked: true
            Label {
                id: animLabels
                text: ListItemData.title
                layoutProperties: DockLayoutProperties {
                    verticalAlignment: VerticalAlignment.Center
                    horizontalAlignment: HorizontalAlignment.Right
                }
            }
        }
    }
    Divider {
    }
}

in cpp

    mAnimListView = mNavPane->findChild<ListView*>("animList");
    XmlDataModel * xmdm = (XmlDataModel*) mAnimListView->dataModel();

  How do I parse through the list in cpp to create a sublist of all checked items ?  I'm not certain how to parse through an entire datamodel from cpp. 

 

---
If you find my post helpful please "like" it and "accept as a solution"
Please use plain text.
Developer
raj_jyani
Posts: 107
Registered: ‎05-11-2011
My Device: BlackBerry Z10 LE
My Carrier: AirTel

Re: Subset of checked listview items

Hi,

 

I have alternate way for do this.

 

1. You have to use GroupDataModel

2. manually pharse XML and add data to GroupDataModel

3. add one extra data field to GroupDataModel for store state of checkbox

4. Iterate all row from cpp code and check weather state is checked or not.

 

Some code for done this task

For Parse XML

 

http://supportforums.blackberry.com/t5/Cascades-Development/How-to-create-a-listview-using-xmldatamo...

 

For update state in qml

 

 onTriggered: {
                var selectedItem = dataModel.data(indexPath);
                btn.text = selectedItem.firstname;
                selectedItem.firstname = "test";
                listView.dataModel.updateItem(indexPath, selectedItem)
            }

 updateItem() method only works on groupDatamodel

 

For Iterate all row of datamodel in CPP

 

GroupDataModel *model = (GroupDataModel *) listView->dataModel();

	int len = model->childCount(listView->rootIndexPath());
	QVariantList qlist;
	for (int i = 0; i < len; i++) {
		qlist.append(QVariant(i));
		qDebug() << " Data : " << model->data(qlist);
		qlist.clear();
	}

 

hope this code help you

 

 

 

Please use plain text.
Developer
Dredvard
Posts: 160
Registered: ‎01-27-2012
My Device: Playbook
My Carrier: Rogers

Re: Subset of checked listview items

Thanks.  I'll give this a try.  The more I read, it seems that XmlDataModel seems only good for making things look pretty to start.  Not much else.

 

I might try this using a QlistDataModel and replace (int i, const Item &value). 

 

Which is more appropriate - QlistDataModel or GroupDataModel?   Don't have a clear understanding of when to use each.  This is a flat list so I don't have any headers.

 

 

 

 
---
If you find my post helpful please "like" it and "accept as a solution"
Please use plain text.
BlackBerry Development Advisor (Retired)
gperry
Posts: 138
Registered: ‎05-11-2012
My Device: Developer
My Carrier: Developer

Re: Subset of checked listview items

http://supportforums.blackberry.com/t5/Cascades-Development-Knowledge/Using-a-Custom-DataModel-to-Fi...

 

Might be worthwhile looking at this Knowledge Base Article 

 

Regards

Graham

Please use plain text.
BlackBerry Development Advisor (Retired)
gperry
Posts: 138
Registered: ‎05-11-2012
My Device: Developer
My Carrier: Developer

Re: Subset of checked listview items

Have you made any progress on this issue?

 

Graham

Please use plain text.
Developer
Dredvard
Posts: 160
Registered: ‎01-27-2012
My Device: Playbook
My Carrier: Rogers

Re: Subset of checked listview items

Yes.  I ended up implementing a qlistmodel.

 

{
	QVariantListDataModel * animdatamodel =
			(QVariantListDataModel *) mAnimListView->dataModel();
	mEnterAnimPlaylist.clear();
	mExitAnimPlaylist.clear();
	QStringList mEnterlist,mExitlist;
	for (i=0;i<animdatamodel->size();i++) {
		QVariantMap qvm = animdatamodel->value(i).toMap();
		if (qvm.value("checked").toBool() == true) {
			if (qvm.value("animtype").toString().compare("enter") == 0) {
				mEnterlist << qvm.value("title").toString();
				mEnterAnimPlaylist.append(qvm);
			} else {
				mExitlist << qvm.value("title").toString();
				mExitAnimPlaylist.append(qvm);
			}
		}
	}
}

 

---
If you find my post helpful please "like" it and "accept as a solution"
Please use plain text.