Wt examples  3.7.1
Public Member Functions | Private Member Functions | Private Attributes | List of all members
TreeViewDragDrop Class Reference

Main application class. More...

Inheritance diagram for TreeViewDragDrop:
Inheritance graph
[legend]

Public Member Functions

 TreeViewDragDrop (const WEnvironment &env)
 Constructor. More...
 
virtual ~TreeViewDragDrop ()
 
- Public Member Functions inherited from Wt::WApplication
 WApplication (const WEnvironment &environment)
 
 ~WApplication ()
 
const WEnvironmentenvironment () const
 
WContainerWidgetroot () const
 
WWidgetfindWidget (const std::string &name)
 
void setTitle (const WString &title)
 
const WStringtitle () const
 
const WStringcloseMessage () const
 
std::shared_ptr< WLocalizedStringslocalizedStrings ()
 
void setLocalizedStrings (const std::shared_ptr< WLocalizedStrings > &stringResolver)
 
WMessageResourceBundlemessageResourceBundle ()
 
void setLocale (const WLocale &locale)
 
const WLocalelocale () const
 
virtual void refresh ()
 
void bindWidget (std::unique_ptr< WWidget > widget, const std::string &domId)
 
std::string docRoot () const
 
void setConnectionMonitor (const std::string &jsObject)
 
std::string sessionId () const
 
void changeSessionId ()
 
void processEvents ()
 
virtual void waitForEvent ()
 
virtual void initialize ()
 
virtual void finalize ()
 
void setTwoPhaseRenderingThreshold (int size)
 
void setCookie (const std::string &name, const std::string &value, int maxAge, const std::string &domain="", const std::string &path="", bool secure=false)
 
void removeCookie (const std::string &name, const std::string &domain="", const std::string &path="")
 
void addMetaLink (const std::string &href, const std::string &rel, const std::string &media, const std::string &hreflang, const std::string &type, const std::string &sizes, bool disabled)
 
void removeMetaLink (const std::string &href)
 
void addMetaHeader (const std::string &name, const WString &content, const std::string &lang="")
 
void addMetaHeader (MetaHeaderType type, const std::string &name, const WString &content, const std::string &lang="")
 
WString metaHeader (MetaHeaderType type, const std::string &name) const
 
void removeMetaHeader (MetaHeaderType type, const std::string &name="")
 
WLogEntry log (const std::string &type) const
 
void setLoadingIndicator (std::unique_ptr< WLoadingIndicator > indicator)
 
WLoadingIndicatorloadingIndicator () const
 
void quit ()
 
void quit (const WString &restartMessage)
 
bool hasQuit () const
 
::int64_t maximumRequestSize () const
 
Signal< ::int64_t > & requestTooLarge ()
 
void setConfirmCloseMessage (const WString &message)
 
void deferRendering ()
 
void resumeRendering ()
 
std::string encodeUntrustedUrl (const std::string &url) const
 
void pushExposedConstraint (WWidget *w)
 
WCssStyleSheetstyleSheet ()
 
void useStyleSheet (const WLink &link, const std::string &media="all")
 
void useStyleSheet (const WLink &link, const std::string &condition, const std::string &media)
 
void useStyleSheet (const WLinkedCssStyleSheet &styleSheet, const std::string &condition="")
 
void removeStyleSheet (const WLink &link)
 
void setTheme (const std::shared_ptr< WTheme > &theme)
 
std::shared_ptr< WThemetheme () const
 
void setCssTheme (const std::string &name)
 
void setLayoutDirection (LayoutDirection direction)
 
LayoutDirection layoutDirection () const
 
void setBodyClass (const std::string &styleClass)
 
std::string bodyClass () const
 
void setHtmlClass (const std::string &styleClass)
 
std::string htmlClass () const
 
std::string url (const std::string &internalPath=std::string()) const
 
virtual std::string makeAbsoluteUrl (const std::string &url) const
 
std::string resolveRelativeUrl (const std::string &url) const
 
std::string bookmarkUrl () const
 
std::string bookmarkUrl (const std::string &internalPath) const
 
void setInternalPath (const std::string &path, bool emitChange=false)
 
void setInternalPathDefaultValid (bool valid)
 
bool internalPathDefaultValid () const
 
void setInternalPathValid (bool valid)
 
bool internalPathValid () const
 
std::string internalPath () const
 
std::string internalPathNextPart (const std::string &path) const
 
bool internalPathMatches (const std::string &path) const
 
Signal< std::string > & internalPathChanged ()
 
Signal< std::string > & internalPathInvalid ()
 
void redirect (const std::string &url)
 
