File indexing completed on 2024-09-22 05:15:39

0001 /*
0002     This file is part of the Okteta Kasten module, made within the KDE community.
0003 
0004     SPDX-FileCopyrightText: 2009 Friedrich W. H. Kossebau <kossebau@kde.org>
0005 
0006     Public domain.
0007 */
0008 
0009 //// ADAPT(start)
0010 //// rename "template_bytearraychecksumparametersetedit.hpp" to the name of the header of your filter,
0011 //// e.g. "mybytearraychecksumparametersetedit.hpp"
0012 #include "template_bytearraychecksumparametersetedit.hpp"
0013 //// ADAPT(end)
0014 
0015 // parameterset
0016 //// ADAPT(start)
0017 //// rename "template_bytearraychecksumparameterset.hpp" to the name of the header of your filter,
0018 //// e.g. "mybytearraychecksumparameterset.hpp"
0019 #include "template_bytearraychecksumparameterset.hpp"
0020 //// ADAPT(end)
0021 // KF
0022 #include <KLocalizedString>
0023 //// ADAPT(start)
0024 //// add includes for all elements used in the widget
0025 #include <QSpinBox>
0026 // Qt
0027 #include <QFormLayout>
0028 //// ADAPT(end)
0029 
0030 //// ADAPT(start)
0031 //// rename "Template_ParameterSetId" to the id of your parameterset,
0032 //// e.g. "MyParameterSet"
0033 const char Template_ByteArrayChecksumParameterSetEdit::Id[] = "Template_ParameterSetId";
0034 //// ADAPT(end)
0035 
0036 Template_ByteArrayChecksumParameterSetEdit::Template_ByteArrayChecksumParameterSetEdit(QWidget* parent)
0037     : AbstractByteArrayChecksumParameterSetEdit(parent)
0038 {
0039 //// ADAPT(start)
0040 //// setup the widget with all edit fields needed for the parameter set
0041 //// if there can be invalid states connect the change signals of the edit fields to some slots
0042 //// where you check if the validity changed
0043     auto* baseLayout = new QFormLayout(this);
0044     // margin is provided by the container for this widget
0045     baseLayout->setContentsMargins(0, 0, 0, 0);
0046 
0047     mBitNumberEdit = new QSpinBox(this);
0048     // For demonstration purpose we start at 0, not 1, to show handling of an invalid state
0049     // Otherwise the range should start at 1 and there is no need to connect to the valueChanged signal
0050     mBitNumberEdit->setRange(0, 8);
0051     // start with the invalid number
0052     mBitNumberEdit->setValue(0);
0053     connect(mBitNumberEdit, qOverload<int>(&QSpinBox::valueChanged),
0054             this, &Template_ByteArrayChecksumParameterSetEdit::onBitNumberChanged);
0055 
0056     const QString levelLabelText =
0057         i18nc("@label:spinbox number of the bit to use",
0058               "Number of bit:");
0059     const QString levelToolTip =
0060         i18nc("@info:tooltip",
0061               "The number of the bit to use for the parity calculation. 1 means the LSB, 8 the MSB.");
0062     mBitNumberEdit->setToolTip(levelToolTip);
0063     const QString levelWhatsThis =
0064         i18nc("@info:whatsthis",
0065               "Select the bit which should be used for the parity calculation. And more explanation.");
0066     mBitNumberEdit->setWhatsThis(levelWhatsThis);
0067 
0068     baseLayout->addRow(levelLabelText, mBitNumberEdit);
0069 
0070     // note start state
0071     mIsValid = isValid();
0072 //// ADAPT(end)
0073 }
0074 
0075 Template_ByteArrayChecksumParameterSetEdit::~Template_ByteArrayChecksumParameterSetEdit() = default;
0076 
0077 //// ADAPT(start)
0078 //// if invalid states are possible implement here the check
0079 bool Template_ByteArrayChecksumParameterSetEdit::isValid() const { return mBitNumberEdit->value() != 0; }
0080 //// ADAPT(end)
0081 
0082 //// ADAPT(start)
0083 //// change "Template_ByteArrayFilterParameterSet" to the class of the parameter set which this widget should edit
0084 //// e.g. "MyByteArrayFilterParameterSet"
0085 //// also adapt the passing of the values between the parameter set and the edit fields
0086 void Template_ByteArrayChecksumParameterSetEdit::setParameterSet(const AbstractByteArrayChecksumParameterSet* parameterSet)
0087 {
0088     const auto* template_ParameterSet =
0089         static_cast<const Template_ByteArrayChecksumParameterSet*>(parameterSet);
0090 
0091     mBitNumberEdit->setValue(template_ParameterSet->bitNumber());
0092 }
0093 
0094 void Template_ByteArrayChecksumParameterSetEdit::getParameterSet(AbstractByteArrayChecksumParameterSet* parameterSet) const
0095 {
0096     auto* template_ParameterSet =
0097         static_cast<Template_ByteArrayChecksumParameterSet*>(parameterSet);
0098 
0099     template_ParameterSet->setBitNumber(mBitNumberEdit->value());
0100 }
0101 //// ADAPT(end)
0102 
0103 //// ADAPT(start)
0104 //// define the slots to catch changes in the values to check if the current state is valid or not
0105 //// not needed if there cannot be invalid states
0106 void Template_ByteArrayChecksumParameterSetEdit::onBitNumberChanged(int value)
0107 {
0108     const bool isValid = (value != 0);
0109 
0110     if (mIsValid == isValid) {
0111         return;
0112     }
0113 
0114     mIsValid = isValid;
0115     Q_EMIT validityChanged(isValid);
0116 }
0117 //// ADAPT(end)
0118 
0119 #include "moc_template_bytearraychecksumparametersetedit.cpp"