File indexing completed on 2024-07-07 05:34:57

0001 /*
0002     This file is part of the Okteta Kasten Framework, made within the KDE community.
0003 
0004     SPDX-FileCopyrightText: 2011 Alex Richardson <alex.richardson@gmx.de>
0005 
0006     SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
0007 */
0008 
0009 #ifndef KASTEN_ABSTRACTARRAYDATA_HPP
0010 #define KASTEN_ABSTRACTARRAYDATA_HPP
0011 
0012 #include <Okteta/Address>
0013 #include "../datainformationbase.hpp"
0014 #include "../primitivedatatype.hpp"
0015 // Qt
0016 #include <Qt>
0017 // Std
0018 #include <memory>
0019 
0020 class QWidget;
0021 class QScriptEngine;
0022 class QScriptValue;
0023 class DataInformation;
0024 class ScriptHandlerInfo;
0025 
0026 namespace Okteta {
0027 class AbstractByteArrayModel;
0028 }
0029 
0030 class QVariant;
0031 
0032 class AbstractArrayData
0033 {
0034 public:
0035     explicit AbstractArrayData(DataInformation* childType, ArrayDataInformation* parent);
0036     AbstractArrayData(const AbstractArrayData&) = delete;
0037 
0038     virtual ~AbstractArrayData();
0039 
0040     AbstractArrayData& operator=(const AbstractArrayData&) = delete;
0041 
0042 public:
0043     void setParent(ArrayDataInformation* parent);
0044     /** @return The current child type. Ownership is NOT transferred */
0045     DataInformation* childType() const;
0046 
0047     virtual QVariant dataAt(uint index, int column, int role) = 0;
0048     virtual unsigned int length() const = 0;
0049     virtual void setLength(uint newLength) = 0;
0050 
0051     virtual QString typeName() const = 0;
0052     virtual QString valueString() const = 0;
0053 
0054     virtual BitCount32 size() const = 0;
0055 
0056     virtual DataInformation* childAt(unsigned int idx) = 0;
0057 
0058     virtual QScriptValue toScriptValue(uint index, QScriptEngine* engine,
0059                                        ScriptHandlerInfo* handlerInfo) = 0;
0060     /** the primitive type or PrimitiveDataType::Invalid for structs etc */
0061     virtual PrimitiveDataType primitiveType() const = 0;
0062 
0063     virtual int indexOf(const DataInformation* data) const = 0;
0064     virtual BitCount64 offset(const DataInformation* child) const = 0;
0065     virtual qint64 readData(const Okteta::AbstractByteArrayModel* input, Okteta::Address address, BitCount64 bitsRemaining) = 0;
0066     virtual bool setChildData(uint row, const QVariant& value, Okteta::AbstractByteArrayModel* out,
0067                               Okteta::Address address, BitCount64 bitsRemaining) = 0;
0068     virtual BitCount32 sizeAt(uint index) = 0;
0069     virtual Qt::ItemFlags childFlags(int row, int column, bool fileLoaded) = 0;
0070     virtual bool isComplex() const = 0;
0071 
0072     virtual QWidget* createChildEditWidget(uint index, QWidget* parent) const = 0;
0073     virtual QVariant dataFromChildWidget(uint index, const QWidget* w) const = 0;
0074     virtual void setChildWidgetData(uint index, QWidget* w) const = 0;
0075 
0076     /** Takes ownership over @p type ! */
0077     static AbstractArrayData* newArrayData(uint length, DataInformation* type, ArrayDataInformation* parent);
0078 
0079 protected:
0080     virtual void setNewParentForChildren() = 0;
0081 
0082 protected:
0083     ArrayDataInformation* mParent;
0084     std::unique_ptr<DataInformation> mChildType;
0085 };
0086 
0087 inline DataInformation* AbstractArrayData::childType() const
0088 {
0089     return mChildType.get();
0090 }
0091 
0092 #endif // KASTEN_ABSTRACTARRAYDATA_HPP