void enableUpdates (bool enabled=true)
 
bool updatesEnabled () const
 
void triggerUpdate ()
 
void attachThread (bool attach=true)
 
void doJavaScript (const std::string &javascript, bool afterLoaded=true)
 
void addAutoJavaScript (const std::string &javascript)
 
void declareJavaScriptFunction (const std::string &name, const std::string &function)
 
bool require (const std::string &url, const std::string &symbol=std::string())
 
bool requireJQuery (const std::string &url)
 
bool customJQuery () const
 
void setJavaScriptClass (const std::string &className)
 
std::string javaScriptClass ()
 
EventSignal< WKeyEvent > & globalKeyWentDown ()
 
EventSignal< WKeyEvent > & globalKeyPressed ()
 
EventSignal< WKeyEvent > & globalKeyWentUp ()
 
EventSignalglobalEnterPressed ()
 
EventSignalglobalEscapePressed ()
 
WCssStyleSheetstyleSheet ()
 
void useStyleSheet (const WLink &link, const std::string &media="all")
 
void useStyleSheet (const WLink &link, const std::string &condition, const std::string &media)
 
void useStyleSheet (const WLinkedCssStyleSheet &styleSheet, const std::string &condition="")
 
void removeStyleSheet (const WLink &link)
 
void setTheme (const std::shared_ptr< WTheme > &theme)
 
std::shared_ptr< WThemetheme () const
 
void setCssTheme (const std::string &name)
 
void setLayoutDirection (LayoutDirection direction)
 
LayoutDirection layoutDirection () const
 
void setBodyClass (const std::string &styleClass)
 
std::string bodyClass () const
 
void setHtmlClass (const std::string &styleClass)
 
std::string htmlClass () const
 
std::string url (const std::string &internalPath=std::string()) const
 
virtual std::string makeAbsoluteUrl (const std::string &url) const
 
std::string resolveRelativeUrl (const std::string &url) const
 
std::string bookmarkUrl () const
 
std::string bookmarkUrl (const std::string &internalPath) const
 
void setInternalPath (const std::string &path, bool emitChange=false)
 
void setInternalPathDefaultValid (bool valid)
 
bool internalPathDefaultValid () const
 
void setInternalPathValid (bool valid)
 
bool internalPathValid () const
 
std::string internalPath () const
 
std::string internalPathNextPart (const std::string &path) const
 
bool internalPathMatches (const std::string &path) const
 
Signal< std::string > & internalPathChanged ()
 
Signal< std::string > & internalPathInvalid ()
 
void redirect (const std::string &url)
 
void enableUpdates (bool enabled=true)
 
bool updatesEnabled () const
 
void triggerUpdate ()
 
void attachThread (bool attach=true)
 
void doJavaScript (const std::string &javascript, bool afterLoaded=true)
 
void addAutoJavaScript (const std::string &javascript)
 
void declareJavaScriptFunction (const std::string &name, const std::string &function)
 
bool require (const std::string &url, const std::string &symbol=std::string())
 
bool requireJQuery (const std::string &url)
 
bool customJQuery () const
 
void setJavaScriptClass (const std::string &className)
 
std::string javaScriptClass ()
 
EventSignal< WKeyEvent > & globalKeyWentDown ()
 
EventSignal< WKeyEvent > & globalKeyPressed ()
 
EventSignal< WKeyEvent > & globalKeyWentUp ()
 
EventSignalglobalEnterPressed ()
 
EventSignalglobalEscapePressed ()
 
- Public Member Functions inherited from Wt::WObject
void addChild (std::unique_ptr< WObject > child)
 
Child * addChild (std::unique_ptr< Child > child)
 
std::unique_ptr< WObjectremoveChild (WObject *child)
 
std::unique_ptr< Child > removeChild (Child *child)
 
virtual const std::string id () const
 
virtual void setObjectName (const std::string &name)
 
virtual std::string objectName () const
 
void resetLearnedSlots ()
 
void resetLearnedSlot (void(T::*method)())
 
WStatelessSlot * implementStateless (void(T::*method)())
 
WStatelessSlot * implementStateless (void(T::*method)(), void(T::*undoMethod)())
 
void isNotStateless ()
 
WStatelessSlot * implementJavaScript (void(T::*method)(), const std::string &jsCode)
 
- Public Member Functions inherited from Wt::Core::observable
 observable () noexcept
 
virtual ~observable ()
 
auto bindSafe (void(C::*method)(Args...)) noexcept
 
auto bindSafe (void(C::*method)(Args...) const) const noexcept
 
