on xenial help sign in
more review changes. plugin renaming
6b9d8f5Nick Dedekind
modules/Unity/Indicators/indicatorsmodel.cpp+47−37
@@ -30,7 +30,7 @@
30 \qmltype IndicatorsModel
30 \qmltype IndicatorsModel
31 \inherits QAbstractListModel
31 \inherits QAbstractListModel
32
32
33− \brief The IndicatorsModel class defines the list model for indicators plugins
33+ \brief The IndicatorsModel class defines the list model for indicators
34
34
35 \b {This component is under heavy development.}
35 \b {This component is under heavy development.}
36
36
@@ -81,18 +81,18 @@ int IndicatorsModel::count() const
81/*!
81/*!
82 \qmlmethod IndicatorsModel::unload()
82 \qmlmethod IndicatorsModel::unload()
83
83
84− Load all plugins.
84+ Load all indicators.
85*/
85*/
86void IndicatorsModel::load()
86void IndicatorsModel::load()
87{
87{
88− m_plugins.clear();
88+ m_indicators.clear();
89 m_manager->load();
89 m_manager->load();
90}
90}
91
91
92/*!
92/*!
93 \qmlmethod IndicatorsModel::unload()
93 \qmlmethod IndicatorsModel::unload()
94
94
95− Unload all plugins.
95+ Unload all indicators.
96*/
96*/
97void IndicatorsModel::unload()
97void IndicatorsModel::unload()
98{
98{
@@ -100,49 +100,57 @@ void IndicatorsModel::unload()
100}
100}
101
101
102/*! \internal */
102/*! \internal */
103−void IndicatorsModel::onIndicatorLoaded(const QString& indicator)
103+void IndicatorsModel::onIndicatorLoaded(const QString& indicator_name)
104{
104{
105− Indicator::Ptr plugin = m_manager->indicator(indicator);
105+ Indicator::Ptr indicator = m_manager->indicator(indicator_name);
106− if (!plugin)
106+ if (!indicator)
107+ {
107 return;
108 return;
109+ }
108
110
109− if (m_plugins.indexOf(plugin) >= 0)
111+ if (m_indicators.indexOf(indicator) >= 0)
112+ {
110 return;
113 return;
114+ }
111
115
112 // find the insert position
116 // find the insert position
113 int pos = 0;
117 int pos = 0;
114− while (pos < count()) {
118+ while (pos < count())
119+ {
115 // keep going while the existing priority is less.
120 // keep going while the existing priority is less.
116− if (indicatorData(plugin, Priority).toInt() < data(index(pos), Priority).toInt())
121+ if (indicatorData(indicator, Priority).toInt() < data(index(pos), Priority).toInt())
117 break;
122 break;
118 pos++;
123 pos++;
119 }
124 }
120
125
121− QObject::connect(plugin.data(), SIGNAL(identifierChanged(const QString&)), this, SLOT(onIdentifierChanged()));
126+ QObject::connect(indicator.data(), SIGNAL(identifierChanged(const QString&)), this, SLOT(onIdentifierChanged()));
122− QObject::connect(plugin.data(), SIGNAL(indicatorPropertiesChanged(const QVariant&)), this, SLOT(onIndicatorPropertiesChanged()));
127+ QObject::connect(indicator.data(), SIGNAL(indicatorPropertiesChanged(const QVariant&)), this, SLOT(onIndicatorPropertiesChanged()));
123
128
124 beginInsertRows(QModelIndex(), pos, pos);
129 beginInsertRows(QModelIndex(), pos, pos);
125
130
126− m_plugins.insert(pos, plugin);
131+ m_indicators.insert(pos, indicator);
127 endInsertRows();
132 endInsertRows();
128}
133}
129
134
130/*! \internal */
135/*! \internal */
131−void IndicatorsModel::onIndicatorAboutToBeUnloaded(const QString& indicator)
136+void IndicatorsModel::onIndicatorAboutToBeUnloaded(const QString& indicator_name)
132{
137{
133− Indicator::Ptr plugin = m_manager->indicator(indicator);
138+ Indicator::Ptr indicator = m_manager->indicator(indicator_name);
134− if (!plugin)
139+ if (!indicator)
140+ {
135 return;
141 return;
142+ }
136
143
137 int i = 0;
144 int i = 0;
138− QMutableListIterator<Indicator::Ptr> iter(m_plugins);
145+ QMutableListIterator<Indicator::Ptr> iter(m_indicators);
139 while(iter.hasNext())
146 while(iter.hasNext())
140 {
147 {
141− if (plugin == iter.next())
148+ if (indicator == iter.next())
142 {
149 {
143 beginRemoveRows(QModelIndex(), i, i);
150 beginRemoveRows(QModelIndex(), i, i);
144 iter.remove();
151 iter.remove();
145 endRemoveRows();
152 endRemoveRows();
153+ break;
146 }
154 }
147 i++;
155 i++;
148 }
156 }
@@ -164,15 +172,17 @@ void IndicatorsModel::onIndicatorPropertiesChanged()
164/*! \internal */
172/*! \internal */
165void IndicatorsModel::notifyDataChanged(QObject *sender, int role)
173void IndicatorsModel::notifyDataChanged(QObject *sender, int role)
166{
174{
167− Indicator* plugin = qobject_cast<Indicator*>(sender);
175+ Indicator* indicator = qobject_cast<Indicator*>(sender);
168− if (!plugin)
176+ if (!indicator)
177+ {
169 return;
178 return;
179+ }
170
180
171 int index = 0;
181 int index = 0;
172− QMutableListIterator<Indicator::Ptr> iter(m_plugins);
182+ QMutableListIterator<Indicator::Ptr> iter(m_indicators);
173 while(iter.hasNext())
183 while(iter.hasNext())
174 {
184 {
175− if (iter.next().data() == plugin)
185+ if (indicator == iter.next())
176 {
186 {
177 QModelIndex changedIndex = this->index(index);
187 QModelIndex changedIndex = this->index(index);
178 dataChanged(changedIndex, changedIndex, QVector<int>() << role);
188 dataChanged(changedIndex, changedIndex, QVector<int>() << role);
@@ -207,14 +217,14 @@ int IndicatorsModel::columnCount(const QModelIndex &) const
207}
217}
208
218
209/*! \internal */
219/*! \internal */
210−QVariant IndicatorsModel::defaultData(Indicator::Ptr plugin, int role)
220+QVariant IndicatorsModel::defaultData(Indicator::Ptr indicator, int role)
211{
221{
212 switch (role)
222 switch (role)
213 {
223 {
214 case Priority:
224 case Priority:
215 return 0;
225 return 0;
216 case Title:
226 case Title:
217− return plugin ? plugin->identifier() : "Unknown";
227+ return indicator ? indicator->identifier() : "Unknown";
218 case Description:
228 case Description:
219 return "";
229 return "";
220 case WidgetSource:
230 case WidgetSource:
@@ -233,47 +243,47 @@ Q_INVOKABLE QVariant IndicatorsModel::data(int row, int role) const
233/*! \internal */
243/*! \internal */
234QVariant IndicatorsModel::data(const QModelIndex &index, int role) const
244QVariant IndicatorsModel::data(const QModelIndex &index, int role) const
235{
245{
236− if (!index.isValid() || index.row() >= m_plugins.size())
246+ if (!index.isValid() || index.row() >= m_indicators.size())
237 return QVariant();
247 return QVariant();
238
248
239− Indicator::Ptr plugin = m_plugins[index.row()];
249+ Indicator::Ptr indicator = m_indicators[index.row()];
240
250
241 switch (role)
251 switch (role)
242 {
252 {
243 case Identifier:
253 case Identifier:
244− if (plugin)
254+ if (indicator)
245 {
255 {
246− return QVariant(plugin->identifier());
256+ return QVariant(indicator->identifier());
247 }
257 }
248 break;
258 break;
249 case IndicatorProperties:
259 case IndicatorProperties:
250− if (plugin)
260+ if (indicator)
251 {
261 {
252− return QVariant(plugin->indicatorProperties());
262+ return QVariant(indicator->indicatorProperties());
253 }
263 }
254 break;
264 break;
255 case IsValid:
265 case IsValid:
256− return (plugin ? true : false);
266+ return (indicator ? true : false);
257 case Priority:
267 case Priority:
258 case Title:
268 case Title:
259 case Description:
269 case Description:
260 case WidgetSource:
270 case WidgetSource:
261 case PageSource:
271 case PageSource:
262− return indicatorData(plugin, role);
272+ return indicatorData(indicator, role);
263 default:
273 default:
264 break;
274 break;
265 }
275 }
266 return QVariant();
276 return QVariant();
267}
277}
268
278
269−QVariant IndicatorsModel::indicatorData(const Indicator::Ptr& plugin, int role) const
279+QVariant IndicatorsModel::indicatorData(const Indicator::Ptr& indicator, int role) const
270{
280{
271− if (plugin && m_parsed_indicator_data.contains(plugin->identifier()))
281+ if (indicator && m_parsed_indicator_data.contains(indicator->identifier()))
272 {
282 {
273− QVariantMap data = m_parsed_indicator_data[plugin->identifier()];
283+ QVariantMap data = m_parsed_indicator_data[indicator->identifier()];
274 return data.value(roleNames()[role], QVariant());
284 return data.value(roleNames()[role], QVariant());
275 }
285 }
276− return defaultData(plugin, role);
286+ return defaultData(indicator, role);
277}
287}
278
288
279/*! \internal */
289/*! \internal */
@@ -285,7 +295,7 @@ QModelIndex IndicatorsModel::parent(const QModelIndex&) const
285/*! \internal */
295/*! \internal */
286int IndicatorsModel::rowCount(const QModelIndex&) const
296int IndicatorsModel::rowCount(const QModelIndex&) const
287{
297{
288− return m_plugins.count();
298+ return m_indicators.count();
289}
299}
290
300
291void IndicatorsModel::setIndicatorData(const QVariant& data)
301void IndicatorsModel::setIndicatorData(const QVariant& data)
modules/Unity/Indicators/indicatorsmodel.h+1−1
@@ -78,7 +78,7 @@ private Q_SLOTS:
78private:
78private:
79 IndicatorsManager *m_manager;
79 IndicatorsManager *m_manager;
80
80
81− QList<Indicator::Ptr> m_plugins;
81+ QList<Indicator::Ptr> m_indicators;
82 QVariant m_indicator_data;
82 QVariant m_indicator_data;
83 QMap<QString, QVariantMap> m_parsed_indicator_data;
83 QMap<QString, QVariantMap> m_parsed_indicator_data;
84
84