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 #include "abstractgititemsmodel.h"
0009 #include "libkommit_export.h"
0010 
0011 #include <QCalendar>
0012 #include <QSet>
0013 
0014 namespace Git
0015 {
0016 
0017 class Commit;
0018 class Manager;
0019 class AuthorsModel;
0020 class LIBKOMMIT_EXPORT LogsModel : public AbstractGitItemsModel
0021 {
0022     Q_OBJECT
0023 
0024 public:
0025     enum class LogMatchType { ExactMatch, BeginMatch };
0026     explicit LogsModel(Manager *git, AuthorsModel *authorsModel = nullptr, QObject *parent = nullptr);
0027     ~LogsModel() override;
0028 
0029     int rowCount(const QModelIndex &parent) const override;
0030     int columnCount(const QModelIndex &parent) const override;
0031     QVariant data(const QModelIndex &index, int role) const override;
0032     QVariant headerData(int section, Qt::Orientation orientation, int role) const override;
0033 
0034     Commit *at(int index) const;
0035     Commit *fromIndex(const QModelIndex &index) const;
0036     QModelIndex findIndexByHash(const QString &hash) const;
0037     Git::Commit *findLogByHash(const QString &hash, LogMatchType matchType = LogMatchType::ExactMatch) const;
0038 
0039     Q_REQUIRED_RESULT const QString &branch() const;
0040     void setBranch(const QString &newBranch);
0041 
0042     Q_REQUIRED_RESULT bool fullDetails() const;
0043     void setFullDetails(bool newFullDetails);
0044 
0045     Q_REQUIRED_RESULT QString calendarType() const;
0046     void setCalendarType(const QString &newCalendarType);
0047 
0048 protected:
0049     void fill() override;
0050 
0051 private:
0052     bool mFullDetails{false};
0053     void initChilds();
0054     void initGraph();
0055 
0056     QString mBranch;
0057     QList<Commit *> mData;
0058     QStringList mBranches;
0059     QMap<QString, Commit *> mDataByCommitHashLong;
0060     QMap<QString, Commit *> mDataByCommitHashShort;
0061     AuthorsModel *mAuthorsModel;
0062     QCalendar mCalendar;
0063     QSet<QString> mSeenHases;
0064 };
0065 }