Wt examples: FolderView Class Reference

Wt examples 4.10.4

Loading...
Searching...
No Matches
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:
[legend]

## Public Member Functions
| FolderView ()
| 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 WDropEvent &event, const WModelIndex &target)
| Drop event.

## Detailed Description

A specialized treeview that supports a custom drop event.

Definition at line 21 of file FolderView.h.

## Constructor & Destructor Documentation

## ◆ FolderView()

FolderView::FolderView | ( |  | ) |

Constructor.

Definition at line 17 of file FolderView.C.

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

## Member Function Documentation

## ◆ dropEvent()

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

Drop event.

Definition at line 26 of file FolderView.C.

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

## 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 28 of file FolderView.h.

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

- treeview-dragdrop/FolderView.h
- treeview-dragdrop/FolderView.C