diff --git a/lib/jkqtcommon/jkqtpbasicimagetools.cpp b/lib/jkqtcommon/jkqtpbasicimagetools.cpp index 91dc63be0f..67b3b038e5 100644 --- a/lib/jkqtcommon/jkqtpbasicimagetools.cpp +++ b/lib/jkqtcommon/jkqtpbasicimagetools.cpp @@ -38,6 +38,7 @@ const int JKQTPImageTools::LUTSIZE = 256; QMap JKQTPImageTools::global_jkqtpimagetools_lutstore = JKQTPImageTools::getDefaultLUTs(); int JKQTPImageTools::global_next_userpalette = JKQTPMathImageFIRST_REGISTERED_USER_PALETTE; +std::mutex JKQTPImageTools::lutMutex = std::mutex(); @@ -2648,6 +2649,7 @@ bool JKQTPImagePlot_QPairCompareFirst(const QPair &s1, const QPair lock(JKQTPImageTools::lutMutex); static QStringList sl; if (sl.size()!=JKQTPImageTools::global_jkqtpimagetools_lutstore.size()) { @@ -2665,6 +2667,7 @@ QStringList JKQTPImageTools::getPredefinedPalettes() { QStringList JKQTPImageTools::getPredefinedPalettesMachineReadable() { + std::lock_guard lock(JKQTPImageTools::lutMutex); static QStringList sl; if (sl.size()!=JKQTPImageTools::global_jkqtpimagetools_lutstore.size()) { @@ -2686,6 +2689,7 @@ QStringList JKQTPImageTools::getPredefinedPalettesMachineReadable() { QString JKQTPImageTools::JKQTPMathImageColorPalette2String(JKQTPMathImageColorPalette p) { + std::lock_guard lock(JKQTPImageTools::lutMutex); auto it=JKQTPImageTools::global_jkqtpimagetools_lutstore.find(p); if (it==JKQTPImageTools::global_jkqtpimagetools_lutstore.end()) return QString::number(static_cast(p)); else { @@ -2696,6 +2700,7 @@ QString JKQTPImageTools::JKQTPMathImageColorPalette2String(JKQTPMathImageColorPa JKQTPMathImageColorPalette JKQTPImageTools::String2JKQTPMathImageColorPalette(const QString &p) { + std::lock_guard lock(JKQTPImageTools::lutMutex); for (auto it=JKQTPImageTools::global_jkqtpimagetools_lutstore.begin(); it!=JKQTPImageTools::global_jkqtpimagetools_lutstore.end(); ++it) { if (QString::compare(p, it.value().name, Qt::CaseInsensitive)==0) { return static_cast(it.key()); @@ -2807,6 +2812,7 @@ QIcon JKQTPImageTools::GetPaletteIcon(JKQTPMathImageColorPalette palette) { int JKQTPImageTools::registerPalette(const QString &name, const JKQTPImageTools::LUTType &paletteLut, const QString &nameT) { + std::lock_guard lock(JKQTPImageTools::lutMutex); int id=JKQTPImageTools::global_next_userpalette++; JKQTPImageTools::global_jkqtpimagetools_lutstore[id].name=name; JKQTPImageTools::global_jkqtpimagetools_lutstore[id].nameT=((nameT.size()>0)?nameT:name); diff --git a/lib/jkqtcommon/jkqtpbasicimagetools.h b/lib/jkqtcommon/jkqtpbasicimagetools.h index 9641117be5..9d4659061c 100644 --- a/lib/jkqtcommon/jkqtpbasicimagetools.h +++ b/lib/jkqtcommon/jkqtpbasicimagetools.h @@ -28,6 +28,7 @@ #include #include #include +#include #include #include "jkqtcommon/jkqtcommon_imexport.h" #include "jkqtcommon/jkqtpmathtools.h" @@ -482,6 +483,9 @@ struct JKQTPImageTools { \see registerPalette() registerPalettesFromFile() */ static JKQTCOMMON_LIB_EXPORT int global_next_userpalette; + /** \brief Mutex to protect global_jkqtpimagetools_lutstore and global_next_userpalette */ + static JKQTCOMMON_LIB_EXPORT std::mutex lutMutex; + /*! \brief returns data of the default LUTs, used to initialize global_jkqtpimagetools_lutstore \internal diff --git a/lib/jkqtcommon/jkqtpdebuggingtools.cpp b/lib/jkqtcommon/jkqtpdebuggingtools.cpp index b474a2059d..69b90cac5a 100644 --- a/lib/jkqtcommon/jkqtpdebuggingtools.cpp +++ b/lib/jkqtcommon/jkqtpdebuggingtools.cpp @@ -23,15 +23,15 @@ #include - - -int JKQTPAutoOutputTimer::global_indent=0; +namespace JKQTPAutoOutputTimer_private { + thread_local int global_indent=0; +} JKQTPAutoOutputTimer::JKQTPAutoOutputTimer(const QString& _message) : QElapsedTimer(),message(_message),indent() { - this->indent=QString(global_indent, QLatin1Char(' ')); - global_indent+=4; + this->indent=QString(JKQTPAutoOutputTimer_private::global_indent, QLatin1Char(' ')); + JKQTPAutoOutputTimer_private::global_indent+=4; #if QT_VERSION >= 0x040800 qDebug()<indent<<"TIMER_START: "<indent<<"TIMER_END: "< #include #include +#include #include #include @@ -63,6 +64,7 @@ QString JKQTMathText::init_caligraphicFont="decorative"; QString JKQTMathText::init_blackboardFont="blackboard"; QString JKQTMathText::init_fracturFont="fraktur"; bool JKQTMathText::s_firstStart=true; +std::mutex JKQTMathText::s_mutex=std::mutex(); @@ -126,7 +128,7 @@ JKQTMathText::JKQTMathText(QObject* parent, bool useFontsForGUI): - + std::lock_guard lock(s_mutex); if (s_firstStart) { //t0=std::chrono::high_resolution_clock::now(); diff --git a/lib/jkqtmathtext/jkqtmathtext.h b/lib/jkqtmathtext/jkqtmathtext.h index 5825f19166..23677300ad 100644 --- a/lib/jkqtmathtext/jkqtmathtext.h +++ b/lib/jkqtmathtext/jkqtmathtext.h @@ -40,6 +40,7 @@ #include #include #include +#include class JKQTMathTextNode; // forward @@ -1069,6 +1070,8 @@ class JKQTMATHTEXT_LIB_EXPORT JKQTMathText : public QObject { static QString init_fracturFont; /** \brief used to check for the first construction of a JKQTMathText ... if \c true several static variables are initialized in the constructor */ static bool s_firstStart; + /** \brief mutex to protect the static members */ + static std::mutex s_mutex; }; diff --git a/lib/jkqtmathtext/jkqtmathtexttools.cpp b/lib/jkqtmathtext/jkqtmathtexttools.cpp index 6d7eff0a06..4b50daf5a8 100644 --- a/lib/jkqtmathtext/jkqtmathtexttools.cpp +++ b/lib/jkqtmathtext/jkqtmathtexttools.cpp @@ -21,7 +21,6 @@ #include "jkqtmathtext/jkqtmathtexttools.h" #include "jkqtmathtext/jkqtmathtext.h" -#include "jkqtcommon/jkqtpcodestructuring.h" #include "jkqtcommon/jkqtpstringtools.h" #include #include @@ -35,6 +34,8 @@ void initJKQTMathTextResources() { static bool initialized=false; + static std::mutex mutex_initialized; + std::lock_guard lock(mutex_initialized); if (!initialized) { #ifdef JKQTMATHTEXT_COMPILED_WITH_XITS Q_INIT_RESOURCE(xits); @@ -249,6 +250,8 @@ JKQTMathTextFontSpecifier JKQTMathTextFontSpecifier::getXITSFamilies() } static JKQTMathTextFontSpecifier fontSpec; + static std::mutex fontSpecMutex; + std::lock_guard lock(fontSpecMutex); if (fontSpec.m_fontName.isEmpty() && fontSpec.m_mathFontName.isEmpty()) { fontSpec.m_transformOnOutput=false; for (int i=0; i lock(fontSpecMutex); if (fontSpec.m_fontName.isEmpty() && fontSpec.m_mathFontName.isEmpty()) { fontSpec.m_transformOnOutput=false; for (int i=0; i lock(fontSpecMutex); if (fontSpec.m_fontName.isEmpty() && fontSpec.m_mathFontName.isEmpty()) { fontSpec.m_transformOnOutput=false; #if (QT_VERSION lock(fontSpecMutex); if (fontSpec.m_fontName.isEmpty() && fontSpec.m_mathFontName.isEmpty()) { fontSpec.m_transformOnOutput=false; for (int i=0; i lock(fontSpecMutex); if (fontSpec.m_fontName.isEmpty() && fontSpec.m_mathFontName.isEmpty()) { #if (QT_VERSION lock(fontSpecMutex); if (fontSpec.m_fontName.isEmpty() && fontSpec.m_mathFontName.isEmpty()) { const QFont f=QGuiApplication::font().family(); QFont testFnt; @@ -927,8 +940,8 @@ bool JKQTMathTextTBRDataH::operator==(const JKQTMathTextTBRDataH &other) const QRectF JKQTMathTextGetTightBoundingRect(const QFont &fm, const QString &text, QPaintDevice *pd) { - static QList JKQTMathText_tbrs=QList(); - static QHash JKQTMathText_tbrh=QHash(); + thread_local QList JKQTMathText_tbrs=QList(); + thread_local QHash JKQTMathText_tbrh=QHash(); JKQTMathTextTBRDataH dh(fm, text, pd); if (pd) { diff --git a/lib/jkqtmathtext/nodes/jkqtmathtextboxinstructionnode.cpp b/lib/jkqtmathtext/nodes/jkqtmathtextboxinstructionnode.cpp index 55cb324a6e..6083a6c84a 100644 --- a/lib/jkqtmathtext/nodes/jkqtmathtextboxinstructionnode.cpp +++ b/lib/jkqtmathtext/nodes/jkqtmathtextboxinstructionnode.cpp @@ -169,6 +169,9 @@ QHash JKQTMathTe void JKQTMathTextBoxInstructionNode::fillInstructions() { + static std::mutex sMutex; + std::lock_guard lock(sMutex); + if (instructions.size()>0) return; { InstructionProperties i(InstructionProperties::NoModification, diff --git a/lib/jkqtmathtext/nodes/jkqtmathtextdecoratednode.cpp b/lib/jkqtmathtext/nodes/jkqtmathtextdecoratednode.cpp index 940e9c671e..d32af005f4 100644 --- a/lib/jkqtmathtext/nodes/jkqtmathtextdecoratednode.cpp +++ b/lib/jkqtmathtext/nodes/jkqtmathtextdecoratednode.cpp @@ -172,6 +172,8 @@ QHash JKQTMathTextDecoratedN void JKQTMathTextDecoratedNode::fillInstructions() { + static std::mutex sMutex; + std::lock_guard lock(sMutex); if (instructions.size()>0) return; instructions["vec"]=MTDvec; diff --git a/lib/jkqtmathtext/nodes/jkqtmathtextfracnode.cpp b/lib/jkqtmathtext/nodes/jkqtmathtextfracnode.cpp index 00046f2ea6..92ed57615b 100644 --- a/lib/jkqtmathtext/nodes/jkqtmathtextfracnode.cpp +++ b/lib/jkqtmathtext/nodes/jkqtmathtextfracnode.cpp @@ -39,6 +39,8 @@ QHash JKQTMathTextFracNode::instruction void JKQTMathTextFracNode::fillInstructions() { + static std::mutex sMutex; + std::lock_guard lock(sMutex); if (instructions.size()>0) return; instructions["frac"]=MTFMfrac; instructions["dfrac"] = MTFMdfrac; diff --git a/lib/jkqtmathtext/nodes/jkqtmathtextinstructionnode.cpp b/lib/jkqtmathtext/nodes/jkqtmathtextinstructionnode.cpp index f6b40ebfe1..1b8ab1ca4c 100644 --- a/lib/jkqtmathtext/nodes/jkqtmathtextinstructionnode.cpp +++ b/lib/jkqtmathtext/nodes/jkqtmathtextinstructionnode.cpp @@ -144,6 +144,9 @@ QHash JKQTMat void JKQTMathTextSimpleInstructionNode::fillInstructions() { + static std::mutex sMutex; + std::lock_guard lock(sMutex); + if (instructions.size()>0) return; { InstructionProperties i([](const QStringList& parameters) -> QString { bool ok=false; diff --git a/lib/jkqtmathtext/nodes/jkqtmathtextmodifyenvironmentnode.cpp b/lib/jkqtmathtext/nodes/jkqtmathtextmodifyenvironmentnode.cpp index 7274f2be4a..584a8a68e1 100644 --- a/lib/jkqtmathtext/nodes/jkqtmathtextmodifyenvironmentnode.cpp +++ b/lib/jkqtmathtext/nodes/jkqtmathtextmodifyenvironmentnode.cpp @@ -116,6 +116,9 @@ QHash lock(sMutex); + if (instructions.size()>0) return; { InstructionProperties i([](JKQTMathTextEnvironment& ev, const QStringList& /*parameters*/) { ev.bold=false; @@ -534,6 +537,9 @@ QHash lock(sMutex); + if (instructions.size()>0) return; { InstructionProperties i([](JKQTMathTextEnvironment& ev, const QStringList& /*parameters*/, const JKQTMathText* parentMathText) { diff --git a/lib/jkqtmathtext/nodes/jkqtmathtextsymbolnode.cpp b/lib/jkqtmathtext/nodes/jkqtmathtextsymbolnode.cpp index f38007dcc9..e055e0dc1f 100644 --- a/lib/jkqtmathtext/nodes/jkqtmathtextsymbolnode.cpp +++ b/lib/jkqtmathtext/nodes/jkqtmathtextsymbolnode.cpp @@ -491,6 +491,8 @@ QHash JKQTMathTextSymbolNode:: void JKQTMathTextSymbolNode::fillSymbolTables() { + static std::mutex sMutex; + std::lock_guard lock(sMutex); if (symbols.size()>0) return; // tables have already been filled! So nothing to do here /************************************************************************************** diff --git a/lib/jkqtmathtext/nodes/jkqtmathtexttextnode.cpp b/lib/jkqtmathtext/nodes/jkqtmathtexttextnode.cpp index 002fc9741c..66e1ec3d35 100644 --- a/lib/jkqtmathtext/nodes/jkqtmathtexttextnode.cpp +++ b/lib/jkqtmathtext/nodes/jkqtmathtexttextnode.cpp @@ -76,15 +76,10 @@ bool JKQTMathTextTextBaseNode::toHtml(QString &html, JKQTMathTextEnvironment cur QHash JKQTMathTextTextNode::blackboardUnicodeTable=QHash(); void JKQTMathTextTextNode::fillStaticTables() { + static std::mutex sMutex; + std::lock_guard lock(sMutex); if (blackboardUnicodeTable.size()>0) return; - blackboardUnicodeTable['C']=0x2102; - blackboardUnicodeTable['H']=0x210D; - blackboardUnicodeTable['N']=0x2115; - blackboardUnicodeTable['P']=0x2119; - blackboardUnicodeTable['Q']=0x211A; - blackboardUnicodeTable['R']=0x211D; - blackboardUnicodeTable['Z']=0x2124; for (const QChar ch: QString("ABDEFGIJKLMOSTUVWXYZ")) { blackboardUnicodeTable[ch]=0x1D538+(ch.unicode()-QChar('A').unicode()); @@ -95,6 +90,14 @@ void JKQTMathTextTextNode::fillStaticTables() { for (const QChar ch: QString("0123456789")) { blackboardUnicodeTable[ch]=0x1D7D8+(ch.unicode()-QChar('0').unicode()); } + + blackboardUnicodeTable['C']=0x2102; + blackboardUnicodeTable['H']=0x210D; + blackboardUnicodeTable['N']=0x2115; + blackboardUnicodeTable['P']=0x2119; + blackboardUnicodeTable['Q']=0x211A; + blackboardUnicodeTable['R']=0x211D; + blackboardUnicodeTable['Z']=0x2124; } JKQTMathTextTextNode::JKQTMathTextTextNode(JKQTMathText* _parent, const QString& textIn, bool addWhitespace, bool stripInnerWhitepace): diff --git a/lib/jkqtmathtext/nodes/jkqtmathtextwhitespacenode.cpp b/lib/jkqtmathtext/nodes/jkqtmathtextwhitespacenode.cpp index b7d779c2d2..fbca5d96d1 100644 --- a/lib/jkqtmathtext/nodes/jkqtmathtextwhitespacenode.cpp +++ b/lib/jkqtmathtext/nodes/jkqtmathtextwhitespacenode.cpp @@ -138,6 +138,8 @@ QHash JKQTMathTextWhitespa void JKQTMathTextWhitespaceNode::fillSupportedInstructions() { + static std::mutex sMutex; + std::lock_guard lock(sMutex); if (supportedInstructions.size()==0) { supportedInstructions[" "]=WhitespaceProps(WSTthicker, 1); supportedInstructions["nbsp"]=WhitespaceProps(WSTNonbreaking, 1); @@ -427,6 +429,9 @@ QHash JKQTMathTextPhantomNode::instructi void JKQTMathTextPhantomNode::fillInstructions() { + static std::mutex sMutex; + std::lock_guard lock(sMutex); + if (instructions.size()>0) return; instructions["phantom"] = FMwidthAndHeight; instructions["hphantom"] = FMwidth; instructions["vphantom"] = FMheight; diff --git a/lib/jkqtmathtext/parsers/jkqtmathtextlatexparser.cpp b/lib/jkqtmathtext/parsers/jkqtmathtextlatexparser.cpp index b13c502331..2348232a0f 100644 --- a/lib/jkqtmathtext/parsers/jkqtmathtextlatexparser.cpp +++ b/lib/jkqtmathtext/parsers/jkqtmathtextlatexparser.cpp @@ -60,6 +60,8 @@ QHash JKQTMathTextLatexParser::big_instructions_family; // define some static sets for easy character lookup/identificattion void JKQTMathTextLatexParser::initStaticStructures() { + static std::mutex sMutex; + std::lock_guard lock(sMutex); if (accentLetters.size()==0) { auto fAddUml=[](const QString& cmd, const QChar& letter, const QChar& ch) { QString i; diff --git a/lib/jkqtplotter/jkqtpbaseplotter.cpp b/lib/jkqtplotter/jkqtpbaseplotter.cpp index 9a38b97fc2..c0402e40a0 100644 --- a/lib/jkqtplotter/jkqtpbaseplotter.cpp +++ b/lib/jkqtplotter/jkqtpbaseplotter.cpp @@ -53,15 +53,18 @@ #include "jkqtmathtext/jkqtmathtext.h" #include -static QString globalUserSettigsFilename=""; -static QString globalUserSettigsPrefix=""; -static QList jkqtpPaintDeviceAdapters; -static QList jkqtpSaveDataAdapters; +QString JKQTBasePlotter::globalUserSettigsFilename=""; +QString JKQTBasePlotter::globalUserSettigsPrefix=""; +std::mutex JKQTBasePlotter::globalUserSettingsMutex = std::mutex(); +JKQTPSynchronized> JKQTBasePlotter::jkqtpPaintDeviceAdapters; +JKQTPSynchronized> JKQTBasePlotter::jkqtpSaveDataAdapters; void initJKQTBasePlotterResources() { + static std::mutex sMutex; + std::lock_guard lock(sMutex); Q_INIT_RESOURCE(jkqtpbaseplotter); initJKQTMathTextResources(); } @@ -69,30 +72,34 @@ void initJKQTBasePlotterResources() void JKQTBasePlotter::setDefaultJKQTBasePrinterUserSettings(QString userSettigsFilename, const QString& userSettigsPrefix) { + std::lock_guard lock(globalUserSettingsMutex); globalUserSettigsFilename=userSettigsFilename; globalUserSettigsPrefix=userSettigsPrefix; } void JKQTBasePlotter::registerPaintDeviceAdapter(JKQTPPaintDeviceAdapter *adapter) { - jkqtpPaintDeviceAdapters.append(adapter); + JKQTPSynchronized>::Locker lock(jkqtpPaintDeviceAdapters); + jkqtpPaintDeviceAdapters.get().append(adapter); } void JKQTBasePlotter::deregisterPaintDeviceAdapter(JKQTPPaintDeviceAdapter *adapter) { - if (jkqtpPaintDeviceAdapters.contains(adapter)) jkqtpPaintDeviceAdapters.removeAll(adapter); + JKQTPSynchronized>::Locker lock(jkqtpPaintDeviceAdapters); + if (jkqtpPaintDeviceAdapters.get().contains(adapter)) jkqtpPaintDeviceAdapters.get().removeAll(adapter); } bool JKQTBasePlotter::registerSaveDataAdapter(JKQTPSaveDataAdapter *adapter) { if (adapter){ + JKQTPSynchronized>::Locker lock(jkqtpSaveDataAdapters); QString format=adapter->getFilter(); - for (int i=0; igetFilter()==format) { + for (int i=0; igetFilter()==format) { return false; } } - jkqtpSaveDataAdapters.append(adapter); + jkqtpSaveDataAdapters.get().append(adapter); return true; } return false; @@ -100,10 +107,16 @@ bool JKQTBasePlotter::registerSaveDataAdapter(JKQTPSaveDataAdapter *adapter) bool JKQTBasePlotter::deregisterSaveDataAdapter(JKQTPSaveDataAdapter *adapter) { - if (jkqtpSaveDataAdapters.contains(adapter)) jkqtpSaveDataAdapters.removeAll(adapter); + JKQTPSynchronized>::Locker lock(jkqtpSaveDataAdapters); + if (jkqtpSaveDataAdapters.get().contains(adapter)) jkqtpSaveDataAdapters.get().removeAll(adapter); return true; } + + + + + JKQTBasePlotter::textSizeData JKQTBasePlotter::getTextSizeDetail(const QFont &fm, const QString &text, QPainter& painter) { return getTextSizeDetail(fm.family(), fm.pointSizeF(), text, painter); @@ -111,6 +124,7 @@ JKQTBasePlotter::textSizeData JKQTBasePlotter::getTextSizeDetail(const QFont &fm JKQTBasePlotter::textSizeData JKQTBasePlotter::getTextSizeDetail(const QString &fontName, double fontSize, const QString &text, QPainter& painter) { + thread_local QHash s_TextSizeDataCache; JKQTBasePlotter::textSizeKey dh(fontName, fontSize, text, painter.device()); if (s_TextSizeDataCache.contains(dh)) return s_TextSizeDataCache[dh]; JKQTBasePlotter::textSizeData d; @@ -185,8 +199,11 @@ JKQTBasePlotter::JKQTBasePlotter(bool datastore_internal, QObject* parent, JKQTP lineWidthPrintMultiplier=1; fontSizeMultiplier=1; lineWidthMultiplier=1; - userSettigsFilename=globalUserSettigsFilename; - userSettigsPrefix=globalUserSettigsPrefix; + { + std::lock_guard lock(globalUserSettingsMutex); + userSettigsFilename=globalUserSettigsFilename; + userSettigsPrefix=globalUserSettigsPrefix; + } #ifndef JKQTPLOTTER_COMPILE_WITHOUT_PRINTSUPPORT currentPrinter=QPrinterInfo::defaultPrinter().printerName(); #endif @@ -3599,9 +3616,12 @@ void JKQTBasePlotter::saveData(const QString& filename, const QString &format) { fileformats<getFilter(); - fileformatIDs<>::Locker lock(jkqtpSaveDataAdapters); + for (int i=0; igetFilter(); + fileformatIDs<=0 && idx>::Locker lock(jkqtpSaveDataAdapters); + if (idx>=0 && idx > dataset=datastore->getData(&cn); - jkqtpSaveDataAdapters[idx]->saveJKQTPData(fn, dataset, cn); + jkqtpSaveDataAdapters.get()[idx]->saveJKQTPData(fn, dataset, cn); } } } @@ -3849,8 +3870,11 @@ void JKQTBasePlotter::saveImage(const QString& filename, bool displayPreview) { filt<getFilter(); + { + JKQTPSynchronized>::Locker lock(jkqtpPaintDeviceAdapters); + for (int i=0; igetFilter(); + } } int qtwritersidx=filt.size(); QList writerformats=QImageWriter::supportedImageFormats(); @@ -3874,12 +3898,14 @@ void JKQTBasePlotter::saveImage(const QString& filename, bool displayPreview) { saveUserSettings(); if (!fn.isEmpty()) { int filtID=filt.indexOf(selFormat); - bool isWithSpecialDeviceAdapter=filtID>=filtStartSize && filtID>::Locker lock(jkqtpPaintDeviceAdapters); + + bool isWithSpecialDeviceAdapter=filtID>=filtStartSize && filtIDgetFileExtension().contains(e)) { + for (int i=0; igetFileExtension().contains(e)) { adapterID=i; isWithSpecialDeviceAdapter=true; break; @@ -3897,7 +3923,7 @@ void JKQTBasePlotter::saveImage(const QString& filename, bool displayPreview) { return; } #endif - if (isWithSpecialDeviceAdapter && adapterID>=0 && adapterID=0 && adapterIDcreatePaintdevice(fn, jkqtp_roundTo(gridPrintingSize.width()), jkqtp_roundTo(gridPrintingSize.height())); + QPaintDevice* paintDevice=jkqtpPaintDeviceAdapters.get()[adapterID]->createPaintdevice(fn, jkqtp_roundTo(gridPrintingSize.width()), jkqtp_roundTo(gridPrintingSize.height())); #ifndef JKQTPLOTTER_COMPILE_WITHOUT_PRINTSUPPORT - if (!printpreviewNew(paintDevice, jkqtpPaintDeviceAdapters[adapterID]->getSetAbsolutePaperSize(), jkqtpPaintDeviceAdapters[adapterID]->getPrintSizeXInMM(), jkqtpPaintDeviceAdapters[adapterID]->getPrintSizeYInMM(), displayPreview)) { + if (!printpreviewNew(paintDevice, jkqtpPaintDeviceAdapters.get()[adapterID]->getSetAbsolutePaperSize(), jkqtpPaintDeviceAdapters.get()[adapterID]->getPrintSizeXInMM(), jkqtpPaintDeviceAdapters.get()[adapterID]->getPrintSizeYInMM(), displayPreview)) { delete paintDevice; @@ -3932,7 +3958,7 @@ void JKQTBasePlotter::saveImage(const QString& filename, bool displayPreview) { { #endif delete paintDevice; - paintDevice=jkqtpPaintDeviceAdapters[adapterID]->createPaintdeviceMM(fn,printSizeX_Millimeter,printSizeY_Millimeter); + paintDevice=jkqtpPaintDeviceAdapters.get()[adapterID]->createPaintdeviceMM(fn,printSizeX_Millimeter,printSizeY_Millimeter); printpreviewPaintRequestedNewPaintDevice(paintDevice); delete paintDevice; } @@ -5299,7 +5325,6 @@ void JKQTBasePlotter::setEmittingSignalsEnabled(bool enabled) } -QHash JKQTBasePlotter::s_TextSizeDataCache=QHash(); JKQTBasePlotter::textSizeKey::textSizeKey(const QFont &f, const QString &text, QPaintDevice *pd): text(), f(), ldpiX(0), ldpiY(0), pdpiX(0), pdpiY(0) diff --git a/lib/jkqtplotter/jkqtpbaseplotter.h b/lib/jkqtplotter/jkqtpbaseplotter.h index acb4917c72..415b432453 100644 --- a/lib/jkqtplotter/jkqtpbaseplotter.h +++ b/lib/jkqtplotter/jkqtpbaseplotter.h @@ -28,6 +28,7 @@ #include "jkqtmathtext/jkqtmathtext.h" #include "jkqtplotter/jkqtpbaseelements.h" #include "jkqtcommon/jkqtpenhancedpainter.h" +#include "jkqtcommon/jkqtpconcurrencytools.h" #include "jkqtplotter/gui/jkqtpenhancedspinboxes.h" #include @@ -2032,8 +2033,6 @@ class JKQTPLOTTER_LIB_EXPORT JKQTBasePlotter: public QObject { */ void enableDebugShowTextBoxes(bool enabled=true); protected: - /** \brief this is a cache for JKQTBasePlotter::textSizeData calculated with JKQTBasePlotter::getTextSizeDetail() */ - static QHash s_TextSizeDataCache; @@ -2595,6 +2594,11 @@ class JKQTPLOTTER_LIB_EXPORT JKQTBasePlotter: public QObject { bool emitPlotSignals; + static QString globalUserSettigsFilename; + static QString globalUserSettigsPrefix; + static std::mutex globalUserSettingsMutex; + static JKQTPSynchronized> jkqtpPaintDeviceAdapters; + static JKQTPSynchronized> jkqtpSaveDataAdapters;