File indexing completed on 2024-06-09 09:10:17

0001 // SPDX-FileCopyrightText: 2021 Devin Lin <devin@kde.org>
0002 // SPDX-License-Identifier: GPL-2.0-or-later
0003 
0004 #pragma once
0005 
0006 #include <QAbstractListModel>
0007 #include <QObject>
0008 
0009 class TerminalTabModel : public QAbstractListModel
0010 {
0011     Q_OBJECT
0012 
0013 public:
0014     explicit TerminalTabModel(QObject *parent = nullptr);
0015 
0016     static TerminalTabModel *self()
0017     {
0018         static TerminalTabModel *singleton = new TerminalTabModel();
0019         return singleton;
0020     }
0021 
0022     enum { NameRole = Qt::DisplayRole };
0023 
0024     int rowCount(const QModelIndex &parent) const override;
0025     QVariant data(const QModelIndex &index, int role) const override;
0026     bool setData(const QModelIndex &index, const QVariant &value, int role) override;
0027     Qt::ItemFlags flags(const QModelIndex &index) const override;
0028     QHash<int, QByteArray> roleNames() const override;
0029 
0030     Q_INVOKABLE void newTab();
0031     Q_INVOKABLE void removeTab(int index);
0032 
0033 private:
0034     int m_indexCounter;
0035     QList<QString> m_tabNames;
0036 };