Commit 90bf629a authored by Michael Reeves's avatar Michael Reeves

Refactor continue convertion to LineRef and friends

QtNumberType is now used to help sort out depenacies on Qt's
"int-for-all" decision.
parent 7c314667
......@@ -21,13 +21,13 @@
#ifndef LINEREF_H
#define LINEREF_H
#include "TypeUtils.h"
#include <stdlib.h>
#include <type_traits>
#include <QtGlobal>
#define TYPE_MAX(x) std::numeric_limits<x>::max()
#define TYPE_MIN(x) std::numeric_limits<x>::min()
class LineRef
{
public:
......@@ -89,7 +89,6 @@ static_assert(std::is_convertible<LineRef, int>::value, "Can not convert LineRef
static_assert(std::is_convertible<int, LineRef>::value, "Can not convert int to LineRef.");
typedef LineRef::LineType LineCount;
typedef size_t PtrDiffRef;
typedef LineRef::LineType LineIndex;
#endif
......@@ -85,8 +85,8 @@ class MergeLine
{
public:
Diff3LineList::const_iterator id3l;
int d3lLineIdx = -1; // Needed to show the correct window pos.
int srcRangeLength = 0; // how many src-lines have this properties
LineIndex d3lLineIdx = -1; // Needed to show the correct window pos.
LineCount srcRangeLength = 0; // how many src-lines have this properties
e_MergeDetails mergeDetails = eDefault;
bool bConflict = false;
bool bWhiteSpaceConflict = false;
......
......@@ -59,7 +59,7 @@ void Overview::setRange(int firstLine, int pageHeight)
m_pageHeight = pageHeight;
update();
}
void Overview::setFirstLine(int firstLine)
void Overview::setFirstLine(QtNumberType firstLine)
{
m_firstLine = firstLine;
update();
......
......@@ -33,15 +33,15 @@ public:
e_OverviewMode getOverviewMode();
public Q_SLOTS:
void setFirstLine(int firstLine);
void setFirstLine(QtNumberType firstLine);
void slotRedraw();
Q_SIGNALS:
void setLine(int);
void setLine(LineRef);
private:
const Diff3LineList* m_pDiff3LineList;
Options* m_pOptions;
bool m_bTripleDiff;
int m_firstLine;
LineRef m_firstLine;
int m_pageHeight;
QPixmap m_pixmap;
e_OverviewMode m_eOverviewMode;
......
......@@ -598,7 +598,7 @@ bool SourceData::FileData::preprocess(bool bPreserveCR, QTextCodec* pEncoding)
const QChar* p = m_unicodeBuf.unicode();
m_bIsText = true;
int lines = 1;
LineCount lines = 1;
m_bIncompleteConversion = false;
for(i = 0; i < ucSize; ++i)
{
......
/**
*
* Copyright (C) 2018 Michael Reeves
*
* This file is part of Kdiff3.
*
* Kdiff3 is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 of the License, or
* (at your option) any later version.
*
* Kdiff3 is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Kdiff3. If not, see <http://www.gnu.org/licenses/>.
*
*/
#ifndef TYPEUTILS_H
#define TYPEUTILS_H
#include <stdlib.h>
#include <type_traits>
#include <QtGlobal>
#define TYPE_MAX(x) std::numeric_limits<x>::max()
#define TYPE_MIN(x) std::numeric_limits<x>::min()
typedef size_t PtrDiffRef;
typedef qint32 QtNumberType;//Qt insists on one type for all but does not create a typedef for it.
static_assert(sizeof(int) >= sizeof(qint32), "Legacy LP32 systems/compilers not supported"); // e.g. Windows 16-bit
#endif
......@@ -1459,5 +1459,5 @@ void Diff3LineList::calcDiff3LineVector(Diff3LineVector& d3lv)
{
d3lv[j] = &(*i);
}
Q_ASSERT(j == (int)d3lv.size());
Q_ASSERT(j == d3lv.size());
}
......@@ -45,7 +45,6 @@
/* The integer type of a line number. */
typedef qint64 GNULineRef;
#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
static_assert(std::is_signed<GNULineRef>::value, "GNULineRef must be signed.");
static_assert(sizeof(GNULineRef) >= sizeof(size_t), "GNULineRef must be able to receive size_t values.");
......
......@@ -860,7 +860,7 @@ void KDiff3App::slotFilePrint()
QPaintDevice* pPaintDevice = painter.device();
int dpiy = pPaintDevice->logicalDpiY();
int columnDistance = (int)((0.5 / 2.54) * dpiy); // 0.5 cm between the columns
int columnDistance = qRound((0.5 / 2.54) * dpiy); // 0.5 cm between the columns
int columns = m_bTripleDiff ? 3 : 2;
int columnWidth = (pPaintDevice->width() - (columns - 1) * columnDistance) / columns;
......
......@@ -134,7 +134,7 @@ void KDiff3Part::getNameAndVersion(const QString& str, const QString& lineStart,
}
int vpos = str.lastIndexOf("\t", -1);
if(vpos > 0 && vpos > (int)pos2)
if(vpos > 0 && vpos > pos2)
{
version = str.mid(vpos + 1);
while(!version.right(1)[0].isLetterOrNumber())
......
......@@ -575,7 +575,7 @@ void MergeResultWindow::merge(bool bAutoSolve, e_SrcSelector defaultSelector, bo
update();
}
void MergeResultWindow::setFirstLine(int firstLine)
void MergeResultWindow::setFirstLine(QtNumberType firstLine)
{
m_firstLine = std::max(0, firstLine);
update();
......@@ -1202,7 +1202,7 @@ QString calcHistorySortKey(const QString& keyOrder, QRegExp& matchedRegExpr, con
continue;
bool bOk = false;
int groupIdx = keyIt->toInt(&bOk);
if(!bOk || groupIdx < 0 || groupIdx > (int)parenthesesGroupList.size())
if(!bOk || groupIdx < 0 || groupIdx > parenthesesGroupList.size())
continue;
QString s = matchedRegExpr.cap(groupIdx);
if(groupIdx == 0)
......@@ -2026,7 +2026,7 @@ void MergeResultWindow::focusInEvent(QFocusEvent* e)
QWidget::focusInEvent(e);
}
int MergeResultWindow::convertToLine(int y)
LineRef MergeResultWindow::convertToLine(int y)
{
const QFontMetrics& fm = fontMetrics();
int fontHeight = fm.lineSpacing();
......@@ -2034,7 +2034,7 @@ int MergeResultWindow::convertToLine(int y)
int yOffset = topLineYOffset - m_firstLine * fontHeight;
int line = std::min((y - yOffset) / fontHeight, m_nofLines - 1);
LineRef line = std::min((y - yOffset) / fontHeight, m_nofLines - 1);
return line;
}
......@@ -2044,11 +2044,11 @@ void MergeResultWindow::mousePressEvent(QMouseEvent* e)
int xOffset = getTextXOffset();
int line = convertToLine(e->y());
LineRef line = convertToLine(e->y());
QString s = getString(line);
QTextLayout textLayout(s, font(), this);
getTextLayoutForLine(line, s, textLayout);
int pos = textLayout.lineAt(0).xToCursor(e->x() - textLayout.position().x());
QtNumberType pos = textLayout.lineAt(0).xToCursor(e->x() - textLayout.position().x());
bool bLMB = e->button() == Qt::LeftButton;
bool bMMB = e->button() == Qt::MidButton;
......@@ -2058,7 +2058,7 @@ void MergeResultWindow::mousePressEvent(QMouseEvent* e)
{
m_cursorXPos = 0;
m_cursorOldXPixelPos = 0;
m_cursorYPos = std::max(line, 0);
m_cursorYPos = std::max((LineRef::LineType)line, 0);
int l = 0;
MergeLineList::iterator i = m_mergeLineList.begin();
for(i = m_mergeLineList.begin(); i != m_mergeLineList.end(); ++i)
......@@ -2083,7 +2083,7 @@ void MergeResultWindow::mousePressEvent(QMouseEvent* e)
else if(bLMB) // Normal cursor placement
{
pos = std::max(pos, 0);
line = std::max(line, 0);
line = std::max((LineRef::LineType)line, 0);
if(e->QInputEvent::modifiers() & Qt::ShiftModifier)
{
if(!m_selection.isValidFirstLine())
......@@ -2110,7 +2110,7 @@ void MergeResultWindow::mousePressEvent(QMouseEvent* e)
else if(bMMB) // Paste clipboard
{
pos = std::max(pos, 0);
line = std::max(line, 0);
line = std::max((LineRef::LineType)line, 0);
m_selection.reset();
m_cursorXPos = pos;
......@@ -2125,7 +2125,7 @@ void MergeResultWindow::mouseDoubleClickEvent(QMouseEvent* e)
{
if(e->button() == Qt::LeftButton)
{
int line = convertToLine(e->y());
LineRef line = convertToLine(e->y());
QString s = getString(line);
QTextLayout textLayout(s, font(), this);
getTextLayoutForLine(line, s, textLayout);
......@@ -2169,7 +2169,7 @@ void MergeResultWindow::mouseReleaseEvent(QMouseEvent* e)
void MergeResultWindow::mouseMoveEvent(QMouseEvent* e)
{
int line = convertToLine(e->y());
LineRef line = convertToLine(e->y());
QString s = getString(line);
QTextLayout textLayout(s, font(), this);
getTextLayoutForLine(line, s, textLayout);
......@@ -2290,7 +2290,7 @@ void MergeResultWindow::keyPressEvent(QKeyEvent* e)
{
if(deleteSelection2(str, x, y, mlIt, melIt)) break;
if(!melIt->isEditableText()) break;
if(x >= (int)str.length())
if(x >= str.length())
{
if(y < m_nofLines - 1)
{
......@@ -2400,7 +2400,7 @@ void MergeResultWindow::keyPressEvent(QKeyEvent* e)
MergeEditLine mel(mlIt->id3l); // Associate every mel with an id3l, even if not really valid.
mel.setString(indentation + str.mid(x));
if(x < (int)str.length()) // Cut off the old line.
if(x < str.length()) // Cut off the old line.
{
// Since ps possibly points into melIt->str, first copy it into a temporary.
QString temp = str.left(x);
......@@ -2487,13 +2487,13 @@ void MergeResultWindow::keyPressEvent(QKeyEvent* e)
}
else
{
while(x < (int)str.length() && (str[x] == ' ' || str[x] == '\t'))
while(x < str.length() && (str[x] == ' ' || str[x] == '\t'))
{
int newX = textLayoutOrig.nextCursorPosition(x);
if(newX == x) break;
x = newX;
}
while(x < (int)str.length() && (str[x] != ' ' && str[x] != '\t'))
while(x < str.length() && (str[x] != ' ' && str[x] != '\t'))
{
int newX = textLayoutOrig.nextCursorPosition(x);
if(newX == x) break;
......
......@@ -71,7 +71,7 @@ public:
void slotUpdateAvailabilities(const bool bMergeEditorVisible, const bool m_bTripleDiff);
public Q_SLOTS:
void setFirstLine(int firstLine);
void setFirstLine(QtNumberType firstLine);
void setHorizScrollOffset(int horizScrollOffset);
void slotGoCurrent();
......@@ -107,7 +107,7 @@ public Q_SLOTS:
Q_SIGNALS:
void scrollMergeResultWindow( int deltaX, int deltaY );
void modifiedChanged(bool bModified);
void setFastSelectorRange( int line1, int nofLines );
void setFastSelectorRange( LineRef line1, LineCount nofLines );
void sourceMask( int srcMask, int enabledMask );
void resizeSignal();
void selectionEnd();
......@@ -191,7 +191,7 @@ private:
int srcSelect, e_MergeDetails mergeDetails, int rangeMark, bool bUserModified, bool bLineRemoved, bool bWhiteSpaceConflict
);
void setFastSelector(MergeLineList::iterator i);
int convertToLine( int y );
LineRef convertToLine( QtNumberType y );
bool event(QEvent*) override;
void mousePressEvent ( QMouseEvent* e ) override;
void mouseDoubleClickEvent ( QMouseEvent* e ) override;
......@@ -203,7 +203,7 @@ private:
void focusInEvent( QFocusEvent* e ) override;
QPixmap m_pixmap;
int m_firstLine;
LineRef m_firstLine;
int m_horizScrollOffset;
LineCount m_nofLines;
int m_maxTextWidth;
......
......@@ -422,7 +422,7 @@ class OptionEncodingComboBox : public QComboBox, public OptionCodec
if(codecName == defaultName())
saveDefaultIndex(m_codecVec.size());
QString itemText = visibleCodecName.isEmpty() ? codecName : visibleCodecName + QStringLiteral(" (") + codecName + QStringLiteral(")");
addItem(itemText, (int)m_codecVec.size());
addItem(itemText, m_codecVec.size());
m_codecVec.push_back(c);
}
}
......
......@@ -2054,7 +2054,7 @@ void KDiff3App::slotEditFindNext()
{
m_pDiffTextWindow1->setSelection(d3vLine, posInLine, d3vLine, posInLine + s.length(), l, p);
m_pDiffVScrollBar->setValue(l - m_pDiffVScrollBar->pageStep() / 2);
m_pHScrollBar->setValue(std::max(0, p + (int)s.length() - m_pHScrollBar->pageStep()));
m_pHScrollBar->setValue(std::max(0, p + s.length() - m_pHScrollBar->pageStep()));
m_pFindDialog->currentLine = d3vLine;
m_pFindDialog->currentPos = posInLine + 1;
return;
......@@ -2073,7 +2073,7 @@ void KDiff3App::slotEditFindNext()
{
m_pDiffTextWindow2->setSelection(d3vLine, posInLine, d3vLine, posInLine + s.length(), l, p);
m_pDiffVScrollBar->setValue(l - m_pDiffVScrollBar->pageStep() / 2);
m_pHScrollBar->setValue(std::max(0, p + (int)s.length() - m_pHScrollBar->pageStep()));
m_pHScrollBar->setValue(std::max(0, p + s.length() - m_pHScrollBar->pageStep()));
m_pFindDialog->currentLine = d3vLine;
m_pFindDialog->currentPos = posInLine + 1;
return;
......@@ -2092,7 +2092,7 @@ void KDiff3App::slotEditFindNext()
{
m_pDiffTextWindow3->setSelection(d3vLine, posInLine, d3vLine, posInLine + s.length(), l, p);
m_pDiffVScrollBar->setValue(l - m_pDiffVScrollBar->pageStep() / 2);
m_pHScrollBar->setValue(std::max(0, p + (int)s.length() - m_pHScrollBar->pageStep()));
m_pHScrollBar->setValue(std::max(0, p + s.length() - m_pHScrollBar->pageStep()));
m_pFindDialog->currentLine = d3vLine;
m_pFindDialog->currentPos = posInLine + 1;
return;
......@@ -2111,7 +2111,7 @@ void KDiff3App::slotEditFindNext()
{
m_pMergeResultWindow->setSelection(d3vLine, posInLine, d3vLine, posInLine + s.length());
m_pMergeVScrollBar->setValue(d3vLine - m_pMergeVScrollBar->pageStep() / 2);
m_pHScrollBar->setValue(std::max(0, posInLine + (int)s.length() - m_pHScrollBar->pageStep()));
m_pHScrollBar->setValue(std::max(0, posInLine + s.length() - m_pHScrollBar->pageStep()));
m_pFindDialog->currentLine = d3vLine;
m_pFindDialog->currentPos = posInLine + 1;
return;
......
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