@@ -53,19 +53,22 @@ void FlatMenuProxyModel::setSourceModel(QAbstractItemModel *source)
53 QAbstractProxyModel::setSourceModel(source);
53 QAbstractProxyModel::setSourceModel(source);
55 if (source) {
55 if (source) {
57+ // FIXME - not working correctly with dynamic inserts/removes
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()));
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()));
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()));
78− SIGNAL(rowsInserted(QModelIndex,int,int)),
79− SIGNAL(countChanged()));
81− SIGNAL(rowsRemoved(QModelIndex,int,int)),
82− SIGNAL(countChanged()));
84− SIGNAL(modelReset()),
85− SIGNAL(countChanged()));
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());
212−void FlatMenuProxyModel::onRowsAboutToBeInserted(const QModelIndex &index, int first, int last)
215− if (index.isValid()) {
216− int firstIndex = rowOffsetOf(index, first);
217− int lastIndex = rowOffsetOf(index, last, true);
219− beginInsertRows(QModelIndex(), firstIndex, lastIndex);
220− m_rowCount += (lastIndex - firstIndex + 1);
224−void FlatMenuProxyModel::onRowsAboutToBeRemoved(const QModelIndex &index, int first, int last)
226− if (index.isValid()) {
227− int firstIndex = rowOffsetOf(index, first);
228− int lastIndex = rowOffsetOf(index, last, true);
230− m_indexCache.clear();
231− beginRemoveRows(QModelIndex(), firstIndex, lastIndex);
232− m_rowCount -= (lastIndex - firstIndex + 1);
236void FlatMenuProxyModel::onModelAboutToBeReset()
205void FlatMenuProxyModel::onModelAboutToBeReset()
238 beginResetModel();
207 beginResetModel();
241−void FlatMenuProxyModel::onRowsInserted(const QModelIndex &index, int first, int last)
243− if (index.isValid()) {
244− m_indexCache.clear();
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);
254− beginInsertRows(QModelIndex(), firstIndex, lastIndex);
255− m_rowCount += lastIndex - firstIndex + 1;
261− Q_EMIT countChanged();
264−void FlatMenuProxyModel::onRowsRemoved(const QModelIndex &index, int, int)
266− if (index.isValid()) {
268− Q_EMIT countChanged();
272void FlatMenuProxyModel::onModelReset()
210void FlatMenuProxyModel::onModelReset()
274 // initiliaze rowCount
212 // initiliaze rowCount
@@ -282,6 +220,60 @@ void FlatMenuProxyModel::onModelReset()
282 Q_EMIT countChanged();
220 Q_EMIT countChanged();
223+// void FlatMenuProxyModel::onRowsAboutToBeInserted(const QModelIndex &index, int first, int last)
225+// if (index.isValid()) {
226+// int firstIndex = rowOffsetOf(index, first);
227+// int lastIndex = rowOffsetOf(index, last, true);
229+// beginInsertRows(QModelIndex(), firstIndex, lastIndex);
230+// m_rowCount += (lastIndex - firstIndex + 1);
234+// void FlatMenuProxyModel::onRowsAboutToBeRemoved(const QModelIndex &index, int first, int last)
236+// if (index.isValid()) {
237+// int firstIndex = rowOffsetOf(index, first);
238+// int lastIndex = rowOffsetOf(index, last, true);
240+// m_indexCache.clear();
241+// beginRemoveRows(QModelIndex(), firstIndex, lastIndex);
242+// m_rowCount -= (lastIndex - firstIndex + 1);
246+// void FlatMenuProxyModel::onRowsInserted(const QModelIndex &index, int first, int last)
248+// if (index.isValid()) {
249+// m_indexCache.clear();
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);
259+// beginInsertRows(QModelIndex(), firstIndex, lastIndex);
260+// m_rowCount += lastIndex - firstIndex + 1;
266+// Q_EMIT countChanged();
269+// void FlatMenuProxyModel::onRowsRemoved(const QModelIndex &index, int, int)
271+// if (index.isValid()) {
273+// Q_EMIT countChanged();
285int FlatMenuProxyModel::recursiveRowCount(const QModelIndex &index) const
277int FlatMenuProxyModel::recursiveRowCount(const QModelIndex &index) const
287 int size = sourceModel()->rowCount(index);
279 int size = sourceModel()->rowCount(index);