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

unstable

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