43 #include <QDoubleSpinBox>
46 #include <QFileDialog>
56 if(index.column() != 1)
60 QString itemType = ((
TreeModel*)(index.model()))->itemType(index);
62 if(itemType ==
intId){
63 editor =
new QSpinBox(parent);
71 editor =
new QSpinBox(parent);
88 editor =
new QLineEdit(parent);
96 editor =
new QLineEdit(parent);
103 else if(itemType ==
boolId){
104 editor =
new QComboBox(parent);
110 editor =
new QLineEdit(parent);
112 else if(!
is_null(rcp_dynamic_cast<const FileNameValidator>(paramValidator))){
114 ((
TreeModel*)(index.model()))->data(index.sibling(index.row(), 0),Qt::DisplayRole).toString();
115 QString currentPath = ((
TreeModel*)(index.model()))->data(index,Qt::DisplayRole).toString();
116 if(currentPath.size() == 0){
117 currentPath = QDir::homePath();
120 if(paramName.indexOf(
"Input Directory", 0, Qt::CaseInsensitive) > -1 ||
121 paramName.indexOf(
"Output Directory", 0, Qt::CaseInsensitive) > -1){
122 QString dirname = QFileDialog::getExistingDirectory(parent, paramName,
123 currentPath, QFileDialog::ShowDirsOnly);
125 ((
TreeModel*)(index.model()))->setData(index, dirname);
130 if(rcp_dynamic_cast<const FileNameValidator>(paramValidator)->fileMustExist()){
131 filename = QFileDialog::getOpenFileName(parent, paramName, currentPath);
134 filename = QFileDialog::getSaveFileName(parent, paramName, currentPath);
137 ((
TreeModel*)(index.model()))->setData(index, filename);
141 else if(paramValidator->validStringValues()->size() != 0){
143 editor =
new QComboBox(parent);
145 static_cast<QComboBox*
>(editor)->addItem(QString::fromStdString(*itr));
149 editor =
new QLineEdit(parent);
152 else if(itemType.contains(
arrayId)){
163 QString itemType = ((
TreeModel*)(index.model()))->itemType(index);
164 QVariant value = index.model()->data(index);
165 if(itemType ==
intId){
166 static_cast<QSpinBox*
>(editor)->setValue(value.toInt());
169 static_cast<QSpinBox*
>(editor)->setValue(value.toInt());
172 static_cast<QLineEdit*
>(editor)->setText(value.toString());
175 static_cast<QLineEdit*
>(editor)->setText(value.toString());
177 else if(itemType ==
boolId){
178 static_cast<QComboBox*
>(editor)->setEditText(value.toString());
182 if(
is_null(validator) || validator->validStringValues()->size()==0)
183 static_cast<QLineEdit*>(editor)->setText(value.toString());
185 static_cast<QComboBox*
>(editor)->setEditText(value.toString());
187 else if(itemType.contains(
arrayId)){
196 QString itemType = ((
TreeModel*)(index.model()))->itemType(index);
197 if(itemType ==
intId){
198 QSpinBox *spinBox =
static_cast<QSpinBox*
>(editor);
199 spinBox->interpretText();
200 model->setData(index, spinBox->value(), Qt::EditRole);
203 QSpinBox *spinBox =
static_cast<QSpinBox*
>(editor);
204 spinBox->interpretText();
205 model->setData(index, (
short)spinBox->value(), Qt::EditRole);
208 QLineEdit *lineEdit =
static_cast<QLineEdit*
>(editor);
209 model->setData(index, lineEdit->text(), Qt::EditRole);
212 QLineEdit *lineEdit =
static_cast<QLineEdit*
>(editor);
213 model->setData(index, lineEdit->text(), Qt::EditRole);
215 else if(itemType ==
boolId){
216 bool value =
static_cast<QComboBox*
>(editor)->currentText()
218 model->setData(index, value, Qt::EditRole);
222 static_cast<const TreeModel*
>(index.model())->getValidator(index);
225 value =
static_cast<QLineEdit*
>(editor)->text();
228 value =
static_cast<QComboBox*
>(editor)->currentText();
230 model->
setData(index, value, Qt::EditRole);
232 else if(itemType.contains(
arrayId)){
234 model->setData(index, value, Qt::EditRole);
238 model->setData(index, value, Qt::EditRole);
245 editor->setGeometry(option.rect);
250 QString name = model->
data(
251 index.sibling(index.row(),0),Qt::DisplayRole).toString();
The delegate used in the MVC framework for Optika.
bool is_null(const boost::shared_ptr< T > &p)
static const QString & getBoolEditorTrue()
Gets the value the delegate uses to represent "true" when constructing comboboxes for boolean paramet...
QVariant data(const QModelIndex &index, int role=Qt::DisplayRole) const
void setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const
bool setData(const QModelIndex &index, const QVariant &value, int role=Qt::EditRole)
QWidget * createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const
void setArrayWidgetData(QWidget *editor, QString type, const QModelIndex &index, bool isTwoD=false) const
Sets the data in an array widget to the current values found at index.
static const QString & getBoolEditorFalse()
Gets the value the delegate uses to represent "false" when constructing comboboxes for boolean parame...
QVariant extractValueFromArray(QWidget *editor, QString type, bool isTwoD=false) const
Gets an array from an ArrayWidget and puts it into a QVariant.
virtual void updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option, const QModelIndex &index) const
Delegate(QObject *parent=0)
Constructs a Delegate.
RCP< const ParameterEntryValidator > getValidator(const QModelIndex &index) const
Gets the validator for a particular TreeItem.
static void applyToSpinBox(RCP< const EnhancedNumberValidator< S > > validator, QSpinBox *spinBox)
Applied attributes of the validator to the spin box.
virtual void setEditorData(QWidget *editor, const QModelIndex &index) const
static void applyToLineEdit(RCP< const EnhancedNumberValidator< S > > validator, QLineEdit *lineEdit)
TreeModel is a type of QAbstractItemModel that has a Tree like structure.
QWidget * getArrayEditor(const QModelIndex &index, QString type, QWidget *parent, bool isTwoD=false) const
Creates an ArrayWidget to edit the parameter at the given QModelIndex.
QString getArrayType(QString itemType)
Given a type string, determines the template type of the Array.
static const int getRawDataRole()
Returns constant representing the RawDataRole.