├── xhtml.cmake ├── README.md ├── xbinaryview.pri ├── xmodel.cmake ├── xbinaryview.cmake ├── xdatetimeeditx.cmake ├── xhtml.pri ├── xmodel.pri ├── xdatetimeeditx.pri ├── xcomboboxex.cmake ├── xmodel_archiverecords.cmake ├── xcomboboxex.pri ├── xmodel_binary.pri ├── xtableview.pri ├── xlineedithex.pri ├── xmodel_binary.cmake ├── xlineedithex.cmake ├── xtableview.cmake ├── LICENSE ├── xabstracttableview.pri ├── xlineedit_num.cpp ├── xlineedit_num_validator.cpp ├── xlineedit_num_validator.h ├── subclassofqstyleditemdelegate.h ├── xabstracttableview.cmake ├── xlineedit_num.h ├── xdatetimeeditx.h ├── subclassofqstyleditemdelegate.cpp ├── xmodel_archiverecords.h ├── xmodel_streams.h ├── xheaderview.h ├── xmodel_hex.h ├── xmodel_fparts.h ├── xsortfilterproxymodel.h ├── xmodel_binary.h ├── xhtml.h ├── xtableview.h ├── xdatetimeeditx.cpp ├── xmodel_msrecord.h ├── xlineeditvalidator.h ├── dialogbits8.h ├── xcomboboxex.h ├── xmodel.h ├── xbinaryview.h ├── xdevicetableeditview.h ├── xsortfilterproxymodel.cpp ├── xmodel_hex.cpp ├── xmodel.cpp ├── xlineedithex.h ├── xheaderview.cpp ├── xmodel_streams.cpp ├── xdevicetableview.h ├── xhtml.cpp ├── xmodel_fparts.cpp ├── xmodel_binary.cpp ├── xtableview.cpp ├── xmodel_archiverecords.cpp ├── xbinaryview.cpp ├── xabstracttableview.h ├── xcomboboxex.cpp ├── xlineeditvalidator.cpp ├── dialogbits8.cpp └── xmodel_msrecord.cpp /xhtml.cmake: -------------------------------------------------------------------------------- 1 | include_directories(${CMAKE_CURRENT_LIST_DIR}) 2 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Controls 2 | 3 | Controls for some projects: 4 | 5 | * Detect it Easy 6 | * XPEViewer 7 | * XELFViewer 8 | * XMachOViewer 9 | * XAPKDetector 10 | * xntsv -------------------------------------------------------------------------------- /xbinaryview.pri: -------------------------------------------------------------------------------- 1 | INCLUDEPATH += $$PWD 2 | DEPENDPATH += $$PWD 3 | 4 | HEADERS += \ 5 | $$PWD/xbinaryview.h 6 | 7 | SOURCES += \ 8 | $$PWD/xbinaryview.cpp 9 | 10 | -------------------------------------------------------------------------------- /xmodel.cmake: -------------------------------------------------------------------------------- 1 | include_directories(${CMAKE_CURRENT_LIST_DIR}) 2 | 3 | set(XMODEL_SOURCES 4 | ${XMODEL_SOURCES} 5 | ${CMAKE_CURRENT_LIST_DIR}/xmodel.cpp 6 | ${CMAKE_CURRENT_LIST_DIR}/xmodel.h 7 | ) 8 | -------------------------------------------------------------------------------- /xbinaryview.cmake: -------------------------------------------------------------------------------- 1 | include_directories(${CMAKE_CURRENT_LIST_DIR}) 2 | 3 | set(XBINARYVIEW_SOURCES 4 | ${XBINARYVIEW_SOURCES} 5 | ${CMAKE_CURRENT_LIST_DIR}/xbinaryview.cpp 6 | ${CMAKE_CURRENT_LIST_DIR}/xbinaryview.h 7 | ) 8 | -------------------------------------------------------------------------------- /xdatetimeeditx.cmake: -------------------------------------------------------------------------------- 1 | include_directories(${CMAKE_CURRENT_LIST_DIR}) 2 | 3 | set(XDATETIMEEDITX_SOURCES 4 | ${XDATETIMEEDITX_SOURCES} 5 | ${CMAKE_CURRENT_LIST_DIR}/xdatetimeeditx.cpp 6 | ${CMAKE_CURRENT_LIST_DIR}/xdatetimeeditx.h 7 | ) 8 | -------------------------------------------------------------------------------- /xhtml.pri: -------------------------------------------------------------------------------- 1 | INCLUDEPATH += $$PWD 2 | DEPENDPATH += $$PWD 3 | 4 | HEADERS += \ 5 | $$PWD/xhtml.h 6 | 7 | SOURCES += \ 8 | $$PWD/xhtml.cpp 9 | 10 | DISTFILES += \ 11 | $$PWD/LICENSE \ 12 | $$PWD/README.md \ 13 | $$PWD/xhtml.cmake -------------------------------------------------------------------------------- /xmodel.pri: -------------------------------------------------------------------------------- 1 | INCLUDEPATH += $$PWD 2 | DEPENDPATH += $$PWD 3 | 4 | HEADERS += \ 5 | $$PWD/xmodel.h 6 | 7 | SOURCES += \ 8 | $$PWD/xmodel.cpp 9 | 10 | DISTFILES += \ 11 | $$PWD/LICENSE \ 12 | $$PWD/README.md \ 13 | $$PWD/xmodel.cmake -------------------------------------------------------------------------------- /xdatetimeeditx.pri: -------------------------------------------------------------------------------- 1 | INCLUDEPATH += $$PWD 2 | DEPENDPATH += $$PWD 3 | 4 | HEADERS += \ 5 | $$PWD/xdatetimeeditx.h 6 | 7 | SOURCES += \ 8 | $$PWD/xdatetimeeditx.cpp 9 | 10 | DISTFILES += \ 11 | $$PWD/LICENSE \ 12 | $$PWD/README.md \ 13 | $$PWD/xdatetimeeditx.cmake -------------------------------------------------------------------------------- /xcomboboxex.cmake: -------------------------------------------------------------------------------- 1 | include_directories(${CMAKE_CURRENT_LIST_DIR}) 2 | 3 | set(XCOMBOBOXEX_SOURCES 4 | ${XCOMBOBOXEX_SOURCES} 5 | ${CMAKE_CURRENT_LIST_DIR}/subclassofqstyleditemdelegate.cpp 6 | ${CMAKE_CURRENT_LIST_DIR}/subclassofqstyleditemdelegate.h 7 | ${CMAKE_CURRENT_LIST_DIR}/xcomboboxex.cpp 8 | ${CMAKE_CURRENT_LIST_DIR}/xcomboboxex.h 9 | ) 10 | -------------------------------------------------------------------------------- /xmodel_archiverecords.cmake: -------------------------------------------------------------------------------- 1 | include_directories(${CMAKE_CURRENT_LIST_DIR}) 2 | 3 | set(XMODEL_ARCHIVERECORDS_SOURCES 4 | ${XMODEL_ARCHIVERECORDS_SOURCES} 5 | ${CMAKE_CURRENT_LIST_DIR}/xmodel.cpp 6 | ${CMAKE_CURRENT_LIST_DIR}/xmodel.h 7 | ${CMAKE_CURRENT_LIST_DIR}/xmodel_archiverecords.cpp 8 | ${CMAKE_CURRENT_LIST_DIR}/xmodel_archiverecords.h 9 | ) 10 | -------------------------------------------------------------------------------- /xcomboboxex.pri: -------------------------------------------------------------------------------- 1 | INCLUDEPATH += $$PWD 2 | DEPENDPATH += $$PWD 3 | 4 | HEADERS += \ 5 | $$PWD/subclassofqstyleditemdelegate.h \ 6 | $$PWD/xcomboboxex.h 7 | 8 | SOURCES += \ 9 | $$PWD/subclassofqstyleditemdelegate.cpp \ 10 | $$PWD/xcomboboxex.cpp 11 | 12 | DISTFILES += \ 13 | $$PWD/LICENSE \ 14 | $$PWD/README.md \ 15 | $$PWD/xcomboboxex.cmake 16 | -------------------------------------------------------------------------------- /xmodel_binary.pri: -------------------------------------------------------------------------------- 1 | INCLUDEPATH += $$PWD 2 | DEPENDPATH += $$PWD 3 | 4 | HEADERS += \ 5 | $$PWD/xmodel_binary.h \ 6 | $$PWD/xmodel_fparts.h \ 7 | $$PWD/xmodel_hex.h 8 | 9 | SOURCES += \ 10 | $$PWD/xmodel_binary.cpp \ 11 | $$PWD/xmodel_fparts.cpp \ 12 | $$PWD/xmodel_hex.cpp 13 | 14 | DISTFILES += \ 15 | $$PWD/LICENSE \ 16 | $$PWD/README.md \ 17 | $$PWD/xmodel_binary.cmake 18 | -------------------------------------------------------------------------------- /xtableview.pri: -------------------------------------------------------------------------------- 1 | INCLUDEPATH += $$PWD 2 | DEPENDPATH += $$PWD 3 | 4 | !contains(XCONFIG, xmodel) { 5 | XCONFIG += xmodel 6 | include($$PWD/xmodel.pri) 7 | } 8 | 9 | HEADERS += \ 10 | $$PWD/xheaderview.h \ 11 | $$PWD/xsortfilterproxymodel.h \ 12 | $$PWD/xtableview.h \ 13 | $$PWD/xmodel_msrecord.h 14 | 15 | SOURCES += \ 16 | $$PWD/xheaderview.cpp \ 17 | $$PWD/xsortfilterproxymodel.cpp \ 18 | $$PWD/xtableview.cpp \ 19 | $$PWD/xmodel_msrecord.cpp 20 | 21 | DISTFILES += \ 22 | $$PWD/LICENSE \ 23 | $$PWD/README.md \ 24 | $$PWD/xtableview.cmake 25 | -------------------------------------------------------------------------------- /xlineedithex.pri: -------------------------------------------------------------------------------- 1 | INCLUDEPATH += $$PWD 2 | DEPENDPATH += $$PWD 3 | 4 | HEADERS += \ 5 | $$PWD/dialogbits8.h \ 6 | $$PWD/xlineedithex.h \ 7 | $$PWD/xlineedit_num.h \ 8 | $$PWD/xlineedit_num_validator.h \ 9 | $$PWD/xlineeditvalidator.h 10 | 11 | SOURCES += \ 12 | $$PWD/dialogbits8.cpp \ 13 | $$PWD/xlineedithex.cpp \ 14 | $$PWD/xlineedit_num.cpp \ 15 | $$PWD/xlineedit_num_validator.cpp \ 16 | $$PWD/xlineeditvalidator.cpp 17 | 18 | FORMS += \ 19 | $$PWD/dialogbits8.ui 20 | 21 | DISTFILES += \ 22 | $$PWD/LICENSE \ 23 | $$PWD/README.md \ 24 | $$PWD/xlineedithex.cmake 25 | -------------------------------------------------------------------------------- /xmodel_binary.cmake: -------------------------------------------------------------------------------- 1 | include_directories(${CMAKE_CURRENT_LIST_DIR}) 2 | 3 | set(XMODEL_BINARY_SOURCES 4 | ${XMODEL_BINARY_SOURCES} 5 | ${CMAKE_CURRENT_LIST_DIR}/xmodel_archiverecords.cpp 6 | ${CMAKE_CURRENT_LIST_DIR}/xmodel_archiverecords.h 7 | ${CMAKE_CURRENT_LIST_DIR}/xmodel_binary.cpp 8 | ${CMAKE_CURRENT_LIST_DIR}/xmodel_binary.h 9 | ${CMAKE_CURRENT_LIST_DIR}/xmodel_fparts.cpp 10 | ${CMAKE_CURRENT_LIST_DIR}/xmodel_fparts.h 11 | ${CMAKE_CURRENT_LIST_DIR}/xmodel_hex.cpp 12 | ${CMAKE_CURRENT_LIST_DIR}/xmodel_hex.h 13 | ${CMAKE_CURRENT_LIST_DIR}/xmodel_streams.cpp 14 | ${CMAKE_CURRENT_LIST_DIR}/xmodel_streams.h 15 | ) 16 | -------------------------------------------------------------------------------- /xlineedithex.cmake: -------------------------------------------------------------------------------- 1 | include_directories(${CMAKE_CURRENT_LIST_DIR}) 2 | 3 | set(XLINEEDITHEX_SOURCES 4 | ${XLINEEDITHEX_SOURCES} 5 | ${CMAKE_CURRENT_LIST_DIR}/dialogbits8.cpp 6 | ${CMAKE_CURRENT_LIST_DIR}/dialogbits8.h 7 | ${CMAKE_CURRENT_LIST_DIR}/dialogbits8.ui 8 | ${CMAKE_CURRENT_LIST_DIR}/xlineeditvalidator.cpp 9 | ${CMAKE_CURRENT_LIST_DIR}/xlineeditvalidator.h 10 | ${CMAKE_CURRENT_LIST_DIR}/xlineedithex.cpp 11 | ${CMAKE_CURRENT_LIST_DIR}/xlineedithex.h 12 | ${CMAKE_CURRENT_LIST_DIR}/xlineedit_num.cpp 13 | ${CMAKE_CURRENT_LIST_DIR}/xlineedit_num.h 14 | ${CMAKE_CURRENT_LIST_DIR}/xlineedit_num_validator.cpp 15 | ${CMAKE_CURRENT_LIST_DIR}/xlineedit_num_validator.h 16 | ) 17 | -------------------------------------------------------------------------------- /xtableview.cmake: -------------------------------------------------------------------------------- 1 | include_directories(${CMAKE_CURRENT_LIST_DIR}) 2 | 3 | if (NOT DEFINED XMODEL_SOURCES) 4 | include(${CMAKE_CURRENT_LIST_DIR}/xmodel.cmake) 5 | set(XTABLEVIEW_SOURCES ${XTABLEVIEW_SOURCES} ${XMODEL_SOURCES}) 6 | endif() 7 | 8 | set(XTABLEVIEW_SOURCES 9 | ${XTABLEVIEW_SOURCES} 10 | ${CMAKE_CURRENT_LIST_DIR}/xtableview.cpp 11 | ${CMAKE_CURRENT_LIST_DIR}/xtableview.h 12 | ${CMAKE_CURRENT_LIST_DIR}/xheaderview.cpp 13 | ${CMAKE_CURRENT_LIST_DIR}/xheaderview.h 14 | ${CMAKE_CURRENT_LIST_DIR}/xsortfilterproxymodel.cpp 15 | ${CMAKE_CURRENT_LIST_DIR}/xsortfilterproxymodel.h 16 | ${CMAKE_CURRENT_LIST_DIR}/xmodel.cpp 17 | ${CMAKE_CURRENT_LIST_DIR}/xmodel.h 18 | ${CMAKE_CURRENT_LIST_DIR}/xmodel_msrecord.cpp 19 | ${CMAKE_CURRENT_LIST_DIR}/xmodel_msrecord.h 20 | ) 21 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2017-2025 hors 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /xabstracttableview.pri: -------------------------------------------------------------------------------- 1 | INCLUDEPATH += $$PWD 2 | DEPENDPATH += $$PWD 3 | 4 | HEADERS += \ 5 | $$PWD/xabstracttableview.h \ 6 | $$PWD/xdevicetableeditview.h \ 7 | $$PWD/xdevicetableview.h 8 | 9 | SOURCES += \ 10 | $$PWD/xabstracttableview.cpp \ 11 | $$PWD/xdevicetableeditview.cpp \ 12 | $$PWD/xdevicetableview.cpp 13 | 14 | !contains(XCONFIG, dialogtextinfo) { 15 | XCONFIG += dialogtextinfo 16 | include($$PWD/../FormatDialogs/dialogtextinfo.pri) 17 | } 18 | 19 | !contains(XCONFIG, dialogresize) { 20 | XCONFIG += dialogresize 21 | include($$PWD/../FormatDialogs/dialogresize.pri) 22 | } 23 | 24 | !contains(XCONFIG, dialogremove) { 25 | XCONFIG += dialogremove 26 | include($$PWD/../FormatDialogs/dialogremove.pri) 27 | } 28 | 29 | !contains(XCONFIG, xshortcuts) { 30 | XCONFIG += xshortcuts 31 | include($$PWD/../XShortcuts/xshortcuts.pri) 32 | } 33 | 34 | !contains(XCONFIG, xinfodb) { 35 | XCONFIG += xinfodb 36 | include($$PWD/../XInfoDB/xinfodb.pri) 37 | } 38 | 39 | !contains(XCONFIG, xbinaryview) { 40 | XCONFIG += xbinaryview 41 | include($$PWD/xbinaryview.pri) 42 | } 43 | 44 | DISTFILES += \ 45 | $$PWD/LICENSE \ 46 | $$PWD/README.md \ 47 | $$PWD/xabstracttableview.cmake 48 | -------------------------------------------------------------------------------- /xlineedit_num.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2025 hors 2 | * 3 | * Permission is hereby granted, free of charge, to any person obtaining a copy 4 | * of this software and associated documentation files (the "Software"), to deal 5 | * in the Software without restriction, including without limitation the rights 6 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | * copies of the Software, and to permit persons to whom the Software is 8 | * furnished to do so, subject to the following conditions: 9 | * 10 | * The above copyright notice and this permission notice shall be included in 11 | * all copies or substantial portions of the Software. 12 | * 13 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 19 | * SOFTWARE. 20 | */ 21 | #include "xlineedit_num.h" 22 | 23 | XLineEdit_num::XLineEdit_num() 24 | { 25 | } 26 | -------------------------------------------------------------------------------- /xlineedit_num_validator.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2025 hors 2 | * 3 | * Permission is hereby granted, free of charge, to any person obtaining a copy 4 | * of this software and associated documentation files (the "Software"), to deal 5 | * in the Software without restriction, including without limitation the rights 6 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | * copies of the Software, and to permit persons to whom the Software is 8 | * furnished to do so, subject to the following conditions: 9 | * 10 | * The above copyright notice and this permission notice shall be included in 11 | * all copies or substantial portions of the Software. 12 | * 13 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 19 | * SOFTWARE. 20 | */ 21 | #include "xlineedit_num_validator.h" 22 | 23 | XLineEdit_num_validator::XLineEdit_num_validator(QObject *parent) : QValidator{parent} 24 | { 25 | } 26 | -------------------------------------------------------------------------------- /xlineedit_num_validator.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2025 hors 2 | * 3 | * Permission is hereby granted, free of charge, to any person obtaining a copy 4 | * of this software and associated documentation files (the "Software"), to deal 5 | * in the Software without restriction, including without limitation the rights 6 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | * copies of the Software, and to permit persons to whom the Software is 8 | * furnished to do so, subject to the following conditions: 9 | * 10 | * The above copyright notice and this permission notice shall be included in 11 | * all copies or substantial portions of the Software. 12 | * 13 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 19 | * SOFTWARE. 20 | */ 21 | #ifndef XLINEEDIT_NUM_VALIDATOR_H 22 | #define XLINEEDIT_NUM_VALIDATOR_H 23 | 24 | #include 25 | #include 26 | 27 | class XLineEdit_num_validator : public QValidator { 28 | public: 29 | explicit XLineEdit_num_validator(QObject *parent = nullptr); 30 | }; 31 | 32 | #endif // XLINEEDIT_NUM_VALIDATOR_H 33 | -------------------------------------------------------------------------------- /subclassofqstyleditemdelegate.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2017-2025 hors 2 | * 3 | * Permission is hereby granted, free of charge, to any person obtaining a copy 4 | * of this software and associated documentation files (the "Software"), to deal 5 | * in the Software without restriction, including without limitation the rights 6 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | * copies of the Software, and to permit persons to whom the Software is 8 | * furnished to do so, subject to the following conditions: 9 | * 10 | * The above copyright notice and this permission notice shall be included in 11 | * all copies or substantial portions of the Software. 12 | * 13 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 19 | * SOFTWARE. 20 | */ 21 | #ifndef SUBCLASSOFQSTYLEDITEMDELEGATE_H 22 | #define SUBCLASSOFQSTYLEDITEMDELEGATE_H 23 | 24 | #include 25 | 26 | class SubclassOfQStyledItemDelegate : public QStyledItemDelegate { 27 | public: 28 | explicit SubclassOfQStyledItemDelegate(QWidget *pParent = nullptr); 29 | 30 | protected: 31 | virtual void paint(QPainter *pPainter, const QStyleOptionViewItem &styleOptionViewItem, const QModelIndex &modelIndex) const override; 32 | }; 33 | 34 | #endif // SUBCLASSOFQSTYLEDITEMDELEGATE_H 35 | -------------------------------------------------------------------------------- /xabstracttableview.cmake: -------------------------------------------------------------------------------- 1 | include_directories(${CMAKE_CURRENT_LIST_DIR}) 2 | 3 | if (NOT DEFINED DIALOGRESIZE_SOURCES) 4 | include(${CMAKE_CURRENT_LIST_DIR}/../FormatDialogs/dialogresize.cmake) 5 | set(XABSTRACTTABLEVIEW_SOURCES ${XABSTRACTTABLEVIEW_SOURCES} ${DIALOGRESIZE_SOURCES}) 6 | endif() 7 | if (NOT DEFINED DIALOGREMOVE_SOURCES) 8 | include(${CMAKE_CURRENT_LIST_DIR}/../FormatDialogs/dialogremove.cmake) 9 | set(XABSTRACTTABLEVIEW_SOURCES ${XABSTRACTTABLEVIEW_SOURCES} ${DIALOGREMOVE_SOURCES}) 10 | endif() 11 | if (NOT DEFINED DIALOGTEXTINFO_SOURCES) 12 | include(${CMAKE_CURRENT_LIST_DIR}/../FormatDialogs/dialogtextinfo.cmake) 13 | set(XABSTRACTTABLEVIEW_SOURCES ${XABSTRACTTABLEVIEW_SOURCES} ${DIALOGTEXTINFO_SOURCES}) 14 | endif() 15 | if (NOT DEFINED XSHORTCUTS_SOURCES) 16 | include(${CMAKE_CURRENT_LIST_DIR}/../XShortcuts/xshortcuts.cmake) 17 | set(XABSTRACTTABLEVIEW_SOURCES ${XABSTRACTTABLEVIEW_SOURCES} ${XSHORTCUTS_SOURCES}) 18 | endif() 19 | if (NOT DEFINED XINFODB_SOURCES) 20 | include(${CMAKE_CURRENT_LIST_DIR}/../XInfoDB/xinfodb.cmake) 21 | set(XABSTRACTTABLEVIEW_SOURCES ${XABSTRACTTABLEVIEW_SOURCES} ${XINFODB_SOURCES}) 22 | endif() 23 | if (NOT DEFINED XBINARYVIEW_SOURCES) 24 | include(${CMAKE_CURRENT_LIST_DIR}/xbinaryview.cmake) 25 | set(XABSTRACTTABLEVIEW_SOURCES ${XABSTRACTTABLEVIEW_SOURCES} ${XBINARYVIEW_SOURCES}) 26 | endif() 27 | 28 | set(XABSTRACTTABLEVIEW_SOURCES 29 | ${XABSTRACTTABLEVIEW_SOURCES} 30 | ${CMAKE_CURRENT_LIST_DIR}/xabstracttableview.cpp 31 | ${CMAKE_CURRENT_LIST_DIR}/xabstracttableview.h 32 | ${CMAKE_CURRENT_LIST_DIR}/xdevicetableview.cpp 33 | ${CMAKE_CURRENT_LIST_DIR}/xdevicetableview.h 34 | ${CMAKE_CURRENT_LIST_DIR}/xdevicetableeditview.cpp 35 | ${CMAKE_CURRENT_LIST_DIR}/xdevicetableeditview.h 36 | ) 37 | -------------------------------------------------------------------------------- /xlineedit_num.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2025 hors 2 | * 3 | * Permission is hereby granted, free of charge, to any person obtaining a copy 4 | * of this software and associated documentation files (the "Software"), to deal 5 | * in the Software without restriction, including without limitation the rights 6 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | * copies of the Software, and to permit persons to whom the Software is 8 | * furnished to do so, subject to the following conditions: 9 | * 10 | * The above copyright notice and this permission notice shall be included in 11 | * all copies or substantial portions of the Software. 12 | * 13 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 19 | * SOFTWARE. 20 | */ 21 | #ifndef XLINEEDIT_NUM_H 22 | #define XLINEEDIT_NUM_H 23 | 24 | #include 25 | #include 26 | 27 | class XLineEdit_num : public QLineEdit { 28 | public: 29 | enum MODE { 30 | MODE_UNKNOWN = 0, 31 | MODE_HEX, 32 | MODE_DEC, 33 | MODE_SIGN_DEC 34 | }; 35 | 36 | enum BITS { 37 | BITS_UNKNOWN = 0, 38 | BITS_8 = 8, 39 | BITS_16 = 16, 40 | BITS_32 = 32, 41 | BITS_64 = 64 42 | }; 43 | 44 | XLineEdit_num(); 45 | 46 | private: 47 | QVariant m_vValue; 48 | }; 49 | 50 | #endif // XLINEEDIT_NUM_H 51 | -------------------------------------------------------------------------------- /xdatetimeeditx.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2017-2025 hors 2 | * 3 | * Permission is hereby granted, free of charge, to any person obtaining a copy 4 | * of this software and associated documentation files (the "Software"), to deal 5 | * in the Software without restriction, including without limitation the rights 6 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | * copies of the Software, and to permit persons to whom the Software is 8 | * furnished to do so, subject to the following conditions: 9 | * 10 | * The above copyright notice and this permission notice shall be included in 11 | * all copies or substantial portions of the Software. 12 | * 13 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 19 | * SOFTWARE. 20 | */ 21 | #ifndef XDATETIMEEDITX_H 22 | #define XDATETIMEEDITX_H 23 | 24 | #include 25 | 26 | class XDateTimeEditX : public QDateTimeEdit { 27 | Q_OBJECT 28 | 29 | public: 30 | enum DT_TYPE { 31 | DT_TYPE_UNKNOWN = 0, 32 | DT_TYPE_POSIX 33 | }; 34 | 35 | XDateTimeEditX(QWidget *pParent = nullptr); 36 | 37 | void setValue(QVariant vValue, DT_TYPE dtType); 38 | QVariant getValue(); 39 | 40 | private slots: 41 | void _setDateTime(const QDateTime &dtValue); 42 | 43 | signals: 44 | void valueChanged(QVariant vValue); 45 | 46 | private: 47 | QVariant m_vValue; 48 | DT_TYPE m_dtType; 49 | }; 50 | 51 | #endif // XDATETIMEEDITX_H 52 | -------------------------------------------------------------------------------- /subclassofqstyleditemdelegate.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2017-2025 hors 2 | * 3 | * Permission is hereby granted, free of charge, to any person obtaining a copy 4 | * of this software and associated documentation files (the "Software"), to deal 5 | * in the Software without restriction, including without limitation the rights 6 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | * copies of the Software, and to permit persons to whom the Software is 8 | * furnished to do so, subject to the following conditions: 9 | * 10 | * The above copyright notice and this permission notice shall be included in 11 | * all copies or substantial portions of the Software. 12 | * 13 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 19 | * SOFTWARE. 20 | */ 21 | #include "subclassofqstyleditemdelegate.h" 22 | 23 | SubclassOfQStyledItemDelegate::SubclassOfQStyledItemDelegate(QWidget *pParent) : QStyledItemDelegate(pParent) 24 | { 25 | } 26 | 27 | void SubclassOfQStyledItemDelegate::paint(QPainter *pPainter, const QStyleOptionViewItem &styleOptionViewItem, const QModelIndex &modelIndex) const 28 | { 29 | QStyleOptionViewItem &refToNonConstOption = const_cast(styleOptionViewItem); 30 | refToNonConstOption.showDecorationSelected = false; 31 | // refToNonConstOption.state &= ~QStyle::State_HasFocus & 32 | // ~QStyle::State_MouseOver; 33 | 34 | QStyledItemDelegate::paint(pPainter, refToNonConstOption, modelIndex); 35 | } 36 | -------------------------------------------------------------------------------- /xmodel_archiverecords.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2025 hors 2 | * 3 | * Permission is hereby granted, free of charge, to any person obtaining a copy 4 | * of this software and associated documentation files (the "Software"), to deal 5 | * in the Software without restriction, including without limitation the rights 6 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | * copies of the Software, and to permit persons to do so, subject to the 8 | * following conditions: 9 | * 10 | * The above copyright notice and this permission notice shall be included in 11 | * all copies or substantial portions of the Software. 12 | * 13 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 19 | * SOFTWARE. 20 | */ 21 | #ifndef XMODEL_ARCHIVERECORDS_H 22 | #define XMODEL_ARCHIVERECORDS_H 23 | 24 | #include "xbinary.h" 25 | #include "xmodel.h" 26 | 27 | class XModel_ArchiveRecords : public XModel { 28 | Q_OBJECT 29 | 30 | public: 31 | explicit XModel_ArchiveRecords(const QList &listColumns, QList *pListArchiveRecords, QObject *pParent = nullptr); 32 | 33 | QVariant data(const QModelIndex &index, int nRole = Qt::DisplayRole) const override; 34 | QVariant headerData(int nSection, Qt::Orientation orientation, int nRole = Qt::DisplayRole) const override; 35 | 36 | private: 37 | QList *m_pListArchiveRecords; 38 | void _initColumns(); 39 | QList m_listColumns; 40 | }; 41 | 42 | #endif // XMODEL_ARCHIVERECORDS_H 43 | -------------------------------------------------------------------------------- /xmodel_streams.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2025 hors 2 | * 3 | * Permission is hereby granted, free of charge, to any person obtaining a copy 4 | * of this software and associated documentation files (the "Software"), to deal 5 | * in the Software without restriction, including without limitation the rights 6 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | * copies of the Software, and to permit persons to do so, subject to the 8 | * following conditions: 9 | * 10 | * The above copyright notice and this permission notice shall be included in 11 | * all copies or substantial portions of the Software. 12 | * 13 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 19 | * SOFTWARE. 20 | */ 21 | #ifndef XMODEL_STREAMS_H 22 | #define XMODEL_STREAMS_H 23 | 24 | #include "xbinary.h" 25 | #include "xmodel.h" 26 | 27 | class XModel_Streams : public XModel { 28 | Q_OBJECT 29 | 30 | public: 31 | enum COLUMN { 32 | COLUMN_NAME = 0, 33 | COLUMN_OFFSET, 34 | COLUMN_SIZE, 35 | COLUMN_COMPRESSMETHOD, 36 | COLUMN_UNCOMPRESSEDSIZE, 37 | __COLUMN_COUNT 38 | }; 39 | 40 | explicit XModel_Streams(QList *pListFParts, QObject *pParent = nullptr); 41 | 42 | QVariant data(const QModelIndex &index, int nRole = Qt::DisplayRole) const override; 43 | QVariant headerData(int nSection, Qt::Orientation orientation, int nRole = Qt::DisplayRole) const override; 44 | 45 | private: 46 | QList *m_pListFParts; 47 | void _initColumns(); 48 | }; 49 | 50 | #endif // XMODEL_STREAMS_H 51 | -------------------------------------------------------------------------------- /xheaderview.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2024-2025 hors 2 | * 3 | * Permission is hereby granted, free of charge, to any person obtaining a copy 4 | * of this software and associated documentation files (the "Software"), to deal 5 | * in the Software without restriction, including without limitation the rights 6 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | * copies of the Software, and to permit persons to whom the Software is 8 | * furnished to do so, subject to the following conditions: 9 | * 10 | * The above copyright notice and this permission notice shall be included in 11 | * all copies or substantial portions of the Software. 12 | * 13 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 19 | * SOFTWARE. 20 | */ 21 | #ifndef XHEADERVIEW_H 22 | #define XHEADERVIEW_H 23 | 24 | #include 25 | #include 26 | #include 27 | 28 | class XHeaderView : public QHeaderView { 29 | Q_OBJECT 30 | 31 | public: 32 | XHeaderView(QWidget *pParent = nullptr); 33 | ~XHeaderView(); 34 | 35 | QSize sizeHint() const override; 36 | void setNumberOfFilters(qint32 nNumberOfFilters); 37 | void clearFilters(); 38 | void updateGeometries() override; 39 | void adjustPositions(); 40 | QList getFilters(); 41 | void setFilterEnabled(qint32 nColumn, bool bFilterEnabled); 42 | 43 | private slots: 44 | void _textChanged(const QString &sText); 45 | void onSectionResized(int i, int nOldSize, int nNewSize); 46 | void onSectionClicked(int logicalIndex); 47 | 48 | signals: 49 | void filterChanged(); 50 | 51 | private: 52 | QList m_listLineEdits; 53 | }; 54 | 55 | #endif // XHEADERVIEW_H 56 | -------------------------------------------------------------------------------- /xmodel_hex.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2025 hors 2 | * 3 | * Permission is hereby granted, free of charge, to any person obtaining a copy 4 | * of this software and associated documentation files (the "Software"), to deal 5 | * in the Software without restriction, including without limitation the rights 6 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | * copies of the Software, and to permit persons to whom the Software is 8 | * furnished to do so, subject to the following conditions: 9 | * 10 | * The above copyright notice and this permission notice shall be included in 11 | * all copies or substantial portions of the Software. 12 | * 13 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 19 | * SOFTWARE. 20 | */ 21 | #ifndef XMODEL_HEX_H 22 | #define XMODEL_HEX_H 23 | 24 | #include 25 | #include "xmodel.h" 26 | 27 | class XModel_Hex : public XModel { 28 | Q_OBJECT 29 | 30 | public: 31 | enum COLUMN { 32 | COLUMN_ADDRESS = 0, 33 | COLUMN_HEX, 34 | COLUMN_ASCII, 35 | __COLUMN_COUNT 36 | }; 37 | 38 | explicit XModel_Hex(QIODevice *pDevice, qint64 nOffset, qint64 nSize, quint64 nStartAddress, qint32 nBytesPerLine, QObject *pParent = nullptr); 39 | 40 | QVariant data(const QModelIndex &index, int nRole = Qt::DisplayRole) const override; 41 | QVariant headerData(int nSection, Qt::Orientation orientation, int nRole = Qt::DisplayRole) const override; 42 | 43 | private: 44 | QIODevice *m_pDevice; 45 | qint64 m_nOffset; 46 | qint64 m_nSize; 47 | quint64 m_nStartAddress; 48 | qint32 m_nBytesPerLine; 49 | 50 | QString _bytesToHex(const QByteArray &ba) const; 51 | QString _bytesToAscii(const QByteArray &ba) const; 52 | }; 53 | 54 | #endif // XMODEL_HEX_H 55 | -------------------------------------------------------------------------------- /xmodel_fparts.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2025 hors 2 | * 3 | * Permission is hereby granted, free of charge, to any person obtaining a copy 4 | * of this software and associated documentation files (the "Software"), to deal 5 | * in the Software without restriction, including without limitation the rights 6 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | * copies of the Software, and to permit persons to whom the Software is 8 | * furnished to do so, subject to the following conditions: 9 | * 10 | * The above copyright notice and this permission notice shall be included in 11 | * all copies or substantial portions of the Software. 12 | * 13 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 19 | * SOFTWARE. 20 | */ 21 | #ifndef XMODEL_FPARTS_H 22 | #define XMODEL_FPARTS_H 23 | 24 | #include "xbinary.h" 25 | #include "xmodel.h" 26 | 27 | class XModel_FPARTS : public XModel { 28 | Q_OBJECT 29 | 30 | public: 31 | enum COLUMN { 32 | COLUMN_NAME = 0, 33 | COLUMN_OFFSET, 34 | COLUMN_SIZE, 35 | COLUMN_VADDRESS, 36 | COLUMN_VSIZE, 37 | COLUMN_PART, 38 | __COLUMN_COUNT 39 | }; 40 | 41 | explicit XModel_FPARTS(QList *pListFParts, QObject *pParent = nullptr); 42 | 43 | QVariant data(const QModelIndex &index, int nRole = Qt::DisplayRole) const override; 44 | QVariant headerData(int nSection, Qt::Orientation orientation, int nRole = Qt::DisplayRole) const override; 45 | virtual SORT_METHOD getSortMethod(qint32 nColumn) override; 46 | virtual bool isCustomFilter() override; 47 | virtual bool isCustomSort() override; 48 | 49 | private: 50 | QList *m_pListFParts; 51 | void _initColumns(); 52 | }; 53 | 54 | #endif // XMODEL_FPARTS_H 55 | -------------------------------------------------------------------------------- /xsortfilterproxymodel.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2024-2025 hors 2 | * 3 | * Permission is hereby granted, free of charge, to any person obtaining a copy 4 | * of this software and associated documentation files (the "Software"), to deal 5 | * in the Software without restriction, including without limitation the rights 6 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | * copies of the Software, and to permit persons to whom the Software is 8 | * furnished to do so, subject to the following conditions: 9 | * 10 | * The above copyright notice and this permission notice shall be included in 11 | * all copies or substantial portions of the Software. 12 | * 13 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 19 | * SOFTWARE. 20 | */ 21 | 22 | #ifndef XSORTFILTERPROXYMODEL_H 23 | #define XSORTFILTERPROXYMODEL_H 24 | 25 | #include 26 | #include "xmodel.h" 27 | 28 | class XSortFilterProxyModel : public QSortFilterProxyModel { 29 | public: 30 | explicit XSortFilterProxyModel(QObject *pParent = nullptr); 31 | void setFilters(const QList &listFilters); 32 | void setSortMethod(qint32 nColumn, XModel::SORT_METHOD sortMethod); 33 | void setSourceModel(QAbstractItemModel *sourceModel) override; 34 | QVariant data(const QModelIndex &index, int nRole = Qt::DisplayRole) const override; 35 | virtual void sort(int column, Qt::SortOrder order = Qt::AscendingOrder) override; 36 | 37 | protected: 38 | bool filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const override; 39 | bool lessThan(const QModelIndex &left, const QModelIndex &right) const override; 40 | 41 | private: 42 | bool m_bIsXmodel; 43 | bool m_bIsCustomFilter; 44 | bool m_bIsCustomSort; 45 | XModel *m_pXModel; 46 | QList m_listFilters; 47 | QMap m_mapSortMethods; 48 | }; 49 | 50 | #endif // XSORTFILTERPROXYMODEL_H 51 | -------------------------------------------------------------------------------- /xmodel_binary.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2025 hors 2 | * 3 | * Permission is hereby granted, free of charge, to any person obtaining a copy 4 | * of this software and associated documentation files (the "Software"), to deal 5 | * in the Software without restriction, including without limitation the rights 6 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | * copies of the Software, and to permit persons to whom the Software is 8 | * furnished to do so, subject to the following conditions: 9 | * 10 | * The above copyright notice and this permission notice shall be included in 11 | * all copies or substantial portions of the Software. 12 | * 13 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 19 | * SOFTWARE. 20 | */ 21 | #ifndef XMODEL_BINARY_H 22 | #define XMODEL_BINARY_H 23 | 24 | #include "xbinary.h" 25 | #include "xmodel.h" 26 | 27 | class XModel_Binary : public XModel { 28 | Q_OBJECT 29 | 30 | enum COLUMN_HEADER { 31 | COLUMN_HEADER_NAME = 0, 32 | COLUMN_HEADER_OFFSET, 33 | COLUMN_HEADER_SIZE, 34 | COLUMN_HEADER_TYPE, 35 | COLUMN_HEADER_VALUE, 36 | COLUMN_HEADER_INFO, 37 | COLUMN_HEADER_COMMENT, 38 | __COLUMN_HEADER_SIZE 39 | }; 40 | 41 | public: 42 | XModel_Binary(const XBinary::DATA_RECORDS_OPTIONS &dataRecordsOptions, QList *pListDataRecords, QList *pListTitles, 43 | QObject *pParent); 44 | 45 | virtual QVariant data(const QModelIndex &index, int nRole = Qt::DisplayRole) const; 46 | virtual QVariant headerData(int nSection, Qt::Orientation orientation, int nRole = Qt::DisplayRole) const; 47 | void setComments(QList *pListComments); 48 | 49 | private: 50 | XBinary::DATA_RECORDS_OPTIONS m_dataRecordsOptions; 51 | QList *m_pListDataRecords; 52 | QList *m_pListTitles; 53 | QList *m_pListComments; 54 | }; 55 | 56 | #endif // XMODEL_BINARY_H 57 | -------------------------------------------------------------------------------- /xhtml.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2021-2025 hors 2 | * 3 | * Permission is hereby granted, free of charge, to any person obtaining a copy 4 | * of this software and associated documentation files (the "Software"), to deal 5 | * in the Software without restriction, including without limitation the rights 6 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | * copies of the Software, and to permit persons to whom the Software is 8 | * furnished to do so, subject to the following conditions: 9 | * 10 | * The above copyright notice and this permission notice shall be included in 11 | * all copies or substantial portions of the Software. 12 | * 13 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 19 | * SOFTWARE. 20 | */ 21 | #ifndef XHTML_H 22 | #define XHTML_H 23 | 24 | #include 25 | #include 26 | 27 | class XHtml : public QObject { 28 | Q_OBJECT 29 | 30 | public: 31 | struct TABLECELL { 32 | QString sText; 33 | bool bBold; 34 | Qt::Alignment alignment; 35 | }; 36 | 37 | explicit XHtml(QObject *pParent = nullptr); 38 | 39 | void appendText(const QString &sText); 40 | void appendHtml(const QString &sHtml); 41 | void appendParagraph(const QString &sText); 42 | void appendHeading(qint32 nLevel, const QString &sText); 43 | void appendLineBreak(); 44 | void appendHorizontalRule(); 45 | void addTableBegin(qint32 nBorder = 1, qint32 nCellPadding = 5); 46 | void addTableRow(const QList &listTableCells); 47 | void addTableEnd(); 48 | void addListBegin(bool bOrdered = false); 49 | void addListItem(const QString &sText); 50 | void addListEnd(); 51 | void clear(); 52 | QString toString() const; 53 | static QString makeLink(const QString &sText, const QString &sLink); 54 | static QString escapeHtml(const QString &sText); 55 | static QString makeBold(const QString &sText); 56 | static QString makeItalic(const QString &sText); 57 | 58 | private: 59 | static QString alignmentToString(Qt::Alignment alignment); 60 | 61 | private: 62 | QString m_sString; 63 | bool m_bInList; 64 | }; 65 | 66 | #endif // XHTML_H 67 | -------------------------------------------------------------------------------- /xtableview.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2024-2025 hors 2 | * 3 | * Permission is hereby granted, free of charge, to any person obtaining a copy 4 | * of this software and associated documentation files (the "Software"), to deal 5 | * in the Software without restriction, including without limitation the rights 6 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | * copies of the Software, and to permit persons to whom the Software is 8 | * furnished to do so, subject to the following conditions: 9 | * 10 | * The above copyright notice and this permission notice shall be included in 11 | * all copies or substantial portions of the Software. 12 | * 13 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 19 | * SOFTWARE. 20 | */ 21 | #ifndef XTABLEVIEW_H 22 | #define XTABLEVIEW_H 23 | 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | 31 | #include "xheaderview.h" 32 | #include "xsortfilterproxymodel.h" 33 | #include "xmodel.h" 34 | #include "xoptions.h" 35 | 36 | class XTableView : public QTableView { 37 | Q_OBJECT 38 | 39 | public: 40 | XTableView(QWidget *pParent = nullptr); 41 | ~XTableView(); 42 | 43 | void setCustomModel(QAbstractItemModel *pModel, bool bFilterEnabled); 44 | void clear(); 45 | XSortFilterProxyModel *getProxyModel(); 46 | void setFilterEnabled(qint32 nColumn, bool bFilterEnabled); 47 | void adjust(); 48 | 49 | signals: 50 | void invalidateSignal(); 51 | 52 | private: 53 | void deleteOldModel(QAbstractItemModel **ppOldModel); 54 | void handleFilter(); 55 | 56 | private slots: 57 | void onFilterChanged(); 58 | void onSortChanged(int column, Qt::SortOrder order); 59 | void horisontalScroll(); 60 | 61 | private: 62 | XHeaderView *m_pHeaderView; 63 | XSortFilterProxyModel *m_pSortFilterProxyModel; 64 | QAbstractItemModel *m_pOldModel; 65 | QAbstractItemModel *m_pModel; 66 | bool m_bIsXmodel; 67 | bool m_bIsCustomFilter; 68 | bool m_bIsCustomSort; 69 | XModel *m_pXModel; 70 | QFutureWatcher m_watcher; 71 | bool m_bIsStop; 72 | }; 73 | 74 | #endif // XTABLEVIEW_H 75 | -------------------------------------------------------------------------------- /xdatetimeeditx.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2017-2025 hors 2 | * 3 | * Permission is hereby granted, free of charge, to any person obtaining a copy 4 | * of this software and associated documentation files (the "Software"), to deal 5 | * in the Software without restriction, including without limitation the rights 6 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | * copies of the Software, and to permit persons to whom the Software is 8 | * furnished to do so, subject to the following conditions: 9 | * 10 | * The above copyright notice and this permission notice shall be included in 11 | * all copies or substantial portions of the Software. 12 | * 13 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 19 | * SOFTWARE. 20 | */ 21 | #include "xdatetimeeditx.h" 22 | 23 | XDateTimeEditX::XDateTimeEditX(QWidget *pParent) : QDateTimeEdit(pParent) 24 | { 25 | m_dtType = DT_TYPE_UNKNOWN; 26 | 27 | connect(this, SIGNAL(dateTimeChanged(QDateTime)), this, SLOT(_setDateTime(QDateTime))); 28 | } 29 | 30 | void XDateTimeEditX::setValue(QVariant vValue, DT_TYPE dtType) 31 | { 32 | if (m_vValue != vValue) { 33 | m_vValue = vValue; 34 | emit valueChanged(vValue); 35 | } 36 | 37 | if (m_dtType != dtType) { 38 | m_dtType = dtType; 39 | 40 | if (dtType == DT_TYPE_POSIX) { 41 | setDisplayFormat("yyyy-MM-dd hh:mm:ss"); 42 | QDateTime dt = QDateTime::fromString("1970-01-01 00:00:00", "yyyy-MM-dd hh:mm:ss"); 43 | setMinimumDateTime(QDateTime(dt)); 44 | setDateTime(dt); 45 | } 46 | } 47 | 48 | if (m_dtType == DT_TYPE_POSIX) { 49 | QDateTime dt; 50 | dt.setMSecsSinceEpoch((quint64)vValue.toULongLong() * 1000); 51 | 52 | setDateTime(dt); 53 | } 54 | } 55 | 56 | QVariant XDateTimeEditX::getValue() 57 | { 58 | return m_vValue; 59 | } 60 | 61 | void XDateTimeEditX::_setDateTime(const QDateTime &dtValue) 62 | { 63 | quint64 nCurrentValue = 0; 64 | 65 | if (m_dtType == DT_TYPE_POSIX) { 66 | nCurrentValue = (quint64)dtValue.toMSecsSinceEpoch() / 1000; 67 | } 68 | 69 | QVariant vValue = nCurrentValue; 70 | 71 | if (m_vValue != vValue) { 72 | m_vValue = vValue; 73 | 74 | emit valueChanged(vValue); 75 | } 76 | } 77 | -------------------------------------------------------------------------------- /xmodel_msrecord.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2025 hors 2 | * 3 | * Permission is hereby granted, free of charge, to any person obtaining a copy 4 | * of this software and associated documentation files (the "Software"), to deal 5 | * in the Software without restriction, including without limitation the rights 6 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | * copies of the Software, and to permit persons to whom the Software is 8 | * furnished to do so, subject to the following conditions: 9 | * 10 | * The above copyright notice and this permission notice shall be included in 11 | * all copies or substantial portions of the Software. 12 | * 13 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 19 | * SOFTWARE. 20 | */ 21 | 22 | #ifndef XMODEL_MSRECORD_H 23 | #define XMODEL_MSRECORD_H 24 | 25 | #include "xbinary.h" 26 | #include "xmodel.h" 27 | 28 | class XModel_MSRecord : public XModel { 29 | Q_OBJECT 30 | 31 | public: 32 | enum COLUMN { 33 | COLUMN_NUMBER, 34 | COLUMN_OFFSET, 35 | COLUMN_ADDRESS, 36 | COLUMN_REGION, 37 | COLUMN_SIZE, 38 | COLUMN_INFO, 39 | COLUMN_VALUE, 40 | __COLUMN_SIZE 41 | }; 42 | 43 | XModel_MSRecord(QIODevice *pDevice, const XBinary::_MEMORY_MAP &memoryMap, QVector *pListRecods, XBinary::VT valueType, 44 | QObject *pParent = nullptr); 45 | 46 | void setValue(XBinary::ENDIAN endian, XBinary::VT valueType, QVariant varValue); 47 | void setSignaturesList(QList *pListSignatureRecords); 48 | 49 | virtual QVariant data(const QModelIndex &index, int nRole = Qt::DisplayRole) const; 50 | virtual QVariant headerData(int nSection, Qt::Orientation orientation, int nRole = Qt::DisplayRole) const; 51 | virtual SORT_METHOD getSortMethod(qint32 nColumn); 52 | virtual bool isCustomFilter(); 53 | virtual bool isCustomSort(); 54 | 55 | private: 56 | QIODevice *m_pDevice; 57 | XBinary::_MEMORY_MAP m_memoryMap; 58 | QVector *m_pListRecords; 59 | XBinary::MODE m_modeAddress; 60 | XBinary::MODE m_modeOffset; 61 | XBinary::ENDIAN m_endian; 62 | QVariant m_varValue; 63 | XBinary::VT m_valueType; 64 | QString m_sValue; 65 | QList *m_pListSignatureRecords; 66 | }; 67 | 68 | #endif // XMODEL_MSRECORD_H 69 | -------------------------------------------------------------------------------- /xlineeditvalidator.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2017-2025 hors 2 | * 3 | * Permission is hereby granted, free of charge, to any person obtaining a copy 4 | * of this software and associated documentation files (the "Software"), to deal 5 | * in the Software without restriction, including without limitation the rights 6 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | * copies of the Software, and to permit persons to whom the Software is 8 | * furnished to do so, subject to the following conditions: 9 | * 10 | * The above copyright notice and this permission notice shall be included in 11 | * all copies or substantial portions of the Software. 12 | * 13 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 19 | * SOFTWARE. 20 | */ 21 | #ifndef XLINEEDITVALIDATOR_H 22 | #define XLINEEDITVALIDATOR_H 23 | 24 | #include 25 | #include 26 | 27 | class XLineEditValidator : public QValidator { 28 | Q_OBJECT 29 | 30 | public: 31 | enum MODE { 32 | MODE_TEXT = 0, 33 | MODE_DEC_8, 34 | MODE_DEC_16, 35 | MODE_DEC_32, 36 | MODE_DEC_64, 37 | MODE_SIGN_DEC_8, 38 | MODE_SIGN_DEC_16, 39 | MODE_SIGN_DEC_32, 40 | MODE_SIGN_DEC_64, 41 | MODE_BIN_8, 42 | MODE_BIN_16, 43 | MODE_BIN_32, 44 | MODE_BIN_64, 45 | MODE_HEX_8, 46 | MODE_HEX_16, 47 | MODE_HEX_32, 48 | MODE_HEX_64, 49 | MODE_UUID, 50 | MODE_SIZE, 51 | MODE_DOUBLE 52 | }; 53 | 54 | explicit XLineEditValidator(QObject *pParent = nullptr); 55 | 56 | void setMode(MODE mode); 57 | MODE getMode(); 58 | virtual State validate(QString &sInput, int &nPos) const; 59 | void setMaxValue(qint64 nValue); 60 | 61 | static quint64 binStringToValue(const QString &sString, bool *pbSuccess = 0); 62 | static QString value8ToBinString(quint8 nValue); 63 | static QString value16ToBinString(quint16 nValue); 64 | static QString value32ToBinString(quint32 nValue); 65 | static QString value64ToBinString(quint64 nValue); 66 | static QString _valueToBinString(quint64 nValue, qint32 nBits); 67 | static QString _valueToSizeString(quint64 nValue); 68 | static qint32 getNumberOfBits(MODE mode); 69 | 70 | private: 71 | MODE m_mode; 72 | qint64 m_nMaxValue; 73 | }; 74 | 75 | #endif // XLINEEDITVALIDATOR_H 76 | -------------------------------------------------------------------------------- /dialogbits8.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2023-2025 hors 2 | * 3 | * Permission is hereby granted, free of charge, to any person obtaining a copy 4 | * of this software and associated documentation files (the "Software"), to deal 5 | * in the Software without restriction, including without limitation the rights 6 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | * copies of the Software, and to permit persons to whom the Software is 8 | * furnished to do so, subject to the following conditions: 9 | * 10 | * The above copyright notice and this permission notice shall be included in 11 | * all copies or substantial portions of the Software. 12 | * 13 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 19 | * SOFTWARE. 20 | */ 21 | #ifndef DIALOGBITS8_H 22 | #define DIALOGBITS8_H 23 | 24 | #include 25 | #include 26 | #include "xlineeditvalidator.h" 27 | 28 | namespace Ui { 29 | class DialogBits8; 30 | } 31 | 32 | class DialogBits8 : public QDialog { 33 | Q_OBJECT 34 | 35 | public: 36 | explicit DialogBits8(QWidget *pParent, bool bStayOnTop); 37 | ~DialogBits8(); 38 | 39 | void setReadonly(bool bIsReadonly); 40 | void setValue_uint8(quint8 nValue); 41 | void setValue_uint16(quint16 nValue); 42 | void setValue_uint32(quint32 nValue); 43 | void setValue_uint64(quint64 nValue); 44 | void reload(); 45 | quint8 getValue_uint8(); 46 | quint16 getValue_uint16(); 47 | quint32 getValue_uint32(); 48 | quint64 getValue_uint64(); 49 | 50 | private slots: 51 | void _handleButton(QToolButton *pToolButton); 52 | void on_lineEditHex_textChanged(const QString &sString); 53 | void on_lineEditSigned_textChanged(const QString &sString); 54 | void on_lineEditUnsigned_textChanged(const QString &sString); 55 | void on_lineEditBin_textChanged(const QString &sString); 56 | void toggledSlot(bool bState); 57 | void enableControls(bool bState); 58 | void on_pushButtonCancel_clicked(); 59 | 60 | void on_pushButtonOK_clicked(); 61 | 62 | private: 63 | Ui::DialogBits8 *ui; 64 | quint64 m_nValue; 65 | bool m_bIsReadonly; 66 | XLineEditValidator m_validatorHex; 67 | XLineEditValidator m_validatorSigned; 68 | XLineEditValidator m_validatorUnsigned; 69 | XLineEditValidator m_validatorBin; 70 | QList m_listButtons; 71 | qint32 m_nBits; 72 | }; 73 | 74 | #endif // DIALOGBITS8_H 75 | -------------------------------------------------------------------------------- /xcomboboxex.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2017-2025 hors 2 | * 3 | * Permission is hereby granted, free of charge, to any person obtaining a copy 4 | * of this software and associated documentation files (the "Software"), to deal 5 | * in the Software without restriction, including without limitation the rights 6 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | * copies of the Software, and to permit persons to whom the Software is 8 | * furnished to do so, subject to the following conditions: 9 | * 10 | * The above copyright notice and this permission notice shall be included in 11 | * all copies or substantial portions of the Software. 12 | * 13 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 19 | * SOFTWARE. 20 | */ 21 | #ifndef XCOMBOBOXEX_H 22 | #define XCOMBOBOXEX_H 23 | 24 | #include 25 | #include 26 | #include 27 | #include 28 | 29 | #include "subclassofqstyleditemdelegate.h" 30 | 31 | class XComboBoxEx : public QComboBox { 32 | Q_OBJECT 33 | 34 | public: 35 | enum CBTYPE { 36 | CBTYPE_LIST = 0, 37 | CBTYPE_FLAGS, 38 | CBTYPE_ELIST, // Extended list 39 | CBTYPE_CUSTOM_FLAGS 40 | }; 41 | 42 | struct CUSTOM_FLAG { 43 | quint64 nValue; 44 | QString sString; 45 | bool bIsChecked; 46 | bool bIsReadOnly; 47 | }; 48 | 49 | explicit XComboBoxEx(QWidget *pParent = nullptr); 50 | 51 | void setData(const QMap &mapData, CBTYPE cbtype = CBTYPE_LIST, quint64 nMask = 0, const QString &sTitle = ""); 52 | void setValue(QVariant varValue); 53 | QVariant getValue(); 54 | void setReadOnly(bool bIsReadOnly); 55 | QString getDescription(); 56 | void addCustomFlags(const QString &sTitle, const QList &listCustomFlags); 57 | void setCustomFlag(quint64 nValue); 58 | QList getCustomFlags(); 59 | static void _addCustomFlag(QList *pListCustomFlags, quint64 nValue, const QString &sString, bool bChecked); 60 | void setItemEnabled(qint32 nRow, bool bState); 61 | 62 | private slots: 63 | void currentIndexChangedSlot(int nIndex); 64 | void itemChangedSlot(QStandardItem *pItem); 65 | 66 | signals: 67 | void valueChanged(QVariant vValue); 68 | 69 | private: 70 | QVariant m_varValue; 71 | bool m_bIsReadonly; 72 | QStandardItemModel m_model; 73 | CBTYPE m_cbtype; 74 | quint64 m_nMask; 75 | QMap m_mapData; 76 | }; 77 | 78 | #define PXComboBoxEx XComboBoxEx * 79 | 80 | #endif // XCOMBOBOXEX_H 81 | -------------------------------------------------------------------------------- /xmodel.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2025 hors 2 | * 3 | * Permission is hereby granted, free of charge, to any person obtaining a copy 4 | * of this software and associated documentation files (the "Software"), to deal 5 | * in the Software without restriction, including without limitation the rights 6 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | * copies of the Software, and to permit persons to whom the Software is 8 | * furnished to do so, subject to the following conditions: 9 | * 10 | * The above copyright notice and this permission notice shall be included in 11 | * all copies or substantial portions of the Software. 12 | * 13 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 19 | * SOFTWARE. 20 | */ 21 | 22 | #ifndef XMODEL_H 23 | #define XMODEL_H 24 | 25 | #include 26 | 27 | class XModel : public QAbstractItemModel { 28 | Q_OBJECT 29 | 30 | public: 31 | enum SORT_METHOD { 32 | SORT_METHOD_DEFAULT, 33 | SORT_METHOD_HEX, 34 | }; 35 | 36 | enum USERROLE { 37 | USERROLE_ORIGINDEX = 0, 38 | USERROLE_SIZE, 39 | USERROLE_OFFSET, 40 | USERROLE_ADDRESS, 41 | USERROLE_STRING1, 42 | USERROLE_STRING2 43 | }; 44 | 45 | explicit XModel(QObject *pParent); 46 | virtual ~XModel() override; 47 | 48 | void setColumnSymbolSize(qint32 nColumn, qint32 nValue); 49 | qint32 getColumnSymbolSize(qint32 nColumn) const; 50 | void setColumnAlignment(qint32 nColumn, qint32 flag); 51 | qint32 getColumnAlignment(qint32 nColumn) const; 52 | void setColumnName(qint32 nColumn, const QString &sName); 53 | QString getColumnName(qint32 nColumn) const; 54 | virtual SORT_METHOD getSortMethod(qint32 nColumn); 55 | virtual bool isCustomFilter(); 56 | virtual bool isCustomSort(); 57 | void setRowHidden(qint32 nRow, bool bState); 58 | void setRowPrio(qint32 nRow, quint64 nPrio); 59 | bool isRowHidden(qint32 nRow); 60 | quint64 getRowPrio(qint32 nRow); 61 | virtual QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const override; 62 | virtual QModelIndex parent(const QModelIndex &child) const override; 63 | void _setRowCount(qint32 nRowCount); 64 | void _setColumnCount(qint32 nColumnCount); 65 | virtual int rowCount(const QModelIndex &parent = QModelIndex()) const override; 66 | virtual int columnCount(const QModelIndex &parent = QModelIndex()) const override; 67 | 68 | void adjustColumnToContent(qint32 nColumn, bool bHeader); 69 | void adjustColumnsToContent(bool bHeader); 70 | 71 | private: 72 | QHash m_hashRowHidden; 73 | QHash m_hashRowPrio; 74 | QHash m_hashColumnSymbolSize; 75 | QHash m_hashColumnAlignment; 76 | QHash m_hashColumnName; 77 | qint32 m_nRowCount; 78 | qint32 m_nColumnCount; 79 | }; 80 | 81 | #endif // XMODEL_H 82 | -------------------------------------------------------------------------------- /xbinaryview.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2019-2025 hors 2 | * 3 | * Permission is hereby granted, free of charge, to any person obtaining a copy 4 | * of this software and associated documentation files (the "Software"), to deal 5 | * in the Software without restriction, including without limitation the rights 6 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | * copies of the Software, and to permit persons to whom the Software is 8 | * furnished to do so, subject to the following conditions: 9 | * 10 | * The above copyright notice and this permission notice shall be included in all 11 | * copies or substantial portions of the Software. 12 | * 13 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 19 | * SOFTWARE. 20 | */ 21 | #ifndef XBINARYVIEW_H 22 | #define XBINARYVIEW_H 23 | 24 | #include "xbinary.h" 25 | #include "xoptions.h" 26 | #include "xinfodb.h" 27 | #include "xcapstone.h" 28 | 29 | class XBinaryView : public QObject { 30 | Q_OBJECT 31 | 32 | public: 33 | enum LOCMODE { 34 | LOCMODE_OFFSET = 0, 35 | LOCMODE_ADDRESS, 36 | LOCMODE_RELADDRESS, 37 | LOCMODE_THIS 38 | }; 39 | 40 | struct OPTIONS { 41 | qint64 nStartOffset; 42 | qint64 nTotalSize; 43 | XADDR nInitAddress; 44 | XADDR nEntryPointAddress; // TODO move to xdb todo use bool 45 | XBinary::FT fileType; 46 | XBinary::DM disasmMode; 47 | bool bAprox; 48 | bool bMenu_Hex; 49 | bool bMenu_Disasm; 50 | bool bMenu_MemoryMap; 51 | bool bMenu_MainHex; 52 | bool bHideReadOnly; 53 | bool bIsImage; 54 | XADDR nModuleAddress; 55 | bool bShowVirtual; 56 | qint64 nStartSelectionOffset; // -1 no selection 57 | qint64 nSizeOfSelection; // TODO Check 58 | QString sTitle; // For dialogs 59 | LOCMODE addressMode; 60 | }; 61 | 62 | struct VIEWSTRUCT { 63 | XVPOS nViewPos; 64 | XADDR nAddress; 65 | qint64 nOffset; 66 | qint64 nSize; 67 | }; 68 | 69 | explicit XBinaryView(QObject *pParent = nullptr); 70 | virtual ~XBinaryView(); 71 | 72 | void setData(QIODevice *pDevice, const OPTIONS &options); 73 | void reset(); 74 | QIODevice *getDevice(); 75 | 76 | XVPOS deviceOffsetToViewPos(qint64 nOffset); 77 | qint64 viewPosToDeviceOffset(XVPOS nViewPos); 78 | XADDR viewPosToAddress(XVPOS nViewPos); 79 | bool isViewPosValid(XVPOS nViewPos); 80 | bool isEnd(XVPOS nViewPos); 81 | qint64 getViewSizeByViewPos(XVPOS nViewPos); 82 | XVPOS addressToViewPos(XADDR nAddress); 83 | XVPOS locationToViewPos(XADDR nLocation, XBinary::LT locationType); 84 | VIEWSTRUCT _getViewStructByOffset(qint64 nOffset); 85 | VIEWSTRUCT _getViewStructByAddress(XADDR nAddress); 86 | // VIEWSTRUCT _getViewStructByScroll(qint64 nValue); 87 | VIEWSTRUCT _getViewStructByViewPos(XVPOS nViewPos); 88 | 89 | qint64 getViewSize(); 90 | XBinary::_MEMORY_MAP *getMemoryMap(); 91 | XDisasmCore *getDisasmCore(); 92 | OPTIONS *getOptions(); 93 | 94 | private: 95 | QIODevice *m_pDevice; 96 | QList m_listViewStruct; 97 | XDisasmCore m_disasmCore; 98 | XBinary::_MEMORY_MAP m_memoryMap; 99 | OPTIONS m_options; 100 | qint64 m_nViewSize; 101 | }; 102 | 103 | #endif // XBINARYVIEW_H 104 | -------------------------------------------------------------------------------- /xdevicetableeditview.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2020-2025 hors 2 | * 3 | * Permission is hereby granted, free of charge, to any person obtaining a copy 4 | * of this software and associated documentation files (the "Software"), to deal 5 | * in the Software without restriction, including without limitation the rights 6 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | * copies of the Software, and to permit persons to whom the Software is 8 | * furnished to do so, subject to the following conditions: 9 | * 10 | * The above copyright notice and this permission notice shall be included in 11 | * all copies or substantial portions of the Software. 12 | * 13 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 19 | * SOFTWARE. 20 | */ 21 | #ifndef XDEVICETABLEEDITVIEW_H 22 | #define XDEVICETABLEEDITVIEW_H 23 | 24 | #include "dialoghexedit.h" 25 | #include "dialogsearchstrings.h" 26 | #include "xdevicetableview.h" 27 | #if defined(QT_SCRIPT_LIB) || defined(QT_QML_LIB) 28 | #include "dialogdiehexviewer.h" 29 | #endif 30 | #include "dialogdatainspector.h" 31 | #include "dialogxdataconvertor.h" 32 | #include "dialogshowdata.h" 33 | #include "dumpprocess.h" 34 | #include "xdialogprocess.h" 35 | #include "dialogresize.h" 36 | #include "dialogremove.h" 37 | #include "dialogsearchvalues.h" 38 | #include "dialogvisualization.h" 39 | #include "dialogbookmarks.h" 40 | 41 | class XDeviceTableEditView : public XDeviceTableView { 42 | Q_OBJECT 43 | 44 | public: 45 | struct HIGHLIGHTREGION { 46 | bool bIsValid; 47 | quint64 nLocation; 48 | XBinary::LT locationType; 49 | qint64 nSize; 50 | QColor colText; 51 | QColor colBackground; 52 | QColor colBackgroundSelected; 53 | QString sComment; 54 | }; 55 | 56 | enum VIEWWIDGET { 57 | VIEWWIDGET_DATAINSPECTOR, 58 | VIEWWIDGET_DATACONVERTOR, 59 | VIEWWIDGET_MULTISEARCH, 60 | VIEWWIDGET_BOOKMARKS, 61 | VIEWWIDGET_STRINGS, 62 | VIEWWIDGET_VISUALIZATION, 63 | #if defined(QT_SCRIPT_LIB) || defined(QT_QML_LIB) 64 | VIEWWIDGET_SCRIPTS, 65 | #endif 66 | }; 67 | 68 | XDeviceTableEditView(QWidget *pParent = nullptr); 69 | 70 | static QList _convertBookmarksToHighlightRegion(QVector *pList); 71 | static QList getHighlightRegion(QList *pList, quint64 nLocation, XBinary::LT locationType); 72 | 73 | void setViewWidgetState(VIEWWIDGET viewWidget, bool bState); 74 | bool getViewWidgetState(VIEWWIDGET viewWidget); 75 | void dumpMemory(const QString &sDumpName, qint64 nOffset = 0, qint64 nSize = -1); 76 | 77 | public slots: 78 | void _editHex(); 79 | void _editPatch(); 80 | void _editRemove(); 81 | void _editResize(); 82 | void _strings(); 83 | void _visualization(); 84 | void _dataInspector(); 85 | void _dataConvertor(); 86 | void _multisearch(); 87 | void _bookmarkNew(); 88 | void _bookmarkList(); 89 | void _copyDataSlot(); 90 | void _dumpToFileSlot(); 91 | void _hexSignatureSlot(); 92 | #if defined(QT_SCRIPT_LIB) || defined(QT_QML_LIB) 93 | void _scripts(); 94 | #endif 95 | 96 | signals: 97 | void viewWidgetsStateChanged(); 98 | void closeWidget_DataInspector(); 99 | void closeWidget_DataConvertor(); 100 | void closeWidget_Multisearch(); 101 | void closeWidget_Strings(); 102 | void closeWidget_Visualization(); 103 | void closeWidget_Bookmarks(); 104 | #if defined(QT_SCRIPT_LIB) || defined(QT_QML_LIB) 105 | void closeWidget_Scripts(); 106 | #endif 107 | 108 | private: 109 | QSet m_stViewWidgetState; 110 | }; 111 | 112 | #endif // XDEVICETABLEEDITVIEW_H 113 | -------------------------------------------------------------------------------- /xsortfilterproxymodel.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2024-2025 hors 2 | * 3 | * Permission is hereby granted, free of charge, to any person obtaining a copy 4 | * of this software and associated documentation files (the "Software"), to deal 5 | * in the Software without restriction, including without limitation the rights 6 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | * copies of the Software, and to permit persons to whom the Software is 8 | * furnished to do so, subject to the following conditions: 9 | * 10 | * The above copyright notice and this permission notice shall be included in 11 | * all copies or substantial portions of the Software. 12 | * 13 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 19 | * SOFTWARE. 20 | */ 21 | 22 | #include "xsortfilterproxymodel.h" 23 | 24 | XSortFilterProxyModel::XSortFilterProxyModel(QObject *pParent) : QSortFilterProxyModel(pParent) 25 | { 26 | m_bIsXmodel = false; 27 | m_bIsCustomFilter = false; 28 | m_bIsCustomSort = false; 29 | m_pXModel = nullptr; 30 | } 31 | 32 | void XSortFilterProxyModel::setFilters(const QList &listFilters) 33 | { 34 | m_listFilters = listFilters; 35 | } 36 | 37 | void XSortFilterProxyModel::setSortMethod(qint32 nColumn, XModel::SORT_METHOD sortMethod) 38 | { 39 | m_mapSortMethods.insert(nColumn, sortMethod); 40 | } 41 | 42 | void XSortFilterProxyModel::setSourceModel(QAbstractItemModel *sourceModel) 43 | { 44 | m_listFilters.clear(); 45 | 46 | m_pXModel = dynamic_cast(sourceModel); 47 | 48 | if (m_pXModel) { 49 | qint32 nNumberOfColumns = m_pXModel->columnCount(); 50 | 51 | for (qint32 i = 0; i < nNumberOfColumns; i++) { 52 | XModel::SORT_METHOD sortMethod = m_pXModel->getSortMethod(i); 53 | 54 | setSortMethod(i, sortMethod); 55 | } 56 | 57 | m_bIsXmodel = true; 58 | m_bIsCustomFilter = m_pXModel->isCustomFilter(); 59 | m_bIsCustomSort = m_pXModel->isCustomSort(); 60 | } else { 61 | m_bIsXmodel = false; 62 | m_bIsCustomFilter = false; 63 | m_bIsCustomSort = false; 64 | } 65 | 66 | QSortFilterProxyModel::setSourceModel(sourceModel); 67 | } 68 | 69 | QVariant XSortFilterProxyModel::data(const QModelIndex &index, int nRole) const 70 | { 71 | return QSortFilterProxyModel::data(index, nRole); 72 | } 73 | 74 | void XSortFilterProxyModel::sort(int column, Qt::SortOrder order) 75 | { 76 | QSortFilterProxyModel::sort(column, order); 77 | } 78 | 79 | bool XSortFilterProxyModel::filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const 80 | { 81 | bool bResult = true; 82 | 83 | if (m_bIsCustomFilter) { 84 | bResult = !(m_pXModel->isRowHidden(sourceRow)); 85 | } else { 86 | qint32 nCount = m_listFilters.count(); 87 | 88 | for (qint32 i = 0; i < nCount; i++) { 89 | QString sFilter = m_listFilters.at(i); 90 | if (sFilter != "") { 91 | QModelIndex index = sourceModel()->index(sourceRow, i, sourceParent); 92 | 93 | if (index.isValid()) { 94 | QString sValue = sourceModel()->data(index).toString(); 95 | 96 | if (!sValue.contains(sFilter, Qt::CaseInsensitive)) { 97 | bResult = false; 98 | break; 99 | } 100 | } 101 | } 102 | } 103 | } 104 | 105 | return bResult; 106 | } 107 | 108 | bool XSortFilterProxyModel::lessThan(const QModelIndex &left, const QModelIndex &right) const 109 | { 110 | bool bResult = false; 111 | 112 | if (m_bIsCustomSort) { 113 | bResult = (m_pXModel->getRowPrio(left.row()) < m_pXModel->getRowPrio(right.row())); 114 | } else { 115 | qint32 nColumn = left.column(); 116 | 117 | XModel::SORT_METHOD sortMethod = m_mapSortMethods.value(nColumn, XModel::SORT_METHOD_DEFAULT); 118 | 119 | if (sortMethod == XModel::SORT_METHOD_HEX) { 120 | QString sLeft = left.data().toString(); 121 | QString sRight = right.data().toString(); 122 | 123 | sLeft = sLeft.remove(" "); 124 | sRight = sRight.remove(" "); 125 | 126 | bResult = sLeft.toULongLong(0, 16) < sRight.toULongLong(0, 16); 127 | } else { 128 | bResult = QSortFilterProxyModel::lessThan(left, right); 129 | } 130 | } 131 | 132 | return bResult; 133 | } 134 | -------------------------------------------------------------------------------- /xmodel_hex.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2025 hors 2 | * 3 | * Permission is hereby granted, free of charge, to any person obtaining a copy 4 | * of this software and associated documentation files (the "Software"), to deal 5 | * in the Software without restriction, including without limitation the rights 6 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | * copies of the Software, and to permit persons to whom the Software is 8 | * furnished to do so, subject to the following conditions: 9 | * 10 | * The above copyright notice and this permission notice shall be included in 11 | * all copies or substantial portions of the Software. 12 | * 13 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 19 | * SOFTWARE. 20 | */ 21 | #include "xmodel_hex.h" 22 | 23 | #include 24 | 25 | XModel_Hex::XModel_Hex(QIODevice *pDevice, qint64 nOffset, qint64 nSize, quint64 nStartAddress, qint32 nBytesPerLine, QObject *pParent) 26 | : XModel(pParent), m_pDevice(pDevice), m_nOffset(nOffset), m_nSize(nSize), m_nStartAddress(nStartAddress), m_nBytesPerLine(nBytesPerLine) 27 | { 28 | if (!m_pDevice) { 29 | _setRowCount(0); 30 | _setColumnCount(0); 31 | return; 32 | } 33 | 34 | if (m_nSize < 0) { 35 | m_nSize = m_pDevice->size() - m_nOffset; 36 | if (m_nSize < 0) m_nSize = 0; 37 | } 38 | 39 | if (m_nBytesPerLine <= 0) m_nBytesPerLine = 16; 40 | 41 | qint32 rows = (qint32)((m_nSize + m_nBytesPerLine - 1) / m_nBytesPerLine); 42 | _setRowCount(rows); 43 | _setColumnCount(__COLUMN_COUNT); 44 | 45 | setColumnName(COLUMN_ADDRESS, QObject::tr("Address")); 46 | setColumnName(COLUMN_HEX, QObject::tr("Hex")); 47 | setColumnName(COLUMN_ASCII, QObject::tr("ASCII")); 48 | 49 | setColumnAlignment(COLUMN_ADDRESS, Qt::AlignVCenter | Qt::AlignRight); 50 | setColumnAlignment(COLUMN_HEX, Qt::AlignVCenter | Qt::AlignLeft); 51 | setColumnAlignment(COLUMN_ASCII, Qt::AlignVCenter | Qt::AlignLeft); 52 | } 53 | 54 | QVariant XModel_Hex::data(const QModelIndex &index, int nRole) const 55 | { 56 | QVariant result; 57 | 58 | if (!index.isValid()) return result; 59 | 60 | int row = index.row(); 61 | int column = index.column(); 62 | 63 | if (nRole == Qt::DisplayRole) { 64 | qint64 lineOffset = m_nOffset + (qint64)row * m_nBytesPerLine; 65 | int bytesThisLine = (int)qMin(m_nBytesPerLine, m_nSize - (row * (qint64)m_nBytesPerLine)); 66 | if (bytesThisLine < 0) bytesThisLine = 0; 67 | 68 | if (!m_pDevice->isSequential()) { 69 | qint64 prev = m_pDevice->pos(); 70 | m_pDevice->seek(lineOffset); 71 | QByteArray chunk = m_pDevice->read(bytesThisLine); 72 | m_pDevice->seek(prev); 73 | 74 | if (column == COLUMN_ADDRESS) { 75 | result = QString::number((qulonglong)(m_nStartAddress + (quint64)(row * m_nBytesPerLine)), 16).rightJustified(8, '0'); 76 | } else if (column == COLUMN_HEX) { 77 | result = _bytesToHex(chunk); 78 | } else if (column == COLUMN_ASCII) { 79 | result = _bytesToAscii(chunk); 80 | } 81 | } 82 | } else if (nRole == Qt::TextAlignmentRole) { 83 | result = getColumnAlignment(column); 84 | } 85 | 86 | return result; 87 | } 88 | 89 | QVariant XModel_Hex::headerData(int nSection, Qt::Orientation orientation, int nRole) const 90 | { 91 | QVariant result; 92 | 93 | if (orientation == Qt::Horizontal) { 94 | if (nRole == Qt::DisplayRole) { 95 | result = getColumnName(nSection); 96 | } else if (nRole == Qt::TextAlignmentRole) { 97 | result = getColumnAlignment(nSection); 98 | } 99 | } 100 | 101 | return result; 102 | } 103 | 104 | QString XModel_Hex::_bytesToHex(const QByteArray &ba) const 105 | { 106 | QString s; 107 | s.reserve(ba.size() * 3); 108 | for (int i = 0; i < ba.size(); ++i) { 109 | unsigned char c = (unsigned char)ba.at(i); 110 | s.append(QString::number(c, 16).rightJustified(2, '0')); 111 | if (i + 1 < ba.size()) s.append(' '); 112 | } 113 | return s; 114 | } 115 | 116 | QString XModel_Hex::_bytesToAscii(const QByteArray &ba) const 117 | { 118 | QString s; 119 | s.reserve(ba.size()); 120 | for (int i = 0; i < ba.size(); ++i) { 121 | unsigned char c = (unsigned char)ba.at(i); 122 | if (c >= 0x20 && c <= 0x7E) s.append(QChar(c)); 123 | else s.append('.'); 124 | } 125 | return s; 126 | } 127 | -------------------------------------------------------------------------------- /xmodel.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2025 hors 2 | * 3 | * Permission is hereby granted, free of charge, to any person obtaining a copy 4 | * of this software and associated documentation files (the "Software"), to deal 5 | * in the Software without restriction, including without limitation the rights 6 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | * copies of the Software, and to permit persons to whom the Software is 8 | * furnished to do so, subject to the following conditions: 9 | * 10 | * The above copyright notice and this permission notice shall be included in 11 | * all copies or substantial portions of the Software. 12 | * 13 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 19 | * SOFTWARE. 20 | */ 21 | 22 | #include "xmodel.h" 23 | 24 | XModel::XModel(QObject *pParent) : QAbstractItemModel(pParent) 25 | { 26 | m_nRowCount = 0; 27 | m_nColumnCount = 0; 28 | } 29 | 30 | XModel::~XModel() 31 | { 32 | } 33 | 34 | void XModel::setColumnSymbolSize(qint32 nColumn, qint32 nValue) 35 | { 36 | m_hashColumnSymbolSize[nColumn] = nValue; // TODO optimize use allocated memory 37 | } 38 | 39 | qint32 XModel::getColumnSymbolSize(qint32 nColumn) const 40 | { 41 | return m_hashColumnSymbolSize.value(nColumn, 40); 42 | } 43 | 44 | void XModel::setColumnAlignment(qint32 nColumn, qint32 flag) 45 | { 46 | m_hashColumnAlignment[nColumn] = flag; // TODO optimize use allocated memory 47 | } 48 | 49 | qint32 XModel::getColumnAlignment(qint32 nColumn) const 50 | { 51 | return m_hashColumnAlignment.value(nColumn, Qt::AlignVCenter | Qt::AlignLeft); 52 | } 53 | 54 | void XModel::setColumnName(qint32 nColumn, const QString &sName) 55 | { 56 | m_hashColumnName[nColumn] = sName; // TODO optimize use allocated memory 57 | } 58 | 59 | QString XModel::getColumnName(qint32 nColumn) const 60 | { 61 | return m_hashColumnName.value(nColumn, ""); 62 | } 63 | 64 | bool XModel::isCustomFilter() 65 | { 66 | return false; 67 | } 68 | 69 | bool XModel::isCustomSort() 70 | { 71 | return false; 72 | } 73 | 74 | void XModel::setRowHidden(qint32 nRow, bool bState) 75 | { 76 | m_hashRowHidden[nRow] = bState; // TODO optimize use allocated memory 77 | } 78 | 79 | void XModel::setRowPrio(qint32 nRow, quint64 nPrio) 80 | { 81 | m_hashRowPrio[nRow] = nPrio; 82 | } 83 | 84 | bool XModel::isRowHidden(qint32 nRow) 85 | { 86 | return m_hashRowHidden.value(nRow, false); 87 | } 88 | 89 | quint64 XModel::getRowPrio(qint32 nRow) 90 | { 91 | return m_hashRowPrio.value(nRow, 0); 92 | } 93 | 94 | QModelIndex XModel::index(int row, int column, const QModelIndex &parent) const 95 | { 96 | QModelIndex result; 97 | 98 | if (hasIndex(row, column, parent)) { 99 | result = createIndex(row, column); 100 | } 101 | 102 | return result; 103 | } 104 | 105 | QModelIndex XModel::parent(const QModelIndex &child) const 106 | { 107 | Q_UNUSED(child) 108 | 109 | return QModelIndex(); 110 | } 111 | 112 | void XModel::_setRowCount(qint32 nRowCount) 113 | { 114 | m_nRowCount = nRowCount; 115 | } 116 | 117 | void XModel::_setColumnCount(qint32 nColumnCount) 118 | { 119 | m_nColumnCount = nColumnCount; 120 | } 121 | 122 | int XModel::rowCount(const QModelIndex &parent) const 123 | { 124 | Q_UNUSED(parent) 125 | 126 | return m_nRowCount; 127 | } 128 | 129 | int XModel::columnCount(const QModelIndex &parent) const 130 | { 131 | Q_UNUSED(parent) 132 | 133 | return m_nColumnCount; 134 | } 135 | 136 | void XModel::adjustColumnToContent(qint32 nColumn, bool bHeader) 137 | { 138 | qint32 nSymbolSize = 0; 139 | 140 | if (bHeader) { 141 | nSymbolSize = qMax(nSymbolSize, headerData(nColumn, Qt::Horizontal).toString().length()); 142 | } 143 | 144 | qint32 nNumberOfRows = rowCount(); 145 | 146 | for (qint32 i = 0; i < nNumberOfRows; i++) { 147 | QModelIndex index = this->index(i, nColumn); 148 | QString sData = data(index, Qt::DisplayRole).toString(); 149 | 150 | nSymbolSize = qMax(nSymbolSize, sData.length()); 151 | } 152 | 153 | setColumnSymbolSize(nColumn, nSymbolSize); 154 | } 155 | 156 | void XModel::adjustColumnsToContent(bool bHeader) 157 | { 158 | qint32 nNumberOfColumns = columnCount(); 159 | 160 | for (qint32 i = 0; i < nNumberOfColumns; i++) { 161 | adjustColumnToContent(i, bHeader); 162 | } 163 | } 164 | 165 | XModel::SORT_METHOD XModel::getSortMethod(qint32 nColumn) 166 | { 167 | Q_UNUSED(nColumn) 168 | 169 | return SORT_METHOD_DEFAULT; 170 | } 171 | -------------------------------------------------------------------------------- /xlineedithex.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2017-2025 hors 2 | * 3 | * Permission is hereby granted, free of charge, to any person obtaining a copy 4 | * of this software and associated documentation files (the "Software"), to deal 5 | * in the Software without restriction, including without limitation the rights 6 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | * copies of the Software, and to permit persons to whom the Software is 8 | * furnished to do so, subject to the following conditions: 9 | * 10 | * The above copyright notice and this permission notice shall be included in 11 | * all copies or substantial portions of the Software. 12 | * 13 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 19 | * SOFTWARE. 20 | */ 21 | #ifndef XLINEEDITHEX_H 22 | #define XLINEEDITHEX_H 23 | 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include 31 | 32 | #include "xlineeditvalidator.h" 33 | #include "dialogbits8.h" 34 | 35 | // TODO setMode 36 | class XLineEditHEX : public QLineEdit { 37 | Q_OBJECT 38 | 39 | public: 40 | // struct OPTIONS { 41 | // bool bDemangle; // TODO Check 42 | // bool bShowHexAddress; // TODO Check 43 | // bool bShowHexOffset; // TODO Check 44 | // bool bShowHexRelAddress; // TODO Check 45 | // bool bShowDisasmAddress; // TODO Check 46 | // bool bShowDisasmOffset; // TODO Check 47 | // bool bShowDisasmRelAddress; // TODO Check 48 | // }; 49 | 50 | enum _MODE { 51 | _MODE_UNKNOWN = 0, 52 | _MODE_TEXT, 53 | _MODE_UUID, 54 | _MODE_SIZE, 55 | _MODE_DOUBLE, 56 | _MODE_HEX, 57 | _MODE_DEC, 58 | _MODE_SIGN_DEC, 59 | _MODE_BIN 60 | // TODO more 61 | }; 62 | 63 | explicit XLineEditHEX(QWidget *pParent = nullptr); 64 | 65 | void setValue_uint8(quint8 nValue, _MODE mode = _MODE_HEX); 66 | void setValue_int8(qint8 nValue, _MODE mode = _MODE_HEX); 67 | void setValue_uint16(quint16 nValue, _MODE mode = _MODE_HEX); 68 | void setValue_int16(qint16 nValue, _MODE mode = _MODE_HEX); 69 | void setValue_uint32(quint32 nValue, _MODE mode = _MODE_HEX); 70 | void setValue_int32(qint32 nValue, _MODE mode = _MODE_HEX); 71 | void setValue_uint64(quint64 nValue, _MODE mode = _MODE_HEX); 72 | void setValue_int64(qint64 nValue, _MODE mode = _MODE_HEX); 73 | void setValidatorModeValue(XLineEditValidator::MODE mode, QVariant varValue); 74 | void setMode(_MODE mode); 75 | // void setValueOS(quint64 nValue, HEXValidator::MODE validatorMode = HEXValidator::MODE_HEX); 76 | void setValue32_64(quint64 nValue, _MODE mode = _MODE_HEX); 77 | void setValue_String(const QString &sText, qint32 nMaxLength = 0); 78 | void setValue_UUID(const QString &sText); 79 | void setValue_double(double dValue); 80 | void setValue_Variant(const QVariant &variant); 81 | // quint64 getIntValue(); 82 | // qint64 getSignValue(); 83 | QVariant _getValue(); 84 | 85 | void setMaxValue(qint64 nValue); 86 | 87 | quint8 getValue_uint8(); 88 | qint8 getValue_int8(); 89 | quint16 getValue_uint16(); 90 | qint16 getValue_int16(); 91 | quint32 getValue_uint32(); 92 | qint32 getValue_int32(); 93 | quint64 getValue_uint64(); 94 | qint64 getValue_int64(); 95 | 96 | // static MODE getModeFromValue(quint64 nValue); 97 | static QString getFormatString(XLineEditValidator::MODE mode, qint64 nValue); 98 | static qint32 getWidthFromMode(QWidget *pWidget, XLineEditValidator::MODE mode); 99 | static qint32 getSymbolWidth(QWidget *pWidget); 100 | void setColon(bool bIsColon); 101 | bool isFocused(); 102 | void setValidatorMode(XLineEditValidator::MODE validatorMode); 103 | XLineEditValidator::MODE getValidatorMode(); 104 | 105 | protected: 106 | // void keyPressEvent(QKeyEvent* keyEvent); 107 | bool eventFilter(QObject *pObject, QEvent *pEvent); 108 | 109 | private slots: 110 | void _setText(const QString &sText); 111 | void _returnPressed(); 112 | void customContextMenu(const QPoint &nPos); 113 | void updateFont(); 114 | 115 | public slots: 116 | void _copy(); 117 | void _copyValue(); 118 | void _copySignValue(); 119 | void _clearValue(); 120 | void _bits(); 121 | 122 | signals: 123 | void valueChanged(QVariant varValue); 124 | void focused(bool bState); 125 | 126 | private: 127 | QVariant m_vValue; 128 | XLineEditValidator m_validator; 129 | bool m_bIsColon; 130 | bool m_bIsFocused; 131 | _MODE m_mode; 132 | }; 133 | 134 | #define PXLineEditHEX XLineEditHEX * 135 | 136 | #endif // XLINEEDITHEX_H 137 | -------------------------------------------------------------------------------- /xheaderview.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2024-2025 hors 2 | * 3 | * Permission is hereby granted, free of charge, to any person obtaining a copy 4 | * of this software and associated documentation files (the "Software"), to deal 5 | * in the Software without restriction, including without limitation the rights 6 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | * copies of the Software, and to permit persons to whom the Software is 8 | * furnished to do so, subject to the following conditions: 9 | * 10 | * The above copyright notice and this permission notice shall be included in 11 | * all copies or substantial portions of the Software. 12 | * 13 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 19 | * SOFTWARE. 20 | */ 21 | #include "xheaderview.h" 22 | 23 | XHeaderView::XHeaderView(QWidget *pParent) : QHeaderView(Qt::Horizontal, pParent) 24 | { 25 | connect(this, SIGNAL(sectionResized(int, int, int)), this, SLOT(onSectionResized(int, int, int))); 26 | connect(this, SIGNAL(sectionClicked(int)), this, SLOT(onSectionClicked(int))); 27 | 28 | setSectionsClickable(true); 29 | } 30 | 31 | XHeaderView::~XHeaderView() 32 | { 33 | qint32 nCount = m_listLineEdits.count(); 34 | 35 | for (qint32 i = 0; i < nCount; i++) { 36 | delete m_listLineEdits.at(i); 37 | } 38 | 39 | m_listLineEdits.clear(); 40 | } 41 | 42 | QSize XHeaderView::sizeHint() const 43 | { 44 | QSize baseSize = QHeaderView::sizeHint(); 45 | 46 | if (m_listLineEdits.count()) { 47 | baseSize.setHeight(baseSize.height() + 4 + m_listLineEdits.at(0)->sizeHint().height()); 48 | } 49 | 50 | return baseSize; 51 | } 52 | 53 | void XHeaderView::setNumberOfFilters(qint32 nNumberOfFilters) 54 | { 55 | qint32 nOldCount = m_listLineEdits.count(); 56 | 57 | for (qint32 i = 0; i < nOldCount; i++) { 58 | delete m_listLineEdits.at(i); 59 | } 60 | 61 | m_listLineEdits.clear(); 62 | 63 | for (qint32 i = 0; i < nNumberOfFilters; i++) { 64 | QLineEdit *pLineEdit = new QLineEdit(this); 65 | pLineEdit->setPlaceholderText(tr("Filter")); 66 | pLineEdit->setToolTip(tr("Filter")); 67 | connect(pLineEdit, SIGNAL(textChanged(QString)), this, SLOT(_textChanged(QString))); 68 | m_listLineEdits.append(pLineEdit); 69 | } 70 | 71 | adjustPositions(); 72 | } 73 | 74 | void XHeaderView::clearFilters() 75 | { 76 | qint32 nCount = m_listLineEdits.count(); 77 | 78 | for (qint32 i = 0; i < nCount; i++) { 79 | m_listLineEdits.at(i)->clear(); 80 | } 81 | } 82 | 83 | void XHeaderView::updateGeometries() 84 | { 85 | if (m_listLineEdits.count()) { 86 | qint32 nLineEditHeight = m_listLineEdits.at(0)->sizeHint().height(); 87 | setViewportMargins(0, 0, 0, nLineEditHeight + 4); 88 | } else { 89 | setViewportMargins(0, 0, 0, 0); 90 | } 91 | 92 | QHeaderView::updateGeometries(); 93 | adjustPositions(); 94 | } 95 | 96 | void XHeaderView::adjustPositions() 97 | { 98 | qint32 nCount = m_listLineEdits.count(); 99 | 100 | QSize baseSize = QHeaderView::sizeHint(); 101 | 102 | for (qint32 i = 0; i < nCount; i++) { 103 | qint32 nLineEditHeight = m_listLineEdits.at(i)->sizeHint().height(); 104 | 105 | m_listLineEdits.at(i)->move(sectionPosition(i) - offset(), baseSize.height() + 2); 106 | m_listLineEdits.at(i)->resize(sectionSize(i) - 2, nLineEditHeight); 107 | m_listLineEdits.at(i)->show(); 108 | } 109 | } 110 | 111 | QList XHeaderView::getFilters() 112 | { 113 | QList listResult; 114 | 115 | qint32 nCount = m_listLineEdits.count(); 116 | 117 | for (qint32 i = 0; i < nCount; i++) { 118 | listResult.append(m_listLineEdits.at(i)->text()); 119 | } 120 | 121 | return listResult; 122 | } 123 | 124 | void XHeaderView::setFilterEnabled(qint32 nColumn, bool bFilterEnabled) 125 | { 126 | // TODO 127 | if ((nColumn >= 0) && (nColumn < m_listLineEdits.count())) { 128 | m_listLineEdits.at(nColumn)->setReadOnly(!bFilterEnabled); 129 | } 130 | } 131 | 132 | void XHeaderView::_textChanged(const QString &sText) 133 | { 134 | Q_UNUSED(sText) 135 | 136 | emit filterChanged(); 137 | } 138 | 139 | void XHeaderView::onSectionResized(int i, int nOldSize, int nNewSize) 140 | { 141 | Q_UNUSED(i) 142 | Q_UNUSED(nOldSize) 143 | Q_UNUSED(nNewSize) 144 | 145 | adjustPositions(); 146 | } 147 | 148 | void XHeaderView::onSectionClicked(int logicalIndex) 149 | { 150 | Qt::SortOrder sortOrder = sortIndicatorOrder(); 151 | 152 | if (sortIndicatorSection() == logicalIndex) { 153 | sortOrder = (sortOrder == Qt::AscendingOrder) ? Qt::DescendingOrder : Qt::AscendingOrder; 154 | } else { 155 | sortOrder = Qt::AscendingOrder; 156 | } 157 | 158 | emit sortIndicatorChanged(logicalIndex, sortOrder); 159 | } 160 | -------------------------------------------------------------------------------- /xmodel_streams.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2025 hors 2 | * 3 | * Permission is hereby granted, free of charge, to any person obtaining a copy 4 | * of this software and associated documentation files (the "Software"), to deal 5 | * in the Software without restriction, including without limitation the rights 6 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | * copies of the Software, and to permit persons to do so, subject to the 8 | * following conditions: 9 | * 10 | * The above copyright notice and this permission notice shall be included in 11 | * all copies or substantial portions of the Software. 12 | * 13 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 19 | * SOFTWARE. 20 | */ 21 | #include "xmodel_streams.h" 22 | 23 | XModel_Streams::XModel_Streams(QList *pListFParts, QObject *pParent) : XModel(pParent) 24 | { 25 | m_pListFParts = pListFParts; 26 | if (pListFParts) { 27 | _setRowCount(pListFParts->count()); 28 | } else { 29 | _setRowCount(0); 30 | } 31 | _setColumnCount(__COLUMN_COUNT); 32 | _initColumns(); 33 | } 34 | 35 | void XModel_Streams::_initColumns() 36 | { 37 | setColumnName(COLUMN_NAME, QObject::tr("Name")); 38 | setColumnName(COLUMN_OFFSET, QObject::tr("Offset")); 39 | setColumnName(COLUMN_SIZE, QObject::tr("Size")); 40 | setColumnName(COLUMN_COMPRESSMETHOD, QObject::tr("Compress")); 41 | setColumnName(COLUMN_UNCOMPRESSEDSIZE, QObject::tr("U.Size")); 42 | 43 | setColumnAlignment(COLUMN_NAME, Qt::AlignVCenter | Qt::AlignLeft); 44 | setColumnAlignment(COLUMN_OFFSET, Qt::AlignVCenter | Qt::AlignRight); 45 | setColumnAlignment(COLUMN_SIZE, Qt::AlignVCenter | Qt::AlignRight); 46 | setColumnAlignment(COLUMN_COMPRESSMETHOD, Qt::AlignVCenter | Qt::AlignLeft); 47 | setColumnAlignment(COLUMN_UNCOMPRESSEDSIZE, Qt::AlignVCenter | Qt::AlignRight); 48 | 49 | setColumnSymbolSize(COLUMN_NAME, 20); 50 | setColumnSymbolSize(COLUMN_OFFSET, 16); 51 | setColumnSymbolSize(COLUMN_SIZE, 16); 52 | setColumnSymbolSize(COLUMN_COMPRESSMETHOD, 10); 53 | setColumnSymbolSize(COLUMN_UNCOMPRESSEDSIZE, 16); 54 | } 55 | 56 | QVariant XModel_Streams::data(const QModelIndex &index, int nRole) const 57 | { 58 | QVariant result; 59 | 60 | if (!m_pListFParts) { 61 | return result; 62 | } 63 | 64 | if (index.isValid()) { 65 | qint32 nRow = index.row(); 66 | if (nRow >= 0 && nRow < m_pListFParts->count()) { 67 | qint32 nColumn = index.column(); 68 | const XBinary::FPART &rec = m_pListFParts->at(nRow); 69 | if (nRole == Qt::DisplayRole) { 70 | if (nColumn == COLUMN_NAME) { 71 | result = rec.sName; 72 | } else if (nColumn == COLUMN_OFFSET) { 73 | result = QString::number(rec.nFileOffset, 16); 74 | } else if (nColumn == COLUMN_SIZE) { 75 | result = QString::number(rec.nFileSize, 16); 76 | } else if (nColumn == COLUMN_COMPRESSMETHOD) { 77 | if (rec.mapProperties.contains(XBinary::FPART_PROP_COMPRESSMETHOD)) { 78 | XBinary::COMPRESS_METHOD cm = (XBinary::COMPRESS_METHOD)rec.mapProperties.value(XBinary::FPART_PROP_COMPRESSMETHOD).toInt(); 79 | result = XBinary::compressMethodToString(cm); 80 | } 81 | } else if (nColumn == COLUMN_UNCOMPRESSEDSIZE) { 82 | if (rec.mapProperties.contains(XBinary::FPART_PROP_UNCOMPRESSEDSIZE)) { 83 | quint64 nUSz = rec.mapProperties.value(XBinary::FPART_PROP_UNCOMPRESSEDSIZE).toULongLong(); 84 | result = QString::number(nUSz, 16); 85 | } 86 | } 87 | } else if (nRole == Qt::TextAlignmentRole) { 88 | result = getColumnAlignment(nColumn); 89 | } else if (nRole >= Qt::UserRole) { 90 | if (nRole == (Qt::UserRole + XModel::USERROLE_ORIGINDEX)) { 91 | result = nRow; 92 | } else if (nRole == (Qt::UserRole + XModel::USERROLE_OFFSET)) { 93 | result = rec.nFileOffset; 94 | } else if (nRole == (Qt::UserRole + XModel::USERROLE_SIZE)) { 95 | result = rec.nFileSize; 96 | } else if (nRole == (Qt::UserRole + XModel::USERROLE_STRING1)) { 97 | result = rec.sName; 98 | } 99 | } 100 | } 101 | } 102 | 103 | return result; 104 | } 105 | 106 | QVariant XModel_Streams::headerData(int nSection, Qt::Orientation orientation, int nRole) const 107 | { 108 | QVariant result; 109 | 110 | if (orientation == Qt::Horizontal) { 111 | if (nRole == Qt::DisplayRole) { 112 | result = getColumnName(nSection); 113 | } else if (nRole == Qt::TextAlignmentRole) { 114 | result = getColumnAlignment(nSection); 115 | } 116 | } 117 | 118 | return result; 119 | } 120 | -------------------------------------------------------------------------------- /xdevicetableview.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2020-2025 hors 2 | * 3 | * Permission is hereby granted, free of charge, to any person obtaining a copy 4 | * of this software and associated documentation files (the "Software"), to deal 5 | * in the Software without restriction, including without limitation the rights 6 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | * copies of the Software, and to permit persons to whom the Software is 8 | * furnished to do so, subject to the following conditions: 9 | * 10 | * The above copyright notice and this permission notice shall be included in 11 | * all copies or substantial portions of the Software. 12 | * 13 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 19 | * SOFTWARE. 20 | */ 21 | #ifndef XDEVICETABLEVIEW_H 22 | #define XDEVICETABLEVIEW_H 23 | 24 | #include "dialoggotoaddress.h" 25 | #include "dialoghexsignature.h" 26 | #include "dialogsearch.h" 27 | #include "xabstracttableview.h" 28 | #include "xformats.h" 29 | #include "xdialogprocess.h" 30 | #include "searchprocess.h" 31 | #include "xbinaryview.h" 32 | 33 | class XDeviceTableView : public XAbstractTableView { 34 | Q_OBJECT 35 | 36 | public: 37 | struct DEVICESTATE { 38 | quint64 nSelectionDeviceOffset; 39 | qint64 nSelectionSize; 40 | // qint64 nCursorOffset; 41 | qint64 nStartDeviceOffset; 42 | }; 43 | 44 | XDeviceTableView(QWidget *pParent = nullptr); 45 | ~XDeviceTableView(); 46 | 47 | void setXInfoDB(XInfoDB *pXInfoDB); 48 | XInfoDB *getXInfoDB(); 49 | void setData(QIODevice *pDevice, const XBinaryView::OPTIONS &options); 50 | void reset(); 51 | QIODevice *getDevice(); 52 | XBinaryView *getBinaryView(); 53 | void setLocationMode(XBinaryView::LOCMODE locationMode); 54 | XBinaryView::LOCMODE getlocationMode(); 55 | void setLocationBase(qint32 nBase); 56 | qint32 getLocationBase(); 57 | qint64 write_array(qint64 nOffset, char *pData, qint64 nDataSize); 58 | QByteArray read_array(qint64 nOffset, qint32 nSize); 59 | void goToAddress(XADDR nAddress, bool bShort = false, bool bAprox = false, bool bSaveVisited = false); 60 | void goToOffset(qint64 nOffset, bool bShort = false, bool bAprox = false, bool bSaveVisited = false); 61 | void goToLocation(XADDR nLocation, XBinary::LT locationType, bool bShort = false, bool bAprox = false, bool bSaveVisited = false); 62 | void setLocationOffset(XADDR nLocation, XBinary::LT locationType, qint64 nSize); 63 | void setSelectionAddress(XADDR nAddress, qint64 nSize); // TODO remove 64 | void setSelectionRelAddress(XADDR nRelAddress, qint64 nSize); // TODO remove 65 | void setSelectionOffset(qint64 nOffset, qint64 nSize); // TODO remove 66 | bool isEdited(); 67 | bool saveBackup(); 68 | void adjustAfterAnalysis(); // TODO Check mb remove 69 | virtual DEVICESTATE getDeviceState(); 70 | virtual void setDeviceState(const DEVICESTATE &deviceState); 71 | 72 | void setDeviceSelection(qint64 nOffset, qint64 nSize); 73 | bool isPrevVisitedAvailable(); 74 | bool isNextVisitedAvailable(); 75 | void goToNextVisited(); 76 | void goToPrevVisited(); 77 | void addVisited(qint64 nViewPos); 78 | void clearVisited(); 79 | 80 | virtual void setLocation(quint64 nLocation, qint32 nLocationType, qint64 nSize); 81 | 82 | public slots: 83 | void setEdited(qint64 nDeviceOffset, qint64 nDeviceSize); 84 | void _goToAddressSlot(); 85 | void _goToOffsetSlot(); 86 | 87 | protected: 88 | virtual void adjustScrollCount(); 89 | virtual bool isViewPosValid(XVPOS nViewPos); 90 | virtual bool isEnd(XVPOS nViewPos); 91 | 92 | signals: 93 | void visitedStateChanged(); 94 | void deviceSizeChanged(qint64 nOldSize, qint64 nNewSize); 95 | 96 | protected slots: 97 | void _goToSelectionStart(); 98 | void _goToSelectionEnd(); 99 | void _findStringSlot(); 100 | void _findSignatureSlot(); 101 | void _findValueSlot(); 102 | void _findSlot(XBinary::SEARCHMODE mode); 103 | void _findNextSlot(); 104 | void _selectAllSlot(); 105 | void _copyAddressSlot(); 106 | void _copyRelAddressSlot(); 107 | void _copyOffsetSlot(); 108 | void _setEdited(qint64 nDeviceOffset, qint64 nDeviceSize); 109 | void goToAddressSlot(XADDR nAddress, qint64 nSize); 110 | void goToAddressSlot(XADDR nAddress); 111 | void reloadView(); 112 | void selectionChangedSlot(); 113 | void changeLocationMode(); 114 | void changeLocationBase(); 115 | 116 | public slots: 117 | void currentLocationChangedSlot(quint64 nLocation, qint32 nLocationType, qint64 nSize); 118 | 119 | private: 120 | static const qint32 N_MAX_VISITED = 100; 121 | XInfoDB m_emptyXInfoDB; 122 | XInfoDB *m_pXInfoDB; 123 | XBinary::SEARCHDATA m_searchData; 124 | XBinaryView::LOCMODE m_locationMode; 125 | qint32 m_nLocationBase; 126 | QList m_listVisited; 127 | qint32 m_nVisitedIndex; 128 | 129 | XBinaryView m_binaryView; 130 | }; 131 | 132 | #endif // XDEVICETABLEVIEW_H 133 | -------------------------------------------------------------------------------- /xhtml.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2021-2025 hors 2 | * 3 | * Permission is hereby granted, free of charge, to any person obtaining a copy 4 | * of this software and associated documentation files (the "Software"), to deal 5 | * in the Software without restriction, including without limitation the rights 6 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | * copies of the Software, and to permit persons to whom the Software is 8 | * furnished to do so, subject to the following conditions: 9 | * 10 | * The above copyright notice and this permission notice shall be included in 11 | * all copies or substantial portions of the Software. 12 | * 13 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 19 | * SOFTWARE. 20 | */ 21 | #include "xhtml.h" 22 | 23 | XHtml::XHtml(QObject *pParent) : QObject(pParent), m_bInList(false) 24 | { 25 | } 26 | 27 | void XHtml::appendText(const QString &sText) 28 | { 29 | m_sString.append(escapeHtml(sText)); 30 | } 31 | 32 | void XHtml::appendHtml(const QString &sHtml) 33 | { 34 | m_sString.append(sHtml); 35 | } 36 | 37 | void XHtml::appendParagraph(const QString &sText) 38 | { 39 | m_sString.append(QString("

