Wt examples  3.2.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.
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
WLocalizedStringslocalizedStrings ()
void setLocalizedStrings (WLocalizedStrings *stringResolver)
WMessageResourceBundlemessageResourceBundle ()
void setLocale (const std::string &locale)
std::string locale () const
virtual void refresh ()
void bindWidget (WWidget *widget, const std::string &domId)
std::string docRoot () const
std::string sessionId () const
void changeSessionId ()
void processEvents ()
void setAjaxMethod (AjaxMethod method)
AjaxMethod ajaxMethod () 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 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="")
void removeMetaHeader (MetaHeaderType type, const std::string &name="")
WLogEntry log (const std::string &type) const
void setLoadingIndicator (WLoadingIndicator *indicator)
WLoadingIndicatorloadingIndicator () const
void quit ()
bool isQuited () const
::int64_t maximumRequestSize () const
Signal< ::int64_t > & requestTooLarge ()
void setConfirmCloseMessage (const WString &message)
void deferRendering ()
void resumeRendering ()
boost::function< void()> bind (const F &f)
WCssStyleSheetstyleSheet ()
void useStyleSheet (const std::string &url)
void useStyleSheet (const std::string &url, const std::string &condition, const std::string &media="all")
void setCssTheme (const std::string &theme)
std::string cssTheme () const
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)
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 ()
void redirect (const std::string &url)
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())
void setJavaScriptClass (const std::string &className)
std::string javaScriptClass ()
EventSignal< WKeyEvent > & globalKeyWentDown ()
EventSignal< WKeyEvent > & globalKeyPressed ()
EventSignal< WKeyEvent > & globalKeyWentUp ()
EventSignalglobalEnterPressed ()
EventSignalglobalEscapePressed ()
 WObject (WObject *parent=0)
virtual ~WObject ()
virtual const std::string id () const
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)())
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 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 void(WObject::* Method )()
typedef boost::function
< WApplication *(const
WEnvironment &)> 
ApplicationCreator
- Static Public Member Functions inherited from Wt::WApplication
static WApplicationinstance ()
static std::string resourcesUrl ()
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 WStatelessSlot * getStateless (Method method)
- Static Protected Member Functions inherited from Wt::WApplication
static WObjectsender ()

Detailed Description

Main application class.

Definition at line 237 of file TreeViewDragDrop.C.

Constructor & Destructor Documentation

TreeViewDragDrop::TreeViewDragDrop ( const WEnvironment env)
inline

Constructor.

Definition at line 242 of file TreeViewDragDrop.C.

: WApplication(env),
popup_(0),
{
setCssTheme("polished");
/*
* Create the data models.
*/
folderModel_ = new WStandardItemModel(0, 1, this);
fileModel_ = new FileModel(this);
/*
The header items are also endered using an ItemDelegate, and thus
support other data, e.g.:
fileModel_->setHeaderFlags(0, Horizontal, HeaderIsUserCheckable);
fileModel_->setHeaderData(0, Horizontal,
std::string("icons/file.gif"),
Wt::DecorationRole);
*/
/*
* Setup the user interface.
*/
}
virtual TreeViewDragDrop::~TreeViewDragDrop ( )
inlinevirtual

Definition at line 279 of file TreeViewDragDrop.C.

{
delete popup_;
}

Member Function Documentation

WWidget* TreeViewDragDrop::aboutDisplay ( )
inlineprivate

Creates the hints text.

Definition at line 456 of file TreeViewDragDrop.C.

{
WText *result = new WText(WString::tr("about-text"));
result->setStyleClass("about");
return result;
}
void TreeViewDragDrop::convertToDate ( WStandardItem item)
inlineprivate

Convert a string to a date.

Definition at line 586 of file TreeViewDragDrop.C.

{
WDate d = WDate::fromString(item->text(), FileModel::dateEditFormat);
item->setData(boost::any(d), DisplayRole);
}
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 623 of file TreeViewDragDrop.C.

{
WStandardItem *result = new WStandardItem(location);
if (!folderId.empty()) {
result->setData(boost::any(folderId));
result->setFlags(result->flags() | ItemIsDropEnabled);
folderNameMap_[folderId] = location;
} else
result->setFlags(result->flags().clear(ItemIsSelectable));
result->setIcon("icons/folder.gif");
return result;
}
WText* TreeViewDragDrop::createTitle ( const WString title)
inlineprivate

Creates a title widget.

Definition at line 347 of file TreeViewDragDrop.C.

{
WText *result = new WText(title);
result->setInline(false);
result->setStyleClass("title");
return result;
}
void TreeViewDragDrop::createUI ( )
inlineprivate

Setup the user interface.

Definition at line 311 of file TreeViewDragDrop.C.

