1 /*
2 This file is part of the Okteta Kasten Framework, made within the KDE community.
3
4 SPDX-FileCopyrightText: 2011 Alex Richardson <alex.richardson@gmx.de>
5
6 SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
7 */
8
9 #ifndef KASTEN_ABSTRACTARRAYDATA_HPP
10 #define KASTEN_ABSTRACTARRAYDATA_HPP
11
12 #include <Okteta/Address>
13 #include "../datainformationbase.hpp"
14 #include "../primitivedatatype.hpp"
15
16 #include <Qt>
17 #include <QScopedPointer>
18
19 class QWidget;
20 class QScriptEngine;
21 class QScriptValue;
22 class DataInformation;
23 class ScriptHandlerInfo;
24
25 namespace Okteta {
26 class AbstractByteArrayModel;
27 }
28
29 class QVariant;
30
31 class AbstractArrayData
32 {
33 Q_DISABLE_COPY(AbstractArrayData)
34
35 public:
36 explicit AbstractArrayData(DataInformation* childType, ArrayDataInformation* parent);
37 virtual ~AbstractArrayData();
38
39 void setParent(ArrayDataInformation* parent);
40 /** @return The current child type. Ownership is NOT transferred */
41 DataInformation* childType() const;
42
43 virtual QVariant dataAt(uint index, int column, int role) = 0;
44 virtual unsigned int length() const = 0;
45 virtual void setLength(uint newLength) = 0;
46
47 virtual QString typeName() const = 0;
48
49 virtual BitCount32 size() const = 0;
50
51 virtual DataInformation* childAt(unsigned int idx) = 0;
52
53 virtual QScriptValue toScriptValue(uint index, QScriptEngine* engine,
54 ScriptHandlerInfo* handlerInfo) = 0;
55 /** the primitive type or PrimitiveDataType::Invalid for structs etc */
56 virtual PrimitiveDataType primitiveType() const = 0;
57
58 virtual int indexOf(const DataInformation* data) const = 0;
59 virtual BitCount64 offset(const DataInformation* child) const = 0;
60 virtual qint64 readData(Okteta::AbstractByteArrayModel* input, Okteta::Address address, BitCount64 bitsRemaining) = 0;
61 virtual bool setChildData(uint row, const QVariant& value, Okteta::AbstractByteArrayModel* out,
62 Okteta::Address address, BitCount64 bitsRemaining) = 0;
63 virtual BitCount32 sizeAt(uint index) = 0;
64 virtual Qt::ItemFlags childFlags(int row, int column, bool fileLoaded) = 0;
65 virtual bool isComplex() const = 0;
66
67 virtual QWidget* createChildEditWidget(uint index, QWidget* parent) const = 0;
68 virtual QVariant dataFromChildWidget(uint index, const QWidget* w) const = 0;
69 virtual void setChildWidgetData(uint index, QWidget* w) const = 0;
70
71 /** Takes ownership over @p type ! */
72 static AbstractArrayData* newArrayData(uint length, DataInformation* type, ArrayDataInformation* parent);
73
74 protected:
75 virtual void setNewParentForChildren() = 0;
76
77 protected:
78 ArrayDataInformation* mParent;
79 QScopedPointer<DataInformation> mChildType;
80 };
81
childType() const82 inline DataInformation* AbstractArrayData::childType() const
83 {
84 return mChildType.data();
85 }
86
87 #endif // KASTEN_ABSTRACTARRAYDATA_HPP
88