• 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
  • info
statistictablemodel.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 "statistictablemodel.h"
24 
25 // Okteta core
26 #include <character.h>
27 #include <charcodec.h>
28 #include <valuecodec.h>
29 // KDE
30 #include <KLocale>
31 #include <KApplication>
32 #include <KColorScheme>
33 
34 
35 namespace Kasten2
36 {
37 
38 static const unsigned char StatisticsDefaultUndefinedChar = '?';
39 static const Okteta::ValueCoding DefaultValueCoding = Okteta::HexadecimalCoding;
40 static const int StatisticsByteSetSize = 256;
41 
42 
43 StatisticTableModel::StatisticTableModel( int *byteCount, QObject *parent )
44  : QAbstractTableModel( parent ),
45  mByteCount( byteCount ),
46  mValueCoding( DefaultValueCoding ),
47  mValueCodec( Okteta::ValueCodec::createCodec(DefaultValueCoding) ),
48  mCharCodec( Okteta::CharCodec::createCodec(Okteta::LocalEncoding) ),
49  mUndefinedChar( QLatin1Char(StatisticsDefaultUndefinedChar) )
50 {
51 }
52 
53 void StatisticTableModel::update( int size )
54 {
55  mSize = size;
56  emit dataChanged( index(0,CountId), index(StatisticsByteSetSize-1,PercentId) );
57  emit sizeChanged( mSize );
58 }
59 
60 void StatisticTableModel::setUndefinedChar( QChar undefinedChar )
61 {
62  mUndefinedChar = undefinedChar;
63 
64  emit dataChanged( index(0,CharacterId), index(StatisticsByteSetSize-1,CharacterId) );
65 }
66 
67 void StatisticTableModel::setValueCoding( int valueCoding )
68 {
69  // no changes?
70  if( mValueCoding == valueCoding )
71  return;
72 
73  delete mValueCodec;
74 
75  mValueCoding = (Okteta::ValueCoding)valueCoding;
76  mValueCodec = Okteta::ValueCodec::createCodec( mValueCoding );
77 // CodedByte.resize( ByteCodec->encodingWidth() );
78 
79  emit dataChanged( index(0,ValueId), index(StatisticsByteSetSize-1,ValueId) );
80  emit headerChanged();
81 }
82 
83 void StatisticTableModel::setCharCodec( const QString &codeName )
84 {
85  if( codeName == mCharCodec->name() )
86  return;
87 
88  delete mCharCodec;
89  mCharCodec = Okteta::CharCodec::createCodec( codeName );
90 
91  emit dataChanged( index(0,CharacterId), index(StatisticsByteSetSize-1,CharacterId) );
92 }
93 
94 
95 int StatisticTableModel::rowCount( const QModelIndex &parent ) const
96 {
97  return (! parent.isValid()) ? StatisticsByteSetSize : 0;
98 }
99 
100 int StatisticTableModel::columnCount( const QModelIndex &parent ) const
101 {
102  return (! parent.isValid()) ? NoOfIds : 0;
103 }
104 
105 QVariant StatisticTableModel::data( const QModelIndex &index, int role ) const
106 {
107  QVariant result;
108  if( role == Qt::DisplayRole )
109  {
110  const unsigned char byte = index.row();
111  const int column = index.column();
112  switch( column )
113  {
114  case CharacterId:
115  {
116  const Okteta::Character decodedChar = mCharCodec->decode( byte );
117  result =
118  decodedChar.isUndefined() ?
119  i18nc( "@item:intable character is not defined", "undef." ) :
120  (decodedChar.unicode() == 0x09) ? // tab only creates a wider column
121  QString() :
122  QString( static_cast<QChar>(decodedChar) );
123  // TODO: show proper descriptions for all control values, incl. space and delete
124  // cmp. KCharSelect
125  break;
126  }
127  case ValueId:
128  {
129  QString value;
130  mValueCodec->encode( value, 0, byte );
131  result = value;
132  break;
133  }
134  case CountId:
135  result = ( mSize == -1 ) ?
136  QVariant( QLatin1String("-") ) :
137  QVariant( mByteCount[byte] );
138  break;
139  case PercentId:
140  result = ( mSize > 0 ) ?
141  // TODO: before we printed only a string (which killed sorting) with QString::number( x, 'f', 6 )
142  // Qt now cuts trailing 0s, results in unaligned numbers, not so beautiful.
143  QVariant( 100.0*(double)mByteCount[byte]/mSize ) :
144  QVariant( QLatin1String("-") );
145  break;
146  default:
147  ;
148  }
149  }
150  else if( role == Qt::TextAlignmentRole )
151  result = Qt::AlignRight;
152  else if( role == Qt::ForegroundRole )
153  {
154  const int column = index.column();
155  bool isInactive = false;
156  switch( column )
157  {
158  case CountId:
159  isInactive = ( mSize == -1 );
160  break;
161  case PercentId:
162  isInactive = ( mSize <= 0 );
163  break;
164  default:
165  ;
166  }
167  if( isInactive )
168  {
169  const QPalette& palette = KApplication::kApplication()->palette();
170  const KColorScheme colorScheme( palette.currentColorGroup(), KColorScheme::View );
171  result = colorScheme.foreground( KColorScheme::InactiveText );
172  }
173  }
174 
175  return result;
176 }
177 
178 QVariant StatisticTableModel::headerData( int section, Qt::Orientation orientation, int role ) const
179 {
180  QVariant result;
181 
182  if( role == Qt::DisplayRole )
183  {
184  const QString titel =
185  section == ValueId ? (
186  mValueCoding == Okteta::HexadecimalCoding ? i18nc("@title:column short for Hexadecimal","Hex") :
187  mValueCoding == Okteta::DecimalCoding ? i18nc("@title:column short for Decimal", "Dec") :
188  mValueCoding == Okteta::OctalCoding ? i18nc("@title:column short for Octal", "Oct") :
189  mValueCoding == Okteta::BinaryCoding ? i18nc("@title:column short for Binary", "Bin") :
190  QString() ) :
191  section == CharacterId ? i18nc("@title:column short for Character", "Char") :
192  section == CountId ? i18nc("@title:column count of characters", "Count") :
193  section == PercentId ? i18nc("@title:column Percent of byte in total", "Percent") :
194  QString();
195  result = titel;
196  }
197  else if( role == Qt::ToolTipRole )
198  {
199  const QString titel =
200  section == ValueId ? (
201  mValueCoding == Okteta::HexadecimalCoding ?
202  i18nc("@info:tooltip column contains the value in hexadecimal format","Hexadecimal") :
203  mValueCoding == Okteta::DecimalCoding ?
204  i18nc("@info:tooltip column contains the value in decimal format", "Decimal") :
205  mValueCoding == Okteta::OctalCoding ?
206  i18nc("@info:tooltip column contains the value in octal format", "Octal") :
207  mValueCoding == Okteta::BinaryCoding ?
208  i18nc("@info:tooltip column contains the value in binary format", "Binary") :
209  // else
210  QString() ) :
211  section == CharacterId ?
212  i18nc("@info:tooltip column contains the character with the value", "Character") :
213 // section == CountId ? i18nc("@info:tooltip count of characters", "Count") :
214 // section == PercentId ? i18nc("@info:tooltip Percent of byte in total", "Percent") :
215  QString();
216  result = titel;
217  }
218  else
219  result = QAbstractTableModel::headerData( section, orientation, role );
220 
221  return result;
222 }
223 
224 StatisticTableModel::~StatisticTableModel()
225 {
226  delete mValueCodec;
227  delete mCharCodec;
228 }
229 
230 }
character.h
Okteta::ValueCodec::createCodec
static ValueCodec * createCodec(ValueCoding valueCoding)
Definition: valuecodec.cpp:36
Kasten2::StatisticTableModel::columnCount
virtual int columnCount(const QModelIndex &parent) const
Definition: statistictablemodel.cpp:100
Kasten2::StatisticTableModel::sizeChanged
void sizeChanged(int size)
Kasten2::StatisticTableModel::rowCount
virtual int rowCount(const QModelIndex &parent) const
Definition: statistictablemodel.cpp:95
Kasten2::StatisticsDefaultUndefinedChar
static const unsigned char StatisticsDefaultUndefinedChar
Definition: statistictablemodel.cpp:38
Okteta::Character::isUndefined
bool isUndefined() const
Definition: character.h:52
Kasten2::StatisticTableModel::~StatisticTableModel
virtual ~StatisticTableModel()
Definition: statistictablemodel.cpp:224
Okteta::CharCodec::decode
virtual Character decode(Byte byte) const =0
Kasten2::StatisticTableModel::data
virtual QVariant data(const QModelIndex &index, int role) const
Definition: statistictablemodel.cpp:105
QObject
Kasten2::StatisticTableModel::CharacterId
Definition: statistictablemodel.h:48
Kasten2::StatisticTableModel::CountId
Definition: statistictablemodel.h:49
Okteta::OctalCoding
Definition: oktetacore.h:34
Kasten2::StatisticTableModel::setUndefinedChar
void setUndefinedChar(QChar undefinedChar)
Definition: statistictablemodel.cpp:60
Kasten2::StatisticTableModel::StatisticTableModel
StatisticTableModel(int *byteCount, QObject *parent=0)
Definition: statistictablemodel.cpp:43
Okteta::CharCodec::createCodec
static CharCodec * createCodec(CharCoding charCoding)
Definition: charcodec.cpp:68
Okteta::DecimalCoding
Definition: oktetacore.h:34
Kasten2::StatisticTableModel::update
void update(int size)
Definition: statistictablemodel.cpp:53
valuecodec.h
Okteta::BinaryCoding
Definition: oktetacore.h:34
Kasten2::StatisticTableModel::setValueCoding
void setValueCoding(int valueCoding)
Definition: statistictablemodel.cpp:67
statistictablemodel.h
charcodec.h
Kasten2::StatisticTableModel::setCharCodec
void setCharCodec(const QString &codecName)
Definition: statistictablemodel.cpp:83
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::StatisticTableModel::ValueId
Definition: statistictablemodel.h:47
Kasten2::StatisticsByteSetSize
static const int StatisticsByteSetSize
Definition: statistictablemodel.cpp:40
Kasten2::StatisticTableModel::headerChanged
void headerChanged()
Kasten2::DefaultValueCoding
static const Okteta::ValueCoding DefaultValueCoding
Definition: statistictablemodel.cpp:39
Okteta::Character
Definition: character.h:35
Kasten2::StatisticTableModel::headerData
virtual QVariant headerData(int section, Qt::Orientation orientation, int role) const
Definition: statistictablemodel.cpp:178
QAbstractTableModel
Kasten2::StatisticTableModel::NoOfIds
Definition: statistictablemodel.h:51
Okteta::HexadecimalCoding
Definition: oktetacore.h:34
Kasten2::StatisticTableModel::PercentId
Definition: statistictablemodel.h:50
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:09 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