18 const QStyleOptionViewItem &option,
const QModelIndex &index)
23 if (index.column() == 4 && event->type() == QEvent::MouseButtonRelease)
25 const bool included = (index.data(Qt::DisplayRole).toString() ==
"Yes");
26 model->setData(index, !included, Qt::EditRole);
29 return QStyledItemDelegate::editorEvent(event, model, option, index);
33 const QModelIndex &index)
const
35 if (index.column() == 0)
return QStyledItemDelegate::createEditor(parent, option, index);
38 if (index.column()==1)
40 QComboBox *editor =
new QComboBox(parent);
41 editor->addItem(
"Element"); editor->addItem(
"Isotope"); editor->addItem(
"Particle Size");editor->addItem(
"Organic Carbon");editor->addItem(
"Exclude");
42 string element_name = index.sibling(index.row(),0).data(Qt::DisplayRole).toString().toStdString();
44 editor->setCurrentText(
"Exclude");
46 editor->setCurrentText(
"Element");
48 editor->setCurrentText(
"Isotope");
50 editor->setCurrentText(
"Particle Size");
52 editor->setCurrentText(
"Organic Carbon");
57 if (index.column()==2)
59 QComboBox *editor =
new QComboBox(parent);
60 vector<string> element_names =
Data->GetElementNames();
61 if (index.sibling(index.row(),1).data(Qt::DisplayRole)!=
"Isotope")
62 { editor->setEnabled(
false);
63 editor->setCurrentText(
"");
66 editor->setEnabled(
true);
69 for (
unsigned int i=0; i<element_names.size(); i++)
70 if (element_names[i]!=index.sibling(index.row(),0).data(Qt::DisplayRole).toString().toStdString())
71 editor->addItem(QString::fromStdString(element_names[i]));
72 editor->setCurrentText(index.data().toString());
75 if (index.column()==3)
77 QLineEdit *editor =
new QLineEdit(parent);
78 if (index.sibling(index.row(),1).data(Qt::DisplayRole)!=
"Isotope")
79 { editor->setEnabled(
false);
83 editor->setEnabled(
true);
85 QString text = index.data(Qt::DisplayRole).toString();
87 editor->setText(text);
90 if (index.column()==4)
92 if (index.column()==5)
93 return QStyledItemDelegate::createEditor(parent, option, index);
101 if (index.column()==5)
103 QStyledItemDelegate::setEditorData(editor, index);
106 QVariant var = index.data(Qt::DisplayRole);
107 if (index.column()==0)
109 QLabel *label =
static_cast<QLabel*
>(editor);
110 label->setText(var.toString());
112 if (index.column()==1)
114 QComboBox *combo =
static_cast<QComboBox*
>(editor);
115 string element_name = index.sibling(index.row(),0).data(Qt::DisplayRole).toString().toStdString();
117 combo->setCurrentText(
"Exclude");
119 combo->setCurrentText(
"Element");
121 combo->setCurrentText(
"Isotope");
123 combo->setCurrentText(
"Particle Size");
125 combo->setCurrentText(
"Organic Carbon");
129 if (index.column()==2)
131 QComboBox *combo =
static_cast<QComboBox*
>(editor);
132 combo->setCurrentText(var.toString());
134 if (index.column()==3)
136 QLineEdit *lineedit =
static_cast<QLineEdit*
>(editor);
137 lineedit->setText(var.toString());
139 if (index.column()==4)
141 QCheckBox *chkbox =
static_cast<QCheckBox*
>(editor);
142 if (var.toString()==
"No")
143 chkbox->setChecked(
false);
145 chkbox->setChecked(
true);
149 const QModelIndex &index)
const
151 if (index.column() == 0 || index.column() == 5)
153 QStyledItemDelegate::setModelData(editor, model, index);
156 QString element = model->data(index.sibling(index.row(), 0)).toString();
158 if (index.column() == 1)
160 QComboBox *comboBox =
static_cast<QComboBox*
>(editor);
161 model->setData(index,comboBox->currentText());
164 if (index.column() == 2)
166 QComboBox *comboBox =
static_cast<QComboBox*
>(editor);
167 model->setData(index,comboBox->currentText());
170 if (index.column() == 3)
172 QLineEdit *lineEdit =
static_cast<QLineEdit*
>(editor);
173 model->setData(index,lineEdit->text());
176 if (index.column() == 4)
178 QCheckBox *chkbox =
static_cast<QCheckBox*
>(editor);
180 if (chkbox->checkState()==Qt::CheckState::Checked)
181 model->setData(index,
true);
183 model->setData(index,
false);
bool editorEvent(QEvent *event, QAbstractItemModel *model, const QStyleOptionViewItem &option, const QModelIndex &index) override
Toggles the "Include in analysis" column with a single click.