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: 2003, 2008 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 "valuebytearraycolumntextrenderer.hpp"
0010 
0011 // Okteta core
0012 #include <Okteta/ValueCodec>
0013 #include <Okteta/AbstractByteArrayModel>
0014 // Qt
0015 #include <QTextStream>
0016 
0017 namespace Kasten {
0018 
0019 ValueByteArrayColumnTextRenderer::ValueByteArrayColumnTextRenderer(
0020     const Okteta::AbstractByteArrayModel* byteArrayModel, Okteta::Address offset,
0021     const Okteta::CoordRange& coordRange,
0022     int noOfBytesPerLine, int byteSpacingWidth, int noOfGroupedBytes,
0023     Okteta::ValueCoding valueCoding)
0024     : AbstractByteArrayColumnTextRenderer(byteArrayModel, offset, coordRange,
0025         noOfBytesPerLine)
0026     , mValueCodec(Okteta::ValueCodec::createCodec(valueCoding))
0027 {
0028     setWidths(mValueCodec->encodingWidth(), byteSpacingWidth, noOfGroupedBytes);
0029 }
0030 
0031 ValueByteArrayColumnTextRenderer::~ValueByteArrayColumnTextRenderer()
0032 {
0033     delete mValueCodec;
0034 }
0035 
0036 void ValueByteArrayColumnTextRenderer::renderLine(QTextStream* stream, bool isSubline) const
0037 {
0038     Q_UNUSED(isSubline)
0039 
0040     int p = 0;
0041     int pEnd = mNoOfBytesPerLine;
0042     // correct boundaries
0043     if (mRenderLine == mCoordRange.start().line()) {
0044         p = mCoordRange.start().pos();
0045     }
0046     if (mRenderLine == mCoordRange.end().line()) {
0047         pEnd = mCoordRange.end().pos() + 1;
0048     }
0049 
0050     QString E;
0051     E.resize(mValueCodec->encodingWidth());
0052     // draw individual chars
0053     uint e = 0;
0054     for (; p < pEnd; ++p, ++mOffset) {
0055         // get next position
0056         const uint t = mLinePositions[p];
0057         // clear spacing
0058         *stream << whiteSpace(t - e);
0059         mValueCodec->encode(&E, 0, mByteArrayModel->byte(mOffset));
0060         *stream << E;
0061         e = t + mValueCodec->encodingWidth();
0062     }
0063 
0064     *stream << whiteSpace(mNoOfCharsPerLine - e);
0065     ++mRenderLine;
0066 }
0067 
0068 }