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 //
0008 // Created by hamed on 25.03.22.
0009 //
0010 
0011 #pragma once
0012 #include "abstractgititemsmodel.h"
0013 #include "libkommit_export.h"
0014 
0015 #include <QCalendar>
0016 
0017 namespace Git
0018 {
0019 
0020 class Log;
0021 class Manager;
0022 class AuthorsModel;
0023 class LIBKOMMIT_EXPORT LogsModel : public AbstractGitItemsModel
0024 {
0025     Q_OBJECT
0026 
0027     enum Role
0028     {
0029         Subject,
0030         Message,
0031         Date,
0032         Author,
0033         Hash,
0034         ShortHash,
0035         Body
0036     };
0037 
0038 public:
0039     enum class LogMatchType { ExactMatch, BeginMatch };
0040     explicit LogsModel(Manager *git, AuthorsModel *authorsModel = nullptr, QObject *parent = nullptr);
0041     ~LogsModel() override;
0042 
0043     int rowCount(const QModelIndex &parent) const override;
0044 
0045     QVariant data(const QModelIndex &index, int role) const override;
0046 
0047 
0048     Log *at(int index) const;
0049     Log *fromIndex(const QModelIndex &index) const;
0050     QModelIndex findIndexByHash(const QString &hash) const;
0051     Git::Log *findLogByHash(const QString &hash, LogMatchType matchType = LogMatchType::ExactMatch) const;
0052 
0053     Q_REQUIRED_RESULT const QString &branch() const;
0054     void setBranch(const QString &newBranch);
0055 
0056     Q_REQUIRED_RESULT QString calendarType() const;
0057     void setCalendarType(const QString &newCalendarType);
0058 
0059 protected:
0060     void fill() override;
0061 
0062 private:
0063     void initChilds();
0064     void initGraph();
0065 
0066     QString mBranch;
0067     QList<Log *> mData;
0068     QStringList mBranches;
0069     QMap<QString, Log *> mDataByCommitHashLong;
0070     QMap<QString, Log *> mDataByCommitHashShort;
0071     AuthorsModel *mAuthorsModel;
0072     QCalendar mCalendar;
0073 
0074     // QAbstractItemModel interface
0075 public:
0076     QHash<int, QByteArray> roleNames() const override final;
0077 };
0078 }