Commit 7495b4aa authored by Ronan Abhamon's avatar Ronan Abhamon

feat(components/timeline): force render when a contact is removed

parent dac94d02
......@@ -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
)
......
......@@ -108,7 +108,7 @@ void App::registerTypes () {
qmlRegisterSingletonType<TimelineModel>(
"Linphone", 1, 0, "TimelineModel",
[](QQmlEngine *, QJSEngine *) -> QObject *{
return new TimelineModel();
return new TimelineModel(ContactsListProxyModel::getContactsListModel());
}
);
}
......
......@@ -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();
}
......
......@@ -34,7 +34,7 @@ public slots:
private:
QList<ContactModel *> m_list;
QHash<const linphone::Friend *, ContactModel* > m_friend_to_contact;
QHash<const linphone::Friend *, ContactModel *> m_friend_to_contact;
std::shared_ptr<linphone::FriendList> m_linphone_friends;
};
......
......@@ -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<int, QByteArray> TimelineModel::roleNames () const {
QHash<int, QByteArray> 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<int, QByteArray> TimelineModel::roleNames () const {
QHash<int, QByteArray> 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();
}
#ifndef TIMELINE_MODEL_H_
#define TIMELINE_MODEL_H_
#include <QAbstractListModel>
#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<int, QByteArray> 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
......
#ifndef UTILS_H_
#define UTILS_H_
#include <QString>
namespace Utils {
......@@ -5,3 +8,5 @@ namespace Utils {
return QString::fromLocal8Bit(string.c_str(), string.size());
}
}
#endif // UTILS_H_
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment