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
8bf12ac5
Commit
8bf12ac5
authored
Oct 03, 2016
by
Ronan Abhamon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix(ContactsListProxyModel): supports weight filter
parent
cb598949
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
67 additions
and
14 deletions
+67
-14
ContactModel.hpp
tests/src/components/contacts/ContactModel.hpp
+6
-4
ContactsListModel.hpp
tests/src/components/contacts/ContactsListModel.hpp
+2
-0
ContactsListProxyModel.cpp
tests/src/components/contacts/ContactsListProxyModel.cpp
+45
-8
ContactsListProxyModel.hpp
tests/src/components/contacts/ContactsListProxyModel.hpp
+9
-1
main.cpp
tests/src/main.cpp
+2
-0
Contacts.qml
tests/ui/views/MainWindow/Contacts.qml
+3
-1
No files found.
tests/src/components/contacts/ContactModel.hpp
View file @
8bf12ac5
...
...
@@ -6,6 +6,8 @@
// ===================================================================
class
ContactModel
:
public
QObject
{
friend
class
ContactsListProxyModel
;
Q_OBJECT
;
Q_PROPERTY
(
...
...
@@ -76,14 +78,14 @@ public:
m_sip_addresses
=
sip_addresses
;
}
QString
getUsername
()
const
{
return
m_username
;
}
signals:
void
contactUpdated
();
private:
QString
getUsername
()
const
{
return
m_username
;
}
void
setUsername
(
const
QString
&
username
)
{
m_username
=
username
;
}
...
...
tests/src/components/contacts/ContactsListModel.hpp
View file @
8bf12ac5
...
...
@@ -8,6 +8,8 @@
// ===================================================================
class
ContactsListModel
:
public
QAbstractListModel
{
friend
class
ContactsListProxyModel
;
Q_OBJECT
;
public:
...
...
tests/src/components/contacts/ContactsListProxyModel.cpp
View file @
8bf12ac5
...
...
@@ -2,6 +2,10 @@
#include "ContactsListProxyModel.hpp"
#define USERNAME_WEIGHT 0.5
#define MAIN_SIP_ADDRESS_WEIGHT 0.3
#define OTHER_SIP_ADDRESSES_WEIGHT 0.2
// ===================================================================
ContactsListModel
*
ContactsListProxyModel
::
m_list
=
nullptr
;
...
...
@@ -9,6 +13,11 @@ ContactsListModel *ContactsListProxyModel::m_list = nullptr;
ContactsListProxyModel
::
ContactsListProxyModel
(
QObject
*
parent
)
:
QSortFilterProxyModel
(
parent
)
{
setSourceModel
(
m_list
);
setDynamicSortFilter
(
true
);
setFilterCaseSensitivity
(
Qt
::
CaseInsensitive
);
foreach
(
const
ContactModel
*
contact
,
m_list
->
m_list
)
m_weights
[
contact
]
=
0
;
sort
(
0
);
}
...
...
@@ -16,7 +25,7 @@ void ContactsListProxyModel::initContactsListModel (ContactsListModel *list) {
if
(
!
m_list
)
m_list
=
list
;
else
qWarning
()
<<
"Contacts list model already defined."
;
qWarning
()
<<
"Contacts list model
is
already defined."
;
}
bool
ContactsListProxyModel
::
filterAcceptsRow
(
int
source_row
,
const
QModelIndex
&
source_parent
)
const
{
...
...
@@ -25,17 +34,45 @@ bool ContactsListProxyModel::filterAcceptsRow (int source_row, const QModelIndex
index
.
data
(
ContactsListModel
::
ContactRole
)
);
qDebug
()
<<
"A"
;
int
weight
=
m_weights
[
contact
]
=
computeContactWeight
(
*
contact
);
return
weight
>
0
;
}
bool
ContactsListProxyModel
::
lessThan
(
const
QModelIndex
&
left
,
const
QModelIndex
&
right
)
const
{
const
ContactModel
*
contact_a
=
qvariant_cast
<
ContactModel
*>
(
sourceModel
()
->
data
(
left
,
ContactsListModel
::
ContactRole
)
);
const
ContactModel
*
contact_b
=
qvariant_cast
<
ContactModel
*>
(
sourceModel
()
->
data
(
right
,
ContactsListModel
::
ContactRole
)
);
float
weight_a
=
m_weights
[
contact_a
];
float
weight_b
=
m_weights
[
contact_b
];
return
contact
->
getUsername
().
contains
(
filterRegExp
().
pattern
(),
Qt
::
CaseInsensitive
// Sort by weight and name.
return
(
weight_a
>
weight_b
||
(
weight_a
==
weight_b
&&
contact_a
->
m_username
<=
contact_b
->
m_username
)
);
}
bool
ContactsListProxyModel
::
lessThan
(
const
QModelIndex
&
left
,
const
QModelIndex
&
right
)
const
{
float
ContactsListProxyModel
::
computeContactWeight
(
const
ContactModel
&
contact
)
const
{
float
weight
=
0
;
if
(
filterRegExp
().
indexIn
(
contact
.
m_username
)
!=
-
1
)
weight
+=
USERNAME_WEIGHT
;
const
QStringList
&
addresses
=
contact
.
m_sip_addresses
;
if
(
filterRegExp
().
indexIn
(
addresses
[
0
])
!=
-
1
)
weight
+=
MAIN_SIP_ADDRESS_WEIGHT
;
int
size
=
addresses
.
size
();
qDebug
()
<<
"B"
;
if
(
size
>
1
)
for
(
auto
it
=
++
addresses
.
constBegin
();
it
!=
addresses
.
constEnd
();
++
it
)
if
(
filterRegExp
().
indexIn
(
*
it
)
!=
-
1
)
weight
+=
OTHER_SIP_ADDRESSES_WEIGHT
/
size
;
return
true
;
return
weight
;
}
tests/src/components/contacts/ContactsListProxyModel.hpp
View file @
8bf12ac5
...
...
@@ -16,10 +16,18 @@ public:
protected:
bool
filterAcceptsRow
(
int
source_row
,
const
QModelIndex
&
source_parent
)
const
;
bool
lessThan
(
const
QModelIndex
&
left
,
const
QModelIndex
&
right
)
const
;
bool
lessThan
(
const
QModelIndex
&
left
,
const
QModelIndex
&
right
)
const
;
private:
float
computeContactWeight
(
const
ContactModel
&
contact
)
const
;
// The contacts list is shared between `ContactsListProxyModel`
// it's necessary to initialize it with `initContactsListModel`.
static
ContactsListModel
*
m_list
;
// It's just a cache to save values computed by `filterAcceptsRow`
// and reused by `lessThan`.
mutable
QHash
<
const
ContactModel
*
,
float
>
m_weights
;
};
#endif // CONTACTS_LIST_PROXY_MODEL_H
tests/src/main.cpp
View file @
8bf12ac5
...
...
@@ -10,6 +10,8 @@
#include "app.hpp"
#include "components/contacts/ContactsListProxyModel.hpp"
#include "components/contacts/ContactsListModel.hpp"
#include "components/notification/Notification.hpp"
// ===================================================================
...
...
tests/ui/views/MainWindow/Contacts.qml
View file @
8bf12ac5
...
...
@@ -32,7 +32,9 @@ ColumnLayout {
}
placeholderText
:
qsTr
(
'
searchContactPlaceholder
'
)
onTextChanged
:
contacts
.
setFilterRegExp
(
text
)
onTextChanged
:
{
contacts
.
setFilterFixedString
(
text
)
}
}
ExclusiveButtons
{
...
...
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