SedSat3 1.1.6
Sediment Source Apportionment Tool - Advanced statistical methods for environmental pollution research
Loading...
Searching...
No Matches
elementtabledelegate.cpp
Go to the documentation of this file.
2#include "QCheckBox"
3#include "QComboBox"
4#include "QLineEdit"
5#include "QLabel"
6
8{
9 Data=_Data;
10}
11
12QWidget *ElementTableDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem &option,
13 const QModelIndex &index) const
14{
15 if (index.column() == 0) return QStyledItemDelegate::createEditor(parent, option, index);
16
17
18 if (index.column()==1)
19 {
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");
33
34
35 return editor;
36 }
37 if (index.column()==2)
38 {
39 QComboBox *editor = new QComboBox(parent);
40 vector<string> element_names = Data->GetElementNames();
41 if (index.sibling(index.row(),1).data(Qt::DisplayRole)!="Isotope")
42 { editor->setEnabled(false);
43 editor->setCurrentText("");
44 }
45 else
46 editor->setEnabled(true);
47
48
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());
53 return editor;
54 }
55 if (index.column()==3)
56 {
57 QLineEdit *editor = new QLineEdit(parent);
58 if (index.sibling(index.row(),1).data(Qt::DisplayRole)!="Isotope")
59 { editor->setEnabled(false);
60 editor->setText("");
61 }
62 else
63 editor->setEnabled(true);
64
65 QString text = index.data(Qt::DisplayRole).toString();
66
67 editor->setText(text);
68 return editor;
69 }
70 if (index.column()==4)
71 {
72 QCheckBox *editor = new QCheckBox(parent);
73 editor->setChecked(index.data(Qt::DisplayRole).toBool());
74 return editor;
75 }
76
77 return nullptr;
78
79}
80
81void ElementTableDelegate::setEditorData(QWidget *editor, const QModelIndex &index) const
82{
83 QVariant var = index.data(Qt::DisplayRole);
84 if (index.column()==0)
85 {
86 QLabel *label = static_cast<QLabel*>(editor);
87 label->setText(var.toString());
88 }
89 if (index.column()==1)
90 {
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");
103
104 return;
105 }
106 if (index.column()==2)
107 {
108 QComboBox *combo = static_cast<QComboBox*>(editor);
109 combo->setCurrentText(var.toString());
110 }
111 if (index.column()==3)
112 {
113 QLineEdit *lineedit = static_cast<QLineEdit*>(editor);
114 lineedit->setText(var.toString());
115 }
116 if (index.column()==4)
117 {
118 QCheckBox *chkbox = static_cast<QCheckBox*>(editor);
119 if (var.toString()=="No")
120 chkbox->setChecked(false);
121 else
122 chkbox->setChecked(true);
123 }
124}
125void ElementTableDelegate::setModelData(QWidget *editor, QAbstractItemModel *model,
126 const QModelIndex &index) const
127{
128 if (index.column() == 0) QStyledItemDelegate::setModelData(editor, model, index);
129 QString element = model->data(index.sibling(index.row(), 0)).toString();
130
131 if (index.column() == 1)
132 {
133 QComboBox *comboBox = static_cast<QComboBox*>(editor);
134 model->setData(index,comboBox->currentText());
135 return;
136 }
137 if (index.column() == 2)
138 {
139 QComboBox *comboBox = static_cast<QComboBox*>(editor);
140 model->setData(index,comboBox->currentText());
141 return;
142 }
143 if (index.column() == 3)
144 {
145 QLineEdit *lineEdit = static_cast<QLineEdit*>(editor);
146 model->setData(index,lineEdit->text());
147 return;
148 }
149 if (index.column() == 4)
150 {
151 QCheckBox *chkbox = static_cast<QCheckBox*>(editor);
152 qDebug()<<chkbox->checkState();
153 if (chkbox->checkState()==Qt::CheckState::Checked)
154 model->setData(index,true);
155 else
156 model->setData(index,false);
157 return;
158 }
159}
160
162 const QStyleOptionViewItem &option, const QModelIndex &index) const
163{
164 editor->setGeometry(option.rect);
165}
166
167void ElementTableDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option,
168 const QModelIndex &index) const
169{
170 QStyledItemDelegate::paint(painter, option, index);
171}
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.
@ element
Standard chemical element concentration.
@ isotope
Isotopic ratio (e.g., 206Pb/207Pb)
@ organic_carbon
Organic carbon content.
@ particle_size
Particle size distribution parameter.
@ do_not_include
Exclude from all analyses.