@@ -53,19 +53,22 @@ void FlatMenuProxyModel::setSourceModel(QAbstractItemModel *source)
5353 QAbstractProxyModel::setSourceModel(source);
5454
5555 if (source) {
56+
57+ // FIXME - not working correctly with dynamic inserts/removes
58+
5659 connect(source,
5760 SIGNAL(rowsAboutToBeInserted(QModelIndex,int,int)),
58− SLOT(onRowsAboutToBeInserted(QModelIndex,int,int)));
61+ SLOT(onModelAboutToBeReset()));
5962 connect(source,
6063 SIGNAL(rowsInserted(QModelIndex,int,int)),
61− SLOT(onRowsInserted(QModelIndex,int,int)));
64+ SLOT(onModelReset()));
6265
6366 connect(source,
6467 SIGNAL(rowsAboutToBeRemoved(QModelIndex,int,int)),
65− SLOT(onRowsAboutToBeRemoved(QModelIndex,int,int)));
68+ SLOT(onModelAboutToBeReset()));
6669 connect(source,
6770 SIGNAL(rowsRemoved(QModelIndex,int,int)),
68− SLOT(onRowsRemoved(QModelIndex,int,int)));
71+ SLOT(onModelReset()));
6972
7073 connect(source,
7174 SIGNAL(modelAboutToBeReset()),
@@ -74,16 +77,6 @@ void FlatMenuProxyModel::setSourceModel(QAbstractItemModel *source)
7477 SIGNAL(modelReset()),
7578 SLOT(onModelReset()));
7679
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−
8780 // initiliaze rowCount
8881 QModelIndex lastItem = source->index(source->rowCount() - 1, 0);
8982 m_rowCount = recursiveRowCount(lastItem);
@@ -209,66 +202,11 @@ int FlatMenuProxyModel::count() const
209202 return rowCount(QModelIndex());
210203}
211204
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−
236205void FlatMenuProxyModel::onModelAboutToBeReset()
237206{
238207 beginResetModel();
239208}
240209
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−
272210void FlatMenuProxyModel::onModelReset()
273211{
274212 // initiliaze rowCount
@@ -282,6 +220,60 @@ void FlatMenuProxyModel::onModelReset()
282220 Q_EMIT countChanged();
283221}
284222
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+
285277int FlatMenuProxyModel::recursiveRowCount(const QModelIndex &index) const
286278{
287279 int size = sourceModel()->rowCount(index);