File indexing completed on 2024-12-22 04:48:18
0001 /* 0002 SPDX-License-Identifier: GPL-2.0-or-later 0003 SPDX-FileCopyrightText: 2024 Louis Schul <schul9louis@gmail.com> 0004 */ 0005 0006 #include "pumlParserUtils.h" 0007 0008 #include "logic/parser/renderer.h" 0009 #include "logic/plugins/puml/pumlHelper.h" 0010 #include <QStandardPaths> 0011 0012 void PUMLParserUtils::clearInfo() 0013 { 0014 m_notePUMLBlocks.clear(); 0015 } 0016 0017 void PUMLParserUtils::clearPreviousInfo() 0018 { 0019 m_previousPUMLDiag.clear(); 0020 } 0021 0022 void PUMLParserUtils::preTok() 0023 { 0024 m_samePUMLBlocks = m_previousNotePUMLBlocks == m_notePUMLBlocks && !m_notePUMLBlocks.isEmpty(); 0025 if (!m_samePUMLBlocks || m_pumlDarkChanged) { 0026 m_previousNotePUMLBlocks = m_notePUMLBlocks; 0027 m_previousPUMLDiag.clear(); 0028 m_pumlDarkChanged = false; 0029 m_samePUMLBlocks = false; 0030 } 0031 m_currentPUMLBlockIndex = 0; 0032 } 0033 0034 void PUMLParserUtils::addToNotePUMLBlock(const QString &pumlBlock) 0035 { 0036 m_notePUMLBlocks.append(pumlBlock); 0037 } 0038 0039 void PUMLParserUtils::pumlDarkChanged() 0040 { 0041 m_pumlDarkChanged = true; 0042 } 0043 0044 QString PUMLParserUtils::renderCode(const QString &_text, const bool pumlDark) 0045 { 0046 QString returnValue; 0047 if (m_samePUMLBlocks) { 0048 returnValue = m_previousPUMLDiag[m_currentPUMLBlockIndex]; 0049 m_currentPUMLBlockIndex++; 0050 } else { 0051 const int diagNbr = m_previousPUMLDiag.size(); 0052 const QString diagName = QStringLiteral("/KleverNotesPUMLDiag") + QString::number(diagNbr) + QStringLiteral(".png"); 0053 const QString diagPath = QStandardPaths::writableLocation(QStandardPaths::TempLocation) + diagName; 0054 const QString imgPath = PumlHelper::makeDiagram(_text, diagPath, pumlDark) ? diagPath : QLatin1String(); 0055 returnValue = Renderer::image(imgPath, diagName, diagName); 0056 m_previousPUMLDiag.append(returnValue); 0057 } 0058 0059 return returnValue; 0060 }