auto bindSafe (const Function &function) noexcept
 

Private Member Functions

void createUI ()
 Setup the user interface. More...
 
WTextcreateTitle (const WString &title)
 Creates a title widget. More...
 
WTreeViewfolderView ()
 Creates the folder WTreeView. More...
 
WTableViewfileView ()
 Creates the file table view (a WTableView) More...
 
void editFile (const WModelIndex &item)
 Edit a particular row. More...
 
WWidgetpieChart ()
 Creates the chart. More...
 
WWidgetaboutDisplay ()
 Creates the hints text. More...
 
void folderChanged ()
 Change the filter on the file view when the selected folder changes. More...
 
void showPopup (const WModelIndex &item, const WMouseEvent &event)
 Show a popup for a folder item. More...
 
void popupAction ()
 Process the result of the popup menu. More...
 
void dialogDone ()
 Process the result of the message box. More...
 
void populateFiles ()
 Populate the files model. More...
 
void convertToDate (WStandardItem *item)
 Convert a string to a date. More...
 
void convertToNumber (WStandardItem *item)
 Convert a string to a number. More...
 
void populateFolders ()
 Populate the folders model. More...
 
WStandardItemcreateFolderItem (const WString &location, const std::string &folderId=std::string())
 Create a folder item. More...
 

Private Attributes

WStandardItemModelfolderModel_
 The folder model (used by folderView_) More...
 
WStandardItemModelfileModel_
 The file model (used by fileView_) More...
 
WSortFilterProxyModelfileFilterModel_
 The sort filter proxy model that adapts fileModel_. More...
 
std::map< std::string, WStringfolderNameMap_
 Maps folder id's to folder descriptions. More...
 
WTreeViewfolderView_
 The folder view. More...
 
WTableViewfileView_
 The file view. More...
 
WPopupMenupopup_
 Popup menu on the folder view. More...
 
WMessageBoxpopupActionBox_
 Message box to confirm the poup menu action. More...
 

Additional Inherited Members

- Public Types inherited from Wt::WApplication
typedef Wt::ApplicationCreator ApplicationCreator
 
typedef std::function< std::unique_ptr< WApplication >const WEnvironment &)> ApplicationCreator
 
- Public Types inherited from Wt::WObject
typedef void(WObject::* Method) ()
 
- Static Public Member Functions inherited from Wt::WApplication
static WApplicationinstance ()
 
static std::string resourcesUrl ()
 
static std::string relativeResourcesUrl ()
 
static std::string appRoot ()
 
static bool readConfigurationProperty (const std::string &name, std::string &value)
 
- Protected Member Functions inherited from Wt::WApplication
virtual void notify (const WEvent &e)
 
virtual bool isExposed (WWidget *w) const
 
virtual void enableAjax ()
 
virtual void unload ()
 
virtual void idleTimeout ()
 
virtual void handleJavaScriptError (const std::string &errorText)
 
- Protected Member Functions inherited from Wt::WObject
virtual WStatelessSlot * getStateless (Method method)
 

Detailed Description

Main application class.

Definition at line 237 of file TreeViewDragDrop.C.

Constructor & Destructor Documentation

◆ TreeViewDragDrop()

TreeViewDragDrop::TreeViewDragDrop ( const WEnvironment env)
inline

Constructor.

Definition at line 242 of file TreeViewDragDrop.C.

243  : WApplication(env),
244  popup_(0),
245  popupActionBox_(0)
246  {
247  setCssTheme("polished");
248 
249  /*
250  * Create the data models.
251  */
252  folderModel_ = new WStandardItemModel(0, 1, this);
253  populateFolders();
254 
255  fileModel_ = new FileModel(this);
256  populateFiles();
257 
258  /*
259  The header items are also endered using an ItemDelegate, and thus
260  support other data, e.g.:
261 
262  fileModel_->setHeaderFlags(0, Horizontal, HeaderIsUserCheckable);
263  fileModel_->setHeaderData(0, Horizontal,
264  std::string("icons/file.gif"),
265  Wt::DecorationRole);
266  */
271  fileFilterModel_->setFilterRole(UserRole);
272 
273  /*
274  * Setup the user interface.
275  */
276  createUI();
277  }
WStandardItemModel * folderModel_
The folder model (used by folderView_)
virtual void setSourceModel(const std::shared_ptr< WAbstractItemModel > &sourceModel) override
WMessageBox * popupActionBox_
Message box to confirm the poup menu action.
void populateFiles()
Populate the files model.
void setFilterKeyColumn(int column)
A specialized standard item model which report a specific drag and drop mime type.
WSortFilterProxyModel * fileFilterModel_
The sort filter proxy model that adapts fileModel_.
void setFilterRole(ItemDataRole role)
void createUI()
Setup the user interface.
void setDynamicSortFilter(bool enable)
WPopupMenu * popup_
Popup menu on the folder view.
void populateFolders()
Populate the folders model.
void setCssTheme(const std::string &name)
WApplication(const WEnvironment &environment)
WStandardItemModel * fileModel_
The file model (used by fileView_)

