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 <QFrame>
27
28class BranchTreeWidget;
29class QListWidget;
30class QListWidgetItem;
31class QLabel;
32class GitBase;
33class GitTags;
34class GitCache;
35class QPushButton;
36class BranchesWidgetMinimal;
37class BranchesViewDelegate;
38class QTreeWidget;
39class QTreeWidgetItem;
40class RefTreeWidget;
41
42/*!
43 \brief BranchesWidget is the widget that creates the layout that contains all the widgets related with the display of
44 branch information, such as BranchTreeWidget but also the widgets that show information for the tags, submodules and
45 stashes.
46
47*/
48class BranchesWidget : public QFrame
49{
50 Q_OBJECT
51
52signals:
53 void fullReload();
54 void logReload();
55
56 /**
57 * @brief panelsVisibilityChanged Signal triggered whenever the visibility of the panels in the BranchesWidget
58 * changes.
59 */
60 void panelsVisibilityChanged();
61 /*!
62 \brief Signal triggered when the user selects a commit via branch or tag selection.
63
64 \param sha The selected sha.
65 */
66 void signalSelectCommit(const QString &sha);
67 /*!
68 \brief Signal triggered when a the user wants to open a submodule as a new repository view. This signal will lead
69 GitQlient to open a new tab in the general UI view and change the current repository view to that one.
70
71 \param submoduleName The module name.
72 */
73 void signalOpenSubmodule(const QString &submoduleName);
74 /*!
75 \brief Signal triggered when a merge is required.
76
77 \param currentBranch The current branch.
78 \param fromBranch The branch to merge into the current one.
79 */
80 void signalMergeRequired(const QString &currentBranch, const QString &fromBranch);
81 /*!
82 * \brief signalPullConflict Signal triggered when trying to pull and a conflict happens.
83 */
84 void signalPullConflict();
85 /**
86 * @brief minimalViewStateChanged Signal triggered when the minimal view is active.
87 */
88 void minimalViewStateChanged(bool isActive);
89
90 /**
91 * @brief Signal triggered when a merge with squash behavior has been requested. Since it involves a lot of changes
92 * at UI level this action is not performed here.
93 *
94 * @param origin The branch to merge from.
95 * @param destination The branch to merge into.
96 */
97 void mergeSqushRequested(const QString &origin, const QString &destination);
98
99public:
100 /*!
101 \brief Default constructor.
102
103 \param git The git object to perform Git commands.
104 \param parent The parent widget if needed.
105 */
106 explicit BranchesWidget(const QSharedPointer<GitCache> &cache, const QSharedPointer<GitBase> &git,
107 QWidget *parent = nullptr);
108
109 /**
110 * @brief Destructor;
111 */
112 ~BranchesWidget();
113
114 /**
115 * @brief isMinimalViewActive Checks if the minimal view is active.
116 * @return True if active, otherwise false.
117 */
118 bool isMinimalViewActive() const;
119
120 /*!
121 \brief This method configures the widget gathering all the information regarding branches, tags, stashes and
122 submodules.
123
124 */
125 void showBranches();
126
127 /**
128 * @brief refreshCurrentBranchLink Reloads the current branch link
129 */
130 void refreshCurrentBranchLink();
131 /*!
132 \brief Clears all widget's information.
133
134 */
135 void clear();
136
137 /**
138 * @brief returnToSavedView Returns to the view mode previously saved. This methods bypasses the forceMinimalView.
139 * method.
140 */
141 void returnToSavedView();
142
143 /**
144 * @brief forceMinimalView Forces the minimal view but temporarily: id doesn't save the state.
145 */
146 void forceMinimalView();
147
148 /**
149 * @brief onPanelsVisibilityChaned Reloads the visibility of the stash, submodules, and subtree panels.
150 */
151 void onPanelsVisibilityChaned();
152
153private:
154 QSharedPointer<GitCache> mCache;
155 QSharedPointer<GitBase> mGit;
156 QSharedPointer<GitTags> mGitTags;
157 BranchTreeWidget *mLocalBranchesTree = nullptr;
158 BranchesViewDelegate *mLocalDelegate = nullptr;
159 BranchTreeWidget *mRemoteBranchesTree = nullptr;
160 BranchesViewDelegate *mRemotesDelegate = nullptr;
161 BranchesViewDelegate *mTagsDelegate = nullptr;
162 RefTreeWidget *mTagsTree = nullptr;
163 QListWidget *mStashesList = nullptr;
164 QLabel *mStashesCount = nullptr;
165 QLabel *mStashesArrow = nullptr;
166 QLabel *mSubmodulesCount = nullptr;
167 QLabel *mSubmodulesArrow = nullptr;
168 QListWidget *mSubmodulesList = nullptr;
169 QLabel *mSubtreeCount = nullptr;
170 QLabel *mSubtreeArrow = nullptr;
171 QListWidget *mSubtreeList = nullptr;
172 QPushButton *mMinimize = nullptr;
173 QFrame *mFullBranchFrame = nullptr;
174 BranchesWidgetMinimal *mMinimal = nullptr;
175 QString mLastSearch;
176 int mLastIndex;
177 RefTreeWidget *mLastTreeSearched = nullptr;
178
179 /**
180 * @brief fullView Shows the full branches view.
181 */
182 void fullView();
183
184 /**
185 * @brief minimalView Shows the minimalistic branches view.
186 */
187 void minimalView();
188
189 /*!
190 \brief Method that for a given \p branch process all the information and creates the item that will be stored in the
191 local branches BranchTreeWidget.
192
193 \param branch The branch to be added in the tree widget.
194 */
195 void processLocalBranch(const QString &sha, QString branch);
196 /*!
197 \brief Method that for a given \p branch process all the information and creates the item that will be stored in the
198 remote branches BranchTreeWidget.
199
200 \param branch The remote branch to be added in the tree widget.
201 */
202 void processRemoteBranch(const QString &sha, QString branch);
203 /*!
204 \brief Process all the tags and adds them into the QListWidget.
205
206 */
207 void processTags();
208 /*!
209 \brief Process all the stashes and adds them into the QListWidget.
210
211 */
212 void processStashes();
213 /*!
214 \brief Process all the submodules and adds them into QListWidget.
215
216 */
217 void processSubmodules();
218
219 /**
220 * @brief processSubtrees Process all the subtrees and adds them into the QListWidget.
221 */
222 void processSubtrees();
223 /*!
224 \brief Once all the items have been added to the conrresponding BranchTreeWidget, the columns are adjusted to show
225 the data correctly from a UI point of view.
226
227 \param treeWidget
228 */
229 void adjustBranchesTree(BranchTreeWidget *treeWidget);
230 /*!
231 \brief Shows the tags context menu.
232
233 \param p The position where the menu will be displayed.
234 */
235 void showTagsContextMenu(const QPoint &p);
236 /*!
237 \brief Shows the stashes context menu.
238
239 \param p The position where the menu will be displayed.
240 */
241 void showStashesContextMenu(const QPoint &p);
242 /*!
243 \brief Shows the submodules context menu.
244
245 \param p The position where the menu will be displayed.
246 */
247 void showSubmodulesContextMenu(const QPoint &p);
248
249 /**
250 * @brief showSubtreesContextMenu Shows the subtrees context menu.
251 * @param p The position where the menu will be displayed.
252 */
253 void showSubtreesContextMenu(const QPoint &p);
254 /*!
255 \brief Expands or contracts the stashes list widget.
256
257 */
258 void onStashesHeaderClicked();
259 /*!
260 \brief Expands or contracts the submodules list widget.
261
262 */
263 void onSubmodulesHeaderClicked();
264
265 /**
266 * @brief onSubtreesHeaderClicked Expands or contracts the subtrees list widget.
267 */
268 void onSubtreesHeaderClicked();
269 /*!
270 \brief Gets the SHA for a given tag and notifies the UI that it should select it in the repository view.
271
272 \param item The tag item from the tags list.
273 */
274 void onTagClicked(QTreeWidgetItem *item);
275 /*!
276 \brief Gets the SHA for a given stash and notifies the UI that it should select it in the repository view.
277
278 \param item The stash item from the stashes list.
279 */
280 void onStashClicked(QListWidgetItem *item);
281
282 /**
283 * @brief onStashSelected Gets the SHA for a given stash and notifies the UI that it should select it in the
284 * repository view.
285 * @param stash The stash name.
286 */
287 void onStashSelected(const QString &stashId);
288
289 /**
290 * @brief onSearchBranch Searches for a branch in the children BranchTreeWidget.
291 */
292 void onSearchBranch();
293
294 QPair<QString, QString> getSubtreeData(const QString &prefix);
295};
296