HAL
gatelibrary_table_model.cpp
Go to the documentation of this file.
2 
3 #include "gui/gui_globals.h"
8 
9 #include <QDateTime>
10 
11 namespace hal
12 {
13 
15  {
16  }
17 
19  {
20  Q_UNUSED(parent)
21 
22  return mEntries.size();
23  }
24 
26  {
27  Q_UNUSED(parent)
28 
29  return 2;
30  }
31 
32  QVariant GatelibraryTableModel::data(const QModelIndex& index, int role) const
33  {
34  if(index.row() < mEntries.size() && index.column() < columnCount())
35  {
36  if (role == Qt::DisplayRole)
37  {
38  switch (index.column())
39  {
40  case 0: return QString::fromStdString(mEntries[index.row()]->get_name());
41  case 1: return mEntries[index.row()]->get_id();
42 
43  }
44  }
45  else if (role == Qt::TextAlignmentRole)
46  {
47  switch (index.column())
48  {
49  case 0:
51  case 1:
53  default:
54  return QVariant(Qt::AlignCenter);
55  }
56  }
57  }
58 
59  return QVariant();
60  }
61 
62  QVariant GatelibraryTableModel::headerData(int section, Qt::Orientation orientation, int role) const
63  {
64  if(role != Qt::DisplayRole)
65  return QVariant();
66 
67  if(orientation == Qt::Horizontal)
68  {
69  switch(section)
70  {
71  case 0: return "Name";
72  case 1: return "ID";
73  default: return QVariant();
74  }
75  }
76 
77  return section + 1;
78  }
79 
81  {
83  mEntries.clear();
84  endResetModel();
85  }
86 
87 
89  {
90 
91  if (!g)
92  return;
94  mEntries.clear();
95 
96  for (auto elem : g->get_gate_types())
97  {
98  mEntries.append(elem.second);
99  }
100 
101  std::sort(mEntries.begin(), mEntries.end(), [](GateType* a, GateType* b)
102  {
103  return a->get_name() < b->get_name();
104  });
105 
106  endResetModel();
107  }
108 
110  {
111  if(index >= mEntries.size())
112  return nullptr;
113 
114  return mEntries[index];
115  }
116 
117 }
void loadFile(const GateLibrary *g)
QVariant headerData(int section, Qt::Orientation orientation, int role) const override
GateType * getGateTypeAtIndex(int index)
GatelibraryTableModel(QObject *parent=nullptr)
int columnCount(const QModelIndex &parent=QModelIndex()) const override
int rowCount(const QModelIndex &parent=QModelIndex()) const override
QVariant data(const QModelIndex &index, int role) const override
virtual QModelIndex index(int row, int column, const QModelIndex &parent) const const override
int column() const const
int row() const const
QObject * parent() const const
QString fromStdString(const std::string &str)
AlignLeft
DisplayRole
Orientation