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
Highlighted
Developer
Posts: 92
Registered: ‎08-01-2013
My Device: Z10, Q5, Q10
My Carrier: Vodaphone
Accepted Solution

List View in C++

Hi All,

 

I need to create a List View with 2 levels.

like with a header that says TODAY, YESTERDAY etc..

and items received on those days inside those headers.

please find the attached image as an example.

 

I went through all the documentation and examples available; but all of which is in QML.

i need a pure C++ example.

 

I have implemented a single level list view subclassing ListItemProvider etc.

but i have no clue about a 2 level list in c++.

Please could somebody point me to some example or sample that is in c++ for a 2 level list view?

 

Please Help!!

 

Regards.

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

Re: List View in C++

I think you are looking for a GroupDataModel, there is QML and C++ examples in the documentation...

 

http://developer.blackberry.com/native/reference/cascades/bb__cascades__groupdatamodel.html


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

Developer of stokLocker, Sympatico and Super Sentences.
Developer
Posts: 92
Registered: ‎08-01-2013
My Device: Z10, Q5, Q10
My Carrier: Vodaphone

Re: List View in C++

Great! skipped reading that, but i want the list to be somewhat like :

 

- Green
        - Cucumber
        - Peas
        - Salad
    - Red
        - Tomato
        - Red Radish
        - Carrot
    - Yellow
        - Corn
        - Paprika

so do i need to subclass DataModel class?

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

Re: List View in C++

Not really unless you need filtering or customisation of the look, if not the GroupDataModel is exactly what you need in this case.

If you need to customise in some way then you can subclass it similar to the way the sample you got that List from does.

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

Developer of stokLocker, Sympatico and Super Sentences.
Developer
Posts: 92
Registered: ‎08-01-2013
My Device: Z10, Q5, Q10
My Carrier: Vodaphone

Re: List View in C++

[ Edited ]

How will i append data to my Model?

i mean i have created simple lists several times and what i do there is read data from the database, create a QList<CustomItems> from the same and append it to QListDataModel.

 

It is simple enough because there is only one type of item.

Now i have a header and list items into the header, so how m i supposed to append both to the list model.

This is what i did in simple list to load data&colon;

 

void ListScreen::loadData()

{

 

qDebug() << " load data " ;
CardDao cardDao ;

 

// get all Card Data from database
QList<CardData> qlListData = cardDao .allListData() ;

 

// clear previous list.
_ldmListViewModel->clear() ;

 

if(!(qlCardDataList.isEmpty()))
{
     // add new list in data model
    _ldmListViewModel->append(qlListData ) ;
}
else 
    qDebug() << " error loading data " ;
}

 

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

Re: List View in C++

You need to define two different item types in your ListView.

 

Something similar to...

 

listItemComponents: [
    ListItemComponent {
        type: "header"
		            
        Header {
            title: {
                ListItemData.color
            }
        }
    },
    ListItemComponent {
        StandardListItem {
            title: ListItemData.vegatable
            description: ListItemData.desc
        }
    }
}

 


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

Developer of stokLocker, Sympatico and Super Sentences.
Developer
Posts: 6,152
Registered: ‎07-05-2012
My Device: Playbook, Dev Alpha C, Z10 LE, Z30
My Carrier: Orange

Re: List View in C++

Please use the 'Insert Code' button when including code in your posting, this is the clipboard icon with a 'C' in it. This way your code will be easier to read and likely to get a better response.


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

Developer of stokLocker, Sympatico and Super Sentences.
Developer
Posts: 92
Registered: ‎08-01-2013
My Device: Z10, Q5, Q10
My Carrier: Vodaphone

Re: List View in C++

I know i'll have to use ListItemComponent that way, or better still ListItemProvider, i'm doing it in C++

 

class GroupListItemManager : public ListItemProvider
{
public:
    VisualNode * createItem(ListView* list, QString type)
    {
        Q_UNUSED(list);
 
        if (type.compare(GroupDataModel::Header) == 0) {
            return new Header();
        } else {
            return new StandardListItem();
        }
    }
 
    void updateItem(ListView* list, VisualNode *control, QString type,
        QVariantList indexPath, QVariant data)
    {
        Q_UNUSED(list);
        Q_UNUSED(indexPath);
 
        if (type.compare(GroupDataModel::Header) == 0) {
            QString caption = data.value<QString>();
            static_cast<Header*>(control)->setTitle(caption);
        } else {
            QVariantMap map = data.value<QVariantMap>();
            static_cast<StandardListItem*>(control)->setTitle(QString("%1, %2").arg(
                map["country"].toString(), map["continent"].toString()));
        }
    }
};

 

But for ListItemProvider to come into action i'll need to append/insert something to my data model..

How m i to append/insert Header/StandardListItem in the Model??

 

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

Re: List View in C++

You would need to write back to the database.


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

Developer of stokLocker, Sympatico and Super Sentences.
Developer
Posts: 6,152
Registered: ‎07-05-2012
My Device: Playbook, Dev Alpha C, Z10 LE, Z30
My Carrier: Orange

Re: List View in C++

Look at the Database CRUD example in samples for one way of doing this.


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

Developer of stokLocker, Sympatico and Super Sentences.