File indexing completed on 2025-01-19 05:11:29

0001 /*
0002 SPDX-FileCopyrightText: 2021 Hamed Masafi <hamed.masfi@gmail.com>
0003 
0004 SPDX-License-Identifier: GPL-3.0-or-later
0005 */
0006 
0007 #pragma once
0008 
0009 #include "abstractgititemsmodel.h"
0010 #include "libkommit_export.h"
0011 #include "types.h"
0012 
0013 namespace Git
0014 {
0015 
0016 class Branch;
0017 class Manager;
0018 class LIBKOMMIT_EXPORT BranchesModel : public AbstractGitItemsModel
0019 {
0020     Q_OBJECT
0021 
0022 public:
0023     struct BranchData {
0024         QString name;
0025         int commitsAhead;
0026         int commitsBehind;
0027     };
0028     explicit BranchesModel(Manager *git, QObject *parent = nullptr);
0029 
0030     int rowCount(const QModelIndex &parent) const override;
0031     int columnCount(const QModelIndex &parent) const override;
0032     QVariant data(const QModelIndex &index, int role) const override;
0033     QVariant headerData(int section, Qt::Orientation orientation, int role) const override;
0034 
0035     QSharedPointer<Branch> fromIndex(const QModelIndex &index) const;
0036     QSharedPointer<Branch> findByName(const QString &branchName) const;
0037 
0038     Q_REQUIRED_RESULT const QString &currentBranch() const;
0039     Q_REQUIRED_RESULT const QString &referenceBranch() const;
0040     void setReferenceBranch(const QString &newReferenceBranch);
0041 
0042 protected:
0043     void fill() override;
0044 
0045 private:
0046     QMap<QSharedPointer<Branch>, QPair<int, int>> mCompareWithRef;
0047     PointerList<Branch> mData;
0048     QString mCurrentBranch;
0049     QString mReferenceBranch;
0050     void calculateCommitStats();
0051     void calc();
0052 };
0053 
0054 } // namespace Git