qse  0.5.4
Public Slots | Public Member Functions | Private Types | Private Member Functions | Private Attributes | List of all members
QseGraphScansModel Class Reference

#include <qsegraphscansmodel.h>

Inheritance diagram for QseGraphScansModel:
Inheritance graph

Public Slots

void operationCompleted ()
 

Public Member Functions

 QseGraphScansModel (QseDataSet *dataSet, QTableView *table, QObject *parent=0)
 
int rowCount (const QModelIndex &parent=QModelIndex()) const
 
int columnCount (const QModelIndex &parent=QModelIndex()) const
 
QVariant data (const QModelIndex &index, int role) const
 
QVariant headerData (int section, Qt::Orientation orientation, int role=Qt::DisplayRole) const
 
QModelIndex indexOfScan (int n)
 

Private Types

typedef QAbstractTableModel inherited
 

Private Member Functions

bool scanSelected (int s)
 

Private Attributes

QseDataSetm_DataSet
 
QTableView * m_TableView
 
int m_PrevRowCount
 
int m_PrevColumnCount
 

Detailed Description

Definition at line 9 of file qsegraphscansmodel.h.

Member Typedef Documentation

typedef QAbstractTableModel QseGraphScansModel::inherited
private

Definition at line 11 of file qsegraphscansmodel.h.

Constructor & Destructor Documentation

QseGraphScansModel::QseGraphScansModel ( QseDataSet dataSet,
QTableView *  table,
QObject *  parent = 0 
)

Definition at line 9 of file qsegraphscansmodel.cpp.

10  : QAbstractTableModel(parent),
11  m_DataSet(dataSet),
12  m_TableView(table),
13  m_PrevRowCount(0),
15 {
16 // connect(dataSet, SIGNAL(dataChanged()),
17 // this, SLOT(dataChanged()));
18  connect(dataSet, SIGNAL(operationCompleted()),
19  this, SLOT(operationCompleted()));
20 }
QTableView * m_TableView

Member Function Documentation

int QseGraphScansModel::columnCount ( const QModelIndex &  parent = QModelIndex()) const

Definition at line 109 of file qsegraphscansmodel.cpp.

Referenced by data().

110 {
111  int res = 3;
112 
113 // if (res > m_PrevColumnCount) {
114 // printf("QseGraphScansModel::columnCount(%d>%d)\n", res, m_PrevColumnCount);
115 // } else if (res < m_PrevColumnCount) {
116 // printf("QseGraphScansModel::columnCount(%d<%d)\n", res, m_PrevColumnCount);
117 // }
118 
119 // m_PrevColumnCount = res;
120 
121  return res;
122 }
QVariant QseGraphScansModel::data ( const QModelIndex &  index,
int  role 
) const

Definition at line 194 of file qsegraphscansmodel.cpp.

References columnCount(), QseScan::columnCount(), m_DataSet, min(), QseDataSet::scan(), QseScan::scanColumnCountLine(), QseScan::scanColumnNamesLine(), QseScan::scanCommand(), and QseScan::scanDateLine().

195 {
196  if (!index.isValid()) {
197  return QVariant();
198  }
199 
200  int row = index.row();
201  int col = index.column();
202 
203  QseScan *scan = m_DataSet->scan(row);
204 
205  switch (role) {
206  case Qt::DisplayRole:
207  switch (col) {
208  case 0:
209  return scan -> name();
210  break;
211  case 1:
212  return scan -> maxRowCount();
213  break;
214  case 2:
215  return scan -> columnCount();
216  break;
217  default:
218  return QVariant();
219  }
220  break;
221 
222 // case Qt::BackgroundRole:
223 // return QColor(255,255,192);
224 // break;
225 
226 // case Qt::ForegroundRole:
227 // return QBrush(Qt::red);
228 // break;
229 
230  case Qt::ToolTipRole:
231  {
232  const int maxlines = 15;
233  const int maxlength = 80;
234 
235  QString res;
236 
237  res = scan->scanCommand()+"\n";
238  res += scan->scanDateLine()+"\n";
239 
240  QStringList hdr = scan -> header();
241  int nlines = min(hdr.size(),maxlines);
242  for (int i=0; i<nlines; i++) {
243  QString l = hdr[i];
244  if (l.size()>maxlength) {
245  res += l.mid(0,maxlength) + " ...\n";
246  } else {
247  res += l + "\n";
248  }
249  }
250  if (hdr.size()>maxlines) {
251  res += "...";
252  } else {
253  int ncols = scan->columnCount();
254  res += scan->scanColumnCountLine()+"\n";
255  QString l = scan->scanColumnNamesLine();
256  if (l.size()>maxlength) {
257  res += l.mid(0,maxlength) + " ...\n";
258  } else {
259  res += l + "\n";
260  }
261  }
262  return res;
263  }
264  break;
265 
266  case Qt::SizeHintRole:
267  switch (col) {
268  case 0:
269  return QSize(200,15);
270  break;
271 
272  case 1:
273  return QSize(20,15);
274  break;
275 
276  case 2:
277  return QSize(20,15);
278  break;
279 
280  default:
281  return QVariant();
282  }
283  break;
284 
285  default:
286 // printf("QseGraphScansModel::data(%d,%d,%s)\n", row,col, role_string(role));
287  return QVariant();
288  }
289 }
QseScan * scan(int n) const
Definition: qsedataset.cpp:70
QString scanDateLine() const
Definition: qsescan.cpp:321
int columnCount() const
Definition: qsescan.cpp:45
QString scanCommand() const
Definition: qsescan.cpp:226
QString scanColumnNamesLine() const
Definition: qsescan.cpp:335
int columnCount(const QModelIndex &parent=QModelIndex()) const
QString scanColumnCountLine() const
Definition: qsescan.cpp:328
static int min(int a, int b)
QVariant QseGraphScansModel::headerData ( int  section,
Qt::Orientation  orientation,
int  role = Qt::DisplayRole 
) const

