8#include <Wt/WApplication>
10#include <Wt/WContainerWidget>
11#include <Wt/WDatePicker>
12#include <Wt/WDateValidator>
14#include <Wt/WEnvironment>
15#include <Wt/WIntValidator>
16#include <Wt/WItemDelegate>
18#include <Wt/WLineEdit>
19#include <Wt/WMessageBox>
20#include <Wt/WPushButton>
21#include <Wt/WRegExpValidator>
22#include <Wt/WGridLayout>
23#include <Wt/WPopupMenu>
24#include <Wt/WSortFilterProxyModel>
25#include <Wt/WStandardItem>
26#include <Wt/WStandardItemModel>
27#include <Wt/WTableView>
28#include <Wt/WTreeView>
30#include <Wt/WVBoxLayout>
32#include <Wt/Chart/WPieChart>
108 (
new WIntValidator(0, std::numeric_limits<int>::max(),
this));
223 m->
setData(modelRow, 3, boost::any(boost::lexical_cast<int>
369 "event.cancelBubble = true; event.returnValue = false; return false;");
429 using namespace Chart;
431 WPieChart *chart =
new WPieChart();
434 chart->setTitle(
"File sizes");
436 chart->setLabelsColumn(1);
437 chart->setDataColumn(3);
439 chart->setPerspectiveEnabled(
true, 0.2);
440 chart->setDisplayLabels(Outside | TextLabel);
442 if (!WApplication::instance()->
environment().ajax()) {
443 chart->resize(500, 200);
473 std::string folder = boost::any_cast<std::string>(d);
493 popup_->
addItem(
"icons/folder_new.gif",
"Create a New Folder");
504 subMenu->
addItem(
"Sub Item 1");
505 subMenu->
addItem(
"Sub Item 2");
537 +
"' is not implemented.",
NoIcon,
Ok);
563 std::ifstream f((
appRoot() +
"data/files.csv").c_str());
566 throw std::runtime_error(
"Could not read: data/files.csv");
573 item->
setIcon(
"icons/file.gif");
596 int i = boost::lexical_cast<int>(item->
text());
625 boost::any(std::string(
"SandBox")));
633 const std::string& folderId = std::string())
637 if (!folderId.empty()) {
638 result->
setData(boost::any(folderId));
644 result->
setIcon(
"icons/folder.gif");
655 app->
setTitle(
"WTreeView Drag & Drop");
WApplication * createApplication(const WEnvironment &env)
int main(int argc, char **argv)
A dialog for editing a 'file'.
void handleFinish(DialogCode result)
WAbstractItemModel * model_
WDatePicker * createdPicker_
WDatePicker * modifiedPicker_
FileEditDialog(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.
FileModel(WObject *parent)
Constructor.
static WString dateDisplayFormat
Date display format.
A specialized treeview that supports a custom drop event.
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.
WText * createTitle(const WString &title)
Creates a title widget.
WWidget * pieChart()
Creates the chart.
WMessageBox * popupActionBox_
Message box to confirm the poup menu action.
WSortFilterProxyModel * fileFilterModel_
The sort filter proxy model that adapts fileModel_.
std::map< std::string, WString > folderNameMap_
Maps folder id's to folder descriptions.
void editFile(const WModelIndex &item)
Edit a particular row.
WStandardItem * createFolderItem(const WString &location, const std::string &folderId=std::string())
Create a folder item.
WTreeView * folderView()
Creates the folder WTreeView.
WPopupMenu * popup_
Popup menu on the folder view.
void createUI()
Setup the user interface.
virtual ~TreeViewDragDrop()
WWidget * aboutDisplay()
Creates the hints text.
WTableView * fileView()
Creates the file table view (a WTableView)
WStandardItemModel * folderModel_
The folder model (used by folderView_)
WTableView * fileView_
The file view.
WStandardItemModel * fileModel_
The file model (used by fileView_)
void convertToDate(WStandardItem *item)
Convert a string to a date.
void showPopup(const WModelIndex &item, const WMouseEvent &event)
Show a popup for 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.
void populateFolders()
Populate the folders model.
Wt::Signals::connection connect(const F &function)
virtual Wt::Signals::connection connect(WObject *target, WObject::Method method)
virtual bool setHeaderData(int section, Orientation orientation, const boost::any &value, int role=EditRole)
virtual bool setData(const WModelIndex &index, const boost::any &value, int role=EditRole)
virtual WModelIndex index(int row, int column, const WModelIndex &parent=WModelIndex()) const=0
virtual boost::any data(const WModelIndex &index, int role=DisplayRole) const=0
virtual int rowCount(const WModelIndex &parent=WModelIndex()) const=0
WModelIndexSet selectedIndexes() const
void setDragEnabled(bool enable)
Signal< WModelIndex, WMouseEvent > & mouseWentUp()
Signal & selectionChanged()
WAbstractItemModel * model() const
void select(const WModelIndex &index, SelectionFlag option=Select)
void setItemDelegateForColumn(int column, WAbstractItemDelegate *delegate)
bool isSelected(const WModelIndex &index) const
virtual void setColumnAlignment(int column, AlignmentFlag alignment)
Signal< WModelIndex, WMouseEvent > & doubleClicked()
void setSelectionMode(SelectionMode mode)
void sortByColumn(int column, SortOrder order)
virtual WModelIndex mapToSource(const WModelIndex &proxyIndex) const=0
WAbstractItemModel * sourceModel() const
void setCssTheme(const std::string &name)
WMessageResourceBundle & messageResourceBundle()
friend friend class WContainerWidget
WContainerWidget * root() const
void setTwoPhaseRenderingThreshold(int size)
void setTitle(const WString &title)
static std::string appRoot()
void useStyleSheet(const WLink &link, const std::string &media="all")
const WEnvironment & environment() const
const WString & title() const
void addWidget(WWidget *widget, int stretch=0, WFlags< AlignmentFlag > alignment=0)
void setResizable(int index, bool enabled=true, const WLength &initialSize=WLength::Auto)
const WString currentText() const
void setCurrentIndex(int index)
int findText(const WString &text, WFlags< MatchFlag > flags=MatchExactly|MatchCaseSensitive)
void addItem(const WString &text)
void setFormat(const WString &format)
void setDate(const WDate &date)
WLineEdit * lineEdit() const
static WDate fromString(const WString &s)
Signal< DialogCode > & finished()
WContainerWidget * contents() const
DialogCode result() const
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)
void setTextFormat(const WString &format)
void setBuddy(WFormWidget *buddy)
const WString & text() const
Signal< StandardButton > & buttonClicked()
static StandardButton show(const WString &caption, const WString &text, WFlags< StandardButton > buttons, const WAnimation &animation=WAnimation())
void use(const std::string &path, bool loadInMemory=true)
boost::any data(int role=DisplayRole) const
void setFilterRole(int role)
void setFilterRegExp(const WString &pattern)
void setDynamicSortFilter(bool enable)
virtual void setSourceModel(WAbstractItemModel *sourceModel)
void setFilterKeyColumn(int column)
WStandardItem * invisibleRootItem() const
WStandardItem * item(int row, int column=0) const
void appendRow(const std::vector< WStandardItem * > &items)
void setIcon(const std::string &uri)
void setText(const WString &text)
WFlags< ItemFlag > flags() const
void appendRow(const std::vector< WStandardItem * > &items)
void setFlags(WFlags< ItemFlag > flags)
void setRowCount(int rows)
virtual void setData(const boost::any &data, int role=UserRole)
static WString tr(const char *key)
static WString fromUTF8(const std::string &value, bool checkValid=false)
std::string toUTF8() const
virtual void setModel(WAbstractItemModel *model)
virtual void setColumnWidth(int column, const WLength &width)
virtual void setAlternatingRowColors(bool enable)
virtual void setModel(WAbstractItemModel *model)
virtual void resize(const WLength &width, const WLength &height)
void expandToDepth(int depth)
void setMandatory(bool how)
WString asString(const boost::any &v, const WString &formatString=WString())
void readFromCsv(std::istream &f, Wt::WAbstractItemModel *model, int numRows, bool firstLineIsHeaders)
Utility function that reads a model from a CSV file.