File indexing completed on 2025-01-19 04:22:44

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 namespace Git
0012 {
0013 
0014 class Manager;
0015 class LIBKOMMIT_EXPORT BranchesModel : public AbstractGitItemsModel
0016 {
0017     Q_OBJECT
0018 
0019 public:
0020     struct BranchData {
0021         QString name;
0022         int commitsAhead;
0023         int commitsBehind;
0024     };
0025     explicit BranchesModel(Manager *git, QObject *parent = nullptr);
0026 
0027     int rowCount(const QModelIndex &parent) const override;
0028     int columnCount(const QModelIndex &parent) const override;
0029     QVariant data(const QModelIndex &index, int role) const override;
0030     QVariant headerData(int section, Qt::Orientation orientation, int role) const override;
0031 
0032     BranchData *fromIndex(const QModelIndex &index) const;
0033 
0034     Q_REQUIRED_RESULT const QString &currentBranch() const;
0035     Q_REQUIRED_RESULT const QString &referenceBranch() const;
0036     void setReferenceBranch(const QString &newReferenceBranch);
0037 
0038 protected:
0039     void fill() override;
0040 
0041 private:
0042     QList<BranchData *> mData;
0043     QString mCurrentBranch;
0044     QString mReferenceBranch;
0045     void calculateCommitStats();
0046 };
0047 
0048 } // namespace Git