/*
* Copyright (C) 2015 Canonical, Ltd.
*
* This program is free software: you can redistribute it and/or modify it under
* the terms of the GNU Lesser General Public License version 3, as published by
* the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranties of MERCHANTABILITY,
* SATISFACTORY QUALITY, 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 program. If not, see .
*/
#include "screens.h"
// Qt
#include
#include
#include
Q_DECLARE_METATYPE(QScreen*)
Screens::Screens(QObject *parent) :
QAbstractListModel(parent)
{
// start with one screen attached
m_screenList.append(new Screen());
}
Screens::~Screens() noexcept
{
qDeleteAll(m_screenList);
m_screenList.clear();
}
QHash Screens::roleNames() const
{
QHash roles;
roles[ScreenRole] = "screen";
roles[OutputTypeRole] = "outputType";
return roles;
}
QVariant Screens::data(const QModelIndex &index, int role) const
{
if (!index.isValid() || index.row() >= m_screenList.size()) {
return QVariant();
}
switch(role) {
case ScreenRole:
return QVariant::fromValue(m_screenList.at(index.row())->qScreen);
case OutputTypeRole:
return m_screenList.at(index.row())->outputTypes;
}
return QVariant();
}
int Screens::rowCount(const QModelIndex &) const
{
return count();
}
int Screens::count() const
{
return m_screenList.size();
}