• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdesdk API Reference
  • KDE Home
  • Contact Us
 

okteta

  • sources
  • kde-4.12
  • kdesdk
  • okteta
  • kasten
  • gui
  • io
  • streamencoder
  • viewtext
bytearrayrowscolumntextrenderer.cpp
Go to the documentation of this file.
1 /*
2  This file is part of the Okteta Kasten module, made within the KDE community.
3 
4  Copyright 2008 Friedrich W. H. Kossebau <kossebau@kde.org>
5 
6  This library is free software; you can redistribute it and/or
7  modify it under the terms of the GNU Lesser General Public
8  License as published by the Free Software Foundation; either
9  version 2.1 of the License, or (at your option) version 3, or any
10  later version accepted by the membership of KDE e.V. (or its
11  successor approved by the membership of KDE e.V.), which shall
12  act as a proxy defined in Section 6 of version 3 of the license.
13 
14  This library is distributed in the hope that it will be useful,
15  but WITHOUT ANY WARRANTY; without even the implied warranty of
16  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17  Lesser General Public License for more details.
18 
19  You should have received a copy of the GNU Lesser General Public
20  License along with this library. If not, see <http://www.gnu.org/licenses/>.
21 */
22 
23 #include "bytearrayrowscolumntextrenderer.h"
24 
25 // Okteta core
26 #include <valuecodec.h>
27 #include <charcodec.h>
28 #include <character.h>
29 #include <abstractbytearraymodel.h>
30 // Qt
31 #include <QtCore/QTextStream>
32 
33 
34 namespace Kasten2
35 {
36 
37 ByteArrayRowsColumnTextRenderer::ByteArrayRowsColumnTextRenderer( const Okteta::AbstractByteArrayModel* byteArrayModel,
38  Okteta::Address offset,
39  const Okteta::CoordRange& coordRange,
40  int noOfBytesPerLine, int byteSpacingWidth, int noOfGroupedBytes,
41  int visibleCodings,
42  Okteta::ValueCoding valueCoding,
43  const QString& charCodecName, QChar substituteChar, QChar undefinedChar )
44  : mByteArrayModel( byteArrayModel ),
45  mCoordRange( coordRange ),
46  mNoOfBytesPerLine( noOfBytesPerLine ),
47  mVisibleCodings( visibleCodings ),
48  mValueCodec( Okteta::ValueCodec::createCodec(valueCoding) ),
49  mCharCodec( Okteta::CharCodec::createCodec(charCodecName) ),
50  mSubstituteChar( substituteChar ),
51  mUndefinedChar( undefinedChar ),
52  mOffset( offset ),
53  mNoOfCharsPerLine( 0 ),
54  mLinePositions( new int[mNoOfBytesPerLine] )
55 {
56  const int encodingWidth = ( mVisibleCodings & 1 ) ? mValueCodec->encodingWidth() : 1;
57  setWidths( encodingWidth, byteSpacingWidth, noOfGroupedBytes );
58 }
59 
60 
61 int ByteArrayRowsColumnTextRenderer::noOfSublinesNeeded() const
62 {
63  return ( mVisibleCodings > 2 ) ? 2 : 1;
64 }
65 
66 void ByteArrayRowsColumnTextRenderer::setWidths( int byteWidth, int byteSpacingWidth, int noOfGroupedBytes )
67 {
68  // TODO: remove this hack and make it more general
69  if( byteSpacingWidth > 0 )
70  byteSpacingWidth = DefaultTRByteSpacingWidth;
71 
72  int spacingTrigger = noOfGroupedBytes-1;
73  if( spacingTrigger < 0 )
74  spacingTrigger = mNoOfBytesPerLine; // ensures to never trigger the group spacing
75 
76  int N = 0;
77  int p = 0;
78  int gs = 0;
79  int *P = mLinePositions;
80  for( ; P<&mLinePositions[mNoOfBytesPerLine]; ++P, ++p, ++gs )
81  {
82  *P = N;
83  N += byteWidth;
84 
85  // is there a space behind the actual byte (if it is not the last)?
86  if( gs == spacingTrigger )
87  {
88  N += TRGroupSpacingWidth;
89  gs = -1;
90  }
91  else
92  N += byteSpacingWidth;
93  }
94  N -= (gs==0)?TRGroupSpacingWidth:byteSpacingWidth;
95 
96  mNoOfCharsPerLine = N;
97 }
98 
99 
100 void ByteArrayRowsColumnTextRenderer::renderFirstLine( QTextStream *stream, int lineIndex ) const
101 {
102  mRenderLine = lineIndex;
103  renderLine( stream, false );
104 }
105 
106 
107 void ByteArrayRowsColumnTextRenderer::renderNextLine( QTextStream* stream, bool isSubline ) const
108 {
109  renderLine( stream, isSubline );
110 }
111 
112 void ByteArrayRowsColumnTextRenderer::renderLine( QTextStream* stream, bool isSubline ) const
113 {
114  const int lineOffset = mOffset;
115 
116  int p = 0;
117  int pEnd = mNoOfBytesPerLine;
118  // correct boundaries
119  if( mRenderLine == mCoordRange.start().line() )
120  p = mCoordRange.start().pos();
121  if( mRenderLine == mCoordRange.end().line() )
122  pEnd = mCoordRange.end().pos()+1;
123 
124  uint e = 0;
125  if( isSubline || mVisibleCodings == 2 )
126  {
127  const QChar tabChar = QLatin1Char( '\t' );
128  const QChar returnChar = QLatin1Char( '\n' );
129 
130  // draw individual chars
131  for( ; p<pEnd; ++p, ++mOffset )
132  {
133  // get next position
134  const uint t = mLinePositions[p];
135  // clear spacing
136  *stream << whiteSpace( t-e );
137 
138  // print char
139  const Okteta::Character byteChar = mCharCodec->decode( mByteArrayModel->byte(mOffset) );
140 
141  const QChar streamChar = byteChar.isUndefined() ? Okteta::Character(mUndefinedChar) :
142  (!byteChar.isPrint()
143  || byteChar == tabChar
144  || byteChar == returnChar) ? Okteta::Character(mSubstituteChar) :
145  byteChar;
146  *stream << streamChar;
147 
148  e = t + 1;
149  }
150  }
151  else
152  {
153  QString E;
154  E.resize( mValueCodec->encodingWidth() );
155  // draw individual chars
156  for( ; p<pEnd; ++p, ++mOffset )
157  {
158  // get next position
159  const uint t = mLinePositions[p];
160  // clear spacing
161  *stream << whiteSpace( t-e );
162  mValueCodec->encode( E, 0, mByteArrayModel->byte(mOffset) );
163  *stream << E;
164  e = t + mValueCodec->encodingWidth();
165  }
166  }
167 
168  *stream << whiteSpace( mNoOfCharsPerLine-e );
169 
170  if( isSubline || mVisibleCodings < 3 )
171  ++mRenderLine;
172  else
173  mOffset = lineOffset;
174 }
175 
176 
177 ByteArrayRowsColumnTextRenderer::~ByteArrayRowsColumnTextRenderer()
178 {
179  delete [] mLinePositions;
180  delete mCharCodec;
181  delete mValueCodec;
182 }
183 
184 }
Kasten2::ByteArrayRowsColumnTextRenderer::~ByteArrayRowsColumnTextRenderer
virtual ~ByteArrayRowsColumnTextRenderer()
Definition: bytearrayrowscolumntextrenderer.cpp:177
Okteta::CoordRange
describes a range in the buffercoord
Definition: coordrange.h:51
character.h
Okteta::Address
qint32 Address
Definition: address.h:34
Okteta::AbstractByteArrayModel
could it be useful to hide the data access behind an iterator? * class KDataBufferIterator { public: ...
Definition: abstractbytearraymodel.h:79
Kasten2::ByteArrayRowsColumnTextRenderer::mOffset
Okteta::Address mOffset
Data to print.
Definition: bytearrayrowscolumntextrenderer.h:88
abstractbytearraymodel.h
Kasten2::AbstractColumnTextRenderer::whiteSpace
static QString whiteSpace(unsigned int length)
Definition: abstractcolumntextrenderer.cpp:35
Kasten2::ByteArrayRowsColumnTextRenderer::mNoOfBytesPerLine
const int mNoOfBytesPerLine
Definition: bytearrayrowscolumntextrenderer.h:77
KDE::Range::start
T start() const
Definition: range.h:86
Okteta::Character::isUndefined
bool isUndefined() const
Definition: character.h:52
Okteta::CharCodec::decode
virtual Character decode(Byte byte) const =0
Kasten2::ByteArrayRowsColumnTextRenderer::mVisibleCodings
const int mVisibleCodings
Definition: bytearrayrowscolumntextrenderer.h:79
Kasten2::ByteArrayRowsColumnTextRenderer::ByteArrayRowsColumnTextRenderer
ByteArrayRowsColumnTextRenderer(const Okteta::AbstractByteArrayModel *byteArrayModel, Okteta::Address offset, const Okteta::CoordRange &coordRange, int noOfBytesPerLine, int byteSpacingWidth, int noOfGroupedBytes, int visibleCodings, Okteta::ValueCoding valueCoding, const QString &charCodecName, QChar substituteChar, QChar undefinedChar)
Definition: bytearrayrowscolumntextrenderer.cpp:37
Kasten2::ByteArrayRowsColumnTextRenderer::mByteArrayModel
const Okteta::AbstractByteArrayModel * mByteArrayModel
Definition: bytearrayrowscolumntextrenderer.h:73
Kasten2::ByteArrayRowsColumnTextRenderer::renderLine
void renderLine(QTextStream *stream, bool isSubline) const
Definition: bytearrayrowscolumntextrenderer.cpp:112
Kasten2::ByteArrayRowsColumnTextRenderer::mLinePositions
int *const mLinePositions
Definition: bytearrayrowscolumntextrenderer.h:93
KDE::Range::end
T end() const
Definition: range.h:88
valuecodec.h
Kasten2::ByteArrayRowsColumnTextRenderer::mNoOfCharsPerLine
int mNoOfCharsPerLine
buffered value of how many chars a line needs
Definition: bytearrayrowscolumntextrenderer.h:91
Okteta::AbstractByteArrayModel::byte
virtual Byte byte(Address offset) const =0
locates working range The idea behind is to tell buffer which range will be requested in the followin...
Kasten2::ByteArrayRowsColumnTextRenderer::renderFirstLine
virtual void renderFirstLine(QTextStream *stream, int lineIndex) const
Definition: bytearrayrowscolumntextrenderer.cpp:100
Kasten2::ByteArrayRowsColumnTextRenderer::mValueCodec
const Okteta::ValueCodec * mValueCodec
Definition: bytearrayrowscolumntextrenderer.h:80
charcodec.h
Kasten2::ByteArrayRowsColumnTextRenderer::mSubstituteChar
const QChar mSubstituteChar
Definition: bytearrayrowscolumntextrenderer.h:82
Kasten2::ByteArrayRowsColumnTextRenderer::renderNextLine
virtual void renderNextLine(QTextStream *stream, bool isSubline) const
Definition: bytearrayrowscolumntextrenderer.cpp:107
Kasten2::ByteArrayRowsColumnTextRenderer::setWidths
void setWidths(int byteWidth, int byteSpacingWidth, int noOfGroupedBytes)
Definition: bytearrayrowscolumntextrenderer.cpp:66
N
Okteta::ValueCoding
ValueCoding
Definition: oktetacore.h:34
bytearrayrowscolumntextrenderer.h
Kasten2::ByteArrayRowsColumnTextRenderer::mCharCodec
const Okteta::CharCodec * mCharCodec
Definition: bytearrayrowscolumntextrenderer.h:81
Kasten2::ByteArrayRowsColumnTextRenderer::mCoordRange
const Okteta::CoordRange mCoordRange
Definition: bytearrayrowscolumntextrenderer.h:75
Kasten2::ByteArrayRowsColumnTextRenderer::mUndefinedChar
const QChar mUndefinedChar
Definition: bytearrayrowscolumntextrenderer.h:83
Okteta::ValueCodec::encodingWidth
virtual unsigned int encodingWidth() const =0
Kasten2::ByteArrayRowsColumnTextRenderer::mRenderLine
int mRenderLine
Line to print.
Definition: bytearrayrowscolumntextrenderer.h:86
Okteta::Character
Definition: character.h:35
Kasten2::ByteArrayRowsColumnTextRenderer::noOfSublinesNeeded
virtual int noOfSublinesNeeded() const
default returns 1
Definition: bytearrayrowscolumntextrenderer.cpp:61
Okteta::ValueCodec::encode
virtual void encode(QString &digits, unsigned int pos, Byte byte) const =0
Encodes the byte using full coding width, prefixing with 0s if needed, and writes the result to digit...
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 23:04:07 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

okteta

Skip menu "okteta"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Related Pages

kdesdk API Reference

Skip menu "kdesdk API Reference"
  • kapptemplate
  • kcachegrind
  • kompare
  • lokalize
  • okteta
  • umbrello
  •   umbrello

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal