gerritmodel.h 4.3 KB
Newer Older
hjk's avatar
hjk committed
1
/****************************************************************************
2
**
Eike Ziller's avatar
Eike Ziller committed
3
4
** Copyright (C) 2015 The Qt Company Ltd.
** Contact: http://www.qt.io/licensing
5
**
hjk's avatar
hjk committed
6
** This file is part of Qt Creator.
7
**
hjk's avatar
hjk committed
8
9
10
11
** 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
Eike Ziller's avatar
Eike Ziller committed
12
13
** a written agreement between you and The Qt Company.  For licensing terms and
** conditions see http://www.qt.io/terms-conditions.  For further information
Eike Ziller's avatar
Eike Ziller committed
14
** use the contact form at http://www.qt.io/contact-us.
15
16
**
** GNU Lesser General Public License Usage
hjk's avatar
hjk committed
17
** Alternatively, this file may be used under the terms of the GNU Lesser
Eike Ziller's avatar
Eike Ziller committed
18
19
20
21
22
23
** General Public License version 2.1 or version 3 as published by the Free
** Software Foundation and appearing in the file LICENSE.LGPLv21 and
** LICENSE.LGPLv3 included in the packaging of this file.  Please review the
** following information to ensure the GNU Lesser General Public License
** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
hjk's avatar
hjk committed
24
**
Eike Ziller's avatar
Eike Ziller committed
25
26
** In addition, as a special exception, The Qt Company gives you certain additional
** rights.  These rights are described in The Qt Company LGPL Exception
27
28
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
hjk's avatar
hjk committed
29
****************************************************************************/
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46

#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;

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

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

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

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

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

    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;
83
84
    QString dependsOnId;
    QString neededById;
85
86
87
88
89
90
91
92
    QString title;
    QString owner;
    QString email;
    QString project;
    QString branch;
    QString status;
    QDateTime lastUpdated;
    GerritPatchSet currentPatchSet;
93
    int depth;
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
119
};

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();

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

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

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

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

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

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

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

} // namespace Internal
} // namespace Gerrit

Q_DECLARE_METATYPE(Gerrit::Internal::GerritChangePtr)

#endif // GERRIT_INTERNAL_GERRITMODEL_H