mirror of
https://gitlab.linphone.org/BC/public/linphone-desktop.git
synced 2026-05-07 14:44:01 +00:00
feat(components/timeline): force render when a contact is removed
This commit is contained in:
parent
dac94d0295
commit
7495b4aadc
7 changed files with 54 additions and 27 deletions
|
|
@ -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();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
#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
|
||||
|
|
|
|||
|
|
@ -1,3 +1,6 @@
|
|||
#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_
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue