Changeset View
Changeset View
Standalone View
Standalone View
src/helper.cpp
Show First 20 Lines • Show All 56 Lines • ▼ Show 20 Line(s) | |||||
57 | } | 57 | } | ||
58 | 58 | | |||
59 | QColor EventViews::resourceColor(const Akonadi::Collection &coll, const PrefsPtr &preferences) | 59 | QColor EventViews::resourceColor(const Akonadi::Collection &coll, const PrefsPtr &preferences) | ||
60 | { | 60 | { | ||
61 | if (!coll.isValid()) { | 61 | if (!coll.isValid()) { | ||
62 | return QColor(); | 62 | return QColor(); | ||
63 | } | 63 | } | ||
64 | const QString id = QString::number(coll.id()); | 64 | const QString id = QString::number(coll.id()); | ||
65 | // Color stored in eventviewsrc (and in memory) | ||||
65 | QColor color = preferences->resourceColorKnown(id); | 66 | QColor color = preferences->resourceColorKnown(id); | ||
66 | if (!color.isValid() && coll.hasAttribute<Akonadi::CollectionColorAttribute>()) { | 67 | if (color.isValid()) { | ||
68 | return color; | ||||
69 | } | ||||
70 | // Color stored in akonadi | ||||
71 | if (coll.hasAttribute<Akonadi::CollectionColorAttribute>()) { | ||||
dkurz: You might want to invert the condition here and return early, to reduce the indentation of the… | |||||
That would duplicate the call to resourceColor: if (!hasAttribute) return preferences->resourceColor(id); if (colorAttr && colorAttr->color().isValid()) return colorAttr->color(); return preferences->resourceColor(id); Not great IMHO. dfaure: That would duplicate the call to resourceColor:
```
if (!hasAttribute)
return preferences… | |||||
67 | Akonadi::CollectionColorAttribute *colorAttr | 72 | Akonadi::CollectionColorAttribute *colorAttr | ||
68 | = coll.attribute<Akonadi::CollectionColorAttribute>(); | 73 | = coll.attribute<Akonadi::CollectionColorAttribute>(); | ||
69 | if (colorAttr && colorAttr->color().isValid()) { | 74 | if (colorAttr && colorAttr->color().isValid()) { | ||
70 | color = colorAttr->color(); | 75 | return colorAttr->color(); | ||
71 | } else { | | |||
72 | return preferences->resourceColor(id); | | |||
73 | } | 76 | } | ||
74 | } | 77 | } | ||
75 | return color; | 78 | // Generate new color and store it in eventsviewsrc (and in memory) | ||
79 | return preferences->resourceColor(id); | ||||
76 | } | 80 | } | ||
77 | 81 | | |||
78 | QColor EventViews::resourceColor(const Akonadi::Item &item, const PrefsPtr &preferences) | 82 | QColor EventViews::resourceColor(const Akonadi::Item &item, const PrefsPtr &preferences) | ||
79 | { | 83 | { | ||
80 | if (!item.isValid()) { | 84 | if (!item.isValid()) { | ||
81 | return QColor(); | 85 | return QColor(); | ||
82 | } | 86 | } | ||
83 | const QString id = QString::number(item.parentCollection().id()); | 87 | return resourceColor(item.parentCollection(), preferences); | ||
84 | | ||||
85 | QColor color = preferences->resourceColorKnown(id); | | |||
86 | if (!color.isValid() | | |||
87 | && item.parentCollection().hasAttribute<Akonadi::CollectionColorAttribute>()) { | | |||
88 | Akonadi::CollectionColorAttribute *colorAttr | | |||
89 | = item.parentCollection().attribute<Akonadi::CollectionColorAttribute>(); | | |||
90 | if (colorAttr && colorAttr->color().isValid()) { | | |||
91 | color = colorAttr->color(); | | |||
92 | } else { | | |||
93 | return preferences->resourceColor(id); | | |||
94 | } | | |||
95 | } | | |||
96 | return color; | | |||
97 | } | 88 | } | ||
98 | 89 | | |||
99 | int EventViews::yearDiff(const QDate &start, const QDate &end) | 90 | int EventViews::yearDiff(const QDate &start, const QDate &end) | ||
100 | { | 91 | { | ||
101 | return end.year() - start.year(); | 92 | return end.year() - start.year(); | ||
102 | } | 93 | } | ||
103 | 94 | | |||
104 | QPixmap EventViews::cachedSmallIcon(const QString &name) | 95 | QPixmap EventViews::cachedSmallIcon(const QString &name) | ||
105 | { | 96 | { | ||
106 | return QIcon::fromTheme(name).pixmap(16, 16); | 97 | return QIcon::fromTheme(name).pixmap(16, 16); | ||
107 | } | 98 | } |
You might want to invert the condition here and return early, to reduce the indentation of the following lines, but I guess this is just a matter of taste.