{
w->setStyleClass("maindiv");
/*
* The main layout is a 3x2 grid layout.
*/
WGridLayout *layout = new WGridLayout();
layout->addWidget(createTitle("Folders"), 0, 0);
layout->addWidget(createTitle("Files"), 0, 1);
layout->addWidget(folderView(), 1, 0);
layout->setColumnResizable(0);
// select the first folder
WVBoxLayout *vbox = new WVBoxLayout();
vbox->addWidget(fileView(), 1);
vbox->addWidget(pieChart(), 1);
vbox->setResizable(0);
layout->addLayout(vbox, 1, 1);
layout->addWidget(aboutDisplay(), 2, 0, 1, 2, AlignTop);
/*
* Let row 1 and column 1 take the excess space.
*/
layout->setRowStretch(1, 1);
layout->setColumnStretch(1, 1);
w->setLayout(layout);
}
void TreeViewDragDrop::dialogDone ( )
inlineprivate

Process the result of the message box.

Definition at line 547 of file TreeViewDragDrop.C.

{
}
void TreeViewDragDrop::editFile ( const WModelIndex item)
inlineprivate

Edit a particular row.

Definition at line 422 of file TreeViewDragDrop.C.

{
}
WTableView* TreeViewDragDrop::fileView ( )
inlineprivate

Creates the file table view (a WTableView)

Definition at line 386 of file TreeViewDragDrop.C.

{
WTableView *tableView = new WTableView();
tableView->setAlternatingRowColors(true);
tableView->setSelectionMode(ExtendedSelection);
tableView->setDragEnabled(true);
tableView->setColumnWidth(0, 100);
tableView->setColumnWidth(1, 150);
tableView->setColumnWidth(2, 100);
tableView->setColumnWidth(3, 60);
tableView->setColumnWidth(4, 100);
tableView->setColumnWidth(5, 100);
WItemDelegate *delegate = new WItemDelegate(this);
tableView->setItemDelegateForColumn(4, delegate);
tableView->setItemDelegateForColumn(5, delegate);
tableView->setColumnAlignment(3, AlignRight);
tableView->setColumnAlignment(4, AlignRight);
tableView->setColumnAlignment(5, AlignRight);
tableView->sortByColumn(1, AscendingOrder);
tableView->doubleClicked().connect(this, &TreeViewDragDrop::editFile);
fileView_ = tableView;
return tableView;
}
void TreeViewDragDrop::folderChanged ( )
inlineprivate

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

Definition at line 465 of file TreeViewDragDrop.C.

{
if (folderView_->selectedIndexes().empty())
return;
WModelIndex selected = *folderView_->selectedIndexes().begin();
boost::any d = selected.data(UserRole);
if (!d.empty()) {
std::string folder = boost::any_cast<std::string>(d);
// For simplicity, we assume here that the folder-id does not
// contain special regexp characters, otherwise these need to be
// escaped -- or use the \Q \E qutoing escape regular expression
// syntax (and escape \E)
}
}
WTreeView* TreeViewDragDrop::folderView ( )
inlineprivate

Creates the folder WTreeView.

Definition at line 357 of file TreeViewDragDrop.C.

{
WTreeView *treeView = new FolderView();
/*
* To support right-click, we need to disable the built-in browser
* context menu.
*
* Note that disabling the context menu and catching the
* right-click does not work reliably on all browsers.
*/
("oncontextmenu",
"event.cancelBubble = true; event.returnValue = false; return false;");
treeView->setModel(folderModel_);
treeView->resize(200, WLength::Auto);
treeView->setSelectionMode(SingleSelection);
treeView->expandToDepth(1);
treeView->selectionChanged()
treeView->mouseWentUp().connect(this, &TreeViewDragDrop::showPopup);
folderView_ = treeView;
return treeView;
}
WWidget* TreeViewDragDrop::pieChart ( )
inlineprivate

Creates the chart.

Definition at line 428 of file TreeViewDragDrop.C.

{
using namespace Chart;
WPieChart *chart = new WPieChart();
chart->setModel(fileFilterModel_);
chart->setTitle("File sizes");
chart->setLabelsColumn(1); // Name
chart->setDataColumn(3); // Size
chart->setPerspectiveEnabled(true, 0.2);
chart->setDisplayLabels(Outside | TextLabel);
if (!WApplication::instance()->environment().ajax()) {
chart->resize(500, 200);
chart->setMargin(WLength::Auto, Left | Right);
w->addWidget(chart);
w->setStyleClass("about");
return w;
} else {
chart->setStyleClass("about");
return chart;
}
}
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 559 of file TreeViewDragDrop.C.

