Bug 303336 - Model Errors
Summary: Model Errors
Status: RESOLVED FIXED
Alias: None
Product: telepathy
Classification: Frameworks and Libraries
Component: log-viewer (show other bugs)
Version: git-latest
Platform: unspecified Linux
: NOR normal
Target Milestone: Future
Assignee: Telepathy Bugs
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2012-07-10 23:39 UTC by David Edmundson
Modified: 2012-07-15 16:37 UTC (History)
2 users (show)

See Also:
Latest Commit:
Version Fixed In: 0.5


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description David Edmundson 2012-07-10 23:39:27 UTC
I have an entry in my log viewer tree with no display name, (and as such no accountPtr which is causing a crash when clicked).

Output from program when running is:
QSortFilterProxyModel: invalid inserted rows reported by source model
Comment 1 David Edmundson 2012-07-10 23:41:34 UTC
FRom the code:

    if (newEntries.size() > 0) {
        Q_FOREACH(const Tpl::EntityPtr &entity, newEntries) {
            EntityModelItem *parent = m_rootItem->item(pendingEntities->account());
            if (!parent) {
                beginInsertRows(QModelIndex(), m_rootItem->itemCount(), m_rootItem->itemCount());
                parent = new EntityModelItem(m_rootItem);
                parent->setData(QVariant::fromValue(pendingEntities->account()), EntityModel::AccountRole);
                m_rootItem->addItem(parent);
                endInsertRows();
            }

            QModelIndex parentIndex = index(parent->row(), 0, QModelIndex());
            beginInsertRows(parentIndex, m_rootItem->item(parentIndex.row())->row(), m_rootItem->item(parentIndex.row())->row() + 1);
            EntityModelItem *item = new EntityModelItem(parent);
            item->setData(QVariant::fromValue(pendingEntities->account()), EntityModel::AccountRole);
            item->setData(QVariant::fromValue(entity), EntityModel::EntityRole);
            parent->addItem(item);

            if (pendingEntities->account()->connection()) {
                Tp::PendingOperation *op =
                    pendingEntities->account()->connection()->contactManager()->contactsForIdentifiers(
                                            QStringList() << entity->identifier());
                connect(op, SIGNAL(finished(Tp::PendingOperation*)),
                        this, SLOT(onEntityContactRetrieved(Tp::PendingOperation*)));
            }
        }

        endInsertRows();
    }
}


these beginInsertRows and endInsertRows doe not line up.

if there are many entities being inserted, beginInsert is called many times, endInsert only once.
Comment 2 Martin Klapetek 2012-07-11 00:27:11 UTC
Are the calls actually being queued up? Because I'd assume that endInsert() simply ends all inserting operations, ie. signaling the view "I'm done with inserting, do your stuff now".
Comment 3 Daniel Vrátil 2012-07-13 17:02:23 UTC
(In reply to comment #2)
> Are the calls actually being queued up? Because I'd assume that endInsert()
> simply ends all inserting operations, ie. signaling the view "I'm done with
> inserting, do your stuff now".

The Qt documentation is not completely clear about this, but I assume they want the calls to be paired:

"An insertRows() implementation must call beginInsertRows() before inserting new rows into the data structure, and endInsertRows() immediately afterwards."

d_ed already fixed this in git [0], but the "invalid inserted rows reported by source model" error is still there.

[0] http://quickgit.kde.org/index.php?p=ktp-text-ui.git&a=commit&h=7de1e05aa6bf9a7ec7636ac50b8680b0b4345f3c
Comment 4 David Edmundson 2012-07-13 17:08:07 UTC
There is something called QModelTest which may be useful here.
Comment 5 Daniel Vrátil 2012-07-15 16:37:53 UTC
Git commit bca67be2b9d31416ba3ef6b2b56e09fd0379a8f8 by Dan Vrátil.
Committed on 15/07/2012 at 18:38.
Pushed by dvratil into branch 'master'.

Fix EntityModel warnings

REVIEW: 105579

M  +22   -26   logviewer/entity-model.cpp

http://commits.kde.org/telepathy-text-ui/bca67be2b9d31416ba3ef6b2b56e09fd0379a8f8