rock_widget_collection  0.1
Public Member Functions | List of all members
StreamAlignerModel Class Reference

Inherits QAbstractItemModel.

Public Member Functions

 StreamAlignerModel (QObject *parent=0)
 
 ~StreamAlignerModel ()
 
virtual int columnCount (const QModelIndex &parent=QModelIndex()) const
 
virtual QVariant data (const QModelIndex &index, int role=Qt::DisplayRole) const
 
virtual QModelIndex index (int row, int column, const QModelIndex &parent=QModelIndex()) const
 
virtual QModelIndex parent (const QModelIndex &child) const
 
virtual int rowCount (const QModelIndex &parent=QModelIndex()) const
 
virtual QVariant headerData (int section, Qt::Orientation orientation, int role=Qt::DisplayRole) const
 
void updateData (const aggregator::StreamAlignerStatus &status)
 

Detailed Description

Definition at line 203 of file StreamAlignerWidget.cpp.

Constructor & Destructor Documentation

◆ StreamAlignerModel()

StreamAlignerModel::StreamAlignerModel ( QObject *  parent = 0)
explicit

Definition at line 252 of file StreamAlignerWidget.cpp.

252  : QAbstractItemModel(parent)
253 {
254 }
virtual QModelIndex parent(const QModelIndex &child) const

◆ ~StreamAlignerModel()

StreamAlignerModel::~StreamAlignerModel ( )

Definition at line 221 of file StreamAlignerWidget.cpp.

222 {
223  for(std::vector<TaskRepresentation *>::const_iterator it = taskRep.begin(); it != taskRep.end(); it++)
224  {
225  delete *it;
226  }
227  taskRep.clear();
228  taskRepMap.clear();
229 }

Member Function Documentation

◆ columnCount()

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

Definition at line 276 of file StreamAlignerWidget.cpp.

277 {
278  return 6;
279 }

◆ data()

QVariant StreamAlignerModel::data ( const QModelIndex &  index,
int  role = Qt::DisplayRole 
) const
virtual

Definition at line 281 of file StreamAlignerWidget.cpp.

282 {
283  if(!index.isValid())
284  return QVariant();
285 
286  //task rep
287  if(index.internalId() == 1)
288  {
289  return taskRep[index.row()]->data(index.column(), role);
290  }
291 
292  //this index points to a stream
293  return taskRep[index.parent().row()]->data(index.row(), index.column(), role);
294 
295  return QVariant();
296 }
virtual QModelIndex index(int row, int column, const QModelIndex &parent=QModelIndex()) const

◆ headerData()

QVariant StreamAlignerModel::headerData ( int  section,
Qt::Orientation  orientation,
int  role = Qt::DisplayRole 
) const
virtual

Definition at line 256 of file StreamAlignerWidget.cpp.

257 {
258  return StreamRepresentation::headerData(section, role);
259 }
static QVariant headerData(int col, int role)

◆ index()

QModelIndex StreamAlignerModel::index ( int  row,
int  column,
const QModelIndex &  parent = QModelIndex() 
) const
virtual

Definition at line 298 of file StreamAlignerWidget.cpp.

299 {
300  if (!hasIndex(row, column, parent))
301  return QModelIndex();
302 
303  if (!parent.isValid())
304  {
305  //index to root node
306  const int taskCount = taskRep.size();
307  if(row >= taskCount)
308  return QModelIndex();
309  return createIndex(row, column, 1);
310  } else {
311  if(parent.internalId() != 1)
312  throw std::runtime_error("Expected id 1 got something else");
313 
314  if(row < taskRep[parent.row()]->getStreamCount())
315  return createIndex(row, column, (void *) taskRep[parent.row()] );
316  }
317 
318  return QModelIndex();
319 }
virtual QModelIndex parent(const QModelIndex &child) const

◆ parent()

QModelIndex StreamAlignerModel::parent ( const QModelIndex &  child) const
virtual

Definition at line 321 of file StreamAlignerWidget.cpp.

322 {
323  if(!child.isValid()) {
324  return QModelIndex();
325  }
326 
327  //top level items have no valid parents
328  if(child.internalId() == 1)
329  return QModelIndex();
330 
331  int i = 0;
332  for(std::vector<TaskRepresentation *>::const_iterator it = taskRep.begin(); it != taskRep.end(); it++) {
333  if(*it == child.internalPointer())
334  return createIndex(i, 0, 1);
335  i++;
336  }
337  return QModelIndex();
338 }

◆ rowCount()

int StreamAlignerModel::rowCount ( const QModelIndex &  parent = QModelIndex()) const
virtual

Definition at line 261 of file StreamAlignerWidget.cpp.

262 {
263  if(parent.isValid())
264  {
265  //parent is no task rep
266  if(parent.internalId() != 1)
267  return 0;
268 
269  //return stream count of task rep
270  return taskRep[parent.row()]->getStreamCount();
271  }
272 
273  return taskRep.size();
274 }
virtual QModelIndex parent(const QModelIndex &child) const

◆ updateData()

void StreamAlignerModel::updateData ( const aggregator::StreamAlignerStatus &  status)

Definition at line 231 of file StreamAlignerWidget.cpp.

232 {
233  std::string name = status.name;
234  if( name.empty() )
235  name = "<anonymous>";
236 
237  if(!taskRepMap.count(name))
238  {
239  TaskRepresentation *tp = new TaskRepresentation( name );
240  taskRepMap[name] = tp;
241  taskRep.push_back(tp);
242  emit layoutChanged();
243  }
244 
245  taskRepMap[name]->updateData(status);
246 
247  //inform rest of the world that we got new data
248  if(!taskRep.empty())
249  emit dataChanged(createIndex(0,0,0), createIndex(taskRep.size()-1, 5, 0));
250 }

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