diff options
Diffstat (limited to 'Swift/QtUI/QtFormWidget.cpp')
-rw-r--r-- | Swift/QtUI/QtFormWidget.cpp | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/Swift/QtUI/QtFormWidget.cpp b/Swift/QtUI/QtFormWidget.cpp index 2df8d7f..158bc9d 100644 --- a/Swift/QtUI/QtFormWidget.cpp +++ b/Swift/QtUI/QtFormWidget.cpp @@ -241,4 +241,34 @@ Form::ref QtFormWidget::getCompletedForm() { return result; } +template<class T> void QtFormWidget::setEnabled(QWidget* rawWidget, bool editable) { + T* widget = qobject_cast<T*>(rawWidget); + if (widget) { + widget->setEnabled(editable); + } +} + +template<class T> void QtFormWidget::setEditable(QWidget* rawWidget, bool editable) { + T* widget = qobject_cast<T*>(rawWidget); + if (widget) { + widget->setReadOnly(!editable); + } +} + +void QtFormWidget::setEditable(bool editable) { + if (!form_) { + return; + } + foreach (boost::shared_ptr<FormField> field, form_->getFields()) { + QWidget* widget = NULL; + if (field) { + widget = fields_[field->getName()]; + } + setEnabled<QCheckBox>(widget, editable); + setEnabled<QListWidget>(widget, editable); + setEditable<QTextEdit>(widget, editable); + setEditable<QLineEdit>(widget, editable); + } +} + } |