on xenial help sign in
removed dynamic insert/remove. replaced with model reset
4787a4fNick Dedekind
modules/IndicatorsClient/flatmenuproxymodel.cpp+61−69
@@ -53,19 +53,22 @@ void FlatMenuProxyModel::setSourceModel(QAbstractItemModel *source)
53 QAbstractProxyModel::setSourceModel(source);
53 QAbstractProxyModel::setSourceModel(source);
54
54
55 if (source) {
55 if (source) {
56+
57+ // FIXME - not working correctly with dynamic inserts/removes
58+
56 connect(source,
59 connect(source,
57 SIGNAL(rowsAboutToBeInserted(QModelIndex,int,int)),
60 SIGNAL(rowsAboutToBeInserted(QModelIndex,int,int)),
58− SLOT(onRowsAboutToBeInserted(QModelIndex,int,int)));
61+ SLOT(onModelAboutToBeReset()));
59 connect(source,
62 connect(source,
60 SIGNAL(rowsInserted(QModelIndex,int,int)),
63 SIGNAL(rowsInserted(QModelIndex,int,int)),
61− SLOT(onRowsInserted(QModelIndex,int,int)));
64+ SLOT(onModelReset()));
62
65
63 connect(source,
66 connect(source,
64 SIGNAL(rowsAboutToBeRemoved(QModelIndex,int,int)),
67 SIGNAL(rowsAboutToBeRemoved(QModelIndex,int,int)),
65− SLOT(onRowsAboutToBeRemoved(QModelIndex,int,int)));
68+ SLOT(onModelAboutToBeReset()));
66 connect(source,
69 connect(source,
67 SIGNAL(rowsRemoved(QModelIndex,int,int)),
70 SIGNAL(rowsRemoved(QModelIndex,int,int)),
68− SLOT(onRowsRemoved(QModelIndex,int,int)));
71+ SLOT(onModelReset()));
69
72
70 connect(source,
73 connect(source,
71 SIGNAL(modelAboutToBeReset()),
74 SIGNAL(modelAboutToBeReset()),
@@ -74,16 +77,6 @@ void FlatMenuProxyModel::setSourceModel(QAbstractItemModel *source)
74 SIGNAL(modelReset()),
77 SIGNAL(modelReset()),
75 SLOT(onModelReset()));
78 SLOT(onModelReset()));
76
79
77− connect(source,
78− SIGNAL(rowsInserted(QModelIndex,int,int)),
79− SIGNAL(countChanged()));
80− connect(source,
81− SIGNAL(rowsRemoved(QModelIndex,int,int)),
82− SIGNAL(countChanged()));
83− connect(source,
84− SIGNAL(modelReset()),
85− SIGNAL(countChanged()));
86−
87 // initiliaze rowCount
80 // initiliaze rowCount
88 QModelIndex lastItem = source->index(source->rowCount() - 1, 0);
81 QModelIndex lastItem = source->index(source->rowCount() - 1, 0);
89 m_rowCount = recursiveRowCount(lastItem);
82 m_rowCount = recursiveRowCount(lastItem);
@@ -209,66 +202,11 @@ int FlatMenuProxyModel::count() const
209 return rowCount(QModelIndex());
202 return rowCount(QModelIndex());
210}
203}
211
204
212−void FlatMenuProxyModel::onRowsAboutToBeInserted(const QModelIndex &index, int first, int last)
213−{
214−
215− if (index.isValid()) {
216− int firstIndex = rowOffsetOf(index, first);
217− int lastIndex = rowOffsetOf(index, last, true);
218−
219− beginInsertRows(QModelIndex(), firstIndex, lastIndex);
220− m_rowCount += (lastIndex - firstIndex + 1);
221− }
222−}
223−
224−void FlatMenuProxyModel::onRowsAboutToBeRemoved(const QModelIndex &index, int first, int last)
225−{
226− if (index.isValid()) {
227− int firstIndex = rowOffsetOf(index, first);
228− int lastIndex = rowOffsetOf(index, last, true);
229−
230− m_indexCache.clear();
231− beginRemoveRows(QModelIndex(), firstIndex, lastIndex);
232− m_rowCount -= (lastIndex - firstIndex + 1);
233− }
234−}
235−
236void FlatMenuProxyModel::onModelAboutToBeReset()
205void FlatMenuProxyModel::onModelAboutToBeReset()
237{
206{
238 beginResetModel();
207 beginResetModel();
239}
208}
240
209
241−void FlatMenuProxyModel::onRowsInserted(const QModelIndex &index, int first, int last)
242−{
243− if (index.isValid()) {
244− m_indexCache.clear();
245− endInsertRows();
246− for (int i=first; i <= last; i++) {
247− QModelIndex subIndex = sourceModel()->index(i, 0, index.parent());
248− if (subIndex.isValid()) {
249− int subSectionSize = recursiveRowCount(subIndex);
250− if (subSectionSize > 0) {
251− int firstIndex = rowOffsetOf(index, i) + 1;
252− int lastIndex = rowOffsetOf(index, i, true);
253−
254− beginInsertRows(QModelIndex(), firstIndex, lastIndex);
255− m_rowCount += lastIndex - firstIndex + 1;
256− endInsertRows();
257− }
258− }
259− }
260− }
261− Q_EMIT countChanged();
262−}
263−
264−void FlatMenuProxyModel::onRowsRemoved(const QModelIndex &index, int, int)
265−{
266− if (index.isValid()) {
267− endRemoveRows();
268− Q_EMIT countChanged();
269− }
270−}
271−
272void FlatMenuProxyModel::onModelReset()
210void FlatMenuProxyModel::onModelReset()
273{
211{
274 // initiliaze rowCount
212 // initiliaze rowCount
@@ -282,6 +220,60 @@ void FlatMenuProxyModel::onModelReset()
282 Q_EMIT countChanged();
220 Q_EMIT countChanged();
283}
221}
284
222
223+// void FlatMenuProxyModel::onRowsAboutToBeInserted(const QModelIndex &index, int first, int last)
224+// {
225+// if (index.isValid()) {
226+// int firstIndex = rowOffsetOf(index, first);
227+// int lastIndex = rowOffsetOf(index, last, true);
228+
229+// beginInsertRows(QModelIndex(), firstIndex, lastIndex);
230+// m_rowCount += (lastIndex - firstIndex + 1);
231+// }
232+// }
233+
234+// void FlatMenuProxyModel::onRowsAboutToBeRemoved(const QModelIndex &index, int first, int last)
235+// {
236+// if (index.isValid()) {
237+// int firstIndex = rowOffsetOf(index, first);
238+// int lastIndex = rowOffsetOf(index, last, true);
239+
240+// m_indexCache.clear();
241+// beginRemoveRows(QModelIndex(), firstIndex, lastIndex);
242+// m_rowCount -= (lastIndex - firstIndex + 1);
243+// }
244+// }
245+
246+// void FlatMenuProxyModel::onRowsInserted(const QModelIndex &index, int first, int last)
247+// {
248+// if (index.isValid()) {
249+// m_indexCache.clear();
250+// endInsertRows();
251+// for (int i=first; i <= last; i++) {
252+// QModelIndex subIndex = sourceModel()->index(i, 0, index.parent());
253+// if (subIndex.isValid()) {
254+// int subSectionSize = recursiveRowCount(subIndex);
255+// if (subSectionSize > 0) {
256+// int firstIndex = rowOffsetOf(index, i) + 1;
257+// int lastIndex = rowOffsetOf(index, i, true);
258+
259+// beginInsertRows(QModelIndex(), firstIndex, lastIndex);
260+// m_rowCount += lastIndex - firstIndex + 1;
261+// endInsertRows();
262+// }
263+// }
264+// }
265+// }
266+// Q_EMIT countChanged();
267+// }
268+
269+// void FlatMenuProxyModel::onRowsRemoved(const QModelIndex &index, int, int)
270+// {
271+// if (index.isValid()) {
272+// endRemoveRows();
273+// Q_EMIT countChanged();
274+// }
275+// }
276+
285int FlatMenuProxyModel::recursiveRowCount(const QModelIndex &index) const
277int FlatMenuProxyModel::recursiveRowCount(const QModelIndex &index) const
286{
278{
287 int size = sourceModel()->rowCount(index);
279 int size = sourceModel()->rowCount(index);
modules/IndicatorsClient/flatmenuproxymodel.h+4−4
@@ -64,11 +64,11 @@ public:
64 Q_INVOKABLE QVariantMap get(int row) const;
64 Q_INVOKABLE QVariantMap get(int row) const;
65
65
66public Q_SLOTS:
66public Q_SLOTS:
67− void onRowsInserted(const QModelIndex &parent, int start, int end);
67+ // void onRowsInserted(const QModelIndex &parent, int start, int end);
68− void onRowsAboutToBeInserted(const QModelIndex &parent, int start, int end);
68+ // void onRowsAboutToBeInserted(const QModelIndex &parent, int start, int end);
69
69
70− void onRowsRemoved(const QModelIndex &parent, int start, int end);
70+ // void onRowsRemoved(const QModelIndex &parent, int start, int end);
71− void onRowsAboutToBeRemoved(const QModelIndex &parent, int start, int end);
71+ // void onRowsAboutToBeRemoved(const QModelIndex &parent, int start, int end);
72
72
73 void onModelAboutToBeReset();
73 void onModelAboutToBeReset();
74 void onModelReset();
74 void onModelReset();