Wt examples 3.3.12
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.
 
virtual ~TreeViewDragDrop ()
 
- Public Member Functions inherited from Wt::WApplication
 WApplication (const WEnvironment &environment)
 
 ~WApplication ()
 
const WEnvironmentenvironment () const
 
WContainerWidgetroot () const
 
WWidgetfindWidget (const std::string &name)
 
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 WCssStyleSheet &styleSheet, const std::string &condition="")
 
void removeStyleSheet (const WLink &link)
 
void setTheme (const WTheme *theme)
 
const 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 setTitle (const WString &title)
 
const WStringtitle () const
 
const WStringcloseMessage () const
 
WLocalizedStringslocalizedStrings ()
 
WMessageResourceBundlebuiltinLocalizedStrings ()
 
void setLocalizedStrings (WLocalizedStrings *stringResolver)
 
WMessageResourceBundlemessageResourceBundle ()
 
void setLocale (const WLocale &locale)
 
const WLocalelocale () const
 
virtual void refresh ()
 
void bindWidget (WWidget *widget, const std::string &domId)
 
void enableUpdates (bool enabled=true)
 
bool updatesEnabled () const
 
void triggerUpdate ()
 
UpdateLock getUpdateLock ()
 
void attachThread (bool attach=true)
 
EventSignal< WKeyEvent > & globalKeyWentDown ()
 
EventSignal< WKeyEvent > & globalKeyPressed ()
 
EventSignal< WKeyEvent > & globalKeyWentUp ()
 
EventSignalglobalEnterPressed ()
 
EventSignalglobalEscapePressed ()
 
bool debug () const
 
void setFocus (const std::string &id, int selectionStart, int selectionEnd)
 
void loadJavaScript (const char *jsFile, const WJavaScriptPreamble &preamble)
 
bool javaScriptLoaded (const char *jsFile) const
 
void setConfirmCloseMessage (const WString &message)
 
void enableInternalPaths ()
 
void deferRendering ()
 
void resumeRendering ()
 
boost::function< void()> bind (const F &f)
 
std::string encodeUntrustedUrl (const std::string &url) const
 
void pushExposedConstraint (WWidget *w)
 
void popExposedConstraint (WWidget *w)
 
void addGlobalWidget (WWidget *w)
 
void removeGlobalWidget (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 WCssStyleSheet &styleSheet, const std::string &condition="")
 
void removeStyleSheet (const WLink &link)
 
void setTheme (const WTheme *theme)
 
const 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 setTitle (const WString &title)
 
const WStringtitle () const
 
const WStringcloseMessage () const
 
WLocalizedStringslocalizedStrings ()
 
WMessageResourceBundlebuiltinLocalizedStrings ()
 
void setLocalizedStrings (WLocalizedStrings *stringResolver)
 
WMessageResourceBundlemessageResourceBundle ()
 
void setLocale (const WLocale &locale)
 
const WLocalelocale () const
 
virtual void refresh ()
 
void bindWidget (WWidget *widget, const std::string &domId)
 
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
 
std::string internalSubPath (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)
 
std::string docRoot () const
 
void setConnectionMonitor (const std::string &jsObject)
 
std::string sessionId () const
 
void changeSessionId ()
 
WebSession * session () const
 
void enableUpdates (bool enabled=true)
 
bool updatesEnabled () const
 
void triggerUpdate ()
 
UpdateLock getUpdateLock ()
 
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 ()
 
void processEvents ()
 
virtual void waitForEvent ()
 
void setAjaxMethod (AjaxMethod method)
 
AjaxMethod ajaxMethod () const
 
WContainerWidgetdomRoot () const
 
WContainerWidgetdomRoot2 () const
 
std::string encodeObject (WObject *object)
 
WObjectdecodeObject (const std::string &objectId) const
 
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 setCookie (const std::string &name, const std::string &value, const WDateTime &expires, 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 (WLoadingIndicator *indicator)
 
WLoadingIndicatorloadingIndicator () const
 
std::string onePixelGifUrl ()
 
std::string docType () const
 
void quit ()
 
void quit (const WString &restartMessage)
 
bool isQuited () const
 
bool hasQuit () const
 
::int64_t maximumRequestSize () const
 
Signal< ::int64_t > & requestTooLarge ()
 
bool isConnected () const
 
- Public Member Functions inherited from Wt::WObject
 WObject (WObject *parent=0)
 
virtual ~WObject ()
 
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)
 
void addChild (WObject *child)
 
virtual void removeChild (WObject *child)
 
const std::vector< WObject * > & children () const
 
