mirror of
https://github.com/jkriege2/JKQtPlotter.git
synced 2024-12-25 01:51:49 +08:00
change to allow compiling against older Qt versions
This commit is contained in:
parent
b2aad7ca20
commit
e25b494eb5
@ -212,6 +212,7 @@ JKQTPExpected<QGradient, JKQTPCSSParser::GeneralError> JKQTPCSSParser::parseGrad
|
||||
|
||||
if (get) getToken();
|
||||
|
||||
#if (QT_VERSION >= QT_VERSION_CHECK(5, 12, 0))
|
||||
static QMap<QString,QGradient::Preset> s_GradientPresets = []() {
|
||||
QMap<QString,QGradient::Preset> m;
|
||||
for (int i=1; i<QMetaEnum::fromType<QGradient::Preset>().keyCount(); i++) {
|
||||
@ -220,7 +221,7 @@ JKQTPExpected<QGradient, JKQTPCSSParser::GeneralError> 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<QGradient, JKQTPCSSParser::GeneralError> 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) };
|
||||
}
|
||||
|
@ -390,7 +390,7 @@ namespace {
|
||||
m["diagcross"]=Qt::DiagCrossPattern;
|
||||
return m;
|
||||
}();
|
||||
|
||||
#if (QT_VERSION >= QT_VERSION_CHECK(5, 12, 0))
|
||||
static QMap<QString,QGradient::Preset> s_GradientPresets = []() {
|
||||
QMap<QString,QGradient::Preset> m;
|
||||
for (int i=1; i<QMetaEnum::fromType<QGradient::Preset>().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 '"<<style<<"' into a QGradient: "<<E.what();
|
||||
return Qt::SolidPattern;
|
||||
}
|
||||
#if (QT_VERSION >= 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));
|
||||
|
@ -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
|
||||
|
@ -997,35 +997,36 @@ namespace {
|
||||
|
||||
}
|
||||
|
||||
template<>
|
||||
struct std::hash<JKQTMathTextCacheKeyBase>
|
||||
{
|
||||
std::size_t operator()(const JKQTMathTextCacheKeyBase& data) const noexcept
|
||||
namespace std {
|
||||
template<>
|
||||
struct hash<JKQTMathTextCacheKeyBase>
|
||||
{
|
||||
return qHash(data.f)+std::hash<int>()(data.ldpiX)+std::hash<int>()(data.ldpiY)+std::hash<int>()(data.pdpiX)+std::hash<int>()(data.pdpiY);
|
||||
}
|
||||
};
|
||||
size_t operator()(const JKQTMathTextCacheKeyBase& data) const noexcept
|
||||
{
|
||||
return qHash(data.f)+hash<int>()(data.ldpiX)+hash<int>()(data.ldpiY)+hash<int>()(data.pdpiX)+hash<int>()(data.pdpiY);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
template<>
|
||||
struct std::hash<JKQTMathTextTBRDataH<QString>>
|
||||
{
|
||||
std::size_t operator()(const JKQTMathTextTBRDataH<QString>& data) const noexcept
|
||||
template<>
|
||||
struct hash<JKQTMathTextTBRDataH<QString>>
|
||||
{
|
||||
return qHash(data.f)+qHash(data.text)+std::hash<int>()(data.ldpiX)+std::hash<int>()(data.ldpiY)+std::hash<int>()(data.pdpiX)+std::hash<int>()(data.pdpiY);
|
||||
}
|
||||
};
|
||||
size_t operator()(const JKQTMathTextTBRDataH<QString>& data) const noexcept
|
||||
{
|
||||
return qHash(data.f)+qHash(data.text)+hash<int>()(data.ldpiX)+hash<int>()(data.ldpiY)+hash<int>()(data.pdpiX)+hash<int>()(data.pdpiY);
|
||||
}
|
||||
};
|
||||
|
||||
template<>
|
||||
struct std::hash<JKQTMathTextTBRDataH<QChar>>
|
||||
{
|
||||
std::size_t operator()(const JKQTMathTextTBRDataH<QChar>& data) const noexcept
|
||||
template<>
|
||||
struct hash<JKQTMathTextTBRDataH<QChar>>
|
||||
{
|
||||
return qHash(data.f)+qHash(data.text)+std::hash<int>()(data.ldpiX)+std::hash<int>()(data.ldpiY)+std::hash<int>()(data.pdpiX)+std::hash<int>()(data.pdpiY);
|
||||
}
|
||||
};
|
||||
|
||||
size_t operator()(const JKQTMathTextTBRDataH<QChar>& data) const noexcept
|
||||
{
|
||||
return qHash(data.f)+qHash(data.text)+hash<int>()(data.ldpiX)+hash<int>()(data.ldpiY)+hash<int>()(data.pdpiX)+hash<int>()(data.pdpiY);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
QRectF JKQTMathTextGetTightBoundingRect(const QFont &f, const QString &text, QPaintDevice *pd)
|
||||
|
@ -884,7 +884,7 @@ JKQTMathTextNode* JKQTMathTextLatexParser::parseLatexString(bool get, JKQTMathTe
|
||||
bool first=true;
|
||||
bool firstLine=true;
|
||||
QVector<JKQTMathTextNode*> line;
|
||||
qsizetype colCount=0;
|
||||
size_t colCount=0;
|
||||
//qDebug()<<"start "<<envname;
|
||||
while (first || currentToken==MTTampersand || currentToken==MTTinstructionNewline) {
|
||||
//qDebug()<<" - START: "<<tokenType2String(currentToken)<<" first="<<first;
|
||||
@ -930,12 +930,12 @@ JKQTMathTextNode* JKQTMathTextLatexParser::parseLatexString(bool get, JKQTMathTe
|
||||
line.append(it);
|
||||
|
||||
if (currentToken==MTTinstructionNewline || (currentToken==MTTinstructionEnd && currentTokenName==envname) || line.size()>0) {
|
||||
colCount=qMax(colCount, static_cast<qsizetype>(line.size()));
|
||||
colCount=qMax(colCount, static_cast<size_t>(line.size()));
|
||||
//qDebug()<<" - colCount="<<colCount;
|
||||
if (line.size()==0 || (line.size()>=1 && static_cast<qsizetype>(line.size())==colCount)) {
|
||||
if (line.size()==0 || (line.size()>=1 && static_cast<size_t>(line.size())==colCount)) {
|
||||
items.append(line);
|
||||
//qDebug()<<" - appending line with "<<line.size()<<" items. items.size now "<<items.size();
|
||||
} else if (line.size()>=1 && static_cast<qsizetype>(line.size())!=colCount) {
|
||||
} else if (line.size()>=1 && static_cast<size_t>(line.size())!=colCount) {
|
||||
addToErrorList(tr("error @ ch. %1: wrong number of entries widthin '\\begin{%2}...\\end{%2}'").arg(currentTokenID).arg(envname));
|
||||
}
|
||||
}
|
||||
|
@ -3741,7 +3741,7 @@ bool JKQTBasePlotter::saveImage(const QString& filename, bool displayPreview) {
|
||||
QSharedPointer<QPaintDevice> paintDevice=QSharedPointer<QPaintDevice>(jkqtpPaintDeviceAdapters.get()[adapterID]->createPaintdevice(fn, jkqtp_roundTo<int>(gridPrintingSize.width()), jkqtp_roundTo<int>(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;
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
|
@ -207,14 +207,17 @@ int main(int argc, char* argv[])
|
||||
fileList<<" <table>\n";
|
||||
fileList<<" <tr>\n";
|
||||
i=1;
|
||||
|
||||
auto myIsLower=[](const QString& s) { for (size_t i=0; i<s.size(); i++) if (!s[i].isLower()) return false; return true; };
|
||||
auto myIsUpper=[](const QString& s) { for (size_t i=0; i<s.size(); i++) if (!s[i].isUpper()) return false; return true; };
|
||||
#if (QT_VERSION>=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<b;
|
||||
});
|
||||
for (const QString& arrow: arrowNames) {
|
||||
|
Loading…
Reference in New Issue
Block a user