File indexing completed on 2024-04-21 05:53:01

0001 /*
0002     This file is part of the Okteta project, made within the KDE community.
0003 
0004     SPDX-FileCopyrightText: 2009, 2011, 2015 Friedrich W. H. Kossebau <kossebau@kde.org>
0005 
0006     Public domain.
0007 */
0008 
0009 //// include the generated header from the UI file
0010 // ui
0011 #include "ui_example_widget.h"
0012 //// include the header of the bytearray model you want to use
0013 // Okteta core
0014 #include <okteta/piecetablebytearraymodel.hpp>
0015 //// or
0016 #include <Okteta/PieceTableByteArrayModel>
0017 
0018 //// only needed for the example
0019 // Qt
0020 #include <QApplication>
0021 
0022 //// some static data so the bytearray model is not empty on start
0023 //// and the widgets not just white after the start of the example program :)
0024 static constexpr char exampleInitialData[] =
0025     "This is some data for the Okteta byte array widgets:"
0026     "\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0A\x0B\x0C\x0D\x0E\x0F"
0027     "\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1A\x1B\x1C\x1D\x1E\x1F"
0028     "\x20\x21\x22\x23\x24\x25\x26\x27\x28\x29\x2A\x2B\x2C\x2D\x2E\x2F"
0029     "\x30\x31\x32\x33\x34\x35\x36\x37\x38\x39\x3A\x3B\x3C\x3D\x3E\x3F"
0030     "\x40\x41\x42\x43\x44\x45\x46\x47\x48\x49\x4A\x4B\x4C\x4D\x4E\x4F"
0031     "\x50\x51\x52\x53\x54\x55\x56\x57\x58\x59\x5A\x5B\x5C\x5D\x5E\x5F"
0032     "\x60\x61\x62\x63\x64\x65\x66\x67\x68\x69\x6A\x6B\x6C\x6D\x6E\x6F"
0033     "\x70\x71\x72\x73\x74\x75\x76\x77\x78\x79\x7A\x7B\x7C\x7D\x7E\x7F"
0034     "\x80\x81\x82\x83\x84\x85\x86\x87\x88\x89\x8A\x8B\x8C\x8D\x8E\x8F"
0035     "\x90\x91\x92\x93\x94\x95\x96\x97\x98\x99\x9A\x9B\x9C\x9D\x9E\x9F"
0036     "\xA0\xA1\xA2\xA3\xA4\xA5\xA6\xA7\xA8\xA9\xAA\xAB\xAC\xAD\xAE\xAF"
0037     "\xB0\xB1\xB2\xB3\xB4\xB5\xB6\xB7\xB8\xB9\xBA\xBB\xBC\xBD\xBE\xBF"
0038     "\xC0\xC1\xC2\xC3\xC4\xC5\xC6\xC7\xC8\xC9\xCA\xCB\xCC\xCD\xCE\xCF"
0039     "\xD0\xD1\xD2\xD3\xD4\xD5\xD6\xD7\xD8\xD9\xDA\xDB\xDC\xDD\xDE\xDF"
0040     "\xE0\xE1\xE2\xE3\xE4\xE5\xE6\xE7\xE8\xE9\xEA\xEB\xEC\xED\xEE\xEF"
0041     "\xF0\xF1\xF2\xF3\xF4\xF5\xF6\xF7\xF8\xF9\xFA\xFB\xFC\xFD\xFE\xFF";
0042 
0043 static constexpr int exampleInitialDataSize = sizeof(exampleInitialData) / sizeof(exampleInitialData[0]);
0044 
0045 class Widget : public QWidget
0046 {
0047 public:
0048     explicit Widget(QWidget* parent = nullptr);
0049     ~Widget() override;
0050 
0051 private:
0052     Ui::Example_Widget ui;
0053 
0054     //// the bytearray, by a class subclassing Okteta::AbstractByteArrayModel,
0055     //// either you own specialized one or one of the standard ones, e.g. the PieceTableByteArrayModel
0056     //// (the Okteta widgets only have some empty dummy bytearray as default internally)
0057     Okteta::PieceTableByteArrayModel* mByteArrayModel;
0058 };
0059 
0060 Widget::Widget(QWidget* parent)
0061     : QWidget(parent)
0062 {
0063     //// initialize as usual when using UI files
0064     ui.setupUi(this);
0065 
0066     //// create the bytearray
0067     mByteArrayModel =
0068         new Okteta::PieceTableByteArrayModel(QByteArray::fromRawData(exampleInitialData, exampleInitialDataSize), this);
0069 
0070     //// then set it to the bytearray view
0071     //// the same bytearray object can be set to multiple views
0072     //// they will share it, as the Okteta classes implement the MVC pattern
0073     ui.mByteArrayColumnView->setByteArrayModel(mByteArrayModel);
0074     ui.mByteArrayRowView->setByteArrayModel(mByteArrayModel);
0075 }
0076 
0077 Widget::~Widget() = default;
0078 
0079 int main(int argc, char* argv[])
0080 {
0081     QApplication programCore(argc, argv);
0082 
0083     auto* widget = new Widget;
0084     widget->show();
0085 
0086     return QApplication::exec();
0087 }