8#include <Wt/WApplication.h>
9#include <Wt/WComboBox.h>
10#include <Wt/WContainerWidget.h>
11#include <Wt/WDatePicker.h>
12#include <Wt/WDateValidator.h>
13#include <Wt/WDialog.h>
14#include <Wt/WEnvironment.h>
15#include <Wt/WIntValidator.h>
16#include <Wt/WItemDelegate.h>
18#include <Wt/WLineEdit.h>
19#include <Wt/WMessageBox.h>
20#include <Wt/WPushButton.h>
21#include <Wt/WRegExpValidator.h>
22#include <Wt/WGridLayout.h>
23#include <Wt/WPopupMenu.h>
24#include <Wt/WSortFilterProxyModel.h>
25#include <Wt/WStandardItem.h>
26#include <Wt/WStandardItemModel.h>
27#include <Wt/WTableView.h>
28#include <Wt/WTreeView.h>
30#include <Wt/WVBoxLayout.h>
32#include <Wt/Chart/WPieChart.h>
57 : WStandardItemModel() { }
81 FileEditDialog(std::shared_ptr<WAbstractItemModel> model,
const WModelIndex& item)
86 int modelRow =
item_.row();
88 resize(300, WLength::Auto);
95 auto nameEdit = std::make_unique<WLineEdit>(asString(
model_->data(modelRow, 1)));
99 auto typeEdit = std::make_unique<WComboBox>();
108 auto sizeEdit = std::make_unique<WLineEdit>(asString(
model_->data(modelRow, 3)));
111 (std::make_shared<WIntValidator>(0, std::numeric_limits<int>::max()));
115 auto createdPicker = std::make_unique<WDatePicker>();
122 auto modifiedPicker = std::make_unique<WDatePicker>();
131 auto layout = std::make_unique<WGridLayout>();
133 std::unique_ptr<WLabel> label;
136 label = std::make_unique<WLabel>(
"Name:");
138 layout->addWidget(std::move(label), row, 0);
139 layout->addWidget(std::move(nameEdit), row, 1);
142 label = std::make_unique<WLabel>(
"Type:");
144 layout->addWidget(std::move(label), row, 0);
145 layout->addWidget(std::move(typeEdit), row, 1);
148 label = std::make_unique<WLabel>(
"Size");
150 layout->addWidget(std::move(label), row, 0);
151 layout->addWidget(std::move(sizeEdit), row, 1);
154 label = std::make_unique<WLabel>(
"Created:");
156 layout->addWidget(std::move(label), row, 0);
157 layout->addWidget(std::move(createdPicker), row, 2);
160 label = std::make_unique<WLabel>(
"Modified:");
162 layout->addWidget(std::move(label), row, 0);
163 layout->addWidget(std::move(modifiedPicker), row, 2);
166 std::unique_ptr<WPushButton>button;
167 auto buttons = std::make_unique<WContainerWidget>();
169 button = std::make_unique<WPushButton>(
"Save");
170 button->clicked().connect(
this, &WDialog::accept);
171 buttons->addWidget(std::move(button));
173 button = std::make_unique<WPushButton>(
"Cancel");
174 contents()->enterPressed().connect(
this, &WDialog::accept);
175 button->clicked().connect(
this, &WDialog::reject);
176 buttons->addWidget(std::move(button));
181 switch (item.column()) {
196 layout->addWidget(std::move(buttons), row, 0, 0, 3, AlignmentFlag::Center);
197 layout->setColumnStretch(1, 1);
199 contents()->setLayout(std::move(layout));
207 std::shared_ptr<WAbstractItemModel>
model_;
216 if (result == DialogCode::Accepted) {
227 std::shared_ptr<WAbstractItemModel> m =
model_;
228 int modelRow =
item_.row();
230 std::shared_ptr<WAbstractProxyModel> proxyModel =
231 std::dynamic_pointer_cast<WAbstractProxyModel>(m);
233 m = proxyModel->sourceModel();
234 modelRow = proxyModel->mapToSource(
item_).row();
237 m->setData(modelRow, 1, cpp17::any(
nameEdit_->text()));
238 m->setData(modelRow, 2, cpp17::any(
typeEdit_->currentText()));
239 m->setData(modelRow, 3, cpp17::any(asNumber
263 setCssTheme(
"polished");
269 std::make_shared<WStandardItemModel>(0, 1);
274 std::make_shared<FileModel>();
334 WContainerWidget *w = root();
335 w->setStyleClass(
"maindiv");
340 std::unique_ptr<WGridLayout> layout =
341 std::make_unique<WGridLayout>();
345 layout->setColumnResizable(0);
350 std::unique_ptr<WVBoxLayout> vbox =
351 std::make_unique<WVBoxLayout>();
354 vbox->setResizable(0);
356 layout->addLayout(std::move(vbox), 1, 1);
363 layout->setRowStretch(1, 1);
364 layout->setColumnStretch(1, 1);
366 w->setLayout(std::move(layout));
372 auto result = std::make_unique<WText>(title);
373 result->setInline(
false);
374 result->setStyleClass(
"title");
382 auto treeView = std::make_unique<FolderView>();
391 treeView->setAttributeValue
393 "event.cancelBubble = true; event.returnValue = false; return false;");
395 treeView->resize(200, WLength::Auto);
396 treeView->setSelectionMode(SelectionMode::Single);
397 treeView->expandToDepth(1);
398 treeView->selectionChanged()
405 return std::move(treeView);
412 = std::make_unique<WTableView>();
414 tableView->setAlternatingRowColors(
true);
417 tableView->setSelectionMode(SelectionMode::Extended);
418 tableView->setDragEnabled(
true);
420 tableView->setColumnWidth(0, 100);
421 tableView->setColumnWidth(1, 150);
422 tableView->setColumnWidth(2, 100);
423 tableView->setColumnWidth(3, 60);
424 tableView->setColumnWidth(4, 100);
425 tableView->setColumnWidth(5, 100);
427 auto delegate = std::make_shared<WItemDelegate>();
429 tableView->setItemDelegateForColumn(4, delegate);
430 tableView->setItemDelegateForColumn(5, delegate);
432 tableView->setColumnAlignment(3, AlignmentFlag::Right);
433 tableView->setColumnAlignment(4, AlignmentFlag::Right);
434 tableView->setColumnAlignment(5, AlignmentFlag::Right);
436 tableView->sortByColumn(1, SortOrder::Ascending);
439 this, std::placeholders::_1));
455 using namespace Chart;
457 auto chart = std::make_unique<WPieChart>();
460 chart->setTitle(
"File sizes");
462 chart->setLabelsColumn(1);
463 chart->setDataColumn(3);
465 chart->setPerspectiveEnabled(
true, 0.2);
466 chart->setDisplayLabels(LabelOption::Outside | LabelOption::TextLabel);
468 if (!WApplication::instance()->environment().ajax()) {
469 chart->resize(500, 200);
470 chart->setMargin(WLength::Auto, Side::Left | Side::Right);
472 auto w = std::make_unique<WContainerWidget>();
473 w->addWidget(std::move(chart));
474 w->setStyleClass(
"about");
477 chart->setStyleClass(
"about");
478 return std::move(chart);
485 std::unique_ptr<WText> result
486 = std::make_unique<WText>(WString::tr(
"about-text"));
487 result->setStyleClass(
"about");
488 return std::move(result);
498 WModelIndex selected = *
folderView_->selectedIndexes().begin();
499 cpp17::any d = selected.data(ItemDataRole::User);
500 if (cpp17::any_has_value(d)) {
501 std::string folder = cpp17::any_cast<std::string>(d);
507 fileFilterModel_->setFilterRegExp(std::unique_ptr<std::regex>(
new std::regex(folder)));
513 void showPopup(
const WModelIndex& item,
const WMouseEvent& event) {
514 if (event.button() == MouseButton::Right) {
520 popup_ = std::make_unique<WPopupMenu>();
521 popup_->addItem(
"icons/folder_new.gif",
"Create a New Folder");
522 popup_->addItem(
"Rename this Folder")->setCheckable(
true);
523 popup_->addItem(
"Delete this Folder");
525 popup_->addItem(
"Folder Details");
527 popup_->addItem(
"Application Inventory");
528 popup_->addItem(
"Hardware Inventory");
531 std::unique_ptr<WPopupMenu> subMenu = std::make_unique<WPopupMenu>();
532 subMenu->addItem(
"Sub Item 1");
533 subMenu->addItem(
"Sub Item 2");
534 popup_->addMenu(
"File Deployments", std::move(subMenu));
561 WString text =
popup_->result()->text();
565 + text +
"' is not implemented.",
590 fileModel_->invisibleRootItem()->setRowCount(0);
592 std::ifstream f((appRoot() +
"data/files.csv").c_str());
595 throw std::runtime_error(
"Could not read: data/files.csv");
599 for (
int i = 0; i <
fileModel_->rowCount(); ++i) {
601 item->setFlags(item->flags() | ItemFlag::DragEnabled);
602 item->setIcon(
"icons/file.gif");
604 std::string folderId = item->text().toUTF8();
606 item->setData(cpp17::any(folderId), ItemDataRole::User);
619 item->setData(cpp17::any(d), ItemDataRole::Display);
625 int i = asNumber(item->text());
626 item->setData(cpp17::any(i), ItemDataRole::Edit);
632 std::unique_ptr<WStandardItem> level1;
652 level1 =
createFolderItem(WString(
reinterpret_cast<const char*
>(u8
"Frankf\u00DCrt")));
657 cpp17::any(std::string(
"SandBox")));
665 const std::string& folderId = std::string())
668 = std::make_unique<WStandardItem>(location);
670 if (!folderId.empty()) {
671 result->setData(cpp17::any(folderId));
672 result->setFlags(result->flags() | ItemFlag::DropEnabled);
675 result->setFlags(result->flags().clear(ItemFlag::Selectable));
677 result->setIcon(
"icons/folder.gif");
685 auto app = std::make_unique<TreeViewDragDrop>(env);
686 app->setTwoPhaseRenderingThreshold(0);
687 app->setTitle(
"WTreeView Drag & Drop");
688 app->useStyleSheet(
"styles.css");
689 app->messageResourceBundle().use(WApplication::appRoot() +
"about");
692 return std::move(app);
int main(int argc, char **argv)
std::unique_ptr< WApplication > createApplication(const WEnvironment &env)
A dialog for editing a 'file'.
void handleFinish(DialogCode result)
std::shared_ptr< WAbstractItemModel > model_
WDatePicker * createdPicker_
WDatePicker * modifiedPicker_
FileEditDialog(std::shared_ptr< WAbstractItemModel > model, const WModelIndex &item)
A specialized standard item model which report a specific drag and drop mime type.
static WString dateEditFormat
Date edit format.
virtual std::string mimeType() const
Return the mime type.
static WString dateDisplayFormat
Date display format.
static const char * FileSelectionMimeType
Constant that indicates the mime type for a selection of files.
void folderChanged()
Change the filter on the file view when the selected folder changes.
std::unique_ptr< WWidget > aboutDisplay()
Creates the hints text.
std::shared_ptr< WStandardItemModel > fileModel_
The file model (used by fileView_)
std::map< std::string, WString > folderNameMap_
Maps folder id's to folder descriptions.
void editFile(const WModelIndex &item)
Edit a particular row.
std::shared_ptr< WSortFilterProxyModel > fileFilterModel_
The sort filter proxy model that adapts fileModel_.
std::unique_ptr< WTreeView > folderView()
Creates the folder WTreeView.
std::unique_ptr< WText > createTitle(const WString &title)
Creates a title widget.
void createUI()
Setup the user interface.
virtual ~TreeViewDragDrop()
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< WTableView > fileView()
Creates the file table view (a WTableView)
std::unique_ptr< WPopupMenu > popup_
Popup menu on the folder view.
WTableView * fileView_
The file view.
void convertToDate(WStandardItem *item)
Convert a string to a date.
std::unique_ptr< WWidget > pieChart()
Creates the chart.
void showPopup(const WModelIndex &item, const WMouseEvent &event)
Show a popup for a folder item.
std::unique_ptr< WStandardItem > createFolderItem(const WString &location, const std::string &folderId=std::string())
Create a folder item.
TreeViewDragDrop(const WEnvironment &env)
Constructor.
void popupAction()
Process the result of the popup menu.
void populateFiles()
Populate the files model.
void convertToNumber(WStandardItem *item)
Convert a string to a number.
void dialogDone()
Process the result of the message box.
WTreeView * folderView_
The folder view.
std::unique_ptr< FileEditDialog > dialog_
void populateFolders()
Populate the folders model.
void readFromCsv(std::istream &f, std::shared_ptr< WAbstractItemModel > model, int numRows, bool firstLineIsHeaders)