File indexing completed on 2024-05-26 04:40:48
0001 /* 0002 SPDX-FileCopyrightText: 2020 Friedrich W. H. Kossebau <kossebau@kde.org> 0003 0004 SPDX-License-Identifier: LGPL-2.0-or-later 0005 */ 0006 0007 #include "sessionlistmodel.h" 0008 0009 // KDevelopSessionsWatch 0010 #include <kdevelopsessionswatch.h> 0011 0012 SessionListModel::SessionListModel(QObject *parent) 0013 : QAbstractListModel(parent) 0014 { 0015 KDevelopSessionsWatch::registerObserver(this); 0016 } 0017 0018 SessionListModel::~SessionListModel() 0019 { 0020 KDevelopSessionsWatch::unregisterObserver(this); 0021 } 0022 0023 0024 QHash<int, QByteArray> SessionListModel::roleNames() const 0025 { 0026 auto roleNames = QAbstractListModel::roleNames(); 0027 roleNames.insert(SessionIdRole, QByteArrayLiteral("sessionId")); 0028 return roleNames; 0029 } 0030 0031 int SessionListModel::rowCount(const QModelIndex &index) const 0032 { 0033 if (!index.isValid()) { 0034 return m_sessionDataList.size(); 0035 } 0036 0037 return 0; 0038 } 0039 0040 QVariant SessionListModel::data(const QModelIndex &index, int role) const 0041 { 0042 if (!index.isValid() || index.row() >= m_sessionDataList.size()) { 0043 return QVariant(); 0044 } 0045 0046 const KDevelopSessionData sessionData = m_sessionDataList.at(index.row()); 0047 0048 switch (role) { 0049 case Qt::DisplayRole: { 0050 return sessionData.description; 0051 case SessionIdRole: 0052 return sessionData.id; 0053 } 0054 } 0055 0056 return QVariant(); 0057 } 0058 0059 void SessionListModel::setSessionDataList(const QVector<KDevelopSessionData>& sessionDataList) 0060 { 0061 beginResetModel(); 0062 m_sessionDataList = sessionDataList; 0063 endResetModel(); 0064 } 0065 0066 0067 void SessionListModel::openSession(const QString& sessionId) 0068 { 0069 KDevelopSessionsWatch::openSession(sessionId); 0070 } 0071 0072 #include "moc_sessionlistmodel.cpp"