Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
f05656e
Add the Cppcheck file extension
GAlexDark Jun 15, 2023
33327d7
Add Cppcheck folder
GAlexDark Jun 15, 2023
aaaea07
Fix error: using typedef-name after 'class'
GAlexDark Jun 15, 2023
e3aec4e
Fix error: invalid conversion from 'int' to 'const char*'
GAlexDark Jun 15, 2023
9c0ad4e
Port QStringRef (deprecated) to QStringView
GAlexDark Jun 15, 2023
b37bb8a
Add QVectorIterator class declaration
GAlexDark Jun 15, 2023
f6c17c9
Port QFileInfo::created() (deprecated) to QFileInfo::birthTime()
GAlexDark Jun 15, 2023
3542e3a
Port qSort() (deprecated) to std::sort()
GAlexDark Jun 15, 2023
51a5888
Port QDateTime::toTime_t() (deprecated) to QDateTime::toSecsSinceEpoch()
GAlexDark Jun 15, 2023
a0b689d
Port QDateTime::fromTime_t() (deprecated)
GAlexDark Jun 15, 2023
1b2b6ad
Port Qt enum values (deprecated) to QLocale enum values
GAlexDark Jun 15, 2023
d03b587
CWE: 398. Missing member copy
GAlexDark Jun 16, 2023
b5fe0bc
CWE: 398. Parameter passed By Value
GAlexDark Jun 16, 2023
26d0a2e
CWE: 398. Parameter passed by value
GAlexDark Jun 16, 2023
e12b0e2
CWE: 398. Uninit member var
GAlexDark Jun 16, 2023
53a6585
CWE: 398. Parameter passed by value
GAlexDark Jun 16, 2023
6191f3b
CWE: 398. Uninit member var
GAlexDark Jun 16, 2023
6f3f5ca
CWE: 398. Uninit member var
GAlexDark Jun 16, 2023
1ffca09
CWE: 398. Uninit member var
GAlexDark Jun 16, 2023
005c76e
Fix error: invalid conversion from 'int' to 'QTextDocument::FindFlag'
GAlexDark Jun 16, 2023
75bfafd
Port QFontMetrics::width() (obsolete)
GAlexDark Jun 16, 2023
5ea752e
Port QWheelEvent::delta() (obsolete)
GAlexDark Jun 16, 2023
1a373f2
Fix error: conversion from 'int' to 'QChar' is ambiguous
GAlexDark Jun 16, 2023
6198311
Port QWheelEvent::delta() (obsolete)
GAlexDark Jun 16, 2023
1e5617d
Port QString::SkipEmptyParts (obsolete)
GAlexDark Jun 16, 2023
47c2ec4
Fixed implicitly cast to the bool type.
GAlexDark Jun 18, 2023
04e05b6
Fixed m_pixmapItem initialization
GAlexDark Jun 18, 2023
3a8881b
Maybe 'else' keyword is missing.
GAlexDark Jun 18, 2023
bcf04be
Fixed expression
GAlexDark Jun 18, 2023
0a26284
Fixed CWE: 398. Uninit member
GAlexDark Jun 18, 2023
5ec98dc
Fixed pointer check after use
GAlexDark Jun 18, 2023
2cb5f3d
Fixed an odd precise comparison.
GAlexDark Jun 18, 2023
41659b1
Fixed 'false' value is implicitly cast to the integer type.
GAlexDark Jun 18, 2023
20a1b90
Fixed an odd precise comparison.
GAlexDark Jun 18, 2023
4843be6
Fixed comparison of integers of different types
GAlexDark Jun 18, 2023
c32946a
Update README.md
GAlexDark Jun 18, 2023
3d1eab6
Fix error: unknown type name 'QDateTime'
GAlexDark Jun 18, 2023
20b0e0c
Fixed(?): value 'PE_ContentType' not handled in switch
GAlexDark Jun 19, 2023
f1abaa4
Revert "Fixed an odd precise comparison."
GAlexDark Jun 21, 2023
e5ce85d
Fixed an odd precise comparison.
GAlexDark Jun 21, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,6 @@ lib/*
*.idb
*.ncb
*.suo

*.cppcheck
/*-cppcheck-build-dir
14 changes: 8 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,15 @@ Microsoft Office and can be used in any platform that **Qt 5.2** or newer suppor

* Put the source code in any directory you like

* Run following command at the toplevel directory of the project
* Run following command at the toplevel directory of the project:

| | Windows Qt MINGW | Windows Qt MSVC |
|--------------------|----------------------------|---------------------|
| ```qmake``` | ```qmake``` | ```qmake``` |
| ```make``` | ```mingw32-make``` | ```nmake``` |
| | ```mingw32-make check``` | ```nmake check``` |
| ```make install``` | ```mingw32-make install``` | ```nmake install``` |

```
qmake
make
make install
```

The library, the header files, and others will be installed to your system.

Expand Down
90 changes: 84 additions & 6 deletions examples/officeopenxml/opc_package_viewer/binedit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ BinEdit::BinEdit(QWidget *parent)
m_addressBytes = 4;
init();
m_unmodifiedState = 0;
m_readOnly = false;
m_readOnly = 0;
m_hexCursor = true;
m_cursorPosition = 0;
m_anchorPosition = 0;
Expand Down Expand Up @@ -130,27 +130,63 @@ void BinEdit::init()
m_descent = fm.descent();
m_ascent = fm.ascent();
m_lineHeight = fm.lineSpacing();

#if (QT_VERSION >= QT_VERSION_CHECK(5,15,14))
m_charWidth = fm.horizontalAdvance(QChar(QLatin1Char('M')));
m_margin = m_charWidth;
m_columnWidth = 2 * m_charWidth + fm.horizontalAdvance(QChar(QLatin1Char(' ')));
#else
m_charWidth = fm.width(QChar(QLatin1Char('M')));
m_margin = m_charWidth;
m_columnWidth = 2 * m_charWidth + fm.width(QChar(QLatin1Char(' ')));
#endif

m_numLines = m_size / m_bytesPerLine + 1;
m_numVisibleLines = viewport()->height() / m_lineHeight;
m_textWidth = m_bytesPerLine * m_charWidth + m_charWidth;
#if (QT_VERSION >= QT_VERSION_CHECK(5,15,14))
int m_numberWidth = fm.horizontalAdvance(QChar(QLatin1Char('9')));
#else
int m_numberWidth = fm.width(QChar(QLatin1Char('9')));
#endif
m_labelWidth =
2*m_addressBytes * m_numberWidth + (m_addressBytes - 1)/2 * m_charWidth;

int expectedCharWidth = m_columnWidth / 3;
const char *hex = "0123456789abcdef";
m_isMonospacedFont = true;

#if (QT_VERSION >= QT_VERSION_CHECK(5,15,14))
while (*hex) {
if (fm.horizontalAdvance(QLatin1Char(*hex)) != expectedCharWidth) {
m_isMonospacedFont = false;
break;
}
++hex;
}
#else
while (*hex) {
if (fm.width(QLatin1Char(*hex)) != expectedCharWidth) {
m_isMonospacedFont = false;
break;
}
++hex;
}
#endif


#if (QT_VERSION >= QT_VERSION_CHECK(5,15,14))
if (m_isMonospacedFont && fm.horizontalAdvance(QLatin1String("M M ")) != m_charWidth * 4) {
// On Qt/Mac, monospace font widths may have a fractional component
// This breaks the assumption that width("MMM") == width('M') * 3

m_isMonospacedFont = false;
m_columnWidth = fm.horizontalAdvance(QLatin1String("MMM"));
m_labelWidth = m_addressBytes == 4
? fm.horizontalAdvance(QLatin1String("MMMM:MMMM"))
: fm.horizontalAdvance(QLatin1String("MMMM:MMMM:MMMM:MMMM"));
}
#else
if (m_isMonospacedFont && fm.width(QLatin1String("M M ")) != m_charWidth * 4) {
// On Qt/Mac, monospace font widths may have a fractional component
// This breaks the assumption that width("MMM") == width('M') * 3
Expand All @@ -161,6 +197,7 @@ void BinEdit::init()
? fm.width(QLatin1String("MMMM:MMMM"))
: fm.width(QLatin1String("MMMM:MMMM:MMMM:MMMM"));
}
#endif

horizontalScrollBar()->setRange(0, 2 * m_margin + m_bytesPerLine * m_columnWidth
+ m_labelWidth + m_textWidth - viewport()->width());
Expand Down Expand Up @@ -461,7 +498,11 @@ void BinEdit::changeEvent(QEvent *e)
void BinEdit::wheelEvent(QWheelEvent *e)
{
if (e->modifiers() & Qt::ControlModifier) {
#if (QT_VERSION >= QT_VERSION_CHECK(5,15,14))
const int delta = e->pixelDelta().y();
#else
const int delta = e->delta();
#endif
if (delta < 0)
zoomOut();
else if (delta > 0)
Expand Down Expand Up @@ -505,8 +546,12 @@ int BinEdit::posAt(const QPoint &pos) const
break;
QChar qc(QLatin1Char(dataAt(dataPos)));
if (!qc.isPrint())
qc = 0xB7;
qc = QChar(0xB7);
#if (QT_VERSION >= QT_VERSION_CHECK(5,15,14))
x -= fontMetrics().horizontalAdvance(qc);
#else
x -= fontMetrics().width(qc);
#endif
if (x <= 0)
break;
}
Expand Down Expand Up @@ -787,7 +832,7 @@ void BinEdit::paintEvent(QPaintEvent *e)
break;
QChar qc(QLatin1Char(dataAt(pos, isOld)));
if (qc.unicode() >= 127 || !qc.isPrint())
qc = 0xB7;
qc = QChar(0xB7);
printable += qc;
}
} else {
Expand Down Expand Up @@ -830,20 +875,36 @@ void BinEdit::paintEvent(QPaintEvent *e)

if (color.isValid()) {
painter.fillRect(item_x - m_charWidth/2, y-m_ascent, m_columnWidth, m_lineHeight, color);
#if (QT_VERSION >= QT_VERSION_CHECK(5,15,14))
int printable_item_x = -xoffset + m_margin + m_labelWidth + m_bytesPerLine * m_columnWidth + m_charWidth
+ fm.horizontalAdvance(printable.left(c));
painter.fillRect(printable_item_x, y-m_ascent,
fm.horizontalAdvance(printable.at(c)),
m_lineHeight, color);
#else
int printable_item_x = -xoffset + m_margin + m_labelWidth + m_bytesPerLine * m_columnWidth + m_charWidth
+ fm.width(printable.left(c));
painter.fillRect(printable_item_x, y-m_ascent,
fm.width(printable.at(c)),
m_lineHeight, color);
#endif
}

if (!isFullySelected && pos >= selStart && pos <= selEnd) {
selectionRect |= QRect(item_x - m_charWidth/2, y-m_ascent, m_columnWidth, m_lineHeight);
#if (QT_VERSION >= QT_VERSION_CHECK(5,15,14))
int printable_item_x = -xoffset + m_margin + m_labelWidth + m_bytesPerLine * m_columnWidth + m_charWidth
+ fm.horizontalAdvance(printable.left(c));
printableSelectionRect |= QRect(printable_item_x, y-m_ascent,
fm.horizontalAdvance(printable.at(c)),
m_lineHeight);
#else
int printable_item_x = -xoffset + m_margin + m_labelWidth + m_bytesPerLine * m_columnWidth + m_charWidth
+ fm.width(printable.left(c));
printableSelectionRect |= QRect(printable_item_x, y-m_ascent,
fm.width(printable.at(c)),
m_lineHeight);
#endif
}
}
}
Expand Down Expand Up @@ -878,8 +939,13 @@ void BinEdit::paintEvent(QPaintEvent *e)
painter.drawRect(cursorRect.adjusted(0, 0, 0, -1));
painter.restore();
if (m_hexCursor && m_cursorVisible) {
#if (QT_VERSION >= QT_VERSION_CHECK(5,15,14))
if (m_lowNibble)
cursorRect.adjust(fm.horizontalAdvance(itemString.left(1)), 0, 0, 0);
#else
if (m_lowNibble)
cursorRect.adjust(fm.width(itemString.left(1)), 0, 0, 0);
#endif
painter.fillRect(cursorRect, Qt::red);
painter.save();
painter.setClipRect(cursorRect);
Expand All @@ -893,8 +959,13 @@ void BinEdit::paintEvent(QPaintEvent *e)

if (isFullySelected) {
painter.save();
#if (QT_VERSION >= QT_VERSION_CHECK(5,15,14))
painter.fillRect(text_x, y-m_ascent, fm.horizontalAdvance(printable), m_lineHeight,
palette().highlight());
#else
painter.fillRect(text_x, y-m_ascent, fm.width(printable), m_lineHeight,
palette().highlight());
#endif
painter.setPen(palette().highlightedText().color());
painter.drawText(text_x, y, printable);
painter.restore();
Expand All @@ -911,10 +982,17 @@ void BinEdit::paintEvent(QPaintEvent *e)
}

if (cursor >= 0 && !printable.isEmpty()) {
#if (QT_VERSION >= QT_VERSION_CHECK(5,15,14))
QRect cursorRect(text_x + fm.horizontalAdvance(printable.left(cursor)),
y-m_ascent,
fm.horizontalAdvance(printable.at(cursor)),
m_lineHeight);
#else
QRect cursorRect(text_x + fm.width(printable.left(cursor)),
y-m_ascent,
fm.width(printable.at(cursor)),
m_lineHeight);
#endif
painter.save();
if (m_hexCursor || !m_cursorVisible) {
painter.setPen(Qt::red);
Expand Down Expand Up @@ -1216,7 +1294,7 @@ QString BinEdit::toolTip(const QHelpEvent *helpEvent) const
asDouble(selStart, doubleValueOld, true);
str << tableRowStartC << tr("<i>double</i>&nbsp;value:") << numericTableRowSepC
<< doubleValue << tableRowEndC;
if (doubleValue != doubleValueOld)
if (!qFuzzyCompare(doubleValue, doubleValueOld))
str << tableRowStartC << tr("Previous <i>double</i>&nbsp;value:") << numericTableRowSepC
<< doubleValueOld << tableRowEndC;
str << "</table>";
Expand All @@ -1230,7 +1308,7 @@ QString BinEdit::toolTip(const QHelpEvent *helpEvent) const
asFloat(selStart, floatValueOld, true);
str << tableRowStartC << tr("<i>float</i>&nbsp;value:") << numericTableRowSepC
<< floatValue << tableRowEndC;
if (floatValue != floatValueOld)
if (!qFuzzyCompare(floatValue, floatValueOld))
str << tableRowStartC << tr("Previous <i>float</i>&nbsp;value:") << numericTableRowSepC
<< floatValueOld << tableRowEndC;

Expand Down Expand Up @@ -1330,7 +1408,7 @@ void BinEdit::keyPressEvent(QKeyEvent *e)
} else {
if (c.unicode() >= 128 || !c.isPrint())
continue;
changeData(m_cursorPosition, c.unicode(), m_cursorPosition + 1);
changeData(m_cursorPosition, c.unicode(), true);
setCursorPosition(m_cursorPosition + 1);
}
setBlinkingCursorEnabled(true);
Expand Down
4 changes: 2 additions & 2 deletions examples/officeopenxml/opc_package_viewer/binedit.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ class BinEdit : public QAbstractScrollArea
bool isReadOnly() const;

int find(const QByteArray &pattern, int from = 0,
QTextDocument::FindFlags findFlags = 0);
QTextDocument::FindFlags findFlags = QTextDocument::FindFlags());

void selectAll();
void clear();
Expand All @@ -110,7 +110,7 @@ class BinEdit : public QAbstractScrollArea

public Q_SLOTS:
void highlightSearchResults(const QByteArray &pattern,
QTextDocument::FindFlags findFlags = 0);
QTextDocument::FindFlags findFlags = QTextDocument::FindFlags());
void copy(bool raw = false);
void setNewWindowRequestAllowed(bool c);

Expand Down
8 changes: 6 additions & 2 deletions examples/officeopenxml/opc_package_viewer/imagewidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ ImageWidgetPrivate::ImageWidgetPrivate(ImageWidget *q) :
m_scaleMax = 64;
m_wheelScaleEnabled = true;
m_autoAdjustEnabled = false;
m_pixmapItem = nullptr;
}

/*!
Expand Down Expand Up @@ -195,7 +196,7 @@ bool ImageWidget::isMouseWheelEnabled() const
*/
void ImageWidget::setCurrentScale(double factor)
{
if (factor == 0) {
if (qFuzzyCompare(factor, 0)) {
if (!d->m_autoAdjustEnabled) {
d->m_autoAdjustEnabled = true;
d->doAutoFit();
Expand Down Expand Up @@ -245,8 +246,11 @@ void ImageWidget::wheelEvent(QWheelEvent *event)
if (d->m_wheelScaleEnabled) {
//Disable auto fit!!
d->m_autoAdjustEnabled = false;

#if (QT_VERSION >= QT_VERSION_CHECK(5,15,14))
double numDegrees = -event->angleDelta().y() / 8.0;
#else
double numDegrees = -event->delta() / 8.0;
#endif
double numSteps = numDegrees / 15.0;
double factor = pow(1.125, numSteps);

Expand Down
2 changes: 1 addition & 1 deletion examples/officeopenxml/opc_packages_diff/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ void MainWindow::onRunButtonClicked()
return;
}

QStringList args = ui->diffArgumentsEdit->text().split(QRegularExpression("\\s+"), QString::SkipEmptyParts);
QStringList args = ui->diffArgumentsEdit->text().split(QRegularExpression("\\s+"), Qt::SkipEmptyParts);
for (int i=0; i<args.size(); ++i) {
if (args[i] == QLatin1String("%1"))
args[i] = m_dir1->path();
Expand Down
41 changes: 31 additions & 10 deletions src/3rdParty/karchive/src/karchive.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ bool KArchive::close()
closeSucceeded = d->saveFile->commit();
delete d->saveFile;
d->saveFile = 0;
} if (d->deviceOwned) {
} else if (d->deviceOwned) {
delete d->dev; // we created it ourselves in open()
}

Expand Down Expand Up @@ -234,9 +234,15 @@ bool KArchive::addLocalFile(const QString &fileName, const QString &destName)
if (symLinkTarget.isEmpty()) { // Mac or Windows
symLinkTarget = fileInfo.symLinkTarget();
}
QDateTime fileWasCreated;
#if (QT_VERSION >= QT_VERSION_CHECK(5,13,0))
fileWasCreated = fileInfo.birthTime();
#else
fileWasCreated = fileInfo.created();
#endif
return writeSymLink(destName, symLinkTarget, fileInfo.owner(),
fileInfo.group(), fi.st_mode, fileInfo.lastRead(), fileInfo.lastModified(),
fileInfo.created());
fileWasCreated);
}/*end if*/

qint64 size = fileInfo.size();
Expand All @@ -249,9 +255,14 @@ bool KArchive::addLocalFile(const QString &fileName, const QString &destName)
//qWarning() << "couldn't open file " << fileName;
return false;
}

QDateTime fileWasCreated;
#if (QT_VERSION >= QT_VERSION_CHECK(5,13,0))
fileWasCreated = fileInfo.birthTime();
#else
fileWasCreated = fileInfo.created();
#endif
if (!prepareWriting(destName, fileInfo.owner(), fileInfo.group(), size,
fi.st_mode, fileInfo.lastRead(), fileInfo.lastModified(), fileInfo.created())) {
fi.st_mode, fileInfo.lastRead(), fileInfo.lastModified(), fileWasCreated)) {
//qWarning() << " prepareWriting" << destName << "failed";
return false;
}
Expand Down Expand Up @@ -316,9 +327,11 @@ bool KArchive::writeFile(const QString &name, const QByteArray &data,

// Write data
// Note: if data is null, don't call write, it would terminate the KCompressionDevice
if (data.constData() && size && !writeData(data.constData(), size)) {
//qWarning() << "writeData failed";
return false;
if (!data.isNull() && !data.isEmpty()) {
if (!writeData(data.constData(), size)) {
//qWarning() << "writeData failed";
return false;
}
}

if (!finishWriting(size)) {
Expand Down Expand Up @@ -515,7 +528,13 @@ QDateTime KArchivePrivate::time_tToDateTime(uint time_t)
if (time_t == uint(-1)) {
return QDateTime();
}
return QDateTime::fromTime_t(time_t);
QDateTime retVal;
#if (QT_VERSION >= QT_VERSION_CHECK(5,13,0))
retVal = QDateTime::fromSecsSinceEpoch(time_t);
#else
retVal = QDateTime::fromTime_t(time_t);
#endif
return retVal;
}

////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -874,9 +893,11 @@ bool KArchiveDirectory::copyTo(const QString &dest, bool recursiveCopy) const
}
}
} while (!dirStack.isEmpty());

#if (QT_VERSION >= QT_VERSION_CHECK(5,13,0))
std::sort(fileList.begin(), fileList.end(), sortByPosition); // sort on d->pos, so we have a linear access
#else
qSort(fileList.begin(), fileList.end(), sortByPosition); // sort on d->pos, so we have a linear access

#endif
for (QList<const KArchiveFile *>::const_iterator it = fileList.constBegin(), end = fileList.constEnd();
it != end; ++it) {
const KArchiveFile *f = *it;
Expand Down
Loading