/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * Copyright (C) 2017 Simon Stuerz * * * * This file is part of guh-control * * * * This library is free software; you can redistribute it and/or * * modify it under the terms of the GNU Lesser General Public * * License as published by the Free Software Foundation; either * * version 2.1 of the License, or (at your option) any later version. * * * * This library is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * * Lesser General Public License for more details. * * * * You should have received a copy of the GNU Lesser General Public * * License along with this library; If not, see * * . * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ #include "actiontypes.h" ActionTypes::ActionTypes(QObject *parent) : QAbstractListModel(parent) { } QList ActionTypes::actionTypes() { return m_actionTypes; } int ActionTypes::count() const { return m_actionTypes.count(); } ActionType *ActionTypes::get(int index) const { return m_actionTypes.at(index); } ActionType *ActionTypes::getActionType(const QUuid &actionTypeId) const { foreach (ActionType *actionType, m_actionTypes) { if (actionType->id() == actionTypeId) { return actionType; } } return 0; } int ActionTypes::rowCount(const QModelIndex &parent) const { Q_UNUSED(parent) return m_actionTypes.count(); } QVariant ActionTypes::data(const QModelIndex &index, int role) const { if (index.row() < 0 || index.row() >= m_actionTypes.count()) return QVariant(); ActionType *actionType = m_actionTypes.at(index.row()); if (role == NameRole) { return actionType->name(); } else if (role == IdRole) { return actionType->id().toString(); } return QVariant(); } void ActionTypes::addActionType(ActionType *actionType) { beginInsertRows(QModelIndex(), m_actionTypes.count(), m_actionTypes.count()); //qDebug() << "ActionTypes: loaded actionType" << actionType->name(); m_actionTypes.append(actionType); endInsertRows(); } void ActionTypes::clearModel() { beginResetModel(); m_actionTypes.clear(); endResetModel(); } QHash ActionTypes::roleNames() const { QHash roles; roles[NameRole] = "name"; roles[IdRole] = "id"; return roles; }