how to retrieve list element
-
Hi all -
This one's a little complicated; I've simplified the code as much as possible.
I have a list of zones; each zone has its own list of equipment. I'm trying to retrieve the equipment list using a model, based on the currently selected zone in the zone list, then retrieving each equipment item using a delegate.
Where I'm stuck is how to code the retrieval of the equipment list element. Here's my code:
class EquipmentItem { Q_GADGET Q_PROPERTY(QString name MEMBER m_name) QString m_name; public: Q_INVOKABLE QString name() const { return m_name; } } typedef QList<QUuid> ZoneEquipmentList; class Zone { Q_GADGET ZoneEquipmentList m_equipmentList; public: Q_PROPERTY(ZoneEquipmentList equipmentList MEMBER m_equipmentList) ZoneEquipmentList equipmentList() const { return m_equipmentList; } } class ZoneModel: public QAbstractListModel { Q_OBJECT private: ZoneList *m_list; public: Q_INVOKABLE Zone getZone(int index) { Zone z = Zone(); if (m_list->size() >= index + 1) { z = m_list->getItem(index); } return z; } } GridView { id: equipmentView model: zoneModel.getZone(zoneSelected).equipmentList delegate: Text{ id: card text: // ??? what do I do here??? } }Thanks...this one has me going cross-eyed.
EDIT: I probably should have mentioned that when I try this:
delegate: Text { text: "Equipmentscreen.qml: " + model.name }then "model.name" comes back as undefined. Could this have something to do with roles? My equipment model has them, but the individual equipment item class does not.
Thanks...
-
Hi all -
This one's a little complicated; I've simplified the code as much as possible.
I have a list of zones; each zone has its own list of equipment. I'm trying to retrieve the equipment list using a model, based on the currently selected zone in the zone list, then retrieving each equipment item using a delegate.
Where I'm stuck is how to code the retrieval of the equipment list element. Here's my code:
class EquipmentItem { Q_GADGET Q_PROPERTY(QString name MEMBER m_name) QString m_name; public: Q_INVOKABLE QString name() const { return m_name; } } typedef QList<QUuid> ZoneEquipmentList; class Zone { Q_GADGET ZoneEquipmentList m_equipmentList; public: Q_PROPERTY(ZoneEquipmentList equipmentList MEMBER m_equipmentList) ZoneEquipmentList equipmentList() const { return m_equipmentList; } } class ZoneModel: public QAbstractListModel { Q_OBJECT private: ZoneList *m_list; public: Q_INVOKABLE Zone getZone(int index) { Zone z = Zone(); if (m_list->size() >= index + 1) { z = m_list->getItem(index); } return z; } } GridView { id: equipmentView model: zoneModel.getZone(zoneSelected).equipmentList delegate: Text{ id: card text: // ??? what do I do here??? } }Thanks...this one has me going cross-eyed.
EDIT: I probably should have mentioned that when I try this:
delegate: Text { text: "Equipmentscreen.qml: " + model.name }then "model.name" comes back as undefined. Could this have something to do with roles? My equipment model has them, but the individual equipment item class does not.
Thanks...
Well, I figured out one way to do it, though I'm not at all sure it's the best way to do it.
delegate: Text { property string equipmentName: equipmentModel.getItem(model.modelData).name() text: "Equipmentscreen.qml: " + equipmentName }So, the rather circuitous route is:
- go to the zone model to get the selected zone
- from the zone, get its equipment list
- for each item in the list (via the delegate), use the UUID to look up the index in the equipment list
- extract its name and store in a QML string
Similar logic for all other equipment fields I want to report on.
It works, but before I mark this as solved, I'd be interested in critique.
Thanks...
-
M mzimmers has marked this topic as solved on
-
M mzimmers has marked this topic as unsolved on
-
M mzimmers has marked this topic as solved on