• 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
  • array
arraydatainformation.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 2009, 2010, 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 #include "arraydatainformation.h"
23 
24 #include <KDebug>
25 
26 #include "../primitivefactory.h"
27 #include "../dummydatainformation.h"
28 #include "../../parsers/scriptvalueconverter.h"
29 #include "../../script/classes/arrayscriptclass.h"
30 #include "../../script/scripthandlerinfo.h"
31 #include "../../script/scriptlogger.h"
32 
33 #include "complexarraydata.h"
34 #include "primitivearraydata.h"
35 
36 ArrayDataInformation::ArrayDataInformation(const QString& name, uint length, DataInformation* childType,
37  DataInformation* parent, const QScriptValue& lengthFunction)
38  : DataInformationWithDummyChildren(name, parent)
39 {
40  if (lengthFunction.isValid())
41  {
42  Q_ASSERT(lengthFunction.isFunction());
43  setLengthFunction(lengthFunction);
44  }
45  if (length > MAX_LEN)
46  {
47  logWarn() << length << "exceeds maximum length of" << MAX_LEN
48  << ". Setting it to" << MAX_LEN << "instead";
49  length = MAX_LEN;
50  }
51  Q_CHECK_PTR(childType);
52  childType->setParent(this);
53  mData.reset(AbstractArrayData::newArrayData(length, childType, this));
54 }
55 
56 ArrayDataInformation::ArrayDataInformation(const ArrayDataInformation& d)
57  : DataInformationWithDummyChildren(d), mData(0)
58 {
59  uint length = d.mData->length();
60  DataInformation* childType = d.mData.data()->childType();
61  mData.reset(AbstractArrayData::newArrayData(length, childType->clone(), this));
62 }
63 
64 ArrayDataInformation::~ArrayDataInformation()
65 {
66 }
67 
68 bool ArrayDataInformation::setArrayLength(uint newLength)
69 {
70  if (newLength > MAX_LEN)
71  {
72  logWarn() << QString(QLatin1String("new array length is too large (%1), limiting to (%2)"))
73  .arg(QString::number(newLength), QString::number(MAX_LEN));
74  newLength = MAX_LEN;
75  }
76  uint oldLength = mData->length();
77  topLevelDataInformation()->_childCountAboutToChange(this, oldLength, newLength);
78  mData->setLength(newLength);
79  topLevelDataInformation()->_childCountChanged(this, oldLength, newLength);
80  return true;
81 }
82 
83 void ArrayDataInformation::setArrayType(DataInformation* newChildType)
84 {
85  Q_CHECK_PTR(newChildType);
86  if (newChildType->isPrimitive() && newChildType->asPrimitive()->type() == mData->primitiveType())
87  {
88  //there is no need to change the type
89  logInfo() << "New and old child type are identical, skipping: " << mData->primitiveType();
90  delete newChildType;
91  return;
92  }
93  newChildType->setParent(this);
94  uint len = mData->length();
95  TopLevelDataInformation* topLevel = topLevelDataInformation();
96  if (len > 0)
97  {
98  //first create with length of 0, then change length to actual length (to ensure model is correct)
99  topLevel->_childCountAboutToChange(this, len, 0);
100  mData.reset(AbstractArrayData::newArrayData(0, newChildType, this));
101  topLevel->_childCountChanged(this, len, 0);
102 
103  topLevel->_childCountAboutToChange(this, 0, len);
104  mData->setLength(len);
105  topLevel->_childCountChanged(this, 0, len);
106  }
107  else
108  {
109  //no need to emit the signals, which cause expensive model update
110  mData.reset(AbstractArrayData::newArrayData(len, newChildType, this));
111  //only the type of the array changed -> emit that this has changed data
112  topLevel->setChildDataChanged();
113  }
114 }
115 
116 QScriptValue ArrayDataInformation::childType() const
117 {
118  return mData->typeName().toLower();
119 }
120 
121 QVariant ArrayDataInformation::childData(int row, int column, int role) const
122 {
123  Q_ASSERT(uint(row) < mData->length());
124  return mData->dataAt(row, column, role);
125 }
126 
127 QWidget* ArrayDataInformation::createEditWidget(QWidget*) const
128 {
129  Q_ASSERT_X(false, "ArrayDataInformation::createEditWidget", "this should never happen!");
130  return 0;
131 }
132 
133 QVariant ArrayDataInformation::dataFromWidget(const QWidget*) const
134 {
135  Q_ASSERT_X(false, "ArrayDataInformation::dataFromWidget", "this should never happen!");
136  return QVariant();
137 }
138 
139 void ArrayDataInformation::setWidgetData(QWidget*) const
140 {
141  Q_ASSERT_X(false, "ArrayDataInformation::setWidgetData", "this should never happen!");
142 }
143 
144 BitCount64 ArrayDataInformation::childPosition(const DataInformation* child, Okteta::Address start) const
145 {
146  if (mParent->isTopLevel())
147  return start * 8 + mData->offset(child);
148  else
149  return mParent->asDataInformation()->childPosition(this, start) + mData->offset(child);
150 }
151 
152 qint64 ArrayDataInformation::readData(Okteta::AbstractByteArrayModel* input, Okteta::Address address,
153  BitCount64 bitsRemaining, quint8* bitOffset)
154 {
155  if (*bitOffset != 0)
156  {
157  //TODO remove this, it will probably cause issues
158  logWarn() << "bit offset != 0 (" << *bitOffset << "), adding padding,"
159  " arrays always start at full bytes";
160  bitsRemaining &= BitCount64(~7); //unset lower 3 bits to make it divisible by 8
161  address++;
162  }
163 
164  //update the length of the array
165  topLevelDataInformation()->scriptHandler()->updateLength(this);
166 
167  //FIXME do not add this padding
168  qint64 ret = mData->readData(input, address, bitsRemaining);
169  mWasAbleToRead = ret >= 0; //if ret is -1 reading failed
170  return ret;
171 }
172 
173 bool ArrayDataInformation::setChildData(uint row, const QVariant& value, Okteta::AbstractByteArrayModel* out,
174  Okteta::Address address, BitCount64 bitsRemaining, quint8 bitOffset)
175 {
176  if (bitOffset != 0)
177  {
178  logWarn() << "bit offset != 0 (" << bitOffset << "), adding padding,"
179  " arrays always start at full bytes";
180  bitsRemaining -= bitOffset;
181  address++;
182  }
183  return mData->setChildData(row, value, out, address, bitsRemaining);
184 }
185 
186 bool ArrayDataInformation::setData(const QVariant&, Okteta::AbstractByteArrayModel*,
187  Okteta::Address, BitCount64, quint8)
188 {
189  Q_ASSERT_X(false, "ArrayDataInformation::setData()", "this should never be called");
190  return false;
191 }
192 
193 QScriptClass* ArrayDataInformation::scriptClass(ScriptHandlerInfo* handlerInfo) const
194 {
195  return handlerInfo->mArrayClass.data();
196 }
197 
198 QScriptValue ArrayDataInformation::childToScriptValue(uint index, QScriptEngine* engine,
199  ScriptHandlerInfo* handlerInfo) const
200 {
201  return mData->toScriptValue(index, engine, handlerInfo);
202 }
DataInformation
Interface that must be implemented by all datatypes.
Definition: datainformation.h:67
ArrayDataInformation::childType
QScriptValue childType() const
Definition: arraydatainformation.cpp:116
DataInformationWithDummyChildren
This class declares all methods that are needed if there can be dummy children.
Definition: dummydatainformation.h:73
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
ArrayDataInformation::setArrayLength
bool setArrayLength(uint newLength)
Definition: arraydatainformation.cpp:68
DataInformation::topLevelDataInformation
TopLevelDataInformation * topLevelDataInformation() const
Definition: datainformation.cpp:240
QScriptClass
complexarraydata.h
TopLevelDataInformation::_childCountAboutToChange
void _childCountAboutToChange(DataInformation *sender, uint oldCount, uint newCount)
Definition: topleveldatainformation.h:184
BitCount64
quint64 BitCount64
Definition: datainformationbase.h:42
TopLevelDataInformation::_childCountChanged
void _childCountChanged(DataInformation *sender, uint oldCount, uint newCount)
Definition: topleveldatainformation.h:192
ArrayDataInformation::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: arraydatainformation.cpp:152
primitivearraydata.h
QWidget
ArrayDataInformation::setData
virtual bool setData(const QVariant &value, Okteta::AbstractByteArrayModel *out, Okteta::Address address, BitCount64 bitsRemaining, quint8 bitOffset)
Writes the current data contained in this object to out.
Definition: arraydatainformation.cpp:186
ArrayDataInformation::childData
virtual QVariant childData(int row, int column, int role) const
the data of child at index row.
Definition: arraydatainformation.cpp:121
PrimitiveDataInformation::type
virtual PrimitiveDataType type() const =0
ArrayDataInformation::setLengthFunction
void setLengthFunction(QScriptValue newFunc)
Definition: arraydatainformation.h:178
ArrayDataInformation::length
uint length() const
Definition: arraydatainformation.h:98
ArrayDataInformation
Definition: arraydatainformation.h:36
ArrayDataInformation::setArrayType
void setArrayType(DataInformation *newChildtype)
Sets the new array type.
Definition: arraydatainformation.cpp:83
ArrayDataInformation::createEditWidget
virtual QWidget * createEditWidget(QWidget *parent) const
create a QWidget for the QItemDelegate
Definition: arraydatainformation.cpp:127
ScriptHandler::updateLength
void updateLength(ArrayDataInformation *array)
Definition: scripthandler.cpp:126
ScriptHandlerInfo::mArrayClass
QScopedPointer< ArrayScriptClass > mArrayClass
Definition: scripthandlerinfo.h:50
DataInformation::mWasAbleToRead
bool mWasAbleToRead
Definition: datainformation.h:243
TopLevelDataInformation
Definition: topleveldatainformation.h:46
DataInformation::logInfo
QDebug logInfo() const
just a shorthand for logger->info(this)
Definition: datainformation.h:314
DataInformation::setParent
void setParent(DataInformationBase *newParent)
Definition: datainformation.h:303
ArrayDataInformation::setWidgetData
virtual void setWidgetData(QWidget *w) const
initialize the delegate widget with the correct data
Definition: arraydatainformation.cpp:139
ArrayDataInformation::childPosition
virtual BitCount64 childPosition(const DataInformation *child, Okteta::Address start) const
Definition: arraydatainformation.cpp:144
ArrayDataInformation::ArrayDataInformation
ArrayDataInformation(const QString &name, uint length, DataInformation *childType, DataInformation *parent=0, const QScriptValue &lengthFuntion=QScriptValue())
creates a new array with initial length length.
Definition: arraydatainformation.cpp:36
DataInformationBase::isTopLevel
virtual bool isTopLevel() const =0
DataInformationBase::asPrimitive
PrimitiveDataInformation * asPrimitive()
AbstractArrayData::newArrayData
static AbstractArrayData * newArrayData(uint length, DataInformation *type, ArrayDataInformation *parent)
Takes ownership over type !
Definition: abstractarraydata.cpp:48
DataInformation::mParent
DataInformationBase * mParent
Definition: datainformation.h:238
DataInformationBase::asDataInformation
DataInformation * asDataInformation()
Definition: datainformationbase.h:107
ScriptHandlerInfo
Definition: scripthandlerinfo.h:39
ArrayDataInformation::setChildData
virtual bool setChildData(uint row, const QVariant &value, Okteta::AbstractByteArrayModel *out, Okteta::Address address, BitCount64 bitsRemaining, quint8 bitOffset)
Definition: arraydatainformation.cpp:173
ArrayDataInformation::dataFromWidget
virtual QVariant dataFromWidget(const QWidget *w) const
get the needed data from the widget
Definition: arraydatainformation.cpp:133
arraydatainformation.h
TopLevelDataInformation::scriptHandler
ScriptHandler * scriptHandler() const
Definition: topleveldatainformation.h:179
TopLevelDataInformation::setChildDataChanged
void setChildDataChanged()
Definition: topleveldatainformation.h:164
DataInformation::clone
virtual DataInformation * clone() const =0
DataInformation::childPosition
virtual BitCount64 childPosition(const DataInformation *child, Okteta::Address start) const =0
DataInformationBase::isPrimitive
virtual bool isPrimitive() const
Definition: datainformationbase.cpp:45
ArrayDataInformation::childToScriptValue
QScriptValue childToScriptValue(uint index, QScriptEngine *engine, ScriptHandlerInfo *handlerInfo) const
Definition: arraydatainformation.cpp:198
ArrayDataInformation::~ArrayDataInformation
virtual ~ArrayDataInformation()
Definition: arraydatainformation.cpp:64
DataInformation::logWarn
QDebug logWarn() const
just a shorthand for logger->warn(this)
Definition: datainformation.h:319
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 23:04:06 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