Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
L
linphone-desktop
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Administrator
linphone-desktop
Commits
a1fc6a63
Commit
a1fc6a63
authored
Nov 30, 2016
by
Ronan Abhamon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix(src/components/chat): use two filters to get filtered messages and the last
parent
55a4e008
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
55 additions
and
81 deletions
+55
-81
CMakeLists.txt
tests/CMakeLists.txt
+0
-2
ChatModel.cpp
tests/src/components/chat/ChatModel.cpp
+1
-3
ChatModel.hpp
tests/src/components/chat/ChatModel.hpp
+2
-0
ChatModelFilter.cpp
tests/src/components/chat/ChatModelFilter.cpp
+0
-19
ChatModelFilter.hpp
tests/src/components/chat/ChatModelFilter.hpp
+0
-35
ChatProxyModel.cpp
tests/src/components/chat/ChatProxyModel.cpp
+25
-18
ChatProxyModel.hpp
tests/src/components/chat/ChatProxyModel.hpp
+27
-4
No files found.
tests/CMakeLists.txt
View file @
a1fc6a63
...
...
@@ -35,7 +35,6 @@ 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
...
...
@@ -56,7 +55,6 @@ 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
...
...
tests/src/components/chat/ChatModel.cpp
View file @
a1fc6a63
...
...
@@ -148,9 +148,7 @@ void ChatModel::removeEntry (ChatEntryData &pair) {
}
);
if
(
it
==
m_entries
.
end
())
qWarning
(
"Unable to find symmetric call."
);
else
if
(
it
!=
m_entries
.
end
())
removeEntry
(
distance
(
m_entries
.
begin
(),
it
));
});
}
...
...
tests/src/components/chat/ChatModel.hpp
View file @
a1fc6a63
...
...
@@ -4,6 +4,8 @@
#include <QAbstractListModel>
#include <linphone++/linphone.hh>
// ===================================================================
// Fetch all N messages of a ChatRoom.
// ===================================================================
class
ChatModel
:
public
QAbstractListModel
{
...
...
tests/src/components/chat/ChatModelFilter.cpp
deleted
100644 → 0
View file @
55a4e008
#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
;
}
tests/src/components/chat/ChatModelFilter.hpp
deleted
100644 → 0
View file @
55a4e008
#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_
tests/src/components/chat/ChatProxyModel.cpp
View file @
a1fc6a63
#include "ChatProxyModel.hpp"
// ===================================================================
ChatModelFilter
::
ChatModelFilter
(
QObject
*
parent
)
:
QSortFilterProxyModel
(
parent
)
{
setSourceModel
(
&
m_chat_model
);
}
const
unsigned
int
ChatProxyModel
::
ENTRIES_CHUNK_SIZE
=
25
;
bool
ChatModelFilter
::
filterAcceptsRow
(
int
source_row
,
const
QModelIndex
&
)
const
{
if
(
m_entry_type_filter
==
ChatModel
::
EntryType
::
GenericEntry
)
return
true
;
ChatProxyModel
::
ChatProxyModel
(
QObject
*
parent
)
:
QSortFilterProxyModel
(
parent
)
{
setSourceModel
(
&
m_chat_model_filter
);
QModelIndex
index
=
sourceModel
()
->
index
(
source_row
,
0
,
QModelIndex
());
const
QVariantMap
&
data
=
qvariant_cast
<
QVariantMap
>
(
index
.
data
()
);
return
data
[
"type"
].
toInt
()
==
m_entry_type_filter
;
}
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
;
void
ChatModelFilter
::
setEntryTypeFilter
(
ChatModel
::
EntryType
type
)
{
m_entry_type_filter
=
type
;
invalidateFilter
()
;
}
QVariant
ChatProxyModel
::
data
(
const
QModelIndex
&
index
,
int
role
)
const
{
QAbstractItemModel
*
model
=
sourceModel
();
// ===================================================================
const
unsigned
int
ChatProxyModel
::
ENTRIES_CHUNK_SIZE
=
25
;
return
model
->
data
(
model
->
index
(
mapToSource
(
index
).
row
()
+
(
model
->
rowCount
()
-
rowCount
()),
0
),
role
);
ChatProxyModel
::
ChatProxyModel
(
QObject
*
parent
)
:
QSortFilterProxyModel
(
parent
)
{
setSourceModel
(
&
m_chat_model_filter
);
}
void
ChatProxyModel
::
loadMoreEntries
()
{
...
...
@@ -31,8 +35,11 @@ void ChatProxyModel::loadMoreEntries () {
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
()
m
_chat_model_filter
.
m
apToSource
(
source_index
).
row
()
);
}
bool
ChatProxyModel
::
filterAcceptsRow
(
int
source_row
,
const
QModelIndex
&
)
const
{
return
m_chat_model_filter
.
rowCount
()
-
source_row
<=
m_n_max_displayed_entries
;
}
tests/src/components/chat/ChatProxyModel.hpp
View file @
a1fc6a63
#ifndef CHAT_PROXY_MODEL_H_
#define CHAT_PROXY_MODEL_H_
#include "ChatModelFilter.hpp"
#include <QSortFilterProxyModel>
#include "ChatModel.hpp"
// ===================================================================
// Fetch the L last filtered chat entries.
// ===================================================================
// Cannot be used as a nested class by Qt and `Q_OBJECTY` macro
// must be used in header c++ file.
class
ChatModelFilter
:
public
QSortFilterProxyModel
{
friend
class
ChatProxyModel
;
Q_OBJECT
;
public:
ChatModelFilter
(
QObject
*
parent
=
Q_NULLPTR
);
protected:
bool
filterAcceptsRow
(
int
source_row
,
const
QModelIndex
&
parent
)
const
;
private:
void
setEntryTypeFilter
(
ChatModel
::
EntryType
type
);
ChatModel
m_chat_model
;
ChatModel
::
EntryType
m_entry_type_filter
=
ChatModel
::
EntryType
::
GenericEntry
;
};
// ===================================================================
class
ChatProxyModel
:
public
QSortFilterProxyModel
{
Q_OBJECT
;
...
...
@@ -23,9 +46,6 @@ signals:
public:
ChatProxyModel
(
QObject
*
parent
=
Q_NULLPTR
);
int
rowCount
(
const
QModelIndex
&
parent
=
QModelIndex
())
const
override
;
QVariant
data
(
const
QModelIndex
&
index
,
int
role
)
const
override
;
public
slots
:
void
loadMoreEntries
();
...
...
@@ -39,6 +59,9 @@ public slots:
static_cast
<
ChatModel
*>
(
m_chat_model_filter
.
sourceModel
())
->
removeAllEntries
();
}
protected:
bool
filterAcceptsRow
(
int
source_row
,
const
QModelIndex
&
source_parent
)
const
;
private:
QString
getSipAddress
()
const
{
static_cast
<
ChatModel
*>
(
m_chat_model_filter
.
sourceModel
())
->
getSipAddress
();
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment