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 <QTreeWidget> |
27 | |
28 | class GitBase; |
29 | class GitCache; |
30 | |
31 | class RefTreeWidget : public QTreeWidget |
32 | { |
33 | Q_OBJECT |
34 | |
35 | public: |
36 | /** |
37 | * @brief Default constructor |
38 | * @param cache The GitQlient cache. |
39 | * @param git The git object to perform Git operations. |
40 | * @param parentThe parent widget if needed. |
41 | */ |
42 | explicit RefTreeWidget(QWidget *parent = nullptr); |
43 | /** |
44 | * @brief focusOnBranch Sets the focus of the three in the item specified in @p branch starting from the position @p |
45 | * lastPos. |
46 | * @param item The text to seach in the tree and set the focus. |
47 | * @param lastPos Starting position for the search. |
48 | * @return |
49 | */ |
50 | int focusOnBranch(const QString &itemText, int startSearchPos = -1); |
51 | |
52 | protected: |
53 | QVector<QTreeWidgetItem *> findChildItem(const QString &text) const; |
54 | }; |
55 | |
56 | /*! |
57 | \brief The BranchTreeWidget class shows all the information regarding the branches and its position respect master and |
58 | its remote branch. |
59 | |
60 | */ |
61 | class BranchTreeWidget : public RefTreeWidget |
62 | { |
63 | Q_OBJECT |
64 | |
65 | signals: |
66 | void fullReload(); |
67 | void logReload(); |
68 | |
69 | /*! |
70 | \brief Signal triggered when the user selects a commit via branch or tag selection. |
71 | |
72 | \param sha The selected sha. |
73 | */ |
74 | void signalSelectCommit(const QString &sha); |
75 | /*! |
76 | \brief Signal triggered when a merge is required. |
77 | |
78 | \param currentBranch The current branch. |
79 | \param fromBranch The branch to merge into the current one. |
80 | */ |
81 | void signalMergeRequired(const QString ¤tBranch, const QString &fromBranch); |
82 | /*! |
83 | * \brief signalPullConflict Signal triggered when trying to pull and a conflict happens. |
84 | */ |
85 | void signalPullConflict(); |
86 | |
87 | /** |
88 | * @brief signalFetchPerformed Signal triggered when a deep fetch is performed. |
89 | */ |
90 | void signalFetchPerformed(); |
91 | /** |
92 | * @brief signalRefreshPRsCache Signal that refreshes PRs cache. |
93 | */ |
94 | void signalRefreshPRsCache(); |
95 | |
96 | /** |
97 | * @brief Signal triggered when a merge with squash behavior has been requested. Since it involves a lot of changes |
98 | * at UI level this action is not performed here. |
99 | * |
100 | * @param origin The branch to merge from. |
101 | * @param destination The branch to merge into. |
102 | */ |
103 | void mergeSqushRequested(const QString &origin, const QString &destination); |
104 | |
105 | public: |
106 | /*! |
107 | \brief Default constructor. |
108 | |
109 | \param git The git object to perform Git operations. |
110 | \param parent The parent widget if needed. |
111 | */ |
112 | explicit BranchTreeWidget(const QSharedPointer<GitCache> &cache, const QSharedPointer<GitBase> &git, |
113 | QWidget *parent = nullptr); |
114 | /*! |
115 | \brief Configures the widget to be the local branches widget. |
116 | |
117 | \param isLocal True if the current widget shows local branches, otherwise false. |
118 | */ |
119 | void setLocalRepo(const bool isLocal) { mLocal = isLocal; } |
120 | |
121 | /** |
122 | * @brief reloadCurrentBranchLink Reloads the link to the current branch. |
123 | */ |
124 | void reloadCurrentBranchLink() const; |
125 | |
126 | private: |
127 | bool mLocal = false; |
128 | QSharedPointer<GitCache> mCache; |
129 | QSharedPointer<GitBase> mGit; |
130 | |
131 | /*! |
132 | \brief Shows the context menu. |
133 | |
134 | \param pos The position of the menu. |
135 | */ |
136 | void (const QPoint &pos); |
137 | /*! |
138 | \brief Checks out the branch selected by the \p item. |
139 | |
140 | \param item The item that contains the data of the branch. |
141 | */ |
142 | void checkoutBranch(QTreeWidgetItem *item); |
143 | /*! |
144 | \brief Selects the commit of the given \p item branch. |
145 | |
146 | \param item The item that contains the data of the branch selected to extract the commit SHA. |
147 | */ |
148 | void selectCommit(QTreeWidgetItem *item); |
149 | |
150 | /** |
151 | * @brief onSelectionChanged Process when a selection has changed. |
152 | */ |
153 | void onSelectionChanged(); |
154 | }; |
155 | |