7611cd360c4fa15aa85b8f8c2046813a896ffd96
[mardrone] / mardrone / uilistelement.cpp
1 #include "uilistelement.h"
2
3 uiListElement::uiListElement(QString name,QString file,QObject *parent): QObject(parent)
4 {
5     m_name=name;
6     m_file=file;
7 }
8 /*
9 uiListElement::uiListElement(const uiListElement &ui)
10 {
11     m_name=ui.m_name;
12     m_file=ui.m_file;
13 }
14 */
15 uiListElement::uiListElement(QObject *parent): QObject(parent)
16 {
17 }
18
19 uiListModel::uiListModel(QObject *parent)
20      : QAbstractListModel(parent)
21  {
22      QHash<int, QByteArray> roles;
23      roles[NameRole] = "name";
24      roles[FileRole] = "file";
25      roles[ModelDataRole] = "modelData";
26      setRoleNames(roles);
27  }
28
29  void uiListModel::addUI(uiListElement *ui)
30  {
31      beginInsertRows(QModelIndex(), rowCount(), rowCount());
32      m_uiList.append(ui);
33      endInsertRows();
34  }
35
36  int uiListModel::rowCount(const QModelIndex & parent) const {
37      return m_uiList.count();
38  }
39  int uiListModel::count()
40 {
41      qDebug() <<"Count:" << m_uiList.count();
42      return m_uiList.count();
43  }
44
45  QVariant uiListModel::data(const QModelIndex & index, int role) const {
46      if (index.row() < 0 || index.row() > m_uiList.count())
47          return QVariant();
48
49      const uiListElement *ui = m_uiList[index.row()];
50      if (role == NameRole)
51          return ui->name();
52      else if (role == FileRole)
53          return ui->file();
54      else if (role == ModelDataRole)
55          return ui->modelData();
56      return QVariant();
57  }