Project

General

Profile

Bug #3343 ยป sortfilter.cpp

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

 
1
#include <string>
2
#include <vector>
3
#include <boost/any.hpp>
4
#include <Wt/WAbstractTableModel>
5
#include <Wt/WApplication>
6
#include <Wt/WSortFilterProxyModel>
7

    
8
using namespace Wt;
9

    
10
class Model : public WAbstractTableModel
11
{
12
public:
13
    Model(WObject *parent = 0);
14

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

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

    
21
private:
22
    std::vector<std::string> data_;
23
};
24

    
25
Model::Model(WObject *parent) :
26
    WAbstractTableModel(parent), data_(2, "111")
27
{
28
}
29

    
30
int Model::columnCount(const WModelIndex &parent) const
31
{
32
    return 1;
33
}
34

    
35
int Model::rowCount(const WModelIndex &parent) const
36
{
37
    return data_.size();
38
}
39

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

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

    
53
class SFApp : public WApplication
54
{
55
public:
56
    SFApp(const WEnvironment &env);
57
};
58

    
59
SFApp::SFApp(const WEnvironment &env) :
60
    WApplication(env)
61
{
62
    Model *model = new Model(this);
63
    WSortFilterProxyModel *proxy = new WSortFilterProxyModel(this);
64
    proxy->setSourceModel(model);
65
    proxy->setDynamicSortFilter(true);
66
    proxy->setFilterRegExp("111");
67

    
68
    model->set(0, "33");
69
    model->set(1, "22");
70
    model->set(1, "11");
71
}
72

    
73
static WApplication *createApplication(const WEnvironment &env)
74
{
75
    return new SFApp(env);
76
}
77

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