From 555bf6604781595745febbfef004ea6bf0803df2 Mon Sep 17 00:00:00 2001 From: Ronan Abhamon Date: Fri, 30 Dec 2016 16:57:22 +0100 Subject: [PATCH] feat(app): remove all slots, use `Q_INVOKABLE` instead. --- tests/src/app/App.hpp | 3 +- tests/src/components/chat/ChatModel.hpp | 5 +-- tests/src/components/chat/ChatProxyModel.hpp | 9 ++--- tests/src/components/contact/ContactModel.hpp | 7 ++-- tests/src/components/contact/VcardModel.hpp | 33 ++++++++-------- .../components/contacts/ContactsListModel.hpp | 5 +-- .../contacts/ContactsListProxyModel.hpp | 3 +- tests/src/components/core/CoreManager.hpp | 3 +- tests/src/components/notifier/Notifier.hpp | 3 +- .../sip-addresses/SipAddressesModel.cpp | 38 ++++++++++--------- .../sip-addresses/SipAddressesModel.hpp | 7 ++-- .../smart-search-bar/SmartSearchBarModel.hpp | 3 +- 12 files changed, 55 insertions(+), 64 deletions(-) diff --git a/tests/src/app/App.hpp b/tests/src/app/App.hpp index 6cfaaf200..6164044e0 100644 --- a/tests/src/app/App.hpp +++ b/tests/src/app/App.hpp @@ -33,8 +33,7 @@ public: return &m_engine; } -public slots: - QString locale () const { + Q_INVOKABLE QString locale () const { return m_locale; } diff --git a/tests/src/components/chat/ChatModel.hpp b/tests/src/components/chat/ChatModel.hpp index 6fde9f368..26b0a0e86 100644 --- a/tests/src/components/chat/ChatModel.hpp +++ b/tests/src/components/chat/ChatModel.hpp @@ -56,9 +56,8 @@ public: QString getSipAddress () const; void setSipAddress (const QString &sip_address); -public slots: - void removeEntry (int id); - void removeAllEntries (); + Q_INVOKABLE void removeEntry (int id); + Q_INVOKABLE void removeAllEntries (); signals: void sipAddressChanged (const QString &sip_address); diff --git a/tests/src/components/chat/ChatProxyModel.hpp b/tests/src/components/chat/ChatProxyModel.hpp index bc780375c..5d20bb9b1 100644 --- a/tests/src/components/chat/ChatProxyModel.hpp +++ b/tests/src/components/chat/ChatProxyModel.hpp @@ -43,12 +43,11 @@ class ChatProxyModel : public QSortFilterProxyModel { public: ChatProxyModel (QObject *parent = Q_NULLPTR); -public slots: - void loadMoreEntries (); - void setEntryTypeFilter (ChatModel::EntryType type); - void removeEntry (int id); + Q_INVOKABLE void loadMoreEntries (); + Q_INVOKABLE void setEntryTypeFilter (ChatModel::EntryType type); + Q_INVOKABLE void removeEntry (int id); - void removeAllEntries () { + Q_INVOKABLE void removeAllEntries () { static_cast(m_chat_model_filter.sourceModel())->removeAllEntries(); } diff --git a/tests/src/components/contact/ContactModel.hpp b/tests/src/components/contact/ContactModel.hpp index b319073b3..0bd24e0f2 100644 --- a/tests/src/components/contact/ContactModel.hpp +++ b/tests/src/components/contact/ContactModel.hpp @@ -26,10 +26,9 @@ public: return m_vcard; } -public slots: - void startEdit (); - void endEdit (); - void abortEdit (); + Q_INVOKABLE void startEdit (); + Q_INVOKABLE void endEdit (); + Q_INVOKABLE void abortEdit (); signals: void contactUpdated (); diff --git a/tests/src/components/contact/VcardModel.hpp b/tests/src/components/contact/VcardModel.hpp index 9ce5240e1..b05dbe847 100644 --- a/tests/src/components/contact/VcardModel.hpp +++ b/tests/src/components/contact/VcardModel.hpp @@ -27,27 +27,26 @@ public: QString getUsername () const; QVariantList getSipAddresses () const; -public slots: - bool addSipAddress (const QString &sip_address); - void removeSipAddress (const QString &sip_address); - bool updateSipAddress (const QString &old_sip_address, const QString &sip_address); + Q_INVOKABLE bool addSipAddress (const QString &sip_address); + Q_INVOKABLE void removeSipAddress (const QString &sip_address); + Q_INVOKABLE bool updateSipAddress (const QString &old_sip_address, const QString &sip_address); - bool addCompany (const QString &company); - void removeCompany (const QString &company); - bool updateCompany (const QString &old_company, const QString &company); + Q_INVOKABLE bool addCompany (const QString &company); + Q_INVOKABLE void removeCompany (const QString &company); + Q_INVOKABLE bool updateCompany (const QString &old_company, const QString &company); - bool addEmail (const QString &email); - void removeEmail (const QString &email); - bool updateEmail (const QString &old_email, const QString &email); + Q_INVOKABLE bool addEmail (const QString &email); + Q_INVOKABLE void removeEmail (const QString &email); + Q_INVOKABLE bool updateEmail (const QString &old_email, const QString &email); - bool addUrl (const QString &url); - void removeUrl (const QString &url); - bool updateUrl (const QString &old_url, const QString &url); + Q_INVOKABLE bool addUrl (const QString &url); + Q_INVOKABLE void removeUrl (const QString &url); + Q_INVOKABLE bool updateUrl (const QString &old_url, const QString &url); - void setStreet (const QString &street); - void setLocality (const QString &locality); - void setPostalCode (const QString &postal_code); - void setCountry (const QString &country); + Q_INVOKABLE void setStreet (const QString &street); + Q_INVOKABLE void setLocality (const QString &locality); + Q_INVOKABLE void setPostalCode (const QString &postal_code); + Q_INVOKABLE void setCountry (const QString &country); signals: void vcardUpdated (); diff --git a/tests/src/components/contacts/ContactsListModel.hpp b/tests/src/components/contacts/ContactsListModel.hpp index aebc1b0a4..ac8c689d3 100644 --- a/tests/src/components/contacts/ContactsListModel.hpp +++ b/tests/src/components/contacts/ContactsListModel.hpp @@ -25,9 +25,8 @@ public: bool removeRow (int row, const QModelIndex &parent = QModelIndex()); bool removeRows (int row, int count, const QModelIndex &parent = QModelIndex()) override; -public slots: - ContactModel *addContact (VcardModel *vcard); - void removeContact (ContactModel *contact); + Q_INVOKABLE ContactModel *addContact (VcardModel *vcard); + Q_INVOKABLE void removeContact (ContactModel *contact); signals: void contactAdded (ContactModel *contact); diff --git a/tests/src/components/contacts/ContactsListProxyModel.hpp b/tests/src/components/contacts/ContactsListProxyModel.hpp index de8e078f4..c43346f29 100644 --- a/tests/src/components/contacts/ContactsListProxyModel.hpp +++ b/tests/src/components/contacts/ContactsListProxyModel.hpp @@ -22,8 +22,7 @@ public: ContactsListProxyModel (QObject *parent = Q_NULLPTR); ~ContactsListProxyModel () = default; -public slots: - void setFilter (const QString &pattern); + Q_INVOKABLE void setFilter (const QString &pattern); protected: bool filterAcceptsRow (int source_row, const QModelIndex &source_parent) const override; diff --git a/tests/src/components/core/CoreManager.hpp b/tests/src/components/core/CoreManager.hpp index 755acfde1..dcc4867d7 100644 --- a/tests/src/components/core/CoreManager.hpp +++ b/tests/src/components/core/CoreManager.hpp @@ -34,10 +34,9 @@ public: return m_instance; } -public slots: // Must be used in a qml scene. // Warning: The ownership of `VcardModel` is `QQmlEngine::JavaScriptOwnership` by default. - VcardModel *createDetachedVcardModel (); + Q_INVOKABLE VcardModel *createDetachedVcardModel (); private: CoreManager (QObject *parent = Q_NULLPTR); diff --git a/tests/src/components/notifier/Notifier.hpp b/tests/src/components/notifier/Notifier.hpp index 32c99f060..21ca12ec3 100644 --- a/tests/src/components/notifier/Notifier.hpp +++ b/tests/src/components/notifier/Notifier.hpp @@ -20,8 +20,7 @@ public: MaxNbTypes }; -public slots: - void showCallMessage (int timeout, const QString &sip_address); + Q_INVOKABLE void showCallMessage (int timeout, const QString &sip_address); private: QObject *createNotification (NotificationType type); diff --git a/tests/src/components/sip-addresses/SipAddressesModel.cpp b/tests/src/components/sip-addresses/SipAddressesModel.cpp index dd138ccba..2dfae1f8c 100644 --- a/tests/src/components/sip-addresses/SipAddressesModel.cpp +++ b/tests/src/components/sip-addresses/SipAddressesModel.cpp @@ -83,6 +83,26 @@ ContactModel *SipAddressesModel::mapSipAddressToContact (const QString &sip_addr return it->value("contact").value(); } +// ----------------------------------------------------------------------------- + +ContactObserver *SipAddressesModel::getContactObserver (const QString &sip_address) { + ContactObserver *model = new ContactObserver(sip_address); + model->setContact(mapSipAddressToContact(sip_address)); + + m_observers.insert(sip_address, model); + QObject::connect( + model, &ContactObserver::destroyed, this, [this, model]() { + const QString &sip_address = model->getSipAddress(); + if (m_observers.remove(sip_address, model) == 0) + qWarning() << QStringLiteral("Unable to remove sip address `%1` from observers.").arg(sip_address); + } + ); + + return model; +} + +// ----------------------------------------------------------------------------- + void SipAddressesModel::handleAllHistoryEntriesRemoved () { QObject *sender = QObject::sender(); if (!sender) @@ -115,24 +135,6 @@ void SipAddressesModel::handleAllHistoryEntriesRemoved () { // ----------------------------------------------------------------------------- -ContactObserver *SipAddressesModel::getContactObserver (const QString &sip_address) { - ContactObserver *model = new ContactObserver(sip_address); - model->setContact(mapSipAddressToContact(sip_address)); - - m_observers.insert(sip_address, model); - QObject::connect( - model, &ContactObserver::destroyed, this, [this, model]() { - const QString &sip_address = model->getSipAddress(); - if (m_observers.remove(sip_address, model) == 0) - qWarning() << QStringLiteral("Unable to remove sip address `%1` from observers.").arg(sip_address); - } - ); - - return model; -} - -// ----------------------------------------------------------------------------- - bool SipAddressesModel::removeRow (int row, const QModelIndex &parent) { return removeRows(row, 1, parent); } diff --git a/tests/src/components/sip-addresses/SipAddressesModel.hpp b/tests/src/components/sip-addresses/SipAddressesModel.hpp index 0df32bd8a..61241dc83 100644 --- a/tests/src/components/sip-addresses/SipAddressesModel.hpp +++ b/tests/src/components/sip-addresses/SipAddressesModel.hpp @@ -20,11 +20,10 @@ public: QHash roleNames () const override; QVariant data (const QModelIndex &index, int role) const override; -public slots: - ContactModel *mapSipAddressToContact (const QString &sip_address) const; - void handleAllHistoryEntriesRemoved (); + Q_INVOKABLE ContactModel *mapSipAddressToContact (const QString &sip_address) const; + Q_INVOKABLE ContactObserver *getContactObserver (const QString &sip_address); - ContactObserver *getContactObserver (const QString &sip_address); + Q_INVOKABLE void handleAllHistoryEntriesRemoved (); private: bool removeRow (int row, const QModelIndex &parent = QModelIndex()); diff --git a/tests/src/components/smart-search-bar/SmartSearchBarModel.hpp b/tests/src/components/smart-search-bar/SmartSearchBarModel.hpp index 4ecfbcb8d..48ef732d2 100644 --- a/tests/src/components/smart-search-bar/SmartSearchBarModel.hpp +++ b/tests/src/components/smart-search-bar/SmartSearchBarModel.hpp @@ -16,8 +16,7 @@ public: QHash roleNames () const override; -public slots: - void setFilter (const QString &pattern); + Q_INVOKABLE void setFilter (const QString &pattern); protected: bool filterAcceptsRow (int source_row, const QModelIndex &source_parent) const override;