Public Member Functions | |
FileEditDialog (WAbstractItemModel *model, const WModelIndex &item) | |
Private Member Functions | |
void | handleFinish (DialogCode result) |
Private Attributes | |
WAbstractItemModel * | model_ |
WModelIndex | item_ |
WLineEdit * | nameEdit_ |
WLineEdit * | sizeEdit_ |
WComboBox * | typeEdit_ |
WDatePicker * | createdPicker_ |
WDatePicker * | modifiedPicker_ |
Definition at line 77 of file TreeViewDragDrop.C.
FileEditDialog::FileEditDialog | ( | WAbstractItemModel * | model, | |
const WModelIndex & | item | |||
) | [inline] |
Definition at line 80 of file TreeViewDragDrop.C.
00081 : WDialog("Edit..."), 00082 model_(model), 00083 item_(item) 00084 { 00085 int modelRow = item_.row(); 00086 00087 resize(300, WLength::Auto); 00088 00089 /* 00090 * Create the form widgets, and load them with data from the model. 00091 */ 00092 00093 // name 00094 nameEdit_ = new WLineEdit(asString(model_->data(modelRow, 1))); 00095 00096 // type 00097 typeEdit_ = new WComboBox(); 00098 typeEdit_->addItem("Document"); 00099 typeEdit_->addItem("Spreadsheet"); 00100 typeEdit_->addItem("Presentation"); 00101 typeEdit_->setCurrentIndex 00102 (typeEdit_->findText(asString(model_->data(modelRow, 2)))); 00103 00104 // size 00105 sizeEdit_ = new WLineEdit(asString(model_->data(modelRow, 3))); 00106 sizeEdit_->setValidator 00107 (new WIntValidator(0, std::numeric_limits<int>::max(), this)); 00108 00109 // created 00110 createdPicker_ = new WDatePicker(); 00111 createdPicker_->lineEdit()->validator()->setMandatory(true); 00112 createdPicker_->setFormat(FileModel::dateEditFormat); 00113 createdPicker_->setDate(boost::any_cast<WDate>(model_->data(modelRow, 4))); 00114 00115 // modified 00116 modifiedPicker_ = new WDatePicker(); 00117 modifiedPicker_->lineEdit()->validator()->setMandatory(true); 00118 modifiedPicker_->setFormat(FileModel::dateEditFormat); 00119 modifiedPicker_->setDate(boost::any_cast<WDate>(model_->data(modelRow, 5))); 00120 00121 /* 00122 * Use a grid layout for the labels and fields 00123 */ 00124 WGridLayout *layout = new WGridLayout(); 00125 00126 WLabel *l; 00127 int row = 0; 00128 00129 layout->addWidget(l = new WLabel("Name:"), row, 0); 00130 layout->addWidget(nameEdit_, row, 1); 00131 l->setBuddy(nameEdit_); 00132 ++row; 00133 00134 layout->addWidget(l = new WLabel("Type:"), row, 0); 00135 layout->addWidget(typeEdit_, row, 1, AlignTop); 00136 l->setBuddy(typeEdit_); 00137 ++row; 00138 00139 layout->addWidget(l = new WLabel("Size:"), row, 0); 00140 layout->addWidget(sizeEdit_, row, 1); 00141 l->setBuddy(sizeEdit_); 00142 ++row; 00143 00144 layout->addWidget(l = new WLabel("Created:"), row, 0); 00145 layout->addWidget(createdPicker_->lineEdit(), row, 1); 00146 layout->addWidget(createdPicker_, row, 2); 00147 l->setBuddy(createdPicker_->lineEdit()); 00148 ++row; 00149 00150 layout->addWidget(l = new WLabel("Modified:"), row, 0); 00151 layout->addWidget(modifiedPicker_->lineEdit(), row, 1); 00152 layout->addWidget(modifiedPicker_, row, 2); 00153 l->setBuddy(modifiedPicker_->lineEdit()); 00154 ++row; 00155 00156 WPushButton *b; 00157 WContainerWidget *buttons = new WContainerWidget(); 00158 buttons->addWidget(b = new WPushButton("Save")); 00159 b->clicked().connect(SLOT(this, WDialog::accept)); 00160 contents()->enterPressed().connect(SLOT(this, WDialog::accept)); 00161 buttons->addWidget(b = new WPushButton("Cancel")); 00162 b->clicked().connect(SLOT(this, WDialog::reject)); 00163 00164 /* 00165 * Focus the form widget that corresonds to the selected item. 00166 */ 00167 switch (item.column()) { 00168 case 2: 00169 typeEdit_->setFocus(); break; 00170 case 3: 00171 sizeEdit_->setFocus(); break; 00172 case 4: 00173 createdPicker_->lineEdit()->setFocus(); break; 00174 case 5: 00175 modifiedPicker_->lineEdit()->setFocus(); break; 00176 default: 00177 nameEdit_->setFocus(); break; 00178 } 00179 00180 layout->addWidget(buttons, row, 0, 0, 3, AlignCenter); 00181 layout->setColumnStretch(1, 1); 00182 00183 contents()->setLayout(layout, AlignTop | AlignJustify); 00184 00185 finished().connect(SLOT(this, FileEditDialog::handleFinish)); 00186 00187 show(); 00188 }
void FileEditDialog::handleFinish | ( | DialogCode | result | ) | [inline, private] |
Definition at line 198 of file TreeViewDragDrop.C.
00199 { 00200 if (result == WDialog::Accepted) { 00201 /* 00202 * Update the model with data from the edit widgets. 00203 * 00204 * You will want to do some validation here... 00205 * 00206 * Note that we directly update the source model to avoid 00207 * problems caused by the dynamic sorting of the proxy model, 00208 * which reorders row numbers, and would cause us to switch to editing 00209 * the wrong data. 00210 */ 00211 WAbstractItemModel *m = model_; 00212 int modelRow = item_.row(); 00213 00214 WAbstractProxyModel *proxyModel = dynamic_cast<WAbstractProxyModel *>(m); 00215 if (proxyModel) { 00216 m = proxyModel->sourceModel(); 00217 modelRow = proxyModel->mapToSource(item_).row(); 00218 } 00219 00220 m->setData(modelRow, 1, boost::any(nameEdit_->text())); 00221 m->setData(modelRow, 2, boost::any(typeEdit_->currentText())); 00222 m->setData(modelRow, 3, boost::any(boost::lexical_cast<int> 00223 (sizeEdit_->text().toUTF8()))); 00224 m->setData(modelRow, 4, boost::any(createdPicker_->date())); 00225 m->setData(modelRow, 5, boost::any(modifiedPicker_->date())); 00226 } 00227 00228 delete this; 00229 }
WAbstractItemModel* FileEditDialog::model_ [private] |
Definition at line 191 of file TreeViewDragDrop.C.
WModelIndex FileEditDialog::item_ [private] |
Definition at line 192 of file TreeViewDragDrop.C.
WLineEdit* FileEditDialog::nameEdit_ [private] |
Definition at line 194 of file TreeViewDragDrop.C.
WLineEdit * FileEditDialog::sizeEdit_ [private] |
Definition at line 194 of file TreeViewDragDrop.C.
WComboBox* FileEditDialog::typeEdit_ [private] |
Definition at line 195 of file TreeViewDragDrop.C.
WDatePicker* FileEditDialog::createdPicker_ [private] |
Definition at line 196 of file TreeViewDragDrop.C.
WDatePicker * FileEditDialog::modifiedPicker_ [private] |
Definition at line 196 of file TreeViewDragDrop.C.