Hi,
I have been fighting with this for a few days now. I am trying to
implement a WAbstractItemModel class. In the end the backend will be a
database with large amounts of data.
Most of the implementation details are inspired by the
WStandardItemModel implementation.
When I use the model from the code below with a WTableView, the text in
all the cells is rendered as hyperlinks (base+/?_=1...). This is not
desired. I am merely passing a WString to the boost::all function. Also,
I think that I have ensured that only the 'fake' root provides
information on children. The actual items should return an 0 for row and
column counts.
This is my first post. Be kind :-)
Thanks for your help!
Here is the relevant class:
class Model :public Wt::WAbstractItemModel
{
private:
std::vector<std::vector<int> > backend;
Wt::WModelIndex root;
public:
Model();
boost::any data(const Wt::WModelIndex &index, int role =
Wt::DisplayRole) const;
Wt::WModelIndex index(int row, int column, const Wt::WModelIndex&
parent = Wt::WModelIndex()) const;
Wt::WModelIndex parent(const Wt::WModelIndex &index) const;
int columnCount(const Wt::WModelIndex &parent = Wt::WModelIndex())
const;
int rowCount(const Wt::WModelIndex &parent = Wt::WModelIndex()) const;
};
Model::Model()
: backend(10, std::vector<int>(10))
{
for (int i = 0; i < 10; ++i) {
for (int j = 0; j < 10; ++ j) {
backend [i][j] = (i+1) * (j+1);
}
}
root = createIndex(-1, -1, static_cast<void*>(0));
}
boost::any Model::data(const Wt::WModelIndex &index, int role) const
{
int row = index.row();
int column = index.column();
if (row < 0 || column < 0
||row >9 || column > 9)
return boost::any();
int value = backend[row][column];
std::string test;
std::stringstream ss;
ss << value;
test = ss.str();
boost::any b;
std::string stuff (test);
return boost::any(stuff);
}
Wt::WModelIndex Model::index(int row, int column, const Wt::WModelIndex&
parent) const {
void *ptr = 0;
std::cerr << "*** index --- row: " << row << ", column: " << column
<< "\n";
if (row < 0 || row > 9 || column < 0 || column >9)
return Wt::WModelIndex();
return createIndex(row, column, ptr);
}
Wt::WModelIndex Model::parent(const Wt::WModelIndex &index) const
{
std::cerr << "** request for parent ***\n";
if (index.internalPointer() == 0) return Wt::WModelIndex();
return root;
}
int Model::columnCount(const Wt::WModelIndex &parent) const
{
if (parent.internalPointer() == 0) return backend[0].size();
return 0;
}
int Model::rowCount(const Wt::WModelIndex &parent) const
{
if (parent.internalPointer() == 0) return backend.size();
return 0;
}
--
Peter Wood
Assistant Professor of Linguistics and German
Department of Languages and Linguistics
University of Saskatchewan
------------------------------------------------------------------------------
BlackBerry® DevCon Americas, Oct. 18-20, San Francisco, CA
The must-attend event for mobile developers. Connect with experts.
Get tools for creating Super Apps. See the latest technologies.
Sessions, hands-on labs, demos & much more. Register early & save!
http://p.sf.net/sfu/rim-blackberry-1
_______________________________________________
witty-interest mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/witty-interest