Project

General

Profile

Bug #3343 ยป sortfilter.cpp

Test case to reproduce - Alexander Morozov, 06/18/2014 04:39 PM

 
#include <string>
#include <vector>
#include <boost/any.hpp>
#include <Wt/WAbstractTableModel>
#include <Wt/WApplication>
#include <Wt/WSortFilterProxyModel>

using namespace Wt;

class Model : public WAbstractTableModel
{
public:
Model(WObject *parent = 0);

virtual int columnCount(const WModelIndex &parent = WModelIndex()) const;
virtual int rowCount(const WModelIndex &parent = WModelIndex()) const;
virtual boost::any data(const WModelIndex &index, int role = DisplayRole) const;

void set(int n, const std::string& value);

private:
std::vector<std::string> data_;
};

Model::Model(WObject *parent) :
WAbstractTableModel(parent), data_(2, "111")
{
}

int Model::columnCount(const WModelIndex &parent) const
{
return 1;
}

int Model::rowCount(const WModelIndex &parent) const
{
return data_.size();
}

boost::any Model::data(const WModelIndex &index, int role) const
{
if (role != DisplayRole) return boost::any();
if (index.row() >= data_.size()) return boost::any();
return boost::any(data_[index.row()]);
}

void Model::set(int n, const std::string& value)
{
data_[n] = value;
dataChanged().emit(index(n, 0), index(n, 0));
}

class SFApp : public WApplication
{
public:
SFApp(const WEnvironment &env);
};

SFApp::SFApp(const WEnvironment &env) :
WApplication(env)
{
Model *model = new Model(this);
WSortFilterProxyModel *proxy = new WSortFilterProxyModel(this);
proxy->setSourceModel(model);
proxy->setDynamicSortFilter(true);
proxy->setFilterRegExp("111");

model->set(0, "33");
model->set(1, "22");
model->set(1, "11");
}

static WApplication *createApplication(const WEnvironment &env)
{
return new SFApp(env);
}

int main(int argc, char **argv)
{
return WRun(argc, argv, createApplication);
}
    (1-1/1)