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 78 of file TreeViewDragDrop.C.


Constructor & Destructor Documentation

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

Definition at line 81 of file TreeViewDragDrop.C.

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


Member Function Documentation

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

Definition at line 199 of file TreeViewDragDrop.C.

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


Member Data Documentation

Definition at line 192 of file TreeViewDragDrop.C.

Definition at line 193 of file TreeViewDragDrop.C.

Definition at line 195 of file TreeViewDragDrop.C.

Definition at line 195 of file TreeViewDragDrop.C.

Definition at line 196 of file TreeViewDragDrop.C.

Definition at line 197 of file TreeViewDragDrop.C.

Definition at line 197 of file TreeViewDragDrop.C.


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

Generated on Thu May 20 18:14:56 2010 for Wt by doxygen 1.5.6