File indexing completed on 2025-01-19 05:20:18
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 SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL 0007 */ 0008 0009 #include "bytearraysequencegenerator.hpp" 0010 0011 // Okteta core 0012 #include <Okteta/AbstractByteArrayModel> 0013 // KF 0014 #include <KLocalizedString> 0015 // Qt 0016 #include <QMimeData> 0017 #include <QByteArray> 0018 0019 namespace Kasten { 0020 0021 ByteArraySequenceGeneratorSettings::ByteArraySequenceGeneratorSettings() = default; 0022 0023 // TODO: support insert to selection, cmp. fill in painting program 0024 // there are two kinds of generated datam fixed size (e.g. sequence) and endless size? 0025 // perhaps by option fill selection? or a separate menu entry fill, which only works on selections? 0026 0027 ByteArraySequenceGenerator::ByteArraySequenceGenerator() 0028 : AbstractModelDataGenerator( 0029 i18nc("name of the generated data", "Sequence"), 0030 QStringLiteral("application/octet-stream"), 0031 StaticGeneration) 0032 {} 0033 0034 ByteArraySequenceGenerator::~ByteArraySequenceGenerator() = default; 0035 0036 // TODO: optimize and check if pattern is just one byte, so memset can be used 0037 // TODO: see if copying larger chunks with memcpy is faster, so 0038 QMimeData* ByteArraySequenceGenerator::generateData() 0039 { 0040 const Okteta::Byte firstByte = 0; 0041 const Okteta::Byte lastByte = 255; 0042 0043 const int insertDataSize = lastByte - firstByte + 1; 0044 QByteArray insertData(insertDataSize, '\0'); 0045 0046 Okteta::Byte byte = firstByte; 0047 for (int i = 0; i < insertDataSize; ++i, ++byte) { 0048 insertData[i] = byte; 0049 } 0050 0051 auto* mimeData = new QMimeData; 0052 mimeData->setData(mimeType(), insertData); 0053 0054 // TODO: a method to get the description of the change, e.g. 0055 #if 0 0056 Okteta::ChangesDescribable* changesDescribable = 0057 qobject_cast<Okteta::ChangesDescribable*>(mByteArrayModel); 0058 0059 if (changesDescribable) { 0060 changesDescribable->openGroupedChange(i18n("Sequence inserted.")); 0061 } 0062 mByteArrayView->insert(insertData); 0063 // mByteArrayModel->replace( filteredSection, filterResult ); 0064 if (changesDescribable) { 0065 changesDescribable->closeGroupedChange(); 0066 } 0067 #endif 0068 0069 return mimeData; 0070 } 0071 0072 } 0073 0074 #include "moc_bytearraysequencegenerator.cpp"