From 4605c0113792d7874fba5dbb5efff1b561b5d89c Mon Sep 17 00:00:00 2001 From: Stepan Salenikovich <stepan.salenikovich@savoirfairelinux.com> Date: Thu, 11 May 2017 16:47:56 -0400 Subject: [PATCH] Person: implement Ring::Role::Number role MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit It returns the bestId() of the lastUsedContactMethod(). This way views will not get an empty QVariant when asking for the number role from a Person item. This also makes sense as what we want to show most of the time and most of the time a Person will only have one ContactMethod anyways. Change-Id: I0edea8c4fe3f6848a523c4f88d3115cf13b20938 Reviewed-by: Nicolas Jäger <nicolas.jager@savoirfairelinux.com> --- src/person.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/person.cpp b/src/person.cpp index c127629c..e041be31 100644 --- a/src/person.cpp +++ b/src/person.cpp @@ -596,6 +596,11 @@ QVariant Person::roleData(int role) const case Qt::EditRole: case static_cast<int>(Ring::Role::Name): return QVariant(formattedName()); + case static_cast<int>(Ring::Role::Number): + { + auto cm = lastUsedContactMethod(); + return cm ? cm->bestId() : QString(); + } case Qt::DecorationRole: return GlobalInstances::pixmapManipulator().decorationRole(this); case static_cast<int>(Person::Role::Organization): -- GitLab