gerritmodel.h 4.23 KB
Newer Older
hjk's avatar
hjk committed
1
/****************************************************************************
2
**
3
** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
hjk's avatar
hjk committed
4
** Contact: http://www.qt-project.org/legal
5
**
hjk's avatar
hjk committed
6
** This file is part of Qt Creator.
7
**
hjk's avatar
hjk committed
8
9
10
11
12
13
14
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Digia.  For licensing terms and
** conditions see http://qt.digia.com/licensing.  For further information
** use the contact form at http://qt.digia.com/contact-us.
15
16
**
** GNU Lesser General Public License Usage
hjk's avatar
hjk committed
17
18
19
20
21
22
23
24
25
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file.  Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Digia gives you certain additional
** rights.  These rights are described in the Digia Qt LGPL Exception
26
27
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
hjk's avatar
hjk committed
28
****************************************************************************/
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45

#ifndef GERRIT_INTERNAL_GERRITMODEL_H
#define GERRIT_INTERNAL_GERRITMODEL_H

#include <QStandardItemModel>
#include <QSharedPointer>
#include <QDateTime>

QT_BEGIN_NAMESPACE
class QUrl;
QT_END_NAMESPACE

namespace Gerrit {
namespace Internal {
class GerritParameters;
class QueryContext;

46
class GerritApproval {
47
public:
48
49
50
51
52
    GerritApproval() : approval(-1) {}

    QString type; // Review type
    QString description; // Type description, possibly empty
    QString reviewer;
53
    QString email;
54
55
    int approval;
};
56

57
58
class GerritPatchSet {
public:
59
    GerritPatchSet() : patchSetNumber(1) {}
60
    QString approvalsToHtml() const;
61
    QString approvalsColumn() const;
62
63
    bool hasApproval(const QString &userName) const;
    int approvalLevel() const;
64
65
66

    QString ref;
    int patchSetNumber;
67
    QList<GerritApproval> approvals;
68
69
70
71
72
};

class GerritChange
{
public:
73
    GerritChange() : number(0), depth(-1) {}
74
75
76
77
78
79
80
81

    bool isValid() const { return number && !url.isEmpty() && !project.isEmpty(); }
    QString filterString() const;
    QStringList gitFetchArguments(const QSharedPointer<GerritParameters> &p) const;

    QString url;
    int number;
    QString id;
82
83
    QString dependsOnId;
    QString neededById;
84
85
86
87
88
89
90
91
    QString title;
    QString owner;
    QString email;
    QString project;
    QString branch;
    QString status;
    QDateTime lastUpdated;
    GerritPatchSet currentPatchSet;
92
    int depth;
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
};

typedef QSharedPointer<GerritChange> GerritChangePtr;

class GerritModel : public QStandardItemModel
{
    Q_OBJECT
public:
    enum Columns {
        NumberColumn,
        TitleColumn,
        OwnerColumn,
        DateColumn,
        ProjectColumn,
        ApprovalsColumn,
        StatusColumn,
        ColumnCount
    };

    enum CustomModelRoles {
        FilterRole = Qt::UserRole + 1,
        GerritChangeRole = Qt::UserRole + 2
    };
    GerritModel(const QSharedPointer<GerritParameters> &, QObject *parent = 0);
    ~GerritModel();

119
120
    GerritChangePtr change(const QModelIndex &index) const;
    QString toHtml(const QModelIndex &index) const;
121

122
    QStandardItem *itemForId(const QString &id) const;
123
124

public slots:
Orgad Shaneh's avatar
Orgad Shaneh committed
125
    void refresh(const QString &query);
126
127
128

signals:
    void refreshStateChanged(bool isRefreshing); // For disabling the "Refresh" button.
Orgad Shaneh's avatar
Orgad Shaneh committed
129
    void queryError();
130
131
132
133
134
135
136

private slots:
    void queryFinished(const QByteArray &);
    void queriesFinished();
    void clearData();

private:
137
138
    QString dependencyHtml(const QString &header, const QString &changeId,
                           const QString &serverPrefix) const;
139
    QList<QStandardItem *> changeToRow(const GerritChangePtr &c) const;
140
141
142

    const QSharedPointer<GerritParameters> m_parameters;
    QueryContext *m_query;
143
    QString m_userName;
144
145
146
147
148
149
150
151
};

} // namespace Internal
} // namespace Gerrit

Q_DECLARE_METATYPE(Gerrit::Internal::GerritChangePtr)

#endif // GERRIT_INTERNAL_GERRITMODEL_H