WObjectparent () const
 

Private Member Functions

void createUI ()
 Setup the user interface.
 
WTextcreateTitle (const WString &title)
 Creates a title widget.
 
WTreeViewfolderView ()
 Creates the folder WTreeView.
 
WTableViewfileView ()
 Creates the file table view (a WTableView)
 
void editFile (const WModelIndex &item)
 Edit a particular row.
 
WWidgetpieChart ()
 Creates the chart.
 
WWidgetaboutDisplay ()
 Creates the hints text.
 
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 popupAction ()
 Process the result of the popup menu.
 
void dialogDone ()
 Process the result of the message box.
 
void populateFiles ()
 Populate the files model.
 
void convertToDate (WStandardItem *item)
 Convert a string to a date.
 
void convertToNumber (WStandardItem *item)
 Convert a string to a number.
 
void populateFolders ()
 Populate the folders model.
 
WStandardItemcreateFolderItem (const WString &location, const std::string &folderId=std::string())
 Create a folder item.
 

Private Attributes

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

Additional Inherited Members

- Public Types inherited from Wt::WApplication
enum  AjaxMethod
 
typedef Wt::ApplicationCreator ApplicationCreator
 
typedef boost::function< 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 bool pathMatches (const std::string &path, const std::string &query)
 
static std::string resourcesUrl ()
 
static std::string relativeResourcesUrl ()
 
static std::string appRoot ()
 
static bool readConfigurationProperty (const std::string &name, std::string &value)
 
- Public Attributes inherited from Wt::WApplication
 XMLHttpRequest
 
 DynamicScriptTag
 
- 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)
 
- Static Protected Member Functions inherited from Wt::WObject
static WObjectsender ()
 

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),
246 {
247 setCssTheme("polished");
248
249 /*
250 * Create the data models.
251 */
252 folderModel_ = new WStandardItemModel(0, 1, this);
254
255 fileModel_ = new FileModel(this);
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 */
272
273 /*
274 * Setup the user interface.
275 */
276 createUI();
277 }
A specialized standard item model which report a specific drag and drop mime type.
WMessageBox * popupActionBox_
Message box to confirm the poup menu action.
WSortFilterProxyModel * fileFilterModel_
The sort filter proxy model that adapts fileModel_.
WPopupMenu * popup_
Popup menu on the folder view.
void createUI()
Setup the user interface.
WStandardItemModel * folderModel_
The folder model (used by folderView_)
WStandardItemModel * fileModel_
The file model (used by fileView_)
void populateFiles()
Populate the files model.
void populateFolders()
Populate the folders model.
void setCssTheme(const std::string &name)
WEnvironment & env()
void setFilterRole(int role)
void setDynamicSortFilter(bool enable)
virtual void setSourceModel(WAbstractItemModel *sourceModel)
void setFilterKeyColumn(int column)
UserRole

◆ ~TreeViewDragDrop()

virtual TreeViewDragDrop::~TreeViewDragDrop ( )
inlinevirtual

Definition at line 279 of file TreeViewDragDrop.C.

279 {
280 delete popup_;
281 delete popupActionBox_;
282 }

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 }
static WString tr(const char *key)
virtual void setStyleClass(const WString &styleClass)

◆ convertToDate()

void TreeViewDragDrop::convertToDate ( WStandardItem item)
inlineprivate

Convert a string to a date.

Definition at line 588 of file TreeViewDragDrop.C.

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

◆ 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 }
EditRole

◆ 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 }
std::map< std::string, WString > folderNameMap_
Maps folder id's to folder descriptions.
void setIcon(const std::string &uri)
WFlags< ItemFlag > flags() const
void setFlags(WFlags< ItemFlag > flags)
ItemIsSelectable
ItemIsDropEnabled

◆ 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 }
const WString & title() const
virtual void setInline(bool isInline)

◆ 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 }
WText * createTitle(const WString &title)
Creates a title widget.
WWidget * pieChart()
Creates the chart.
WTreeView * folderView()
Creates the folder WTreeView.
WWidget * aboutDisplay()
Creates the hints text.
WTableView * fileView()
Creates the file table view (a WTableView)
WTreeView * folderView_
The folder view.
virtual WModelIndex index(int row, int column, const WModelIndex &parent=WModelIndex()) const=0
void select(const WModelIndex &index, SelectionFlag option=Select)
WContainerWidget * root() const
void addWidget(WWidget *widget, int stretch=0, WFlags< AlignmentFlag > alignment=0)
void setResizable(int index, bool enabled=true, const WLength &initialSize=WLength::Auto)
void setLayout(WLayout *layout)
void setColumnStretch(int column, int stretch)
void setColumnResizable(int column, bool enabled=true, const WLength &initialSize=WLength::Auto)
void addWidget(WWidget *widget, int row, int column, WFlags< AlignmentFlag > alignment=0)
void addLayout(WLayout *layout, int row, int column, WFlags< AlignmentFlag > alignment=0)
void setRowStretch(int row, int stretch)

