aboutsummaryrefslogtreecommitdiffstats
path: root/examples/Tutorial/NameList.cs
blob: 43dafa9f55ae5cadfc075af4f131ad6db4577d44 (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
/***************************************************************************************************
 Copyright (C) 2025 The Qt Company Ltd.
 SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
***************************************************************************************************/
using Qt.DotNet;

namespace Tutorial
{
    public class NameList : ListModel<string>
    {
        private List<string> Names { get; } = new();

        public void Add(string name)
        {
            BeginInsertItems(Names.Count, Names.Count);
            Names.Add(name);
            EndInsertItems();
        }

        public override string Data(int index)
        {
            if (index >= Names.Count)
                return null;
            return Names[index];
        }

        public override int ItemCount() => Names.Count;
    }
}