Warning, file /utilities/okteta/kasten/gui/liboktetawidgets/bytearrayvalidator.hpp was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).
0001 /* 0002 This file is part of the Okteta Kasten module, made within the KDE community. 0003 0004 SPDX-FileCopyrightText: 2006, 2009, 2011 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_BYTEARRAYVALIDATOR_HPP 0010 #define KASTEN_BYTEARRAYVALIDATOR_HPP 0011 0012 // Okteta core 0013 #include <Okteta/OktetaCore> 0014 // Qt 0015 #include <QValidator> 0016 0017 namespace Okteta { 0018 class ValueCodec; 0019 class CharCodec; 0020 0021 class ByteArrayValidator : public QValidator 0022 { 0023 Q_OBJECT 0024 0025 public: 0026 // matching Okteta::ValueCoding 0027 enum Coding 0028 { 0029 InvalidCoding = -1, 0030 HexadecimalCoding = 0, 0031 DecimalCoding = 1, 0032 OctalCoding = 2, 0033 BinaryCoding = 3, 0034 CharCoding = 4, 0035 Utf8Coding = 5 0036 }; 0037 0038 public: 0039 explicit ByteArrayValidator(QObject* parent = nullptr, 0040 Coding codecId = CharCoding, 0041 int charCodecId = LocalEncoding); 0042 0043 ~ByteArrayValidator() override; 0044 0045 public: // QValidator API 0046 QValidator::State validate(QString& input, int& pos) const override; 0047 0048 public: 0049 /// Sets one of the value codecs or the current char codec. 0050 void setCodec(Coding codecId); 0051 /// Sets the char codec to use. Does not change the current codec. 0052 void setCharCodec(const QString& charCodecName); 0053 /// Sets the maximal length of the edited bytearray to @p maxLength. 0054 /// If @p maxLength is negative, the behaviour is undefined. Default is @c 32767. 0055 void setMaxLength(int maxLength); 0056 /// Sets the maximal length of the edited bytearray to @p minLength. 0057 /// If @p minLength is negative, the behaviour is undefined. Default is @c 0. 0058 void setMinLength(int minLength); 0059 0060 public: 0061 int maxLength() const; 0062 int minLength() const; 0063 0064 public: 0065 QByteArray toByteArray(const QString& string) const; 0066 QString toString(const QByteArray& byteArray) const; 0067 0068 private: 0069 /** 0070 * Returns a string that is at least as long as @p destLen number of characters, 0071 * by adding zeroes to the left as necessary. 0072 * 0073 * e.g. zeroExtend( "32", 3 ) => "032" 0074 */ 0075 // QString zeroExtend( const QString &src, int destLen ) const; 0076 0077 Coding mCodecId = InvalidCoding; 0078 ValueCodec* mValueCodec = nullptr; 0079 CharCodec* mCharCodec; 0080 int mMaxLength = 32767; 0081 int mMinLength = 0; 0082 }; 0083 0084 inline int ByteArrayValidator::maxLength() const { return mMaxLength; } 0085 inline int ByteArrayValidator::minLength() const { return mMinLength; } 0086 0087 } 0088 0089 #endif