Commit 55a4e008 authored by Ronan Abhamon's avatar Ronan Abhamon

unstable

parent 2a19553f
......@@ -35,6 +35,7 @@ set(SOURCES
src/app/DefaultTranslator.cpp
src/app/Logger.cpp
src/components/chat/ChatModel.cpp
src/components/chat/ChatModelFilter.cpp
src/components/chat/ChatProxyModel.cpp
src/components/contacts/ContactModel.cpp
src/components/contacts/ContactsListModel.cpp
......@@ -55,6 +56,7 @@ set(HEADERS
src/app/DefaultTranslator.hpp
src/app/Logger.hpp
src/components/chat/ChatModel.hpp
src/components/chat/ChatModelFilter.hpp
src/components/chat/ChatProxyModel.hpp
src/components/contacts/ContactModel.hpp
src/components/contacts/ContactsListModel.hpp
......
......@@ -139,7 +139,7 @@
</message>
<message>
<source>removeAllEntriesTitle</source>
<translation>Suppression de l'historique</translation>
<translation>Suppression de l&apos;historique</translation>
</message>
</context>
<context>
......@@ -184,7 +184,7 @@
</message>
<message>
<source>endedCall</source>
<translation>Fin d'appel</translation>
<translation>Fin d&apos;appel</translation>
</message>
<message>
<source>missedIncomingCall</source>
......
#include "ChatProxyModel.hpp"
// ===================================================================
ChatModelFilter::ChatModelFilter (QObject *parent) : QSortFilterProxyModel(parent) {
setSourceModel(&m_chat_model);
}
bool ChatModelFilter::filterAcceptsRow (int source_row, const QModelIndex &source_parent) const {
if (m_entry_type_filter == ChatModel::EntryType::GenericEntry)
return true;
QModelIndex index = sourceModel()->index(source_row, 0, QModelIndex());
const QVariantMap &data = qvariant_cast<QVariantMap>(
index.data()
);
return data["type"].toInt() == m_entry_type_filter;
}
#ifndef CHAT_MODEL_FILTER_H_
#define CHAT_MODEL_FILTER_H_
#include <QSortFilterProxyModel>
#include "ChatModel.hpp"
#include <QtDebug>
// ===================================================================
// Fetch K filtered chat entries.
// ===================================================================
class ChatModelFilter : public QSortFilterProxyModel {
friend class ChatProxyModel;
Q_OBJECT;
public:
ChatModelFilter (QObject *parent = Q_NULLPTR);
protected:
bool filterAcceptsRow (int source_row, const QModelIndex &source_parent) const;
private:
void setEntryTypeFilter (ChatModel::EntryType type) {
m_entry_type_filter = type;
invalidateFilter();
}
ChatModel m_chat_model;
ChatModel::EntryType m_entry_type_filter = ChatModel::EntryType::GenericEntry;
};
#endif // CHAT_MODEL_FILTER_H_
......@@ -2,25 +2,37 @@
// ===================================================================
const unsigned int ChatProxyModel::ENTRIES_CHUNK_SIZE = 25;
ChatProxyModel::ChatProxyModel (QObject *parent) : QSortFilterProxyModel(parent) {
m_chat_model.setParent(this);
setSourceModel(&m_chat_model);
setSourceModel(&m_chat_model_filter);
}
void ChatProxyModel::removeEntry (int id) {
m_chat_model.removeEntry(
mapToSource(index(id, 0)).row()
);
int ChatProxyModel::rowCount (const QModelIndex &parent) const {
int size = QSortFilterProxyModel::rowCount(parent);
return size < m_n_max_displayed_entries ? size : m_n_max_displayed_entries;
}
bool ChatProxyModel::filterAcceptsRow (int source_row, const QModelIndex &source_parent) const {
if (m_entry_type_filter == ChatModel::EntryType::GenericEntry)
return true;
QVariant ChatProxyModel::data (const QModelIndex &index, int role) const {
QAbstractItemModel *model = sourceModel();
QModelIndex index = sourceModel()->index(source_row, 0, source_parent);
const QVariantMap &data = qvariant_cast<QVariantMap>(
index.data()
return model->data(
model->index(
mapToSource(index).row() + (model->rowCount() - rowCount()),
0
),
role
);
}
return data["type"].toInt() == m_entry_type_filter;
void ChatProxyModel::loadMoreEntries () {
// TODO.
}
void ChatProxyModel::removeEntry (int id) {
QModelIndex source_index = mapToSource(index(id, 0));
static_cast<ChatModel *>(m_chat_model_filter.sourceModel())->removeEntry(
mapToSource(source_index).row()
);
}
#ifndef CHAT_PROXY_MODEL_H_
#define CHAT_PROXY_MODEL_H_
#include <QSortFilterProxyModel>
#include "ChatModel.hpp"
#include "ChatModelFilter.hpp"
// ===================================================================
// Fetch the L last filtered chat entries.
// ===================================================================
class ChatProxyModel : public QSortFilterProxyModel {
......@@ -23,32 +23,38 @@ signals:
public:
ChatProxyModel (QObject *parent = Q_NULLPTR);
public slots:
void removeEntry (int id);
int rowCount (const QModelIndex &parent = QModelIndex()) const override;
QVariant data (const QModelIndex &index, int role) const override;
void removeAllEntries () {
m_chat_model.removeAllEntries();
}
public slots:
void loadMoreEntries ();
void setEntryTypeFilter (ChatModel::EntryType type) {
m_entry_type_filter = type;
invalidateFilter();
m_chat_model_filter.setEntryTypeFilter(type);
}
protected:
bool filterAcceptsRow (int source_row, const QModelIndex &source_parent) const;
void removeEntry (int id);
void removeAllEntries () {
static_cast<ChatModel *>(m_chat_model_filter.sourceModel())->removeAllEntries();
}
private:
QString getSipAddress () const {
return m_chat_model.getSipAddress();
static_cast<ChatModel *>(m_chat_model_filter.sourceModel())->getSipAddress();
}
void setSipAddress (const QString &sip_address) {
m_chat_model.setSipAddress(sip_address);
static_cast<ChatModel *>(m_chat_model_filter.sourceModel())->setSipAddress(
sip_address
);
}
ChatModel m_chat_model;
ChatModel::EntryType m_entry_type_filter = ChatModel::EntryType::GenericEntry;
ChatModelFilter m_chat_model_filter;
unsigned int m_n_max_displayed_entries = ENTRIES_CHUNK_SIZE;
static const unsigned int ENTRIES_CHUNK_SIZE;
};
#endif // CHAT_PROXY_MODEL_H_
......@@ -21,6 +21,18 @@ ColumnLayout {
ScrollableListView {
id: chat
property bool _tryToLoadMoreEntries: false
function _loadMoreEntries () {
if (chat.contentY > 500 || _tryToLoadMoreEntries) {
return
}
_tryToLoadMoreEntries = true
proxyModel.loadMoreEntries()
}
Layout.fillHeight: true
Layout.fillWidth: true
......@@ -164,6 +176,8 @@ ColumnLayout {
}
}
}
onContentYChanged: _loadMoreEntries()
}
// -----------------------------------------------------------------
......
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