--- /dev/null
+#include "uilistelement.h"
+
+uiListElement::uiListElement(QString name,QString file,QObject *parent): QObject(parent)
+{
+ m_name=name;
+ m_file=file;
+}
+/*
+uiListElement::uiListElement(const uiListElement &ui)
+{
+ m_name=ui.m_name;
+ m_file=ui.m_file;
+}
+*/
+uiListElement::uiListElement(QObject *parent): QObject(parent)
+{
+}
+
+uiListModel::uiListModel(QObject *parent)
+ : QAbstractListModel(parent)
+ {
+ QHash<int, QByteArray> roles;
+ roles[NameRole] = "name";
+ roles[FileRole] = "file";
+ roles[ModelDataRole] = "modelData";
+ setRoleNames(roles);
+ }
+
+ void uiListModel::addUI(uiListElement *ui)
+ {
+ beginInsertRows(QModelIndex(), rowCount(), rowCount());
+ m_uiList.append(ui);
+ endInsertRows();
+ }
+
+ int uiListModel::rowCount(const QModelIndex & parent) const {
+ return m_uiList.count();
+ }
+ int uiListModel::count()
+{
+ qDebug() <<"Count:" << m_uiList.count();
+ return m_uiList.count();
+ }
+
+ QVariant uiListModel::data(const QModelIndex & index, int role) const {
+ if (index.row() < 0 || index.row() > m_uiList.count())
+ return QVariant();
+
+ const uiListElement *ui = m_uiList[index.row()];
+ if (role == NameRole)
+ return ui->name();
+ else if (role == FileRole)
+ return ui->file();
+ else if (role == ModelDataRole)
+ return ui->modelData();
+ return QVariant();
+ }
--- /dev/null
+#ifndef UILISTELEMENT_H
+#define UILISTELEMENT_H
+
+#include <QObject>
+#include <QString>
+#include <QAbstractListModel>
+#include <QStringList>
+#include <QDebug>
+
+class uiListElement : public QObject
+{
+ Q_OBJECT
+public:
+ Q_PROPERTY(QString name READ name WRITE setName);
+ Q_PROPERTY(QString file READ file WRITE setFile);
+ QString name() const { return m_name;} ; void setName(QString val) { m_name=val;};
+ QString modelData() const { return m_name;} ; void setModelData(QString val) { m_name=val;};
+ QString file() const { return m_file;} ; void setFile(QString val) { m_file=val;};
+
+ explicit uiListElement(QObject *parent = 0);
+ // explicit uiListElement(const uiListElement &ui);
+ explicit uiListElement(QString name,QString fileName,QObject *parent = 0);
+signals:
+
+public slots:
+
+private:
+QString m_name;
+QString m_file;
+
+};
+
+Q_DECLARE_METATYPE(uiListElement*)
+
+class uiListModel : public QAbstractListModel
+{
+ Q_OBJECT
+public:
+ enum uiRoles {
+ NameRole = Qt::UserRole + 1,
+ FileRole,
+ ModelDataRole
+ };
+
+ uiListModel(QObject *parent = 0);
+
+ void addUI(uiListElement *ui);
+
+ int rowCount(const QModelIndex & parent = QModelIndex()) const;
+ Q_INVOKABLE int count();
+ Q_INVOKABLE int roles() { return roleNames().size(); }
+
+ Q_INVOKABLE QObject * get(int index) const { return m_uiList[index];};
+ QVariant data(const QModelIndex & index, int role = Qt::DisplayRole) const;
+
+private:
+ QList<uiListElement*> m_uiList;
+};
+#endif // UILISTELEMENT_H