File indexing completed on 2024-07-07 05:34:58
0001 /* 0002 This file is part of the Okteta Kasten Framework, made within the KDE community. 0003 0004 SPDX-FileCopyrightText: 2010 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 #include "unsignedbitfielddatainformation.hpp" 0010 0011 #include <KLocalizedString> 0012 0013 #include <QScriptValue> 0014 0015 #include <view/poddecoder/typeeditors/uintspinbox.hpp> 0016 #include "../uintdatainformation.hpp" 0017 0018 QString UnsignedBitfieldDataInformation::valueStringImpl() const 0019 { 0020 Q_ASSERT(mWasAbleToRead); 0021 return UIntDataInformationMethods<quint64>::staticValueString(mValue.value<quint64>()); 0022 } 0023 0024 QVariant UnsignedBitfieldDataInformation::valueToQVariant() const 0025 { 0026 Q_ASSERT(mWasAbleToRead); 0027 return UIntDataInformationMethods<quint64>::staticToQVariant(mValue.value<quint64>()); 0028 } 0029 0030 QString UnsignedBitfieldDataInformation::valueToQString(AllPrimitiveTypes value) const 0031 { 0032 return UIntDataInformationMethods<quint64>::staticValueString(value.value<quint64>()); 0033 } 0034 0035 QVariant UnsignedBitfieldDataInformation::valueToQVariant(AllPrimitiveTypes value) const 0036 { 0037 return UIntDataInformationMethods<quint64>::staticToQVariant(value.value<quint64>()); 0038 } 0039 0040 QWidget* UnsignedBitfieldDataInformation::createEditWidget(QWidget* parent) const 0041 { 0042 auto* ret = new UIntSpinBox(parent); 0043 ret->setBase(Kasten::StructureViewPreferences::unsignedDisplayBase()); 0044 ret->setMaximum(mask()); 0045 return ret; 0046 } 0047 0048 QVariant UnsignedBitfieldDataInformation::dataFromWidget(const QWidget* w) const 0049 { 0050 const auto* spin = qobject_cast<const UIntSpinBox*> (w); 0051 if (spin) { 0052 return spin->value(); 0053 } 0054 return {}; 0055 } 0056 0057 void UnsignedBitfieldDataInformation::setWidgetData(QWidget* w) const 0058 { 0059 auto* spin = qobject_cast<UIntSpinBox*> (w); 0060 if (spin) { 0061 spin->setValue(mValue.value<quint64>()); 0062 } 0063 } 0064 0065 QScriptValue UnsignedBitfieldDataInformation::valueAsQScriptValue() const 0066 { 0067 if (width() <= 32) { 0068 return mValue.value<quint32>() & quint32(mask()); // 32 bit or less -> can be put in as value 0069 } 0070 0071 return QString::number(mValue.value<quint64>()); 0072 } 0073 0074 QString UnsignedBitfieldDataInformation::typeNameImpl() const 0075 { 0076 return i18ncp("Data type", "unsigned bitfield (%1 bit wide)", 0077 "unsigned bitfield (%1 bits wide)", width()); 0078 } 0079 0080 AbstractBitfieldDataInformation::Type UnsignedBitfieldDataInformation::bitfieldType() const 0081 { 0082 return AbstractBitfieldDataInformation::Type::Unsigned; 0083 }