improved desktop UI
[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[TextRole] = "text";
25      roles[FileRole] = "file";
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
40  QVariant uiListModel::data(const QModelIndex & index, int role) const {
41      if (index.row() < 0 || index.row() > m_uiList.count())
42          return QVariant();
43 qDebug() << "uiListModel::data" << index << role;
44      const uiListElement *ui = m_uiList[index.row()];
45
46      if (role == NameRole ||role == TextRole ) {
47          qDebug() << "uiListModel::data" << index << role << ui->name();
48          return ui->name();
49      }
50      else if (role == FileRole) {
51          qDebug() << "uiListModel::data" << index << role << ui->file();
52          return ui->file();
53      }
54      return QVariant();
55  }