githandler.h 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. #ifndef GITHANDLER_H
  2. #define GITHANDLER_H
  3. #include <QObject>
  4. #include <repositorymodel.h>
  5. class CommitModel;
  6. class CommitGraph;
  7. typedef QHash<QString, QPointer<CommitModel>> CommitModelContainer;
  8. class GitHandler : public QObject
  9. {
  10. Q_OBJECT
  11. Q_PROPERTY(RepositoryModel* repositories READ repositories NOTIFY repositoriesChanged)
  12. Q_PROPERTY(CommitGraph* graph READ graph WRITE setGraph NOTIFY graphChanged)
  13. Q_PROPERTY(GitRepository* activeRepo READ activeRepo CONSTANT)
  14. Q_PROPERTY(GitDiff* activeDiff READ activeDiff WRITE setActiveDiff NOTIFY activeDiffChanged)
  15. Q_PROPERTY(CommitModel* commits READ commits WRITE setCommits NOTIFY commitsChanged)
  16. public:
  17. GitHandler();
  18. virtual ~GitHandler();
  19. Q_INVOKABLE void open(const QString &path);
  20. Q_INVOKABLE void open(const QUrl &url);
  21. Q_INVOKABLE GitDiff* diff(GitCommit* a, GitCommit* b);
  22. RepositoryModel* repositories() const
  23. {
  24. return m_repositories;
  25. }
  26. CommitGraph* graph() const
  27. {
  28. return m_graph;
  29. }
  30. GitRepository* activeRepo() const
  31. {
  32. return m_activeRepo;
  33. }
  34. GitDiff* activeDiff() const;
  35. CommitModel* commits() const
  36. {
  37. return m_commits;
  38. }
  39. public slots:
  40. void setGraph(CommitGraph* graph)
  41. {
  42. if (m_graph == graph)
  43. return;
  44. m_graph = graph;
  45. emit graphChanged(graph);
  46. }
  47. void setActiveDiff(GitDiff* activeDiff);
  48. void setCommits(CommitModel* commits)
  49. {
  50. if (m_commits == commits)
  51. return;
  52. m_commits = commits;
  53. emit commitsChanged(commits);
  54. }
  55. signals:
  56. void repositoriesChanged(RepositoryModel* repositories);
  57. void graphChanged(CommitGraph* graph);
  58. void activeDiffChanged(GitDiff* activeDiff);
  59. void commitsChanged(CommitModel* commits);
  60. protected:
  61. QString lastError() const;
  62. private:
  63. RepositoryModel* m_repositories;
  64. CommitModel* m_commits;
  65. CommitGraph* m_graph;
  66. GitRepository* m_activeRepo;
  67. QPointer<GitDiff> m_activeDiff;
  68. };
  69. #endif // GITHANDLER_H