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

Main application class. More...

Inheritance diagram for TreeViewDragDrop:
[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, bool doRefresh=true)
 
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 Http::Cookie &cookie)
 
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 Http::Cookie &cookie)
 
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)
 
void suspend (std::chrono::seconds duration)
 
Signalunsuspended ()
 
ServerSideFontMetrics * serverSideFontMetrics ()
 
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
 
void setHtmlAttribute (const std::string &name, const std::string &value)
 
WString htmlAttribute (const std::string &name) const
 
void setBodyAttribute (const std::string &name, const std::string &value)
 
WString bodyAttribute (const std::string &name) 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
 
void setHtmlAttribute (const std::string &name, const std::string &value)
 
WString htmlAttribute (const std::string &name) const
 
void setBodyAttribute (const std::string &name, const std::string &value)
 
WString bodyAttribute (const std::string &name) 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...
 
std::unique_ptr< WTextcreateTitle (const WString &title)
 Creates a title widget. More...
 
std::unique_ptr< WTreeViewfolderView ()
 Creates the folder WTreeView. More...
 
std::unique_ptr< WTableViewfileView ()
 Creates the file table view (a WTableView) More...
 
void editFile (const WModelIndex &item)
 Edit a particular row. More...
 
std::unique_ptr< WWidgetpieChart ()
 Creates the chart. More...
 
std::unique_ptr< 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...
 
std::unique_ptr< WStandardItemcreateFolderItem (const WString &location, const std::string &folderId=std::string())
 Create a folder item. More...
 

Private Attributes

std::shared_ptr< WStandardItemModelfolderModel_
 The folder model (used by folderView_) More...
 
std::shared_ptr< WStandardItemModelfileModel_
 The file model (used by fileView_) More...
 
std::shared_ptr< 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...
 
std::unique_ptr< FileEditDialogdialog_
 
std::unique_ptr< WPopupMenupopup_
 Popup menu on the folder view. More...
 
std::unique_ptr< 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 253 of file TreeViewDragDrop.C.

Constructor & Destructor Documentation

◆ TreeViewDragDrop()

TreeViewDragDrop::TreeViewDragDrop ( const WEnvironment env)
inline

Constructor.

Definition at line 258 of file TreeViewDragDrop.C.

259  : WApplication(env),
260  popup_(nullptr),
261  popupActionBox_(nullptr)
262  {
263  setCssTheme("polished");
264 
265  /*
266  * Create the data models.
267  */
268  folderModel_ =
269  std::make_shared<WStandardItemModel>(0, 1);
270  populateFolders();
271 
272 
273  fileModel_ =
274  std::make_shared<FileModel>();
275  populateFiles();
276 
277  /*
278  * The header items are also endered using an ItemDelegate, and thus
279  * support other data, e.g.:
280  *
281  * fileModel_->setHeaderFlags(0, Horizontal, HeaderIsUserCheckable);
282  * fileModel_->setHeaderData(0, Horizontal,
283  * std::string("icons/file.gif"),
284  * Wt::DecorationRole);
285  */
286  fileFilterModel_ = std::make_shared<WSortFilterProxyModel>();
287  fileFilterModel_->setSourceModel(fileModel_);
288  fileFilterModel_->setDynamicSortFilter(true);
289  fileFilterModel_->setFilterKeyColumn(0);
290  fileFilterModel_->setFilterRole(ItemDataRole::User);
291 
292  /*
293  * Setup the user interface.
294  */
295  createUI();
296 
297  }
std::shared_ptr< WStandardItemModel > fileModel_
The file model (used by fileView_)
std::shared_ptr< WSortFilterProxyModel > fileFilterModel_
The sort filter proxy model that adapts fileModel_.
void createUI()
Setup the user interface.
std::shared_ptr< WStandardItemModel > folderModel_
The folder model (used by folderView_)
std::unique_ptr< WMessageBox > popupActionBox_
Message box to confirm the poup menu action.
std::unique_ptr< WPopupMenu > popup_
Popup menu on the folder view.
void populateFiles()
Populate the files model.
void populateFolders()
Populate the folders model.
void setCssTheme(const std::string &name)
WApplication(const WEnvironment &environment)

◆ ~TreeViewDragDrop()

virtual TreeViewDragDrop::~TreeViewDragDrop ( )
inlinevirtual

Definition at line 299 of file TreeViewDragDrop.C.

300  {
301  dialog_.reset();
302  }
std::unique_ptr< FileEditDialog > dialog_

Member Function Documentation