◆ ~TreeViewDragDrop()

virtual TreeViewDragDrop::~TreeViewDragDrop ( )
inlinevirtual

Definition at line 279 of file TreeViewDragDrop.C.

279  {
280  delete popup_;
281  delete popupActionBox_;
282  }
WMessageBox * popupActionBox_
Message box to confirm the poup menu action.
WPopupMenu * popup_
Popup menu on the folder view.

Member Function Documentation

◆ aboutDisplay()

WWidget* TreeViewDragDrop::aboutDisplay ( )
inlineprivate

Creates the hints text.

Definition at line 457 of file TreeViewDragDrop.C.

457  {
458  WText *result = new WText(WString::tr("about-text"));
459  result->setStyleClass("about");
460  return result;
461  }
virtual void setStyleClass(const WString &styleClass) override

◆ convertToDate()

void TreeViewDragDrop::convertToDate ( WStandardItem item)
inlineprivate

Convert a string to a date.

Definition at line 588 of file TreeViewDragDrop.C.

588  {
589  WDate d = WDate::fromString(item->text(), FileModel::dateEditFormat);
590  item->setData(boost::any(d), DisplayRole);
591  }
static WString dateEditFormat
Date edit format.
virtual void setData(const cpp17::any &data, ItemDataRole role=ItemDataRole::User)
WString text() const

◆ convertToNumber()

void TreeViewDragDrop::convertToNumber ( WStandardItem item)
inlineprivate

Convert a string to a number.

Definition at line 595 of file TreeViewDragDrop.C.

595  {
596  int i = boost::lexical_cast<int>(item->text());
597  item->setData(boost::any(i), EditRole);
598  }
virtual void setData(const cpp17::any &data, ItemDataRole role=ItemDataRole::User)
WString text() const

◆ createFolderItem()

WStandardItem* TreeViewDragDrop::createFolderItem ( const WString location,
const std::string &  folderId = std::string() 
)
inlineprivate

Create a folder item.

Configures flags for drag and drop support.

Definition at line 632 of file TreeViewDragDrop.C.

634  {
635  WStandardItem *result = new WStandardItem(location);
636 
637  if (!folderId.empty()) {
638  result->setData(boost::any(folderId));
639  result->setFlags(result->flags() | ItemIsDropEnabled);
640  folderNameMap_[folderId] = location;
641  } else
642  result->setFlags(result->flags().clear(ItemIsSelectable));
643 
644  result->setIcon("icons/folder.gif");
645 
646  return result;
647  }
WFlags< ItemFlag > flags() const
virtual void setData(const cpp17::any &data, ItemDataRole role=ItemDataRole::User)
std::map< std::string, WString > folderNameMap_
Maps folder id&#39;s to folder descriptions.
void setIcon(const std::string &uri)
WFlags< ItemFlag > & clear(ItemFlag value)
void setFlags(WFlags< ItemFlag > flags)

◆ createTitle()

WText* TreeViewDragDrop::createTitle ( const WString title)
inlineprivate

Creates a title widget.

Definition at line 347 of file TreeViewDragDrop.C.

347  {
348  WText *result = new WText(title);
349  result->setInline(false);
350  result->setStyleClass("title");
351 
352  return result;
353  }
virtual void setStyleClass(const WString &styleClass) override
virtual void setInline(bool isInline) override

◆ createUI()

void TreeViewDragDrop::createUI ( )
inlineprivate

Setup the user interface.

Definition at line 311 of file TreeViewDragDrop.C.

