QAbstractItemModel + ModelTest :: rowsInserted ASSERTion问题 [英] QAbstractItemModel + ModelTest::rowsInserted ASSERTion problem

查看:476
本文介绍了QAbstractItemModel + ModelTest :: rowsInserted ASSERTion问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图用ModelTest调试我的模型(QAbstractItemModel)。我不能理解一个断言。



ModelTest中有两个插槽用于拦截我的模型生成的信号。


  1. ModelTest :: rowsAboutToBeInserted

  2. ModelTest :: rowsInserted

Slot / function 1看起来像这样

  void ModelTest :: rowsAboutToBeInserted(const QModelIndex& parent,int start,int end )
{
更改c;
// ...
c.last = model-> data(model-> index(start-1,0,parent));
c.next = model-> data(model-> index(start,0,parent));
insert.push(c);
}

插槽2看起来像这样

  void ModelTest :: rowsInserted(const QModelIndex& parent,int start,int end)
{
更改c = insert.pop

//其他断言...

(*)Q_ASSERT(c.next == model-> data(model-> index(end + 1,0) ,c.parent)));
}

我不明白dla last assertion(*)。让我们假设在我的应用程序中添加1行。
此行是存储在我的模型中的唯一行。

在我添加行之前的模型中,我调用

beginInsertRows(parentIndex,0,0);

那么为什么modeltest需要


model-> data(model-> index(start,0,parent))



model-> data(model-> index(end + 1,0,c.parent))


我在这里缺少什么?请帮助:)

解决方案

这个断言的想法是检查添加的第一行是否正确移动。如果插入的行之后有一些行,则比较它们的数据。如果没有,你的模型应该在行

  c.next = model-> data > index(start,0,parent)); 

 code> Q_ASSERT(c.next == model-> data(model-> index(end + 1,0,c.parent))); 

应返回无效(空)QVariant。如果两个返回空的QVariant(因为他们应该)断言成功,因此提供一定程度的错误检查,即使在当前插入后没有行。


I'm trying to debug my model (QAbstractItemModel) with ModelTest. And I can't understand one assertion.

There are two slots in ModelTest that intercept signals generated by my model.

  1. ModelTest::rowsAboutToBeInserted
  2. ModelTest::rowsInserted

Slot/function 1 looks like this

void ModelTest::rowsAboutToBeInserted ( const QModelIndex &parent, int start, int end )
{
    Changing c;
    // ...
    c.last = model->data ( model->index ( start - 1, 0, parent ) );
    c.next = model->data ( model->index ( start, 0, parent ) );
    insert.push ( c );
}

And slot 2 looks like this

void ModelTest::rowsInserted ( const QModelIndex & parent, int start, int end )
{
    Changing c = insert.pop();

    // other asserts ...

    (*) Q_ASSERT ( c.next == model->data ( model->index ( end + 1, 0, c.parent ) ) );
}

I don't understand dla last assertion (*). Lets assume that in my app I add 1 row. This row is the only row that is stored in my model. So the row number would be 0.

In my model before adding the row I call

beginInsertRows(parentIndex, 0, 0);

So why does modeltest require

model->data ( model->index ( start, 0, parent ) )

to be equal to

model->data ( model->index ( end + 1, 0, c.parent ) )

What am I missing here ? Please help :)

解决方案

The idea behind this assert is to check if first row after added ones was correctly moved. If there are some rows after inserted ones, then their data are compared. If there aren't any, your model should both in the line

c.next = model->data ( model->index ( start, 0, parent ) );

and in

Q_ASSERT ( c.next == model->data ( model->index ( end + 1, 0, c.parent ) ) );

should return invalid (empty) QVariant. If both return empty QVariant (as they should) assertion succedes, thus providing some level of error-checking even in case of no rows after currently inserted.

这篇关于QAbstractItemModel + ModelTest :: rowsInserted ASSERTion问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