SedSat3 1.1.6
Sediment Source Apportionment Tool - Advanced statistical methods for environmental pollution research
Loading...
Searching...
No Matches
selectsampletablemodel.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
6SelectSampleTableModel::SelectSampleTableModel(SourceSinkData *_data, QObject *parent) : QAbstractTableModel(parent)
7{
8 Data = _data;
9}
10int SelectSampleTableModel::rowCount(const QModelIndex &/*index*/) const
11{
12 return Data->operator[](selectedSource).size();
13}
14int SelectSampleTableModel::columnCount(const QModelIndex &/*index*/) const
15{
16 return 3;
17}
18QVariant SelectSampleTableModel::data(const QModelIndex &index, int role) const
19{
20 if (role == Qt::DisplayRole)
21 { if (index.column()==0)
22 {
23 return QString::fromStdString(Data->operator[](selectedSource).GetSampleNames()[index.row()]);
24 }
25 if (index.column()==1)
26 {
27 if (GetProfileSet(index.row())->IsIncludedInAnalysis())
28 return "Yes";
29 else
30 return "No";
31 }
32 if (index.column()==2)
33 {
34 return QString::fromStdString(GetProfileSet(index.row())->GetNotes());
35 }
36
37 }
38 if (role == Qt::ForegroundRole)
39 {
40 if (GetProfileSet(index.row())->GetNotes()!="")
41 return QVariant::fromValue(QColor(Qt::red));
42 else
43 return QVariant::fromValue(QColor(Qt::black));
44 }
45
46 return QVariant();
47
48}
49
51{
52 return &Data->operator[](selectedSource)[Data->operator[](selectedSource).GetSampleNames()[row]];
53}
54
56{
57 return &Data->operator[](selectedSource)[Data->operator[](selectedSource).GetSampleNames()[row]];
58}
59QVariant SelectSampleTableModel::headerData(int section, Qt::Orientation orientation, int role) const
60{
61 if (role == Qt::DisplayRole)
62 {
63 if (orientation == Qt::Horizontal)
64 { if (section==0)
65 {
66 return "Sample";
67 }
68 if (section==1)
69 {
70 return "Include";
71 }
72 if (section==2)
73 {
74 return "Notes";
75 }
76 }
77 }
78 return QVariant();
79}
80bool SelectSampleTableModel::setData(const QModelIndex & index, const QVariant & value, int role)
81{
82 if (role==Qt::EditRole)
83 {
84
85 if (index.column()==1)
86 {
87 if (value.toString()=="Yes" || value.toBool())
88 GetProfileSet(index.row())->SetIncludedInAnalysis(true);
89 else
90 GetProfileSet(index.row())->SetIncludedInAnalysis(false);
91 }
92
93 }
94 QString result = "Done";
95 emit editCompleted(result);
96 return true;
97}
98Qt::ItemFlags SelectSampleTableModel::flags(const QModelIndex & index) const
99{
100 if (index.column()!=0)
101 return Qt::ItemIsSelectable | Qt::ItemIsEditable | Qt::ItemIsEnabled ;
102 else
103 return Qt::ItemIsSelectable | Qt::ItemIsEnabled ;
104}
Container for elemental concentration data of a single sediment sample.
void SetIncludedInAnalysis(bool included)
Set analysis inclusion status.
bool IsIncludedInAnalysis() const
Check if profile is included in analysis.
string GetNotes() const
Get the notes/annotations associated with this object.
Definition interface.h:180
Elemental_Profile * GetProfileSet(int row)
bool setData(const QModelIndex &index, const QVariant &value, int role=Qt::EditRole) override
QVariant data(const QModelIndex &index, int role=Qt::DisplayRole) const override
int columnCount(const QModelIndex &parent=QModelIndex()) const override
Qt::ItemFlags flags(const QModelIndex &index) const override
QVariant headerData(int section, Qt::Orientation orientation, int role) const override
int rowCount(const QModelIndex &parent=QModelIndex()) const override
SelectSampleTableModel(SourceSinkData *Data, QObject *parent=nullptr)
void editCompleted(const QString &)