Qt IVI Generator Addressbook Example

/**************************************************************************** ** Generated from 'Example.IVI.AddressBook.qface' ** ** Created by: The QFace generator (QtAS 5.12.8) ** ** WARNING! All changes made in this file will be lost! *****************************************************************************/
#include "addressbookbackend.h" #include <QDebug> #include <QtIviCore/QIviSimulationEngine> ContactsModelBackend::ContactsModelBackend(QObject* parent) : QIviPagingModelInterface(parent) { qRegisterMetaType<QIviPagingModelInterface*>(); } /*! \internal */ ContactsModelBackend::~ContactsModelBackend() { } void ContactsModelBackend::initialize() { QIVI_SIMULATION_TRY_CALL(ContactsModelBackend, "initialize", void); emit initializationDone(); } void ContactsModelBackend::registerInstance(const QUuid &identifier) { QIVI_SIMULATION_TRY_CALL(ContactsModelBackend, "registerInstance", void, identifier); qCritical() << "REGISTER" << identifier; emit countChanged(identifier, m_list.count()); } void ContactsModelBackend::unregisterInstance(const QUuid &identifier) { QIVI_SIMULATION_TRY_CALL(ContactsModelBackend, "unregisterInstance", void, identifier); qCritical() << "UNREGISTER" << identifier; } void ContactsModelBackend::fetchData(const QUuid &identifier, int start, int count) { QIVI_SIMULATION_TRY_CALL(ContactsModelBackend, "fetchData", void, identifier, start, count); qCritical() << "FETCH" << identifier << start << count; QVariantList list; int max = qMin(start + count, m_list.count()); for(int i=start; i < max; i++) list.append(QVariant::fromValue(m_list.at(i))); emit dataFetched(identifier, list, start, max < m_list.count()); } void ContactsModelBackend::insert(int index, const Contact &item) { m_list.insert(index, item); emit dataChanged(QUuid(), { QVariant::fromValue(item) }, index, 0); } void ContactsModelBackend::remove(int index) { m_list.removeAt(index); emit dataChanged(QUuid(), QVariantList(), index, 1); } void ContactsModelBackend::move(int currentIndex, int newIndex) { int min = qMin(currentIndex, newIndex); int max = qMax(currentIndex, newIndex); m_list.move(currentIndex, newIndex); QVariantList variantList; for (int i = min; i <= max; i++) variantList.append(QVariant::fromValue(m_list.at(i))); emit dataChanged(QUuid(), variantList, min, max - min + 1); } void ContactsModelBackend::reset() { emit dataChanged(QUuid(), QVariantList(), 0, m_list.count()); m_list.clear(); } void ContactsModelBackend::update(int index, const Contact &item) { m_list[index] = item; emit dataChanged(QUuid(), { QVariant::fromValue(item) }, index, 1); } const Contact &ContactsModelBackend::at(int index) const { return m_list.at(index); } /*! \class AddressBookBackend \inmodule Example.IVI.AddressBook */ AddressBookBackend::AddressBookBackend(QObject *parent) : AddressBookBackend(nullptr, parent) { } AddressBookBackend::AddressBookBackend(QIviSimulationEngine *engine, QObject *parent) : AddressBookBackendInterface(parent) { //In some cases the engine is unused, this doesn't do any harm if it is still used Q_UNUSED(engine) qRegisterMetaType<QQmlPropertyMap*>(); auto contactsModel = (new ContactsModelBackend(this)); m_contacts = contactsModel; engine->registerSimulationInstance(contactsModel, "example.ivi.addressbook.simulation", 1, 0, "ContactsModelBackend"); AddressBookModule::registerTypes(); } AddressBookBackend::~AddressBookBackend() { } /*! \fn void AddressBookBackend::initialize() Initializes the backend and informs about its current state by emitting signals with the current status (property values). */ void AddressBookBackend::initialize() { QIVI_SIMULATION_TRY_CALL(AddressBookBackend, "initialize", void); emit contactsChanged(m_contacts); emit initializationDone(); } QIviPagingModelInterface * AddressBookBackend::contacts() const { return m_contacts; } /*! \fn virtual void AddressBookBackend::setContacts(QIviPagingModel *contacts) */ void AddressBookBackend::setContacts(QIviPagingModelInterface *contacts) { QIVI_SIMULATION_TRY_CALL(AddressBookBackend, "setContacts", void, contacts); if (m_contacts == contacts) return; m_contacts = contacts; emit contactsChanged(m_contacts); } /*! \fn virtual QIviPendingReply<void> AddressBookBackend::insertContact(int index, const Contact &contact) */ QIviPendingReply<void> AddressBookBackend::insertContact(int index, const Contact &contact) { QIviPendingReply<void> pendingReply; QIVI_SIMULATION_TRY_CALL_FUNC(AddressBookBackend, "insertContact", return pendingReply, QIviPendingReplyBase(pendingReply), index, contact ); qWarning() << "Not implemented!"; //Fake that the reply always succeeded QIviPendingReply<void> successReply; successReply.setSuccess(); return successReply; }