◆ 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 }

◆ 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 }
A dialog for editing a 'file'.
WTableView * fileView_
The file view.
WAbstractItemModel * model() const

◆ 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_);
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 }
static WString dateDisplayFormat
Date display format.
void editFile(const WModelIndex &item)
Edit a particular row.
void setDragEnabled(bool enable)
void setItemDelegateForColumn(int column, WAbstractItemDelegate *delegate)
virtual void setColumnAlignment(int column, AlignmentFlag alignment)
Signal< WModelIndex, WMouseEvent > & doubleClicked()
void setSelectionMode(SelectionMode mode)
void sortByColumn(int column, SortOrder order)
void setTextFormat(const WString &format)
virtual void setModel(WAbstractItemModel *model)
virtual void setColumnWidth(int column, const WLength &width)
virtual void setAlternatingRowColors(bool enable)
AscendingOrder
ExtendedSelection
AlignRight

◆ 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 }
WModelIndexSet selectedIndexes() const
boost::any data(int role=DisplayRole) const
void setFilterRegExp(const WString &pattern)

◆ 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);
373 treeView->expandToDepth(1);
374 treeView->selectionChanged()
376
377 treeView->mouseWentUp().connect(this, &TreeViewDragDrop::showPopup);
378
379 folderView_ = treeView;
380
381 return treeView;
382 }
A specialized treeview that supports a custom drop event.
Definition FolderView.h:20
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.
virtual Wt::Signals::connection connect(WObject *target, WObject::Method method)
Signal< WModelIndex, WMouseEvent > & mouseWentUp()
Signal & selectionChanged()
virtual void setAttributeValue(const std::string &name, const WString &value)
static WLength Auto
virtual void setModel(WAbstractItemModel *model)
virtual void resize(const WLength &width, const WLength &height)
void expandToDepth(int depth)
SingleSelection

◆ 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 }
friend friend class WContainerWidget
const WEnvironment & environment() const
virtual void addWidget(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
583 }
584 }
void convertToDate(WStandardItem *item)
Convert a string to a date.
void convertToNumber(WStandardItem *item)
Convert a string to a number.
virtual int rowCount(const WModelIndex &parent=WModelIndex()) const=0
static std::string appRoot()
WStandardItem * invisibleRootItem() const
WStandardItem * item(int row, int column=0) const
void setText(const WString &text)
void setRowCount(int rows)
std::string toUTF8() const
ItemIsDragEnabled
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

◆ 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
625 boost::any(std::string("SandBox")));
626 }
WStandardItem * createFolderItem(const WString &location, const std::string &folderId=std::string())
Create a folder item.
virtual bool setHeaderData(int section, Orientation orientation, const boost::any &value, int role=EditRole)
void appendRow(const std::vector< WStandardItem * > &items)
void appendRow(const std::vector< WStandardItem * > &items)
static WString fromUTF8(const std::string &value, bool checkValid=false)
Horizontal

◆ 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);
539 .connect(this, &TreeViewDragDrop::dialogDone);
541 } else {
542 popup_->hide();
543 }
544 }
void dialogDone()
Process the result of the message box.
const WString & text() const
Signal< StandardButton > & buttonClicked()
static StandardButton show(const WString &caption, const WString &text, WFlags< StandardButton > buttons, const WAnimation &animation=WAnimation())
WMenuItem * result() const

◆ 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");
497 popup_->addItem("Folder Details");
499 popup_->addItem("Application Inventory");
500 popup_->addItem("Hardware Inventory");
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 }
void popupAction()
Process the result of the popup menu.
bool isSelected(const WModelIndex &index) const
virtual bool isHidden() const
void setCheckable(bool checkable)
WMenuItem * addItem(const WString &label, WWidget *contents=0, WMenuItem::LoadPolicy policy=WMenuItem::LazyLoading)
WMenuItem * addSeparator()
WMenuItem * addMenu(const WString &text, WMenu *menu)
Button button() const
Signal & aboutToHide()
void popup(const WPoint &point)

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 Fri May 17 2024 for the C++ Web Toolkit (Wt) by doxygen 1.9.8