311  {
312  WContainerWidget *w = root();
313  w->setStyleClass("maindiv");
314 
315  /*
316  * The main layout is a 3x2 grid layout.
317  */
318  WGridLayout *layout = new WGridLayout();
319  layout->addWidget(createTitle("Folders"), 0, 0);
320  layout->addWidget(createTitle("Files"), 0, 1);
321  layout->addWidget(folderView(), 1, 0);
322  layout->setColumnResizable(0);
323 
324  // select the first folder
326 
327  WVBoxLayout *vbox = new WVBoxLayout();
328  vbox->addWidget(fileView(), 1);
329  vbox->addWidget(pieChart(), 1);
330  vbox->setResizable(0);
331 
332  layout->addLayout(vbox, 1, 1);
333 
334  layout->addWidget(aboutDisplay(), 2, 0, 1, 2);
335 
336  /*
337  * Let row 1 and column 1 take the excess space.
338  */
339  layout->setRowStretch(1, 1);
340  layout->setColumnStretch(1, 1);
341 
342  w->setLayout(layout);
343  }
void setLayout(std::unique_ptr< WLayout > layout)
WStandardItemModel * folderModel_
The folder model (used by folderView_)
virtual void setStyleClass(const WString &styleClass) override
WTableView * fileView()
Creates the file table view (a WTableView)
void setColumnStretch(int column, int stretch)
void addWidget(std::unique_ptr< WWidget > widget, int row, int column, WFlags< AlignmentFlag > alignment)
void addWidget(std::unique_ptr< WWidget > widget, int stretch, WFlags< AlignmentFlag > alignment)
WWidget * pieChart()
Creates the chart.
WTreeView * folderView_
The folder view.
WWidget * aboutDisplay()
Creates the hints text.
WContainerWidget * root() const
void addLayout(std::unique_ptr< WLayout > layout, int row, int column, WFlags< AlignmentFlag > alignment=None)
void setColumnResizable(int column, bool enabled=true, const WLength &initialSize=WLength::Auto)
void setResizable(int index, bool enabled=true, const WLength &initialSize=WLength::Auto)
virtual WModelIndex index(int row, int column, const WModelIndex &parent=WModelIndex()) const=0
void select(const WModelIndex &index, SelectionFlag option=SelectionFlag::Select)
WTreeView * folderView()
Creates the folder WTreeView.
void setRowStretch(int row, int stretch)
WText * createTitle(const WString &title)
Creates a title widget.

◆ dialogDone()

void TreeViewDragDrop::dialogDone ( )
inlineprivate

Process the result of the message box.

Definition at line 548 of file TreeViewDragDrop.C.

548  {
549  delete popupActionBox_;
550  popupActionBox_ = 0;
551  }
WMessageBox * popupActionBox_
Message box to confirm the poup menu action.

◆ editFile()

void TreeViewDragDrop::editFile ( const WModelIndex item)
inlineprivate

Edit a particular row.

Definition at line 422 of file TreeViewDragDrop.C.

422  {
423  new FileEditDialog(fileView_->model(), item);
424  }
std::shared_ptr< WAbstractItemModel > model() const
A dialog for editing a &#39;file&#39;.
WTableView * fileView_
The file view.

◆ fileView()

WTableView* TreeViewDragDrop::fileView ( )
inlineprivate

Creates the file table view (a WTableView)

Definition at line 386 of file TreeViewDragDrop.C.

386  {
387  WTableView *tableView = new WTableView();
388 
389  tableView->setAlternatingRowColors(true);
390 
391  tableView->setModel(fileFilterModel_);
392  tableView->setSelectionMode(ExtendedSelection);
393  tableView->setDragEnabled(true);
394 
395  tableView->setColumnWidth(0, 100);
396  tableView->setColumnWidth(1, 150);
397  tableView->setColumnWidth(2, 100);
398  tableView->setColumnWidth(3, 60);
399  tableView->setColumnWidth(4, 100);
400  tableView->setColumnWidth(5, 100);
401 
402  WItemDelegate *delegate = new WItemDelegate(this);
404  tableView->setItemDelegateForColumn(4, delegate);
405  tableView->setItemDelegateForColumn(5, delegate);
406 
407  tableView->setColumnAlignment(3, AlignRight);
408  tableView->setColumnAlignment(4, AlignRight);
409  tableView->setColumnAlignment(5, AlignRight);
410 
411  tableView->sortByColumn(1, AscendingOrder);
412 
413  tableView->doubleClicked().connect(this, &TreeViewDragDrop::editFile);
414 
415  fileView_ = tableView;
416 
417  return tableView;
418  }
void setTextFormat(const WString &format)
static WString dateDisplayFormat
Date display format.
void setItemDelegateForColumn(int column, const std::shared_ptr< WAbstractItemDelegate > &delegate)
virtual void setModel(const std::shared_ptr< WAbstractItemModel > &model) override
void setSelectionMode(SelectionMode mode)
WSortFilterProxyModel * fileFilterModel_
The sort filter proxy model that adapts fileModel_.
void setDragEnabled(bool enable)
void editFile(const WModelIndex &item)
Edit a particular row.
Signal< WModelIndex, WMouseEvent > & doubleClicked()
virtual void setAlternatingRowColors(bool enable) override
void sortByColumn(int column, SortOrder order)
virtual void setColumnWidth(int column, const WLength &width) override
WTableView * fileView_
The file view.
virtual void setColumnAlignment(int column, AlignmentFlag alignment)

