Project

General

Profile

WSortFilterProxyModel and reset signal

Added by Mark O'Donovan almost 8 years ago

WSortFilterProxyModel does not handle the reset signal.

I use this as sometimes I change the number of columns in the model.

Is this an oversight or by design??

I currently work around this using the following class:

/*
 * WSortFilterProxyModel which handles source-model reset
 */
class ResetAwareFilterProxy : public Wt::WSortFilterProxyModel
{
public:
    ResetAwareFilterProxy(Wt::WObject* parent) : Wt::WSortFilterProxyModel(parent) {};

    //provide access to protected reset() function
    void reset() { Wt::WSortFilterProxyModel::reset(); };

    //connect source-model reset signal to reset() function
    virtual void setSourceModel(Wt::WAbstractItemModel *sourceModel) {
        sourceModel->modelReset().connect( std::bind(&ResetAwareFilterProxy::reset, this) );
        sourceModel->modelReset().connect( std::bind(&Wt::WSortFilterProxyModel::invalidate, this) );
        Wt::WSortFilterProxyModel::setSourceModel( sourceModel );
    };
};

Thanks,

Mark

P.S. How about a brief update of Wt4 progress on the blog :)