13 const QModelIndex &index)
const
15 if (index.column() == 0)
return QStyledItemDelegate::createEditor(parent, option, index);
18 if (index.column()==1)
20 QComboBox *editor =
new QComboBox(parent);
21 editor->addItem(
"Element"); editor->addItem(
"Isotope"); editor->addItem(
"Particle Size");editor->addItem(
"Organic Carbon");editor->addItem(
"Exclude");
22 string element_name = index.sibling(index.row(),0).data(Qt::DisplayRole).toString().toStdString();
24 editor->setCurrentText(
"Exclude");
26 editor->setCurrentText(
"Element");
28 editor->setCurrentText(
"Isotope");
30 editor->setCurrentText(
"Particle Size");
32 editor->setCurrentText(
"Organic Carbon");
37 if (index.column()==2)
39 QComboBox *editor =
new QComboBox(parent);
41 if (index.sibling(index.row(),1).data(Qt::DisplayRole)!=
"Isotope")
42 { editor->setEnabled(
false);
43 editor->setCurrentText(
"");
46 editor->setEnabled(
true);
49 for (
unsigned int i=0; i<element_names.size(); i++)
50 if (element_names[i]!=index.sibling(index.row(),0).data(Qt::DisplayRole).toString().toStdString())
51 editor->addItem(QString::fromStdString(element_names[i]));
52 editor->setCurrentText(index.data().toString());
55 if (index.column()==3)
57 QLineEdit *editor =
new QLineEdit(parent);
58 if (index.sibling(index.row(),1).data(Qt::DisplayRole)!=
"Isotope")
59 { editor->setEnabled(
false);
63 editor->setEnabled(
true);
65 QString text = index.data(Qt::DisplayRole).toString();
67 editor->setText(text);
70 if (index.column()==4)
72 QCheckBox *editor =
new QCheckBox(parent);
73 editor->setChecked(index.data(Qt::DisplayRole).toBool());
83 QVariant var = index.data(Qt::DisplayRole);
84 if (index.column()==0)
86 QLabel *label =
static_cast<QLabel*
>(editor);
87 label->setText(var.toString());
89 if (index.column()==1)
91 QComboBox *combo =
static_cast<QComboBox*
>(editor);
92 string element_name = index.sibling(index.row(),0).data(Qt::DisplayRole).toString().toStdString();
94 combo->setCurrentText(
"Exclude");
96 combo->setCurrentText(
"Element");
98 combo->setCurrentText(
"Isotope");
100 combo->setCurrentText(
"Particle Size");
102 combo->setCurrentText(
"Organic Carbon");
106 if (index.column()==2)
108 QComboBox *combo =
static_cast<QComboBox*
>(editor);
109 combo->setCurrentText(var.toString());
111 if (index.column()==3)
113 QLineEdit *lineedit =
static_cast<QLineEdit*
>(editor);
114 lineedit->setText(var.toString());
116 if (index.column()==4)
118 QCheckBox *chkbox =
static_cast<QCheckBox*
>(editor);
119 if (var.toString()==
"No")
120 chkbox->setChecked(
false);
122 chkbox->setChecked(
true);
126 const QModelIndex &index)
const
128 if (index.column() == 0) QStyledItemDelegate::setModelData(editor, model, index);
129 QString element = model->data(index.sibling(index.row(), 0)).toString();
131 if (index.column() == 1)
133 QComboBox *comboBox =
static_cast<QComboBox*
>(editor);
134 model->setData(index,comboBox->currentText());
137 if (index.column() == 2)
139 QComboBox *comboBox =
static_cast<QComboBox*
>(editor);
140 model->setData(index,comboBox->currentText());
143 if (index.column() == 3)
145 QLineEdit *lineEdit =
static_cast<QLineEdit*
>(editor);
146 model->setData(index,lineEdit->text());
149 if (index.column() == 4)
151 QCheckBox *chkbox =
static_cast<QCheckBox*
>(editor);
152 qDebug()<<chkbox->checkState();
153 if (chkbox->checkState()==Qt::CheckState::Checked)
154 model->setData(index,
true);
156 model->setData(index,
false);
162 const QStyleOptionViewItem &option,
const QModelIndex &index)
const
164 editor->setGeometry(option.rect);
168 const QModelIndex &index)
const
170 QStyledItemDelegate::paint(painter, option, index);
void setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const override
void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const override
ElementTableDelegate(SourceSinkData *_Data, QObject *parent)
QWidget * createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const override
void setEditorData(QWidget *editor, const QModelIndex &index) const override
void updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option, const QModelIndex &index) const override
vector< string > GetElementNames() const
Get all element names in the dataset.
map< string, element_information > * GetElementInformation()
Retrieves pointer to the element information map.