From e25b494eb5eba30240fa89518906bd8ea06157d2 Mon Sep 17 00:00:00 2001 From: jkriege2 Date: Mon, 18 Mar 2024 11:32:09 +0100 Subject: [PATCH] change to allow compiling against older Qt versions --- lib/jkqtcommon/jkqtpcsstools.cpp | 6 ++- lib/jkqtcommon/jkqtpstringtools.cpp | 13 +++--- lib/jkqtcommon/jkqtpstringtools.h | 6 +-- lib/jkqtmathtext/jkqtmathtexttools.cpp | 45 ++++++++++--------- .../parsers/jkqtmathtextlatexparser.cpp | 8 ++-- lib/jkqtplotter/jkqtpbaseplotter.cpp | 4 +- lib/jkqtplotter/jkqtpgraphsbasestyle.cpp | 4 ++ tests/jkqtcommmon/JKQTPCSSParser_test.cpp | 5 ++- tests/jkqtcommmon/JKQTPStringTools_test.cpp | 2 + .../jkqtmathtext_render.cpp | 9 ++-- 10 files changed, 60 insertions(+), 42 deletions(-) diff --git a/lib/jkqtcommon/jkqtpcsstools.cpp b/lib/jkqtcommon/jkqtpcsstools.cpp index 48964705b6..56df796cea 100644 --- a/lib/jkqtcommon/jkqtpcsstools.cpp +++ b/lib/jkqtcommon/jkqtpcsstools.cpp @@ -212,6 +212,7 @@ JKQTPExpected JKQTPCSSParser::parseGrad if (get) getToken(); +#if (QT_VERSION >= QT_VERSION_CHECK(5, 12, 0)) static QMap s_GradientPresets = []() { QMap m; for (int i=1; i().keyCount(); i++) { @@ -220,7 +221,7 @@ JKQTPExpected JKQTPCSSParser::parseGrad } return m; }(); - +#endif const QString func=CurrentToken.StringValue.trimmed().simplified().toLower(); if (CurrentToken.is(Token::TokenType::NAME) && func=="linear-gradient") { QGradientStops colorStops; @@ -321,10 +322,11 @@ JKQTPExpected JKQTPCSSParser::parseGrad lgrad.setStops(colorStops); grad=lgrad; } +#if (QT_VERSION >= QT_VERSION_CHECK(5, 12, 0)) } else if (CurrentToken.isNormStringAnyOf(s_GradientPresets.keys())) { grad=QGradient(s_GradientPresets[CurrentToken.getNormString()]); grad.setCoordinateMode(QGradient::ObjectBoundingMode); - +#endif } else { return {JKQTPUnexpected, UnexpectedTermError("supported gradient-function [linear-gradient|] or predefined gradient name", CurrentToken, pos) }; } diff --git a/lib/jkqtcommon/jkqtpstringtools.cpp b/lib/jkqtcommon/jkqtpstringtools.cpp index 72068a2e68..002c7b0c53 100644 --- a/lib/jkqtcommon/jkqtpstringtools.cpp +++ b/lib/jkqtcommon/jkqtpstringtools.cpp @@ -390,7 +390,7 @@ namespace { m["diagcross"]=Qt::DiagCrossPattern; return m; }(); - +#if (QT_VERSION >= QT_VERSION_CHECK(5, 12, 0)) static QMap s_GradientPresets = []() { QMap m; for (int i=1; i().keyCount(); i++) { @@ -399,6 +399,7 @@ namespace { } return m; }(); +#endif } @@ -422,6 +423,7 @@ Qt::BrushStyle jkqtp_String2QBrushStyleExt(const QString &style, QGradient *grad qWarning()<<"error converting '"<= QT_VERSION_CHECK(5, 12, 0)) } else if (s_GradientPresets.contains(s)) { QGradient g(s_GradientPresets[s]); g.setCoordinateMode(QGradient::ObjectBoundingMode); @@ -429,6 +431,7 @@ Qt::BrushStyle jkqtp_String2QBrushStyleExt(const QString &style, QGradient *grad if (g.type()==QGradient::Type::RadialGradient) return Qt::RadialGradientPattern; else if (g.type()==QGradient::Type::ConicalGradient) return Qt::ConicalGradientPattern; else return Qt::LinearGradientPattern; +#endif } else if (jkqtp_rxExactlyMatches(s, "\\s*image\\s*\\(\\s*[\\\"\\\']?(.*)[\\\"\\\']?\\s*\\)\\s*", &caps)) { if (image) *image=QPixmap(caps[1]); return Qt::TexturePattern; @@ -1097,7 +1100,7 @@ namespace JKQTCommon_private { #endif } -bool jkqtp_rxContains(const QString& text, const QString ®ex, qsizetype offset, QStringList* caps) +bool jkqtp_rxContains(const QString& text, const QString ®ex, size_t offset, QStringList* caps) { #if (QT_VERSION>=QT_VERSION_CHECK(6, 0, 0)) if (!JKQTCommon_private::rxCache.contains(regex)) JKQTCommon_private::rxCache.insert(regex, new QRegularExpression(regex)); @@ -1125,7 +1128,7 @@ bool jkqtp_rxContains(const QString& text, const QString ®ex, qsizetype offse } -qsizetype jkqtp_rxIndexIn(const QString& text, const QString ®ex, qsizetype offset, QStringList* caps) +size_t jkqtp_rxIndexIn(const QString& text, const QString ®ex, size_t offset, QStringList* caps) { #if (QT_VERSION>=QT_VERSION_CHECK(6, 0, 0)) if (!JKQTCommon_private::rxCache.contains(regex)) JKQTCommon_private::rxCache.insert(regex, new QRegularExpression(regex)); @@ -1147,14 +1150,14 @@ qsizetype jkqtp_rxIndexIn(const QString& text, const QString ®ex, qsizetype o tempRX.reset(new QRegExp(regex)); rx=tempRX.data(); } - const qsizetype idx = rx->indexIn(text, offset); + const size_t idx = rx->indexIn(text, offset); if (caps) *caps=rx->capturedTexts(); return idx; #endif } -bool jkqtp_rxPartiallyMatchesAt(const QString& text, const QString ®ex, qsizetype offset, QStringList* caps) +bool jkqtp_rxPartiallyMatchesAt(const QString& text, const QString ®ex, size_t offset, QStringList* caps) { #if (QT_VERSION>=QT_VERSION_CHECK(6, 0, 0)) if (!JKQTCommon_private::rxCache.contains(regex)) JKQTCommon_private::rxCache.insert(regex, new QRegularExpression(regex)); diff --git a/lib/jkqtcommon/jkqtpstringtools.h b/lib/jkqtcommon/jkqtpstringtools.h index 35016497f3..bdce5d0f61 100644 --- a/lib/jkqtcommon/jkqtpstringtools.h +++ b/lib/jkqtcommon/jkqtpstringtools.h @@ -360,7 +360,7 @@ JKQTCOMMON_LIB_EXPORT Qt::MouseButton jkqtp_String2MouseButton(const QString &bu * * \see jkqtp_rxExactlyMatches(), jkqtp_rxIndexIn(), jkqtp_rxContains(), jkqtp_rxPartiallyMatchesAt() */ -JKQTCOMMON_LIB_EXPORT bool jkqtp_rxContains(const QString& text, const QString ®ex, qsizetype offset=0, QStringList* caps=nullptr); +JKQTCOMMON_LIB_EXPORT bool jkqtp_rxContains(const QString& text, const QString ®ex, size_t offset=0, QStringList* caps=nullptr); /** \brief returns the next match (i.e. its index) of the given regular expression \a regex within \a text, * starts from \a offset and optionally returns the match in \a caps \c =[fullmatch, cap1,cap2,...] @@ -371,7 +371,7 @@ JKQTCOMMON_LIB_EXPORT bool jkqtp_rxContains(const QString& text, const QString & * * \see jkqtp_rxExactlyMatches(), jkqtp_rxIndexIn(), jkqtp_rxContains(), jkqtp_rxPartiallyMatchesAt() */ -JKQTCOMMON_LIB_EXPORT qsizetype jkqtp_rxIndexIn(const QString& text, const QString ®ex, qsizetype offset=0, QStringList* caps=nullptr); +JKQTCOMMON_LIB_EXPORT size_t jkqtp_rxIndexIn(const QString& text, const QString ®ex, size_t offset=0, QStringList* caps=nullptr); /** \brief returns \c true, if \a text exactly matches the given regular expression \a regex, * starts from \a offset and optionally returns the match in \a caps \c =[fullmatch, cap1,cap2,...] @@ -395,7 +395,7 @@ JKQTCOMMON_LIB_EXPORT bool jkqtp_rxExactlyMatches(const QString& text, const QSt * * \see jkqtp_rxExactlyMatches(), jkqtp_rxIndexIn(), jkqtp_rxContains(), jkqtp_rxPartiallyMatchesAt() */ -JKQTCOMMON_LIB_EXPORT bool jkqtp_rxPartiallyMatchesAt(const QString& text, const QString ®ex, qsizetype offset=0, QStringList* caps=nullptr); +JKQTCOMMON_LIB_EXPORT bool jkqtp_rxPartiallyMatchesAt(const QString& text, const QString ®ex, size_t offset=0, QStringList* caps=nullptr); #endif // JKQTPSTRINGTOOLS_H_INCLUDED diff --git a/lib/jkqtmathtext/jkqtmathtexttools.cpp b/lib/jkqtmathtext/jkqtmathtexttools.cpp index c1bef43214..3cfcda0ca4 100644 --- a/lib/jkqtmathtext/jkqtmathtexttools.cpp +++ b/lib/jkqtmathtext/jkqtmathtexttools.cpp @@ -997,35 +997,36 @@ namespace { } -template<> -struct std::hash -{ - std::size_t operator()(const JKQTMathTextCacheKeyBase& data) const noexcept +namespace std { + template<> + struct hash { - return qHash(data.f)+std::hash()(data.ldpiX)+std::hash()(data.ldpiY)+std::hash()(data.pdpiX)+std::hash()(data.pdpiY); - } -}; + size_t operator()(const JKQTMathTextCacheKeyBase& data) const noexcept + { + return qHash(data.f)+hash()(data.ldpiX)+hash()(data.ldpiY)+hash()(data.pdpiX)+hash()(data.pdpiY); + } + }; -template<> -struct std::hash> -{ - std::size_t operator()(const JKQTMathTextTBRDataH& data) const noexcept + template<> + struct hash> { - return qHash(data.f)+qHash(data.text)+std::hash()(data.ldpiX)+std::hash()(data.ldpiY)+std::hash()(data.pdpiX)+std::hash()(data.pdpiY); - } -}; + size_t operator()(const JKQTMathTextTBRDataH& data) const noexcept + { + return qHash(data.f)+qHash(data.text)+hash()(data.ldpiX)+hash()(data.ldpiY)+hash()(data.pdpiX)+hash()(data.pdpiY); + } + }; -template<> -struct std::hash> -{ - std::size_t operator()(const JKQTMathTextTBRDataH& data) const noexcept + template<> + struct hash> { - return qHash(data.f)+qHash(data.text)+std::hash()(data.ldpiX)+std::hash()(data.ldpiY)+std::hash()(data.pdpiX)+std::hash()(data.pdpiY); - } -}; - + size_t operator()(const JKQTMathTextTBRDataH& data) const noexcept + { + return qHash(data.f)+qHash(data.text)+hash()(data.ldpiX)+hash()(data.ldpiY)+hash()(data.pdpiX)+hash()(data.pdpiY); + } + }; +} QRectF JKQTMathTextGetTightBoundingRect(const QFont &f, const QString &text, QPaintDevice *pd) diff --git a/lib/jkqtmathtext/parsers/jkqtmathtextlatexparser.cpp b/lib/jkqtmathtext/parsers/jkqtmathtextlatexparser.cpp index f3d7121494..4e18e0fe96 100644 --- a/lib/jkqtmathtext/parsers/jkqtmathtextlatexparser.cpp +++ b/lib/jkqtmathtext/parsers/jkqtmathtextlatexparser.cpp @@ -884,7 +884,7 @@ JKQTMathTextNode* JKQTMathTextLatexParser::parseLatexString(bool get, JKQTMathTe bool first=true; bool firstLine=true; QVector line; - qsizetype colCount=0; + size_t colCount=0; //qDebug()<<"start "<=1 && static_cast(line.size())!=colCount) { + } else if (line.size()>=1 && static_cast(line.size())!=colCount) { addToErrorList(tr("error @ ch. %1: wrong number of entries widthin '\\begin{%2}...\\end{%2}'").arg(currentTokenID).arg(envname)); } } diff --git a/lib/jkqtplotter/jkqtpbaseplotter.cpp b/lib/jkqtplotter/jkqtpbaseplotter.cpp index a2ab14d046..9ec63ef1d7 100644 --- a/lib/jkqtplotter/jkqtpbaseplotter.cpp +++ b/lib/jkqtplotter/jkqtpbaseplotter.cpp @@ -3741,7 +3741,7 @@ bool JKQTBasePlotter::saveImage(const QString& filename, bool displayPreview) { QSharedPointer paintDevice=QSharedPointer(jkqtpPaintDeviceAdapters.get()[adapterID]->createPaintdevice(fn, jkqtp_roundTo(gridPrintingSize.width()), jkqtp_roundTo(gridPrintingSize.height()))); #ifndef JKQTPLOTTER_COMPILE_WITHOUT_PRINTSUPPORT - if (!printpreviewNew(paintDevice.get(), jkqtpPaintDeviceAdapters.get()[adapterID]->getSetAbsolutePaperSize(), jkqtpPaintDeviceAdapters.get()[adapterID]->getPrintSizeXInMM(), jkqtpPaintDeviceAdapters.get()[adapterID]->getPrintSizeYInMM(), displayPreview)) { + if (!printpreviewNew(paintDevice.data(), jkqtpPaintDeviceAdapters.get()[adapterID]->getSetAbsolutePaperSize(), jkqtpPaintDeviceAdapters.get()[adapterID]->getPrintSizeXInMM(), jkqtpPaintDeviceAdapters.get()[adapterID]->getPrintSizeYInMM(), displayPreview)) { if (QFile::exists(tempFM)) { QFile::copy(tempFM, fn); QFile::remove(tempFM); @@ -3751,7 +3751,7 @@ bool JKQTBasePlotter::saveImage(const QString& filename, bool displayPreview) { #endif { paintDevice.reset(jkqtpPaintDeviceAdapters.get()[adapterID]->createPaintdeviceMM(fn,printSizeX_Millimeter,printSizeY_Millimeter)); - printpreviewPaintRequestedNewPaintDevice(paintDevice.get()); + printpreviewPaintRequestedNewPaintDevice(paintDevice.data()); return true; } diff --git a/lib/jkqtplotter/jkqtpgraphsbasestyle.cpp b/lib/jkqtplotter/jkqtpgraphsbasestyle.cpp index 692a1ad469..7905aa135d 100644 --- a/lib/jkqtplotter/jkqtpgraphsbasestyle.cpp +++ b/lib/jkqtplotter/jkqtpgraphsbasestyle.cpp @@ -573,7 +573,11 @@ QBrush JKQTFillStyleSummmary::brush(const QColor &color) const if (brushStyle==Qt::LinearGradientPattern || brushStyle==Qt::RadialGradientPattern || brushStyle==Qt::ConicalGradientPattern) { QGradient g=gradient; JKQTPReplaceCurrentColor(g, color); +#if QT_VERSION >= QT_VERSION_CHECK(5,12,0) g.setCoordinateMode(QGradient::ObjectMode); +#else + g.setCoordinateMode(QGradient::ObjectBoundingMode); +#endif b=QBrush(g); } else { b.setStyle(brushStyle); diff --git a/tests/jkqtcommmon/JKQTPCSSParser_test.cpp b/tests/jkqtcommmon/JKQTPCSSParser_test.cpp index 02105213f4..fedcd8318d 100644 --- a/tests/jkqtcommmon/JKQTPCSSParser_test.cpp +++ b/tests/jkqtcommmon/JKQTPCSSParser_test.cpp @@ -120,11 +120,12 @@ private slots: QVERIFY_THROWS_EXCEPTION(std::exception, n=JKQTPCSSParser::readGradient("wa__flame")); +#if (QT_VERSION >= QT_VERSION_CHECK(5, 12, 0)) QVERIFY_THROWS_NO_EXCEPTION(n=JKQTPCSSParser::readGradient("warmflame")); g = QGradient(QGradient::WarmFlame); g.setCoordinateMode(QGradient::ObjectBoundingMode); QCOMPARE_EQ(n, g); - +#endif QVERIFY_THROWS_NO_EXCEPTION(n=JKQTPCSSParser::readGradient("linear-gradient(to left, red, blue)")); lg = QLinearGradient(1,0.5,0,0.5); @@ -171,11 +172,13 @@ private slots: QLinearGradient lg; +#if (QT_VERSION >= QT_VERSION_CHECK(5, 12, 0)) QVERIFY_THROWS_NO_EXCEPTION(bs=jkqtp_String2QBrushStyleExt("warmflame", &n, nullptr)); g = QGradient(QGradient::WarmFlame); g.setCoordinateMode(QGradient::ObjectBoundingMode); QCOMPARE_EQ(n, g); QCOMPARE_EQ(bs, Qt::LinearGradientPattern); +#endif QVERIFY_THROWS_NO_EXCEPTION(bs=jkqtp_String2QBrushStyleExt("d1", &n, nullptr)); QCOMPARE_EQ(bs, Qt::Dense1Pattern); diff --git a/tests/jkqtcommmon/JKQTPStringTools_test.cpp b/tests/jkqtcommmon/JKQTPStringTools_test.cpp index f42e067000..33e8f45557 100644 --- a/tests/jkqtcommmon/JKQTPStringTools_test.cpp +++ b/tests/jkqtcommmon/JKQTPStringTools_test.cpp @@ -34,11 +34,13 @@ private slots: QLinearGradient lg; +#if (QT_VERSION >= QT_VERSION_CHECK(5, 12, 0)) QVERIFY_THROWS_NO_EXCEPTION(bs=jkqtp_String2QBrushStyleExt("warmflame", &n, nullptr)); g = QGradient(QGradient::WarmFlame); g.setCoordinateMode(QGradient::ObjectBoundingMode); QCOMPARE_EQ(n, g); QCOMPARE_EQ(bs, Qt::LinearGradientPattern); +#endif QVERIFY_THROWS_NO_EXCEPTION(bs=jkqtp_String2QBrushStyleExt("d1", &n, nullptr)); QCOMPARE_EQ(bs, Qt::Dense1Pattern); diff --git a/tools/jkqtmathtext_render/jkqtmathtext_render.cpp b/tools/jkqtmathtext_render/jkqtmathtext_render.cpp index 6af87449ec..c1c73ad57a 100644 --- a/tools/jkqtmathtext_render/jkqtmathtext_render.cpp +++ b/tools/jkqtmathtext_render/jkqtmathtext_render.cpp @@ -207,14 +207,17 @@ int main(int argc, char* argv[]) fileList<<" \n"; fileList<<" \n"; i=1; + + auto myIsLower=[](const QString& s) { for (size_t i=0; i=QT_VERSION_CHECK(6, 0, 0)) std::sort #else qSort #endif - (symbolsAll.begin(), symbolsAll.end(), [](const QString& a, const QString& b) { if (a.contains("harpoon") && !b.contains("harpoon")) return false; - else if (a.isLower() && b.isUpper()) return true; - else if (a.isUpper() && b.isLower()) return false; + (symbolsAll.begin(), symbolsAll.end(), [myIsLower,myIsUpper](const QString& a, const QString& b) { if (a.contains("harpoon") && !b.contains("harpoon")) return false; + else if (myIsLower(a) && myIsUpper(b)) return true; + else if (myIsUpper(a) && myIsLower(b)) return false; else return a