On 2011-05-30, Wim Dumon <[email protected]> wrote:
> UserRole is indeed the default for setData. I could not reproduce this
> report by modifying the treeview-dragdrop example:
> item->setData(boost::any(folderId), UserRole);
> to
> item->setData(boost::any(folderId));
> Result is identical. Maybe you have a miscompilation and a 'make clean' helps?
The problem was that the data() method of WModelIndex has as default
parameter: int role = DisplayRole
And WStandardItem::data() has: int role = UserRole
Somehow I looked at the WStandardItem page instead of the WModelIndex
page or I unconsiously thought that WStandardItem::data() has the same
default value ;).
Anyway, for reference I attached my minimal test code to get the
described casting error (but I don't consider it a bug, since the
API-doc includes all the information) - uncommenting the commented line
and commenting out the next line fixes it:
#include <Wt/WApplication>
#include <Wt/WTreeView>
#include <Wt/WStandardItemModel>
#include <Wt/WStandardItem>
#include <Wt/WLogger>
#include <string>
using namespace Wt;
using namespace std;
class Main : public WApplication {
private:
WTreeView *tree_view_;
public:
Main(const WEnvironment &e)
: WApplication(e)
{
WStandardItemModel *model_ = new WStandardItemModel(0, 1, this);
WStandardItem *i = new WStandardItem(string("value"));
i->setData(boost::any(string("data")));
model_->appendRow(i);
tree_view_ = new WTreeView(root());
tree_view_->setModel(model_);
tree_view_->setSelectionMode(SingleSelection);
tree_view_->selectionChanged().connect(this, &Main::sel_update);
}
void sel_update()
{
if (tree_view_->selectedIndexes().empty())
return;
WModelIndex i = *tree_view_->selectedIndexes().begin();
//boost::any d = i.data(UserRole);
boost::any d = i.data();
if (d.empty())
return;
try {
string s = boost::any_cast<string>(d);
log("info") << "data: " << s;
} catch (const boost::bad_any_cast &e) {
log("error") << "cast error: " << e.what();
}
}
};
Wt::WApplication *create_app(const Wt::WEnvironment& env)
{
return new Main(env);
}
int main(int argc, char **argv)
{
return WRun(argc, argv, &create_app);
}
Best regards
Georg
------------------------------------------------------------------------------
vRanger cuts backup time in half-while increasing security.
With the market-leading solution for virtual backup and recovery,
you get blazing-fast, flexible, and affordable data protection.
Download your free trial now.
http://p.sf.net/sfu/quest-d2dcopy1
_______________________________________________
witty-interest mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/witty-interest