◆ aboutDisplay()

std::unique_ptr<WWidget> TreeViewDragDrop::aboutDisplay ( )
inlineprivate

Creates the hints text.

Definition at line 487 of file TreeViewDragDrop.C.

487  {
488  std::unique_ptr<WText> result
489  = std::make_unique<WText>(WString::tr("about-text"));
490  result->setStyleClass("about");
491  return std::move(result);
492  }

◆ convertToDate()

void TreeViewDragDrop::convertToDate ( WStandardItem item)
inlineprivate

Convert a string to a date.

Definition at line 620 of file TreeViewDragDrop.C.

620  {
621  WDate d = WDate::fromString(item->text(), FileModel::dateEditFormat);
622  item->setData(cpp17::any(d), ItemDataRole::Display);
623  }
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 627 of file TreeViewDragDrop.C.

627  {
628  int i = asNumber(item->text());
629  item->setData(cpp17::any(i), ItemDataRole::Edit);
630  }
double asNumber(const cpp17::any &v)

◆ createFolderItem()

std::unique_ptr<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 667 of file TreeViewDragDrop.C.

669  {
670  auto result
671  = std::make_unique<WStandardItem>(location);
672 
673  if (!folderId.empty()) {
674  result->setData(cpp17::any(folderId));
675  result->setFlags(result->flags() | ItemFlag::DropEnabled);
676  folderNameMap_[folderId] = location;
677  } else
678  result->setFlags(result->flags().clear(ItemFlag::Selectable));
679 
680  result->setIcon("icons/folder.gif");
681 
682  return result;
683  }
std::map< std::string, WString > folderNameMap_
Maps folder id's to folder descriptions.

◆ createTitle()

std::unique_ptr<WText> TreeViewDragDrop::createTitle ( const WString title)
inlineprivate

Creates a title widget.

Definition at line 371 of file TreeViewDragDrop.C.

371  {
372  auto result = std::make_unique<WText>(title);
373  result->setInline(false);
374  result->setStyleClass("title");
375 
376  return result;
377  }
const WString & title() const

◆ createUI()

void TreeViewDragDrop::createUI ( )
inlineprivate

Setup the user interface.

Definition at line 333 of file TreeViewDragDrop.C.

333  {
334  WContainerWidget *w = root();
335  w->setStyleClass("maindiv");
336 
337  /*
338  * The main layout is a 3x2 grid layout.
339  */
340  std::unique_ptr<WGridLayout> layout =
341  std::make_unique<WGridLayout>();
342  layout->addWidget(createTitle("Folders"), 0, 0);
343  layout->addWidget(createTitle("Files"), 0, 1);
344  layout->addWidget(folderView(), 1, 0);
345  layout->setColumnResizable(0);
346 
347  // select the first folder
348  folderView_->select(folderModel_->index(0, 0, folderModel_->index(0, 0)));
349 
350  std::unique_ptr<WVBoxLayout> vbox =
351  std::make_unique<WVBoxLayout>();
352  vbox->addWidget(fileView(), 1);
353  vbox->addWidget(pieChart(), 1);
354  vbox->setResizable(0);
355 
356  layout->addLayout(std::move(vbox), 1, 1);
357 
358  layout->addWidget(aboutDisplay(), 2, 0, 1, 2);
359 
360  /*
361  * Let row 1 and column 1 take the excess space.
362  */
363  layout->setRowStretch(1, 1);
364  layout->setColumnStretch(1, 1);
365 
366  w->setLayout(std::move(layout));
367  }
std::unique_ptr< WTableView > fileView()
Creates the file table view (a WTableView)
std::unique_ptr< WTreeView > folderView()
Creates the folder WTreeView.
std::unique_ptr< WWidget > aboutDisplay()
Creates the hints text.
std::unique_ptr< WText > createTitle(const WString &title)
Creates a title widget.
std::unique_ptr< WWidget > pieChart()
Creates the chart.
WTreeView * folderView_
The folder view.
void select(const WModelIndex &index, SelectionFlag option=SelectionFlag::Select)
WContainerWidget * root() const
void setLayout(std::unique_ptr< WLayout > layout)
virtual void setStyleClass(const WString &styleClass) override

◆ dialogDone()

void TreeViewDragDrop::dialogDone ( )
inlineprivate

Process the result of the message box.

Definition at line 581 of file TreeViewDragDrop.C.

581  {
582  popupActionBox_.reset();
583  }

◆ editFile()

void TreeViewDragDrop::editFile ( const WModelIndex item)
inlineprivate

