KompareDiff2

diffmodel.h
1 /*
2 SPDX-FileCopyrightText: 2001-2004,2009 Otto Bruggeman <[email protected]>
3 SPDX-FileCopyrightText: 2001-2003 John Firebaugh <[email protected]>
4 
5 SPDX-License-Identifier: GPL-2.0-or-later
6 */
7 
8 #ifndef DIFFMODEL_H
9 #define DIFFMODEL_H
10 
11 #include <QObject>
12 #include <QStringList>
13 #include "diffhunk.h"
14 #include "kompare.h"
15 #include "diff2_export.h"
16 
17 namespace Diff2
18 {
19 
20 /**
21  * A model describing the differences between two files.
22  */
23 class DIFF2_EXPORT DiffModel : public QObject
24 {
25  Q_OBJECT
26 public:
27 
28  DiffModel(const QString& srcBaseURL, const QString& destBaseURL);
29  DiffModel();
30  ~DiffModel() override;
31 
32 private:
33  DiffModel(const DiffModel&) : QObject() {}
34 
35 public:
36  int parseDiff(enum Kompare::Format format, const QStringList& list);
37 
38  QString recreateDiff() const;
39 
40  int hunkCount() const { return m_hunks.count(); }
41  int differenceCount() const { return m_differences.count(); }
42  int appliedCount() const { return m_appliedCount; }
43 
44  DiffHunk* hunkAt(int i) { return (m_hunks.at(i)); }
45  const Difference* differenceAt(int i) const { return (m_differences.at(i)); }
46  Difference* differenceAt(int i) { return (m_differences.at(i)); }
47 
48  DiffHunkList* hunks() { return &m_hunks; }
49  const DiffHunkList* hunks() const { return &m_hunks; }
50  DifferenceList* differences() { return &m_differences; }
51  const DifferenceList* differences() const { return &m_differences; }
52 
53  int findDifference(Difference* diff) const { return m_differences.indexOf(diff); }
54 
55  Difference* firstDifference();
56  Difference* lastDifference();
57  Difference* prevDifference();
58  Difference* nextDifference();
59 
60  const QString source() const { return m_source; }
61  const QString destination() const { return m_destination; }
62  const QString sourceFile() const;
63  const QString destinationFile() const;
64  const QString sourcePath() const;
65  const QString destinationPath() const;
66  const QString sourceTimestamp() const { return m_sourceTimestamp; }
67  const QString destinationTimestamp() const { return m_destinationTimestamp; }
68  const QString sourceRevision() const { return m_sourceRevision; }
69  const QString destinationRevision() const { return m_destinationRevision; }
70 
71  void setSourceFile(QString path);
72  void setDestinationFile(QString path);
73  void setSourceTimestamp(QString timestamp);
74  void setDestinationTimestamp(QString timestamp);
75  void setSourceRevision(QString revision);
76  void setDestinationRevision(QString revision);
77 
78  void addHunk(DiffHunk* hunk);
79  void addDiff(Difference* diff);
80  bool hasUnsavedChanges() const;
81 
82  int diffIndex(void) const { return m_diffIndex; }
83  void setDiffIndex(int diffIndex) { m_diffIndex = diffIndex; }
84 
85  void applyDifference(bool apply);
86  void applyAllDifferences(bool apply);
87 
88  bool setSelectedDifference(Difference* diff);
89 
90  DiffModel& operator=(const DiffModel& model);
91  bool operator<(const DiffModel& model);
92 
93  int localeAwareCompareSource(const DiffModel& model);
94 
95  bool isBlended() const { return m_blended; }
96  void setBlended(bool blended) { m_blended = blended; }
97 
98  /**
99  * @p oldlines - lines that were removed.
100  * @p newLines - lines that were inserted.
101  * @p startPos - number of line at which the change occurred
102  */
103  QPair<QList<Difference*>, QList<Difference*> > linesChanged(const QStringList& oldLines, const QStringList& newLines, int editLineNumber);
104 
105 private:
106  void splitSourceInPathAndFileName();
107  void splitDestinationInPathAndFileName();
108  void computeDiffStats(Difference* diff);
109  void processStartMarker(Difference* diff, const QStringList& lines, MarkerListConstIterator& currentMarker, int& currentListLine, bool isSource);
110 
111 private:
112  QString m_source;
113  QString m_destination;
114 
115  QString m_sourcePath;
116  QString m_destinationPath;
117 
118  QString m_sourceFile;
119  QString m_destinationFile;
120 
121  QString m_sourceTimestamp;
122  QString m_destinationTimestamp;
123 
124  QString m_sourceRevision;
125  QString m_destinationRevision;
126 
127  DiffHunkList m_hunks;
128  DifferenceList m_differences;
129 
130  int m_appliedCount;
131 
132  int m_diffIndex;
133  Difference* m_selectedDifference;
134 
135  bool m_blended;
136 
137 private Q_SLOTS:
138  void slotDifferenceApplied(Difference* diff);
139 };
140 
141 } // End of namespace Diff2
142 
143 #endif
144 
A model describing the differences between two files.
Definition: diffmodel.h:23
Diff2 namespace.
Definition: cvsdiffparser.h:12
int indexOf(const T &value, int from) const const
Format
Patch format enum.
Definition: kompare.h:26
DiffHunk.
Definition: diffhunk.h:22
A difference.
Definition: difference.h:119
This file is part of the KDE documentation.
Documentation copyright © 1996-2022 The KDE developers.
Generated on Wed Sep 28 2022 03:51:41 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.