File indexing completed on 2024-04-14 05:37:13

0001 /*
0002     SPDX-FileCopyrightText: 2001-2004,2009 Otto Bruggeman <bruggie@gmail.com>
0003     SPDX-FileCopyrightText: 2001-2003 John Firebaugh <jfirebaugh@kde.org>
0004 
0005     SPDX-License-Identifier: GPL-2.0-or-later
0006 */
0007 
0008 #ifndef KOMPAREDIFF2_DIFFMODEL_H
0009 #define KOMPAREDIFF2_DIFFMODEL_H
0010 
0011 // lib
0012 #include "diffhunk.h"
0013 #include "global.h"
0014 #include "komparediff2_export.h"
0015 // Qt
0016 #include <QObject>
0017 #include <QStringList>
0018 // Std
0019 #include <memory>
0020 
0021 namespace KompareDiff2
0022 {
0023 class DiffModelPrivate;
0024 
0025 /**
0026  * @class DiffModel diffmodel.h <KompareDiff2/DiffModel>
0027  *
0028  * A model describing the differences between two files.
0029  */
0030 class KOMPAREDIFF2_EXPORT DiffModel : public QObject
0031 {
0032     Q_OBJECT
0033 
0034 public:
0035     DiffModel(const QString &srcBaseURL, const QString &destBaseURL);
0036     DiffModel();
0037     ~DiffModel() override;
0038 
0039 public:
0040     DiffModel &operator=(const DiffModel &model);
0041     bool operator<(const DiffModel &model) const;
0042 
0043     int parseDiff(Format format, const QStringList &list);
0044 
0045     QString recreateDiff() const;
0046 
0047     int hunkCount() const;
0048     int differenceCount() const;
0049     int appliedCount() const;
0050 
0051     DiffHunk *hunkAt(int i);
0052     const Difference *differenceAt(int i) const;
0053     Difference *differenceAt(int i);
0054 
0055     DiffHunkList *hunks();
0056     const DiffHunkList *hunks() const;
0057     DifferenceList *differences();
0058     const DifferenceList *differences() const;
0059 
0060     int findDifference(Difference *diff) const;
0061 
0062     Difference *firstDifference();
0063     Difference *lastDifference();
0064     Difference *prevDifference();
0065     Difference *nextDifference();
0066 
0067     QString source() const;
0068     QString destination() const;
0069     QString sourceFile() const;
0070     QString destinationFile() const;
0071     QString sourcePath() const;
0072     QString destinationPath() const;
0073     QString sourceTimestamp() const;
0074     QString destinationTimestamp() const;
0075     QString sourceRevision() const;
0076     QString destinationRevision() const;
0077 
0078     void setSourceFile(const QString &path);
0079     void setDestinationFile(const QString &path);
0080     void setSourceTimestamp(const QString &timestamp);
0081     void setDestinationTimestamp(const QString &timestamp);
0082     void setSourceRevision(const QString &revision);
0083     void setDestinationRevision(const QString &revision);
0084 
0085     void addHunk(DiffHunk *hunk);
0086     void addDiff(Difference *diff);
0087     bool hasUnsavedChanges() const;
0088 
0089     int diffIndex() const;
0090     void setDiffIndex(int diffIndex);
0091 
0092     void applyDifference(bool apply);
0093     void applyAllDifferences(bool apply);
0094 
0095     bool setSelectedDifference(Difference *diff);
0096 
0097     int localeAwareCompareSource(const DiffModel &model) const;
0098 
0099     bool isBlended() const;
0100     void setBlended(bool blended);
0101 
0102     /**
0103      * @p oldlines - lines that were removed.
0104      * @p newLines - lines that were inserted.
0105      * @p startPos - number of line at which the change occurred
0106      */
0107     QPair<QList<Difference *>, QList<Difference *>> linesChanged(const QStringList &oldLines, const QStringList &newLines, int editLineNumber);
0108 
0109 private Q_SLOTS:
0110     void slotDifferenceApplied(Difference *diff);
0111 
0112 private:
0113     Q_DECLARE_PRIVATE(DiffModel)
0114     std::unique_ptr<DiffModelPrivate> const d_ptr;
0115 };
0116 
0117 } // End of namespace KompareDiff2
0118 
0119 #endif