Edit a particular row.

Definition at line 451 of file TreeViewDragDrop.C.

451  {
452  dialog_ = std::make_unique<FileEditDialog>(fileView_->model(), item);
453  }
WTableView * fileView_
The file view.
std::shared_ptr< WAbstractItemModel > model() const

◆ fileView()

std::unique_ptr<WTableView> TreeViewDragDrop::fileView ( )
inlineprivate

Creates the file table view (a WTableView)

Definition at line 413 of file TreeViewDragDrop.C.

413  {
414  auto tableView
415  = std::make_unique<WTableView>();
416 
417  tableView->setAlternatingRowColors(true);
418 
419  tableView->setModel(fileFilterModel_);
420  tableView->setSelectionMode(SelectionMode::Extended);
421  tableView->setDragEnabled(true);
422 
423  tableView->setColumnWidth(0, 100);
424  tableView->setColumnWidth(1, 150);
425  tableView->setColumnWidth(2, 100);
426  tableView->setColumnWidth(3, 60);
427  tableView->setColumnWidth(4, 100);
428  tableView->setColumnWidth(5, 100);
429 
430  auto delegate = std::make_shared<WItemDelegate>();
431  delegate->setTextFormat(FileModel::dateDisplayFormat);
432  tableView->setItemDelegateForColumn(4, delegate);
433  tableView->setItemDelegateForColumn(5, delegate);
434 
435  tableView->setColumnAlignment(3, AlignmentFlag::Right);
436  tableView->setColumnAlignment(4, AlignmentFlag::Right);
437  tableView->setColumnAlignment(5, AlignmentFlag::Right);
438 
439  tableView->sortByColumn(1, SortOrder::Ascending);
440 
441  tableView->doubleClicked().connect(this, std::bind(&TreeViewDragDrop::editFile,
442  this, std::placeholders::_1));
443 
444  fileView_ = tableView.get();
445 
446  return tableView;
447  }
static WString dateDisplayFormat
Date display format.
void editFile(const WModelIndex &item)
Edit a particular row.

◆ folderChanged()

void TreeViewDragDrop::folderChanged ( )
inlineprivate

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

Definition at line 497 of file TreeViewDragDrop.C.

497  {
498  if (folderView_->selectedIndexes().empty())
499  return;
500 
501  WModelIndex selected = *folderView_->selectedIndexes().begin();
502  cpp17::any d = selected.data(ItemDataRole::User);
503  if (cpp17::any_has_value(d)) {
504  std::string folder = cpp17::any_cast<std::string>(d);
505 
506  // For simplicity, we assume here that the folder-id does not
507  // contain special regexp characters, otherwise these need to be
508  // escaped -- or use the \Q \E qutoing escape regular expression
509  // syntax (and escape \E)
510  fileFilterModel_->setFilterRegExp(std::unique_ptr<std::regex>(new std::regex(folder)));
511  }
512  }
WModelIndexSet selectedIndexes() const
cpp17::any data(ItemDataRole role=ItemDataRole::Display) const

◆ folderView()

std::unique_ptr<WTreeView> TreeViewDragDrop::folderView ( )
inlineprivate

Creates the folder WTreeView.

Definition at line 381 of file TreeViewDragDrop.C.

381  {
382  auto treeView = std::make_unique<FolderView>();
383 
384  /*
385  * To support right-click, we need to disable the built-in browser
386  * context menu.
387  *
388  * Note that disabling the context menu and catching the
389  * right-click does not work reliably on all browsers.
390  */
391  // All event handlers ought to be JS, not DOM: #13501
392  WStringStream contextJS;
393  contextJS << WT_CLASS << ".$('" << treeView->id() << "').oncontextmenu = "
394  << "function() { event.cancelBubble = true; event.returnValue = false; return false; };";
396  treeView->setModel(folderModel_);
397  treeView->resize(200, WLength::Auto);
398  treeView->setSelectionMode(SelectionMode::Single);
399  treeView->setEnabledDropLocations(DropLocation::OnItem);
400  treeView->expandToDepth(1);
401  treeView->selectionChanged()
402  .connect(this, &TreeViewDragDrop::folderChanged);
403 
404  treeView->mouseWentUp().connect(this, &TreeViewDragDrop::showPopup);
405 
406  folderView_ = treeView.get();
407 
408  return std::move(treeView);
409  }
void folderChanged()
Change the filter on the file view when the selected folder changes.
void showPopup(const WModelIndex &item, const WMouseEvent &event)
Show a popup for a folder item.
void doJavaScript(const std::string &javascript, bool afterLoaded=true)
static WApplication * instance()
std::string str() const

