summaryrefslogtreecommitdiff
path: root/examples/multimedia/screencapture/screenlistmodel.cpp
blob: 6a3a1efd773d55c3662628adb17ea9c7549d1714 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
// Copyright (C) 2022 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause

#include "screenlistmodel.h"

#include <QScreen>

ScreenListModel::ScreenListModel(const QList<QScreen *> &data, QObject *parent) :
      QAbstractListModel(parent),
      screenList(data)
{
}

int ScreenListModel::rowCount(const QModelIndex &) const
{
    return screenList.size();
}

QVariant ScreenListModel::data(const QModelIndex &index, int role) const
{
    Q_ASSERT(index.isValid());
    Q_ASSERT(index.row() <= screenList.size());

    if (role == Qt::DisplayRole) {
        auto screen = screenList.at(index.row());
        return QString("%1: %2").arg(screen->metaObject()->className(),
                                     screen->name());
    }

    return {};
}

QScreen *ScreenListModel::screen(const QModelIndex &index) const
{
    return screenList.at(index.row());
}

#include "moc_screenlistmodel.cpp"