gerritmodel.h 4.54 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
};

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,
115 116
        GerritChangeRole = Qt::UserRole + 2,
        SortRole = Qt::UserRole + 3
117 118 119 120
    };
    GerritModel(const QSharedPointer<GerritParameters> &, QObject *parent = 0);
    ~GerritModel();

Orgad Shaneh's avatar
Orgad Shaneh committed
121
    QVariant data(const QModelIndex &index, int role) const override;
122

123 124
    GerritChangePtr change(const QModelIndex &index) const;
    QString toHtml(const QModelIndex &index) const;
125

126
    QStandardItem *itemForId(const QString &id) const;
127

128 129 130
    enum QueryState { Idle, Running, Ok, Error };
    QueryState state() const { return m_state; }

Orgad Shaneh's avatar
Orgad Shaneh committed
131
    void refresh(const QString &query);
132 133 134

signals:
    void refreshStateChanged(bool isRefreshing); // For disabling the "Refresh" button.
135
    void stateChanged();
136

137
private:
138 139 140 141
    void queryFinished(const QByteArray &);
    void queriesFinished();
    void clearData();

142 143
    void setState(QueryState s);

144 145
    QString dependencyHtml(const QString &header, const QString &changeId,
                           const QString &serverPrefix) const;
146
    QList<QStandardItem *> changeToRow(const GerritChangePtr &c) const;
147 148

    const QSharedPointer<GerritParameters> m_parameters;
149 150
    QueryContext *m_query = 0;
    QueryState m_state = Idle;
151
    QString m_userName;
152 153 154 155 156 157 158 159
};

} // namespace Internal
} // namespace Gerrit

Q_DECLARE_METATYPE(Gerrit::Internal::GerritChangePtr)

#endif // GERRIT_INTERNAL_GERRITMODEL_H