SedSat3 1.1.6
Sediment Source Apportionment Tool - Advanced statistical methods for environmental pollution research
Loading...
Searching...
No Matches
selectsampledelegate.cpp
Go to the documentation of this file.
2
3#include "QCheckBox"
4#include "QComboBox"
5#include "QLineEdit"
6#include "QLabel"
7
9{
10 Data=_Data;
11}
12
38
39QWidget *SelectSampleDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem &option,
40 const QModelIndex &index) const
41{
42 if (columnTypes[index.column()] == column_type::name) return QStyledItemDelegate::createEditor(parent, option, index);
43 if (columnTypes[index.column()] == column_type::yesno)
44 {
45 QCheckBox *editor = new QCheckBox(parent);
46 editor->setChecked(index.data(Qt::DisplayRole).toBool());
47 return editor;
48 }
49
50 return nullptr;
51
52}
53
54void SelectSampleDelegate::setEditorData(QWidget *editor, const QModelIndex &index) const
55{
56 QVariant var = index.data(Qt::DisplayRole);
57 if (columnTypes[index.column()]==column_type::name)
58 {
59 QLabel *label = static_cast<QLabel*>(editor);
60 label->setText(var.toString());
61 }
62 if (columnTypes[index.column()]==column_type::yesno)
63 {
64 QCheckBox *chkbox = static_cast<QCheckBox*>(editor);
65 if (var.toString()=="No")
66 chkbox->setChecked(false);
67 else
68 chkbox->setChecked(true);
69 }
70}
71void SelectSampleDelegate::setModelData(QWidget *editor, QAbstractItemModel *model,
72 const QModelIndex &index) const
73{
74 if (columnTypes[index.column()] == column_type::name) QStyledItemDelegate::setModelData(editor, model, index);
75 if (columnTypes[index.column()] == column_type::yesno)
76 {
77 QCheckBox *chkbox = static_cast<QCheckBox*>(editor);
78
79 if (chkbox->checkState()==Qt::CheckState::Checked)
80 model->setData(index,true);
81 else
82 model->setData(index,false);
83 return;
84 }
85}
86
88 const QStyleOptionViewItem &option, const QModelIndex &index) const
89{
90 editor->setGeometry(option.rect);
91}
92
93void SelectSampleDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option,
94 const QModelIndex &index) const
95{
96 QStyledItemDelegate::paint(painter, option, index);
97}
98
QVector< column_type > columnTypes
QWidget * createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const override
SelectSampleDelegate(SourceSinkData *_Data, QObject *parent)
void setEditorData(QWidget *editor, const QModelIndex &index) const override
void setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const override
void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const override
void updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option, const QModelIndex &index) const override
@ regressions
@ samples