diff options
Diffstat (limited to 'framework')
-rw-r--r-- | framework/src/domain/peoplemodel.cpp | 33 |
1 files changed, 29 insertions, 4 deletions
diff --git a/framework/src/domain/peoplemodel.cpp b/framework/src/domain/peoplemodel.cpp index 108cab48..f52ac53f 100644 --- a/framework/src/domain/peoplemodel.cpp +++ b/framework/src/domain/peoplemodel.cpp | |||
@@ -79,6 +79,19 @@ static QStringList toStringList(const QList<Sink::ApplicationDomain::Contact::Em | |||
79 | return out; | 79 | return out; |
80 | } | 80 | } |
81 | 81 | ||
82 | QPair<QString, QString> getFirstnameLastname(const QString &fn) | ||
83 | { | ||
84 | auto parts = fn.split(' '); | ||
85 | if (parts.isEmpty()) { | ||
86 | return {}; | ||
87 | } | ||
88 | if (parts.size() == 1) { | ||
89 | return {parts.first(), {}}; | ||
90 | } | ||
91 | const auto lastName = parts.takeLast(); | ||
92 | return {parts.join(' '), lastName}; | ||
93 | } | ||
94 | |||
82 | QVariant PeopleModel::data(const QModelIndex &idx, int role) const | 95 | QVariant PeopleModel::data(const QModelIndex &idx, int role) const |
83 | { | 96 | { |
84 | auto srcIdx = mapToSource(idx); | 97 | auto srcIdx = mapToSource(idx); |
@@ -94,10 +107,22 @@ QVariant PeopleModel::data(const QModelIndex &idx, int role) const | |||
94 | return "contact"; | 107 | return "contact"; |
95 | case DomainObject: | 108 | case DomainObject: |
96 | return QVariant::fromValue(contact); | 109 | return QVariant::fromValue(contact); |
97 | case FirstName: | 110 | case FirstName: { |
98 | return contact->getFirstname(); | 111 | const auto n = contact->getFirstname(); |
99 | case LastName: | 112 | //Fall back to the fn if we have no name |
100 | return contact->getLastname(); | 113 | if (n.isEmpty()) { |
114 | return getFirstnameLastname(contact->getFn()).first; | ||
115 | } | ||
116 | return n; | ||
117 | } | ||
118 | case LastName: { | ||
119 | const auto n = contact->getLastname(); | ||
120 | //Fall back to the fn if we have no name | ||
121 | if (n.isEmpty()) { | ||
122 | return getFirstnameLastname(contact->getFn()).second; | ||
123 | } | ||
124 | return n; | ||
125 | } | ||
101 | case ImageData: | 126 | case ImageData: |
102 | return contact->getPhoto(); | 127 | return contact->getPhoto(); |
103 | } | 128 | } |