%1

").arg(escapeHtml(sText))); 40 | } 41 | 42 | void XHtml::appendHeading(qint32 nLevel, const QString &sText) 43 | { 44 | if (nLevel < 1) nLevel = 1; 45 | if (nLevel > 6) nLevel = 6; 46 | 47 | m_sString.append(QString("%2").arg(nLevel).arg(escapeHtml(sText))); 48 | } 49 | 50 | void XHtml::appendLineBreak() 51 | { 52 | m_sString.append("
"); 53 | } 54 | 55 | void XHtml::appendHorizontalRule() 56 | { 57 | m_sString.append("
"); 58 | } 59 | 60 | void XHtml::addTableBegin(qint32 nBorder, qint32 nCellPadding) 61 | { 62 | m_sString.append(QString("").arg(nBorder).arg(nCellPadding)); 63 | } 64 | 65 | void XHtml::addTableRow(const QList &listTableCells) 66 | { 67 | qint32 nNumbersOfCell = listTableCells.count(); 68 | 69 | if (nNumbersOfCell) { 70 | m_sString.append(""); 71 | 72 | for (qint32 i = 0; i < nNumbersOfCell; i++) { 73 | QString sAlign = alignmentToString(listTableCells.at(i).alignment); 74 | m_sString.append(QString(""); 84 | } 85 | 86 | m_sString.append(""); 87 | } 88 | } 89 | 90 | void XHtml::addTableEnd() 91 | { 92 | m_sString.append("
").arg(sAlign)); 75 | 76 | QString sCellText = escapeHtml(listTableCells.at(i).sText); 77 | 78 | if (listTableCells.at(i).bBold) { 79 | sCellText = QString("%1").arg(sCellText); 80 | } 81 | 82 | m_sString.append(sCellText); 83 | m_sString.append("
"); 93 | } 94 | 95 | void XHtml::addListBegin(bool bOrdered) 96 | { 97 | if (bOrdered) { 98 | m_sString.append("
    "); 99 | } else { 100 | m_sString.append("
      "); 101 | } 102 | m_bInList = true; 103 | } 104 | 105 | void XHtml::addListItem(const QString &sText) 106 | { 107 | m_sString.append(QString("
    • %1
    • ").arg(escapeHtml(sText))); 108 | } 109 | 110 | void XHtml::addListEnd() 111 | { 112 | if (m_bInList) { 113 | if (m_sString.contains("
        ")) { 114 | m_sString.append("
      "); 115 | } else { 116 | m_sString.append("
    "); 117 | } 118 | m_bInList = false; 119 | } 120 | } 121 | 122 | void XHtml::clear() 123 | { 124 | m_sString.clear(); 125 | m_bInList = false; 126 | } 127 | 128 | QString XHtml::toString() const 129 | { 130 | return m_sString; 131 | } 132 | 133 | QString XHtml::makeLink(const QString &sText, const QString &sLink) 134 | { 135 | QString sResult; 136 | 137 | if (sLink != "") { 138 | sResult = QString("%2").arg(escapeHtml(sLink), escapeHtml(sText)); 139 | } else { 140 | sResult = escapeHtml(sText); 141 | } 142 | 143 | return sResult; 144 | } 145 | 146 | QString XHtml::escapeHtml(const QString &sText) 147 | { 148 | QString sResult = sText; 149 | sResult.replace("&", "&"); 150 | sResult.replace("<", "<"); 151 | sResult.replace(">", ">"); 152 | sResult.replace("\"", """); 153 | sResult.replace("'", "'"); 154 | return sResult; 155 | } 156 | 157 | QString XHtml::makeBold(const QString &sText) 158 | { 159 | return QString("%1").arg(escapeHtml(sText)); 160 | } 161 | 162 | QString XHtml::makeItalic(const QString &sText) 163 | { 164 | return QString("%1").arg(escapeHtml(sText)); 165 | } 166 | 167 | QString XHtml::alignmentToString(Qt::Alignment alignment) 168 | { 169 | if (alignment & Qt::AlignLeft) { 170 | return "left"; 171 | } else if (alignment & Qt::AlignRight) { 172 | return "right"; 173 | } else if (alignment & Qt::AlignHCenter) { 174 | return "center"; 175 | } else if (alignment & Qt::AlignJustify) { 176 | return "justify"; 177 | } 178 | 179 | return "center"; // Default alignment 180 | } 181 | -------------------------------------------------------------------------------- /xmodel_fparts.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2025 hors 2 | * 3 | * Permission is hereby granted, free of charge, to any person obtaining a copy 4 | * of this software and associated documentation files (the "Software"), to deal 5 | * in the Software without restriction, including without limitation the rights 6 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | * copies of the Software, and to permit persons to whom the Software is 8 | * furnished to do so, subject to the following conditions: 9 | * 10 | * The above copyright notice and this permission notice shall be included in 11 | * all copies or substantial portions of the Software. 12 | * 13 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 19 | * SOFTWARE. 20 | */ 21 | #include "xmodel_fparts.h" 22 | 23 | XModel_FPARTS::XModel_FPARTS(QList *pListFParts, QObject *pParent) : XModel(pParent) 24 | { 25 | m_pListFParts = pListFParts; 26 | if (pListFParts) { 27 | _setRowCount(pListFParts->count()); 28 | } else { 29 | _setRowCount(0); 30 | } 31 | _setColumnCount(__COLUMN_COUNT); 32 | _initColumns(); 33 | } 34 | 35 | void XModel_FPARTS::_initColumns() 36 | { 37 | setColumnName(COLUMN_NAME, QObject::tr("Name")); 38 | setColumnName(COLUMN_OFFSET, QObject::tr("Offset")); 39 | setColumnName(COLUMN_SIZE, QObject::tr("Size")); 40 | setColumnName(COLUMN_VADDRESS, QObject::tr("Address")); 41 | setColumnName(COLUMN_VSIZE, QObject::tr("V.Size")); 42 | setColumnName(COLUMN_PART, QObject::tr("Part")); 43 | 44 | setColumnAlignment(COLUMN_NAME, Qt::AlignVCenter | Qt::AlignLeft); 45 | setColumnAlignment(COLUMN_OFFSET, Qt::AlignVCenter | Qt::AlignRight); 46 | setColumnAlignment(COLUMN_SIZE, Qt::AlignVCenter | Qt::AlignRight); 47 | setColumnAlignment(COLUMN_VADDRESS, Qt::AlignVCenter | Qt::AlignRight); 48 | setColumnAlignment(COLUMN_VSIZE, Qt::AlignVCenter | Qt::AlignRight); 49 | setColumnAlignment(COLUMN_PART, Qt::AlignVCenter | Qt::AlignLeft); 50 | 51 | setColumnSymbolSize(COLUMN_NAME, 20); 52 | setColumnSymbolSize(COLUMN_OFFSET, 16); 53 | setColumnSymbolSize(COLUMN_SIZE, 16); 54 | setColumnSymbolSize(COLUMN_VADDRESS, 16); 55 | setColumnSymbolSize(COLUMN_VSIZE, 16); 56 | setColumnSymbolSize(COLUMN_PART, 12); 57 | } 58 | 59 | QVariant XModel_FPARTS::data(const QModelIndex &index, int nRole) const 60 | { 61 | QVariant result; 62 | 63 | if (!m_pListFParts) { 64 | return result; 65 | } 66 | 67 | if (index.isValid()) { 68 | qint32 nRow = index.row(); 69 | if (nRow >= 0 && nRow < m_pListFParts->count()) { 70 | qint32 nColumn = index.column(); 71 | const XBinary::FPART &rec = m_pListFParts->at(nRow); 72 | if (nRole == Qt::DisplayRole) { 73 | if (nColumn == COLUMN_NAME) { 74 | result = rec.sName; 75 | } else if (nColumn == COLUMN_OFFSET) { 76 | result = QString::number(rec.nFileOffset, 16); 77 | } else if (nColumn == COLUMN_SIZE) { 78 | result = QString::number(rec.nFileSize, 16); 79 | } else if (nColumn == COLUMN_VADDRESS) { 80 | if (rec.nVirtualAddress != (XADDR)-1) { 81 | result = QString::number(rec.nVirtualAddress, 16); 82 | } 83 | } else if (nColumn == COLUMN_VSIZE) { 84 | if (rec.nVirtualAddress != (XADDR)-1) { 85 | result = QString::number(rec.nVirtualSize, 16); 86 | } 87 | } else if (nColumn == COLUMN_PART) { 88 | result = XBinary::recordFilePartIdToString(rec.filePart); 89 | } 90 | } else if (nRole == Qt::TextAlignmentRole) { 91 | result = getColumnAlignment(nColumn); 92 | } else if (nRole >= Qt::UserRole) { 93 | // Expose some raw values for sorting/filtering 94 | if (nRole == (Qt::UserRole + XModel::USERROLE_ORIGINDEX)) { 95 | result = nRow; 96 | } else if (nRole == (Qt::UserRole + XModel::USERROLE_OFFSET)) { 97 | result = rec.nFileOffset; 98 | } else if (nRole == (Qt::UserRole + XModel::USERROLE_SIZE)) { 99 | result = rec.nFileSize; 100 | } else if (nRole == (Qt::UserRole + XModel::USERROLE_ADDRESS)) { 101 | result = (qulonglong)rec.nVirtualAddress; 102 | } else if (nRole == (Qt::UserRole + XModel::USERROLE_STRING1)) { 103 | result = rec.sName; 104 | } else if (nRole == (Qt::UserRole + XModel::USERROLE_STRING2)) { 105 | result = XBinary::recordFilePartIdToString(rec.filePart); 106 | } 107 | } 108 | } 109 | } 110 | 111 | return result; 112 | } 113 | 114 | QVariant XModel_FPARTS::headerData(int nSection, Qt::Orientation orientation, int nRole) const 115 | { 116 | QVariant result; 117 | 118 | if (orientation == Qt::Horizontal) { 119 | if (nRole == Qt::DisplayRole) { 120 | result = getColumnName(nSection); 121 | } else if (nRole == Qt::TextAlignmentRole) { 122 | result = getColumnAlignment(nSection); 123 | } 124 | } 125 | 126 | return result; 127 | } 128 | 129 | XModel::SORT_METHOD XModel_FPARTS::getSortMethod(qint32 nColumn) 130 | { 131 | SORT_METHOD result = SORT_METHOD_DEFAULT; 132 | 133 | if ((nColumn == COLUMN_OFFSET) || (nColumn == COLUMN_SIZE) || (nColumn == COLUMN_VADDRESS) || (nColumn == COLUMN_VSIZE)) { 134 | result = SORT_METHOD_HEX; 135 | } 136 | 137 | return result; 138 | } 139 | 140 | bool XModel_FPARTS::isCustomFilter() 141 | { 142 | return false; 143 | } 144 | 145 | bool XModel_FPARTS::isCustomSort() 146 | { 147 | return false; 148 | } 149 | -------------------------------------------------------------------------------- /xmodel_binary.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2025 hors 2 | * 3 | * Permission is hereby granted, free of charge, to any person obtaining a copy 4 | * of this software and associated documentation files (the "Software"), to deal 5 | * in the Software without restriction, including without limitation the rights 6 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | * copies of the Software, and to permit persons to whom the Software is 8 | * furnished to do so, subject to the following conditions: 9 | * 10 | * The above copyright notice and this permission notice shall be included in 11 | * all copies or substantial portions of the Software. 12 | * 13 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 19 | * SOFTWARE. 20 | */ 21 | #include "xmodel_binary.h" 22 | 23 | XModel_Binary::XModel_Binary(const XBinary::DATA_RECORDS_OPTIONS &dataRecordsOptions, QList *pListDataRecords, QList *pListTitles, 24 | QObject *pParent) 25 | : XModel(pParent) 26 | { 27 | m_dataRecordsOptions = dataRecordsOptions; 28 | m_pListDataRecords = pListDataRecords; 29 | m_pListTitles = pListTitles; 30 | m_pListComments = nullptr; 31 | 32 | if (dataRecordsOptions.dataHeaderFirst.dhMode == XBinary::DHMODE_HEADER) { 33 | _setRowCount(dataRecordsOptions.dataHeaderFirst.listRecords.count()); 34 | _setColumnCount(__COLUMN_HEADER_SIZE); 35 | 36 | setColumnName(COLUMN_HEADER_NAME, tr("Name")); 37 | setColumnName(COLUMN_HEADER_OFFSET, tr("Offset")); 38 | setColumnName(COLUMN_HEADER_SIZE, tr("Size")); 39 | setColumnName(COLUMN_HEADER_TYPE, tr("Type")); 40 | setColumnName(COLUMN_HEADER_VALUE, tr("Value")); 41 | setColumnName(COLUMN_HEADER_INFO, tr("")); 42 | setColumnName(COLUMN_HEADER_COMMENT, tr("Comment")); 43 | setColumnAlignment(COLUMN_HEADER_NAME, Qt::AlignVCenter | Qt::AlignLeft); 44 | setColumnAlignment(COLUMN_HEADER_OFFSET, Qt::AlignVCenter | Qt::AlignRight); 45 | setColumnAlignment(COLUMN_HEADER_SIZE, Qt::AlignVCenter | Qt::AlignRight); 46 | setColumnAlignment(COLUMN_HEADER_TYPE, Qt::AlignVCenter | Qt::AlignLeft); 47 | setColumnAlignment(COLUMN_HEADER_VALUE, Qt::AlignVCenter | Qt::AlignLeft); 48 | setColumnAlignment(COLUMN_HEADER_INFO, Qt::AlignVCenter | Qt::AlignLeft); 49 | setColumnAlignment(COLUMN_HEADER_COMMENT, Qt::AlignVCenter | Qt::AlignLeft); 50 | } else if (dataRecordsOptions.dataHeaderFirst.dhMode == XBinary::DHMODE_TABLE) { 51 | qint32 nColumnCount = pListTitles->count(); 52 | qint32 nRowCount = pListDataRecords->count(); 53 | _setColumnCount(nColumnCount); 54 | _setRowCount(nRowCount); 55 | 56 | qint32 nNumberOfColumns = m_pListTitles->count(); 57 | 58 | for (qint32 i = 0; i < nNumberOfColumns; i++) { 59 | qint32 flag = Qt::AlignVCenter | Qt::AlignLeft; 60 | 61 | XBinary::VT valType = dataRecordsOptions.dataHeaderFirst.listRecords.at(i).valType; 62 | 63 | if (XBinary::isIntegerType(valType)) { 64 | flag = Qt::AlignVCenter | Qt::AlignRight; 65 | } 66 | 67 | setColumnAlignment(i, flag); 68 | setColumnName(i, m_pListTitles->at(i)); 69 | 70 | if (nRowCount > 0) { 71 | qint32 nColumnSymbolSize = m_pListTitles->at(i).length(); 72 | nColumnSymbolSize = qMax(nColumnSymbolSize, XBinary::getValueSymbolSize(valType)); 73 | setColumnSymbolSize(i, nColumnSymbolSize); 74 | } 75 | } 76 | } 77 | } 78 | 79 | QVariant XModel_Binary::data(const QModelIndex &index, int nRole) const 80 | { 81 | QVariant result; 82 | 83 | if (index.isValid()) { 84 | qint32 nRow = index.row(); 85 | 86 | if (nRow >= 0) { 87 | qint32 nColumn = index.column(); 88 | 89 | if (nRole == Qt::DisplayRole) { 90 | if (m_dataRecordsOptions.dataHeaderFirst.dhMode == XBinary::DHMODE_HEADER) { 91 | if (nColumn == COLUMN_HEADER_NAME) { 92 | result = m_dataRecordsOptions.dataHeaderFirst.listRecords.at(nRow).sName; 93 | } else if (nColumn == COLUMN_HEADER_OFFSET) { 94 | result = QString::number(m_dataRecordsOptions.dataHeaderFirst.listRecords.at(nRow).nRelOffset, 16); 95 | } else if (nColumn == COLUMN_HEADER_SIZE) { 96 | result = QString::number(m_dataRecordsOptions.dataHeaderFirst.listRecords.at(nRow).nSize, 16); 97 | } else if (nColumn == COLUMN_HEADER_TYPE) { 98 | result = XBinary::valueTypeToString(m_dataRecordsOptions.dataHeaderFirst.listRecords.at(nRow).valType, 99 | m_dataRecordsOptions.dataHeaderFirst.listRecords.at(nRow).nSize); 100 | } else if (nColumn == COLUMN_HEADER_VALUE) { 101 | result = XBinary::getValueString(m_pListDataRecords->at(0).listValues.at(nRow), m_dataRecordsOptions.dataHeaderFirst.listRecords.at(nRow).valType, 102 | true); 103 | } else if (nColumn == COLUMN_HEADER_INFO) { 104 | // TODO 105 | } else if (nColumn == COLUMN_HEADER_COMMENT) { 106 | if (m_pListComments) { 107 | if (nRow < m_pListComments->count()) { 108 | result = m_pListComments->at(nRow); 109 | } 110 | } 111 | } 112 | } else if (m_dataRecordsOptions.dataHeaderFirst.dhMode == XBinary::DHMODE_TABLE) { 113 | result = XBinary::getValueString(m_pListDataRecords->at(nRow).listValues.at(nColumn), 114 | m_dataRecordsOptions.dataHeaderFirst.listRecords.at(nColumn).valType, true); 115 | } 116 | } else if (nRole == Qt::TextAlignmentRole) { 117 | result = getColumnAlignment(nColumn); 118 | } 119 | } 120 | } 121 | 122 | return result; 123 | } 124 | 125 | QVariant XModel_Binary::headerData(int nSection, Qt::Orientation orientation, int nRole) const 126 | { 127 | QVariant result; 128 | 129 | if (orientation == Qt::Horizontal) { 130 | if (nRole == Qt::DisplayRole) { 131 | result = getColumnName(nSection); 132 | } else if (nRole == Qt::TextAlignmentRole) { 133 | result = getColumnAlignment(nSection); 134 | } 135 | } 136 | 137 | return result; 138 | } 139 | 140 | void XModel_Binary::setComments(QList *pListComments) 141 | { 142 | m_pListComments = pListComments; 143 | } 144 | -------------------------------------------------------------------------------- /xtableview.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2024-2025 hors 2 | * 3 | * Permission is hereby granted, free of charge, to any person obtaining a copy 4 | * of this software and associated documentation files (the "Software"), to deal 5 | * in the Software without restriction, including without limitation the rights 6 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | * copies of the Software, and to permit persons to whom the Software is 8 | * furnished to do so, subject to the following conditions: 9 | * 10 | * The above copyright notice and this permission notice shall be included in 11 | * all copies or substantial portions of the Software. 12 | * 13 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 19 | * SOFTWARE. 20 | */ 21 | #include "xtableview.h" 22 | #include 23 | 24 | XTableView::XTableView(QWidget *pParent) : QTableView(pParent) 25 | { 26 | m_pOldModel = nullptr; 27 | m_pModel = nullptr; 28 | m_pHeaderView = new XHeaderView(this); 29 | m_pSortFilterProxyModel = new XSortFilterProxyModel(this); 30 | m_bIsXmodel = false; 31 | m_bIsCustomFilter = false; 32 | m_bIsCustomSort = false; 33 | m_pXModel = nullptr; 34 | m_bIsStop = false; 35 | 36 | setHorizontalHeader(m_pHeaderView); 37 | 38 | connect(m_pHeaderView, SIGNAL(filterChanged()), this, SLOT(onFilterChanged())); 39 | connect(m_pHeaderView, SIGNAL(sortIndicatorChanged(int, Qt::SortOrder)), this, SLOT(onSortChanged(int, Qt::SortOrder))); 40 | connect(horizontalScrollBar(), SIGNAL(valueChanged(int)), this, SLOT(horisontalScroll())); 41 | connect(this, SIGNAL(invalidateSignal()), m_pSortFilterProxyModel, SLOT(invalidate())); 42 | 43 | setSortingEnabled(true); 44 | setWordWrap(false); 45 | } 46 | 47 | XTableView::~XTableView() 48 | { 49 | #ifdef QT_DEBUG 50 | qDebug("~XTableView()"); 51 | #endif 52 | 53 | m_bIsStop = true; 54 | m_watcher.waitForFinished(); 55 | } 56 | 57 | void XTableView::setCustomModel(QAbstractItemModel *pModel, bool bFilterEnabled) 58 | { 59 | // TODO Stretch last section 60 | m_pOldModel = m_pModel; 61 | 62 | if (m_pOldModel) { 63 | // #ifdef QT_CONCURRENT_LIB 64 | // #if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) 65 | // QtConcurrent::run(&XTableView::deleteOldModel, this, &m_pOldModel); 66 | // #else 67 | // QtConcurrent::run(this, &XTableView::deleteOldModel, &m_pOldModel); 68 | // #endif 69 | // #else 70 | // deleteOldModel(&m_pOldModel); 71 | // #endif 72 | // m_pOldModel->beginResetModel(); 73 | #ifdef QT_DEBUG 74 | // get elapsed time 75 | QElapsedTimer timer; 76 | timer.start(); 77 | qDebug("m_pOldModel->clear() START"); 78 | // QStandartItemModel 433543 79 | // 470701 ms 80 | #endif 81 | // m_pOldModel->clear(); 82 | deleteOldModel(&m_pOldModel); 83 | #ifdef QT_DEBUG 84 | qDebug("setCustomModel Elapsed time: %lld ms", timer.elapsed()); 85 | #endif 86 | // m_pOldModel->endResetModel(); 87 | } 88 | 89 | m_pModel = pModel; 90 | 91 | if (bFilterEnabled) { 92 | m_pHeaderView->setNumberOfFilters(pModel->columnCount()); 93 | m_pSortFilterProxyModel->setSourceModel(pModel); 94 | setModel(m_pSortFilterProxyModel); 95 | } else { 96 | setModel(pModel); 97 | } 98 | 99 | adjust(); 100 | } 101 | 102 | void XTableView::clear() 103 | { 104 | setModel(nullptr); 105 | } 106 | 107 | void XTableView::deleteOldModel(QAbstractItemModel **ppOldModel) 108 | { 109 | delete (*ppOldModel); 110 | 111 | (*ppOldModel) = nullptr; 112 | } 113 | 114 | void XTableView::handleFilter() 115 | { 116 | QList listFilters = m_pHeaderView->getFilters(); 117 | 118 | qint32 nNumberOfRows = m_pModel->rowCount(); 119 | qint32 nNumberOfFilters = listFilters.count(); 120 | 121 | for (qint32 i = 0; (i < nNumberOfRows) && (!m_bIsStop); i++) { 122 | bool bHidden = false; 123 | 124 | for (qint32 j = 0; j < nNumberOfFilters; j++) { 125 | QString sFilter = listFilters.at(j); 126 | if (sFilter != "") { 127 | QModelIndex index = m_pModel->index(i, j); 128 | 129 | if (index.isValid()) { 130 | QString sValue = m_pModel->data(index).toString(); 131 | 132 | if (!sValue.contains(sFilter, Qt::CaseInsensitive)) { 133 | bHidden = true; 134 | break; 135 | } 136 | } 137 | } 138 | } 139 | 140 | if (m_bIsXmodel) { 141 | m_pXModel->setRowHidden(i, bHidden); 142 | } 143 | } 144 | 145 | if (!m_bIsStop) { 146 | #ifdef QT_DEBUG 147 | qDebug("invalidateSignal"); 148 | #endif 149 | emit invalidateSignal(); 150 | } else { 151 | #ifdef QT_DEBUG 152 | qDebug("XTableView::handleFilter is stopped"); 153 | #endif 154 | } 155 | } 156 | 157 | XSortFilterProxyModel *XTableView::getProxyModel() 158 | { 159 | return m_pSortFilterProxyModel; 160 | } 161 | 162 | void XTableView::setFilterEnabled(qint32 nColumn, bool bFilterEnabled) 163 | { 164 | m_pHeaderView->setFilterEnabled(nColumn, bFilterEnabled); 165 | } 166 | 167 | void XTableView::adjust() 168 | { 169 | m_pXModel = dynamic_cast(m_pModel); 170 | 171 | if (m_pXModel) { 172 | qint32 nNumberOfColumns = m_pXModel->columnCount(); 173 | 174 | for (qint32 i = 0; i < nNumberOfColumns; i++) { 175 | qint32 nSymbolSize = m_pXModel->getColumnSymbolSize(i); 176 | 177 | if (nSymbolSize != -1) { 178 | qint32 nWidth = XOptions::getControlWidth(this, nSymbolSize); 179 | setColumnWidth(i, nWidth); 180 | } 181 | } 182 | m_bIsXmodel = true; 183 | m_bIsCustomFilter = m_pXModel->isCustomFilter(); 184 | m_bIsCustomSort = m_pXModel->isCustomSort(); 185 | } else { 186 | m_bIsXmodel = false; 187 | m_bIsCustomFilter = false; 188 | m_bIsCustomSort = false; 189 | } 190 | } 191 | 192 | void XTableView::onFilterChanged() 193 | { 194 | #ifdef QT_DEBUG 195 | // Elapsed time 196 | QElapsedTimer timer; 197 | timer.start(); 198 | qDebug("onFilterChanged START"); 199 | #endif 200 | 201 | QList listFilters = m_pHeaderView->getFilters(); 202 | 203 | m_pSortFilterProxyModel->setFilters(listFilters); 204 | 205 | if (m_bIsCustomFilter) { 206 | m_bIsStop = true; 207 | m_watcher.waitForFinished(); 208 | m_bIsStop = false; 209 | 210 | #if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) 211 | QFuture future = QtConcurrent::run(&XTableView::handleFilter, this); 212 | #else 213 | QFuture future = QtConcurrent::run(this, &XTableView::handleFilter); 214 | #endif 215 | m_watcher.setFuture(future); 216 | } else { 217 | emit invalidateSignal(); 218 | // m_pSortFilterProxyModel->invalidate(); 219 | } 220 | 221 | #ifdef QT_DEBUG 222 | qDebug("onFilterChanged Elapsed time: %lld ms", timer.elapsed()); 223 | // 16266 ms 224 | // 16342 225 | // 226 | // 227 | #endif 228 | } 229 | 230 | void XTableView::onSortChanged(int column, Qt::SortOrder order) 231 | { 232 | if (m_bIsCustomSort) { 233 | // TODO Thread 234 | m_pSortFilterProxyModel->sort(column, order); 235 | } else { 236 | m_pSortFilterProxyModel->sort(column, order); 237 | } 238 | } 239 | 240 | void XTableView::horisontalScroll() 241 | { 242 | m_pHeaderView->adjustPositions(); 243 | } 244 | -------------------------------------------------------------------------------- /xmodel_archiverecords.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2025 hors 2 | * 3 | * Permission is hereby granted, free of charge, to any person obtaining a copy 4 | * of this software and associated documentation files (the "Software"), to deal 5 | * in the Software without restriction, including without limitation the rights 6 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | * copies of the Software, and to permit persons to do so, subject to the 8 | * following conditions: 9 | * 10 | * The above copyright notice and this permission notice shall be included in 11 | * all copies or substantial portions of the Software. 12 | * 13 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 19 | * SOFTWARE. 20 | */ 21 | #include "xmodel_archiverecords.h" 22 | 23 | XModel_ArchiveRecords::XModel_ArchiveRecords(const QList &listColumns, QList *pListArchiveRecords, QObject *pParent) 24 | : XModel(pParent) 25 | { 26 | m_listColumns = listColumns; 27 | 28 | m_pListArchiveRecords = pListArchiveRecords; 29 | if (pListArchiveRecords) { 30 | _setRowCount(pListArchiveRecords->count()); 31 | } else { 32 | _setRowCount(0); 33 | } 34 | 35 | _setColumnCount(m_listColumns.count()); 36 | _initColumns(); 37 | } 38 | 39 | void XModel_ArchiveRecords::_initColumns() 40 | { 41 | qint32 nNumberOfRecords = m_listColumns.count(); 42 | 43 | for (qint32 i = 0; i < nNumberOfRecords; i++) { 44 | XBinary::FPART_PROP fpartProp = m_listColumns.at(i); 45 | 46 | QString sName; 47 | qint32 nFlags = Qt::AlignVCenter | Qt::AlignLeft; 48 | qint32 nSymbolSize = 16; 49 | 50 | if (fpartProp == XBinary::FPART_PROP_ORIGINALNAME) sName = QObject::tr("Name"); 51 | else if (fpartProp == XBinary::FPART_PROP_COMPRESSEDSIZE) sName = QObject::tr("Compressed size"); 52 | else if (fpartProp == XBinary::FPART_PROP_UNCOMPRESSEDSIZE) sName = QObject::tr("Size"); 53 | else if (fpartProp == XBinary::FPART_PROP_STREAMOFFSET) sName = QObject::tr("Stream offset"); 54 | else if (fpartProp == XBinary::FPART_PROP_STREAMSIZE) sName = QObject::tr("Stream size"); 55 | else if (fpartProp == XBinary::FPART_PROP_COMPRESSMETHOD) sName = QObject::tr("Method"); 56 | 57 | if ((fpartProp == XBinary::FPART_PROP_ORIGINALNAME) || (fpartProp == XBinary::FPART_PROP_COMPRESSMETHOD)) nFlags = Qt::AlignVCenter | Qt::AlignLeft; 58 | else nFlags = Qt::AlignVCenter | Qt::AlignRight; 59 | 60 | if (fpartProp == XBinary::FPART_PROP_ORIGINALNAME) nSymbolSize = 20; 61 | else nSymbolSize = 16; 62 | 63 | setColumnName(i, sName); 64 | setColumnAlignment(i, nFlags); 65 | setColumnSymbolSize(i, nSymbolSize); 66 | } 67 | } 68 | 69 | QVariant XModel_ArchiveRecords::data(const QModelIndex &index, int nRole) const 70 | { 71 | QVariant result; 72 | 73 | if (!m_pListArchiveRecords) { 74 | return result; 75 | } 76 | 77 | if (index.isValid()) { 78 | qint32 nRow = index.row(); 79 | if (nRow >= 0 && nRow < m_pListArchiveRecords->count()) { 80 | qint32 nColumn = index.column(); 81 | const XBinary::ARCHIVERECORD &rec = m_pListArchiveRecords->at(nRow); 82 | if (nRole == Qt::DisplayRole) { 83 | if (nColumn < m_listColumns.count()) { 84 | XBinary::FPART_PROP fpartProp = m_listColumns.at(nColumn); 85 | 86 | if (fpartProp == XBinary::FPART_PROP_ORIGINALNAME) { 87 | result = rec.mapProperties.value(fpartProp).toString(); 88 | } else if ((fpartProp == XBinary::FPART_PROP_COMPRESSEDSIZE) || (fpartProp == XBinary::FPART_PROP_UNCOMPRESSEDSIZE)) { 89 | result = rec.mapProperties.value(fpartProp).toLongLong(); 90 | } else if (fpartProp == XBinary::FPART_PROP_STREAMOFFSET) { 91 | result = rec.nStreamOffset; 92 | } else if (fpartProp == XBinary::FPART_PROP_STREAMSIZE) { 93 | result = rec.nStreamSize; 94 | } else if (fpartProp == XBinary::FPART_PROP_COMPRESSMETHOD) { 95 | result = XBinary::compressMethodToString((XBinary::COMPRESS_METHOD)rec.mapProperties.value(fpartProp).toInt()); 96 | } 97 | } 98 | 99 | // if (nColumn == COLUMN_NAME) { 100 | // if (rec.mapProperties.contains(XBinary::FPART_PROP_ORIGINALNAME)) { 101 | // result = rec.mapProperties.value(XBinary::FPART_PROP_ORIGINALNAME).toString(); 102 | // } 103 | // } else if (nColumn == COLUMN_STREAMOFFSET) { 104 | // result = QString::number(rec.nStreamOffset, 16); 105 | // } else if (nColumn == COLUMN_STREAMSIZE) { 106 | // result = QString::number(rec.nStreamSize, 16); 107 | // // } else if (nColumn == COLUMN_DECOMPRESSEDOFFSET) { 108 | // // result = QString::number(rec.nDecompressedOffset, 16); 109 | // // } else if (nColumn == COLUMN_DECOMPRESSEDSIZE) { 110 | // // result = QString::number(rec.nDecompressedSize, 16); 111 | // } else if (nColumn == COLUMN_COMPRESSMETHOD) { 112 | // if (rec.mapProperties.contains(XBinary::FPART_PROP_COMPRESSMETHOD)) { 113 | // XBinary::COMPRESS_METHOD cm = (XBinary::COMPRESS_METHOD)rec.mapProperties.value(XBinary::FPART_PROP_COMPRESSMETHOD).toInt(); 114 | // result = XBinary::compressMethodToString(cm); 115 | // } 116 | // } else if (nColumn == COLUMN_CRC) { 117 | // if (rec.mapProperties.contains(XBinary::FPART_PROP_CRC_VALUE)) { 118 | // quint32 nCRC = rec.mapProperties.value(XBinary::FPART_PROP_CRC_VALUE).toUInt(); 119 | // result = QString::number(nCRC, 16); 120 | // } 121 | // } else if (nColumn == COLUMN_DATETIME) { 122 | // if (rec.mapProperties.contains(XBinary::FPART_PROP_DATETIME)) { 123 | // QDateTime dt = rec.mapProperties.value(XBinary::FPART_PROP_DATETIME).toDateTime(); 124 | // if (dt.isValid()) { 125 | // result = dt.toString("yyyy-MM-dd HH:mm:ss"); 126 | // } 127 | // } 128 | // } 129 | } else if (nRole == Qt::TextAlignmentRole) { 130 | result = getColumnAlignment(nColumn); 131 | } else if (nRole >= Qt::UserRole) { 132 | if (nRole == (Qt::UserRole + XModel::USERROLE_ORIGINDEX)) { 133 | result = nRow; 134 | } else if (nRole == (Qt::UserRole + XModel::USERROLE_OFFSET)) { 135 | result = rec.nStreamOffset; 136 | } else if (nRole == (Qt::UserRole + XModel::USERROLE_SIZE)) { 137 | result = rec.nStreamSize; 138 | } else if (nRole == (Qt::UserRole + XModel::USERROLE_STRING1)) { 139 | if (rec.mapProperties.contains(XBinary::FPART_PROP_ORIGINALNAME)) { 140 | result = rec.mapProperties.value(XBinary::FPART_PROP_ORIGINALNAME).toString(); 141 | } 142 | } 143 | } 144 | } 145 | } 146 | 147 | return result; 148 | } 149 | 150 | QVariant XModel_ArchiveRecords::headerData(int nSection, Qt::Orientation orientation, int nRole) const 151 | { 152 | QVariant result; 153 | 154 | if (orientation == Qt::Horizontal) { 155 | if (nRole == Qt::DisplayRole) { 156 | result = getColumnName(nSection); 157 | } else if (nRole == Qt::TextAlignmentRole) { 158 | result = getColumnAlignment(nSection); 159 | } 160 | } 161 | 162 | return result; 163 | } 164 | -------------------------------------------------------------------------------- /xbinaryview.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2019-2025 hors 2 | * 3 | * Permission is hereby granted, free of charge, to any person obtaining a copy 4 | * of this software and associated documentation files (the "Software"), to deal 5 | * in the Software without restriction, including without limitation the rights 6 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | * copies of the Software, and to permit persons to whom the Software is 8 | * furnished to do so, subject to the following conditions: 9 | * 10 | * The above copyright notice and this permission notice shall be included in all 11 | * copies or substantial portions of the Software. 12 | * 13 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 19 | * SOFTWARE. 20 | */ 21 | #include "xbinaryview.h" 22 | 23 | XBinaryView::XBinaryView(QObject *pParent) : QObject(pParent) 24 | { 25 | m_pDevice = nullptr; 26 | m_options = {}; 27 | m_nViewSize = 0; 28 | } 29 | 30 | XBinaryView::~XBinaryView() 31 | { 32 | } 33 | 34 | void XBinaryView::setData(QIODevice *pDevice, const OPTIONS &options) 35 | { 36 | m_pDevice = pDevice; 37 | m_options = options; 38 | 39 | m_disasmCore.setMode(m_options.disasmMode); 40 | 41 | m_memoryMap = XFormats::getMemoryMap(m_options.fileType, XBinary::MAPMODE_UNKNOWN, m_pDevice); 42 | 43 | XVPOS nViewPos = 0; 44 | 45 | bool bAll = false; 46 | 47 | if (pDevice) { 48 | if (m_options.nTotalSize <= 0) { 49 | m_options.nTotalSize = pDevice->size() - m_options.nStartOffset; 50 | } 51 | 52 | if ((m_options.nStartOffset == 0) && (m_options.nTotalSize == pDevice->size())) { 53 | bAll = true; 54 | } 55 | } 56 | 57 | m_listViewStruct.clear(); 58 | 59 | qint32 nNumberOfRecords = m_memoryMap.listRecords.count(); 60 | for (qint32 i = 0; i < nNumberOfRecords; i++) { 61 | VIEWSTRUCT record = {}; 62 | record.nAddress = m_memoryMap.listRecords.at(i).nAddress; 63 | record.nOffset = m_memoryMap.listRecords.at(i).nOffset; 64 | record.nSize = m_memoryMap.listRecords.at(i).nSize; 65 | // record.nScrollStart = nScrollStart; 66 | record.nViewPos = nViewPos; 67 | // record.nScrollCount = record.nSize; 68 | 69 | bool bAdd = true; 70 | // // TODO XInfoDB 71 | 72 | if (m_memoryMap.listRecords.at(i).bIsInvisible) { 73 | bAdd = false; 74 | } 75 | 76 | if (!m_options.bShowVirtual) { 77 | if (m_memoryMap.listRecords.at(i).bIsVirtual) { 78 | bAdd = false; 79 | } 80 | } 81 | 82 | // Add if m_nStartOffset and qint64 m_nTotalSize in this viewStruct 83 | if (!bAll) { 84 | if (record.nOffset != -1) { 85 | if (record.nOffset >= m_options.nStartOffset && (record.nOffset + record.nSize <= m_options.nStartOffset + m_options.nTotalSize)) { 86 | bAdd = true; 87 | } else { 88 | bAdd = false; 89 | } 90 | } 91 | } 92 | 93 | // Add if m_nStartOffset and qint64 m_nTotalSize partially in this viewStruct, correct nAddress, nOffset, nSize 94 | if (!bAll) { 95 | if (record.nOffset != -1) { 96 | if (record.nOffset < m_options.nStartOffset && (record.nOffset + record.nSize > m_options.nStartOffset)) { 97 | record.nAddress += m_options.nStartOffset - record.nOffset; 98 | record.nOffset = m_options.nStartOffset; 99 | record.nSize -= m_options.nStartOffset - record.nOffset; 100 | bAdd = true; 101 | } 102 | if (record.nOffset < m_options.nStartOffset + m_options.nTotalSize && (record.nOffset + record.nSize > m_options.nStartOffset + m_options.nTotalSize)) { 103 | record.nSize = m_options.nStartOffset + m_options.nTotalSize - record.nOffset; 104 | bAdd = true; 105 | } 106 | } 107 | } 108 | 109 | if (bAdd) { 110 | nViewPos += record.nSize; 111 | 112 | m_listViewStruct.append(record); 113 | } 114 | } 115 | 116 | m_nViewSize = nViewPos; 117 | } 118 | 119 | void XBinaryView::reset() 120 | { 121 | m_pDevice = nullptr; 122 | m_options = {}; 123 | m_nViewSize = 0; 124 | m_listViewStruct.clear(); 125 | } 126 | 127 | QIODevice *XBinaryView::getDevice() 128 | { 129 | return m_pDevice; 130 | } 131 | 132 | XBinaryView::VIEWSTRUCT XBinaryView::_getViewStructByViewPos(XVPOS nViewPos) 133 | { 134 | VIEWSTRUCT result = {}; 135 | 136 | qint32 nNumberOfRecords = m_listViewStruct.count(); 137 | 138 | for (qint32 i = 0; i < nNumberOfRecords; i++) { 139 | if ((m_listViewStruct.at(i).nViewPos <= nViewPos) && (nViewPos < (m_listViewStruct.at(i).nViewPos + m_listViewStruct.at(i).nSize))) { 140 | result = m_listViewStruct.at(i); 141 | break; 142 | } 143 | } 144 | 145 | return result; 146 | } 147 | 148 | XBinaryView::VIEWSTRUCT XBinaryView::_getViewStructByAddress(XADDR nAddress) 149 | { 150 | VIEWSTRUCT result = {}; 151 | 152 | qint32 nNumberOfRecords = m_listViewStruct.count(); 153 | 154 | for (qint32 i = 0; i < nNumberOfRecords; i++) { 155 | if ((m_listViewStruct.at(i).nAddress != (XADDR)-1) && (m_listViewStruct.at(i).nAddress <= nAddress) && 156 | (nAddress < (m_listViewStruct.at(i).nAddress + m_listViewStruct.at(i).nSize))) { 157 | result = m_listViewStruct.at(i); 158 | break; 159 | } 160 | } 161 | 162 | return result; 163 | } 164 | 165 | XBinaryView::VIEWSTRUCT XBinaryView::_getViewStructByOffset(qint64 nOffset) 166 | { 167 | VIEWSTRUCT result = {}; 168 | 169 | qint32 nNumberOfRecords = m_listViewStruct.count(); 170 | 171 | for (qint32 i = 0; i < nNumberOfRecords; i++) { 172 | if ((m_listViewStruct.at(i).nOffset != -1) && (m_listViewStruct.at(i).nOffset <= nOffset) && 173 | (nOffset < (m_listViewStruct.at(i).nOffset + m_listViewStruct.at(i).nSize))) { 174 | result = m_listViewStruct.at(i); 175 | break; 176 | } 177 | } 178 | 179 | return result; 180 | } 181 | 182 | XVPOS XBinaryView::deviceOffsetToViewPos(qint64 nOffset) 183 | { 184 | XVPOS nResult = 0; 185 | 186 | VIEWSTRUCT viewStruct = _getViewStructByOffset(nOffset); 187 | 188 | if (viewStruct.nSize) { 189 | nResult = viewStruct.nViewPos + (nOffset - viewStruct.nOffset); 190 | } 191 | 192 | return nResult; 193 | } 194 | 195 | qint64 XBinaryView::viewPosToDeviceOffset(XVPOS nViewPos) 196 | { 197 | qint64 nResult = -1; 198 | 199 | VIEWSTRUCT viewStruct = _getViewStructByViewPos(nViewPos); 200 | 201 | if (viewStruct.nSize && (viewStruct.nOffset != -1)) { 202 | nResult = viewStruct.nOffset + (nViewPos - viewStruct.nViewPos); 203 | } 204 | 205 | return nResult; 206 | } 207 | 208 | XADDR XBinaryView::viewPosToAddress(XVPOS nViewPos) 209 | { 210 | XADDR nResult = -1; 211 | 212 | VIEWSTRUCT viewStruct = _getViewStructByViewPos(nViewPos); 213 | 214 | if (viewStruct.nSize && (viewStruct.nOffset != -1)) { 215 | nResult = viewStruct.nAddress + (nViewPos - viewStruct.nViewPos); 216 | } 217 | 218 | return nResult; 219 | } 220 | 221 | bool XBinaryView::isViewPosValid(XVPOS nViewPos) 222 | { 223 | bool bResult = false; 224 | 225 | if ((nViewPos >= 0) && (nViewPos < (XVPOS)m_nViewSize)) { 226 | bResult = true; 227 | } 228 | 229 | return bResult; 230 | } 231 | 232 | bool XBinaryView::isEnd(XVPOS nOffset) 233 | { 234 | return (nOffset == m_nViewSize); 235 | } 236 | 237 | qint64 XBinaryView::getViewSizeByViewPos(XVPOS nViewPos) 238 | { 239 | Q_UNUSED(nViewPos) 240 | 241 | return 1; 242 | } 243 | 244 | XVPOS XBinaryView::addressToViewPos(XADDR nAddress) 245 | { 246 | qint64 nResult = 0; 247 | 248 | qint64 nOffset = XBinary::addressToOffset(getMemoryMap(), nAddress); 249 | 250 | nResult = deviceOffsetToViewPos(nOffset); 251 | 252 | return nResult; 253 | } 254 | 255 | XVPOS XBinaryView::locationToViewPos(XADDR nLocation, XBinary::LT locationType) 256 | { 257 | XVPOS nResult = 0; 258 | 259 | if (locationType == XBinary::LT_ADDRESS) { 260 | qint64 nOffset = XBinary::addressToOffset(getMemoryMap(), nLocation); 261 | nResult = deviceOffsetToViewPos(nOffset); 262 | } else if (locationType == XBinary::LT_RELADDRESS) { 263 | qint64 nOffset = XBinary::relAddressToOffset(getMemoryMap(), nLocation); 264 | nResult = deviceOffsetToViewPos(nOffset); 265 | } else if (locationType == XBinary::LT_OFFSET) { 266 | nResult = deviceOffsetToViewPos(nLocation); 267 | } 268 | 269 | return nResult; 270 | } 271 | 272 | qint64 XBinaryView::getViewSize() 273 | { 274 | return m_nViewSize; 275 | } 276 | 277 | XBinary::_MEMORY_MAP *XBinaryView::getMemoryMap() 278 | { 279 | return &m_memoryMap; 280 | } 281 | 282 | XDisasmCore *XBinaryView::getDisasmCore() 283 | { 284 | return &m_disasmCore; 285 | } 286 | 287 | XBinaryView::OPTIONS *XBinaryView::getOptions() 288 | { 289 | return &m_options; 290 | } 291 | -------------------------------------------------------------------------------- /xabstracttableview.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2020-2025 hors 2 | * 3 | * Permission is hereby granted, free of charge, to any person obtaining a copy 4 | * of this software and associated documentation files (the "Software"), to deal 5 | * in the Software without restriction, including without limitation the rights 6 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | * copies of the Software, and to permit persons to whom the Software is 8 | * furnished to do so, subject to the following conditions: 9 | * 10 | * The above copyright notice and this permission notice shall be included in 11 | * all copies or substantial portions of the Software. 12 | * 13 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 19 | * SOFTWARE. 20 | */ 21 | #ifndef XABSTRACTTABLEVIEW_H 22 | #define XABSTRACTTABLEVIEW_H 23 | 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include 31 | #include 32 | #include 33 | #include 34 | #include 35 | #include 36 | #include 37 | 38 | #include "xshortcutstscrollarea.h" 39 | 40 | class XAbstractTableView : public XShortcutstScrollArea { 41 | Q_OBJECT 42 | 43 | public: 44 | struct COLUMN { 45 | bool bEnable; 46 | qreal nLeft; 47 | qreal nWidth; 48 | QString sTitle; 49 | bool bClickable; 50 | }; 51 | 52 | enum PT { 53 | PT_UNKNOWN = 0, 54 | PT_HEADER, 55 | PT_CELL, 56 | PT_MAP, 57 | PT_MAPHEADER, 58 | // TODO Check more 59 | }; 60 | 61 | struct CURSOR_POSITION { 62 | bool bIsValid; 63 | PT ptype; 64 | qint32 nY; 65 | qint32 nX; 66 | qint32 nRow; 67 | qint32 nColumn; 68 | qint32 nAreaTop; 69 | qint32 nAreaLeft; 70 | qint32 nPercentage; 71 | bool bResizeColumn; 72 | }; 73 | 74 | struct STATE { 75 | // qint64 nCursorViewPos; 76 | QVariant varCursorExtraInfo; 77 | XVPOS nSelectionViewPos; 78 | qint64 nSelectionViewSize; 79 | CURSOR_POSITION cursorPosition; 80 | }; 81 | 82 | struct OS { 83 | XVPOS nViewPos; 84 | qint64 nSize; 85 | QVariant varData; 86 | }; 87 | 88 | enum XCOLOR { 89 | XCOLOR_NORMALTEXT = 0, 90 | XCOLOR_NORMALTEXTBACKGROUND 91 | }; 92 | 93 | struct PAINT_STATISTICS { 94 | qint64 nPaintCount; 95 | qint64 nTotalPaintTime; 96 | qint64 nMinPaintTime; 97 | qint64 nMaxPaintTime; 98 | qint64 nLastPaintTime; 99 | }; 100 | 101 | explicit XAbstractTableView(QWidget *pParent = nullptr); 102 | ~XAbstractTableView(); 103 | 104 | void setActive(bool bIsActive); 105 | bool isActive(); 106 | // void setEnabled(bool bEnabled); 107 | void clear(); 108 | 109 | void addColumn(const QString &sTitle, qint32 nWidth = 0, bool bClickable = false, bool bEnable = true); 110 | void setColumnTitle(qint32 nNumber, const QString &sTitle); 111 | void setColumnEnabled(qint32 nNumber, bool bState); 112 | void setColumnWidth(qint32 nNumber, qint32 nWidth); 113 | qint32 getColumnWidth(qint32 nNumber); 114 | 115 | void reload(bool bUpdateData = false); 116 | virtual void reloadData(bool bSaveSelection) override; 117 | 118 | void setTextFont(const QFont &font); 119 | QFont getTextFont(); 120 | 121 | bool setTextFontFromOptions(XOptions::ID id); 122 | void setTotalScrollCount(qint64 nValue); 123 | quint64 getTotalScrollCount(); 124 | 125 | void setLineDelta(qint32 nValue); 126 | void setSideDelta(qint32 nValue); 127 | qint32 getLinesProPage(); 128 | 129 | void setViewPosStart(qint64 nValue); 130 | XVPOS getViewPosStart(); 131 | 132 | qreal getCharWidth(); 133 | 134 | CURSOR_POSITION getCursorPosition(const QPoint &pos); 135 | 136 | bool isViewPosSelected(XVPOS nViewPos); 137 | QPainter *getBoldTextPointer(); 138 | qint32 getLineDelta(); 139 | qint32 getSideDelta(); 140 | STATE getState(); 141 | void setState(STATE state); 142 | 143 | // qint64 getCursorViewPos(); 144 | // void setCursorViewPos(qint64 nViewPos, qint32 nColumn = -1, QVariant varCursorExtraInfo = QVariant()); 145 | void adjust(bool bUpdateData = false); 146 | 147 | // void setCursorData(QRect rectSquare, QRect rectText, const QString &sText, qint32 nDelta); 148 | // void resetCursorData(); 149 | 150 | // qint32 getCursorDelta(); 151 | 152 | qint64 getMaxScrollValue(); 153 | void setLastColumnStretch(bool bState); 154 | void setHeaderVisible(bool bState); 155 | void setColumnFixed(bool bState); 156 | void setVerticalLinesVisible(bool bState); 157 | void setHorisontalLinesVisible(bool bState); 158 | 159 | qint64 getSelectionInitOffset(); 160 | qint64 getSelectionInitSize(); 161 | void setCurrentBlock(qint64 nViewPos, qint64 nSize); 162 | bool isViewPosInCurrentBlock(qint64 nViewPos); 163 | qreal getLineHeight(); 164 | qreal getHeaderHeight(); 165 | void setHeaderHeight(qreal nHeight); 166 | void setSelectionEnable(bool bState); 167 | void setContextMenuEnable(bool bState); 168 | bool isContextMenuEnable(); 169 | // void setBlinkingCursor(bool bState); 170 | // void setBlinkingCursorEnable(bool bState); 171 | void _verticalScroll(); 172 | bool isSelectionEnable(); 173 | void setMaxSelectionViewSize(qint64 nMaxSelectionViewSize); 174 | void setMapEnable(bool bState); 175 | bool isMapEnable(); 176 | void setMapWidth(qint32 nWidth); 177 | qreal getMapWidth(); 178 | void setMapCount(qint32 nMapCount); 179 | qint32 getMapCount(); 180 | 181 | void enablePaintStatistics(bool bEnable); 182 | bool isPaintStatisticsEnabled() const; 183 | PAINT_STATISTICS getPaintStatistics() const; 184 | void resetPaintStatistics(); 185 | 186 | virtual QList getMenuItems(); 187 | 188 | signals: 189 | void cursorViewPosChanged(qint64 nViewPos); 190 | void selectionChanged(); 191 | void errorMessage(const QString &sText); 192 | void infoMessage(const QString &sText); 193 | void headerClicked(qint32 nNumber); 194 | void cellDoubleClicked(qint32 nRow, qint32 nColumn); 195 | 196 | protected: 197 | void _initSelection(XVPOS nViewPos, qint64 nSize); 198 | void _setSelection(XVPOS nViewPos, qint64 nSize); 199 | void _initSetSelection(XVPOS nViewPos, qint64 nSize); 200 | 201 | private slots: 202 | void verticalScroll(); 203 | void horisontalScroll(); 204 | void _customContextMenu(const QPoint &pos); 205 | // void updateBlink(); 206 | 207 | protected slots: 208 | void _copyValueSlot(); // TODO 209 | 210 | protected: 211 | virtual void paintEvent(QPaintEvent *pEvent) override; 212 | virtual void resizeEvent(QResizeEvent *pEvent) override; 213 | virtual void mouseMoveEvent(QMouseEvent *pEvent) override; 214 | virtual void mousePressEvent(QMouseEvent *pEvent) override; 215 | virtual void mouseReleaseEvent(QMouseEvent *pEvent) override; 216 | virtual void mouseDoubleClickEvent(QMouseEvent *pEvent) override; 217 | virtual void keyPressEvent(QKeyEvent *pEvent) override; 218 | virtual void wheelEvent(QWheelEvent *pEvent) override; 219 | virtual bool isViewPosValid(XVPOS nViewPos); 220 | virtual bool isEnd(XVPOS nViewPos); 221 | virtual OS cursorPositionToOS(const CURSOR_POSITION &cursorPosition); 222 | virtual void updateData(); 223 | virtual void startPainting(QPainter *pPainter); 224 | virtual void paintColumn(QPainter *pPainter, qint32 nColumn, qint32 nLeft, qint32 nTop, qint32 nWidth, qint32 nHeight); 225 | virtual void paintMap(QPainter *pPainter, qint32 nLeft, qint32 nTop, qint32 nWidth, qint32 nHeight); 226 | virtual void paintCell(QPainter *pPainter, qint32 nRow, qint32 nColumn, qint32 nLeft, qint32 nTop, qint32 nWidth, qint32 nHeight); 227 | virtual void paintTitle(QPainter *pPainter, qint32 nColumn, qint32 nLeft, qint32 nTop, qint32 nWidth, qint32 nHeight, const QString &sTitle); 228 | virtual void endPainting(QPainter *pPainter); 229 | virtual bool _goToViewPos(XVPOS nViewPos, bool bSaveCursor = false, bool bShort = false, bool bAprox = false); 230 | virtual XVPOS getCurrentViewPosFromScroll(); 231 | virtual void setCurrentViewPosToScroll(XVPOS nViewPos); 232 | virtual void adjustColumns(); 233 | virtual void adjustHeader(); 234 | virtual void _headerClicked(qint32 nNumber); 235 | virtual void _cellDoubleClicked(qint32 nRow, qint32 nColumn); 236 | virtual qint64 getFixViewPos(XVPOS nViewPos); 237 | virtual void adjustMap(); 238 | 239 | private: 240 | bool m_bIsActive; 241 | // bool m_bIsBlinkingCursorEnable; 242 | qint64 m_nNumberOfRows; 243 | QList m_listColumns; 244 | qreal m_nHeaderHeight; 245 | QPushButton m_pushButtonHeader; 246 | qint32 m_nXViewPos; 247 | XVPOS m_nViewPosStart; // TODO move to state 248 | qreal m_nCharWidth; 249 | qreal m_nCharHeight; 250 | qint32 m_nLinesProPage; 251 | qreal m_nLineHeight; 252 | QFont m_fontText; 253 | qint64 m_nTotalScrollCount; 254 | qint32 m_nViewWidth; 255 | qint32 m_nViewHeight; 256 | qint32 m_nTableWidth; 257 | qreal m_nLineDelta; 258 | qreal m_nSideDelta; 259 | 260 | STATE m_state; 261 | bool m_bMouseSelection; 262 | XVPOS m_nSelectionInitOffset; 263 | qint64 m_nSelectionInitSize; 264 | qint64 m_nMaxSelectionViewSize; 265 | bool m_bMouseResizeColumn; 266 | qint32 m_nResizeColumnNumber; 267 | bool m_bHeaderClickButton; 268 | qint32 m_nHeaderClickColumnNumber; 269 | 270 | // QTimer m_timerCursor; 271 | // QRect m_rectCursorSquare; 272 | // QRect m_rectCursorText; 273 | // QString m_sCursorText; 274 | // qint32 m_nCursorDelta; 275 | bool m_bBlink; 276 | bool m_bLastColumnStretch; 277 | bool m_bHeaderVisible; 278 | bool m_bColumnFixed; 279 | bool m_bVerticalLinesVisible; 280 | bool m_bHorisontalLinesVisible; 281 | bool m_bIsMapEnable; 282 | qreal m_nMapWidth; 283 | qint32 m_nMapCount; 284 | qint64 m_nCurrentBlockViewPos; 285 | qint64 m_nCurrentBlockViewSize; 286 | bool m_bIsSelectionEnable; 287 | bool m_bIsContextMenuEnable; 288 | bool m_bPaintStatisticsEnabled; 289 | PAINT_STATISTICS m_paintStatistics; 290 | }; 291 | 292 | #endif // XABSTRACTTABLEVIEW_H 293 | -------------------------------------------------------------------------------- /xcomboboxex.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2017-2025 hors 2 | * 3 | * Permission is hereby granted, free of charge, to any person obtaining a copy 4 | * of this software and associated documentation files (the "Software"), to deal 5 | * in the Software without restriction, including without limitation the rights 6 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | * copies of the Software, and to permit persons to whom the Software is 8 | * furnished to do so, subject to the following conditions: 9 | * 10 | * The above copyright notice and this permission notice shall be included in 11 | * all copies or substantial portions of the Software. 12 | * 13 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 19 | * SOFTWARE. 20 | */ 21 | #include "xcomboboxex.h" 22 | 23 | XComboBoxEx::XComboBoxEx(QWidget *pParent) : QComboBox(pParent) 24 | { 25 | m_bIsReadonly = false; 26 | m_cbtype = CBTYPE_LIST; 27 | 28 | SubclassOfQStyledItemDelegate *pDelegate = new SubclassOfQStyledItemDelegate(this); 29 | setItemDelegate(pDelegate); 30 | 31 | connect(this, SIGNAL(currentIndexChanged(int)), this, SLOT(currentIndexChangedSlot(int))); 32 | connect(&m_model, SIGNAL(itemChanged(QStandardItem *)), this, SLOT(itemChangedSlot(QStandardItem *))); 33 | } 34 | 35 | void XComboBoxEx::setData(const QMap &mapData, CBTYPE cbtype, quint64 nMask, const QString &sTitle) 36 | { 37 | m_cbtype = cbtype; 38 | m_nMask = nMask; 39 | 40 | m_mapData = mapData; 41 | 42 | m_model.clear(); 43 | m_model.setColumnCount(1); 44 | 45 | m_model.setRowCount(mapData.count() + 1); 46 | 47 | if ((cbtype == CBTYPE_LIST) || (cbtype == CBTYPE_ELIST)) { 48 | m_model.setItem(0, 0, new QStandardItem("")); // Empty 49 | } else if ((cbtype == CBTYPE_FLAGS) || (cbtype == CBTYPE_CUSTOM_FLAGS)) { 50 | QString _sTitle = sTitle; 51 | 52 | if (_sTitle == "") { 53 | _sTitle = tr("Flags"); 54 | } 55 | 56 | m_model.setItem(0, 0, new QStandardItem(_sTitle)); 57 | } 58 | 59 | qint32 nIndex = 1; 60 | 61 | QMapIterator iter(mapData); 62 | 63 | while (iter.hasNext()) { 64 | iter.next(); 65 | 66 | QStandardItem *pItem = new QStandardItem(iter.value()); 67 | pItem->setData(iter.key(), Qt::UserRole); 68 | 69 | if (cbtype == CBTYPE_FLAGS) { 70 | pItem->setFlags(Qt::ItemIsUserCheckable | Qt::ItemIsEnabled); 71 | pItem->setData(Qt::Unchecked, Qt::CheckStateRole); 72 | } 73 | 74 | m_model.setItem(nIndex, 0, pItem); 75 | 76 | nIndex++; 77 | } 78 | 79 | setModel(&m_model); 80 | } 81 | 82 | void XComboBoxEx::setValue(QVariant varValue) 83 | { 84 | this->m_varValue = varValue; 85 | 86 | qint32 nNumberOfItems = m_model.rowCount(); 87 | 88 | if (m_cbtype == CBTYPE_LIST) { 89 | bool bFound = false; 90 | 91 | for (qint32 i = 1; i < nNumberOfItems; i++) { 92 | quint64 _nValue = m_model.item(i, 0)->data(Qt::UserRole).toULongLong(); 93 | 94 | if (_nValue == varValue) { 95 | setCurrentIndex(i); 96 | bFound = true; 97 | break; 98 | } 99 | } 100 | 101 | if (!bFound) { 102 | setCurrentIndex(0); 103 | } 104 | } else if (m_cbtype == CBTYPE_ELIST) { 105 | bool bFound = false; 106 | quint64 nValue = varValue.toULongLong(); 107 | 108 | for (qint32 i = 1; i < nNumberOfItems; i++) { 109 | quint64 _nValue = m_model.item(i, 0)->data(Qt::UserRole).toULongLong(); 110 | nValue &= m_nMask; 111 | 112 | if (_nValue == nValue) { 113 | setCurrentIndex(i); 114 | bFound = true; 115 | break; 116 | } 117 | } 118 | 119 | if (!bFound) { 120 | setCurrentIndex(0); 121 | } 122 | } else if (m_cbtype == CBTYPE_FLAGS) { 123 | quint64 nValue = varValue.toULongLong(); 124 | 125 | for (qint32 i = 1; i < nNumberOfItems; i++) { 126 | quint64 _nValue = m_model.item(i, 0)->data(Qt::UserRole).toULongLong(); 127 | 128 | if (_nValue & nValue) { 129 | m_model.item(i, 0)->setData(Qt::Checked, Qt::CheckStateRole); 130 | } else { 131 | m_model.item(i, 0)->setData(Qt::Unchecked, Qt::CheckStateRole); 132 | } 133 | } 134 | } 135 | } 136 | 137 | QVariant XComboBoxEx::getValue() 138 | { 139 | return m_varValue; 140 | } 141 | 142 | void XComboBoxEx::setReadOnly(bool bIsReadOnly) 143 | { 144 | this->m_bIsReadonly = bIsReadOnly; 145 | 146 | qint32 nNumberOfItems = m_model.rowCount(); 147 | 148 | if (m_cbtype == CBTYPE_FLAGS) { 149 | for (qint32 i = 0; i < nNumberOfItems; i++) { 150 | if (bIsReadOnly) { 151 | m_model.item(i, 0)->setFlags(Qt::ItemIsEnabled); 152 | } else { 153 | m_model.item(i, 0)->setFlags(Qt::ItemIsUserCheckable | Qt::ItemIsEnabled); 154 | } 155 | } 156 | } 157 | } 158 | 159 | QString XComboBoxEx::getDescription() 160 | { 161 | QString sResult; 162 | 163 | if (m_cbtype == CBTYPE_LIST) { 164 | sResult = m_mapData.value(m_varValue.toULongLong()); 165 | } else if (m_cbtype == CBTYPE_ELIST) { 166 | sResult = m_mapData.value(m_varValue.toULongLong() & m_nMask); 167 | } 168 | if (m_cbtype == CBTYPE_FLAGS) { 169 | qint32 nNumberOfItems = m_model.rowCount(); 170 | 171 | for (qint32 i = 1; i < nNumberOfItems; i++) { 172 | if (m_model.item(i, 0)->data(Qt::CheckStateRole).toInt() == Qt::Checked) { 173 | if (sResult != "") { 174 | sResult += " | "; 175 | } 176 | 177 | sResult += m_mapData.value(m_model.item(i, 0)->data(Qt::UserRole).toULongLong()); 178 | } 179 | } 180 | } 181 | 182 | return sResult; 183 | } 184 | 185 | void XComboBoxEx::addCustomFlags(const QString &sTitle, const QList &listCustomFlags) 186 | { 187 | m_model.clear(); 188 | 189 | m_cbtype = CBTYPE_CUSTOM_FLAGS; 190 | 191 | m_model.setColumnCount(1); 192 | m_model.setItem(0, 0, new QStandardItem(sTitle)); 193 | 194 | qint32 nNumberOfRecords = listCustomFlags.count(); 195 | 196 | for (qint32 i = 0; i < nNumberOfRecords; i++) { 197 | QStandardItem *pItem = new QStandardItem(listCustomFlags.at(i).sString); 198 | pItem->setData(listCustomFlags.at(i).nValue, Qt::UserRole); 199 | 200 | if (listCustomFlags.at(i).bIsReadOnly) { 201 | pItem->setFlags(Qt::ItemIsUserCheckable); 202 | } else { 203 | pItem->setFlags(Qt::ItemIsUserCheckable | Qt::ItemIsEnabled); 204 | } 205 | 206 | if (listCustomFlags.at(i).bIsChecked) { 207 | pItem->setData(Qt::Checked, Qt::CheckStateRole); 208 | } else { 209 | pItem->setData(Qt::Unchecked, Qt::CheckStateRole); 210 | } 211 | 212 | m_model.setItem(i + 1, 0, pItem); 213 | } 214 | 215 | setModel(&m_model); 216 | } 217 | 218 | void XComboBoxEx::setCustomFlag(quint64 nValue) 219 | { 220 | qint64 nNumberOfRecords = m_model.rowCount(); 221 | 222 | for (qint32 i = 1; i < nNumberOfRecords; i++) { 223 | if (m_model.item(i, 0)->data(Qt::UserRole).toULongLong() == nValue) { 224 | setItemData(i, Qt::Checked, Qt::CheckStateRole); 225 | } 226 | } 227 | } 228 | 229 | QList XComboBoxEx::getCustomFlags() 230 | { 231 | QList listResult; 232 | 233 | qint32 nNumberOfRecords = m_model.rowCount(); 234 | 235 | for (qint32 i = 0; i < nNumberOfRecords; i++) { 236 | if (m_model.item(i)->data(Qt::CheckStateRole).toUInt() == Qt::Checked) { 237 | quint64 nValue = m_model.item(i)->data(Qt::UserRole).toULongLong(); 238 | 239 | listResult.append(nValue); 240 | } 241 | } 242 | 243 | return listResult; 244 | } 245 | 246 | void XComboBoxEx::_addCustomFlag(QList *pListCustomFlags, quint64 nValue, const QString &sString, bool bChecked) 247 | { 248 | CUSTOM_FLAG record = {}; 249 | 250 | record.nValue = nValue; 251 | record.sString = sString; 252 | record.bIsChecked = bChecked; 253 | 254 | pListCustomFlags->append(record); 255 | } 256 | 257 | void XComboBoxEx::setItemEnabled(qint32 nRow, bool bState) 258 | { 259 | m_model.item(nRow, 0)->setEnabled(bState); 260 | } 261 | 262 | void XComboBoxEx::currentIndexChangedSlot(int nIndex) 263 | { 264 | if (m_cbtype == CBTYPE_FLAGS) { 265 | if (nIndex) { 266 | setCurrentIndex(0); 267 | } 268 | } else if (m_cbtype == CBTYPE_ELIST) { 269 | if (!m_bIsReadonly) { 270 | if (nIndex) { 271 | quint64 nCurrentValue = itemData(nIndex).toULongLong(); 272 | 273 | quint64 _nValue = m_varValue.toULongLong(); 274 | 275 | _nValue &= (~m_nMask); 276 | 277 | _nValue |= nCurrentValue; 278 | 279 | if (_nValue != m_varValue.toULongLong()) { 280 | m_varValue = _nValue; 281 | emit valueChanged(m_varValue); 282 | } 283 | } 284 | } else { 285 | // restore 286 | setValue(m_varValue); 287 | } 288 | } else if (m_cbtype == CBTYPE_LIST) { 289 | if (!m_bIsReadonly) { 290 | if (nIndex) { 291 | QVariant vCurrentValue = itemData(nIndex); 292 | 293 | if (vCurrentValue != m_varValue) { 294 | m_varValue = vCurrentValue; 295 | emit valueChanged(m_varValue); 296 | } 297 | } 298 | } else { 299 | // restore ild value 300 | setValue(m_varValue); 301 | } 302 | } 303 | } 304 | 305 | void XComboBoxEx::itemChangedSlot(QStandardItem *pItem) 306 | { 307 | Q_UNUSED(pItem) 308 | 309 | if ((m_cbtype == CBTYPE_FLAGS) && count()) { 310 | quint64 nCurrentValue = m_varValue.toULongLong(); 311 | 312 | qint32 nNumberOfItems = m_model.rowCount(); 313 | 314 | for (qint32 i = 1; i < nNumberOfItems; i++) { 315 | if (m_model.item(i, 0)->data(Qt::CheckStateRole).toInt() == Qt::Checked) { 316 | nCurrentValue |= m_model.item(i, 0)->data(Qt::UserRole).toULongLong(); 317 | } else { 318 | nCurrentValue &= (0xFFFFFFFFFFFFFFFF ^ m_model.item(i, 0)->data(Qt::UserRole).toULongLong()); 319 | } 320 | } 321 | 322 | if (nCurrentValue != m_varValue.toULongLong()) { 323 | m_varValue = nCurrentValue; 324 | emit valueChanged(nCurrentValue); 325 | } 326 | } 327 | } 328 | -------------------------------------------------------------------------------- /xlineeditvalidator.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2017-2025 hors 2 | * 3 | * Permission is hereby granted, free of charge, to any person obtaining a copy 4 | * of this software and associated documentation files (the "Software"), to deal 5 | * in the Software without restriction, including without limitation the rights 6 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | * copies of the Software, and to permit persons to whom the Software is 8 | * furnished to do so, subject to the following conditions: 9 | * 10 | * The above copyright notice and this permission notice shall be included in 11 | * all copies or substantial portions of the Software. 12 | * 13 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 19 | * SOFTWARE. 20 | */ 21 | #include "xlineeditvalidator.h" 22 | 23 | XLineEditValidator::XLineEditValidator(QObject *pParent) : QValidator(pParent) 24 | { 25 | m_mode = MODE_HEX_32; 26 | m_nMaxValue = 0x7FFFFFFFFFFFFFFF; 27 | } 28 | 29 | void XLineEditValidator::setMode(XLineEditValidator::MODE mode) 30 | { 31 | m_mode = mode; 32 | } 33 | 34 | void XLineEditValidator::setMaxValue(qint64 nValue) 35 | { 36 | m_nMaxValue = nValue; 37 | } 38 | 39 | XLineEditValidator::MODE XLineEditValidator::getMode() 40 | { 41 | return m_mode; 42 | } 43 | 44 | QValidator::State XLineEditValidator::validate(QString &sInput, int &nPos) const 45 | { 46 | Q_UNUSED(nPos) 47 | 48 | QValidator::State result = Acceptable; 49 | 50 | if (!sInput.isEmpty()) { 51 | if ((m_mode == MODE_HEX_8) || (m_mode == MODE_DEC_8) || (m_mode == MODE_SIGN_DEC_8) || (m_mode == MODE_BIN_8) || (m_mode == MODE_HEX_16) || 52 | (m_mode == MODE_DEC_16) || (m_mode == MODE_SIGN_DEC_16) || (m_mode == MODE_BIN_16) || (m_mode == MODE_HEX_32) || (m_mode == MODE_DEC_32) || 53 | (m_mode == MODE_SIGN_DEC_32) || (m_mode == MODE_BIN_32) || (m_mode == MODE_HEX_64) || (m_mode == MODE_DEC_64) || (m_mode == MODE_SIGN_DEC_64) || 54 | (m_mode == MODE_BIN_64)) { 55 | qint64 nMax = 0; 56 | qint64 nMin = 0; 57 | qint32 nLenght = 0; 58 | // TODO Dec Lenght !!! 59 | 60 | // TODO optimize! 61 | if ((m_mode == MODE_HEX_8) || (m_mode == MODE_DEC_8) || (m_mode == MODE_BIN_8)) { 62 | nMax = UCHAR_MAX; 63 | nMin = 0; 64 | } else if (m_mode == MODE_SIGN_DEC_8) { 65 | nMax = SCHAR_MAX; 66 | nMin = SCHAR_MIN; 67 | } else if ((m_mode == MODE_HEX_16) || (m_mode == MODE_DEC_16) || (m_mode == MODE_BIN_16)) { 68 | nMax = USHRT_MAX; 69 | nMin = 0; 70 | } else if (m_mode == MODE_SIGN_DEC_16) { 71 | nMax = SHRT_MAX; 72 | nMin = SHRT_MIN; 73 | } else if ((m_mode == MODE_HEX_32) || (m_mode == MODE_DEC_32) || (m_mode == MODE_BIN_32)) { 74 | nMax = UINT_MAX; 75 | nMin = 0; 76 | } else if (m_mode == MODE_SIGN_DEC_32) { 77 | nMax = INT_MAX; 78 | nMin = INT_MIN; 79 | } else if ((m_mode == MODE_HEX_64) || (m_mode == MODE_DEC_64) || (m_mode == MODE_BIN_64)) { 80 | nMax = ULLONG_MAX; 81 | nMin = 0; 82 | } else if (m_mode == MODE_SIGN_DEC_64) { 83 | // TODO Check 84 | #ifdef LLONG_MAX 85 | nMax = LLONG_MAX; 86 | nMin = LLONG_MIN; 87 | #endif 88 | #ifdef LONG_LONG_MAX 89 | nMax = LONG_LONG_MAX; 90 | nMin = LONG_LONG_MIN; 91 | #endif 92 | } 93 | 94 | nMax = qMin(m_nMaxValue, nMax); 95 | 96 | if (m_mode == MODE_HEX_8) { 97 | nLenght = 2; 98 | } else if (m_mode == MODE_HEX_16) { 99 | nLenght = 4; 100 | } else if (m_mode == MODE_HEX_32) { 101 | nLenght = 8; 102 | } else if (m_mode == MODE_HEX_64) { 103 | nLenght = 16; 104 | } else if (m_mode == MODE_BIN_8) { 105 | nLenght = 8; 106 | } else if (m_mode == MODE_BIN_16) { 107 | nLenght = 16; 108 | } else if (m_mode == MODE_BIN_32) { 109 | nLenght = 32; 110 | } else if (m_mode == MODE_BIN_64) { 111 | nLenght = 64; 112 | } 113 | 114 | if ((m_mode == MODE_HEX_8) || (m_mode == MODE_HEX_16) || (m_mode == MODE_HEX_32) || (m_mode == MODE_HEX_64)) { 115 | result = Invalid; 116 | 117 | bool bSuccess = false; 118 | quint64 nValue = sInput.toULongLong(&bSuccess, 16); 119 | 120 | if (bSuccess && (sInput.length() <= nLenght)) { 121 | if (m_mode != MODE_HEX_64) { 122 | if ((qint64)nValue <= nMax) { 123 | result = Acceptable; 124 | } 125 | } else { 126 | result = Acceptable; 127 | } 128 | } 129 | } else if ((m_mode == MODE_DEC_8) || (m_mode == MODE_DEC_16) || (m_mode == MODE_DEC_32) || (m_mode == MODE_DEC_64)) { 130 | result = Invalid; 131 | 132 | bool bSuccess = false; 133 | quint64 nValue = sInput.toULongLong(&bSuccess, 10); 134 | 135 | if (bSuccess) { 136 | if (m_mode != MODE_DEC_64) { 137 | if ((qint64)nValue <= nMax) { 138 | result = Acceptable; 139 | } 140 | } else { 141 | result = Acceptable; 142 | } 143 | } 144 | } else if ((m_mode == MODE_SIGN_DEC_8) || (m_mode == MODE_SIGN_DEC_16) || (m_mode == MODE_SIGN_DEC_32) || (m_mode == MODE_SIGN_DEC_64)) { 145 | result = Invalid; 146 | 147 | bool bSuccess = false; 148 | qint64 nValue = sInput.toLongLong(&bSuccess, 10); 149 | 150 | if (bSuccess && (nValue <= nMax) && (nValue >= nMin)) { 151 | result = Acceptable; 152 | } else if (sInput == "-") { 153 | result = Intermediate; 154 | } 155 | } else if ((m_mode == MODE_BIN_8) || (m_mode == MODE_BIN_16) || (m_mode == MODE_BIN_32) || (m_mode == MODE_BIN_64)) { 156 | result = Invalid; 157 | 158 | bool bSuccess = false; 159 | quint64 nValue = binStringToValue(sInput, &bSuccess); 160 | 161 | if (bSuccess && (sInput.length() <= nLenght)) { 162 | if (m_mode != MODE_BIN_64) { 163 | if ((qint64)nValue <= nMax) { 164 | result = Acceptable; 165 | } 166 | } else { 167 | result = Acceptable; 168 | } 169 | } 170 | } 171 | } else if (m_mode == MODE_DOUBLE) { 172 | QDoubleValidator val; 173 | val.setLocale(QLocale::C); 174 | val.setNotation(QDoubleValidator::StandardNotation); 175 | result = val.validate(sInput, nPos); 176 | } else if (m_mode == MODE_UUID) { 177 | // TODO 178 | // NNNNNNNN-NNNN-NNNN-NNNN-NNNNNNNNNNNN 179 | // As 5 uints 180 | } 181 | } 182 | 183 | return result; 184 | } 185 | 186 | quint64 XLineEditValidator::binStringToValue(const QString &sString, bool *pbSuccess) 187 | { 188 | quint64 nResult = 0; 189 | 190 | bool bSuccess = false; 191 | if (pbSuccess == nullptr) { 192 | pbSuccess = &bSuccess; 193 | } 194 | 195 | *pbSuccess = true; 196 | 197 | qint32 nSize = sString.size(); 198 | 199 | quint64 nMask = 1; 200 | 201 | for (qint32 i = nSize - 1; i >= 0; i--) { 202 | if (sString.at(i) == QChar('1')) { 203 | nResult += nMask; 204 | } else if (sString.at(i) != QChar('0')) { 205 | *pbSuccess = false; 206 | break; 207 | } 208 | 209 | nMask <<= 1; 210 | } 211 | 212 | return nResult; 213 | } 214 | 215 | QString XLineEditValidator::value8ToBinString(quint8 nValue) 216 | { 217 | return _valueToBinString(nValue, 8); 218 | } 219 | 220 | QString XLineEditValidator::value16ToBinString(quint16 nValue) 221 | { 222 | return _valueToBinString(nValue, 16); 223 | } 224 | 225 | QString XLineEditValidator::value32ToBinString(quint32 nValue) 226 | { 227 | return _valueToBinString(nValue, 32); 228 | } 229 | 230 | QString XLineEditValidator::value64ToBinString(quint64 nValue) 231 | { 232 | return _valueToBinString(nValue, 64); 233 | } 234 | 235 | QString XLineEditValidator::_valueToBinString(quint64 nValue, qint32 nBits) 236 | { 237 | QString sResult; 238 | 239 | for (qint32 i = 0; i < nBits; i++) { 240 | if (nValue & 0x1) { 241 | sResult += "1"; 242 | } else { 243 | sResult += "0"; 244 | } 245 | nValue = nValue >> 1; 246 | } 247 | 248 | std::reverse(sResult.begin(), sResult.end()); 249 | 250 | return sResult; 251 | } 252 | 253 | QString XLineEditValidator::_valueToSizeString(quint64 nValue) 254 | { 255 | QString sResult; 256 | 257 | quint64 nBase = 1024; 258 | QString sValue; 259 | QString sUnit; 260 | 261 | if (nValue < nBase) { 262 | sValue = QString::number(nValue); 263 | sUnit = tr("Bytes"); 264 | } else if (nValue < (nBase * nBase)) { 265 | sValue = QString::number((double)nValue / nBase, 'f', 2); 266 | sUnit = tr("KiB"); 267 | } else if (nValue < (nBase * nBase * nBase)) { 268 | sValue = QString::number((double)nValue / (nBase * nBase), 'f', 2); 269 | sUnit = tr("MiB"); 270 | } else if (nValue < (nBase * nBase * nBase * nBase)) { 271 | sValue = QString::number((double)nValue / (nBase * nBase * nBase), 'f', 2); 272 | sUnit = tr("GiB"); 273 | } else { 274 | sValue = QString::number((double)nValue / (nBase * nBase * nBase * nBase), 'f', 2); 275 | sUnit = tr("TiB"); 276 | } 277 | 278 | sResult = QString("%1 %2").arg(sValue, sUnit); 279 | 280 | return sResult; 281 | } 282 | 283 | qint32 XLineEditValidator::getNumberOfBits(MODE mode) 284 | { 285 | qint32 nResult = 0; 286 | 287 | if ((mode == MODE_DEC_8) || (mode == MODE_SIGN_DEC_8) || (mode == MODE_BIN_8) || (mode == MODE_HEX_8)) { 288 | nResult = 8; 289 | } else if ((mode == MODE_DEC_16) || (mode == MODE_SIGN_DEC_16) || (mode == MODE_BIN_16) || (mode == MODE_HEX_16)) { 290 | nResult = 16; 291 | } else if ((mode == MODE_DEC_32) || (mode == MODE_SIGN_DEC_32) || (mode == MODE_BIN_32) || (mode == MODE_HEX_32)) { 292 | nResult = 32; 293 | } else if ((mode == MODE_DEC_64) || (mode == MODE_SIGN_DEC_64) || (mode == MODE_BIN_64) || (mode == MODE_HEX_64)) { 294 | nResult = 64; 295 | } 296 | 297 | return nResult; 298 | } 299 | -------------------------------------------------------------------------------- /dialogbits8.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2023-2025 hors 2 | * 3 | * Permission is hereby granted, free of charge, to any person obtaining a copy 4 | * of this software and associated documentation files (the "Software"), to deal 5 | * in the Software without restriction, including without limitation the rights 6 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | * copies of the Software, and to permit persons to whom the Software is 8 | * furnished to do so, subject to the following conditions: 9 | * 10 | * The above copyright notice and this permission notice shall be included in 11 | * all copies or substantial portions of the Software. 12 | * 13 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 19 | * SOFTWARE. 20 | */ 21 | #include "dialogbits8.h" 22 | #include "ui_dialogbits8.h" 23 | 24 | DialogBits8::DialogBits8(QWidget *pParent, bool bStayOnTop) : QDialog(pParent), ui(new Ui::DialogBits8) 25 | { 26 | ui->setupUi(this); 27 | 28 | Qt::WindowFlags flags = Qt::Window; 29 | 30 | if (bStayOnTop) { 31 | flags |= Qt::WindowStaysOnTopHint; 32 | } 33 | 34 | setWindowFlags(flags); 35 | 36 | m_nBits = 8; 37 | m_nValue = 0; 38 | m_bIsReadonly = true; 39 | 40 | ui->lineEditHex->setValidator(&m_validatorHex); 41 | ui->lineEditSigned->setValidator(&m_validatorSigned); 42 | ui->lineEditUnsigned->setValidator(&m_validatorUnsigned); 43 | ui->lineEditBin->setValidator(&m_validatorBin); 44 | 45 | _handleButton(ui->toolButton0); 46 | _handleButton(ui->toolButton1); 47 | _handleButton(ui->toolButton2); 48 | _handleButton(ui->toolButton3); 49 | _handleButton(ui->toolButton4); 50 | _handleButton(ui->toolButton5); 51 | _handleButton(ui->toolButton6); 52 | _handleButton(ui->toolButton7); 53 | _handleButton(ui->toolButton8); 54 | _handleButton(ui->toolButton9); 55 | _handleButton(ui->toolButton10); 56 | _handleButton(ui->toolButton11); 57 | _handleButton(ui->toolButton12); 58 | _handleButton(ui->toolButton13); 59 | _handleButton(ui->toolButton14); 60 | _handleButton(ui->toolButton15); 61 | _handleButton(ui->toolButton16); 62 | _handleButton(ui->toolButton17); 63 | _handleButton(ui->toolButton18); 64 | _handleButton(ui->toolButton19); 65 | _handleButton(ui->toolButton20); 66 | _handleButton(ui->toolButton21); 67 | _handleButton(ui->toolButton22); 68 | _handleButton(ui->toolButton23); 69 | _handleButton(ui->toolButton24); 70 | _handleButton(ui->toolButton25); 71 | _handleButton(ui->toolButton26); 72 | _handleButton(ui->toolButton27); 73 | _handleButton(ui->toolButton28); 74 | _handleButton(ui->toolButton29); 75 | _handleButton(ui->toolButton30); 76 | _handleButton(ui->toolButton31); 77 | _handleButton(ui->toolButton32); 78 | _handleButton(ui->toolButton33); 79 | _handleButton(ui->toolButton34); 80 | _handleButton(ui->toolButton35); 81 | _handleButton(ui->toolButton36); 82 | _handleButton(ui->toolButton37); 83 | _handleButton(ui->toolButton38); 84 | _handleButton(ui->toolButton39); 85 | _handleButton(ui->toolButton40); 86 | _handleButton(ui->toolButton41); 87 | _handleButton(ui->toolButton42); 88 | _handleButton(ui->toolButton43); 89 | _handleButton(ui->toolButton44); 90 | _handleButton(ui->toolButton45); 91 | _handleButton(ui->toolButton46); 92 | _handleButton(ui->toolButton47); 93 | _handleButton(ui->toolButton48); 94 | _handleButton(ui->toolButton49); 95 | _handleButton(ui->toolButton50); 96 | _handleButton(ui->toolButton51); 97 | _handleButton(ui->toolButton52); 98 | _handleButton(ui->toolButton53); 99 | _handleButton(ui->toolButton54); 100 | _handleButton(ui->toolButton55); 101 | _handleButton(ui->toolButton56); 102 | _handleButton(ui->toolButton57); 103 | _handleButton(ui->toolButton58); 104 | _handleButton(ui->toolButton59); 105 | _handleButton(ui->toolButton60); 106 | _handleButton(ui->toolButton61); 107 | _handleButton(ui->toolButton62); 108 | _handleButton(ui->toolButton63); 109 | 110 | ui->pushButtonCancel->setFocus(); 111 | } 112 | 113 | DialogBits8::~DialogBits8() 114 | { 115 | delete ui; 116 | } 117 | 118 | void DialogBits8::setReadonly(bool bIsReadonly) 119 | { 120 | m_bIsReadonly = bIsReadonly; 121 | ui->pushButtonOK->setEnabled(!m_bIsReadonly); 122 | } 123 | 124 | void DialogBits8::setValue_uint8(quint8 nValue) 125 | { 126 | m_nBits = 8; 127 | m_nValue = nValue; 128 | 129 | m_validatorHex.setMode(XLineEditValidator::MODE_HEX_8); 130 | m_validatorSigned.setMode(XLineEditValidator::MODE_SIGN_DEC_8); 131 | m_validatorUnsigned.setMode(XLineEditValidator::MODE_DEC_8); 132 | m_validatorBin.setMode(XLineEditValidator::MODE_BIN_8); 133 | 134 | ui->groupBox0_7->show(); 135 | ui->groupBox8_15->hide(); 136 | ui->groupBox16_23->hide(); 137 | ui->groupBox24_31->hide(); 138 | ui->groupBox32_39->hide(); 139 | ui->groupBox40_47->hide(); 140 | ui->groupBox48_55->hide(); 141 | ui->groupBox56_63->hide(); 142 | 143 | reload(); 144 | } 145 | 146 | void DialogBits8::setValue_uint16(quint16 nValue) 147 | { 148 | m_nBits = 16; 149 | m_nValue = nValue; 150 | 151 | m_validatorHex.setMode(XLineEditValidator::MODE_HEX_16); 152 | m_validatorSigned.setMode(XLineEditValidator::MODE_SIGN_DEC_16); 153 | m_validatorUnsigned.setMode(XLineEditValidator::MODE_DEC_16); 154 | m_validatorBin.setMode(XLineEditValidator::MODE_BIN_16); 155 | 156 | ui->groupBox0_7->show(); 157 | ui->groupBox8_15->show(); 158 | ui->groupBox16_23->hide(); 159 | ui->groupBox24_31->hide(); 160 | ui->groupBox32_39->hide(); 161 | ui->groupBox40_47->hide(); 162 | ui->groupBox48_55->hide(); 163 | ui->groupBox56_63->hide(); 164 | 165 | reload(); 166 | } 167 | 168 | void DialogBits8::setValue_uint32(quint32 nValue) 169 | { 170 | m_nBits = 32; 171 | m_nValue = nValue; 172 | 173 | m_validatorHex.setMode(XLineEditValidator::MODE_HEX_32); 174 | m_validatorSigned.setMode(XLineEditValidator::MODE_SIGN_DEC_32); 175 | m_validatorUnsigned.setMode(XLineEditValidator::MODE_DEC_32); 176 | m_validatorBin.setMode(XLineEditValidator::MODE_BIN_32); 177 | 178 | ui->groupBox0_7->show(); 179 | ui->groupBox8_15->show(); 180 | ui->groupBox16_23->show(); 181 | ui->groupBox24_31->show(); 182 | ui->groupBox32_39->hide(); 183 | ui->groupBox40_47->hide(); 184 | ui->groupBox48_55->hide(); 185 | ui->groupBox56_63->hide(); 186 | 187 | reload(); 188 | } 189 | 190 | void DialogBits8::setValue_uint64(quint64 nValue) 191 | { 192 | m_nBits = 64; 193 | m_nValue = nValue; 194 | 195 | m_validatorHex.setMode(XLineEditValidator::MODE_HEX_64); 196 | m_validatorSigned.setMode(XLineEditValidator::MODE_SIGN_DEC_64); 197 | m_validatorUnsigned.setMode(XLineEditValidator::MODE_DEC_64); 198 | m_validatorBin.setMode(XLineEditValidator::MODE_BIN_64); 199 | 200 | ui->groupBox0_7->show(); 201 | ui->groupBox8_15->show(); 202 | ui->groupBox16_23->show(); 203 | ui->groupBox24_31->show(); 204 | ui->groupBox32_39->show(); 205 | ui->groupBox40_47->show(); 206 | ui->groupBox48_55->show(); 207 | ui->groupBox56_63->show(); 208 | 209 | reload(); 210 | } 211 | 212 | void DialogBits8::reload() 213 | { 214 | enableControls(false); 215 | 216 | if (!(ui->lineEditHex->hasFocus())) { 217 | if (m_nBits == 8) { 218 | ui->lineEditHex->setText(QString::number((quint8)m_nValue, 16)); 219 | } else if (m_nBits == 16) { 220 | ui->lineEditHex->setText(QString::number((quint16)m_nValue, 16)); 221 | } else if (m_nBits == 32) { 222 | ui->lineEditHex->setText(QString::number((quint32)m_nValue, 16)); 223 | } else if (m_nBits == 64) { 224 | ui->lineEditHex->setText(QString::number((quint64)m_nValue, 16)); 225 | } 226 | } 227 | if (!(ui->lineEditSigned->hasFocus())) { 228 | if (m_nBits == 8) { 229 | ui->lineEditSigned->setText(QString::number((qint8)m_nValue, 10)); 230 | } else if (m_nBits == 16) { 231 | ui->lineEditSigned->setText(QString::number((qint16)m_nValue, 10)); 232 | } else if (m_nBits == 32) { 233 | ui->lineEditSigned->setText(QString::number((qint32)m_nValue, 10)); 234 | } else if (m_nBits == 64) { 235 | ui->lineEditSigned->setText(QString::number((qint64)m_nValue, 10)); 236 | } 237 | } 238 | if (!(ui->lineEditUnsigned->hasFocus())) { 239 | if (m_nBits == 8) { 240 | ui->lineEditUnsigned->setText(QString::number((quint8)m_nValue, 10)); 241 | } else if (m_nBits == 16) { 242 | ui->lineEditUnsigned->setText(QString::number((quint16)m_nValue, 10)); 243 | } else if (m_nBits == 32) { 244 | ui->lineEditUnsigned->setText(QString::number((quint32)m_nValue, 10)); 245 | } else if (m_nBits == 64) { 246 | ui->lineEditUnsigned->setText(QString::number((quint64)m_nValue, 10)); 247 | } 248 | } 249 | if (!(ui->lineEditBin->hasFocus())) { 250 | if (m_nBits == 8) { 251 | ui->lineEditBin->setText(XLineEditValidator::value8ToBinString((quint8)m_nValue)); 252 | } else if (m_nBits == 16) { 253 | ui->lineEditBin->setText(XLineEditValidator::value16ToBinString((quint16)m_nValue)); 254 | } else if (m_nBits == 32) { 255 | ui->lineEditBin->setText(XLineEditValidator::value32ToBinString((quint32)m_nValue)); 256 | } else if (m_nBits == 64) { 257 | ui->lineEditBin->setText(XLineEditValidator::value64ToBinString((quint64)m_nValue)); 258 | } 259 | } 260 | 261 | for (qint32 i = 0; i < m_nBits; i++) { 262 | if (!m_listButtons.at(i)->hasFocus()) { 263 | bool bIsChecked = m_nValue & ((quint64)1 << i); 264 | m_listButtons.at(i)->setChecked(bIsChecked); 265 | 266 | if (bIsChecked) { 267 | m_listButtons.at(i)->setText("1"); 268 | } else { 269 | m_listButtons.at(i)->setText("0"); 270 | } 271 | } 272 | } 273 | 274 | enableControls(true); 275 | } 276 | 277 | quint8 DialogBits8::getValue_uint8() 278 | { 279 | return (quint8)m_nValue; 280 | } 281 | 282 | quint16 DialogBits8::getValue_uint16() 283 | { 284 | return (quint16)m_nValue; 285 | } 286 | 287 | quint32 DialogBits8::getValue_uint32() 288 | { 289 | return (quint32)m_nValue; 290 | } 291 | 292 | quint64 DialogBits8::getValue_uint64() 293 | { 294 | return m_nValue; 295 | } 296 | 297 | void DialogBits8::_handleButton(QToolButton *pToolButton) 298 | { 299 | m_listButtons.append(pToolButton); 300 | connect(pToolButton, SIGNAL(toggled(bool)), this, SLOT(toggledSlot(bool))); 301 | } 302 | 303 | void DialogBits8::on_lineEditHex_textChanged(const QString &sString) 304 | { 305 | m_nValue = sString.toULongLong(0, 16); 306 | reload(); 307 | } 308 | 309 | void DialogBits8::on_lineEditSigned_textChanged(const QString &sString) 310 | { 311 | m_nValue = sString.toLongLong(0, 10); 312 | reload(); 313 | } 314 | 315 | void DialogBits8::on_lineEditUnsigned_textChanged(const QString &sString) 316 | { 317 | m_nValue = sString.toULongLong(0, 10); 318 | reload(); 319 | } 320 | 321 | void DialogBits8::on_lineEditBin_textChanged(const QString &sString) 322 | { 323 | m_nValue = XLineEditValidator::binStringToValue(sString); 324 | reload(); 325 | } 326 | 327 | void DialogBits8::toggledSlot(bool bState) 328 | { 329 | Q_UNUSED(bState) 330 | 331 | ui->pushButtonCancel->setFocus(); 332 | 333 | for (qint32 i = 0; i < m_nBits; i++) { 334 | bool bBit = m_listButtons.at(i)->isChecked(); 335 | quint64 nFF = 0x01; 336 | quint64 nBitValue = (quint64)bBit; 337 | nFF = nFF << i; 338 | nBitValue = nBitValue << i; 339 | m_nValue = m_nValue & (~nFF); 340 | m_nValue = m_nValue | nBitValue; 341 | } 342 | 343 | reload(); 344 | } 345 | 346 | void DialogBits8::enableControls(bool bState) 347 | { 348 | ui->lineEditHex->blockSignals(!bState); 349 | ui->lineEditSigned->blockSignals(!bState); 350 | ui->lineEditUnsigned->blockSignals(!bState); 351 | ui->lineEditBin->blockSignals(!bState); 352 | 353 | qint32 nNumberOfRecords = m_listButtons.count(); 354 | 355 | for (qint32 i = 0; i < nNumberOfRecords; i++) { 356 | m_listButtons.at(i)->blockSignals(!bState); 357 | } 358 | } 359 | 360 | void DialogBits8::on_pushButtonCancel_clicked() 361 | { 362 | this->close(); 363 | } 364 | 365 | void DialogBits8::on_pushButtonOK_clicked() 366 | { 367 | accept(); 368 | } 369 | -------------------------------------------------------------------------------- /xmodel_msrecord.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2025 hors 2 | * 3 | * Permission is hereby granted, free of charge, to any person obtaining a copy 4 | * of this software and associated documentation files (the "Software"), to deal 5 | * in the Software without restriction, including without limitation the rights 6 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | * copies of the Software, and to permit persons to whom the Software is 8 | * furnished to do so, subject to the following conditions: 9 | * 10 | * The above copyright notice and this permission notice shall be included in 11 | * all copies or substantial portions of the Software. 12 | * 13 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 19 | * SOFTWARE. 20 | */ 21 | 22 | #include "xmodel_msrecord.h" 23 | 24 | XModel_MSRecord::XModel_MSRecord(QIODevice *pDevice, const XBinary::_MEMORY_MAP &memoryMap, QVector *pListRecods, XBinary::VT valueType, 25 | QObject *pParent) 26 | : XModel(pParent) 27 | { 28 | m_pDevice = pDevice; 29 | m_memoryMap = memoryMap; 30 | m_pListRecords = pListRecods; 31 | m_pListSignatureRecords = nullptr; 32 | 33 | m_endian = XBinary::ENDIAN_LITTLE; 34 | m_valueType = valueType; 35 | 36 | qint32 nRowCount = pListRecods->count(); 37 | 38 | _setRowCount(nRowCount); 39 | _setColumnCount(__COLUMN_SIZE); 40 | 41 | m_modeAddress = XBinary::getWidthModeFromSize(memoryMap.nModuleAddress + memoryMap.nImageSize); 42 | m_modeOffset = XBinary::getWidthModeFromSize(memoryMap.nBinarySize); 43 | 44 | setColumnSymbolSize(COLUMN_NUMBER, QString::number(nRowCount).length()); 45 | setColumnSymbolSize(COLUMN_OFFSET, XBinary::getByteSizeFromWidthMode(m_modeOffset) * 2); 46 | setColumnSymbolSize(COLUMN_ADDRESS, XBinary::getByteSizeFromWidthMode(m_modeAddress) * 2); 47 | setColumnSymbolSize(COLUMN_REGION, 1); 48 | setColumnSymbolSize(COLUMN_SIZE, 4); 49 | setColumnSymbolSize(COLUMN_INFO, 8); 50 | 51 | qint32 nNumberOfRegions = memoryMap.listRecords.count(); 52 | qint32 nMaxRegionNameLength = 4; 53 | 54 | for (qint32 i = 0; i < nNumberOfRegions; i++) { 55 | nMaxRegionNameLength = qMax(nMaxRegionNameLength, memoryMap.listRecords.at(i).sName.length()); 56 | nMaxRegionNameLength = qMin(50, nMaxRegionNameLength); 57 | } 58 | 59 | setColumnSymbolSize(COLUMN_REGION, nMaxRegionNameLength); 60 | } 61 | 62 | void XModel_MSRecord::setValue(XBinary::ENDIAN endian, XBinary::VT valueType, QVariant varValue) 63 | { 64 | m_endian = endian; 65 | m_valueType = valueType; 66 | m_varValue = varValue; 67 | 68 | m_sValue = XBinary::getValueString(varValue, valueType); 69 | } 70 | 71 | void XModel_MSRecord::setSignaturesList(QList *pListSignatureRecords) 72 | { 73 | m_pListSignatureRecords = pListSignatureRecords; 74 | } 75 | 76 | QVariant XModel_MSRecord::data(const QModelIndex &index, int nRole) const 77 | { 78 | QVariant result; 79 | 80 | if (index.isValid()) { 81 | qint32 nRow = index.row(); 82 | 83 | if (nRow >= 0) { 84 | qint32 nColumn = index.column(); 85 | 86 | if (nRole == Qt::DisplayRole) { 87 | if (nColumn == COLUMN_NUMBER) { 88 | result = nRow; 89 | } else if (nColumn == COLUMN_OFFSET) { 90 | qint16 nRegionIndex = m_pListRecords->at(nRow).nRegionIndex; 91 | if (nRegionIndex != -1) { 92 | if (m_memoryMap.listRecords.at(nRegionIndex).nOffset != -1) { 93 | result = XBinary::valueToHex(m_modeOffset, m_memoryMap.listRecords.at(nRegionIndex).nOffset + m_pListRecords->at(nRow).nRelOffset); 94 | } 95 | } else { 96 | result = XBinary::valueToHex(m_modeOffset, m_pListRecords->at(nRow).nRelOffset); 97 | } 98 | } else if (nColumn == COLUMN_ADDRESS) { 99 | qint16 nRegionIndex = m_pListRecords->at(nRow).nRegionIndex; 100 | if (nRegionIndex != -1) { 101 | if (m_memoryMap.listRecords.at(nRegionIndex).nAddress != (XADDR)-1) { 102 | result = XBinary::valueToHex(m_modeAddress, m_memoryMap.listRecords.at(nRegionIndex).nAddress + m_pListRecords->at(nRow).nRelOffset); 103 | } 104 | } 105 | } else if (nColumn == COLUMN_REGION) { 106 | if (m_pListRecords->at(nRow).nRegionIndex >= 0) { 107 | result = m_memoryMap.listRecords.at(m_pListRecords->at(nRow).nRegionIndex).sName; 108 | } 109 | } else if (nColumn == COLUMN_SIZE) { 110 | result = QString::number(m_pListRecords->at(nRow).nSize, 16); 111 | } else if (nColumn == COLUMN_INFO) { 112 | if (m_valueType != XBinary::VT_SIGNATURE) { 113 | result = XBinary::valueTypeToString((XBinary::VT)(m_pListRecords->at(nRow).nValueType), 0); 114 | } else { 115 | if (nColumn == COLUMN_INFO) { 116 | if (m_valueType == XBinary::VT_SIGNATURE) { 117 | if (m_pListSignatureRecords && (m_pListSignatureRecords->count() > m_pListRecords->at(nRow).nInfo)) { 118 | if (m_pListSignatureRecords->at(m_pListRecords->at(nRow).nInfo).sPatch != "") { 119 | result = tr("Patch"); 120 | } 121 | } 122 | } 123 | } 124 | } 125 | } else if (nColumn == COLUMN_VALUE) { 126 | if ((m_valueType == XBinary::VT_STRING) || (m_valueType == XBinary::VT_A_I) || (m_valueType == XBinary::VT_U_I) || 127 | (m_valueType == XBinary::VT_UTF8_I)) { 128 | XBinary binary(m_pDevice); 129 | XBinary::VT valueType = m_valueType; 130 | if (m_valueType == XBinary::VT_STRING) { 131 | valueType = (XBinary::VT)(m_pListRecords->at(nRow).nValueType); 132 | } 133 | qint16 nRegionIndex = m_pListRecords->at(nRow).nRegionIndex; 134 | 135 | if (nRegionIndex != -1) { 136 | if (m_memoryMap.listRecords.at(nRegionIndex).nOffset != -1) { 137 | qint64 _nOffset = m_memoryMap.listRecords.at(nRegionIndex).nOffset + m_pListRecords->at(nRow).nRelOffset; 138 | result = binary.read_value(valueType, _nOffset, m_pListRecords->at(nRow).nSize, m_endian == XBinary::ENDIAN_BIG).toString(); 139 | } 140 | } else { 141 | qint64 _nOffset = m_pListRecords->at(nRow).nRelOffset; 142 | result = binary.read_value(valueType, _nOffset, m_pListRecords->at(nRow).nSize, m_endian == XBinary::ENDIAN_BIG).toString(); 143 | } 144 | } else if (m_valueType == XBinary::VT_SIGNATURE) { 145 | if (m_pListSignatureRecords && (m_pListSignatureRecords->count() > m_pListRecords->at(nRow).nInfo)) { 146 | result = m_pListSignatureRecords->at(m_pListRecords->at(nRow).nInfo).sName; 147 | } else { 148 | result = m_sValue; 149 | } 150 | } else { 151 | result = m_sValue; 152 | } 153 | } 154 | } else if (nRole == Qt::TextAlignmentRole) { 155 | if ((nColumn == COLUMN_NUMBER) || (nColumn == COLUMN_OFFSET) || (nColumn == COLUMN_ADDRESS) || (nColumn == COLUMN_SIZE)) { 156 | result = (qint32)Qt::AlignVCenter + (qint32)Qt::AlignRight; 157 | } else { 158 | result = (qint32)Qt::AlignVCenter + (qint32)Qt::AlignLeft; 159 | } 160 | // } else if (nRole == Qt::CheckStateRole) { 161 | // if (nColumn == COLUMN_INFO) { 162 | // if (g_valueType == XBinary::VT_SIGNATURE) { 163 | // if (g_pListSignatureRecords && (g_pListSignatureRecords->count() > g_pListRecords->at(nRow).nInfo)) { 164 | // if (g_pListSignatureRecords->at(g_pListRecords->at(nRow).nInfo).sPatch != "") { 165 | // result = Qt::Checked; 166 | // } 167 | // } 168 | // } 169 | // } 170 | } else if (nRole == Qt::UserRole + USERROLE_ORIGINDEX) { 171 | result = nRow; 172 | } else if (nRole == Qt::UserRole + USERROLE_ADDRESS) { 173 | qint16 nRegionIndex = m_pListRecords->at(nRow).nRegionIndex; 174 | if (nRegionIndex != -1) { 175 | if (m_memoryMap.listRecords.at(nRegionIndex).nAddress != (XADDR)-1) { 176 | result = m_memoryMap.listRecords.at(nRegionIndex).nAddress + m_pListRecords->at(nRow).nRelOffset; 177 | } 178 | } 179 | } else if (nRole == Qt::UserRole + USERROLE_OFFSET) { 180 | qint16 nRegionIndex = m_pListRecords->at(nRow).nRegionIndex; 181 | if (nRegionIndex != -1) { 182 | if (m_memoryMap.listRecords.at(nRegionIndex).nOffset != -1) { 183 | result = m_memoryMap.listRecords.at(nRegionIndex).nOffset + m_pListRecords->at(nRow).nRelOffset; 184 | } 185 | } else { 186 | result = m_pListRecords->at(nRow).nRelOffset; 187 | } 188 | } else if (nRole == Qt::UserRole + USERROLE_SIZE) { 189 | result = m_pListRecords->at(nRow).nSize; 190 | } else if (nRole == Qt::UserRole + USERROLE_STRING1) { 191 | result = m_pListRecords->at(nRow).nValueType; 192 | } 193 | } 194 | } 195 | 196 | return result; 197 | } 198 | 199 | QVariant XModel_MSRecord::headerData(int nSection, Qt::Orientation orientation, int nRole) const 200 | { 201 | QVariant result; 202 | 203 | if (orientation == Qt::Horizontal) { 204 | if (nRole == Qt::DisplayRole) { 205 | if (nSection == COLUMN_NUMBER) { 206 | result = "#"; 207 | } else if (nSection == COLUMN_OFFSET) { 208 | result = tr("Offset"); 209 | } else if (nSection == COLUMN_ADDRESS) { 210 | result = tr("Address"); 211 | } else if (nSection == COLUMN_REGION) { 212 | result = tr("Region"); 213 | } else if (nSection == COLUMN_SIZE) { 214 | result = tr("Size"); 215 | } else if (nSection == COLUMN_INFO) { 216 | // if (g_valueType == XBinary::VT_SIGNATURE) { 217 | // result = tr("Patch"); 218 | // } else { 219 | // result = tr("Info"); 220 | // } 221 | result = tr("Info"); 222 | } else if (nSection == COLUMN_VALUE) { 223 | if (m_valueType == XBinary::VT_STRING) { 224 | result = tr("String"); 225 | } else if (m_valueType == XBinary::VT_SIGNATURE) { 226 | result = tr("Signature"); 227 | } else { 228 | result = tr("Value"); 229 | } 230 | } 231 | } else if (nRole == Qt::TextAlignmentRole) { 232 | if ((nSection == COLUMN_NUMBER) || (nSection == COLUMN_OFFSET) || (nSection == COLUMN_ADDRESS) || (nSection == COLUMN_SIZE)) { 233 | result = (qint32)Qt::AlignVCenter + (qint32)Qt::AlignRight; 234 | } else { 235 | result = (qint32)Qt::AlignVCenter + (qint32)Qt::AlignLeft; 236 | } 237 | } 238 | } 239 | 240 | return result; 241 | } 242 | 243 | bool XModel_MSRecord::isCustomFilter() 244 | { 245 | return false; 246 | } 247 | 248 | bool XModel_MSRecord::isCustomSort() 249 | { 250 | return false; 251 | } 252 | 253 | XModel::SORT_METHOD XModel_MSRecord::getSortMethod(qint32 nColumn) 254 | { 255 | SORT_METHOD result = SORT_METHOD_DEFAULT; 256 | 257 | if ((nColumn == COLUMN_OFFSET) || (nColumn == COLUMN_OFFSET) || (nColumn == COLUMN_SIZE)) { 258 | result = SORT_METHOD_HEX; 259 | } 260 | 261 | return result; 262 | } 263 | --------------------------------------------------------------------------------