Commit 5bac3680 authored by Michael Reeves's avatar Michael Reeves

Add more human readable types.

Using int everywhere makes the code difficult to fallow.
parent 5dc30b13
......@@ -526,10 +526,14 @@ QStringList SourceData::readAndPreprocess(QTextCodec* pEncoding, bool bAutoDetec
if(m_pOptions->m_bIgnoreComments)
{
m_lmppData.removeComments();
LineRef vSize = (LineRef)std::min(m_normalData.m_vSize, m_lmppData.m_vSize);
for(int i = 0; i < (int)vSize; ++i)
qint64 vSize = std::min(m_normalData.m_vSize, m_lmppData.m_vSize);
Q_ASSERT(vSize < std::numeric_limits<int>::max());
for(int i = 0; i < vSize; ++i)
{
m_normalData.m_v[i].setPureComment(m_lmppData.m_v[i].isPureComment());
//Don't crash if vSize is too large.
if(i == std::numeric_limits<int>::max())
break;
}
}
......
......@@ -1125,7 +1125,7 @@ void calcDiff3LineListTrim(
}
void DiffBufferInfo::init(Diff3LineList* pD3ll, const Diff3LineVector* pD3lv,
const LineData* pldA, LineRef sizeA, const LineData* pldB, LineRef sizeB, const LineData* pldC, LineRef sizeC)
const LineData* pldA, LineCount sizeA, const LineData* pldB, LineCount sizeB, const LineData* pldC, LineCount sizeC)
{
m_pDiff3LineList = pD3ll;
m_pDiff3LineVector = pD3lv;
......
......@@ -58,12 +58,12 @@ enum e_MergeDetails
class Diff
{
public:
LineRef nofEquals;
LineCount nofEquals;
qint64 diff1;
qint64 diff2;
Diff(LineRef eq, qint64 d1, qint64 d2)
Diff(LineCount eq, qint64 d1, qint64 d2)
{
nofEquals = eq;
diff1 = d1;
......@@ -109,13 +109,13 @@ class DiffBufferInfo
const LineData* m_pLineDataA;
const LineData* m_pLineDataB;
const LineData* m_pLineDataC;
LineRef m_sizeA;
LineRef m_sizeB;
LineRef m_sizeC;
LineCount m_sizeA;
LineCount m_sizeB;
LineCount m_sizeC;
const Diff3LineList* m_pDiff3LineList;
const Diff3LineVector* m_pDiff3LineVector;
void init(Diff3LineList* d3ll, const Diff3LineVector* d3lv,
const LineData* pldA, LineRef sizeA, const LineData* pldB, LineRef sizeB, const LineData* pldC, LineRef sizeC);
const LineData* pldA, LineCount sizeA, const LineData* pldB, LineCount sizeB, const LineData* pldC, LineCount sizeC);
};
class Diff3Line
......
......@@ -261,7 +261,7 @@ void DiffTextWindow::setFirstLine(int firstLine)
{
int fontHeight = fontMetrics().lineSpacing();
int newFirstLine = std::max(0, firstLine);
LineRef newFirstLine = std::max(0, firstLine);
int deltaY = fontHeight * (d->m_firstLine - newFirstLine);
......@@ -269,7 +269,8 @@ void DiffTextWindow::setFirstLine(int firstLine)
if(d->m_bSelectionInProgress && d->m_selection.isValidFirstLine())
{
int line, pos;
LineRef line;
int pos;
convertToLinePos(d->m_lastKnownMousePos.x(), d->m_lastKnownMousePos.y(), line, pos);
d->m_selection.end(line, pos);
update();
......@@ -305,7 +306,8 @@ void DiffTextWindow::setHorizScrollOffset(int horizScrollOffset)
if(d->m_bSelectionInProgress && d->m_selection.isValidFirstLine())
{
int line, pos;
LineRef line;
int pos;
convertToLinePos(d->m_lastKnownMousePos.x(), d->m_lastKnownMousePos.y(), line, pos);
d->m_selection.end(line, pos);
update();
......@@ -338,20 +340,20 @@ int DiffTextWindow::getMaxTextWidth()
return getAtomic(d->m_maxTextWidth);
}
int DiffTextWindow::getNofLines()
LineCount DiffTextWindow::getNofLines()
{
return d->m_bWordWrap ? d->m_diff3WrapLineVector.size() : d->m_pDiff3LineVector->size();
}
int DiffTextWindow::convertLineToDiff3LineIdx(int line)
int DiffTextWindow::convertLineToDiff3LineIdx(LineRef line)
{
if(line >= 0 && d->m_bWordWrap && d->m_diff3WrapLineVector.size() > 0)
return d->m_diff3WrapLineVector[std::min(line, (int)d->m_diff3WrapLineVector.size() - 1)].diff3LineIndex;
return d->m_diff3WrapLineVector[std::min(line, d->m_diff3WrapLineVector.size() - 1)].diff3LineIndex;
else
return line;
}
int DiffTextWindow::convertDiff3LineIdxToLine(int d3lIdx)
LineRef DiffTextWindow::convertDiff3LineIdxToLine(int d3lIdx)
{
if(d->m_bWordWrap && d->m_pDiff3LineVector != nullptr && d->m_pDiff3LineVector->size() > 0)
return (*d->m_pDiff3LineVector)[std::min(d3lIdx, (int)d->m_pDiff3LineVector->size() - 1)]->sumLinesNeededForDisplay;
......@@ -429,7 +431,7 @@ void DiffTextWindow::mousePressEvent(QMouseEvent* e)
{
if(e->button() == Qt::LeftButton)
{
int line;
LineRef line;
int pos;
convertToLinePos(e->x(), e->y(), line, pos);
......@@ -493,7 +495,7 @@ void DiffTextWindow::mouseDoubleClickEvent(QMouseEvent* e)
d->m_lastKnownMousePos = e->pos();
if(e->button() == Qt::LeftButton)
{
int line;
LineRef line;
int pos;
convertToLinePos(e->x(), e->y(), line, pos);
......@@ -550,7 +552,7 @@ inline int sqr(int x) { return x * x; }
void DiffTextWindow::mouseMoveEvent(QMouseEvent* e)
{
int line;
LineRef line;
int pos;
convertToLinePos(e->x(), e->y(), line, pos);
d->m_lastKnownMousePos = e->pos();
......@@ -655,7 +657,7 @@ void DiffTextWindow::resetSelection()
update();
}
void DiffTextWindow::convertToLinePos(int x, int y, int& line, int& pos)
void DiffTextWindow::convertToLinePos(int x, int y, LineRef& line, int& pos)
{
const QFontMetrics& fm = fontMetrics();
int fontHeight = fm.lineSpacing();
......@@ -1270,10 +1272,10 @@ QString DiffTextWindow::getSelection()
return selectionString;
}
bool DiffTextWindow::findString(const QString& s, int& d3vLine, int& posInLine, bool bDirDown, bool bCaseSensitive)
bool DiffTextWindow::findString(const QString& s, LineRef& d3vLine, int& posInLine, bool bDirDown, bool bCaseSensitive)
{
int it = d3vLine;
int endIt = bDirDown ? (int)d->m_pDiff3LineVector->size() : -1;
int endIt = bDirDown ? d->m_pDiff3LineVector->size() : -1;
int step = bDirDown ? 1 : -1;
int startPos = posInLine;
......@@ -1337,7 +1339,7 @@ void DiffTextWindow::convertLineCoordsToD3LCoords(int line, int pos, int& d3LIdx
}
}
void DiffTextWindow::setSelection(int firstLine, int startPos, int lastLine, int endPos, int& l, int& p)
void DiffTextWindow::setSelection(LineRef firstLine, int startPos, LineRef lastLine, int endPos, LineRef& l, int& p)
{
d->m_selection.reset();
if(lastLine >= getNofLines())
......@@ -1418,7 +1420,7 @@ int DiffTextWindowData::convertLineOnScreenToLineInSource(int lineOnScreen, e_Co
return line;
}
void DiffTextWindow::getSelectionRange(int* pFirstLine, int* pLastLine, e_CoordType coordType)
void DiffTextWindow::getSelectionRange(LineRef* pFirstLine, LineRef* pLastLine, e_CoordType coordType)
{
if(pFirstLine)
*pFirstLine = d->convertLineOnScreenToLineInSource(d->m_selection.beginLine(), coordType, true);
......
......@@ -42,28 +42,28 @@ public:
bool bTriple
);
void reset();
void convertToLinePos( int x, int y, int& line, int& pos );
void convertToLinePos( int x, int y, LineRef& line, int& pos );
QString getSelection();
int getFirstLine();
int calcTopLineInFile( int firstLine );
int getMaxTextWidth();
int getNofLines();
LineCount getNofLines();
int getNofVisibleLines();
int getVisibleTextAreaWidth();
int convertLineToDiff3LineIdx( int line );
int convertDiff3LineIdxToLine( int d3lIdx );
int convertLineToDiff3LineIdx( LineRef line );
LineRef convertDiff3LineIdxToLine( int d3lIdx );
void convertD3LCoordsToLineCoords( int d3LIdx, int d3LPos, int& line, int& pos );
void convertLineCoordsToD3LCoords( int line, int pos, int& d3LIdx, int& d3LPos );
void convertSelectionToD3LCoords();
bool findString( const QString& s, int& d3vLine, int& posInLine, bool bDirDown, bool bCaseSensitive );
void setSelection( int firstLine, int startPos, int lastLine, int endPos, int& l, int& p );
void getSelectionRange( int* firstLine, int* lastLine, e_CoordType coordType );
bool findString( const QString& s, LineRef& d3vLine, int& posInLine, bool bDirDown, bool bCaseSensitive );
void setSelection( LineRef firstLine, int startPos, LineRef lastLine, int endPos, LineRef& l, int& p );
void getSelectionRange( LineRef* firstLine, LineRef* lastLine, e_CoordType coordType );
void setPaintingAllowed( bool bAllowPainting );
void recalcWordWrap( bool bWordWrap, int wrapLineVectorSize, int visibleTextWidth);
......@@ -75,7 +75,7 @@ Q_SIGNALS:
void scrollDiffTextWindow( int deltaX, int deltaY );
void newSelection();
void selectionEnd();
void setFastSelectorLine( int line );
void setFastSelectorLine( LineIndex line );
void gotFocus();
void lineClicked( e_SrcSelector winIdx, int line );
......
......@@ -42,7 +42,10 @@
/* The integer type of a line number. */
typedef qint32 LineRef;
typedef qint32 LineCount;
typedef qint64 GNULineRef;
typedef qint32 LineIndex;
#define LINEREF_MAX std::numeric_limits<LineRef>::max()
#define GNULINEREF_MAX std::numeric_limits<GNULineRef>::max()
static_assert(sizeof(int) >= sizeof(qint32), "Legacy LP32 systems/compilers not supported");// e.g. Windows 16-bit
......
......@@ -891,7 +891,7 @@ void KDiff3App::slotFilePrint()
m_pEventLoopForPrinting->exec();
}
LineRef totalNofLines = std::max(m_pDiffTextWindow1->getNofLines(), m_pDiffTextWindow2->getNofLines());
LineCount totalNofLines = std::max(m_pDiffTextWindow1->getNofLines(), m_pDiffTextWindow2->getNofLines());
if(m_bTripleDiff && m_pDiffTextWindow3)
totalNofLines = std::max(totalNofLines, m_pDiffTextWindow3->getNofLines());
......
......@@ -882,7 +882,7 @@ void MergeResultWindow::slotGoNextUnsolvedConflict()
/** The line is given as a index in the Diff3LineList.
The function calculates the corresponding iterator. */
void MergeResultWindow::slotSetFastSelectorLine(int line)
void MergeResultWindow::slotSetFastSelectorLine(LineIndex line)
{
MergeLineList::iterator i;
for(i = m_mergeLineList.begin(); i != m_mergeLineList.end(); ++i)
......@@ -3058,7 +3058,7 @@ QString MergeResultWindow::getString(int lineIdx)
return s;
}
bool MergeResultWindow::findString(const QString& s, int& d3vLine, int& posInLine, bool bDirDown, bool bCaseSensitive)
bool MergeResultWindow::findString(const QString& s, LineRef& d3vLine, int& posInLine, bool bDirDown, bool bCaseSensitive)
{
int it = d3vLine;
int endIt = bDirDown ? getNofLines() : -1;
......
......@@ -62,7 +62,7 @@ public:
bool isUnsolvedConflictAtCurrent();
bool isUnsolvedConflictAboveCurrent();
bool isUnsolvedConflictBelowCurrent();
bool findString( const QString& s, int& d3vLine, int& posInLine, bool bDirDown, bool bCaseSensitive );
bool findString( const QString& s, LineRef& d3vLine, int& posInLine, bool bDirDown, bool bCaseSensitive );
void setSelection( int firstLine, int startPos, int lastLine, int endPos );
void setOverviewMode( Overview::e_OverviewMode eOverviewMode );
Overview::e_OverviewMode getOverviewMode();
......@@ -86,9 +86,9 @@ public Q_SLOTS:
void slotUnsolve();
void slotMergeHistory();
void slotRegExpAutoMerge();
void slotSplitDiff( int firstD3lLineIdx, int lastD3lLineIdx );
void slotJoinDiffs( int firstD3lLineIdx, int lastD3lLineIdx );
void slotSetFastSelectorLine(int);
void slotSplitDiff( LineIndex firstD3lLineIdx, LineIndex lastD3lLineIdx );
void slotJoinDiffs( LineIndex firstD3lLineIdx, LineIndex lastD3lLineIdx );
void slotSetFastSelectorLine(LineIndex);
void setPaintingAllowed(bool);
void updateSourceMask();
void slotStatusMessageChanged( const QString& );
......
......@@ -56,7 +56,7 @@ bool g_bIgnoreTrivialMatches = true;
static void debugLineCheck(Diff3LineList& d3ll, LineRef size, e_SrcSelector idx)
{
Diff3LineList::iterator it = d3ll.begin();
LineRef i = 0;
int i = 0;
for(it = d3ll.begin(); it != d3ll.end(); ++it)
{
......@@ -2303,8 +2303,8 @@ void ManualDiffHelpList::insertEntry(e_SrcSelector winIdx, LineRef firstLine, Li
ManualDiffHelpList::iterator i;
for(i = begin(); i != end(); ++i)
{
int& l1 = i->firstLine(winIdx);
int& l2 = i->lastLine(winIdx);
LineRef& l1 = i->firstLine(winIdx);
LineRef& l2 = i->lastLine(winIdx);
if(l1 >= 0 && l2 >= 0)
{
if((firstLine <= l1 && lastLine >= l1) || (firstLine <= l2 && lastLine >= l2))
......
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