QXRD  0.11.16
qxrdcalibrantlibrarymodel.cpp
Go to the documentation of this file.
2 #include "qxrdcalibrantlibrary.h"
3 #include "qxrdcalibrant.h"
4 
6  : m_CalibrantLibrary(cal)
7 {
8 
9 }
10 
12 {
13 
14 }
15 
16 int QxrdCalibrantLibraryModel::rowCount (const QModelIndex & parent) const
17 {
18  if (parent.isValid()) {
19  return 0;
20  }
21 
22  return m_CalibrantLibrary->count();
23 }
24 
25 int QxrdCalibrantLibraryModel::columnCount(const QModelIndex & parent) const
26 {
27  if (parent.isValid()) {
28  return 0;
29  }
30 
31  return NumColumns;
32 }
33 
34 QVariant QxrdCalibrantLibraryModel::data (const QModelIndex & index, int role) const
35 {
36  if (index.row() < 0 || index.row() >= m_CalibrantLibrary->count()) {
37  return QVariant();
38  }
39 
40  QxrdCalibrantPtr cal = m_CalibrantLibrary->calibrant(index.row());
41 
42  if (cal) {
43  int col = index.column();
44 
45  if (col == IsUsedColumn) {
46  if (role == Qt::CheckStateRole) {
47  if (cal->get_IsUsed()) {
48  return Qt::Checked;
49  } else {
50  return Qt::Unchecked;
51  }
52  }
53  } else if (col == FlagsColumn) {
54  if (role == Qt::DecorationRole) {
55  if (cal->isLocked()) {
56  return QPixmap(":/images/lock-16x16.png");
57  }
58  }
59  } else if (col == NameColumn) {
60  if (role == Qt::DisplayRole) {
61  return cal->get_Name();
62  }
63  } else if (col == SymmetryColumn) {
64  if (role == Qt::DisplayRole) {
65  switch (cal->get_Symmetry()) {
67  return "Hexagonal";
68  break;
69 
71  return "R-Hexagonal";
72  break;
73 
75  return "Cubic";
76  break;
77 
79  return "BCC";
80  break;
81 
83  return "FCC";
84  break;
85 
87  return "Diamond";
88  break;
89  }
90  }
91  } else if (col == DescriptionColumn) {
92  if (role == Qt::DisplayRole) {
93  return cal->get_Description();
94 // } else if (role==Qt::SizeHintRole) {
95 // return QSize(120,20);
96  }
97  }
98  }
99 
100  return QVariant();
101 }
102 
103 QVariant QxrdCalibrantLibraryModel::headerData ( int section, Qt::Orientation orientation, int role) const
104 {
105  if (columnCount() == 1) {
106  return QVariant();
107  } else {
108  if (orientation==Qt::Horizontal) {
109  if (role==Qt::DisplayRole) {
110  switch (section) {
111  case IsUsedColumn:
112  return "Used?";
113  break;
114 
115  case FlagsColumn:
116  return "Flags";
117  break;
118 
119  case SymmetryColumn:
120  return "Symmetry";
121  break;
122 
123  case NameColumn:
124  return "Name";
125  break;
126 
127  case DescriptionColumn:
128  return "Description";
129  break;
130  }
131  }
132  } else if (orientation==Qt::Vertical) {
133  if (role==Qt::DisplayRole) {
134  return section;
135  }
136  }
137  }
138 
139  return QVariant();
140 }
141 
143 {
144  QxrdCalibrantPtr cal = m_CalibrantLibrary->calibrant(n);
145 
146  if (cal) {
147  return cal->get_IsUsed();
148  } else {
149  return 0;
150  }
151 }
152 
154 {
155  QxrdCalibrantPtr cal = m_CalibrantLibrary->calibrant(n);
156 
157  if (cal) {
158  cal->set_IsUsed(!cal->get_IsUsed());
159 
160  emit dataChanged(index(n,0), index(n,0));
161  }
162 }
163 
165 {
166  QxrdCalibrantPtr cal = m_CalibrantLibrary->calibrant(n);
167 
168  if (cal) {
169  cal->set_IsUsed(v);
170 
171  emit dataChanged(index(n,0), index(n,0));
172  }
173 }
174 
176 {
177  int nc = columnCount();
178 
179  emit dataChanged(index(n,0), index(n,nc-1));
180 }
virtual int rowCount(const QModelIndex &parent=QModelIndex()) const
QSharedPointer< QxrdCalibrantLibrary > QxrdCalibrantLibraryPtr
QxrdCalibrantLibraryModel(QxrdCalibrantLibraryPtr cal)
virtual QVariant headerData(int section, Qt::Orientation orientation, int role=Qt::DisplayRole) const
QSharedPointer< QxrdCalibrant > QxrdCalibrantPtr
virtual QVariant data(const QModelIndex &index, int role) const
virtual int columnCount(const QModelIndex &parent=QModelIndex()) const
QxrdCalibrantLibraryPtr m_CalibrantLibrary