File indexing completed on 2024-06-16 05:24:55
0001 /* 0002 This file is part of the Okteta Kasten module, made within the KDE community. 0003 0004 SPDX-FileCopyrightText: 2007-2010 Friedrich W. H. Kossebau <kossebau@kde.org> 0005 0006 SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL 0007 */ 0008 0009 #ifndef KASTEN_PODDECODERTOOL_HPP 0010 #define KASTEN_PODDECODERTOOL_HPP 0011 0012 // tool 0013 #include "poddata.hpp" 0014 // Kasten core 0015 #include <Kasten/AbstractTool> 0016 // Okteta core 0017 #include <Okteta/OktetaCore> 0018 #include <Okteta/Address> 0019 // Qt 0020 #include <QVector> 0021 0022 namespace Okteta { 0023 class AbstractTypeCodec; 0024 class CharCodec; 0025 class AbstractByteArrayModel; 0026 } 0027 0028 class QByteArray; 0029 0030 namespace Kasten { 0031 class AbstractDifferentSizeDialog; 0032 class ByteArrayView; 0033 0034 class PODDecoderTool : public AbstractTool 0035 { 0036 Q_OBJECT 0037 0038 public: 0039 static inline constexpr int MaxPODSize = sizeof(double); 0040 // ensure strict alignment for double as needed on some architectures (e.g. PA-RISC) 0041 using Aligned64Bit = union { unsigned char Data[MaxPODSize]; double Dummy; }; 0042 0043 private: 0044 static inline constexpr char ConfigGroupId[] = "PODDecoderTool"; 0045 static inline constexpr char ByteOrderConfigKey[] = "ByteOrder"; 0046 static inline constexpr char UnsignedAsHexConfigKey[] = "UnsignedAsHexadecimal"; 0047 0048 static inline constexpr QSysInfo::Endian DefaultByteOrder = QSysInfo::ByteOrder; 0049 static inline constexpr bool DefaultUnsignedAsHex = true; 0050 0051 public: 0052 PODDecoderTool(); 0053 0054 ~PODDecoderTool() override; 0055 0056 public: // AbstractTool API 0057 // virtual AbstractModel* targetModel() const; 0058 QString title() const override; 0059 0060 void setTargetModel(AbstractModel* model) override; 0061 0062 public: 0063 bool isApplyable() const; // candidate for AbstractTool API 0064 bool isReadOnly() const; 0065 QVariant value(int podId) const; 0066 QByteArray bytes(int podId) const; 0067 QString nameOfPOD(int podId) const; 0068 int podCount() const; 0069 0070 // TODO: add option to display & edit data in locale 0071 bool isUnsignedAsHex() const; 0072 QSysInfo::Endian byteOrder() const; 0073 Okteta::CharCodec* charCodec() const; 0074 0075 public: 0076 void setData(const QVariant& data, int podId); 0077 void selectBytesInView(int podId); 0078 void markPOD(int podId); 0079 void unmarkPOD(); 0080 0081 void setDifferentSizeDialog(AbstractDifferentSizeDialog* differentSizeDialog); 0082 0083 public Q_SLOTS: 0084 void setUnsignedAsHex(bool unsignedAsHex); 0085 void setByteOrder(int byteOrder); 0086 0087 Q_SIGNALS: // changes to the setting currently not signalled, because only controlled by view 0088 void isApplyableChanged(bool isApplyable); // candidate for AbstractTool API 0089 void readOnlyChanged(bool isReadOnly); 0090 void dataChanged(); 0091 0092 private: 0093 void updateData(); 0094 void setupDecoder(); 0095 0096 private Q_SLOTS: 0097 void onCursorPositionChange(Okteta::Address pos); 0098 void onContentsChange(); 0099 void onReadOnlyChanged(); 0100 0101 void onCharCodecChange(const QString& codecName); 0102 // void onUndefinedCharChanged(QChar undefinedChar); 0103 0104 private: // source 0105 ByteArrayView* mByteArrayView = nullptr; 0106 Okteta::AbstractByteArrayModel* mByteArrayModel = nullptr; 0107 Okteta::Address mCursorIndex = 0; 0108 0109 bool mReadOnly : 1; 0110 bool mIsPodMarked : 1; 0111 0112 QVector<Okteta::AbstractTypeCodec*> mTypeCodecs; 0113 Okteta::CharCodec* mCharCodec; 0114 AbstractDifferentSizeDialog* mDifferentSizeDialog = nullptr; 0115 0116 private: // settings 0117 bool mUnsignedAsHex : 1; 0118 0119 private: // decoded data 0120 Okteta::PODData mPODData; 0121 QVector<QVariant> mDecodedValueList; 0122 QVector<int> mDecodedValueByteCountList; 0123 }; 0124 0125 inline bool PODDecoderTool::isUnsignedAsHex() const { return mUnsignedAsHex; } 0126 inline QSysInfo::Endian PODDecoderTool::byteOrder() const { return mPODData.byteOrder(); } 0127 inline Okteta::CharCodec* PODDecoderTool::charCodec() const { return mCharCodec; } 0128 0129 } 0130 0131 #endif