◆ folderChanged()

void TreeViewDragDrop::folderChanged ( )
inlineprivate

Change the filter on the file view when the selected folder changes.

Definition at line 466 of file TreeViewDragDrop.C.

466  {
467  if (folderView_->selectedIndexes().empty())
468  return;
469 
470  WModelIndex selected = *folderView_->selectedIndexes().begin();
471  boost::any d = selected.data(UserRole);
472  if (!d.empty()) {
473  std::string folder = boost::any_cast<std::string>(d);
474 
475  // For simplicity, we assume here that the folder-id does not
476  // contain special regexp characters, otherwise these need to be
477  // escaped -- or use the \Q \E qutoing escape regular expression
478  // syntax (and escape \E)
480  }
481  }
cpp17::any data(ItemDataRole role=ItemDataRole::Display) const
WTreeView * folderView_
The folder view.
void setFilterRegExp(std::unique_ptr< std::regex > pattern)
WSortFilterProxyModel * fileFilterModel_
The sort filter proxy model that adapts fileModel_.
WModelIndexSet selectedIndexes() const

◆ folderView()

WTreeView* TreeViewDragDrop::folderView ( )
inlineprivate

Creates the folder WTreeView.

Definition at line 357 of file TreeViewDragDrop.C.

357  {
358  WTreeView *treeView = new FolderView();
359 
360  /*
361  * To support right-click, we need to disable the built-in browser
362  * context menu.
363  *
364  * Note that disabling the context menu and catching the
365  * right-click does not work reliably on all browsers.
366  */
367  treeView->setAttributeValue
368  ("oncontextmenu",
369  "event.cancelBubble = true; event.returnValue = false; return false;");
370  treeView->setModel(folderModel_);
371  treeView->resize(200, WLength::Auto);
372  treeView->setSelectionMode(SingleSelection);
373  treeView->expandToDepth(1);
374  treeView->selectionChanged()
376 
377  treeView->mouseWentUp().connect(this, &TreeViewDragDrop::showPopup);
378 
379  folderView_ = treeView;
380 
381  return treeView;
382  }
WStandardItemModel * folderModel_
The folder model (used by folderView_)
virtual void setAttributeValue(const std::string &name, const WString &value) override
virtual void resize(const WLength &width, const WLength &height) override
WTreeView * folderView_
The folder view.
void setSelectionMode(SelectionMode mode)
A specialized treeview that supports a custom drop event.
Definition: FolderView.h:19
Signal & selectionChanged()
virtual void setModel(const std::shared_ptr< WAbstractItemModel > &model) override
void showPopup(const WModelIndex &item, const WMouseEvent &event)
Show a popup for a folder item.
void expandToDepth(int depth)
Signal< WModelIndex, WMouseEvent > & mouseWentUp()
void folderChanged()
Change the filter on the file view when the selected folder changes.
virtual Wt::Signals::connection connect(WObject *target, WObject::Method method) override

◆ pieChart()

WWidget* TreeViewDragDrop::pieChart ( )
inlineprivate

Creates the chart.

Definition at line 428 of file TreeViewDragDrop.C.

428  {
429  using namespace Chart;
430 
431  WPieChart *chart = new WPieChart();
432  // chart->setPreferredMethod(WPaintedWidget::PngImage);
433  chart->setModel(fileFilterModel_);
434  chart->setTitle("File sizes");
435 
436  chart->setLabelsColumn(1); // Name
437  chart->setDataColumn(3); // Size
438 
439  chart->setPerspectiveEnabled(true, 0.2);
440  chart->setDisplayLabels(Outside | TextLabel);
441 
442  if (!WApplication::instance()->environment().ajax()) {
443  chart->resize(500, 200);
444  chart->setMargin(WLength::Auto, Left | Right);
446  w->addWidget(chart);
447  w->setStyleClass("about");
448  return w;
449  } else {
450  chart->setStyleClass("about");
451  return chart;
452  }
453  }
virtual void setStyleClass(const WString &styleClass) override
const WEnvironment & environment() const
WSortFilterProxyModel * fileFilterModel_
The sort filter proxy model that adapts fileModel_.
virtual void addWidget(std::unique_ptr< WWidget > widget)

◆ populateFiles()

void TreeViewDragDrop::populateFiles ( )
inlineprivate

