Merge lp:~aacid/dee-qt/behave_better into lp:dee-qt

Proposed by Albert Astals Cid
Status: Merged
Approved by: Michal Hruby
Approved revision: 83
Merged at revision: 81
Proposed branch: lp:~aacid/dee-qt/behave_better
Merge into: lp:dee-qt
Diff against target: 65 lines (+12/-4)
1 file modified
deelistmodel.cpp (+12/-4)
To merge this branch: bzr merge lp:~aacid/dee-qt/behave_better
Reviewer Review Type Date Requested Status
PS Jenkins bot (community) continuous-integration Approve
Michal Hruby (community) Approve
Review via email: mp+181258@code.launchpad.net

Commit message

Be a better behaved QAbstractListModel

That means:
  * decrement/increment the count between the begin/end calls
  * Add a workaround so that data() ignores the not really removed row after endRemoveRows has been called

We still are not good behaved in the fact that we call beginInsertRows
after the model has been internall modified, but luckily it seems
not much people listens to that signal's data

We also rely on the fact that nothing will call data() between us
resetting m_rowBeingRemoved to -1 at the end of DeeListModelPrivate::onRowRemoved
and the internal dee model actually removing the row

To post a comment you must log in.
lp:~aacid/dee-qt/behave_better updated
82. By Albert Astals Cid

move the if inside the if

83. By Albert Astals Cid

Actually don't need the if

Revision history for this message
Michal Hruby (mhr3) wrote :

Looks reasonable, it certainly isn't ideal, but that's as far as we can go since changes to dee models emit just a single signal, which isn't easy to map to Qt's begin and end change model.

review: Approve
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'deelistmodel.cpp'
--- deelistmodel.cpp 2013-07-25 14:23:11 +0000
+++ deelistmodel.cpp 2013-08-21 11:03:21 +0000
@@ -49,9 +49,10 @@
49 int m_count;49 int m_count;
50 bool m_listeningSynchronized;50 bool m_listeningSynchronized;
51 QHash<int, QByteArray> m_roleNames;51 QHash<int, QByteArray> m_roleNames;
52 int m_rowBeingRemoved;
52};53};
5354
54DeeListModelPrivate::DeeListModelPrivate(DeeListModel* parent) : m_parent(parent), m_deeModel(NULL), m_count(0), m_listeningSynchronized(false)55DeeListModelPrivate::DeeListModelPrivate(DeeListModel* parent) : m_parent(parent), m_deeModel(NULL), m_count(0), m_listeningSynchronized(false), m_rowBeingRemoved(-1)
55{56{
56}57}
5758
@@ -180,7 +181,6 @@
180 return;181 return;
181 }182 }
182183
183 model->d->m_count++;
184 gint position = dee_model_get_position(model->d->m_deeModel, iter);184 gint position = dee_model_get_position(model->d->m_deeModel, iter);
185 /* Force emission of QAbstractItemModel::rowsInserted by calling185 /* Force emission of QAbstractItemModel::rowsInserted by calling
186 beginInsertRows and endInsertRows. Necessary because according to the186 beginInsertRows and endInsertRows. Necessary because according to the
@@ -189,6 +189,7 @@
189 cannot be explicitly emitted in subclass code."189 cannot be explicitly emitted in subclass code."
190 */190 */
191 model->beginInsertRows(QModelIndex(), position, position);191 model->beginInsertRows(QModelIndex(), position, position);
192 model->d->m_count++;
192 model->endInsertRows();193 model->endInsertRows();
193 Q_EMIT model->countChanged();194 Q_EMIT model->countChanged();
194}195}
@@ -207,7 +208,6 @@
207 what one would expect.208 what one would expect.
208 See Dee's dee_sequence_model_remove() method.209 See Dee's dee_sequence_model_remove() method.
209 */210 */
210 model->d->m_count--;
211 gint position = dee_model_get_position(model->d->m_deeModel, iter);211 gint position = dee_model_get_position(model->d->m_deeModel, iter);
212 /* Force emission of QAbstractItemModel::rowsRemoved by calling212 /* Force emission of QAbstractItemModel::rowsRemoved by calling
213 beginRemoveRows and endRemoveRows. Necessary because according to the213 beginRemoveRows and endRemoveRows. Necessary because according to the
@@ -216,8 +216,11 @@
216 cannot be explicitly emitted in subclass code."216 cannot be explicitly emitted in subclass code."
217 */217 */
218 model->beginRemoveRows(QModelIndex(), position, position);218 model->beginRemoveRows(QModelIndex(), position, position);
219 model->d->m_rowBeingRemoved = position;
220 model->d->m_count--;
219 model->endRemoveRows();221 model->endRemoveRows();
220 Q_EMIT model->countChanged();222 Q_EMIT model->countChanged();
223 model->d->m_rowBeingRemoved = -1;
221}224}
222225
223void226void
@@ -316,7 +319,12 @@
316 GVariant* gvariant;319 GVariant* gvariant;
317 DeeModelIter* iter;320 DeeModelIter* iter;
318321
319 iter = dee_model_get_iter_at_row(d->m_deeModel, index.row());322 int row = index.row();
323 if (d->m_rowBeingRemoved >= 0 && row >= d->m_rowBeingRemoved) {
324 row++;
325 }
326
327 iter = dee_model_get_iter_at_row(d->m_deeModel, row);
320 gvariant = dee_model_get_value(d->m_deeModel, iter, role);328 gvariant = dee_model_get_value(d->m_deeModel, iter, role);
321 QVariant qvariant = QVariantFromGVariant(gvariant);329 QVariant qvariant = QVariantFromGVariant(gvariant);
322 g_variant_unref(gvariant);330 g_variant_unref(gvariant);

Subscribers

People subscribed via source and target branches

to all changes: