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() { }
88 resize(300, WLength::Auto);
99 auto typeEdit = std::make_unique<WComboBox>();
111 (std::make_shared<WIntValidator>(0, std::numeric_limits<int>::max()));
131 auto layout = std::make_unique<WGridLayout>();
133 std::unique_ptr<WLabel>
label;
136 label = std::make_unique<WLabel>(
"Name:");
142 label = std::make_unique<WLabel>(
"Type:");
145 layout->addWidget(std::move(typeEdit),
row, 1);
148 label = std::make_unique<WLabel>(
"Size");
154 label = std::make_unique<WLabel>(
"Created:");
160 label = std::make_unique<WLabel>(
"Modified:");
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);
173 button = std::make_unique<WPushButton>(
"Cancel");
174 contents()->enterPressed().connect(
this, &WDialog::accept);
175 button->clicked().connect(
this, &WDialog::reject);
181 switch (item.column()) {
197 layout->setColumnStretch(1, 1);
207 std::shared_ptr<WAbstractItemModel>
model_;
216 if (
result == DialogCode::Accepted) {
227 std::shared_ptr<WAbstractItemModel>
m =
model_;
230 std::shared_ptr<WAbstractProxyModel>
proxyModel =
231 std::dynamic_pointer_cast<WAbstractProxyModel>(
m);
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);
363 layout->setRowStretch(1, 1);
364 layout->setColumnStretch(1, 1);
366 w->setLayout(std::move(
layout));
374 result->setStyleClass(
"title");
382 auto treeView = std::make_unique<FolderView>();
393 "event.cancelBubble = true; event.returnValue = false; return false;");
395 treeView->resize(200, WLength::Auto);
396 treeView->setSelectionMode(SelectionMode::Single);
397 treeView->setEnabledDropLocations(DropLocation::OnItem);
413 = std::make_unique<WTableView>();
415 tableView->setAlternatingRowColors(
true);
418 tableView->setSelectionMode(SelectionMode::Extended);
428 auto delegate = std::make_shared<WItemDelegate>();
433 tableView->setColumnAlignment(3, AlignmentFlag::Right);
434 tableView->setColumnAlignment(4, AlignmentFlag::Right);
435 tableView->setColumnAlignment(5, AlignmentFlag::Right);
437 tableView->sortByColumn(1, SortOrder::Ascending);
440 this, std::placeholders::_1));
456 using namespace Chart;
458 auto chart = std::make_unique<WPieChart>();
461 chart->setTitle(
"File sizes");
463 chart->setLabelsColumn(1);
464 chart->setDataColumn(3);
466 chart->setPerspectiveEnabled(
true, 0.2);
467 chart->setDisplayLabels(LabelOption::Outside | LabelOption::TextLabel);
470 chart->resize(500, 200);
471 chart->setMargin(WLength::Auto, Side::Left | Side::Right);
473 auto w = std::make_unique<WContainerWidget>();
474 w->addWidget(std::move(
chart));
475 w->setStyleClass(
"about");
478 chart->setStyleClass(
"about");
479 return std::move(
chart);
486 std::unique_ptr<WText>
result
487 = std::make_unique<WText>(WString::tr(
"about-text"));
488 result->setStyleClass(
"about");
500 cpp17::any
d =
selected.data(ItemDataRole::User);
501 if (cpp17::any_has_value(
d)) {
502 std::string
folder = cpp17::any_cast<std::string>(
d);
515 if (
event.button() == MouseButton::Right) {
521 popup_ = std::make_unique<WPopupMenu>();
522 popup_->addItem(
"icons/folder_new.gif",
"Create a New Folder");
523 popup_->addItem(
"Rename this Folder")->setCheckable(
true);
524 popup_->addItem(
"Delete this Folder");
526 popup_->addItem(
"Folder Details");
528 popup_->addItem(
"Application Inventory");
529 popup_->addItem(
"Hardware Inventory");
532 std::unique_ptr<WPopupMenu>
subMenu = std::make_unique<WPopupMenu>();
533 subMenu->addItem(
"Sub Item 1");
534 subMenu->addItem(
"Sub Item 2");
566 +
text +
"' is not implemented.",
591 fileModel_->invisibleRootItem()->setRowCount(0);
596 throw std::runtime_error(
"Could not read: data/files.csv");
602 item->setFlags(item->flags() | ItemFlag::DragEnabled);
603 item->setIcon(
"icons/file.gif");
605 std::string
folderId = item->text().toUTF8();
607 item->setData(cpp17::any(
folderId), ItemDataRole::User);
620 item->setData(cpp17::any(
d), ItemDataRole::Display);
627 item->setData(cpp17::any(
i), ItemDataRole::Edit);
633 std::unique_ptr<WStandardItem>
level1;
658 cpp17::any(std::string(
"SandBox")));
666 const std::string&
folderId = std::string())
669 = std::make_unique<WStandardItem>(
location);
673 result->setFlags(
result->flags() | ItemFlag::DropEnabled);
676 result->setFlags(
result->flags().clear(ItemFlag::Selectable));
678 result->setIcon(
"icons/folder.gif");
686 auto app = std::make_unique<TreeViewDragDrop>(
env);
687 app->setTwoPhaseRenderingThreshold(0);
688 app->setTitle(
"WTreeView Drag & Drop");
689 app->useStyleSheet(
"styles.css");
690 app->messageResourceBundle().use(WApplication::appRoot() +
"about");
693 return std::move(
app);
Wt::Auth::Dbo::UserDatabase< AuthInfo > UserDatabase
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)