Wt examples: FolderView Class Reference

Wt examples 3.3.0

- Main Page
- Modules
- Namespaces
- Classes
- Files

- Class List
- Class Hierarchy
- Class Members

Public Member Functions | Static Public Attributes | Protected Member Functions
FolderView Class Reference
Drag and drop in WTreeView example

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

`#include <FolderView.h>`

Inheritance diagram for FolderView:
[legend]

List of all members.

## 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.

## Detailed Description

A specialized treeview that supports a custom drop event.

Definition at line 19 of file FolderView.h.

## Constructor & Destructor Documentation

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);
    }

## Member Function Documentation

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);
          }
        }
      }
    }

## Member Data Documentation

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:

- /home/koen/project/wt/public-git/wt/examples/treeview-dragdrop/FolderView.h
- /home/koen/project/wt/public-git/wt/examples/treeview-dragdrop/FolderView.C