Wt examples  3.3.0
Public Member Functions | Private Member Functions | Private Attributes | List of all members
FileEditDialog Class Reference

A dialog for editing a 'file'. More...

Inheritance diagram for FileEditDialog:
Inheritance graph
[legend]

Public Member Functions

 FileEditDialog (WAbstractItemModel *model, const WModelIndex &item)
 
- Public Member Functions inherited from Wt::WDialog
 WDialog (WObject *parent=0)
 
 WDialog (const WString &windowTitle, WObject *parent=0)
 
 ~WDialog ()
 
void setWindowTitle (const WString &title)
 
WString windowTitle () const
 
void setCaption (const WString &caption)
 
WString caption () const
 
void setTitleBarEnabled (bool enabled)
 
bool isTitleBarEnabled () const
 
WContainerWidgettitleBar () const
 
WContainerWidgetcontents () const
 
WContainerWidgetfooter () const
 
DialogCode exec (const WAnimation &animation=WAnimation())
 
virtual void done (DialogCode r)
 
virtual void accept ()
 
virtual void reject ()
 
void rejectWhenEscapePressed ()
 
Signal< DialogCode > & finished ()
 
DialogCode result () const
 
void setModal (bool modal)
 
bool isModal () const
 
void setResizable (bool resizable)
 
bool resizable () const
 
void setClosable (bool closable)
 
bool closable () const
 
virtual void setHidden (bool hidden, const WAnimation &animation=WAnimation())
 
virtual void positionAt (const WWidget *widget, Orientation orientation=Vertical)
 
virtual void setMinimumSize (const WLength &width, const WLength &height)
 
virtual void setMaximumSize (const WLength &width, const WLength &height)
 
 WPopupWidget (WWidget *impl, WObject *parent=0)
 
virtual ~WPopupWidget ()
 
void setAnchorWidget (WWidget *widget, Orientation orientation=Vertical)
 
Orientation orientation () const
 
void setTransient (bool transient, int autoHideDelay=0)
 
bool isTransient () const
 
int autoHideDelay () const
 
Signalhidden ()
 
Signalshown ()
 

Private Member Functions

void handleFinish (DialogCode result)
 

Private Attributes

WAbstractItemModelmodel_
 
WModelIndex item_
 
WLineEditnameEdit_
 
WLineEditsizeEdit_
 
WComboBoxtypeEdit_
 
WDatePickercreatedPicker_
 
WDatePickermodifiedPicker_
 

Additional Inherited Members

- Public Types inherited from Wt::WDialog
enum  DialogCode
 
- Public Attributes inherited from Wt::WDialog
 Rejected
 
 Accepted
 
- Protected Member Functions inherited from Wt::WDialog
void render (WFlags< RenderFlag > flags)
 

Detailed Description

A dialog for editing a 'file'.

Definition at line 78 of file TreeViewDragDrop.C.

Constructor & Destructor Documentation

FileEditDialog::FileEditDialog ( WAbstractItemModel model,
const WModelIndex item 
)
inline

Definition at line 81 of file TreeViewDragDrop.C.

