qse  0.5.4
qsescanaveragermodel.cpp
Go to the documentation of this file.
1 #include "qsescanaveragermodel.h"
2 #include "qsescanaverager.h"
3 #include "qsedataset.h"
4 
5 #include <QColor>
6 #include <QTableView>
7 
8 #include <stdio.h>
9 
11 (QseScanAverager *scanaverager, QTableView *table, QObject *parent)
12  : inherited(parent),
13  m_ScanAverager(scanaverager),
14  m_TableView(table),
15  m_PrevRowCount(0),
16  m_PrevColumnCount(0)
17 {
18  connect(m_ScanAverager -> inputData(), SIGNAL(operationCompleted()),
19  this, SLOT(operationCompleted()));
20 
21 // connect(m_ScanAverager -> inputData(), SIGNAL(dataChanged()),
22 // this, SLOT(dataChanged()));
23 
24 // connect(m_ScanAverager -> inputData(), SIGNAL(dataCleared()),
25 // this, SLOT(dataCleared()));
26 
27 // connect(m_ScanAverager -> inputData(), SIGNAL(dataChanged()),
28 // this, SIGNAL(modelReset()));
29 }
30 
31 int
32 QseScanAveragerModel::rowCount(const QModelIndex &parent) const
33 {
34  if (parent.column() > 0) {
35  return 0;
36  }
37 
38  int res = m_ScanAverager -> inputData() -> scanCount();
39 
40 // if (res > m_PrevRowCount) {
41 // printf("QseScanAveragerModel::rowCount(%d>%d)\n", res, m_PrevRowCount);
42 // } else if (res < m_PrevRowCount) {
43 // printf("QseScanAveragerModel::rowCount(%d<%d)\n", res, m_PrevRowCount);
44 // }
45 
46  m_PrevRowCount = res;
47 
48  return res;
49 }
50 
51 int
52 QseScanAveragerModel::columnCount(const QModelIndex &parent) const
53 {
54  int res = 3 // + m_ScanAverager -> inputData() -> maxColumnCount()
55  ;
56 
57 // printf("QseScanAveragerModel::columnCount = %d\n", res);
58 
59 // if (res > m_PrevColumnCount) {
60 // printf("QseScanAveragerModel::columnCount(%d>%d)\n", res, m_PrevColumnCount);
61 // } else if (res < m_PrevColumnCount) {
62 // printf("QseScanAveragerModel::columnCount(%d<%d)\n", res, m_PrevColumnCount);
63 // }
64 
65  m_PrevColumnCount = res;
66 
67  return res;
68 }
69 
70 QVariant
71 QseScanAveragerModel::data(const QModelIndex &index, int role) const
72 {
73 // printf("QseScanAveragerModel::data(%d,%d,%d)\n", index.row(), index.column(), role);
74 
75  if (!index.isValid()) {
76  return QVariant();
77  }
78 
79  if (role == Qt::DisplayRole) {
80 
81  int row = index.row();
82  int col = index.column();
83 
84  QseScan *scan = m_ScanAverager -> inputData() -> scan(row);
85 
86  switch (col) {
87  case 0:
88  return scan -> name();
89  break;
90  case 1:
91  return scan -> maxRowCount();
92  break;
93  case 2:
94  return scan -> columnCount();
95  break;
96  default:
97  QseColumn *c = scan->column(col-3);
98 
99  if (c) {
100  return c -> name();
101  } else {
102  return QVariant();
103  }
104  }
105  } else {
106  return QVariant();
107  }
108 }
109 
110 QVariant
112 (int section, Qt::Orientation orientation, int role) const
113 {
114  if (orientation == Qt::Horizontal && role == Qt::DisplayRole) {
115  switch (section) {
116  case 0:
117  return "Scan Name";
118  break;
119  case 1:
120  return "Rows";
121  break;
122  case 2:
123  return "Columns";
124  break;
125  default:
126  return tr("Col %1").arg(section-3);
127  }
128  }
129 
130  if (orientation == Qt::Vertical && role == Qt::DisplayRole) {
131  return section;
132  }
133 
134  return QVariant();
135 }
136 
137 void
139 {
140 // printf("QseScanAveragerModel::operationCompleted\n");
141 
142 // reset();
143  beginResetModel();
144  endResetModel();
145 
146 // m_TableView -> resizeRowsToContents();
147 // m_TableView -> resizeColumnsToContents();
148 }
149 
150 void
152 {
153 // reset();
154  beginResetModel();
155  endResetModel();
156 
157 // m_TableView -> resizeRowsToContents();
158 // m_TableView -> resizeColumnsToContents();
159 }
160 
161 void
163 {
164 // reset();
165  beginResetModel();
166  endResetModel();
167 }
168 
169 void
171 {
172 }
QAbstractTableModel inherited
int columnCount(const QModelIndex &parent=QModelIndex()) const
QVariant headerData(int section, Qt::Orientation orientation, int role=Qt::DisplayRole) const
QseScanAverager * m_ScanAverager
QseScanAveragerModel(QseScanAverager *averager, QTableView *table, QObject *parent=0)
QseScanAverager * m_ScanAverager
QseColumn * column(int n) const
Definition: qsescan.cpp:104
int rowCount(const QModelIndex &parent=QModelIndex()) const
QVariant data(const QModelIndex &index, int role) const