• 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
  • controllers
  • view
  • bytetable
bytetablemodel.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 2007 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 "bytetablemodel.h"
24 
25 // Okteta core
26 #include <character.h>
27 #include <charcodec.h>
28 #include <valuecodec.h>
29 // KDE
30 #include <KLocale>
31 
32 
33 namespace Kasten2
34 {
35 
36 static const unsigned char ByteTableDefaultUndefinedChar = '?';
37 static const int ByteSetSize = 256;
38 
39 
40 ByteTableModel::ByteTableModel( QObject *parent )
41  : QAbstractTableModel( parent ),
42  mCharCodec( Okteta::CharCodec::createCodec(Okteta::LocalEncoding) ),
43  mUndefinedChar( QLatin1Char(ByteTableDefaultUndefinedChar) )
44 {
45  static const Okteta::ValueCoding CodingIds[NofOfValueCodings] =
46  {
47  Okteta::DecimalCoding,
48  Okteta::HexadecimalCoding,
49  Okteta::OctalCoding,
50  Okteta::BinaryCoding
51  };
52  for( int i=0; i<NofOfValueCodings; ++i )
53  mValueCodec[i] = Okteta::ValueCodec::createCodec( CodingIds[i] );
54 }
55 
56 void ByteTableModel::setUndefinedChar( QChar undefinedChar )
57 {
58  mUndefinedChar = undefinedChar;
59 
60  emit dataChanged( index(0,CharacterId), index(ByteSetSize-1,CharacterId) );
61 }
62 
63 void ByteTableModel::setCharCodec( const QString &codeName )
64 {
65  if( codeName == mCharCodec->name() )
66  return;
67 
68  delete mCharCodec;
69  mCharCodec = Okteta::CharCodec::createCodec( codeName );
70 
71  emit dataChanged( index(0,CharacterId), index(ByteSetSize-1,CharacterId) );
72 }
73 
74 int ByteTableModel::rowCount( const QModelIndex &parent ) const
75 {
76  return (! parent.isValid()) ? ByteSetSize : 0;
77 }
78 
79 int ByteTableModel::columnCount( const QModelIndex &parent ) const
80 {
81  return (! parent.isValid()) ? NoOfIds : 0;
82 }
83 
84 QVariant ByteTableModel::data( const QModelIndex &index, int role ) const
85 {
86  QVariant result;
87  if( role == Qt::DisplayRole )
88  {
89  QString content;
90 
91  const unsigned char byte = index.row();
92  const int column = index.column();
93  if( column == CharacterId )
94  {
95  const Okteta::Character decodedChar = mCharCodec->decode( byte );
96  content =
97  decodedChar.isUndefined() ?
98  i18nc( "@item:intable character is not defined", "undef." ) :
99  (decodedChar.unicode() == 0x09) ? // tab only creates a wider column
100  QString() :
101  QString( static_cast<QChar>(decodedChar) );
102  // TODO: show proper descriptions for all control values, incl. space and delete
103  // cmp. KCharSelect
104  }
105  else if( column < CharacterId )
106  mValueCodec[column]->encode( content, 0, byte );
107 
108  result = content;
109  }
110  else if( role == Qt::TextAlignmentRole )
111  result = Qt::AlignRight;
112 
113  return result;
114 }
115 
116 QVariant ByteTableModel::headerData( int section, Qt::Orientation orientation, int role ) const
117 {
118  QVariant result;
119 
120  if( role == Qt::DisplayRole )
121  {
122  const QString titel =
123  section == DecimalId ? i18nc("@title:column short for Decimal", "Dec") :
124  section == HexadecimalId ? i18nc("@title:column short for Hexadecimal","Hex") :
125  section == OctalId ? i18nc("@title:column short for Octal", "Oct") :
126  section == BinaryId ? i18nc("@title:column short for Binary", "Bin") :
127  section == CharacterId ? i18nc("@title:column short for Character", "Char") :
128  QString();
129  result = titel;
130  }
131  else if( role == Qt::ToolTipRole )
132  {
133  const QString titel =
134  section == DecimalId ?
135  i18nc("@info:tooltip column contains the value in decimal format", "Decimal") :
136  section == HexadecimalId ?
137  i18nc("@info:tooltip column contains the value in hexadecimal format","Hexadecimal") :
138  section == OctalId ?
139  i18nc("@info:tooltip column contains the value in octal format", "Octal") :
140  section == BinaryId ?
141  i18nc("@info:tooltip column contains the value in binary format", "Binary") :
142  section == CharacterId ?
143  i18nc("@info:tooltip column contains the character with the value", "Character") :
144  QString();
145  result = titel;
146  }
147  else
148  result = QAbstractTableModel::headerData( section, orientation, role );
149 
150  return result;
151 }
152 
153 ByteTableModel::~ByteTableModel()
154 {
155  for( int i=0; i<NofOfValueCodings; ++i )
156  delete mValueCodec[i];
157  delete mCharCodec;
158 }
159 
160 }
character.h
Kasten2::ByteTableModel::setCharCodec
void setCharCodec(const QString &codecName)
Definition: bytetablemodel.cpp:63
Okteta::ValueCodec::createCodec
static ValueCodec * createCodec(ValueCoding valueCoding)
Definition: valuecodec.cpp:36
Kasten2::ByteTableModel::~ByteTableModel
virtual ~ByteTableModel()
Definition: bytetablemodel.cpp:153
Kasten2::ByteTableModel::DecimalId
Definition: bytetablemodel.h:45
Kasten2::ByteTableModel::setUndefinedChar
void setUndefinedChar(QChar undefinedChar)
Definition: bytetablemodel.cpp:56
Kasten2::ByteTableModel::BinaryId
Definition: bytetablemodel.h:48
Okteta::Character::isUndefined
bool isUndefined() const
Definition: character.h:52
Kasten2::ByteTableModel::NoOfIds
Definition: bytetablemodel.h:50
Kasten2::ByteTableModel::ByteTableModel
ByteTableModel(QObject *parent=0)
Definition: bytetablemodel.cpp:40
Okteta::CharCodec::decode
virtual Character decode(Byte byte) const =0
Kasten2::ByteTableModel::CharacterId
Definition: bytetablemodel.h:49
QObject
Kasten2::ByteTableDefaultUndefinedChar
static const unsigned char ByteTableDefaultUndefinedChar
Definition: bytetablemodel.cpp:36
Okteta::OctalCoding
Definition: oktetacore.h:34
Kasten2::ByteTableModel::headerData
virtual QVariant headerData(int section, Qt::Orientation orientation, int role) const
Definition: bytetablemodel.cpp:116
Kasten2::ByteTableModel::OctalId
Definition: bytetablemodel.h:47
Okteta::CharCodec::createCodec
static CharCodec * createCodec(CharCoding charCoding)
Definition: charcodec.cpp:68
bytetablemodel.h
Okteta::DecimalCoding
Definition: oktetacore.h:34
valuecodec.h
Okteta::BinaryCoding
Definition: oktetacore.h:34
Kasten2::ByteTableModel::HexadecimalId
Definition: bytetablemodel.h:46
charcodec.h
Okteta::ValueCoding
ValueCoding
Definition: oktetacore.h:34
Okteta::CharCodec::name
virtual const QString & name() const =0
Okteta::LocalEncoding
the coding of your shell
Definition: oktetacore.h:42
Kasten2::ByteSetSize
static const int ByteSetSize
Definition: bytetablemodel.cpp:37
Okteta::Character
Definition: character.h:35
Kasten2::ByteTableModel::data
virtual QVariant data(const QModelIndex &index, int role) const
Definition: bytetablemodel.cpp:84
Kasten2::ByteTableModel::columnCount
virtual int columnCount(const QModelIndex &parent) const
Definition: bytetablemodel.cpp:79
QAbstractTableModel
Okteta::HexadecimalCoding
Definition: oktetacore.h:34
Kasten2::ByteTableModel::rowCount
virtual int rowCount(const QModelIndex &parent) const
Definition: bytetablemodel.cpp:74
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