Populate the files model.

Data (and headers) is read from the CSV file data/files.csv. We add icons to the first column, resolve the folder id to the actual folder name, and configure item flags, and parse date values.

Definition at line 560 of file TreeViewDragDrop.C.

560  {
562 
563  std::ifstream f((appRoot() + "data/files.csv").c_str());
564 
565  if (!f)
566  throw std::runtime_error("Could not read: data/files.csv");
567 
569 
570  for (int i = 0; i < fileModel_->rowCount(); ++i) {
571  WStandardItem *item = fileModel_->item(i, 0);
572  item->setFlags(item->flags() | ItemIsDragEnabled);
573  item->setIcon("icons/file.gif");
574 
575  std::string folderId = item->text().toUTF8();
576 
577  item->setData(boost::any(folderId), UserRole);
578  item->setText(folderNameMap_[folderId]);
579 
581  convertToDate(fileModel_->item(i, 4));
582  convertToDate(fileModel_->item(i, 5));
583  }
584  }
WStandardItem * item(int row, int column=0) const
WFlags< ItemFlag > flags() const
void convertToNumber(WStandardItem *item)
Convert a string to a number.
void convertToDate(WStandardItem *item)
Convert a string to a date.
void setRowCount(int rows)
virtual int rowCount(const WModelIndex &parent=WModelIndex()) const=0
virtual void setData(const cpp17::any &data, ItemDataRole role=ItemDataRole::User)
std::string toUTF8() const
std::map< std::string, WString > folderNameMap_
Maps folder id&#39;s to folder descriptions.
void setIcon(const std::string &uri)
void setText(const WString &text)
static std::string appRoot()
WString text() const
void setFlags(WFlags< ItemFlag > flags)
void readFromCsv(std::istream &f, Wt::WAbstractItemModel *model, int numRows, bool firstLineIsHeaders)
Utility function that reads a model from a CSV file.
Definition: CsvUtil.C:56
WStandardItem * invisibleRootItem() const
WStandardItemModel * fileModel_
The file model (used by fileView_)

◆ populateFolders()

void TreeViewDragDrop::populateFolders ( )
inlineprivate

Populate the folders model.

Definition at line 602 of file TreeViewDragDrop.C.

602  {
603  WStandardItem *level1, *level2;
604 
605  folderModel_->appendRow(level1 = createFolderItem("San Fransisco"));
606  level1->appendRow(level2 = createFolderItem("Investors", "sf-investors"));
607  level1->appendRow(level2 = createFolderItem("Fellows", "sf-fellows"));
608 
609  folderModel_->appendRow(level1 = createFolderItem("Sophia Antipolis"));
610  level1->appendRow(level2 = createFolderItem("R&D", "sa-r_d"));
611  level1->appendRow(level2 = createFolderItem("Services", "sa-services"));
612  level1->appendRow(level2 = createFolderItem("Support", "sa-support"));
613  level1->appendRow(level2 = createFolderItem("Billing", "sa-billing"));
614 
615  folderModel_->appendRow(level1 = createFolderItem("New York"));
616  level1->appendRow(level2 = createFolderItem("Marketing", "ny-marketing"));
617  level1->appendRow(level2 = createFolderItem("Sales", "ny-sales"));
618  level1->appendRow(level2 = createFolderItem("Advisors", "ny-advisors"));
619 
621  (WString::fromUTF8("Frankfürt")));
622  level1->appendRow(level2 = createFolderItem("Sales", "frank-sales"));
623 
624  folderModel_->setHeaderData(0, Horizontal,
625  boost::any(std::string("SandBox")));
626  }
WStandardItemModel * folderModel_
The folder model (used by folderView_)
void appendRow(std::vector< std::unique_ptr< WStandardItem > > items)
WStandardItem * createFolderItem(const WString &location, const std::string &folderId=std::string())
Create a folder item.
virtual bool setHeaderData(int section, Orientation orientation, const cpp17::any &value, ItemDataRole role=ItemDataRole::Edit)
void appendRow(std::vector< std::unique_ptr< WStandardItem > > items)

◆ popupAction()

void TreeViewDragDrop::popupAction ( )
inlineprivate

Process the result of the popup menu.

Definition at line 527 of file TreeViewDragDrop.C.

