|
Wt examples
3.3.0
|
A specialized treeview that supports a custom drop event. More...
#include <FolderView.h>

Public Member Functions | |
| FolderView (Wt::WContainerWidget *parent=0) | |
| Constructor. | |
Static Public Attributes | |
| static const char * | FileSelectionMimeType = "application/x-computers-selection" |
| Constant that indicates the mime type for a selection of files. | |
Protected Member Functions | |
| virtual void | dropEvent (const Wt::WDropEvent &event, const Wt::WModelIndex &target) |
| Drop event. | |
A specialized treeview that supports a custom drop event.
Definition at line 19 of file FolderView.h.
| FolderView::FolderView | ( | Wt::WContainerWidget * | parent = 0 | ) |
Constructor.
Definition at line 19 of file FolderView.C.
: WTreeView(parent) { /* * Accept drops for the custom mime type. */ acceptDrops(FileSelectionMimeType); }
| void FolderView::dropEvent | ( | const Wt::WDropEvent & | event, |
| const Wt::WModelIndex & | target | ||
| ) | [protected, virtual] |
Drop event.
Reimplemented from Wt::WAbstractItemView.
Definition at line 28 of file FolderView.C.
{
/*
* We reimplement the drop event to handle the dropping of a
* selection of computers.
*
* The test below would always be true in this case, since we only
* indicated support for that particular mime type.
*/
if (event.mimeType() == FileSelectionMimeType) {
/*
* The source object for a drag of a selection from a WTreeView is
* a WItemSelectionModel.
*/
WItemSelectionModel *selection
= dynamic_cast<WItemSelectionModel *>(event.source());
#ifdef WT_THREADED
int result = WMessageBox::show
("Drop event",
"Move "
+ boost::lexical_cast<std::string>(selection->selectedIndexes().size())
+ " files to folder '"
+ boost::any_cast<WString>(target.data(DisplayRole)).toUTF8()
+ "' ?",
Yes | No);
#else
int result = Yes;
#endif
if (result == Yes) {
/*
* You can access the source model from the selection and
* manipulate it.
*/
WAbstractItemModel *sourceModel = selection->model();
WModelIndexSet toChange = selection->selectedIndexes();
for (WModelIndexSet::reverse_iterator i = toChange.rbegin();
i != toChange.rend(); ++i) {
WModelIndex index = *i;
/*
* Copy target folder to file. Since we are using a
* dynamic WSortFilterProxyModel that filters on folder, this
* will also result in the removal of the file from the
* current view.
*/
std::map<int, boost::any> data = model()->itemData(target);
data[DecorationRole] = index.data(DecorationRole);
sourceModel->setItemData(index, data);
}
}
}
}
const char * FolderView::FileSelectionMimeType = "application/x-computers-selection" [static] |
Constant that indicates the mime type for a selection of files.
Every kind of dragged data should be identified using a unique mime type.
Definition at line 26 of file FolderView.h.
1.7.5.1