• 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
  • structures
  • datatypes
  • strings
stringdatainformation.cpp
Go to the documentation of this file.
1 /*
2  * This file is part of the Okteta Kasten Framework, made within the KDE community.
3  *
4  * Copyright 2011, 2012 Alex Richardson <alex.richardson@gmx.de>
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 
24 
25 #include "stringdatainformation.h"
26 #include "../dummydatainformation.h"
27 #include "../topleveldatainformation.h"
28 #include "utf32stringdata.h"
29 #include "utf16stringdata.h"
30 #include "utf8stringdata.h"
31 #include "asciistringdata.h"
32 #include "latin1stringdata.h"
33 #include "../../script/classes/stringscriptclass.h"
34 #include "../../script/scripthandlerinfo.h"
35 #include "../../script/scriptlogger.h"
36 
37 #include <QScriptEngine>
38 #include <QBrush>
39 #include <QString>
40 
41 #include <KLocale>
42 
43 StringDataInformation::StringDataInformation(const QString& name, StringType encoding, DataInformationBase* parent)
44  : DataInformationWithDummyChildren(name, parent), mDummy(new DummyDataInformation(this)), mData(0), mEncoding(InvalidEncoding)
45 {
46  setEncoding(encoding); //sets mData
47 }
48 
49 StringDataInformation::StringDataInformation(const StringDataInformation& d)
50  : DataInformationWithDummyChildren(d), mDummy(new DummyDataInformation(this)), mData(0), mEncoding(InvalidEncoding)
51 {
52  setEncoding(d.mEncoding); //sets mData
53  mData->copyTerminationFrom(d.mData.data());
54 }
55 
56 StringDataInformation::~StringDataInformation()
57 {
58 }
59 
60 DataInformation* StringDataInformation::childAt(unsigned int index) const
61 {
62  Q_ASSERT(index < childCount());
63  mDummy->setDummyIndex(index);
64  return mDummy.data();
65 }
66 
67 bool StringDataInformation::setData(const QVariant&, Okteta::AbstractByteArrayModel*,
68  Okteta::Address, BitCount64, quint8)
69 {
70  Q_ASSERT_X(false, "StringDataInformation::setData()", "this should never be called!");
71  return false;
72 }
73 
74 bool StringDataInformation::setChildData(uint row, const QVariant& value, Okteta::AbstractByteArrayModel* out, Okteta::Address address, BitCount64 bitsRemaining, quint8 bitOffset)
75 {
76  Q_UNUSED(row)
77  Q_UNUSED(value)
78  Q_UNUSED(out)
79  Q_UNUSED(address)
80  Q_UNUSED(bitsRemaining)
81  Q_UNUSED(bitOffset)
82  logWarn() << "setChildData not implemented yet!";
83  return false;
84 }
85 
86 
87 qint64 StringDataInformation::readData(Okteta::AbstractByteArrayModel* input, Okteta::Address address,
88  BitCount64 bitsRemaining, quint8* bitOffset)
89 {
90  Q_ASSERT(mHasBeenUpdated); //update must have been called prior to reading
91  if (*bitOffset != 0)
92  {
93  logWarn() << "while reading string bit offset was: " << *bitOffset
94  << ", adding padding and continuing at next byte (address=" << address << ")";
95  bitsRemaining -= 8 - *bitOffset;
96  *bitOffset = 0;
97  address += 1;
98  Q_ASSERT((bitsRemaining % 8) == 0); //must be mod 8
99  }
100  qint64 ret = mData->read(input, address, bitsRemaining);
101  mWasAbleToRead = ret >= 0;
102  return ret;
103 }
104 
105 BitCount32 StringDataInformation::size() const
106 {
107  return mData->size();
108 }
109 
110 void StringDataInformation::setWidgetData(QWidget*) const
111 {
112  //TODO
113 }
114 
115 QVariant StringDataInformation::dataFromWidget(const QWidget*) const
116 {
117  //TODO
118  Q_ASSERT(false);
119  return QVariant();
120 }
121 
122 QWidget* StringDataInformation::createEditWidget(QWidget*) const
123 {
124  //TODO
125  Q_ASSERT(false);
126  return 0;
127 }
128 
129 QString StringDataInformation::typeNameImpl() const
130 {
131  return mData->typeName();
132 }
133 
134 unsigned int StringDataInformation::childCount() const
135 {
136  return mData->count();
137 }
138 
139 Qt::ItemFlags StringDataInformation::flags(int column, bool fileLoaded) const
140 {
141  return DataInformation::flags(column, fileLoaded);
142 }
143 
144 QVariant StringDataInformation::childData(int row, int column, int role) const
145 {
146  Q_ASSERT(row >= 0 && (unsigned)row < childCount());
147  Q_ASSERT(column < COLUMN_COUNT);
148  if (role == Qt::DisplayRole)
149  {
150  if (column == ColumnName)
151  {
152  //TODO termination char
153  return QString(QLatin1Char('[') + QString::number(row) + QLatin1Char(']'));
154  }
155  else if (column == ColumnType)
156  {
157  return mData->charType();
158  }
159  else if (column == ColumnValue)
160  {
161  return mData->stringValue(row);
162  }
163  }
164  //TODO mark eof reached, don't add extra item. i.e. add icon or colour
165  return QVariant();
166 }
167 
168 QString StringDataInformation::valueStringImpl() const
169 {
170  Q_ASSERT(mWasAbleToRead);
171  return mData->completeString();
172 }
173 
174 Qt::ItemFlags StringDataInformation::childFlags(int row, int column, bool fileLoaded) const
175 {
176  Q_UNUSED(fileLoaded);
177  Q_UNUSED(row);
178  Q_UNUSED(column);
179  return Qt::ItemIsSelectable | Qt::ItemIsEnabled; //not editable atm
180  //TODO make editable
181 }
182 
183 void StringDataInformation::setEncoding(StringDataInformation::StringType encoding)
184 {
185  if (mData && mEncoding == encoding)
186  return;
187  if (mData && ((mEncoding == UTF16_LE && encoding == UTF16_BE) || (mEncoding == UTF16_BE || encoding == UTF16_LE)))
188  {
189  //only set endianess, since is already utf 16
190  mData->setLittleEndian(encoding == UTF16_LE);
191  }
192  else if (mData && ((mEncoding == UTF32_LE && encoding == UTF32_BE) || (mEncoding == UTF32_BE && encoding == UTF32_LE)))
193  {
194  //only set endianess, since is already utf 32
195  mData->setLittleEndian(encoding == UTF32_LE);
196  }
197  else
198  {
199  StringData* data = 0;
200  switch (encoding) {
201  case ASCII:
202  data = new AsciiStringData(this);
203  break;
204  case Latin1:
205  data = new Latin1StringData(this);
206  break;
207  case UTF8:
208  data = new Utf8StringData(this);
209  break;
210  case UTF16_LE:
211  data = new Utf16StringData(this);
212  data->setLittleEndian(true);
213  break;
214  case UTF16_BE:
215  data = new Utf16StringData(this);
216  data->setLittleEndian(false);
217  break;
218  case UTF32_LE:
219  data = new Utf32StringData(this);
220  data->setLittleEndian(true);
221  break;
222  case UTF32_BE:
223  data = new Utf32StringData(this);
224  data->setLittleEndian(false);
225  break;
226  default:
227  data = new AsciiStringData(this); //TODO add the other classes
228  break;
229  }
230  if (mData)
231  data->copyTerminationFrom(mData.data());
232  mData.reset(data);
233  }
234  mEncoding = encoding;
235 }
236 //TODO implement string editing
237 
238 BitCount32 StringDataInformation::childSize(uint index) const
239 {
240  return mData->sizeAt(index);
241 }
242 
243 QString StringDataInformation::childTypeName(uint index) const
244 {
245  Q_UNUSED(index)
246  return QString(); //XXX should there be something here?
247 }
248 
249 void StringDataInformation::setChildWidgetData(uint index, QWidget* w) const
250 {
251  Q_ASSERT(false);
252  Q_ASSERT(index < mData->count());
253  Q_UNUSED(index)
254  Q_UNUSED(w)
255 }
256 
257 QVariant StringDataInformation::dataFromChildWidget(uint index, const QWidget* w) const
258 {
259  Q_ASSERT(index < mData->count());
260  Q_ASSERT(false);
261  Q_UNUSED(w)
262  Q_UNUSED(index)
263  return QVariant();
264 }
265 
266 QWidget* StringDataInformation::createChildEditWidget(uint index, QWidget* parent) const
267 {
268  Q_ASSERT(false);
269  Q_UNUSED(parent)
270  Q_UNUSED(index)
271  return 0;
272 }
273 
274 QScriptValue StringDataInformation::childToScriptValue(uint index, QScriptEngine*, ScriptHandlerInfo*) const
275 {
276  //just return as a string
277  return mData->stringValue(index);
278 }
279 
280 BitCount64 StringDataInformation::childPosition(const DataInformation* child, Okteta::Address start) const
281 {
282  Q_UNUSED(start)
283  Q_ASSERT(child->isDummy());
284  Q_ASSERT(child->parent() == this);
285  Q_ASSERT(child == mDummy.data());
286  Q_UNUSED(child)
287  uint index = mDummy->dummyIndex();
288  Q_ASSERT(index < mData->count());
289  BitCount32 offs = 0;
290  for (uint i = 0; i < index; ++i)
291  {
292  offs += mData->sizeAt(i);
293  }
294  return offs;
295 }
296 
297 QVariant StringDataInformation::data(int column, int role) const
298 {
299  if (mData->wasEof())
300  {
301  if (role == Qt::BackgroundRole)
302  return QBrush(Qt::yellow);
303  else if (role == Qt::ToolTipRole)
304  return i18n("End of file reached prematurely");
305  }
306  return DataInformation::data(column, role);
307 }
308 
309 bool StringDataInformation::isString() const
310 {
311  return true;
312 }
313 
314 void StringDataInformation::unsetTerminationMode(StringData::TerminationMode mode)
315 {
316  //clear the mode and set to null terminated of none is left
317  mData->setTerminationMode(StringData::TerminationMode(mData->terminationMode() & ~mode));
318  if (mData->terminationMode() == StringData::None)
319  mData->setTerminationCodePoint(0);
320 }
321 
322 QScriptClass* StringDataInformation::scriptClass(ScriptHandlerInfo* handlerInfo) const
323 {
324  return handlerInfo->mStringClass.data();
325 }
DataInformation
Interface that must be implemented by all datatypes.
Definition: datainformation.h:67
StringDataInformation::UTF8
Definition: stringdatainformation.h:44
StringDataInformation::size
virtual BitCount32 size() const
the size in bits of this element
Definition: stringdatainformation.cpp:105
DataInformationWithDummyChildren
This class declares all methods that are needed if there can be dummy children.
Definition: dummydatainformation.h:73
StringDataInformation::childData
virtual QVariant childData(int row, int column, int role) const
the data of child at index row.
Definition: stringdatainformation.cpp:144
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
StringDataInformation::~StringDataInformation
virtual ~StringDataInformation()
Definition: stringdatainformation.cpp:56
StringData
Definition: stringdata.h:36
StringDataInformation::UTF16_BE
Definition: stringdatainformation.h:44
StringDataInformation::childPosition
virtual BitCount64 childPosition(const DataInformation *child, Okteta::Address start) const
Definition: stringdatainformation.cpp:280
StringDataInformation::isString
virtual bool isString() const
Definition: stringdatainformation.cpp:309
DummyDataInformation
Definition: dummydatainformation.h:30
QScriptClass
BitCount64
quint64 BitCount64
Definition: datainformationbase.h:42
StringDataInformation::setWidgetData
virtual void setWidgetData(QWidget *w) const
initialize the delegate widget with the correct data
Definition: stringdatainformation.cpp:110
QWidget
StringDataInformation::childToScriptValue
virtual QScriptValue childToScriptValue(uint index, QScriptEngine *engine, ScriptHandlerInfo *handlerInfo) const
Definition: stringdatainformation.cpp:274
Latin1StringData
Definition: latin1stringdata.h:33
StringDataInformation::flags
virtual Qt::ItemFlags flags(int column, bool fileLoaded=true) const
Definition: stringdatainformation.cpp:139
stringdatainformation.h
Utf32StringData
Definition: utf32stringdata.h:29
StringDataInformation::setChildWidgetData
virtual void setChildWidgetData(uint index, QWidget *w) const
initialize the delegate widget with the correct data
Definition: stringdatainformation.cpp:249
DataInformation::ColumnType
Definition: datainformation.h:84
StringDataInformation::Latin1
Definition: stringdatainformation.h:44
BitCount32
quint32 BitCount32
Definition: datainformationbase.h:37
StringDataInformation::createChildEditWidget
virtual QWidget * createChildEditWidget(uint index, QWidget *parent) const
create a QWidget for the QItemDelegate
Definition: stringdatainformation.cpp:266
StringDataInformation::ASCII
Definition: stringdatainformation.h:44
StringDataInformation::data
virtual QVariant data(int column, int role) const
get the necessary data (for the model)
Definition: stringdatainformation.cpp:297
DataInformation::ColumnValue
Definition: datainformation.h:84
DataInformation::flags
virtual Qt::ItemFlags flags(int column, bool fileLoaded=true) const
Definition: datainformation.h:251
StringDataInformation::unsetTerminationMode
void unsetTerminationMode(StringData::TerminationMode mode)
Removes this mode from the termination modes.
Definition: stringdatainformation.cpp:314
AsciiStringData
Definition: asciistringdata.h:33
Utf8StringData
Definition: utf8stringdata.h:32
StringData::setLittleEndian
virtual void setLittleEndian(bool littleEndian)
by default just sets value, if more logic is needed can be overridden
Definition: stringdata.h:149
DataInformation::mWasAbleToRead
bool mWasAbleToRead
Definition: datainformation.h:243
StringDataInformation::StringDataInformation
StringDataInformation(const QString &name, StringType encoding, DataInformationBase *parent=0)
Definition: stringdatainformation.cpp:43
StringDataInformation::childTypeName
virtual QString childTypeName(uint index) const
Definition: stringdatainformation.cpp:243
ScriptHandlerInfo::mStringClass
QScopedPointer< StringScriptClass > mStringClass
Definition: scripthandlerinfo.h:54
DataInformation::mHasBeenUpdated
bool mHasBeenUpdated
Definition: datainformation.h:242
StringDataInformation::childCount
virtual unsigned int childCount() const
Definition: stringdatainformation.cpp:134
Utf16StringData
Definition: utf16stringdata.h:32
StringDataInformation::dataFromWidget
virtual QVariant dataFromWidget(const QWidget *w) const
get the needed data from the widget
Definition: stringdatainformation.cpp:115
StringDataInformation::setData
virtual bool setData(const QVariant &value, Okteta::AbstractByteArrayModel *input, Okteta::Address address, BitCount64 bitsRemaining, quint8 bitOffset)
Writes the current data contained in this object to out.
Definition: stringdatainformation.cpp:67
StringDataInformation::setEncoding
void setEncoding(StringType encoding)
Definition: stringdatainformation.cpp:183
StringDataInformation::childSize
virtual BitCount32 childSize(uint index) const
Definition: stringdatainformation.cpp:238
StringDataInformation::StringType
StringType
Definition: stringdatainformation.h:43
latin1stringdata.h
StringDataInformation::dataFromChildWidget
virtual QVariant dataFromChildWidget(uint index, const QWidget *w) const
get the needed data from the widget
Definition: stringdatainformation.cpp:257
StringDataInformation::setChildData
virtual bool setChildData(uint row, const QVariant &value, Okteta::AbstractByteArrayModel *out, Okteta::Address address, BitCount64 bitsRemaining, quint8 bitOffset)
Definition: stringdatainformation.cpp:74
DataInformation::ColumnName
Definition: datainformation.h:84
StringDataInformation::childAt
virtual DataInformation * childAt(unsigned int) const
Definition: stringdatainformation.cpp:60
StringDataInformation::encoding
StringType encoding() const
Definition: stringdatainformation.h:110
Okteta::InvalidEncoding
Definition: oktetacore.h:105
DataInformation::data
virtual QVariant data(int column, int role) const
get the necessary data (for the model)
Definition: datainformation.cpp:156
asciistringdata.h
utf32stringdata.h
ScriptHandlerInfo
Definition: scripthandlerinfo.h:39
DataInformation::parent
DataInformationBase * parent() const
Definition: datainformation.h:309
StringDataInformation::childFlags
virtual Qt::ItemFlags childFlags(int row, int column, bool fileLoaded=true) const
Definition: stringdatainformation.cpp:174
DataInformationBase::isDummy
virtual bool isDummy() const
Definition: datainformationbase.cpp:40
DataInformationBase
Definition: datainformationbase.h:44
StringDataInformation::UTF32_LE
Definition: stringdatainformation.h:44
StringDataInformation::readData
virtual qint64 readData(Okteta::AbstractByteArrayModel *input, Okteta::Address address, BitCount64 bitsRemaining, quint8 *bitOffset)
Reads the necessary data from input and returns the number of bytes read.
Definition: stringdatainformation.cpp:87
StringData::None
Definition: stringdata.h:42
StringDataInformation::createEditWidget
virtual QWidget * createEditWidget(QWidget *parent) const
create a QWidget for the QItemDelegate
Definition: stringdatainformation.cpp:122
StringDataInformation::UTF32_BE
Definition: stringdatainformation.h:44
utf8stringdata.h
StringData::copyTerminationFrom
void copyTerminationFrom(const StringData *data)
Definition: stringdata.h:126
DataInformation::COLUMN_COUNT
Definition: datainformation.h:84
utf16stringdata.h
DataInformation::logWarn
QDebug logWarn() const
just a shorthand for logger->warn(this)
Definition: datainformation.h:319
StringDataInformation
Definition: stringdatainformation.h:39
StringDataInformation::UTF16_LE
Definition: stringdatainformation.h:44
StringData::TerminationMode
TerminationMode
Definition: stringdata.h:41
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