Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
J
jami-libclient
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Deploy
Releases
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
savoirfairelinux
jami-libclient
Commits
e89ca48e
Commit
e89ca48e
authored
9 years ago
by
Emmanuel Lepage Vallee
Committed by
Stepan Salenikovich
9 years ago
Browse files
Options
Downloads
Patches
Plain Diff
contact: Disable categories with 0 reachable element
Refs #74764 Change-Id: I201892b7a8d30aa39993a686ce7b29edc6dbf9a5
parent
5041bea5
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/categorizedcontactmodel.cpp
+55
-17
55 additions, 17 deletions
src/categorizedcontactmodel.cpp
with
55 additions
and
17 deletions
src/categorizedcontactmodel.cpp
+
55
−
17
View file @
e89ca48e
...
@@ -63,16 +63,24 @@ public:
...
@@ -63,16 +63,24 @@ public:
uint
m_Index
;
uint
m_Index
;
QString
m_Name
;
QString
m_Name
;
NodeType
m_Type
;
NodeType
m_Type
;
ContactTreeNode
*
m_pParent
;
QVector
<
ContactTreeNode
*>
m_lChildren
;
QVector
<
ContactTreeNode
*>
m_lChildren
;
CategorizedContactModel
*
m_pModel
;
CategorizedContactModel
*
m_pModel
;
bool
m_Visible
;
//Setter
inline
void
setParent
(
ContactTreeNode
*
n
);
inline
void
setVisible
(
bool
visible
);
//Helpers
//Helpers
void
slotChanged
(
);
void
slotChanged
(
);
void
slotContactMethodCountChanged
(
int
,
int
);
void
slotContactMethodCountChanged
(
int
,
int
);
void
slotContactMethodCountAboutToChange
(
int
,
int
);
void
slotContactMethodCountAboutToChange
(
int
,
int
);
private
:
ContactTreeNode
*
m_pParent
;
bool
m_Visible
;
uint
m_VisibleCounter
;
};
};
class
CategorizedContactModelPrivate
final
:
public
QObject
class
CategorizedContactModelPrivate
final
:
public
QObject
{
{
Q_OBJECT
Q_OBJECT
...
@@ -113,7 +121,8 @@ public Q_SLOTS:
...
@@ -113,7 +121,8 @@ public Q_SLOTS:
CategorizedContactModel
*
CategorizedContactModelPrivate
::
m_spInstance
=
nullptr
;
CategorizedContactModel
*
CategorizedContactModelPrivate
::
m_spInstance
=
nullptr
;
ContactTreeNode
::
ContactTreeNode
(
const
Person
*
ct
,
CategorizedContactModel
*
parent
)
:
CategorizedCompositeNode
(
CategorizedCompositeNode
::
Type
::
CONTACT
),
ContactTreeNode
::
ContactTreeNode
(
const
Person
*
ct
,
CategorizedContactModel
*
parent
)
:
CategorizedCompositeNode
(
CategorizedCompositeNode
::
Type
::
CONTACT
),
m_pContact
(
ct
),
m_Index
(
-
1
),
m_pContactMethod
(
nullptr
),
m_Type
(
ContactTreeNode
::
NodeType
::
PERSON
),
m_pParent
(
nullptr
),
m_pModel
(
parent
),
m_Visible
(
true
)
m_pContact
(
ct
),
m_Index
(
-
1
),
m_pContactMethod
(
nullptr
),
m_Type
(
ContactTreeNode
::
NodeType
::
PERSON
),
m_pParent
(
nullptr
),
m_pModel
(
parent
),
m_Visible
(
true
),
m_VisibleCounter
(
0
)
{
{
m_Visible
=
m_pContact
->
isActive
()
&&
((
!
parent
->
d_ptr
->
m_UnreachableHidden
)
||
m_pContact
->
isReachable
());
m_Visible
=
m_pContact
->
isActive
()
&&
((
!
parent
->
d_ptr
->
m_UnreachableHidden
)
||
m_pContact
->
isReachable
());
QObject
::
connect
(
m_pContact
,
&
Person
::
changed
,[
this
](
){
slotChanged
(
);
});
QObject
::
connect
(
m_pContact
,
&
Person
::
changed
,[
this
](
){
slotChanged
(
);
});
...
@@ -123,14 +132,14 @@ ContactTreeNode::ContactTreeNode(const Person* ct, CategorizedContactModel* pare
...
@@ -123,14 +132,14 @@ ContactTreeNode::ContactTreeNode(const Person* ct, CategorizedContactModel* pare
ContactTreeNode
::
ContactTreeNode
(
ContactMethod
*
cm
,
CategorizedContactModel
*
parent
)
:
CategorizedCompositeNode
(
CategorizedCompositeNode
::
Type
::
NUMBER
),
ContactTreeNode
::
ContactTreeNode
(
ContactMethod
*
cm
,
CategorizedContactModel
*
parent
)
:
CategorizedCompositeNode
(
CategorizedCompositeNode
::
Type
::
NUMBER
),
m_pContactMethod
(
cm
),
m_Index
(
-
1
),
m_pContact
(
nullptr
),
m_Type
(
ContactTreeNode
::
NodeType
::
CONTACTMETHOD
),
m_pParent
(
nullptr
),
m_pModel
(
parent
),
m_pContactMethod
(
cm
),
m_Index
(
-
1
),
m_pContact
(
nullptr
),
m_Type
(
ContactTreeNode
::
NodeType
::
CONTACTMETHOD
),
m_pParent
(
nullptr
),
m_pModel
(
parent
),
m_Visible
(
true
)
m_Visible
(
true
)
,
m_VisibleCounter
(
0
)
{
{
QObject
::
connect
(
m_pContactMethod
,
&
ContactMethod
::
changed
,[
this
](){
slotChanged
();
});
QObject
::
connect
(
m_pContactMethod
,
&
ContactMethod
::
changed
,[
this
](){
slotChanged
();
});
}
}
ContactTreeNode
::
ContactTreeNode
(
const
QString
&
name
,
CategorizedContactModel
*
parent
)
:
CategorizedCompositeNode
(
CategorizedCompositeNode
::
Type
::
CONTACT
),
ContactTreeNode
::
ContactTreeNode
(
const
QString
&
name
,
CategorizedContactModel
*
parent
)
:
CategorizedCompositeNode
(
CategorizedCompositeNode
::
Type
::
CONTACT
),
m_pContactMethod
(
nullptr
),
m_Index
(
-
1
),
m_pContact
(
nullptr
),
m_Type
(
ContactTreeNode
::
NodeType
::
CATEGORY
),
m_Name
(
name
),
m_pParent
(
nullptr
),
m_pContactMethod
(
nullptr
),
m_Index
(
-
1
),
m_pContact
(
nullptr
),
m_Type
(
ContactTreeNode
::
NodeType
::
CATEGORY
),
m_Name
(
name
),
m_pParent
(
nullptr
),
m_pModel
(
parent
),
m_Visible
(
true
)
m_pModel
(
parent
),
m_Visible
(
false
),
m_VisibleCounter
(
0
)
{
{
}
}
...
@@ -168,7 +177,7 @@ void ContactTreeNode::slotContactMethodCountChanged(int count, int oldCount)
...
@@ -168,7 +177,7 @@ void ContactTreeNode::slotContactMethodCountChanged(int count, int oldCount)
for
(
int
i
=
count
;
i
<
oldCount
;
i
++
)
{
for
(
int
i
=
count
;
i
<
oldCount
;
i
++
)
{
ContactTreeNode
*
n2
=
new
ContactTreeNode
(
m_pContact
->
phoneNumbers
()[
i
],
m_pModel
);
ContactTreeNode
*
n2
=
new
ContactTreeNode
(
m_pContact
->
phoneNumbers
()[
i
],
m_pModel
);
n2
->
m_Index
=
m_lChildren
.
size
();
n2
->
m_Index
=
m_lChildren
.
size
();
n2
->
m_p
Parent
=
this
;
n2
->
set
Parent
(
this
)
;
m_lChildren
<<
n2
;
m_lChildren
<<
n2
;
}
}
m_pModel
->
endInsertRows
();
m_pModel
->
endInsertRows
();
...
@@ -187,6 +196,35 @@ void ContactTreeNode::slotContactMethodCountAboutToChange(int count, int oldCoun
...
@@ -187,6 +196,35 @@ void ContactTreeNode::slotContactMethodCountAboutToChange(int count, int oldCoun
}
}
}
}
void
ContactTreeNode
::
setParent
(
ContactTreeNode
*
p
)
{
if
(
p
&&
p
!=
m_pParent
&&
p
->
m_Type
==
NodeType
::
CATEGORY
)
{
p
->
m_VisibleCounter
+=
m_Visible
?
1
:
0
;
const
bool
hasChanged
=
p
->
m_Visible
!=
p
->
m_VisibleCounter
>
0
;
p
->
m_Visible
=
p
->
m_VisibleCounter
>
0
;
if
(
hasChanged
)
{
const
QModelIndex
idx
=
m_pModel
->
index
(
p
->
m_Index
,
0
);
emit
m_pModel
->
dataChanged
(
idx
,
idx
);
}
}
m_pParent
=
p
;
}
void
ContactTreeNode
::
setVisible
(
bool
v
)
{
if
(
v
!=
m_Visible
)
{
if
(
m_pParent
)
{
m_pParent
->
m_VisibleCounter
+=
v
?
1
:
-
1
;
m_pParent
->
m_Visible
=
m_pParent
->
m_VisibleCounter
>
0
;
}
m_Visible
=
v
;
const
QModelIndex
idx
=
m_pModel
->
index
(
m_Index
,
0
,
m_pParent
?
m_pModel
->
index
(
m_pParent
->
m_Index
,
0
)
:
QModelIndex
()
);
emit
m_pModel
->
dataChanged
(
idx
,
idx
);
}
}
CategorizedContactModelPrivate
::
CategorizedContactModelPrivate
(
CategorizedContactModel
*
parent
)
:
QObject
(
parent
),
q_ptr
(
parent
),
CategorizedContactModelPrivate
::
CategorizedContactModelPrivate
(
CategorizedContactModel
*
parent
)
:
QObject
(
parent
),
q_ptr
(
parent
),
m_lCategoryCounter
(),
m_Role
(
Qt
::
DisplayRole
),
m_SortAlphabetical
(
true
),
m_UnreachableHidden
(
false
),
m_pSortedProxy
(
nullptr
)
m_lCategoryCounter
(),
m_Role
(
Qt
::
DisplayRole
),
m_SortAlphabetical
(
true
),
m_UnreachableHidden
(
false
),
m_pSortedProxy
(
nullptr
)
{
{
...
@@ -283,19 +321,20 @@ void CategorizedContactModelPrivate::slotContactAdded(const Person* c)
...
@@ -283,19 +321,20 @@ void CategorizedContactModelPrivate::slotContactAdded(const Person* c)
const
QString
val
=
category
(
c
);
const
QString
val
=
category
(
c
);
ContactTreeNode
*
item
=
getContactTopLevelItem
(
val
);
ContactTreeNode
*
item
=
getContactTopLevelItem
(
val
);
ContactTreeNode
*
contactNode
=
new
ContactTreeNode
(
c
,
q_ptr
);
ContactTreeNode
*
contactNode
=
new
ContactTreeNode
(
c
,
q_ptr
);
contactNode
->
m_p
Parent
=
item
;
contactNode
->
set
Parent
(
item
)
;
contactNode
->
m_Index
=
item
->
m_lChildren
.
size
();
contactNode
->
m_Index
=
item
->
m_lChildren
.
size
();
//emit layoutAboutToBeChanged();
//emit layoutAboutToBeChanged();
q_ptr
->
beginInsertRows
(
q_ptr
->
index
(
item
->
m_Index
,
0
,
QModelIndex
()),
item
->
m_lChildren
.
size
(),
item
->
m_lChildren
.
size
());
{
q_ptr
->
beginInsertRows
(
q_ptr
->
index
(
item
->
m_Index
,
0
,
QModelIndex
()),
item
->
m_lChildren
.
size
(),
item
->
m_lChildren
.
size
());
{
item
->
m_lChildren
<<
contactNode
;
item
->
m_lChildren
<<
contactNode
;
}
q_ptr
->
endInsertRows
();
}
q_ptr
->
endInsertRows
();
reloadTreeVisibility
(
item
);
if
(
c
->
phoneNumbers
().
size
()
>
1
)
{
if
(
c
->
phoneNumbers
().
size
()
>
1
)
{
q_ptr
->
beginInsertRows
(
q_ptr
->
createIndex
(
contactNode
->
m_Index
,
0
,
contactNode
),
0
,
c
->
phoneNumbers
().
size
()
-
1
);
q_ptr
->
beginInsertRows
(
q_ptr
->
createIndex
(
contactNode
->
m_Index
,
0
,
contactNode
),
0
,
c
->
phoneNumbers
().
size
()
-
1
);
for
(
ContactMethod
*
m
:
c
->
phoneNumbers
()
)
{
for
(
ContactMethod
*
m
:
c
->
phoneNumbers
()
)
{
//TODO check if this can be merged with slotContactMethodCountChanged
ContactTreeNode
*
n2
=
new
ContactTreeNode
(
m
,
q_ptr
);
ContactTreeNode
*
n2
=
new
ContactTreeNode
(
m
,
q_ptr
);
n2
->
m_Index
=
contactNode
->
m_lChildren
.
size
();
n2
->
m_Index
=
contactNode
->
m_lChildren
.
size
();
n2
->
m_p
Parent
=
contactNode
;
n2
->
set
Parent
(
contactNode
)
;
contactNode
->
m_lChildren
<<
n2
;
contactNode
->
m_lChildren
<<
n2
;
}
}
q_ptr
->
endInsertRows
();
q_ptr
->
endInsertRows
();
...
@@ -419,10 +458,9 @@ Qt::ItemFlags CategorizedContactModel::flags( const QModelIndex& index ) const
...
@@ -419,10 +458,9 @@ Qt::ItemFlags CategorizedContactModel::flags( const QModelIndex& index ) const
const
ContactTreeNode
*
modelNode
=
static_cast
<
ContactTreeNode
*>
(
index
.
internalPointer
());
const
ContactTreeNode
*
modelNode
=
static_cast
<
ContactTreeNode
*>
(
index
.
internalPointer
());
return
((
modelNode
->
m_Visible
)
?
Qt
::
ItemIsEnabled
:
Qt
::
NoItemFlags
)
return
(
modelNode
->
m_Visible
)
?
Qt
::
ItemIsEnabled
|
Qt
::
ItemIsSelectable
|
(
|
Qt
::
ItemIsSelectable
modelNode
->
m_pParent
?
(
Qt
::
ItemIsDragEnabled
|
Qt
::
ItemIsDropEnabled
)
:
Qt
::
NoItemFlags
|
(
modelNode
->
m_pParent
?
(
Qt
::
ItemIsDragEnabled
|
Qt
::
ItemIsDropEnabled
)
:
Qt
::
ItemIsEnabled
)
:
Qt
::
NoItemFlags
;
);
}
}
int
CategorizedContactModel
::
columnCount
(
const
QModelIndex
&
parent
)
const
int
CategorizedContactModel
::
columnCount
(
const
QModelIndex
&
parent
)
const
...
@@ -586,7 +624,7 @@ void CategorizedContactModelPrivate::reloadTreeVisibility( ContactTreeNode* node
...
@@ -586,7 +624,7 @@ void CategorizedContactModelPrivate::reloadTreeVisibility( ContactTreeNode* node
switch
(
node
->
m_Type
)
{
switch
(
node
->
m_Type
)
{
case
ContactTreeNode
::
NodeType
::
PERSON
:
case
ContactTreeNode
::
NodeType
::
PERSON
:
node
->
m_
Visible
=
node
->
m_pContact
->
isActive
()
&&
((
!
m_UnreachableHidden
)
||
node
->
m_pContact
->
isReachable
());
node
->
set
Visible
(
node
->
m_pContact
->
isActive
()
&&
((
!
m_UnreachableHidden
)
||
node
->
m_pContact
->
isReachable
())
)
;
break
;
break
;
case
ContactTreeNode
::
NodeType
::
CONTACTMETHOD
:
case
ContactTreeNode
::
NodeType
::
CONTACTMETHOD
:
//Nothing to do
//Nothing to do
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment