birthdayparty.cpp Example File
referenceexamples/properties/birthdayparty.cpp
#include "birthdayparty.h"
BirthdayParty::BirthdayParty(QObject *parent)
: QObject(parent), m_host(nullptr)
{
}
Person *BirthdayParty::host() const
{
return m_host;
}
void BirthdayParty::setHost(Person *c)
{
m_host = c;
}
QQmlListProperty<Person> BirthdayParty::guests()
{
return QQmlListProperty<Person>(this, this,
&BirthdayParty::appendGuest,
&BirthdayParty::guestCount,
&BirthdayParty::guest,
&BirthdayParty::clearGuests);
}
void BirthdayParty::appendGuest(Person* p) {
m_guests.append(p);
}
int BirthdayParty::guestCount() const
{
return m_guests.count();
}
Person *BirthdayParty::guest(int index) const
{
return m_guests.at(index);
}
void BirthdayParty::clearGuests() {
m_guests.clear();
}
void BirthdayParty::appendGuest(QQmlListProperty<Person>* list, Person* p) {
reinterpret_cast< BirthdayParty* >(list->data)->appendGuest(p);
}
void BirthdayParty::clearGuests(QQmlListProperty<Person>* list) {
reinterpret_cast< BirthdayParty* >(list->data)->clearGuests();
}
Person* BirthdayParty::guest(QQmlListProperty<Person>* list, int i) {
return reinterpret_cast< BirthdayParty* >(list->data)->guest(i);
}
int BirthdayParty::guestCount(QQmlListProperty<Person>* list) {
return reinterpret_cast< BirthdayParty* >(list->data)->guestCount();
}