1 /* Copyright (c) 2015 Gerald Knizia 2 * 3 * This file is part of the IboView program (see: http://www.iboview.org) 4 * 5 * IboView is free software: you can redistribute it and/or modify 6 * it under the terms of the GNU General Public License as published by 7 * the Free Software Foundation, version 3. 8 * 9 * IboView is distributed in the hope that it will be useful, 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 * GNU General Public License for details. 13 * 14 * You should have received a copy of the GNU General Public License 15 * along with bfint (LICENSE). If not, see http://www.gnu.org/licenses/ 16 * 17 * Please see IboView documentation in README.txt for: 18 * -- A list of included external software and their licenses. The included 19 * external software's copyright is not touched by this agreement. 20 * -- Notes on re-distribution and contributions to/further development of 21 * the IboView software 22 */ 23 24 #ifndef IV_TABLES_H 25 #define IV_TABLES_H 26 27 #include <QAbstractTableModel> 28 #include <QString> 29 #include <vector> 30 #include <QDialog> 31 #include "CxTypes.h" 32 #include "CxPodArray.h" 33 34 class FDocument; 35 class FFrame; 36 namespace Ui{ 37 class TablesForm; 38 } 39 40 class FDocument; 41 42 43 44 // support for tables/curves of user-definable measurements on the 45 // loaded frames (e.g., IRC, bond lengths, charges, IBO displacements, etc.) 46 47 typedef ct::TArray<double> 48 FMeasureSet; // one entry for each frame. 49 typedef ct::TArray<FFrame*> 50 FFrameMeasurePtrList; 51 52 // should I make them QObjects instead? Not sure. 53 // also not sure if "make everything given a frame list" 54 // is really that good of an idea. It might be expensive 55 // and/or re-calculate stuff often. Might need cache 56 // or invalidate settings or similar. 57 struct FMeasure : public ct::FIntrusivePtrDest 58 { 59 enum FFmtFlags { 60 FORMAT_ValueOnly = 0x01 61 }; 62 63 explicit FMeasure(FDocument *pDocument_, QString const &UnitName_, int nDigits_, double fAuToOutFactor_); 64 virtual void MakeValues(FMeasureSet &FrameValues, FFrameMeasurePtrList &Frames) const = 0; 65 virtual QString Name() const = 0; 66 virtual ~FMeasure(); 67 virtual QString UnitName() const; // default implementation returns m_UnitName. 68 virtual QString FmtValue(double f, uint Flags=0) const; 69 70 // a convenience function for computing values for single frames for info purposes. 71 // Flags: FORMAT_* 72 QString MeasureFrame(FFrame *pFrame, uint Flags=0) const; 73 protected: 74 FDocument *m_pDocument; 75 QString m_UnitName; 76 int m_nDigits; // maybe put in a format.h-format instead? would also be better for curves and changing units etc. 77 double m_AuToOut; // factor for converting from atomic units to target unit. 78 }; 79 typedef boost::intrusive_ptr<FMeasure> 80 FMeasurePtr; 81 82 struct FMeasureBondLength : public FMeasure 83 { 84 explicit FMeasureBondLength(int iAt_, int jAt_, FDocument *pDocument_); 85 86 void MakeValues(FMeasureSet &FrameValues, FFrameMeasurePtrList &Frames) const; // override. 87 QString Name() const; // override. 88 protected: 89 int 90 m_iAt, m_jAt; 91 }; 92 93 struct FMeasureBondAngle : public FMeasure 94 { 95 explicit FMeasureBondAngle(int iAt_, int jAt_, int kAt_, FDocument *pDocument_); 96 97 void MakeValues(FMeasureSet &FrameValues, FFrameMeasurePtrList &Frames) const; // override. 98 QString Name() const; // override. 99 protected: 100 int 101 m_iAt, m_jAt, m_kAt; 102 }; 103 104 struct FMeasurePlaneAngle : public FMeasure 105 { 106 explicit FMeasurePlaneAngle(int iAt_, int jAt_, int kAt_, int lAt_, FDocument *pDocument_); 107 108 void MakeValues(FMeasureSet &FrameValues, FFrameMeasurePtrList &Frames) const; // override. 109 QString Name() const; // override. 110 protected: 111 int 112 m_iAt, m_jAt, m_kAt, m_lAt; 113 }; 114 115 116 struct FMeasureFrameId : public FMeasure 117 { 118 explicit FMeasureFrameId(FDocument *pDocument_); 119 120 void MakeValues(FMeasureSet &FrameValues, FFrameMeasurePtrList &Frames) const; // override. 121 QString Name() const; // override. 122 }; 123 124 struct FMeasureFrameGradient : public FMeasure 125 { 126 explicit FMeasureFrameGradient(FDocument *pDocument_); 127 128 void MakeValues(FMeasureSet &FrameValues, FFrameMeasurePtrList &Frames) const; // override. 129 QString Name() const; // override. 130 }; 131 132 struct FMeasureFrameEnergy : public FMeasure 133 { 134 explicit FMeasureFrameEnergy(FDocument *pDocument_); 135 136 void MakeValues(FMeasureSet &FrameValues, FFrameMeasurePtrList &Frames) const; // override. 137 QString Name() const; // override. 138 }; 139 140 141 typedef std::vector<FMeasurePtr> 142 FMeasureList; 143 // columns == measurements, rows == frames. 144 class FDocumentMeasures : public QAbstractTableModel 145 { 146 Q_OBJECT 147 public: 148 typedef QAbstractTableModel 149 FBase; 150 int rowCount(const QModelIndex &parent = QModelIndex()) const; 151 int columnCount(const QModelIndex &parent = QModelIndex()) const; 152 QVariant headerData(int section, Qt::Orientation orientation, int role) const; 153 QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const; 154 bool removeColumns(int row, int count, const QModelIndex &parent = QModelIndex()); 155 156 void AddMeasure(FMeasurePtr pMeasure); 157 158 void ConnectForwardSignals(); 159 public: 160 FDocumentMeasures(FDocument *pDocument_, QObject *Parent_); 161 ~FDocumentMeasures(); 162 public slots: 163 // forwarded from FDocument 164 void parentLayoutAboutToBeChanged(); 165 void parentLayoutChanged(); 166 protected: 167 FDocument 168 *m_pDocument; 169 FMeasureList 170 m_List; 171 FMeasure *GetMeasure(QModelIndex const &index); 172 FMeasure *GetMeasure(int iRow); GetMeasure(QModelIndex const & index)173 FMeasure const *GetMeasure(QModelIndex const &index) const {return const_cast<FDocumentMeasures*>(this)->GetMeasure(index);} GetMeasure(int iRow)174 FMeasure const *GetMeasure(int iRow) const {return const_cast<FDocumentMeasures*>(this)->GetMeasure(iRow);} 175 }; 176 177 178 struct FTablesForm : public QDialog 179 { 180 Q_OBJECT 181 182 Ui::TablesForm 183 *ui; 184 FDocument 185 *m_pDocument; 186 public: 187 typedef QDialog FBase; 188 explicit FTablesForm(FDocument *pDocument_, QWidget *pParent_ = 0); 189 }; 190 191 192 #endif // IV_TABLES_H 193