FileView Class Reference
[Drag and drop in WTreeView example]

A specialized WTreeView that support editing using a WDialog box. More...

Inheritance diagram for FileView:

Inheritance graph
[legend]

List of all members.

Public Member Functions

 FileView (WContainerWidget *parent=0)
 Create a new file view.

Private Member Functions

void edit (const WModelIndex &item)
 Edit a particular row.


Detailed Description

A specialized WTreeView that support editing using a WDialog box.

Note:
Native inline editing support for WTreeView is planned early 2009.

Definition at line 75 of file TreeViewDragDrop.C.


Constructor & Destructor Documentation

FileView::FileView ( WContainerWidget parent = 0  )  [inline]

Create a new file view.

Definition at line 80 of file TreeViewDragDrop.C.

00081     : WTreeView(parent)
00082   {
00083     doubleClicked.connect(SLOT(this, FileView::edit));
00084   }


Member Function Documentation

void FileView::edit ( const WModelIndex item  )  [inline, private]

Edit a particular row.

Definition at line 89 of file TreeViewDragDrop.C.

00089                                      {
00090     int modelRow = item.row();
00091 
00092     WDialog d("Edit...");
00093     d.resize(300, WLength());
00094 
00095     /*
00096      * Create the form widgets, and load them with data from the model.
00097      */
00098 
00099     // name
00100     WLineEdit *nameEdit = new WLineEdit(asString(model()->data(modelRow, 1)));
00101 
00102     // type
00103     WComboBox *typeEdit = new WComboBox();
00104     typeEdit->addItem("Document");
00105     typeEdit->addItem("Spreadsheet");
00106     typeEdit->addItem("Presentation");
00107     typeEdit->setCurrentIndex
00108       (typeEdit->findText(asString(model()->data(modelRow, 2))));
00109 
00110     // size
00111     WLineEdit *sizeEdit
00112       = new WLineEdit(asString(model()->data(modelRow, 3)));
00113     sizeEdit->setValidator
00114       (new WIntValidator(0, std::numeric_limits<int>::max(), this));
00115 
00116     // created
00117     WLineEdit *createdEdit = new WLineEdit();
00118     createdEdit->setValidator
00119       (new WDateValidator(FileModel::dateEditFormat, this));
00120     createdEdit->validator()->setMandatory(true);
00121 
00122     WDatePicker *createdPicker
00123       = new WDatePicker(new WImage("icons/calendar_edit.png"), createdEdit);
00124     createdPicker->setFormat(FileModel::dateEditFormat);
00125     createdPicker->setDate(boost::any_cast<WDate>(model()->data(modelRow, 4)));
00126 
00127     // modified
00128     WLineEdit *modifiedEdit = new WLineEdit();
00129     modifiedEdit->setValidator
00130       (new WDateValidator(FileModel::dateEditFormat, this));
00131     modifiedEdit->validator()->setMandatory(true);
00132 
00133     WDatePicker *modifiedPicker
00134       = new WDatePicker(new WImage("icons/calendar_edit.png"), modifiedEdit);
00135     modifiedPicker->setFormat(FileModel::dateEditFormat);
00136     modifiedPicker->setDate(boost::any_cast<WDate>(model()->data(modelRow, 5)));
00137 
00138     /*
00139      * Use a grid layout for the labels and fields
00140      */
00141     WGridLayout *layout = new WGridLayout();
00142 
00143     WLabel *l;
00144     int row = 0;
00145 
00146     layout->addWidget(l = new WLabel("Name:"), row, 0);
00147     layout->addWidget(nameEdit, row, 1);
00148     l->setBuddy(nameEdit);
00149     ++row;
00150 
00151     layout->addWidget(l = new WLabel("Type:"), row, 0);
00152     layout->addWidget(typeEdit, row, 1, AlignTop);
00153     l->setBuddy(typeEdit);
00154     ++row;
00155 
00156     layout->addWidget(l = new WLabel("Size:"), row, 0);
00157     layout->addWidget(sizeEdit, row, 1);
00158     l->setBuddy(sizeEdit);
00159     ++row;
00160 
00161     layout->addWidget(l = new WLabel("Created:"), row, 0);
00162     layout->addWidget(createdEdit, row, 1);
00163     layout->addWidget(createdPicker, row, 2);
00164     l->setBuddy(createdEdit);
00165     ++row;
00166 
00167     layout->addWidget(l = new WLabel("Modified:"), row, 0);
00168     layout->addWidget(modifiedEdit, row, 1);
00169     layout->addWidget(modifiedPicker, row, 2);
00170     l->setBuddy(modifiedEdit);
00171     ++row;
00172 
00173     WPushButton *b;
00174     WContainerWidget *buttons = new WContainerWidget();
00175     buttons->addWidget(b = new WPushButton("Save"));
00176     b->clicked.connect(SLOT(&d, WDialog::accept));
00177     d.contents()->enterPressed.connect(SLOT(&d, WDialog::accept));
00178     buttons->addWidget(b = new WPushButton("Cancel"));
00179     b->clicked.connect(SLOT(&d, WDialog::reject));
00180 
00181     /*
00182      * Focus the form widget that corresonds to the selected item.
00183      */
00184     switch (item.column()) {
00185     case 2:
00186       typeEdit->setFocus(); break;
00187     case 3:
00188       sizeEdit->setFocus(); break;
00189     case 4:
00190       createdEdit->setFocus(); break;
00191     case 5:
00192       modifiedEdit->setFocus(); break;
00193     default:
00194       nameEdit->setFocus(); break;
00195     }
00196 
00197     layout->addWidget(buttons, row, 0, 0, 2, AlignCenter);
00198     layout->setColumnStretch(1, 1);
00199 
00200     d.contents()->setLayout(layout, AlignTop | AlignJustify);
00201 
00202     if (d.exec() == WDialog::Accepted) {
00203       /*
00204        * Update the model with data from the edit widgets.
00205        *
00206        * You will want to do some validation here...
00207        *
00208        * Note that we directly update the source model to avoid
00209        * problems caused by the dynamic sorting of the proxy model,
00210        * which reorders row numbers, and would cause us to switch to editing
00211        * the wrong data.
00212        */
00213       WAbstractItemModel *m = model();
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   }


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

Generated on Mon Jan 26 14:14:21 2009 for Wt by doxygen 1.5.6