Changeset View
Changeset View
Standalone View
Standalone View
src/imports/activitymodel.h
Show All 18 Lines | |||||
19 | 19 | | |||
20 | #ifndef KACTIVITIES_IMPORTS_ACTIVITY_MODEL_H | 20 | #ifndef KACTIVITIES_IMPORTS_ACTIVITY_MODEL_H | ||
21 | #define KACTIVITIES_IMPORTS_ACTIVITY_MODEL_H | 21 | #define KACTIVITIES_IMPORTS_ACTIVITY_MODEL_H | ||
22 | 22 | | |||
23 | // Qt | 23 | // Qt | ||
24 | #include <QObject> | 24 | #include <QObject> | ||
25 | #include <QAbstractListModel> | 25 | #include <QAbstractListModel> | ||
26 | #include <QJSValue> | 26 | #include <QJSValue> | ||
27 | #include <QCollator> | ||||
27 | 28 | | |||
28 | // STL and Boost | 29 | // STL and Boost | ||
29 | #include <boost/container/flat_set.hpp> | 30 | #include <boost/container/flat_set.hpp> | ||
30 | #include <memory> | 31 | #include <memory> | ||
31 | 32 | | |||
32 | // Local | 33 | // Local | ||
33 | #include <lib/controller.h> | 34 | #include <lib/controller.h> | ||
34 | #include <lib/consumer.h> | 35 | #include <lib/consumer.h> | ||
▲ Show 20 Lines • Show All 88 Lines • ▼ Show 20 Line(s) | |||||
123 | private: | 124 | private: | ||
124 | KActivities::Controller m_service; | 125 | KActivities::Controller m_service; | ||
125 | boost::container::flat_set<State> m_shownStates; | 126 | boost::container::flat_set<State> m_shownStates; | ||
126 | QString m_shownStatesString; | 127 | QString m_shownStatesString; | ||
127 | 128 | | |||
128 | typedef std::shared_ptr<Info> InfoPtr; | 129 | typedef std::shared_ptr<Info> InfoPtr; | ||
129 | 130 | | |||
130 | struct InfoPtrComparator { | 131 | struct InfoPtrComparator { | ||
131 | bool operator() (const InfoPtr& left, const InfoPtr& right) const | 132 | bool operator() (const InfoPtr& left, const InfoPtr& right) const | ||
apol: Do you think it would be possible to store the collator elsewhere?
Re-creating it is a bit… | |||||
132 | { | 133 | { | ||
133 | const QString &leftName = left->name().toLower(); | 134 | QCollator c; | ||
134 | const QString &rightName = right->name().toLower(); | 135 | c.setCaseSensitivity(Qt::CaseInsensitive); | ||
135 | 136 | c.setNumericMode(true); | |||
136 | return | 137 | int rc = c.compare(left->name(), right->name()); | ||
137 | (leftName < rightName) || | 138 | if (rc == 0) { | ||
138 | (leftName == rightName && left->id() < right->id()); | 139 | return left->id() < right->id(); | ||
140 | } | ||||
141 | return rc < 0; | ||||
139 | } | 142 | } | ||
140 | }; | 143 | }; | ||
141 | 144 | | |||
142 | boost::container::flat_set<InfoPtr, InfoPtrComparator> m_knownActivities; | 145 | boost::container::flat_set<InfoPtr, InfoPtrComparator> m_knownActivities; | ||
143 | boost::container::flat_set<InfoPtr, InfoPtrComparator> m_shownActivities; | 146 | boost::container::flat_set<InfoPtr, InfoPtrComparator> m_shownActivities; | ||
144 | 147 | | |||
145 | InfoPtr registerActivity(const QString &id); | 148 | InfoPtr registerActivity(const QString &id); | ||
146 | void unregisterActivity(const QString &id); | 149 | void unregisterActivity(const QString &id); | ||
Show All 15 Lines |
Do you think it would be possible to store the collator elsewhere?
Re-creating it is a bit expensive to be doing it nlogn times per sort (not that it won't work).
We don't support changing the application language at runtime (env vars don't change at runtime), so it shouldn't be a big deal (it could even be a static variable).