File indexing completed on 2024-04-21 04:34:28

0001 #include "arduinowindowmodel.h"
0002 #include "board.h"
0003 
0004 ArduinoWindowModel::ArduinoWindowModel(QObject *parent)
0005     : QAbstractTableModel(parent)
0006 {
0007 }
0008 
0009 void ArduinoWindowModel::populate(const QVector<ArduinoWindowModelStruct> &tdb)
0010 {
0011     beginResetModel();
0012     m_db = tdb;
0013     endResetModel();
0014 }
0015 
0016 QVariant ArduinoWindowModel::data(const QModelIndex& index, int role) const
0017 {
0018     if (!index.isValid())
0019     {
0020         return QVariant();
0021     }
0022 
0023     if (role == Qt::DisplayRole)
0024     {
0025         if (index.column() == ID)
0026         {
0027             return m_db.at(index.row()).m_id;
0028         }
0029         else if (index.column() == NAME)
0030         {
0031             return m_db.at(index.row()).m_name;
0032         }
0033     }
0034 
0035     return QVariant();
0036 }
0037 
0038 ArduinoWindowModelStruct ArduinoWindowModel::getData(int index)
0039 {
0040     if (index > -1)
0041     {
0042         return m_db.at(index);
0043     }
0044     return ArduinoWindowModelStruct{QString(), QString()};
0045 }
0046 
0047 int ArduinoWindowModel::columnCount(const QModelIndex &parent) const
0048 {
0049     Q_UNUSED(parent)
0050     return COLUMNS;
0051 }
0052 
0053 int ArduinoWindowModel::rowCount(const QModelIndex &parent) const
0054 {
0055     Q_UNUSED(parent)
0056     return m_db.count();
0057 }