◆ pieChart()

std::unique_ptr<WWidget> TreeViewDragDrop::pieChart ( )
inlineprivate

Creates the chart.

Definition at line 457 of file TreeViewDragDrop.C.

457  {
458  using namespace Chart;
459 
460  auto chart = std::make_unique<WPieChart>();
461  // chart->setPreferredMethod(WPaintedWidget::PngImage);
462  chart->setModel(fileFilterModel_);
463  chart->setTitle("File sizes");
464 
465  chart->setLabelsColumn(1); // Name
466  chart->setDataColumn(3); // Size
467 
468  chart->setPerspectiveEnabled(true, 0.2);
469  chart->setDisplayLabels(LabelOption::Outside | LabelOption::TextLabel);
470 
471  if (!WApplication::instance()->environment().ajax()) {
472  chart->resize(500, 200);
473  chart->setMargin(WLength::Auto, Side::Left | Side::Right);
474 
475  auto w = std::make_unique<WContainerWidget>();
476  w->addWidget(std::move(chart));
477  w->setStyleClass("about");
478  return std::move(w);
479  } else {
480  chart->setStyleClass("about");
481  return std::move(chart);
482  }
483  }
const WEnvironment & environment() const

◆ 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 592 of file TreeViewDragDrop.C.

592  {
593  fileModel_->invisibleRootItem()->setRowCount(0);
594 
595  std::ifstream f((appRoot() + "data/files.csv").c_str());
596 
597  if (!f)
598  throw std::runtime_error("Could not read: data/files.csv");
599 
601 
602  for (int i = 0; i < fileModel_->rowCount(); ++i) {
603  WStandardItem *item = fileModel_->item(i, 0);
604  item->setFlags(item->flags() | ItemFlag::DragEnabled);
605  item->setIcon("icons/file.gif");
606 
607  std::string folderId = item->text().toUTF8();
608 
609  item->setData(cpp17::any(folderId), ItemDataRole::User);
610  item->setText(folderNameMap_[folderId]);
611 
612  convertToNumber(fileModel_->item(i, 3));
613  convertToDate(fileModel_->item(i, 4));
614  convertToDate(fileModel_->item(i, 5));
615  }
616  }
void convertToDate(WStandardItem *item)
Convert a string to a date.
void convertToNumber(WStandardItem *item)
Convert a string to a number.
static std::string appRoot()
void setIcon(const std::string &uri)
void setText(const WString &text)
WFlags< ItemFlag > flags() const
void setFlags(WFlags< ItemFlag > flags)
std::string toUTF8() const
void readFromCsv(std::istream &f, std::shared_ptr< WAbstractItemModel > model, int numRows, bool firstLineIsHeaders)
Definition: CsvUtil.C:54

◆ populateFolders()

void TreeViewDragDrop::populateFolders ( )
inlineprivate

Populate the folders model.

Definition at line 634 of file TreeViewDragDrop.C.

634  {
635  std::unique_ptr<WStandardItem> level1;
636 
637  level1 = createFolderItem("San Fransisco");
638  level1->appendRow(createFolderItem("Investors", "sf-investors"));
639  level1->appendRow(createFolderItem("Fellows", "sf-fellows"));
640  folderModel_->appendRow(std::move(level1));
641 
642  level1 = createFolderItem("Sophia Antipolis");
643  level1->appendRow(createFolderItem("R&D", "sa-r_d"));
644  level1->appendRow(createFolderItem("Services", "sa-services"));
645  level1->appendRow(createFolderItem("Support", "sa-support"));
646  level1->appendRow(createFolderItem("Billing", "sa-billing"));
647  folderModel_->appendRow(std::move(level1));
648 
649  level1 = createFolderItem("New York");
650  level1->appendRow(createFolderItem("Marketing", "ny-marketing"));
651  level1->appendRow(createFolderItem("Sales", "ny-sales"));
652  level1->appendRow(createFolderItem("Advisors", "ny-advisors"));
653  folderModel_->appendRow(std::move(level1));
654 
655  level1 = createFolderItem(WString(reinterpret_cast<const char*>(u8"Frankf\u00DCrt")));
656  level1->appendRow(createFolderItem("Sales", "frank-sales"));
657  folderModel_->appendRow(std::move(level1));
658 
659  folderModel_->setHeaderData(0, Orientation::Horizontal,
660  cpp17::any(std::string("SandBox")));
661  }
std::unique_ptr< WStandardItem > createFolderItem(const WString &location, const std::string &folderId=std::string())
Create a folder item.

