Main application class. More...
Inherits Wt::WApplication.
Public Member Functions | |
TreeViewDragDrop (const WEnvironment &env) | |
Constructor. | |
virtual | ~TreeViewDragDrop () |
Private Member Functions | |
void | createUI () |
Setup the user interface. | |
WText * | createTitle (const WString &title) |
Creates a title widget. | |
WTreeView * | folderView () |
Creates the folder WTreeView. | |
WTreeView * | fileView () |
Creates the file table view (also a WTreeView). | |
void | editFile (const WModelIndex &item) |
Edit a particular row. | |
WWidget * | pieChart () |
Creates the chart. | |
WWidget * | aboutDisplay () |
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. | |
WStandardItem * | createFolderItem (const WString &location, const std::string &folderId=std::string()) |
Create a folder item. | |
Private Attributes | |
WStandardItemModel * | folderModel_ |
The folder model (used by folderView_). | |
WStandardItemModel * | fileModel_ |
The file model (used by fileView_). | |
WSortFilterProxyModel * | fileFilterModel_ |
The sort filter proxy model that adapts fileModel_. | |
std::map< std::string, WString > | folderNameMap_ |
Maps folder id's to folder descriptions. | |
WTreeView * | folderView_ |
The folder view. | |
WTreeView * | fileView_ |
The file view. | |
WPopupMenu * | popup_ |
Popup menu on the folder view. | |
WMessageBox * | popupActionBox_ |
Message box to confirm the poup menu action. |
Main application class.
Definition at line 235 of file TreeViewDragDrop.C.
TreeViewDragDrop::TreeViewDragDrop | ( | const WEnvironment & | env | ) | [inline] |
Constructor.
Definition at line 240 of file TreeViewDragDrop.C.
: WApplication(env), popup_(0), popupActionBox_(0) { setCssTheme("polished"); /* * Create the data models. */ folderModel_ = new WStandardItemModel(0, 1, this); populateFolders(); fileModel_ = new FileModel(this); populateFiles(); fileFilterModel_ = new WSortFilterProxyModel(this); fileFilterModel_->setSourceModel(fileModel_); fileFilterModel_->setDynamicSortFilter(true); fileFilterModel_->setFilterKeyColumn(0); fileFilterModel_->setFilterRole(UserRole); /* * Setup the user interface. */ createUI(); }
virtual TreeViewDragDrop::~TreeViewDragDrop | ( | ) | [inline, virtual] |
Definition at line 268 of file TreeViewDragDrop.C.
{ delete popup_; delete popupActionBox_; }
WWidget* TreeViewDragDrop::aboutDisplay | ( | ) | [inline, private] |
Creates the hints text.
Definition at line 439 of file TreeViewDragDrop.C.
{ WText *result = new WText(WString::tr("about-text")); result->setStyleClass("about"); return result; }
void TreeViewDragDrop::convertToDate | ( | WStandardItem * | item | ) | [inline, private] |
Convert a string to a date.
Definition at line 563 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() | |||
) | [inline, private] |
Create a folder item.
Configures flags for drag and drop support.
Definition at line 600 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; }
Creates a title widget.
Definition at line 336 of file TreeViewDragDrop.C.
{ WText *result = new WText(title); result->setInline(false); result->setStyleClass("title"); return result; }
void TreeViewDragDrop::createUI | ( | ) | [inline, private] |
Setup the user interface.
Definition at line 300 of file TreeViewDragDrop.C.
{ WContainerWidget *w = root(); 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 folderView_->select(folderModel_->index(0, 0, folderModel_->index(0, 0))); 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 | ( | ) | [inline, private] |
Process the result of the message box.
Definition at line 528 of file TreeViewDragDrop.C.
{ delete popupActionBox_; popupActionBox_ = 0; }
void TreeViewDragDrop::editFile | ( | const WModelIndex & | item | ) | [inline, private] |
Edit a particular row.
Definition at line 414 of file TreeViewDragDrop.C.
{ new FileEditDialog(fileView_->model(), item); }
WTreeView* TreeViewDragDrop::fileView | ( | ) | [inline, private] |
Creates the file table view (also a WTreeView).
Definition at line 375 of file TreeViewDragDrop.C.
{ WTreeView *treeView = new WTreeView(); // Hide the tree-like decoration on the first column, to make it // resemble a plain table treeView->setRootIsDecorated(false); treeView->setAlternatingRowColors(true); treeView->setModel(fileFilterModel_); treeView->setSelectionMode(ExtendedSelection); treeView->setDragEnabled(true); treeView->setColumnWidth(0, 100); treeView->setColumnWidth(1, 150); treeView->setColumnWidth(2, 100); treeView->setColumnWidth(3, 60); treeView->setColumnWidth(4, 100); treeView->setColumnWidth(5, 100); WItemDelegate *delegate = new WItemDelegate(this); delegate->setTextFormat(FileModel::dateDisplayFormat); treeView->setItemDelegateForColumn(4, delegate); treeView->setItemDelegateForColumn(5, delegate); treeView->setColumnAlignment(3, AlignRight); treeView->setColumnAlignment(4, AlignRight); treeView->setColumnAlignment(5, AlignRight); treeView->sortByColumn(1, AscendingOrder); treeView->doubleClicked().connect(SLOT(this, TreeViewDragDrop::editFile)); fileView_ = treeView; return treeView; }
void TreeViewDragDrop::folderChanged | ( | ) | [inline, private] |
Change the filter on the file view when the selected folder changes.
Definition at line 448 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) fileFilterModel_->setFilterRegExp(folder); } }
WTreeView* TreeViewDragDrop::folderView | ( | ) | [inline, private] |
Creates the folder WTreeView.
Definition at line 346 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. */ treeView->setAttributeValue ("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().connect(SLOT(this, TreeViewDragDrop::folderChanged)); treeView->mouseWentUp().connect(SLOT(this, TreeViewDragDrop::showPopup)); folderView_ = treeView; return treeView; }
WWidget* TreeViewDragDrop::pieChart | ( | ) | [inline, private] |
Creates the chart.
Definition at line 420 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); chart->setStyleClass("about"); return chart; }
void TreeViewDragDrop::populateFiles | ( | ) | [inline, private] |
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 540 of file TreeViewDragDrop.C.
{ fileModel_->invisibleRootItem()->setRowCount(0); std::ifstream f("data/files.csv"); readFromCsv(f, fileModel_); 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]); convertToDate(fileModel_->item(i, 4)); convertToDate(fileModel_->item(i, 5)); } }
void TreeViewDragDrop::populateFolders | ( | ) | [inline, private] |
Populate the folders model.
Definition at line 570 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")); folderModel_->appendRow(level1 = createFolderItem (WString::fromUTF8("Frankfürt"))); level1->appendRow(level2 = createFolderItem("Sales", "frank-sales")); folderModel_->setHeaderData(0, Horizontal, boost::any(std::string("SandBox"))); }
void TreeViewDragDrop::popupAction | ( | ) | [inline, private] |
Process the result of the popup menu.
Definition at line 505 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(); delete popup_; popup_ = 0; popupActionBox_ = new WMessageBox("Sorry.","Action '" + text + "' is not implemented.", NoIcon, Ok); popupActionBox_->buttonClicked() .connect(SLOT(this, TreeViewDragDrop::dialogDone)); popupActionBox_->show(); } else { delete popup_; popup_ = 0; } }
void TreeViewDragDrop::showPopup | ( | const WModelIndex & | item, | |
const WMouseEvent & | event | |||
) | [inline, private] |
Show a popup for a folder item.
Definition at line 467 of file TreeViewDragDrop.C.
{ if (event.button() == WMouseEvent::RightButton) { // Select the item, it was not yet selected. if (!folderView_->isSelected(item)) folderView_->select(item); delete 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_->addSeparator(); popup_->addItem("Folder Details"); popup_->addSeparator(); popup_->addItem("Application Inventory"); popup_->addItem("Hardware Inventory"); popup_->addSeparator(); 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. */ popup_->aboutToHide().connect(SLOT(this, TreeViewDragDrop::popupAction)); popup_->popup(event); } }
The sort filter proxy model that adapts fileModel_.
Definition at line 281 of file TreeViewDragDrop.C.
WStandardItemModel* TreeViewDragDrop::fileModel_ [private] |
The file model (used by fileView_).
Definition at line 278 of file TreeViewDragDrop.C.
WTreeView* TreeViewDragDrop::fileView_ [private] |
The file view.
Definition at line 290 of file TreeViewDragDrop.C.
WStandardItemModel* TreeViewDragDrop::folderModel_ [private] |
The folder model (used by folderView_).
Definition at line 275 of file TreeViewDragDrop.C.
std::map<std::string, WString> TreeViewDragDrop::folderNameMap_ [private] |
Maps folder id's to folder descriptions.
Definition at line 284 of file TreeViewDragDrop.C.
WTreeView* TreeViewDragDrop::folderView_ [private] |
The folder view.
Definition at line 287 of file TreeViewDragDrop.C.
WPopupMenu* TreeViewDragDrop::popup_ [private] |
Popup menu on the folder view.
Definition at line 293 of file TreeViewDragDrop.C.
WMessageBox* TreeViewDragDrop::popupActionBox_ [private] |
Message box to confirm the poup menu action.
Definition at line 296 of file TreeViewDragDrop.C.