QXRD  0.11.16
Public Types | Public Member Functions | Private Attributes | List of all members
QxrdCalibrantLibraryModel Class Reference

#include <qxrdcalibrantlibrarymodel.h>

Inheritance diagram for QxrdCalibrantLibraryModel:
Inheritance graph
[legend]
Collaboration diagram for QxrdCalibrantLibraryModel:
Collaboration graph
[legend]

Public Types

enum  {
  IsUsedColumn, FlagsColumn, NameColumn, SymmetryColumn,
  DescriptionColumn, NumColumns
}
 

Public Member Functions

 QxrdCalibrantLibraryModel (QxrdCalibrantLibraryPtr cal)
 
 ~QxrdCalibrantLibraryModel ()
 
virtual int rowCount (const QModelIndex &parent=QModelIndex()) const
 
virtual int columnCount (const QModelIndex &parent=QModelIndex()) const
 
virtual QVariant data (const QModelIndex &index, int role) const
 
virtual QVariant headerData (int section, Qt::Orientation orientation, int role=Qt::DisplayRole) const
 
void toggleIsUsed (int n)
 
int isUsed (int n)
 
void setIsUsed (int n, int v)
 
void calibrantChanged (int n)
 

Private Attributes

QxrdCalibrantLibraryPtr m_CalibrantLibrary
 

Detailed Description

Definition at line 7 of file qxrdcalibrantlibrarymodel.h.

Member Enumeration Documentation

anonymous enum

Constructor & Destructor Documentation

QxrdCalibrantLibraryModel::QxrdCalibrantLibraryModel ( QxrdCalibrantLibraryPtr  cal)

Definition at line 5 of file qxrdcalibrantlibrarymodel.cpp.

6  : m_CalibrantLibrary(cal)
7 {
8 
9 }
QxrdCalibrantLibraryPtr m_CalibrantLibrary
QxrdCalibrantLibraryModel::~QxrdCalibrantLibraryModel ( )

Definition at line 11 of file qxrdcalibrantlibrarymodel.cpp.

12 {
13 
14 }

Member Function Documentation

void QxrdCalibrantLibraryModel::calibrantChanged ( int  n)

Definition at line 175 of file qxrdcalibrantlibrarymodel.cpp.

References columnCount().

176 {
177  int nc = columnCount();
178 
179  emit dataChanged(index(n,0), index(n,nc-1));
180 }
virtual int columnCount(const QModelIndex &parent=QModelIndex()) const

Here is the call graph for this function:

int QxrdCalibrantLibraryModel::columnCount ( const QModelIndex &  parent = QModelIndex()) const
virtual

Definition at line 25 of file qxrdcalibrantlibrarymodel.cpp.

References NumColumns.

Referenced by calibrantChanged(), and headerData().

26 {
27  if (parent.isValid()) {
28  return 0;
29  }
30 
31  return NumColumns;
32 }

Here is the caller graph for this function:

QVariant QxrdCalibrantLibraryModel::data ( const QModelIndex &  index,
int  role 
) const
virtual

Definition at line 34 of file qxrdcalibrantlibrarymodel.cpp.

References QxrdCalibrant::BodyCenteredCubic, DescriptionColumn, QxrdCalibrant::DiamondCubic, QxrdCalibrant::FaceCenteredCubic, FlagsColumn, QxrdCalibrant::Hexagonal, IsUsedColumn, m_CalibrantLibrary, NameColumn, QxrdCalibrant::RHexagonal, QxrdCalibrant::SimpleCubic, and SymmetryColumn.

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 }
QSharedPointer< QxrdCalibrant > QxrdCalibrantPtr
QxrdCalibrantLibraryPtr m_CalibrantLibrary
QVariant QxrdCalibrantLibraryModel::headerData ( int  section,
Qt::Orientation  orientation,
int  role = Qt::DisplayRole 
) const
virtual

Definition at line 103 of file qxrdcalibrantlibrarymodel.cpp.

References columnCount(), DescriptionColumn, FlagsColumn, IsUsedColumn, NameColumn, and SymmetryColumn.

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 }
virtual int columnCount(const QModelIndex &parent=QModelIndex()) const

Here is the call graph for this function:

int QxrdCalibrantLibraryModel::isUsed ( int  n)

Definition at line 142 of file qxrdcalibrantlibrarymodel.cpp.

References m_CalibrantLibrary.

143 {
144  QxrdCalibrantPtr cal = m_CalibrantLibrary->calibrant(n);
145 
146  if (cal) {
147  return cal->get_IsUsed();
148  } else {
149  return 0;
150  }
151 }
QSharedPointer< QxrdCalibrant > QxrdCalibrantPtr
QxrdCalibrantLibraryPtr m_CalibrantLibrary
int QxrdCalibrantLibraryModel::rowCount ( const QModelIndex &  parent = QModelIndex()) const
virtual

Definition at line 16 of file qxrdcalibrantlibrarymodel.cpp.

References m_CalibrantLibrary.

17 {
18  if (parent.isValid()) {
19  return 0;
20  }
21 
22  return m_CalibrantLibrary->count();
23 }
QxrdCalibrantLibraryPtr m_CalibrantLibrary
void QxrdCalibrantLibraryModel::setIsUsed ( int  n,
int  v 
)

Definition at line 164 of file qxrdcalibrantlibrarymodel.cpp.

References m_CalibrantLibrary.

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 }
QSharedPointer< QxrdCalibrant > QxrdCalibrantPtr
QxrdCalibrantLibraryPtr m_CalibrantLibrary
void QxrdCalibrantLibraryModel::toggleIsUsed ( int  n)

Definition at line 153 of file qxrdcalibrantlibrarymodel.cpp.

References m_CalibrantLibrary.

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 }
QSharedPointer< QxrdCalibrant > QxrdCalibrantPtr
QxrdCalibrantLibraryPtr m_CalibrantLibrary

Member Data Documentation

QxrdCalibrantLibraryPtr QxrdCalibrantLibraryModel::m_CalibrantLibrary
private

Definition at line 37 of file qxrdcalibrantlibrarymodel.h.

Referenced by data(), isUsed(), rowCount(), setIsUsed(), and toggleIsUsed().


The documentation for this class was generated from the following files: