Wt examples  3.3.6
Public Member Functions | Static Public Attributes | Protected Member Functions | List of all members
FolderView Class Reference

A specialized treeview that supports a custom drop event. More...

#include <FolderView.h>

Inheritance diagram for FolderView:
Inheritance graph
[legend]

Public Member Functions

 FolderView (Wt::WContainerWidget *parent=0)
 Constructor. More...
 

Static Public Attributes

static const char * FileSelectionMimeType = "application/x-computers-selection"
 Constant that indicates the mime type for a selection of files. More...
 

Protected Member Functions

virtual void dropEvent (const Wt::WDropEvent &event, const Wt::WModelIndex &target)
 Drop event. More...
 

Detailed Description

A specialized treeview that supports a custom drop event.

Definition at line 19 of file FolderView.h.

Constructor & Destructor Documentation

◆ FolderView()

FolderView::FolderView ( Wt::WContainerWidget *  parent = 0)

Constructor.

Definition at line 19 of file FolderView.C.

20  : WTreeView(parent)
21 {
22  /*
23  * Accept drops for the custom mime type.
24  */
25  acceptDrops(FileSelectionMimeType);
26 }
static const char * FileSelectionMimeType
Constant that indicates the mime type for a selection of files.
Definition: FolderView.h:26

Member Function Documentation

◆ dropEvent()

void FolderView::dropEvent ( const Wt::WDropEvent &  event,
const Wt::WModelIndex &  target 
)
protectedvirtual

Drop event.

Definition at line 28 of file FolderView.C.

30 {
31  /*
32  * We reimplement the drop event to handle the dropping of a
33  * selection of computers.
34  *
35  * The test below would always be true in this case, since we only
36  * indicated support for that particular mime type.
37  */
38  if (event.mimeType() == FileSelectionMimeType) {
39  /*
40  * The source object for a drag of a selection from a WTreeView is
41  * a WItemSelectionModel.
42  */
43  WItemSelectionModel *selection
44  = dynamic_cast<WItemSelectionModel *>(event.source());
45 
46 #ifdef WT_THREADED
47  int result = WMessageBox::show
48  ("Drop event",
49  "Move "
50  + boost::lexical_cast<std::string>(selection->selectedIndexes().size())
51  + " files to folder '"
52  + boost::any_cast<WString>(target.data(DisplayRole)).toUTF8()
53  + "' ?",
54  Yes | No);
55 #else
56  int result = Yes;
57 #endif
58 
59  if (result == Yes) {
60  /*
61  * You can access the source model from the selection and
62  * manipulate it.
63  */
64  WAbstractItemModel *sourceModel = selection->model();
65 
66  WModelIndexSet toChange = selection->selectedIndexes();
67 
68  for (WModelIndexSet::reverse_iterator i = toChange.rbegin();
69  i != toChange.rend(); ++i) {
70  WModelIndex index = *i;
71 
72  /*
73  * Copy target folder to file. Since we are using a
74  * dynamic WSortFilterProxyModel that filters on folder, this
75  * will also result in the removal of the file from the
76  * current view.
77  */
78  std::map<int, boost::any> data = model()->itemData(target);
79  data[DecorationRole] = index.data(DecorationRole);
80  sourceModel->setItemData(index, data);
81  }
82  }
83  }
84 }
static const char * FileSelectionMimeType
Constant that indicates the mime type for a selection of files.
Definition: FolderView.h:26

Member Data Documentation

◆ FileSelectionMimeType

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.


The documentation for this class was generated from the following files:

Generated on Thu Jan 12 2017 for the C++ Web Toolkit (Wt) by doxygen 1.8.13