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


Thank you for visiting the BlackBerry Support Community Forums.

BlackBerry will be closing the BlackBerry Support Community Forums Device Forums on April 1st (Developers, see below)

BlackBerry remains committed to providing excellent customer support to our customers. We are delighted to direct you to the CrackBerry Forums, a well-established and thorough support channel, for continued BlackBerry support. Please visit http://forums.crackberry.com or http://crackberry.com/ask. You can also continue to visit BlackBerry Support or the BlackBerry Knowledge Base for official support options available for your BlackBerry Smartphone.

"When we launched CrackBerry.com 10 years ago, we set out to make it a fun and useful destination where BlackBerry Smartphone owners could share their excitement and learn to unleash the full potential of their BlackBerry. A decade later, the CrackBerry community is as active and passionate as ever and I know our knowledgeable members and volunteers will be excited to welcome and assist more BlackBerry owners with their questions."

- Kevin Michaluk, Founder, CrackBerry.com

Developers, for more information about the BlackBerry Developer Community please review Join the Conversation on the BlackBerry Developer Community Forums found on Inside BlackBerry.


Reply
New Developer
Posts: 92
Registered: ‎01-23-2009
My Device: Z10
My Carrier: klarmobil

Update Sorting in ListView

I have a ListView with a GroupDataModel (list_items) which sorts the items by one property like this:

 

this->list_items->setSortingKeys(QStringList("SequenceNumber"));

 I want to be able to move some items up and down the list by updating their sequence number. I have defined the property like this:

 

int sequence_number;											
Q_PROPERTY(int SequenceNumber READ getSequenceNumber NOTIFY onSequenceNumberChanged FINAL);

 where I emit the signal on sequence number update.

 

However something is missing, my list stays unchanged. Can someone help?

Retired
Posts: 418
Registered: ‎07-18-2012
My Device: Q10
My Carrier: Bell Canada

Re: Update Sorting in ListView

[ Edited ]

I think you'll have to do a remove/insert to make the model aware of the change.

 

Alternately - and less efficiently - you could conncet your sequence changed signal to a slot which changes and reverts the sorting order.

 

 

--
Rob is no longer associated with BlackBerry.
New Developer
Posts: 92
Registered: ‎01-23-2009
My Device: Z10
My Carrier: klarmobil

Re: Update Sorting in ListView

Well remove/insert does not work if the event originates from the affected item rows.
Retired
Posts: 418
Registered: ‎07-18-2012
My Device: Q10
My Carrier: Bell Canada

Re: Update Sorting in ListView

[ Edited ]

Hi,

 

I've just built a test to see if I can reproduce this - and it worked for me...

 

Tested on 10.2.0.1743 (Z10)

 

I have an Item that looks like this;

class Item: public QObject {
Q_OBJECT
public:
	Item(QObject * owner = NULL) : QObject(owner), _sequenceNumber(0) {
	}
	virtual ~Item() { }

	Q_PROPERTY(QString name READ name WRITE setName NOTIFY nameChanged);
	Q_INVOKABLE QString name() {
		return _name;
	}
	Q_INVOKABLE void setName(const QString & name) {
		if (_name!=name) {
			_name = name;
			emit nameChanged(name);
		}
	}

	Q_PROPERTY(int sequenceNumber READ sequenceNumber WRITE setSequenceNumber NOTIFY sequenceNumberChanged);
	Q_INVOKABLE int sequenceNumber() {
		return _sequenceNumber;
	}
	Q_INVOKABLE void setSequenceNumber(int sequenceNumber) {
		if (_sequenceNumber!=sequenceNumber) {
			_sequenceNumber = sequenceNumber;
			emit sequenceNumberChanged(sequenceNumber);
		}
	}

signals:
	void nameChanged(QString);
	void sequenceNumberChanged(int);

private:
	QString _name;
	int _sequenceNumber;
};

 Created my data model like this:

	ListView * lv = root->findChild<ListView*>("listView");

	GroupDataModel * gdm = new GroupDataModel(this);

	gdm->setSortingKeys(QStringList() << "sequenceNumber");

	for (int i = 0; i < 10; ++i) {
		Item * next = new Item(this);

		next->setName(QString("Dude %1").arg(i));
		next->setSequenceNumber(rand() % 20);

		items << next;
		gdm->insert(next);
	}

	lv->setDataModel(gdm);

 Added a timer, and tampered with the sequence numbers like this:

void ApplicationUI::onTick() {
	int which = rand() % items.size();
	items[which]->setSequenceNumber(
			items[which]->sequenceNumber() + (rand() % 10 - 8));
}

 Used this QML:

import bb.cascades 1.2

Page {
    Container {
        //Todo: fill me with QML
        ListView {
            objectName: "listView"
            listItemComponents: [
                ListItemComponent {
                    type: "item"
                    content: Container {
                        Label {
                            text: ListItemData.name + "  [" + ListItemData.sequenceNumber + "]"
                        }
                    }
                }
            ]
        }
    }
}

 Can you provide more code?

 

Thanks!

 

 

--
Rob is no longer associated with BlackBerry.
Highlighted
New Developer
Posts: 92
Registered: ‎01-23-2009
My Device: Z10
My Carrier: klarmobil

Re: Update Sorting in ListView

It works for me now too. After some further experiments it suddenly started to work. Though now happy with it I still don't know what the problem originally was.