527  {
528  if (popup_->result()) {
529  /*
530  * You could also bind extra data to an item using setData() and
531  * check here for the action asked. For now, we just use the text.
532  */
533  WString text = popup_->result()->text();
534  popup_->hide();
535 
536  popupActionBox_ = new WMessageBox("Sorry.","Action '" + text
537  + "' is not implemented.", NoIcon, Ok);
541  } else {
542  popup_->hide();
543  }
544  }
WMessageBox * popupActionBox_
Message box to confirm the poup menu action.
WString text() const
void dialogDone()
Process the result of the message box.
static StandardButton show(const WString &caption, const WString &text, WFlags< StandardButton > buttons, const WAnimation &animation=WAnimation())
WMenuItem * result() const
WPopupMenu * popup_
Popup menu on the folder view.
virtual Wt::Signals::connection connect(WObject *target, WObject::Method method) override
Signal< StandardButton > & buttonClicked()

◆ showPopup()

void TreeViewDragDrop::showPopup ( const WModelIndex item,
const WMouseEvent event 
)
inlineprivate

Show a popup for a folder item.

Definition at line 485 of file TreeViewDragDrop.C.

485  {
486  if (event.button() == WMouseEvent::RightButton) {
487  // Select the item, it was not yet selected.
488  if (!folderView_->isSelected(item))
489  folderView_->select(item);
490 
491  if (!popup_) {
492  popup_ = new WPopupMenu();
493  popup_->addItem("icons/folder_new.gif", "Create a New Folder");
494  popup_->addItem("Rename this Folder")->setCheckable(true);
495  popup_->addItem("Delete this Folder");
496  popup_->addSeparator();
497  popup_->addItem("Folder Details");
498  popup_->addSeparator();
499  popup_->addItem("Application Inventory");
500  popup_->addItem("Hardware Inventory");
501  popup_->addSeparator();
502 
503  WPopupMenu *subMenu = new WPopupMenu();
504  subMenu->addItem("Sub Item 1");
505  subMenu->addItem("Sub Item 2");
506  popup_->addMenu("File Deployments", subMenu);
507 
508  /*
509  * This is one method of executing a popup, which does not block a
510  * thread for a reentrant event loop, and thus scales.
511  *
512  * Alternatively you could call WPopupMenu::exec(), which returns
513  * the result, but while waiting for it, blocks the thread.
514  */
516  }
517 
518  if (popup_->isHidden())
519  popup_->popup(event);
520  else
521  popup_->hide();
522  }
523  }
WMenuItem * addItem(const WString &label, std::unique_ptr< WWidget > contents=nullptr, ContentLoading policy=ContentLoading::Lazy)
WMenuItem * addSeparator()
WMenuItem * addMenu(const WString &text, std::unique_ptr< WMenu > menu)
virtual bool isHidden() const override
WTreeView * folderView_
The folder view.
void setCheckable(bool checkable)
MouseButton button() const
WPopupMenu * popup_
Popup menu on the folder view.
void select(const WModelIndex &index, SelectionFlag option=SelectionFlag::Select)
Signal & aboutToHide()
void popupAction()
Process the result of the popup menu.
void popup(const WPoint &point)
virtual Wt::Signals::connection connect(WObject *target, WObject::Method method) override
bool isSelected(const WModelIndex &index) const

Member Data Documentation

◆ fileFilterModel_

WSortFilterProxyModel* TreeViewDragDrop::fileFilterModel_
private

The sort filter proxy model that adapts fileModel_.

Definition at line 292 of file TreeViewDragDrop.C.

◆ fileModel_

WStandardItemModel* TreeViewDragDrop::fileModel_
private

The file model (used by fileView_)

Definition at line 289 of file TreeViewDragDrop.C.

◆ fileView_

WTableView* TreeViewDragDrop::fileView_
private

The file view.

Definition at line 301 of file TreeViewDragDrop.C.

◆ folderModel_

WStandardItemModel* TreeViewDragDrop::folderModel_
private

The folder model (used by folderView_)

Definition at line 286 of file TreeViewDragDrop.C.

◆ folderNameMap_

std::map<std::string, WString> TreeViewDragDrop::folderNameMap_
private

Maps folder id's to folder descriptions.

Definition at line 295 of file TreeViewDragDrop.C.

◆ folderView_

WTreeView* TreeViewDragDrop::folderView_
private

The folder view.

Definition at line 298 of file TreeViewDragDrop.C.

◆ popup_

WPopupMenu* TreeViewDragDrop::popup_
private

Popup menu on the folder view.

Definition at line 304 of file TreeViewDragDrop.C.

◆ popupActionBox_

WMessageBox* TreeViewDragDrop::popupActionBox_
private

Message box to confirm the poup menu action.

Definition at line 307 of file TreeViewDragDrop.C.


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

Generated on Tue Dec 15 2020 for the C++ Web Toolkit (Wt) by doxygen 1.8.13