Purpose

rbreviewslistmodel.cpp
1/*
2 SPDX-FileCopyrightText: 2015 Aleix Pol Gonzalez <aleixpol@kde.org>
3
4 SPDX-License-Identifier: LGPL-2.0-or-later
5*/
6
7#include "rbreviewslistmodel.h"
8#include "reviewboardjobs.h"
9
10ReviewsListModel::ReviewsListModel(QObject *parent)
11 : QAbstractListModel(parent)
12{
13 refresh();
14}
15
16void ReviewsListModel::refresh()
17{
18 if (m_server.isEmpty() || m_repository.isEmpty()) {
20 m_values.clear();
22 return;
23 }
24
25 ReviewBoard::ReviewListRequest *repo = new ReviewBoard::ReviewListRequest(m_server, m_username, m_status, this);
26 connect(repo, &ReviewBoard::ReviewListRequest::finished, this, &ReviewsListModel::receivedReviews);
27 repo->start();
28}
29
30void ReviewsListModel::receivedReviews(KJob *job)
31{
32 if (job->error() != 0) {
33 qWarning() << "error review list" << job->errorString();
34
36 m_values.clear();
38 return;
39 }
40
41 const QVariantList revs = dynamic_cast<ReviewBoard::ReviewListRequest *>(job)->reviews();
43 m_values.clear();
44 for (const QVariant &review : revs) {
45 QVariantMap reviewMap = review.toMap();
46 QVariantMap repoMap = reviewMap[QStringLiteral("links")].toMap()[QStringLiteral("repository")].toMap();
47 if (repoMap[QStringLiteral("title")].toString() == m_repository) {
48 m_values += Value{reviewMap[QStringLiteral("summary")], reviewMap[QStringLiteral("id")]};
49 }
50 }
52}
53
54QVariant ReviewsListModel::data(const QModelIndex &idx, int role) const
55{
56 if (!idx.isValid() || idx.column() != 0 || idx.row() >= m_values.size()) {
57 return QVariant();
58 }
59
60 switch (role) {
61 case Qt::DisplayRole:
62 return m_values[idx.row()].summary;
63 case Qt::ToolTipRole:
64 return m_values[idx.row()].id;
65 }
66 return QVariant();
67}
68
69int ReviewsListModel::rowCount(const QModelIndex &parent) const
70{
71 return parent.isValid() ? 0 : m_values.count();
72}
73
74QVariant ReviewsListModel::get(int row, const QByteArray &role)
75{
76 return index(row, 0).data(roleNames().key(role));
77}
78
79#include "moc_rbreviewslistmodel.cpp"
virtual QString errorString() const
int error() const
void finished(KJob *job)
char * toString(const EngineQuery &query)
virtual QHash< int, QByteArray > roleNames() const const
virtual QModelIndex index(int row, int column, const QModelIndex &parent) const const override
void clear()
qsizetype count() const const
qsizetype size() const const
int column() const const
QVariant data(int role) const const
bool isValid() const const
int row() const const
QMetaObject::Connection connect(const QObject *sender, PointerToMemberFunction signal, Functor functor)
QObject * parent() const const
bool isEmpty() const const
DisplayRole
bool isEmpty() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Sat Dec 21 2024 17:03:06 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.