diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 33d06153e..00f123e32 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -42,6 +42,7 @@ set(SOURCES src/components/settings/AccountSettingsModel.cpp src/components/settings/SettingsModel.cpp src/components/smart-search-bar/SmartSearchBarModel.cpp + src/components/smart-search-bar/SmartSearchBarProxyModel.cpp src/components/timeline/TimelineModel.cpp src/main.cpp ) @@ -60,6 +61,7 @@ set(HEADERS src/components/settings/AccountSettingsModel.hpp src/components/settings/SettingsModel.hpp src/components/smart-search-bar/SmartSearchBarModel.hpp + src/components/smart-search-bar/SmartSearchBarProxyModel.hpp src/components/timeline/TimelineModel.hpp src/utils.hpp ) diff --git a/tests/src/app/App.cpp b/tests/src/app/App.cpp index 0b9686d30..13e5e14bd 100644 --- a/tests/src/app/App.cpp +++ b/tests/src/app/App.cpp @@ -108,7 +108,7 @@ void App::registerTypes () { qmlRegisterSingletonType( "Linphone", 1, 0, "TimelineModel", [](QQmlEngine *, QJSEngine *) -> QObject *{ - return new TimelineModel(); + return new TimelineModel(ContactsListProxyModel::getContactsListModel()); } ); } diff --git a/tests/src/components/contacts/ContactsListModel.cpp b/tests/src/components/contacts/ContactsListModel.cpp index 098417e50..d84e2bce2 100644 --- a/tests/src/components/contacts/ContactsListModel.cpp +++ b/tests/src/components/contacts/ContactsListModel.cpp @@ -59,7 +59,9 @@ bool ContactsListModel::removeRows (int row, int count, const QModelIndex &paren ContactModel *contact = m_list[row]; m_list.removeAt(row); + m_friend_to_contact.remove(contact->m_linphone_friend.get()); // m_linphone_friends->removeFriend(contact->m_linphone_friend); + contact->deleteLater(); } diff --git a/tests/src/components/contacts/ContactsListModel.hpp b/tests/src/components/contacts/ContactsListModel.hpp index 4ab812819..54ce8d8c3 100644 --- a/tests/src/components/contacts/ContactsListModel.hpp +++ b/tests/src/components/contacts/ContactsListModel.hpp @@ -34,7 +34,7 @@ public slots: private: QList m_list; - QHash m_friend_to_contact; + QHash m_friend_to_contact; std::shared_ptr m_linphone_friends; }; diff --git a/tests/src/components/timeline/TimelineModel.cpp b/tests/src/components/timeline/TimelineModel.cpp index 8826c22a9..55d77fee6 100644 --- a/tests/src/components/timeline/TimelineModel.cpp +++ b/tests/src/components/timeline/TimelineModel.cpp @@ -12,7 +12,45 @@ using namespace std; // =================================================================== -TimelineModel::TimelineModel (QObject *parent): QAbstractListModel(parent) { +TimelineModel::TimelineModel (const ContactsListModel *contacts_list) { + init_entries(); + + // Invalidate model if a contact is removed. + connect( + contacts_list, &ContactsListModel::rowsRemoved, this, + [this](const QModelIndex &, int, int) { + beginResetModel(); + // Nothing. + endResetModel(); + } + ); +} + +int TimelineModel::rowCount (const QModelIndex &) const { + return m_entries.count(); +} + +QHash TimelineModel::roleNames () const { + QHash roles; + roles[Qt::DisplayRole] = "$timelineEntry"; + return roles; +} + +QVariant TimelineModel::data (const QModelIndex &index, int role) const { + int row = index.row(); + + if (row < 0 || row >= m_entries.count()) + return QVariant(); + + if (role == Qt::DisplayRole) + return m_entries[row]; + + return QVariant(); +} + +// ------------------------------------------------------------------- + +void TimelineModel::init_entries () { // Returns an iterator entry position to insert a new entry. auto search_entry = [this]( const QVariantMap &map, @@ -89,25 +127,3 @@ TimelineModel::TimelineModel (QObject *parent): QAbstractListModel(parent) { } } } - -int TimelineModel::rowCount (const QModelIndex &) const { - return m_entries.count(); -} - -QHash TimelineModel::roleNames () const { - QHash roles; - roles[Qt::DisplayRole] = "$timelineEntry"; - return roles; -} - -QVariant TimelineModel::data (const QModelIndex &index, int role) const { - int row = index.row(); - - if (row < 0 || row >= m_entries.count()) - return QVariant(); - - if (role == Qt::DisplayRole) - return m_entries[row]; - - return QVariant(); -} diff --git a/tests/src/components/timeline/TimelineModel.hpp b/tests/src/components/timeline/TimelineModel.hpp index 9dcc40451..4c830b1ab 100644 --- a/tests/src/components/timeline/TimelineModel.hpp +++ b/tests/src/components/timeline/TimelineModel.hpp @@ -1,7 +1,7 @@ #ifndef TIMELINE_MODEL_H_ #define TIMELINE_MODEL_H_ -#include +#include "../contacts/ContactsListModel.hpp" // =================================================================== @@ -9,13 +9,15 @@ class TimelineModel : public QAbstractListModel { Q_OBJECT; public: - TimelineModel (QObject *parent = Q_NULLPTR); + TimelineModel (const ContactsListModel *contacts_list); int rowCount (const QModelIndex &) const; QHash roleNames () const; QVariant data (const QModelIndex &index, int role) const; private: + void init_entries (); + // A timeline enty is a object that contains: // - A QDateTime `timestamp`. // - A `sipAddresses` value, if it exists only one address, it's diff --git a/tests/src/utils.hpp b/tests/src/utils.hpp index ac6aa1f55..81fce800d 100644 --- a/tests/src/utils.hpp +++ b/tests/src/utils.hpp @@ -1,3 +1,6 @@ +#ifndef UTILS_H_ +#define UTILS_H_ + #include namespace Utils { @@ -5,3 +8,5 @@ namespace Utils { return QString::fromLocal8Bit(string.c_str(), string.size()); } } + +#endif // UTILS_H_