File indexing completed on 2024-04-21 05:44:08

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_DIFFERENCE_H
0009 #define KOMPAREDIFF2_DIFFERENCE_H
0010 
0011 // lib
0012 #include "differencestring.h"
0013 #include "komparediff2_export.h"
0014 // Qt
0015 #include <QObject>
0016 // Std
0017 #include <memory>
0018 
0019 namespace KompareDiff2
0020 {
0021 class DifferencePrivate;
0022 
0023 /**
0024  * @class Difference difference.h <KompareDiff2/Difference>
0025  *
0026  * A difference.
0027  */
0028 class KOMPAREDIFF2_EXPORT Difference : public QObject
0029 {
0030     Q_OBJECT
0031 public:
0032     enum Type {
0033         Change,
0034         Insert,
0035         Delete,
0036         Unchanged,
0037     };
0038 
0039 public:
0040     Difference(int sourceLineNo, int destinationLineNo, int type = Difference::Unchanged);
0041     ~Difference() override;
0042 
0043 public:
0044     int type() const;
0045 
0046     int sourceLineNumber() const;
0047     int destinationLineNumber() const;
0048 
0049     int sourceLineCount() const;
0050     int destinationLineCount() const;
0051 
0052     int sourceLineEnd() const;
0053     int destinationLineEnd() const;
0054 
0055     /// Destination line number that tracks applying/unapplying of other differences
0056     /// Essentially a line number in a patch consisting of applied diffs only
0057     int trackingDestinationLineNumber() const;
0058     int trackingDestinationLineEnd() const;
0059     void setTrackingDestinationLineNumber(int i);
0060 
0061     DifferenceString *sourceLineAt(int i) const;
0062     DifferenceString *destinationLineAt(int i) const;
0063 
0064     DifferenceStringList sourceLines() const;
0065     DifferenceStringList destinationLines() const;
0066 
0067     bool hasConflict() const;
0068     void setConflict(bool conflicts);
0069 
0070     bool isUnsaved() const;
0071     void setUnsaved(bool unsaved);
0072 
0073     void apply(bool apply);
0074     /// Apply without emitting any signals
0075     void applyQuietly(bool apply);
0076     bool applied() const;
0077 
0078     void setType(int type);
0079 
0080     void addSourceLine(const QString &line);
0081     void addDestinationLine(const QString &line);
0082 
0083     /** This method will calculate the differences between the individual strings and store them as Markers */
0084     void determineInlineDifferences();
0085 
0086     QString recreateDifference() const;
0087 
0088 Q_SIGNALS:
0089     void differenceApplied(KompareDiff2::Difference *);
0090 
0091 private:
0092     Q_DECLARE_PRIVATE(Difference)
0093     std::unique_ptr<DifferencePrivate> const d_ptr;
0094 };
0095 
0096 using DifferenceList =              QList<Difference *>;
0097 using DifferenceListIterator =      QList<Difference *>::iterator;
0098 using DifferenceListConstIterator = QList<Difference *>::const_iterator;
0099 
0100 } // End of namespace KompareDiff2
0101 
0102 #endif