Debian Codegraph @

avogadro/qtplugins/propertytables/propertymodel.h

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 #ifndef PROPMODEL_H
7 #define PROPMODEL_H
8
9 #include <QtCore/QAbstractTableModel>
10 #include <QtCore/QList>
11 #include <QtCore/QObject>
12 #include <QtCore/QString>
13
14 #include <avogadro/core/angleiterator.h>
15 #include <avogadro/core/dihedraliterator.h>
16 #include <avogadro/qtgui/rwmolecule.h>
17
18 #include <Eigen/Geometry>
19
20 namespace Avogadro {
21
22 namespace QtGui {
23 class Molecule;
24 }
25
26 enum PropertyType
27 {
28 Other = 0,
29 AtomType,
30 BondType,
31 AngleType,
32 TorsionType,
33 ConformerType,
34 ResidueType,
35 MoleculeType,
36 };
37
38 class PropertyModel : public QAbstractTableModel
39 {
40 Q_OBJECT
41
42 public slots:
43 void updateTable(unsigned int flags);
44
45 public:
46 explicit PropertyModel(PropertyType type, QObject* parent = nullptr);
47
48 int rowCount(const QModelIndex& parent = QModelIndex()) const override;
49 int columnCount(const QModelIndex& parent = QModelIndex()) const override;
50 QVariant data(const QModelIndex& index, int role) const override;
51 Qt::ItemFlags flags(const QModelIndex& index) const override;
52 bool setData(const QModelIndex& index, const QVariant& value,
53 int role = Qt::EditRole) override;
54 QVariant headerData(int section, Qt::Orientation orientation,
55 int role = Qt::DisplayRole) const override;
56
57 void setMolecule(QtGui::Molecule* molecule);
58
59 // Return what type of model this is
60 PropertyType type() const { return m_type; };
61 bool isColorIndex(const QModelIndex& index) const;
62
63 // Partial charge type selection
64 QStringList availableChargeTypes() const;
65 void setChargeType(const QString& type);
66 QString chargeType() const { return m_chargeType; }
67
68 // Generate all data pertaining to angles and torsions
69 void updateCache() const;
70
71 // Get the angle for a given index
72 Core::Angle getAngle(unsigned int angle) const;
73 Real getAngleValue(unsigned int angle) const;
74
75 // Get the torson for a given index
76 Core::Dihedral getTorsion(unsigned int torsion) const;
77 Real getTorsionValue(unsigned int torsion) const;
78
79 private:
80 PropertyType m_type;
81 QtGui::Molecule* m_molecule;
82 QString m_chargeType; // user-selected charge type override (empty = auto)
83
84 mutable bool m_validCache;
85 mutable std::vector<Core::Angle> m_angles;
86 mutable std::vector<Core::Dihedral> m_torsions;
87
88 // Track structure counts to detect actual structural changes vs
89 // coordinate-only
90 mutable Index m_lastAtomCount = 0;
91 mutable Index m_lastBondCount = 0;
92
93 QString secStructure(unsigned int type) const;
94
95 std::vector<int> m_fragment;
96 Eigen::Affine3d m_transform;
97 bool fragmentHasAtom(int uid) const;
98 void buildFragment(const QtGui::RWBond& bond, const QtGui::RWAtom& startAtom);
99 bool fragmentRecurse(const QtGui::RWBond& bond,
100 const QtGui::RWAtom& startAtom,
101 const QtGui::RWAtom& currentAtom);
102
103 void setBondLength(unsigned int index, double value);
104 void setAngle(unsigned int index, double newValue);
105 void setTorsion(unsigned int index, double newValue);
106 void transformFragment() const;
107
108 QtGui::RWAtom otherBondedAtom(const QtGui::RWBond& bond,
109 const QtGui::RWAtom& atom) const
110 {
111 return bond.atom1() == atom ? bond.atom2() : bond.atom1();
112 }
113
114 /*
115 * For each category (atom, bond etc), an enum specifies which columns hold
116 * which data.
117 */
118
119 // Atom Data
120 enum AtomColumn
121 {
122 AtomDataElement = 0,
123 AtomDataValence,
124 AtomDataFormalCharge,
125 AtomDataPartialCharge,
126 AtomDataX,
127 AtomDataY,
128 AtomDataZ,
129 AtomDataLabel,
130 AtomDataIsotope,
131 AtomDataColor,
132 AtomDataCustom,
133 };
134
135 // Bond Data
136 enum BondColumn
137 {
138 BondDataType = 0,
139 BondDataAtom1,
140 BondDataAtom2,
141 BondDataOrder,
142 BondDataLength,
143 BondDataLabel
144 };
145
146 // Angle Data
147 enum AngleColumn
148 {
149 AngleDataType = 0,
150 AngleDataAtom1,
151 AngleDataAtom2,
152 AngleDataAtom3,
153 AngleDataValue
154 };
155
156 // Torsion Data
157 enum TorsionColumn
158 {
159 TorsionDataType = 0,
160 TorsionDataAtom1,
161 TorsionDataAtom2,
162 TorsionDataAtom3,
163 TorsionDataAtom4,
164 TorsionDataValue
165 };
166
167 // Conformer Data
168 enum ConformerColumn
169 {
170 ConformerDataRMSD = 0,
171 ConformerDataEnergy
172 };
173
174 // Residue Data
175 enum ResidueColumn
176 {
177 ResidueDataName = 0,
178 ResidueDataID,
179 ResidueDataChain,
180 ResidueDataSecStructure,
181 ResidueDataLabel,
182 ResidueDataColor,
183 ResidueDataHeterogen
184 };
185 };
186
187 } // end namespace Avogadro
188
189 #endif