82  : WDialog("Edit..."),
83  model_(model),
84  item_(item)
85  {
86  int modelRow = item_.row();
87 
88  resize(300, WLength::Auto);
89 
90  /*
91  * Create the form widgets, and load them with data from the model.
92  */
93 
94  // name
95  nameEdit_ = new WLineEdit(asString(model_->data(modelRow, 1)));
96 
97  // type
98  typeEdit_ = new WComboBox();
99  typeEdit_->addItem("Document");
100  typeEdit_->addItem("Spreadsheet");
101  typeEdit_->addItem("Presentation");
103  (typeEdit_->findText(asString(model_->data(modelRow, 2))));
104 
105  // size
106  sizeEdit_ = new WLineEdit(asString(model_->data(modelRow, 3)));
107  sizeEdit_->setValidator
108  (new WIntValidator(0, std::numeric_limits<int>::max(), this));
109 
110  // created
111  createdPicker_ = new WDatePicker();
112  createdPicker_->lineEdit()->validator()->setMandatory(true);
114  createdPicker_->setDate(boost::any_cast<WDate>(model_->data(modelRow, 4)));
115 
116  // modified
118  modifiedPicker_->lineEdit()->validator()->setMandatory(true);
120  modifiedPicker_->setDate(boost::any_cast<WDate>(model_->data(modelRow, 5)));
121 
122  /*
123  * Use a grid layout for the labels and fields
124  */
125  WGridLayout *layout = new WGridLayout();
126 
127  WLabel *l;
128  int row = 0;
129 
130  layout->addWidget(l = new WLabel("Name:"), row, 0);
131  layout->addWidget(nameEdit_, row, 1);
132  l->setBuddy(nameEdit_);
133  ++row;
134 
135  layout->addWidget(l = new WLabel("Type:"), row, 0);
136  layout->addWidget(typeEdit_, row, 1);
137  l->setBuddy(typeEdit_);
138  ++row;
139 
140  layout->addWidget(l = new WLabel("Size:"), row, 0);
141  layout->addWidget(sizeEdit_, row, 1);
142  l->setBuddy(sizeEdit_);
143  ++row;
144 
145  layout->addWidget(l = new WLabel("Created:"), row, 0);
146  layout->addWidget(createdPicker_->lineEdit(), row, 1);
147  layout->addWidget(createdPicker_, row, 2);
149  ++row;
150 
151  layout->addWidget(l = new WLabel("Modified:"), row, 0);
152  layout->addWidget(modifiedPicker_->lineEdit(), row, 1);
153  layout->addWidget(modifiedPicker_, row, 2);
155  ++row;
156 
157  WPushButton *b;
158  WContainerWidget *buttons = new WContainerWidget();
159  buttons->addWidget(b = new WPushButton("Save"));
160  b->clicked().connect(this, &WDialog::accept);
161  contents()->enterPressed().connect(this, &WDialog::accept);
162  buttons->addWidget(b = new WPushButton("Cancel"));
163  b->clicked().connect(this, &WDialog::reject);
164 
165  /*
166  * Focus the form widget that corresonds to the selected item.
167  */
168  switch (item.column()) {
169  case 2:
170  typeEdit_->setFocus(); break;
171  case 3:
172  sizeEdit_->setFocus(); break;
173  case 4:
174  createdPicker_->lineEdit()->setFocus(); break;
175  case 5:
176  modifiedPicker_->lineEdit()->setFocus(); break;
177  default:
178  nameEdit_->setFocus(); break;
179  }
180 
181  layout->addWidget(buttons, row, 0, 0, 3, AlignCenter);
182  layout->setColumnStretch(1, 1);
183 
184  contents()->setLayout(layout);
185 
186  finished().connect(this, &FileEditDialog::handleFinish);
187 
188  show();
189  }

Member Function Documentation

void FileEditDialog::handleFinish ( DialogCode  result)
inlineprivate

Definition at line 199 of file TreeViewDragDrop.C.

200  {
201  if (result == WDialog::Accepted) {
202  /*
203  * Update the model with data from the edit widgets.
204  *
205  * You will want to do some validation here...
206  *
207  * Note that we directly update the source model to avoid
208  * problems caused by the dynamic sorting of the proxy model,
209  * which reorders row numbers, and would cause us to switch to editing
210  * the wrong data.
211  */
213  int modelRow = item_.row();
214 
215  WAbstractProxyModel *proxyModel = dynamic_cast<WAbstractProxyModel *>(m);
216  if (proxyModel) {
217  m = proxyModel->sourceModel();
218  modelRow = proxyModel->mapToSource(item_).row();
219  }
220 
221  m->setData(modelRow, 1, boost::any(nameEdit_->text()));
222  m->setData(modelRow, 2, boost::any(typeEdit_->currentText()));
223  m->setData(modelRow, 3, boost::any(boost::lexical_cast<int>
224  (sizeEdit_->text().toUTF8())));
225  m->setData(modelRow, 4, boost::any(createdPicker_->date()));
226  m->setData(modelRow, 5, boost::any(modifiedPicker_->date()));
227  }
228 
229  delete this;
230  }

Member Data Documentation

WDatePicker* FileEditDialog::createdPicker_
private

Definition at line 197 of file TreeViewDragDrop.C.

WModelIndex FileEditDialog::item_
private

Definition at line 193 of file TreeViewDragDrop.C.

WAbstractItemModel* FileEditDialog::model_
private

Definition at line 192 of file TreeViewDragDrop.C.

WDatePicker * FileEditDialog::modifiedPicker_
private

Definition at line 197 of file TreeViewDragDrop.C.

WLineEdit* FileEditDialog::nameEdit_
private

Definition at line 195 of file TreeViewDragDrop.C.

WLineEdit * FileEditDialog::sizeEdit_
private

Definition at line 195 of file TreeViewDragDrop.C.

WComboBox* FileEditDialog::typeEdit_
private

Definition at line 196 of file TreeViewDragDrop.C.


The documentation for this class was generated from the following file:

Generated on Fri May 31 2013 for the C++ Web Toolkit (Wt) by doxygen 1.8.3.1