1 /**************************************************************************** 2 ** 3 ** Copyright (C) 2016 The Qt Company Ltd. 4 ** Contact: https://www.qt.io/licensing/ 5 ** 6 ** This file is part of Qt Creator. 7 ** 8 ** Commercial License Usage 9 ** Licensees holding valid commercial Qt licenses may use this file in 10 ** accordance with the commercial license agreement provided with the 11 ** Software or, alternatively, in accordance with the terms contained in 12 ** a written agreement between you and The Qt Company. For licensing terms 13 ** and conditions see https://www.qt.io/terms-conditions. For further 14 ** information use the contact form at https://www.qt.io/contact-us. 15 ** 16 ** GNU General Public License Usage 17 ** Alternatively, this file may be used under the terms of the GNU 18 ** General Public License version 3 as published by the Free Software 19 ** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT 20 ** included in the packaging of this file. Please review the following 21 ** information to ensure the GNU General Public License requirements will 22 ** be met: https://www.gnu.org/licenses/gpl-3.0.html. 23 ** 24 ****************************************************************************/ 25 26 #pragma once 27 28 #include "gerritparameters.h" 29 #include "gerritserver.h" 30 31 #include <QStandardItemModel> 32 #include <QSharedPointer> 33 #include <QDateTime> 34 35 namespace Gerrit { 36 namespace Internal { 37 class QueryContext; 38 39 class GerritApproval { 40 public: 41 QString type; // Review type 42 QString description; // Type description, possibly empty 43 GerritUser reviewer; 44 int approval = -1; 45 }; 46 47 class GerritPatchSet { 48 public: 49 QString approvalsToHtml() const; 50 QString approvalsColumn() const; 51 bool hasApproval(const GerritUser &user) const; 52 int approvalLevel() const; 53 54 QString url; 55 QString ref; 56 int patchSetNumber = 1; 57 QList<GerritApproval> approvals; 58 }; 59 60 class GerritChange 61 { 62 public: isValid()63 bool isValid() const { return number && !url.isEmpty() && !project.isEmpty(); } 64 QString filterString() const; 65 QStringList gitFetchArguments(const GerritServer &server) const; 66 QString fullTitle() const; // title with potential "Draft" specifier 67 68 QString url; 69 int number = 0; 70 int dependsOnNumber = 0; 71 int neededByNumber = 0; 72 QString title; 73 GerritUser owner; 74 QString project; 75 QString branch; 76 QString status; 77 QDateTime lastUpdated; 78 GerritPatchSet currentPatchSet; 79 int depth = -1; 80 }; 81 82 using GerritChangePtr = QSharedPointer<GerritChange>; 83 84 class GerritModel : public QStandardItemModel 85 { 86 Q_OBJECT 87 public: 88 enum Columns { 89 NumberColumn, 90 TitleColumn, 91 OwnerColumn, 92 DateColumn, 93 ProjectColumn, 94 ApprovalsColumn, 95 StatusColumn, 96 ColumnCount 97 }; 98 99 enum CustomModelRoles { 100 FilterRole = Qt::UserRole + 1, 101 GerritChangeRole = Qt::UserRole + 2, 102 SortRole = Qt::UserRole + 3 103 }; 104 GerritModel(const QSharedPointer<GerritParameters> &, QObject *parent = nullptr); 105 ~GerritModel() override; 106 107 QVariant data(const QModelIndex &index, int role) const override; 108 109 GerritChangePtr change(const QModelIndex &index) const; 110 QString toHtml(const QModelIndex &index) const; 111 112 QStandardItem *itemForNumber(int number) const; server()113 QSharedPointer<GerritServer> server() const { return m_server; } 114 115 enum QueryState { Idle, Running, Ok, Error }; state()116 QueryState state() const { return m_state; } 117 118 void refresh(const QSharedPointer<GerritServer> &server, const QString &query); 119 120 signals: 121 void refreshStateChanged(bool isRefreshing); // For disabling the "Refresh" button. 122 void stateChanged(); 123 void errorText(const QString &text); 124 125 private: 126 void resultRetrieved(const QByteArray &); 127 void queryFinished(); 128 void clearData(); 129 130 void setState(QueryState s); 131 132 QString dependencyHtml(const QString &header, const int changeNumber, 133 const QString &serverPrefix) const; 134 QList<QStandardItem *> changeToRow(const GerritChangePtr &c) const; 135 136 const QSharedPointer<GerritParameters> m_parameters; 137 QSharedPointer<GerritServer> m_server; 138 QueryContext *m_query = nullptr; 139 QueryState m_state = Idle; 140 }; 141 142 } // namespace Internal 143 } // namespace Gerrit 144 145 Q_DECLARE_METATYPE(Gerrit::Internal::GerritChangePtr) 146