◆ popupAction()

void TreeViewDragDrop::popupAction ( )
inlineprivate

Process the result of the popup menu.

Definition at line 558 of file TreeViewDragDrop.C.

558  {
559  if (popup_->result()) {
560  /*
561  * You could also bind extra data to an item using setData() and
562  * check here for the action asked. For now, we just use the text.
563  */
564  WString text = popup_->result()->text();
565  popup_->hide();
566 
567  popupActionBox_ = std::make_unique<WMessageBox>("Sorry.","Action '"
568  + text + "' is not implemented.",
569  Icon::None,
570  StandardButton::Ok);
571  popupActionBox_->buttonClicked()
572  .connect(this, &TreeViewDragDrop::dialogDone);
573  popupActionBox_->show();
574  } else {
575  popup_->hide();
576  }
577  }
void dialogDone()
Process the result of the message box.

◆ showPopup()

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

Show a popup for a folder item.

Definition at line 516 of file TreeViewDragDrop.C.

516  {
517  if (event.button() == MouseButton::Right) {
518  // Select the item, it was not yet selected.
519  if (!folderView_->isSelected(item))
520  folderView_->select(item);
521 
522  if (!popup_) {
523  popup_ = std::make_unique<WPopupMenu>();
524  popup_->addItem("icons/folder_new.gif", "Create a New Folder");
525  popup_->addItem("Rename this Folder")->setCheckable(true);
526  popup_->addItem("Delete this Folder");
527  popup_->addSeparator();
528  popup_->addItem("Folder Details");
529  popup_->addSeparator();
530  popup_->addItem("Application Inventory");
531  popup_->addItem("Hardware Inventory");
532  popup_->addSeparator();
533 
534  std::unique_ptr<WPopupMenu> subMenu = std::make_unique<WPopupMenu>();
535  subMenu->addItem("Sub Item 1");
536  subMenu->addItem("Sub Item 2");
537  popup_->addMenu("File Deployments", std::move(subMenu));
538 
539  /*
540  * This is one method of executing a popup, which does not block a
541  * thread for a reentrant event loop, and thus scales.
542  *
543  * Alternatively you could call WPopupMenu::exec(), which returns
544  * the result, but while waiting for it, blocks the thread.
545  */
546  popup_->aboutToHide().connect(this, &TreeViewDragDrop::popupAction);
547  }
548 
549  if (popup_->isHidden())
550  popup_->popup(event);
551  else
552  popup_->hide();
553  }
554  }
void popupAction()
Process the result of the popup menu.
bool isSelected(const WModelIndex &index) const
MouseButton button() const

Member Data Documentation

◆ dialog_

std::unique_ptr<FileEditDialog> TreeViewDragDrop::dialog_
private

Definition at line 323 of file TreeViewDragDrop.C.

◆ fileFilterModel_

std::shared_ptr<WSortFilterProxyModel> TreeViewDragDrop::fileFilterModel_
private

The sort filter proxy model that adapts fileModel_.

Definition at line 312 of file TreeViewDragDrop.C.

◆ fileModel_

std::shared_ptr<WStandardItemModel> TreeViewDragDrop::fileModel_
private

The file model (used by fileView_)

Definition at line 309 of file TreeViewDragDrop.C.

◆ fileView_

WTableView* TreeViewDragDrop::fileView_
private

The file view.

Definition at line 321 of file TreeViewDragDrop.C.

◆ folderModel_

std::shared_ptr<WStandardItemModel> TreeViewDragDrop::folderModel_
private

The folder model (used by folderView_)

Definition at line 306 of file TreeViewDragDrop.C.

◆ folderNameMap_

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

Maps folder id's to folder descriptions.

Definition at line 315 of file TreeViewDragDrop.C.

◆ folderView_

WTreeView* TreeViewDragDrop::folderView_
private

The folder view.

Definition at line 318 of file TreeViewDragDrop.C.

◆ popup_

std::unique_ptr<WPopupMenu> TreeViewDragDrop::popup_
private

Popup menu on the folder view.

Definition at line 326 of file TreeViewDragDrop.C.

◆ popupActionBox_

std::unique_ptr<WMessageBox> TreeViewDragDrop::popupActionBox_
private

Message box to confirm the poup menu action.

Definition at line 329 of file TreeViewDragDrop.C.


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