1 | #pragma once |
2 | |
3 | /**************************************************************************************** |
4 | ** GitQlient is an application to manage and operate one or several Git repositories. With |
5 | ** GitQlient you will be able to add commits, branches and manage all the options Git provides. |
6 | ** Copyright (C) 2021 Francesc Martinez |
7 | ** |
8 | ** LinkedIn: www.linkedin.com/in/cescmm/ |
9 | ** Web: www.francescmm.com |
10 | ** |
11 | ** This program is free software; you can redistribute it and/or |
12 | ** modify it under the terms of the GNU Lesser General Public |
13 | ** License as published by the Free Software Foundation; either |
14 | ** version 2 of the License, or (at your option) any later version. |
15 | ** |
16 | ** This program is distributed in the hope that it will be useful, |
17 | ** but WITHOUT ANY WARRANTY; without even the implied warranty of |
18 | ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
19 | ** Lesser General Public License for more details. |
20 | ** |
21 | ** You should have received a copy of the GNU Lesser General Public |
22 | ** License along with this library; if not, write to the Free Software |
23 | ** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
24 | ***************************************************************************************/ |
25 | |
26 | #include <QTreeView> |
27 | |
28 | class GitCache; |
29 | class GitBase; |
30 | class CommitHistoryModel; |
31 | class ShaFilterProxyModel; |
32 | class GitServerCache; |
33 | class GitQlientSettings; |
34 | |
35 | /** |
36 | * @brief The CommitHistoryView is the class that represents the View in a MVC pattern. It shows the data provided by |
37 | * the model regarding the repository graph and the commit information. |
38 | * |
39 | * @class CommitHistoryView CommitHistoryView.h "CommitHistoryView.h" |
40 | */ |
41 | class CommitHistoryView : public QTreeView |
42 | { |
43 | Q_OBJECT |
44 | |
45 | signals: |
46 | void fullReload(); |
47 | void referencesReload(); |
48 | void logReload(); |
49 | |
50 | /*! |
51 | \brief Signal triggered when the user wants to open the diff of a commit compared to its parent. |
52 | |
53 | \param sha The SHA to diff. |
54 | */ |
55 | void signalOpenDiff(const QString &sha); |
56 | /*! |
57 | \brief Signal triggered when the user whants to diff the shas in the list. This signal is only emited if the user |
58 | selected two SHAs. |
59 | |
60 | \param sha The shas to diff between. |
61 | */ |
62 | void signalOpenCompareDiff(const QStringList &sha); |
63 | /*! |
64 | \brief Signal triggered when the user wants to amend a commit. |
65 | |
66 | \param sha The SHA of the commit to amend. |
67 | */ |
68 | void signalAmendCommit(const QString &sha); |
69 | /*! |
70 | \brief Signal triggered when a merge has been requested. Since it involves a lot of changes at UI level this action |
71 | is not performed here. |
72 | |
73 | \param origin The branch to merge from. |
74 | \param destination The branch to merge into. |
75 | */ |
76 | void signalMergeRequired(const QString &origin, const QString &destination); |
77 | |
78 | /** |
79 | * @brief Signal triggered when a merge with squash behavior has been requested. Since it involves a lot of changes |
80 | * at UI level this action is not performed here. |
81 | * |
82 | * @param origin The branch to merge from. |
83 | * @param destination The branch to merge into. |
84 | */ |
85 | void mergeSqushRequested(const QString &origin, const QString &destination); |
86 | |
87 | /*! |
88 | * \brief signalConflict Signal triggered when trying to cherry-pick or pull and a conflict happens. |
89 | */ |
90 | void signalCherryPickConflict(const QStringList &pendingShas); |
91 | /*! |
92 | * \brief signalPullConflict Signal triggered when trying to pull and a conflict happens. |
93 | */ |
94 | void signalPullConflict(); |
95 | /** |
96 | * @brief showPrDetailedView Signal that makes the view change to the Pull Request detailed view |
97 | * @param pr The pull request number to show. |
98 | */ |
99 | void showPrDetailedView(int pr); |
100 | |
101 | public: |
102 | /** |
103 | * @brief Default constructor. |
104 | * |
105 | * @param cache The internal cache for the current repository. |
106 | * @param git The git object to perform Git commands. |
107 | * @param parent The parent widget if needed. |
108 | */ |
109 | explicit CommitHistoryView(const QSharedPointer<GitCache> &cache, const QSharedPointer<GitBase> &git, |
110 | const QSharedPointer<GitQlientSettings> &settings, |
111 | const QSharedPointer<GitServerCache> &gitServerCache, QWidget *parent = nullptr); |
112 | /** |
113 | * @brief Destructor. |
114 | */ |
115 | ~CommitHistoryView() override; |
116 | |
117 | /** |
118 | * @brief Sets the model that will be used by the view. |
119 | * |
120 | * @param model Model to set into the view. |
121 | */ |
122 | void setModel(QAbstractItemModel *model) override; |
123 | /** |
124 | * @brief Returns the list of SHAs that the user has selected in the view. |
125 | * |
126 | * @return QStringList Gets the selected SHA list. |
127 | */ |
128 | QStringList getSelectedShaList() const; |
129 | /** |
130 | * @brief If the view has a filter active this method tells the filter which SHAs are going to be shown. |
131 | * |
132 | * @param shaList List of SHA to pass to the filter. |
133 | */ |
134 | void filterBySha(const QStringList &shaList); |
135 | /** |
136 | * @brief Activates/deactivates filtering in the view. |
137 | * |
138 | * @param activate True to activate the filter. Otherwise false, |
139 | */ |
140 | void activateFilter(bool activate) { mIsFiltering = activate; } |
141 | /** |
142 | * @brief Tells if the user has any active filter. |
143 | * |
144 | * @return bool Returns true if the widget is actively filtering. Otherwise, false. |
145 | */ |
146 | bool hasActiveFilter() const { return mIsFiltering; } |
147 | |
148 | /** |
149 | * @brief Clears any selection or data in the view. |
150 | */ |
151 | void clear(); |
152 | /** |
153 | * @brief Puts the focus (and selects) the given SHA. |
154 | * |
155 | * @param goToSha The SHA to select. |
156 | */ |
157 | void focusOnCommit(const QString &goToSha); |
158 | /** |
159 | * @brief Gets the current selected SHA. |
160 | * |
161 | * @return QString Returns the current selected SHA. |
162 | */ |
163 | QString getCurrentSha() const { return mCurrentSha; } |
164 | /** |
165 | * @brief Overridden function to make it public. Useful to retrieve the indexes when a search is done. |
166 | * |
167 | * @return QModelIndexList The list of selected indexes. |
168 | */ |
169 | QModelIndexList selectedIndexes() const override; |
170 | |
171 | private: |
172 | QSharedPointer<GitCache> mCache; |
173 | QSharedPointer<GitBase> mGit; |
174 | QSharedPointer<GitQlientSettings> mSettings; |
175 | QSharedPointer<GitServerCache> mGitServerCache; |
176 | CommitHistoryModel *mCommitHistoryModel = nullptr; |
177 | ShaFilterProxyModel *mProxyModel = nullptr; |
178 | bool mIsFiltering = false; |
179 | QString mCurrentSha; |
180 | |
181 | /** |
182 | * @brief Shows the context menu for the CommitHistoryView. |
183 | * |
184 | * @param p The point where the context menu will be shown. |
185 | */ |
186 | void (const QPoint &p); |
187 | /** |
188 | * @brief Configures the tree view and how the columns look like. |
189 | * |
190 | * @fn setupGeometry |
191 | */ |
192 | void setupGeometry(); |
193 | /** |
194 | * @brief Stores the new selected SHA. |
195 | * |
196 | * @param index The index that changed. Used to retrieve the row. |
197 | * @param parent The parent of the index. Not used. |
198 | */ |
199 | void currentChanged(const QModelIndex &index, const QModelIndex &parent) override; |
200 | /** |
201 | * @brief refreshView Refreshes the view. |
202 | */ |
203 | void refreshView(); |
204 | /** |
205 | * @brief onHeaderContextMenu Shows the context menu for the header of the tree view. |
206 | * @param pos The position of the cursor that will be used to show the menu. |
207 | */ |
208 | void (const QPoint &pos); |
209 | }; |
210 | |