Debian Codegraph @

avogadro/qtplugins/vibrations/vibrationmodel.cpp

raw
1 /******************************************************************************
2 This source file is part of the Avogadro project.
3 This source code is released under the 3-Clause BSD License, (see "LICENSE").
4 ******************************************************************************/
5
6 #include "vibrationmodel.h"
7
8 #include <avogadro/qtgui/molecule.h>
9
10 namespace Avogadro::QtPlugins {
11
12 VibrationModel::VibrationModel(QObject* p)
13 : QAbstractItemModel(p), m_molecule(nullptr), m_hasRaman(false)
14 {
15 }
16
17 QModelIndex VibrationModel::parent(const QModelIndex&) const
18 {
19 return QModelIndex();
20 }
21
22 int VibrationModel::rowCount(const QModelIndex& p) const
23 {
24 if (p.isValid() || !m_molecule)
25 return 0;
26 else
27 return m_molecule->vibrationFrequencies().size();
28 }
29
30 int VibrationModel::columnCount(const QModelIndex&) const
31 {
32 // do we have raman data?
33 if (m_molecule && m_hasRaman)
34 return 3;
35
36 return 2;
37 }
38
39 Qt::ItemFlags VibrationModel::flags(const QModelIndex&) const
40 {
41 return Qt::ItemIsEnabled | Qt::ItemIsSelectable;
42 }
43
44 void VibrationModel::setMolecule(QtGui::Molecule* mol)
45 {
46 m_molecule = mol;
47 m_hasRaman = mol->vibrationRamanIntensities().size() > 0;
48 }
49
50 QVariant VibrationModel::headerData(int section, Qt::Orientation orientation,
51 int role) const
52 {
53 if (role == Qt::DisplayRole) {
54 if (orientation == Qt::Horizontal) {
55 switch (section) {
56 case 0:
57 return QString("Frequency (cm⁻¹)");
58 case 1:
59 return QString("Intensity (km/mol)");
60 case 2:
61 return QString("Raman Intensity (a.u.)");
62 }
63 } else if (orientation == Qt::Vertical) {
64 return QString::number(section + 1);
65 }
66 }
67 return QVariant();
68 }
69
70 bool VibrationModel::setData(const QModelIndex&, const QVariant&, int)
71 {
72 return false;
73 }
74
75 QVariant VibrationModel::data(const QModelIndex& idx, int role) const
76 {
77 if (!idx.isValid() || idx.column() > 2 || !m_molecule ||
78 static_cast<int>(m_molecule->vibrationFrequencies().size()) <=
79 idx.row()) {
80 return QVariant();
81 }
82
83 if (role == Qt::DisplayRole) {
84 switch (idx.column()) {
85 case 0:
86 if (static_cast<int>(m_molecule->vibrationFrequencies().size()) >
87 idx.row())
88 return m_molecule->vibrationFrequencies()[idx.row()];
89 else
90 return "No value";
91 case 1:
92 if (static_cast<int>(m_molecule->vibrationIRIntensities().size()) >
93 idx.row())
94 return m_molecule->vibrationIRIntensities()[idx.row()];
95 else
96 return "No value";
97 case 2:
98 if (static_cast<int>(m_molecule->vibrationRamanIntensities().size()) >
99 idx.row())
100 return m_molecule->vibrationRamanIntensities()[idx.row()];
101 else
102 return "No value";
103 default:
104 return "Invalid";
105 }
106 }
107
108 return QVariant();
109 }
110
111 QModelIndex VibrationModel::index(int row, int column,
112 const QModelIndex& p) const
113 {
114 if (!p.isValid())
115 if (row >= 0 && m_molecule &&
116 row < static_cast<int>(m_molecule->vibrationFrequencies().size()))
117 return createIndex(row, column);
118 return QModelIndex();
119 }
120
121 void VibrationModel::clear() {}
122 } // namespace Avogadro::QtPlugins