Members of the KDE Community are recommended to subscribe to the kde-community mailing list at https://mail.kde.org/mailman/listinfo/kde-community to allow them to participate in important discussions and receive other important announcements

Commit 930ae634 authored by Michael Reeves's avatar Michael Reeves

Refactor move Selection to seprate file.

parent eea07bb9
......@@ -19,7 +19,8 @@ set(kdiff3part_PART_SRCS
gnudiff_xmalloc.cpp
common.cpp
smalldialogs.cpp
progress.cpp )
progress.cpp
selection.cpp )
add_library(kdiff3part MODULE ${kdiff3part_PART_SRCS})
......
......@@ -26,7 +26,6 @@
#include "options.h"
#include "gnudiff_diff.h"
// Each range with matching elements is followed by a range with differences on either side.
// Then again range of matching elements should follow.
struct Diff
......@@ -325,74 +324,6 @@ void calcWhiteDiff3Lines( Diff3LineList& d3ll, const LineData* pldA, const Lin
void calcDiff3LineVector( Diff3LineList& d3ll, Diff3LineVector& d3lv );
class Selection
{
public:
Selection(){}
private:
LineRef firstLine = -1;
LineRef lastLine = -1;
int firstPos = -1;
int lastPos = -1;
LineRef oldFirstLine = -1;
LineRef oldLastLine = -1;
public:
//private:
bool bSelectionContainsData = false;
public:
inline LineRef getFirstLine() { return firstLine; };
inline LineRef getLastLine() { return lastLine; };
inline int getFirstPos() { return firstPos; };
inline int getLastPos() { return lastPos; };
inline bool isValidFirstLine() { return firstLine != -1; }
inline void clearOldSelection() { oldLastLine = -1, oldFirstLine = -1; };
inline LineRef getOldLastLine() { return oldLastLine; };
inline LineRef getOldFirstLine() { return oldFirstLine; };
inline bool selectionContainsData(void) { return bSelectionContainsData; };
bool isEmpty() { return firstLine == -1 || (firstLine == lastLine && firstPos == lastPos) || bSelectionContainsData == false; }
void reset()
{
oldLastLine = lastLine;
oldFirstLine = firstLine;
firstLine = -1;
lastLine = -1;
bSelectionContainsData = false;
}
void start( LineRef l, int p ) { firstLine = l; firstPos = p; }
void end( LineRef l, int p ) {
if ( oldLastLine == -1 )
oldLastLine = lastLine;
lastLine = l;
lastPos = p;
//bSelectionContainsData = (firstLine == lastLine && firstPos == lastPos);
}
bool within( LineRef l, LineRef p );
bool lineWithin( LineRef l );
int firstPosInLine(LineRef l);
int lastPosInLine(LineRef l);
LineRef beginLine(){
if (firstLine<0 && lastLine<0) return -1;
return max2((LineRef)0,min2(firstLine,lastLine));
}
LineRef endLine(){
if (firstLine<0 && lastLine<0) return -1;
return max2(firstLine,lastLine);
}
int beginPos() { return firstLine==lastLine ? min2(firstPos,lastPos) :
firstLine<lastLine ? (firstLine<0?0:firstPos) : (lastLine<0?0:lastPos); }
int endPos() { return firstLine==lastLine ? max2(firstPos,lastPos) :
firstLine<lastLine ? lastPos : firstPos; }
};
// Helper class that swaps left and right for some commands.
class MyPainter : public QPainter
{
......
......@@ -15,6 +15,7 @@
* *
***************************************************************************/
#include "selection.h"
#include "difftextwindow.h"
#include "kdiff3.h"
#include "merger.h"
......@@ -677,89 +678,6 @@ void DiffTextWindow::convertToLinePos(int x, int y, LineRef& line, int& pos)
pos = -1;
}
int Selection::firstPosInLine(LineRef l)
{
Q_ASSERT(firstLine != -1);
LineRef l1 = firstLine;
LineRef l2 = lastLine;
int p1 = firstPos;
int p2 = lastPos;
if(l1 > l2) {
std::swap(l1, l2);
std::swap(p1, p2);
}
if(l1 == l2 && p1 > p2) {
std::swap(p1, p2);
}
if(l == l1)
return p1;
return 0;
}
int Selection::lastPosInLine(LineRef l)
{
Q_ASSERT(firstLine != -1);
LineRef l1 = firstLine;
LineRef l2 = lastLine;
int p1 = firstPos;
int p2 = lastPos;
if(l1 > l2) {
std::swap(l1, l2);
std::swap(p1, p2);
}
if(l1 == l2 && p1 > p2) {
std::swap(p1, p2);
}
if(l == l2)
return p2;
return INT_MAX;
}
bool Selection::within(LineRef l, LineRef p)
{
if(firstLine == -1) return false;
LineRef l1 = firstLine;
LineRef l2 = lastLine;
int p1 = firstPos;
int p2 = lastPos;
if(l1 > l2) {
std::swap(l1, l2);
std::swap(p1, p2);
}
if(l1 == l2 && p1 > p2) {
std::swap(p1, p2);
}
if(l1 <= l && l <= l2)
{
if(l1 == l2)
return p >= p1 && p < p2;
if(l == l1)
return p >= p1;
if(l == l2)
return p < p2;
return true;
}
return false;
}
bool Selection::lineWithin(LineRef l)
{
if(firstLine == -1) return false;
LineRef l1 = firstLine;
LineRef l2 = lastLine;
if(l1 > l2) {
std::swap(l1, l2);
}
return (l1 <= l && l <= l2);
}
class FormatRangeHelper
{
private:
......
......@@ -19,6 +19,7 @@
#define MERGERESULTWINDOW_H
#include "diff.h"
#include "selection.h"
#include <QWidget>
#include <QPixmap>
......
#include "gnudiff_diff.h"
#include "selection.h"
#include <QtGlobal>
int Selection::firstPosInLine(LineRef l)
{
Q_ASSERT(firstLine != invalidRef);
LineRef l1 = firstLine;
LineRef l2 = lastLine;
int p1 = firstPos;
int p2 = lastPos;
if(l1 > l2)
{
std::swap(l1, l2);
std::swap(p1, p2);
}
if(l1 == l2 && p1 > p2)
{
std::swap(p1, p2);
}
if(l == l1)
return p1;
return 0;
}
int Selection::lastPosInLine(LineRef l)
{
Q_ASSERT(firstLine != invalidRef);
LineRef l1 = firstLine;
LineRef l2 = lastLine;
int p1 = firstPos;
int p2 = lastPos;
if(l1 > l2)
{
std::swap(l1, l2);
std::swap(p1, p2);
}
if(l1 == l2 && p1 > p2)
{
std::swap(p1, p2);
}
if(l == l2)
return p2;
return INT_MAX;
}
bool Selection::within(LineRef l, LineRef p)
{
if(firstLine == invalidRef)
return false;
LineRef l1 = firstLine;
LineRef l2 = lastLine;
int p1 = firstPos;
int p2 = lastPos;
if(l1 > l2)
{
std::swap(l1, l2);
std::swap(p1, p2);
}
if(l1 == l2 && p1 > p2)
{
std::swap(p1, p2);
}
if(l1 <= l && l <= l2)
{
if(l1 == l2)
return p >= p1 && p < p2;
if(l == l1)
return p >= p1;
if(l == l2)
return p < p2;
return true;
}
return false;
}
bool Selection::lineWithin(LineRef l)
{
if(firstLine == invalidRef)
return false;
LineRef l1 = firstLine;
LineRef l2 = lastLine;
if(l1 > l2)
{
std::swap(l1, l2);
}
return (l1 <= l && l <= l2);
}
#include "gnudiff_diff.h"
#include "common.h"
class Selection
{
public:
Selection(){}
private:
const LineRef invalidRef = -1;
LineRef firstLine = invalidRef;
LineRef lastLine = invalidRef;
int firstPos = -1;
int lastPos = -1;
LineRef oldFirstLine = invalidRef;
LineRef oldLastLine = invalidRef;
public:
//private:
bool bSelectionContainsData = false;
public:
inline LineRef getFirstLine() { return firstLine; };
inline LineRef getLastLine() { return lastLine; };
inline int getFirstPos() { return firstPos; };
inline int getLastPos() { return lastPos; };
inline bool isValidFirstLine() { return firstLine != invalidRef; }
inline void clearOldSelection() { oldLastLine = invalidRef, oldFirstLine = invalidRef; };
inline LineRef getOldLastLine() { return oldLastLine; };
inline LineRef getOldFirstLine() { return oldFirstLine; };
inline bool selectionContainsData(void) { return bSelectionContainsData; };
bool isEmpty() { return firstLine == invalidRef || (firstLine == lastLine && firstPos == lastPos) || bSelectionContainsData == false; }
void reset()
{
oldLastLine = lastLine;
oldFirstLine = firstLine;
firstLine = invalidRef;
lastLine = invalidRef;
bSelectionContainsData = false;
}
void start( LineRef l, int p ) { firstLine = l; firstPos = p; }
void end( LineRef l, int p ) {
if ( oldLastLine == invalidRef )
oldLastLine = lastLine;
lastLine = l;
lastPos = p;
//bSelectionContainsData = (firstLine == lastLine && firstPos == lastPos);
}
bool within( LineRef l, LineRef p );
bool lineWithin( LineRef l );
int firstPosInLine(LineRef l);
int lastPosInLine(LineRef l);
LineRef beginLine(){
if (firstLine<0 && lastLine<0) return invalidRef;
return max2((LineRef)0,min2(firstLine,lastLine));
}
LineRef endLine(){
if (firstLine<0 && lastLine<0) return invalidRef;
return max2(firstLine,lastLine);
}
int beginPos() { return firstLine==lastLine ? min2(firstPos,lastPos) :
firstLine<lastLine ? (firstLine<0?0:firstPos) : (lastLine<0?0:lastPos); }
int endPos() { return firstLine==lastLine ? max2(firstPos,lastPos) :
firstLine<lastLine ? lastPos : firstPos; }
};
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment