File indexing completed on 2024-06-23 05:49:06

0001 /*
0002     This file is part of the Okteta Kasten Framework, made within the KDE community.
0003 
0004     SPDX-FileCopyrightText: 2009, 2010, 2011 Alex Richardson <alex.richardson@gmx.de>
0005     SPDX-FileCopyrightText: 2009 Friedrich W. H. Kossebau <kossebau@kde.org>
0006 
0007     SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
0008 */
0009 
0010 #ifndef KASTEN_STRUCTURESTOOL_HPP
0011 #define KASTEN_STRUCTURESTOOL_HPP
0012 
0013 // Okteta Kasten gui
0014 #include <Kasten/Okteta/ByteArrayView>
0015 // tool
0016 #include "datatypes/topleveldatainformation.hpp"
0017 // Kasten core
0018 #include <Kasten/AbstractTool>
0019 // Okteta core
0020 #include <Okteta/AddressRange>
0021 // Std
0022 #include <memory>
0023 
0024 class QModelIndex;
0025 class QByteArray;
0026 
0027 class DataInformation;
0028 
0029 namespace Okteta {
0030 class ArrayChangeMetricsList;
0031 class AbstractByteArrayModel;
0032 }
0033 
0034 namespace Kasten {
0035 class StructuresManager;
0036 
0037 class StructuresTool : public AbstractTool
0038 {
0039     Q_OBJECT
0040 
0041 public:
0042     StructuresTool();
0043     ~StructuresTool() override;
0044 
0045 public: // AbstractTool API
0046     // virtual AbstractModel* targetModel() const;
0047     QString title() const override;
0048     void setTargetModel(AbstractModel* model) override;
0049 
0050 public:
0051     QSysInfo::Endian byteOrder() const;
0052     void setByteOrder(QSysInfo::Endian order);
0053     bool setData(const QVariant& value, int role, DataInformation* item, uint row);
0054     Okteta::AbstractByteArrayModel* byteArrayModel() const;
0055     StructuresManager* manager() const;
0056     void lockStructure(const QModelIndex& idx);
0057     void unlockStructure(const QModelIndex& idx);
0058     bool isStructureLocked(const QModelIndex& idx) const;
0059     /** check if there is any ByteArrayModel available to lock the structure */
0060     bool canStructureBeLocked(const QModelIndex& idx) const;
0061     bool isFileLoaded() const;
0062     QByteArray bytes(const DataInformation* data) const;
0063 
0064     void selectBytesInView(const QModelIndex& idx);
0065 
0066     // interface for model
0067     QVariant headerData(int column, int role) const;
0068     int childCount() const;
0069     DataInformation* childAt(int idx) const;
0070     TopLevelDataInformation::List allData() const;
0071 
0072 Q_SIGNALS:
0073     void dataChanged(int row, void* data); // actually a DataInformation*
0074     void dataCleared();
0075     void byteOrderChanged();
0076     void byteArrayModelChanged(Okteta::AbstractByteArrayModel* model);
0077     /** items are inserted before @p startIndex */
0078     void childrenAboutToBeInserted(DataInformation* sender, uint startIndex, uint endIndex);
0079     /** items are inserted before @p startIndex */
0080     void childrenInserted(const DataInformation* sender, uint startIndex, uint endIndex);
0081     /** items are removed before @p startIndex */
0082     void childrenAboutToBeRemoved(DataInformation* sender, uint startIndex, uint endIndex);
0083     /** items are inserted before @p startIndex */
0084     void childrenRemoved(const DataInformation* sender, uint startIndex, uint endIndex);
0085 
0086 public Q_SLOTS:
0087     void setByteOrder(int order);
0088     void mark(const QModelIndex& idx);
0089     void unmark(/*const QModelIndex& idx*/);
0090     void updateData(const Okteta::ArrayChangeMetricsList& list);
0091     void addChildItem(TopLevelDataInformation* child);
0092     void setEnabledStructuresInView();
0093     void validateAllStructures();
0094 
0095 private Q_SLOTS:
0096     void onByteOrderChanged();
0097     void onCursorPositionChange(Okteta::Address pos);
0098     void onContentsChange(const Okteta::ArrayChangeMetricsList&);
0099     void onChildItemDataChanged();
0100 
0101 private:
0102     Okteta::Address startAddress(const TopLevelDataInformation* data) const;
0103     Okteta::AddressRange dataRange(const DataInformation* data) const;
0104 
0105 private:
0106     // source
0107     ByteArrayView* mByteArrayView = nullptr;
0108     Okteta::AbstractByteArrayModel* mByteArrayModel = nullptr;
0109     Okteta::Address mCursorIndex = 0;
0110     Okteta::ArrayChangeMetricsList mArrayChangesWhileWriting;
0111 
0112     // settings
0113     QSysInfo::Endian mByteOrder;
0114     std::unique_ptr<StructuresManager> mManager;
0115     TopLevelDataInformation::List mData;
0116     TopLevelDataInformation::List mInvalidData;
0117     bool mWritingData : 1;
0118     bool mCurrentItemDataChanged : 1;
0119     bool mIsStructureMarked : 1;
0120 };
0121 
0122 }
0123 
0124 #endif