diffmodel.h 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. #ifndef DIFFMODEL_H
  2. #define DIFFMODEL_H
  3. #include <QObject>
  4. #include <QString>
  5. #include <git2/diff.h>
  6. class DiffModel : public QObject
  7. {
  8. Q_OBJECT
  9. Q_PROPERTY(QString path READ path CONSTANT)
  10. Q_PROPERTY(QString data READ data NOTIFY dataChanged)
  11. Q_PROPERTY(int type READ type NOTIFY typeChanged)
  12. Q_PROPERTY(quint16 similarity READ similarity NOTIFY similarityChanged)
  13. Q_ENUMS(DiffType)
  14. public:
  15. enum DiffType {
  16. Unmodified = GIT_DELTA_UNMODIFIED,
  17. Added = GIT_DELTA_ADDED,
  18. Deleted = GIT_DELTA_DELETED,
  19. Modified = GIT_DELTA_MODIFIED,
  20. Renamed = GIT_DELTA_RENAMED,
  21. Copied = GIT_DELTA_COPIED,
  22. Ignored = GIT_DELTA_IGNORED,
  23. Untracked = GIT_DELTA_UNTRACKED,
  24. TypeChange = GIT_DELTA_TYPECHANGE,
  25. Unreadable = GIT_DELTA_UNREADABLE,
  26. Conflicted = GIT_DELTA_CONFLICTED
  27. };
  28. explicit DiffModel(const QString& path = QString(), QObject *parent = 0);
  29. DiffModel(const DiffModel& other);
  30. DiffModel& operator=(const DiffModel& other);
  31. ~DiffModel();
  32. void append(const QString& unifiedData);
  33. QString data() const
  34. {
  35. return m_data;
  36. }
  37. int type() const
  38. {
  39. return m_type;
  40. }
  41. QString path() const
  42. {
  43. return m_path;
  44. }
  45. void setType(int type)
  46. {
  47. if(m_type != type) {
  48. m_type = type;
  49. emit typeChanged(m_type);
  50. }
  51. }
  52. quint16 similarity() const
  53. {
  54. return m_similarity;
  55. }
  56. public slots:
  57. void setSimilarity(quint16 similarity)
  58. {
  59. if (m_similarity == similarity)
  60. return;
  61. m_similarity = similarity;
  62. emit similarityChanged(similarity);
  63. }
  64. signals:
  65. void dataChanged(QString data);
  66. void typeChanged(int type);
  67. void similarityChanged(quint16 similarity);
  68. private:
  69. QString m_path;
  70. int m_type;
  71. QString m_data;
  72. quint16 m_similarity;
  73. };
  74. #endif // DIFFMODEL_H