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.
1// SedSAT3 – Sediment Source Assessment Tool, version 3
2// U.S. Geological Survey. See LICENSE.md and DISCLAIMER.md in the repository root.
3
5
6#include "QCheckBox"
7#include "QComboBox"
8#include "QLineEdit"
9#include "QLabel"
10
12 : QStyledItemDelegate(parent)
13{
14 Data=data;
15}
16
42
43QWidget *SelectSampleDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem &option,
44 const QModelIndex &index) const
45{
46 if (columnTypes[index.column()] == column_type::name) return QStyledItemDelegate::createEditor(parent, option, index);
47 if (columnTypes[index.column()] == column_type::yesno)
48 {
49 QCheckBox *editor = new QCheckBox(parent);
50 editor->setChecked(index.data(Qt::DisplayRole).toBool());
51 return editor;
52 }
53
54 return nullptr;
55
56}
57
58void SelectSampleDelegate::setEditorData(QWidget *editor, const QModelIndex &index) const
59{
60 QVariant var = index.data(Qt::DisplayRole);
61 if (columnTypes[index.column()]==column_type::name)
62 {
63 QLabel *label = static_cast<QLabel*>(editor);
64 label->setText(var.toString());
65 }
66 if (columnTypes[index.column()]==column_type::yesno)
67 {
68 QCheckBox *chkbox = static_cast<QCheckBox*>(editor);
69 if (var.toString()=="No")
70 chkbox->setChecked(false);
71 else
72 chkbox->setChecked(true);
73 }
74}
75void SelectSampleDelegate::setModelData(QWidget *editor, QAbstractItemModel *model,
76 const QModelIndex &index) const
77{
78 if (columnTypes[index.column()] == column_type::name) QStyledItemDelegate::setModelData(editor, model, index);
79 if (columnTypes[index.column()] == column_type::yesno)
80 {
81 QCheckBox *chkbox = static_cast<QCheckBox*>(editor);
82
83 if (chkbox->checkState()==Qt::CheckState::Checked)
84 model->setData(index,true);
85 else
86 model->setData(index,false);
87 return;
88 }
89}
90
92 const QStyleOptionViewItem &option, const QModelIndex &/*index*/) const
93{
94 editor->setGeometry(option.rect);
95}
96
97void SelectSampleDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option,
98 const QModelIndex &index) const
99{
100 QStyledItemDelegate::paint(painter, option, index);
101}
102
QVector< column_type > columnTypes
QWidget * createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const override
void setEditorData(QWidget *editor, const QModelIndex &index) const override
void setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const override
SelectSampleDelegate(SourceSinkData *data, QObject *parent)
void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const override
void updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option, const QModelIndex &index) const override