{
std::ifstream f((appRoot() + "data/files.csv").c_str());
if (!f)
throw std::runtime_error("Could not read: data/files.csv");
for (int i = 0; i < fileModel_->rowCount(); ++i) {
WStandardItem *item = fileModel_->item(i, 0);
item->setFlags(item->flags() | ItemIsDragEnabled);
item->setIcon("icons/file.gif");
std::string folderId = item->text().toUTF8();
item->setData(boost::any(folderId), UserRole);
item->setText(folderNameMap_[folderId]);
}
}
void TreeViewDragDrop::populateFolders ( )
inlineprivate

Populate the folders model.

Definition at line 593 of file TreeViewDragDrop.C.

{
WStandardItem *level1, *level2;
folderModel_->appendRow(level1 = createFolderItem("San Fransisco"));
level1->appendRow(level2 = createFolderItem("Investors", "sf-investors"));
level1->appendRow(level2 = createFolderItem("Fellows", "sf-fellows"));
folderModel_->appendRow(level1 = createFolderItem("Sophia Antipolis"));
level1->appendRow(level2 = createFolderItem("R&D", "sa-r_d"));
level1->appendRow(level2 = createFolderItem("Services", "sa-services"));
level1->appendRow(level2 = createFolderItem("Support", "sa-support"));
level1->appendRow(level2 = createFolderItem("Billing", "sa-billing"));
folderModel_->appendRow(level1 = createFolderItem("New York"));
level1->appendRow(level2 = createFolderItem("Marketing", "ny-marketing"));
level1->appendRow(level2 = createFolderItem("Sales", "ny-sales"));
level1->appendRow(level2 = createFolderItem("Advisors", "ny-advisors"));
(WString::fromUTF8("Frankfürt")));
level1->appendRow(level2 = createFolderItem("Sales", "frank-sales"));
folderModel_->setHeaderData(0, Horizontal,
boost::any(std::string("SandBox")));
}
void TreeViewDragDrop::popupAction ( )
inlineprivate

Process the result of the popup menu.

Definition at line 526 of file TreeViewDragDrop.C.

{
if (popup_->result()) {
/*
* You could also bind extra data to an item using setData() and
* check here for the action asked. For now, we just use the text.
*/
WString text = popup_->result()->text();
popupActionBox_ = new WMessageBox("Sorry.","Action '" + text
+ "' is not implemented.", NoIcon, Ok);
.connect(this, &TreeViewDragDrop::dialogDone);
} else {
}
}
void TreeViewDragDrop::showPopup ( const WModelIndex item,
const WMouseEvent event 
)
inlineprivate

Show a popup for a folder item.

Definition at line 484 of file TreeViewDragDrop.C.

{
if (event.button() == WMouseEvent::RightButton) {
// Select the item, it was not yet selected.
if (!folderView_->isSelected(item))
if (!popup_) {
popup_ = new WPopupMenu();
popup_->addItem("icons/folder_new.gif", "Create a New Folder");
popup_->addItem("Rename this Folder")->setCheckable(true);
popup_->addItem("Delete this Folder");
popup_->addItem("Folder Details");
popup_->addItem("Application Inventory");
popup_->addItem("Hardware Inventory");
WPopupMenu *subMenu = new WPopupMenu();
subMenu->addItem("Sub Item 1");
subMenu->addItem("Sub Item 2");
popup_->addMenu("File Deployments", subMenu);
/*
* This is one method of executing a popup, which does not block a
* thread for a reentrant event loop, and thus scales.
*
* Alternatively you could call WPopupMenu::exec(), which returns
* the result, but while waiting for it, blocks the thread.
*/
}
if (popup_->isHidden())
popup_->popup(event);
else
}
}

Member Data Documentation

WSortFilterProxyModel* TreeViewDragDrop::fileFilterModel_
private

The sort filter proxy model that adapts fileModel_.

Definition at line 292 of file TreeViewDragDrop.C.

WStandardItemModel* TreeViewDragDrop::fileModel_
private

The file model (used by fileView_)

Definition at line 289 of file TreeViewDragDrop.C.

WTableView* TreeViewDragDrop::fileView_
private

The file view.

Definition at line 301 of file TreeViewDragDrop.C.

WStandardItemModel* TreeViewDragDrop::folderModel_
private

The folder model (used by folderView_)

Definition at line 286 of file TreeViewDragDrop.C.

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

Maps folder id's to folder descriptions.

Definition at line 295 of file TreeViewDragDrop.C.

WTreeView* TreeViewDragDrop::folderView_
private

The folder view.

Definition at line 298 of file TreeViewDragDrop.C.

WPopupMenu* TreeViewDragDrop::popup_
private

Popup menu on the folder view.

Definition at line 304 of file TreeViewDragDrop.C.

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 Wed Aug 27 2014 for the C++ Web Toolkit (Wt) by doxygen 1.8.1.2