Definition at line 293 of file qsegraphscansmodel.cpp.

294 {
295  if (orientation == Qt::Horizontal && role == Qt::DisplayRole) {
296  switch (section) {
297  case 0:
298  return "Scan";
299  break;
300  case 1:
301  return "rows";
302  break;
303  case 2:
304  return "cols";
305  break;
306  default:
307  return QVariant();
308  }
309  }
310 
311  if (orientation == Qt::Vertical && role == Qt::DisplayRole) {
312  return section;
313  }
314 
315  return QVariant();
316 }
QModelIndex QseGraphScansModel::indexOfScan ( int  n)

Definition at line 83 of file qsegraphscansmodel.cpp.

84 {
85  return index(n,0,QModelIndex());
86 }
void QseGraphScansModel::operationCompleted ( )
slot

Definition at line 31 of file qsegraphscansmodel.cpp.

References m_DataSet, m_PrevColumnCount, m_PrevRowCount, m_TableView, and scanSelected().

32 {
33  int nrows = m_DataSet -> scanCount();
34  int ncols = 3;
35 
36  if (ncols > m_PrevColumnCount) {
37  beginInsertColumns(QModelIndex(), m_PrevColumnCount, ncols-1);
38  m_PrevColumnCount = ncols;
39  endInsertColumns();
40  } else if (ncols < m_PrevColumnCount) {
41  beginRemoveColumns(QModelIndex(), ncols, m_PrevColumnCount-1);
42  m_PrevColumnCount = ncols;
43  endRemoveColumns();
44  }
45 
46  if (nrows > m_PrevRowCount) {
47  beginInsertRows(QModelIndex(), m_PrevRowCount, nrows-1);
48 
50  QItemSelectionModel *m = m_TableView -> selectionModel();
51 
53  m -> select(index(nrows-1,0),
54  QItemSelectionModel::Current | QItemSelectionModel::Rows |
55  QItemSelectionModel::Select);
56  } else {
57  QItemSelection ss(index(m_PrevRowCount-1,0),index(m_PrevRowCount-1,0));
58  ss.select(index(nrows-1,0),index(nrows-1,0));
59  m -> select(ss,
60  QItemSelectionModel::Current | QItemSelectionModel::Rows |
61  QItemSelectionModel::Toggle);
62  }
63  }
64 
65  m_PrevRowCount = nrows;
66  endInsertRows();
67  } else if (nrows < m_PrevRowCount) {
68  beginRemoveRows(QModelIndex(), nrows, m_PrevRowCount-1);
69  m_PrevRowCount = nrows;
70  endRemoveRows();
71  }
72 
73  QModelIndex topLeft = createIndex(0,0);
74  QModelIndex botRight = createIndex(m_PrevRowCount,m_PrevColumnCount);
75 
76  emit dataChanged(topLeft, botRight);
77 
78  m_TableView -> resizeRowsToContents();
79  m_TableView -> resizeColumnsToContents();
80 }
QTableView * m_TableView
int QseGraphScansModel::rowCount ( const QModelIndex &  parent = QModelIndex()) const

Definition at line 89 of file qsegraphscansmodel.cpp.

References m_DataSet.

90 {
91  if (parent.column() > 0) {
92  return 0;
93  }
94 
95  int res = m_DataSet -> scanCount();
96 
97 // if (res > m_PrevRowCount) {
98 // printf("QseGraphScansModel::rowCount(%d>%d)\n", res, m_PrevRowCount);
99 // } else if (res < m_PrevRowCount) {
100 // printf("QseGraphScansModel::rowCount(%d<%d)\n", res, m_PrevRowCount);
101 // }
102 
103 // m_PrevRowCount = res;
104 
105  return res;
106 }
bool QseGraphScansModel::scanSelected ( int  s)
private

Definition at line 23 of file qsegraphscansmodel.cpp.

References m_TableView.

Referenced by operationCompleted().

24 {
25  QItemSelectionModel *m = m_TableView -> selectionModel();
26 
27  return (m->isRowSelected(s, QModelIndex()));
28 }
QTableView * m_TableView

Member Data Documentation

QseDataSet* QseGraphScansModel::m_DataSet
private

Definition at line 34 of file qsegraphscansmodel.h.

Referenced by data(), operationCompleted(), and rowCount().

int QseGraphScansModel::m_PrevColumnCount
mutableprivate

Definition at line 37 of file qsegraphscansmodel.h.

Referenced by operationCompleted().

int QseGraphScansModel::m_PrevRowCount
mutableprivate

Definition at line 36 of file qsegraphscansmodel.h.

Referenced by operationCompleted().

QTableView* QseGraphScansModel::m_TableView
private

Definition at line 35 of file qsegraphscansmodel.h.

Referenced by operationCompleted(), and scanSelected().


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