FileEditDialog Class Reference
[Drag and drop in WTreeView example]

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

Inheritance diagram for FileEditDialog:

Inheritance graph
[legend]

List of all members.

Public Member Functions

 FileEditDialog (WAbstractItemModel *model, const WModelIndex &item)

Private Member Functions

void handleFinish (DialogCode result)

Private Attributes

WAbstractItemModelmodel_
WModelIndex item_
WLineEditnameEdit_
WLineEditsizeEdit_
WComboBoxtypeEdit_
WDatePickercreatedPicker_
WDatePickermodifiedPicker_


Detailed Description

A dialog for editing a 'file'.

Definition at line 76 of file TreeViewDragDrop.C.


Constructor & Destructor Documentation

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

Definition at line 79 of file TreeViewDragDrop.C.

00080     : WDialog("Edit..."),
00081       model_(model),
00082       item_(item)
00083   {
00084     int modelRow = item_.row();
00085 
00086     resize(300, WLength::Auto);
00087 
00088     /*
00089      * Create the form widgets, and load them with data from the model.
00090      */
00091 
00092     // name
00093     nameEdit_ = new WLineEdit(asString(model_->data(modelRow, 1)));
00094 
00095     // type
00096     typeEdit_ = new WComboBox();
00097     typeEdit_->addItem("Document");
00098     typeEdit_->addItem("Spreadsheet");
00099     typeEdit_->addItem("Presentation");
00100     typeEdit_->setCurrentIndex
00101       (typeEdit_->findText(asString(model_->data(modelRow, 2))));
00102 
00103     // size
00104     sizeEdit_ = new WLineEdit(asString(model_->data(modelRow, 3)));
00105     sizeEdit_->setValidator
00106       (new WIntValidator(0, std::numeric_limits<int>::max(), this));
00107 
00108     // created
00109     createdPicker_ = new WDatePicker();
00110     createdPicker_->lineEdit()->validator()->setMandatory(true);
00111     createdPicker_->setFormat(FileModel::dateEditFormat);
00112     createdPicker_->setDate(boost::any_cast<WDate>(model_->data(modelRow, 4)));
00113 
00114     // modified
00115     modifiedPicker_ = new WDatePicker();
00116     modifiedPicker_->lineEdit()->validator()->setMandatory(true);
00117     modifiedPicker_->setFormat(FileModel::dateEditFormat);
00118     modifiedPicker_->setDate(boost::any_cast<WDate>(model_->data(modelRow, 5)));
00119 
00120     /*
00121      * Use a grid layout for the labels and fields
00122      */
00123     WGridLayout *layout = new WGridLayout();
00124 
00125     WLabel *l;
00126     int row = 0;
00127 
00128     layout->addWidget(l = new WLabel("Name:"), row, 0);
00129     layout->addWidget(nameEdit_, row, 1);
00130     l->setBuddy(nameEdit_);
00131     ++row;
00132 
00133     layout->addWidget(l = new WLabel("Type:"), row, 0);
00134     layout->addWidget(typeEdit_, row, 1, AlignTop);
00135     l->setBuddy(typeEdit_);
00136     ++row;
00137 
00138     layout->addWidget(l = new WLabel("Size:"), row, 0);
00139     layout->addWidget(sizeEdit_, row, 1);
00140     l->setBuddy(sizeEdit_);
00141     ++row;
00142 
00143     layout->addWidget(l = new WLabel("Created:"), row, 0);
00144     layout->addWidget(createdPicker_->lineEdit(), row, 1);
00145     layout->addWidget(createdPicker_, row, 2);
00146     l->setBuddy(createdPicker_->lineEdit());
00147     ++row;
00148 
00149     layout->addWidget(l = new WLabel("Modified:"), row, 0);
00150     layout->addWidget(modifiedPicker_->lineEdit(), row, 1);
00151     layout->addWidget(modifiedPicker_, row, 2);
00152     l->setBuddy(modifiedPicker_->lineEdit());
00153     ++row;
00154 
00155     WPushButton *b;
00156     WContainerWidget *buttons = new WContainerWidget();
00157     buttons->addWidget(b = new WPushButton("Save"));
00158     b->clicked().connect(SLOT(this, WDialog::accept));
00159     contents()->enterPressed().connect(SLOT(this, WDialog::accept));
00160     buttons->addWidget(b = new WPushButton("Cancel"));
00161     b->clicked().connect(SLOT(this, WDialog::reject));
00162 
00163     /*
00164      * Focus the form widget that corresonds to the selected item.
00165      */
00166     switch (item.column()) {
00167     case 2:
00168       typeEdit_->setFocus(); break;
00169     case 3:
00170       sizeEdit_->setFocus(); break;
00171     case 4:
00172       createdPicker_->lineEdit()->setFocus(); break;
00173     case 5:
00174       modifiedPicker_->lineEdit()->setFocus(); break;
00175     default:
00176       nameEdit_->setFocus(); break;
00177     }
00178 
00179     layout->addWidget(buttons, row, 0, 0, 3, AlignCenter);
00180     layout->setColumnStretch(1, 1);
00181 
00182     contents()->setLayout(layout, AlignTop | AlignJustify);
00183 
00184     finished().connect(SLOT(this, FileEditDialog::handleFinish));
00185 
00186     show();
00187   }


Member Function Documentation

void FileEditDialog::handleFinish ( DialogCode  result  )  [inline, private]

Definition at line 197 of file TreeViewDragDrop.C.

00198   {
00199     if (result == WDialog::Accepted) {
00200       /*
00201        * Update the model with data from the edit widgets.
00202        *
00203        * You will want to do some validation here...
00204        *
00205        * Note that we directly update the source model to avoid
00206        * problems caused by the dynamic sorting of the proxy model,
00207        * which reorders row numbers, and would cause us to switch to editing
00208        * the wrong data.
00209        */
00210       WAbstractItemModel *m = model_;
00211       int modelRow = item_.row();
00212 
00213       WAbstractProxyModel *proxyModel = dynamic_cast<WAbstractProxyModel *>(m);
00214       if (proxyModel) {
00215         m = proxyModel->sourceModel();
00216         modelRow = proxyModel->mapToSource(item_).row();
00217       }
00218 
00219       m->setData(modelRow, 1, boost::any(nameEdit_->text()));
00220       m->setData(modelRow, 2, boost::any(typeEdit_->currentText()));
00221       m->setData(modelRow, 3, boost::any(boost::lexical_cast<int>
00222                                          (sizeEdit_->text().toUTF8())));
00223       m->setData(modelRow, 4, boost::any(createdPicker_->date()));
00224       m->setData(modelRow, 5, boost::any(modifiedPicker_->date()));
00225     }
00226 
00227     delete this;
00228   }


Member Data Documentation

Definition at line 190 of file TreeViewDragDrop.C.

Definition at line 191 of file TreeViewDragDrop.C.

Definition at line 193 of file TreeViewDragDrop.C.

Definition at line 193 of file TreeViewDragDrop.C.

Definition at line 194 of file TreeViewDragDrop.C.

Definition at line 195 of file TreeViewDragDrop.C.

Definition at line 195 of file TreeViewDragDrop.C.


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

Generated on Mon Mar 9 08:28:56 2009 for Wt by doxygen 1.5.6