File indexing completed on 2025-01-05 05:23:53
0001 /* 0002 This file is part of the Okteta Kasten module, made within the KDE community. 0003 0004 SPDX-FileCopyrightText: 2023 Friedrich W. H. Kossebau <kossebau@kde.org> 0005 0006 SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL 0007 */ 0008 0009 #include "valuebytearraycolumnhtmlrenderer.hpp" 0010 0011 // Okteta core 0012 #include <Okteta/ValueCodec> 0013 #include <Okteta/AbstractByteArrayModel> 0014 // Qt 0015 #include <QTextStream> 0016 0017 namespace Kasten { 0018 0019 ValueByteArrayColumnHtmlRenderer::ValueByteArrayColumnHtmlRenderer( 0020 const Okteta::AbstractByteArrayModel* byteArrayModel, Okteta::Address offset, 0021 const Okteta::CoordRange& coordRange, 0022 int noOfBytesPerLine, int noOfGroupedBytes, 0023 Okteta::ValueCoding valueCoding) 0024 : AbstractByteArrayColumnHtmlRenderer(byteArrayModel, offset, coordRange, 0025 noOfBytesPerLine) 0026 , mValueCodec(Okteta::ValueCodec::createCodec(valueCoding)) 0027 { 0028 Q_UNUSED(noOfGroupedBytes) 0029 } 0030 0031 ValueByteArrayColumnHtmlRenderer::~ValueByteArrayColumnHtmlRenderer() = default; 0032 0033 void ValueByteArrayColumnHtmlRenderer::renderLine(QTextStream* stream, bool isSubline) const 0034 { 0035 Q_UNUSED(isSubline) 0036 0037 int p = 0; 0038 int pEnd = mNoOfBytesPerLine; 0039 // correct boundaries 0040 if (mRenderLine == mCoordRange.start().line()) { 0041 p = mCoordRange.start().pos(); 0042 } 0043 if (mRenderLine == mCoordRange.end().line()) { 0044 pEnd = mCoordRange.end().pos() + 1; 0045 } 0046 const bool needsFilledEmptyCells = 0047 (mCoordRange.lines() == 1) ? ((0 < p) || (pEnd < mNoOfBytesPerLine)) : 0048 (mCoordRange.lines() == 2) ? (mCoordRange.end().pos() + 1 < mCoordRange.start().pos() ) : 0049 /* eefault */ false; 0050 const unsigned int codingWidth = needsFilledEmptyCells ? mValueCodec->encodingWidth() : 0; 0051 0052 *stream << emptyCells(p, codingWidth); 0053 0054 QString E; 0055 E.resize(mValueCodec->encodingWidth()); 0056 // draw individual chars 0057 for (; p < pEnd; ++p, ++mOffset) { 0058 mValueCodec->encode(&E, 0, mByteArrayModel->byte(mOffset)); 0059 *stream << "<td><tt>" << E.toHtmlEscaped() << "</tt></td>"; 0060 } 0061 0062 *stream << emptyCells(mNoOfBytesPerLine - p, codingWidth); 0063 0064 ++mRenderLine; 0065 } 0066 0067 }