Integrating model/view framework with undo framework



  • Hi
    I'm trying to integrate model/view (QStandardItmeModel/QTreeView) framework with undo framework. From what i understand the best way to do it is to create a proxy model that will log every change in the source model into the QUndoStack (this will alow me to undo internal drag&drop operations). Now i encounter a problem - insertRows and setData functions i overloaded in the proxy model are never called when i'm adding adding items to my source model but stragly i can see new items apearing in QTreeView.
    this is the code of how i add items to the source model

    @bool add(QStandardItem* item, QStandardItem* parent, int pos)
    {
    if( pos==-1 ) parent->appendRow(item);
    else parent->insertRow(pos, item);
    return true;
    }@

    this is how i overload the proxy model inster operation:

    @bool UnDoProxyModel::insertRows( int row, int count, const QModelIndex & parent)
    {
    if( mUndoStack==NULL )
    return QIdentityProxyModel::insertRows(row, count, parent);

    InsertRowCmd* tmp = new InsertRowCmd(this, row, count, &parent);
    mUndoStack->push( tmp );
    if( !tmp->getResult() ) delete mUndoStack->command(0);
    return tmp->getResult();
    }@

    this is how connecet source model and proxy model:

    @mModel = new QStandardItemModel(this);
    mProxyModel = new UnDoProxyModel(mUndoStack, this);
    mProxyModel->setSourceModel(mModel);
    ui.treeView->setModel(mProxyModel);
    @

    Am I overloading the righ method? Do I connect the models properly?


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.