diff --git a/kasten/controllers/CMakeLists.txt b/kasten/controllers/CMakeLists.txt index b5cd8db7..f6709f29 100644 --- a/kasten/controllers/CMakeLists.txt +++ b/kasten/controllers/CMakeLists.txt @@ -1,698 +1,698 @@ set(OKTETAKASTENCONTROLLERS_VERSION ${OKTETAKASTEN_LIB_VERSION}) set(OKTETAKASTENCONTROLLERS_SO_VERSION ${OKTETAKASTEN_LIB_SOVERSION}) set( LIBFRAMESPRINT_REL_DIR ../../libs/framesprint ) add_definitions(-DTRANSLATION_DOMAIN=\"liboktetakasten\") include_directories( view/libbytearraychecksum view/libbytearrayfilter view/libfinddialog ${LIBFRAMESPRINT_REL_DIR} ) set(HAVE_QCA2 ${Qca-qt5_FOUND}) configure_file( config-qca2.hpp.cmake ${CMAKE_CURRENT_BINARY_DIR}/config-qca2.hpp ) macro(OKTETAKASTENCONTROLLERS_ADD_SUBLIBRARY _subdir) okteta_add_sublibrary(Controllers NAMESPACE Okteta Kasten REVERSE_NAMESPACE_INCLUDEDIR SUBDIR ${_subdir} ${ARGN} ) endmacro() macro(OKTETAKASTENCONTROLLERS_ADD_SUBLIBRARY_STRUCTURES_TESTED _subdir) okteta_add_sublibrary(Controllers NAMESPACE Okteta Kasten REVERSE_NAMESPACE_INCLUDEDIR SOURCE_TAG structures_tested SUBDIR ${_subdir} ${ARGN} ) endmacro() oktetakastencontrollers_add_sublibrary(document/info PUBLIC DocumentInfoToolFactory DocumentInfoToolViewFactory PRIVATE ByteArrayModelIoDevice DocumentInfoView DocumentInfoTool DocumentInfoToolView ) # unused, TODO: remove? if (FALSE) oktetakastencontrollers_add_sublibrary(document/overwriteonly PUBLIC OverwriteOnlyControllerFactory PRIVATE OverwriteOnlyController ) endif() oktetakastencontrollers_add_sublibrary(view/overwritemode PUBLIC OverwriteModeControllerFactory PRIVATE OverwriteModeController ) oktetakastencontrollers_add_sublibrary(view/info PUBLIC InfoToolFactory InfoToolViewFactory PRIVATE CreateStatisticJob StatisticTableModel InfoView InfoTool InfoToolView KCFG infoviewsettings.kcfgc ) oktetakastencontrollers_add_sublibrary(view/stringsextract PUBLIC StringsExtractToolFactory StringsExtractToolViewFactory PRIVATE ExtractStringsJob ContainedStringTableModel StringsExtractView ContainedString StringsExtractTool StringsExtractToolView ) oktetakastencontrollers_add_sublibrary(view/libbytearraychecksum PRIVATE AbstractByteArrayChecksumAlgorithm AbstractByteArrayChecksumParameterSet AbstractByteArrayChecksumParameterSetEdit ByteArrayChecksumAlgorithmFactory ByteArrayChecksumParameterSetEditFactory ) if( Qca-qt5_FOUND ) set( QCA2CHECKSUM_CLASSES Qca2ByteArrayChecksumAlgorithm ) endif() oktetakastencontrollers_add_sublibrary(view/libbytearraychecksum/algorithm PRIVATE Crc32ByteArrayChecksumAlgorithm Adler32ByteArrayChecksumAlgorithm ModSum8ByteArrayChecksumAlgorithm ModSum16ByteArrayChecksumAlgorithm ModSum32ByteArrayChecksumAlgorithm ModSum64ByteArrayChecksumAlgorithm ## NEWCHECKSUM(start) ## Here add the names of your classes of your checksum algorithm, ## e.g. ## MyByteArrayChecksumAlgorithm ## NEWCHECKSUM(end) NoByteArrayChecksumParameterSet NoByteArrayChecksumParameterSetEdit ModSumByteArrayChecksumParameterSet ModSumByteArrayChecksumParameterSetEdit ## NEWCHECKSUMPARAMETERSET(start) ## Here add the names of your classes of your checksum parameter set and ## of the widget to edit the checksum parameter set, ## e.g. ## MyByteArrayChecksumParameterSet ## MyByteArrayChecksumParameterSetEdit ## NEWCHECKSUMPARAMETERSET(end) ${QCA2CHECKSUM_CLASSES} ) oktetakastencontrollers_add_sublibrary(view/checksum PUBLIC ChecksumToolFactory ChecksumToolViewFactory PRIVATE ChecksumCalculateJob ChecksumLogging ChecksumView ChecksumTool ChecksumToolView ) oktetakastencontrollers_add_sublibrary(view/libfinddialog PUBLIC FindDirection PRIVATE AbstractFindDialog ) oktetakastencontrollers_add_sublibrary(view/poddecoder/typecodecs PRIVATE Binary8Codec Octal8Codec Hexadecimal8Codec UInt8Codec UInt16Codec UInt32Codec UInt64Codec SInt8Codec SInt16Codec SInt32Codec SInt64Codec Float32Codec Float64Codec Char8Codec Utf8Codec ) oktetakastencontrollers_add_sublibrary(view/poddecoder PUBLIC PODDecoderToolFactory PODDecoderToolViewFactory PRIVATE PODData PODTableModel PODDelegate PODTableView PODDecoderTool PODDecoderToolView ) oktetakastencontrollers_add_sublibrary(view/poddecoder/typeeditors SOURCE_TAG typeeditor PRIVATE AbstractValue8Editor Binary8Editor Octal8Editor Hexadecimal8Editor UIntSpinBox SIntSpinBox Float32Editor Float64Editor Char8Editor Utf8Editor ) oktetakastencontrollers_add_sublibrary(view/bytetable PUBLIC ByteTableToolFactory ByteTableToolViewFactory PRIVATE ByteTableModel ByteTableView ByteTableTool ByteTableToolView KCFG bytetableviewsettings.kcfgc ) oktetakastencontrollers_add_sublibrary(view/search PUBLIC SearchControllerFactory PRIVATE SearchUserQueryable SearchDialog SearchJob SearchTool SearchController ) oktetakastencontrollers_add_sublibrary(view/replace PUBLIC ReplaceControllerFactory PRIVATE ReplaceUserQueryable ReplaceController ReplaceDialog ReplacePrompt ReplaceJob ReplaceTool ) oktetakastencontrollers_add_sublibrary(view/libbytearrayfilter PRIVATE AbstractByteArrayFilter AbstractByteArrayFilterParameterSet AbstractByteArrayFilterParameterSetEdit ByteArrayFilterFactory ByteArrayFilterParameterSetEditFactory ) oktetakastencontrollers_add_sublibrary(view/libbytearrayfilter/filter PRIVATE NoByteArrayFilterParameterSet OperandByteArrayFilterParameterSet ReverseByteArrayFilterParameterSet RotateByteArrayFilterParameterSet ## NEWFILTERPARAMETERSET(start) ## Here add the names of your classes of your filter parameter set, ## e.g. ## MyByteArrayFilterParameterSet ## NEWFILTERPARAMETERSET(end) AndByteArrayFilter OrByteArrayFilter XorByteArrayFilter InvertByteArrayFilter ReverseByteArrayFilter RotateByteArrayFilter ShiftByteArrayFilter ## NEWFILTER(start) ## Here add the names of your classes of your filter, ## e.g. ## MyByteArrayFilter ## NEWFILTER(end) NoByteArrayFilterParameterSetedit OperandByteArrayFilterParameterSetedit ReverseByteArrayFilterParameterSetedit RotateByteArrayFilterParameterSetedit ## NEWFILTERPARAMETERSET(start) ## Here add the names of your classes of your widget to edit the filter parameter set, ## e.g. ## MyByteArrayFilterParameterSetedit ## NEWFILTERPARAMETERSET(end) ) oktetakastencontrollers_add_sublibrary(view/filter PUBLIC FilterToolFactory FilterToolViewFactory PRIVATE FilterJob FilterView FilterTool FilterToolView ) oktetakastencontrollers_add_sublibrary(view/charsetconversion PUBLIC CharsetConversionToolFactory CharsetConversionToolViewFactory PRIVATE CharsetConversionJob CharsetConversionView CharsetConversionTool CharsetConversionToolView ) oktetakastencontrollers_add_sublibrary(view/gotooffset PUBLIC GotoOffsetControllerFactory PRIVATE GotoOffsetTool GotoOffsetView GotoOffsetToolView GotoOffsetController ) oktetakastencontrollers_add_sublibrary(view/selectrange PUBLIC SelectRangeControllerFactory PRIVATE SelectRangeTool SelectRangeView SelectRangeToolView SelectRangeController ) oktetakastencontrollers_add_sublibrary(view/bookmarks PUBLIC BookmarksControllerFactory PRIVATE BookmarkEditPopup BookmarksController ) oktetakastencontrollers_add_sublibrary(view/bookmarks PUBLIC BookmarksToolFactory BookmarksToolViewFactory PRIVATE BookmarkListModel BookmarksView BookmarksTool BookmarksToolView ) oktetakastencontrollers_add_sublibrary_structures_tested(view/structures/datatypes PRIVATE TopLevelDataInformation DataInformation DataInformationbase DummyDataInformation DataInformationwithchildren StructureDataInformation TaggedUnionDataInformation UnionDataInformation PrimitiveFactory PrimitiveDataType ) oktetakastencontrollers_add_sublibrary_structures_tested(view/structures/datatypes/array PRIVATE ArrayDataInformation AbstractArrayData ComplexArrayData PrimitiveArrayData ) oktetakastencontrollers_add_sublibrary_structures_tested(view/structures/datatypes/primitive PRIVATE PointerDataInformation CharDataInformation DoubleDataInformation FloatDataInformation SIntDataInformation UIntDataInformation BoolDataInformation FlagDataInformation PrimitiveDataInformation BasicPrimitiveDataInformation EnumDataInformation EnumDefinition ) oktetakastencontrollers_add_sublibrary_structures_tested(view/structures/datatypes/primitive/bitfield PRIVATE AbstractBitfieldDataInformation BoolBitfieldDataInformation SignedBitfieldDataInformation UnsignedBitfieldDataInformation ) oktetakastencontrollers_add_sublibrary_structures_tested(view/structures/datatypes/strings PRIVATE StringDataInformation StringData AsciiStringData Latin1StringData Utf8StringData Utf16StringData Utf32StringData EbcdicStringData ) oktetakastencontrollers_add_sublibrary_structures_tested(../../core/codecs PRIVATE Ebcdic1047CharCodec ) oktetakastencontrollers_add_sublibrary_structures_tested(view/structures/script PRIVATE ScriptEngineInitializer ScriptHandler ScriptHandlerInfo ScriptUtils ScriptLogger ScriptLoggerView SafeReference ) oktetakastencontrollers_add_sublibrary_structures_tested(view/structures/script/classes PRIVATE DefaultScriptClass ArrayScriptClass PrimitiveScriptClass EnumScriptClass PointerScriptClass BitfieldScriptClass StringScriptClass StructUnionScriptClass ) oktetakastencontrollers_add_sublibrary_structures_tested(view/structures/parsers PRIVATE AbstractStructureParser OsdParser ScriptFileParser ScriptValueConverter DataInformationFactory ParserUtils ) oktetakastencontrollers_add_sublibrary_structures_tested(view/structures/settings KCFG structureviewpreferences.kcfgc ) oktetakastencontrollers_add_sublibrary_structures_tested(view/structures PRIVATE AllPrimitiveTypes StructLogging ) #these source files are not needed by the static library for unit tests, therefore keep them separate oktetakastencontrollers_add_sublibrary(view/structures/settings PRIVATE StructureAddRemoveWidget StructuresSelectionDialog StructureViewSettingsWidget StructuresManagerView UI structureviewsettingswidget.ui ) oktetakastencontrollers_add_sublibrary(view/structures PUBLIC StructuresToolFactory StructuresToolViewFactory PRIVATE StructuresManager StructuresTool StructureTreeModel StructureDefinitionFile -# view/structures/modeltest.cpp StructureView StructuresToolView StructureViewItemDelegate ) # structurestool.h cannot be installed as it pulls (too) many private uninstalled headers # KF5 TODO: any tools/controllers and views should be created by the resp. factories # since some time, no more directly. # So on next ABI change depublish tools/controllers & their views # For now keeping all installed, in case someone is using them still/already. # structtoolview.h is not useful, but we keep installing the header just in case someone includes it oktetakastencontrollers_add_sublibrary(${LIBFRAMESPRINT_REL_DIR} PRIVATE AbstractFrameRenderer FramesToPaperPrinter HeaderFooterFrameRenderer ) oktetakastencontrollers_add_sublibrary(view/print PUBLIC PrintControllerFactory PRIVATE PrintTool PrintJob AbstractColumnFrameRenderer PrintColumnStylist ByteArrayFrameRenderer PrintDialog PrintController ) set_source_files_properties(view/print/printtool.cpp PROPERTIES COMPILE_FLAGS -DOKTETA_VERSION=\\\"${Okteta_VERSION}\\\" ) oktetakastencontrollers_add_sublibrary(view/viewconfig PUBLIC ViewConfigControllerFactory PRIVATE BytesPerLineDialog BytesPerGroupDialog ViewConfigController ) oktetakastencontrollers_add_sublibrary(view/viewstatus PUBLIC ViewStatusControllerFactory PRIVATE ViewStatusController ) oktetakastencontrollers_add_sublibrary(view/viewmode PUBLIC ViewModeControllerFactory PRIVATE ViewModeController ) oktetakastencontrollers_add_sublibrary(view/viewprofiles PUBLIC ViewProfilesManageControllerFactory # TODO: two controllers in one subdir ViewProfileControllerFactory PRIVATE ViewProfileEdit ViewProfileEditDialog ViewProfileTableModel ViewProfilesManageDialog ViewProfileController ViewProfilesManageController ) oktetakastencontrollers_add_sublibrary(view/viewcontextmenu PUBLIC ViewContextMenuControllerFactory PRIVATE ViewContextMenuController ) # create a static library for the unit tests. This means we don't have to compile the sources twice add_library(poddecoder-typeeditors STATIC ${oktetakastencontrollers_typeeditor_LIB_SRCS}) set_target_properties( poddecoder-typeeditors PROPERTIES POSITION_INDEPENDENT_CODE TRUE ) target_link_libraries( poddecoder-typeeditors PUBLIC OktetaGui PRIVATE KF5::Completion ) add_library( structureview-tested-srcs STATIC ${oktetakastencontrollers_structures_tested_LIB_SRCS} ) set_target_properties( structureview-tested-srcs PROPERTIES POSITION_INDEPENDENT_CODE TRUE ) target_link_libraries( structureview-tested-srcs PUBLIC OktetaCore KF5::ConfigGui KF5::I18n KF5::Service Qt5::Script Qt5::Xml Qt5::Widgets PRIVATE KF5::Completion KF5::ConfigWidgets ) if(BUILD_TESTING) #structures view unit tests ecm_add_tests( test/primitivearraytest.cpp test/arraydatainformationtest.cpp test/basicdatainformationtest.cpp test/primitivedatainformationtest.cpp test/scriptclassestest.cpp test/uniondatainformationtest.cpp test/allprimitivetypestest.cpp test/scriptvalueconvertertest.cpp test/osdparsertest.cpp test/commonparsertest.cpp test/jsparsertest.cpp test/customtostringtest.cpp test/locktooffsettest.cpp NAME_PREFIX structures- LINK_LIBRARIES structureview-tested-srcs Qt5::Test poddecoder-typeeditors ) #replace tool unit tests ecm_add_test( view/search/searchjob.cpp view/replace/replacejob.cpp test/replacejobtest.cpp TEST_NAME replacejobtest LINK_LIBRARIES OktetaKastenGui OktetaKastenCore Qt5::Test ) endif() list(APPEND oktetakastencontrollers_LIB_HDRS ${CMAKE_CURRENT_BINARY_DIR}/config-qca2.hpp ) set(OPTIONAL_PRIVATE) if( Qca-qt5_FOUND ) set(OPTIONAL_PRIVATE qca-qt5) endif() okteta_add_library(Controllers NAMESPACE Okteta Kasten PUBLIC OktetaKastenGui OktetaKastenCore KastenGui KastenCore PRIVATE structureview-tested-srcs poddecoder-typeeditors KF5::NewStuff KF5::I18n KF5::ConfigWidgets KF5::KCMUtils KF5::IconThemes KF5::Completion Qt5::PrintSupport Qt5::Script +# Qt5::Test # QAbstractItemModelTester ${OPTIONAL_PRIVATE} VERSION ${OKTETAKASTENCONTROLLERS_VERSION} SOVERSION ${OKTETAKASTENCONTROLLERS_SO_VERSION} ABIVERSION ${OKTETAKASTEN_ABI_VERSION} ${KASTEN_ABI_VERSION} SOURCES ${oktetakastencontrollers_LIB_SRCS} HEADERS ${oktetakastencontrollers_LIB_HDRS} CCHEADERS ${oktetakastencontrollers_LIB_CCHDRS} NO_VERSIONED_INCLUDEDIR NO_VERSIONED_PACKAGE_NAME REVERSE_NAMESPACE_INCLUDEDIR REVERSE_NAMESPACE_LIB NO_TARGET_NAMESPACE ) install( FILES view/structures/kns/okteta-structures.knsrc DESTINATION ${KDE_INSTALL_CONFDIR} ) set( elf_structure_FILES view/structures/examples/okteta/structures/elf/metadata.desktop view/structures/examples/okteta/structures/elf/main.osd ) install( FILES ${elf_structure_FILES} DESTINATION ${KDE_INSTALL_DATADIR}/okteta/structures/elf ) set( png_structure_FILES view/structures/examples/okteta/structures/png/metadata.desktop view/structures/examples/okteta/structures/png/main.osd ) install( FILES ${png_structure_FILES} DESTINATION ${KDE_INSTALL_DATADIR}/okteta/structures/png ) install( FILES view/structures/examples/okteta/structures/uuid.js DESTINATION ${KDE_INSTALL_DATADIR}/okteta/structures/ ) install( FILES view/structures/settings/structureviewpreferences.kcfg DESTINATION ${KDE_INSTALL_KCFGDIR} ) configure_file( view/structures/struct2osd.in ${CMAKE_CURRENT_BINARY_DIR}/struct2osd @ONLY ) install( PROGRAMS ${CMAKE_CURRENT_BINARY_DIR}/struct2osd DESTINATION ${KDE_INSTALL_BINDIR} ) install( FILES view/structures/gccxml-to-osd.xsl DESTINATION ${KDE_INSTALL_DATADIR}/okteta/structures/ ) okteta_add_cmakeconfig(Controllers NAMESPACE Okteta Kasten ) if( KASTEN_BUILD_INTERNAL_TEMPLATES ) include_directories( view/libbytearrayfilter/filter view/libbytearraychecksum/algorithm ) okteta_add_sublibrary(ControllersTemplates NAMESPACE Okteta Kasten SUBDIR view/libbytearrayfilter/filter/template PRIVATE Template_ByteArrayFilter Template_ByteArrayFilterParameterSet Template_ByteArrayFilterParameterSetEdit ) okteta_add_sublibrary(ControllersTemplates NAMESPACE Okteta Kasten SUBDIR view/libbytearraychecksum/algorithm/template PRIVATE Template_ByteArrayCheckSumAlgorithm Template_ByteArrayChecksumParameterSet Template_ByteArrayChecksumParameterSetEdit ) add_library( oktetakastencontrollertemplates STATIC ${oktetakastencontrollerstemplates_LIB_SRCS} ) # MSVC needs this target_compile_definitions( oktetakastencontrollertemplates PUBLIC OKTETAKASTENCONTROLLERS_STATIC_DEFINE=1 ) target_link_libraries( oktetakastencontrollertemplates KF5::I18n Qt5::Widgets OktetaCore ) endif() diff --git a/kasten/controllers/view/structures/modeltest.cpp b/kasten/controllers/view/structures/modeltest.cpp deleted file mode 100644 index e29e38fd..00000000 --- a/kasten/controllers/view/structures/modeltest.cpp +++ /dev/null @@ -1,635 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2007 Trolltech ASA. All rights reserved. -** -** This file is part of the Qt Concurrent project on Trolltech Labs. -** -** This file may be used under the terms of the GNU General Public -** License version 2.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of -** this file. Please review the following information to ensure GNU -** General Public Licensing requirements will be met: -** http://www.trolltech.com/products/qt/opensource.html -** -** If you are unsure which license is appropriate for your use, please -** review the following information: -** http://www.trolltech.com/products/qt/licensing.html or contact the -** sales department at sales@trolltech.com. -** -** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE -** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. -** -****************************************************************************/ - -#include - -#include "modeltest.h" - -Q_DECLARE_METATYPE ( QModelIndex ) - -/*! - Connect to all of the models signals. Whenever anything happens recheck everything. -*/ -ModelTest::ModelTest ( QAbstractItemModel *_model, QObject *parent ) : QObject ( parent ), model ( _model ), fetchingMore ( false ) -{ - Q_ASSERT ( model ); - - connect ( model, &QAbstractItemModel::columnsAboutToBeInserted , - this, &ModelTest::runAllTests ); - connect ( model, &QAbstractItemModel::columnsAboutToBeRemoved , - this, &ModelTest::runAllTests ); - connect ( model, &QAbstractItemModel::columnsInserted , - this, &ModelTest::runAllTests ); - connect ( model, &QAbstractItemModel::columnsRemoved , - this, &ModelTest::runAllTests ); - connect ( model, &QAbstractItemModel::dataChanged , - this, &ModelTest::runAllTests ); - connect ( model, &QAbstractItemModel::headerDataChanged , - this, &ModelTest::runAllTests ); - connect ( model, &QAbstractItemModel::layoutAboutToBeChanged , this, &ModelTest::runAllTests ); - connect ( model, &QAbstractItemModel::layoutChanged , this, &ModelTest::runAllTests ); - connect ( model, &QAbstractItemModel::modelReset , this, &ModelTest::runAllTests ); - connect ( model, &QAbstractItemModel::modelAboutToBeReset , this, &ModelTest::modelAboutToBeReset ); - connect ( model, &QAbstractItemModel::modelReset , this, &ModelTest::modelReset ); - connect ( model, &QAbstractItemModel::rowsAboutToBeInserted , - this, &ModelTest::runAllTests ); - connect ( model, &QAbstractItemModel::rowsAboutToBeRemoved , - this, &ModelTest::runAllTests ); - connect ( model, &QAbstractItemModel::rowsInserted , - this, &ModelTest::runAllTests ); - connect ( model, &QAbstractItemModel::rowsRemoved , - this, &ModelTest::runAllTests ); - - // Special checks for inserting/removing - connect ( model, &QAbstractItemModel::layoutAboutToBeChanged, - this, &ModelTest::layoutAboutToBeChanged ); - connect ( model, &QAbstractItemModel::layoutChanged, - this, &ModelTest::layoutChanged ); - - connect ( model, &QAbstractItemModel::rowsAboutToBeInserted , - this, &ModelTest::rowsAboutToBeInserted ); - connect ( model, &QAbstractItemModel::rowsAboutToBeRemoved , - this, &ModelTest::rowsAboutToBeRemoved ); - connect ( model, &QAbstractItemModel::rowsInserted , - this, &ModelTest::rowsInserted ); - connect ( model, &QAbstractItemModel::rowsRemoved , - this, &ModelTest::rowsRemoved ); - - connect ( model, &QAbstractItemModel::rowsAboutToBeMoved , - this, &ModelTest::rowsAboutToBeMoved ); - connect ( model, &QAbstractItemModel::rowsMoved , - this, &ModelTest::rowsMoved ); - - runAllTests(); -} - -void ModelTest::runAllTests() -{ - -// qDebug() << "rats"; - if ( fetchingMore ) - return; - nonDestructiveBasicTest(); - rowCount(); - columnCount(); - hasIndex(); - index(); - parent(); - data(); -} - -/*! - nonDestructiveBasicTest tries to call a number of the basic functions (not all) - to make sure the model doesn't outright segfault, testing the functions that makes sense. -*/ -void ModelTest::nonDestructiveBasicTest() -{ - Q_ASSERT ( model->buddy ( QModelIndex() ) == QModelIndex() ); -// model->canFetchMore ( QModelIndex() ); - Q_ASSERT ( model->columnCount ( QModelIndex() ) >= 0 ); - Q_ASSERT ( model->data ( QModelIndex() ) == QVariant() ); -// fetchingMore = true; -// model->fetchMore ( QModelIndex() ); -// fetchingMore = false; - Qt::ItemFlags flags = model->flags ( QModelIndex() ); - Q_ASSERT ( flags == Qt::ItemIsDropEnabled || flags == 0 ); - Q_UNUSED(flags) - model->hasChildren ( QModelIndex() ); - model->hasIndex ( 0, 0 ); - model->headerData ( 0, Qt::Horizontal ); - model->index ( 0, 0 ); - model->itemData ( QModelIndex() ); - QVariant cache; - model->match ( QModelIndex(), -1, cache ); - model->mimeTypes(); - Q_ASSERT ( model->parent ( QModelIndex() ) == QModelIndex() ); - Q_ASSERT ( model->rowCount() >= 0 ); - QVariant variant; - model->setData ( QModelIndex(), variant, -1 ); - model->setHeaderData ( -1, Qt::Horizontal, QVariant() ); - model->setHeaderData ( 999999, Qt::Horizontal, QVariant() ); - QMap roles; - model->sibling ( 0, 0, QModelIndex() ); - model->span ( QModelIndex() ); - model->supportedDropActions(); -} - -/*! - Tests model's implementation of QAbstractItemModel::rowCount() and hasChildren() - - Models that are dynamically populated are not as fully tested here. - */ -void ModelTest::rowCount() -{ -// qDebug() << "rc"; - // check top row - QModelIndex topIndex = model->index ( 0, 0, QModelIndex() ); - int rows = model->rowCount ( topIndex ); - Q_ASSERT ( rows >= 0 ); - if ( rows > 0 ) - Q_ASSERT ( model->hasChildren ( topIndex ) == true ); - - QModelIndex secondLevelIndex = model->index ( 0, 0, topIndex ); - if ( secondLevelIndex.isValid() ) { // not the top level - // check a row count where parent is valid - rows = model->rowCount ( secondLevelIndex ); - Q_ASSERT ( rows >= 0 ); - if ( rows > 0 ) - Q_ASSERT ( model->hasChildren ( secondLevelIndex ) == true ); - } - - // The models rowCount() is tested more extensively in checkChildren(), - // but this catches the big mistakes -} - -/*! - Tests model's implementation of QAbstractItemModel::columnCount() and hasChildren() - */ -void ModelTest::columnCount() -{ - // check top row - QModelIndex topIndex = model->index ( 0, 0, QModelIndex() ); - Q_ASSERT ( model->columnCount ( topIndex ) >= 0 ); - - // check a column count where parent is valid - QModelIndex childIndex = model->index ( 0, 0, topIndex ); - if ( childIndex.isValid() ) - Q_ASSERT ( model->columnCount ( childIndex ) >= 0 ); - - // columnCount() is tested more extensively in checkChildren(), - // but this catches the big mistakes -} - -/*! - Tests model's implementation of QAbstractItemModel::hasIndex() - */ -void ModelTest::hasIndex() -{ -// qDebug() << "hi"; - // Make sure that invalid values returns an invalid index - Q_ASSERT ( model->hasIndex ( -2, -2 ) == false ); - Q_ASSERT ( model->hasIndex ( -2, 0 ) == false ); - Q_ASSERT ( model->hasIndex ( 0, -2 ) == false ); - - int rows = model->rowCount(); - int columns = model->columnCount(); - - // check out of bounds - Q_ASSERT ( model->hasIndex ( rows, columns ) == false ); - Q_ASSERT ( model->hasIndex ( rows + 1, columns + 1 ) == false ); - - if ( rows > 0 ) - Q_ASSERT ( model->hasIndex ( 0, 0 ) == true ); - - Q_UNUSED(columns) - // hasIndex() is tested more extensively in checkChildren(), - // but this catches the big mistakes -} - -/*! - Tests model's implementation of QAbstractItemModel::index() - */ -void ModelTest::index() -{ -// qDebug() << "i"; - // Make sure that invalid values returns an invalid index - Q_ASSERT ( model->index ( -2, -2 ) == QModelIndex() ); - Q_ASSERT ( model->index ( -2, 0 ) == QModelIndex() ); - Q_ASSERT ( model->index ( 0, -2 ) == QModelIndex() ); - - int rows = model->rowCount(); - int columns = model->columnCount(); - - if ( rows == 0 ) - return; - - // Catch off by one errors - Q_ASSERT ( model->index ( rows, columns ) == QModelIndex() ); - Q_ASSERT ( model->index ( 0, 0 ).isValid() == true ); - - // Make sure that the same index is *always* returned - QModelIndex a = model->index ( 0, 0 ); - QModelIndex b = model->index ( 0, 0 ); - Q_ASSERT ( a == b ); - Q_UNUSED(columns) - // index() is tested more extensively in checkChildren(), - // but this catches the big mistakes -} - -/*! - Tests model's implementation of QAbstractItemModel::parent() - */ -void ModelTest::parent() -{ -// qDebug() << "p"; - // Make sure the model wont crash and will return an invalid QModelIndex - // when asked for the parent of an invalid index. - Q_ASSERT ( model->parent ( QModelIndex() ) == QModelIndex() ); - - if ( model->rowCount() == 0 ) - return; - - // Column 0 | Column 1 | - // QModelIndex() | | - // \- topIndex | topIndex1 | - // \- childIndex | childIndex1 | - - // Common error test #1, make sure that a top level index has a parent - // that is a invalid QModelIndex. - QModelIndex topIndex = model->index ( 0, 0, QModelIndex() ); - Q_ASSERT ( model->parent ( topIndex ) == QModelIndex() ); - - // Common error test #2, make sure that a second level index has a parent - // that is the first level index. - if ( model->rowCount ( topIndex ) > 0 ) { - QModelIndex childIndex = model->index ( 0, 0, topIndex ); - Q_ASSERT ( model->parent ( childIndex ) == topIndex ); - } - - // Common error test #3, the second column should NOT have the same children - // as the first column in a row. - // Usually the second column shouldn't have children. - QModelIndex topIndex1 = model->index ( 0, 1, QModelIndex() ); - if ( model->rowCount ( topIndex1 ) > 0 ) { - QModelIndex childIndex = model->index ( 0, 0, topIndex ); - QModelIndex childIndex1 = model->index ( 0, 0, topIndex1 ); - Q_ASSERT ( childIndex != childIndex1 ); - } - - // Full test, walk n levels deep through the model making sure that all - // parent's children correctly specify their parent. - checkChildren ( QModelIndex() ); -} - -/*! - Called from the parent() test. - - A model that returns an index of parent X should also return X when asking - for the parent of the index. - - This recursive function does pretty extensive testing on the whole model in an - effort to catch edge cases. - - This function assumes that rowCount(), columnCount() and index() already work. - If they have a bug it will point it out, but the above tests should have already - found the basic bugs because it is easier to figure out the problem in - those tests then this one. - */ -void ModelTest::checkChildren ( const QModelIndex &parent, int currentDepth ) -{ - // First just try walking back up the tree. - QModelIndex p = parent; - while ( p.isValid() ) - p = p.parent(); - - // For models that are dynamically populated -// if ( model->canFetchMore ( parent ) ) { -// fetchingMore = true; -// model->fetchMore ( parent ); -// fetchingMore = false; -// } - - int rows = model->rowCount ( parent ); - int columns = model->columnCount ( parent ); - - if ( rows > 0 ) - { - - Q_ASSERT(parent.column() <= 0); - Q_ASSERT ( model->hasChildren ( parent ) ); - } - - // Some further testing against rows(), columns(), and hasChildren() - Q_ASSERT ( rows >= 0 ); - Q_ASSERT ( columns >= 0 ); - if ( rows > 0 ) - Q_ASSERT ( model->hasChildren ( parent ) == true ); - - //qDebug() << "parent:" << model->data(parent).toString() << "rows:" << rows - // << "columns:" << columns << "parent column:" << parent.column(); - - Q_ASSERT ( model->hasIndex ( rows, 0, parent ) == false ); - Q_ASSERT ( model->index(rows, 0, parent).isValid() == false ); - for ( int r = 0; r < rows; ++r ) { -// if ( model->canFetchMore ( parent ) ) { -// fetchingMore = true; -// model->fetchMore ( parent ); -// fetchingMore = false; -// } - Q_ASSERT ( model->hasIndex ( r, columns, parent ) == false ); - Q_ASSERT ( model->index(r, columns, parent).isValid() == false ); - for ( int c = 0; c < columns; ++c ) { - Q_ASSERT ( model->hasIndex ( r, c, parent ) == true ); - QModelIndex index = model->index ( r, c, parent ); - // rowCount() and columnCount() said that it existed... - Q_ASSERT ( index.isValid() == true ); - - // index() should always return the same index when called twice in a row - QModelIndex modifiedIndex = model->index ( r, c, parent ); - Q_ASSERT ( index == modifiedIndex ); - - // Make sure we get the same index if we request it twice in a row - QModelIndex a = model->index ( r, c, parent ); - QModelIndex b = model->index ( r, c, parent ); - Q_ASSERT ( a == b ); - - // Some basic checking on the index that is returned - Q_ASSERT ( index.model() == model ); - Q_ASSERT ( index.row() == r ); - Q_ASSERT ( index.column() == c ); - // While you can technically return a QVariant usually this is a sign - // of an bug in data() Disable if this really is ok in your model. -// qDebug() << index << index.data() << index.parent(); - Q_ASSERT ( model->data ( index, Qt::DisplayRole ).isValid() == true ); - - // If the next test fails here is some somewhat useful debug you play with. - /* - if (model->parent(index) != parent) { - qDebug() << r << c << currentDepth << model->data(index).toString() - << model->data(parent).toString(); - qDebug() << index << parent << model->parent(index); - // And a view that you can even use to show the model. - //QTreeView view; - //view.setModel(model); - //view.show(); - }*/ - - // Check that we can get back our real parent. - Q_ASSERT ( model->parent ( index ) == parent ); - - // recursively go down the children - if ( model->hasChildren ( index ) && currentDepth < 10 ) { - //qDebug() << r << c << "has children" << model->rowCount(index); - checkChildren ( index, ++currentDepth ); - }/* else { if (currentDepth >= 10) qDebug() << "checked 10 deep"; };*/ - - // make sure that after testing the children that the index doesn't change. - QModelIndex newerIndex = model->index ( r, c, parent ); - Q_ASSERT ( index == newerIndex ); - } - } -} - -/*! - Tests model's implementation of QAbstractItemModel::data() - */ -void ModelTest::data() -{ - // Invalid index should return an invalid qvariant - Q_ASSERT ( !model->data ( QModelIndex() ).isValid() ); - - if ( model->rowCount() == 0 ) - return; - - // A valid index should have a valid QVariant data - Q_ASSERT ( model->index ( 0, 0 ).isValid() ); - - // shouldn't be able to set data on an invalid index - Q_ASSERT ( model->setData ( QModelIndex(), QStringLiteral ( "foo" ), Qt::DisplayRole ) == false ); - - // General Purpose roles that should return a QString - QVariant variant = model->data ( model->index ( 0, 0 ), Qt::ToolTipRole ); - if ( variant.isValid() ) { - Q_ASSERT ( qVariantCanConvert ( variant ) ); - } - variant = model->data ( model->index ( 0, 0 ), Qt::StatusTipRole ); - if ( variant.isValid() ) { - Q_ASSERT ( qVariantCanConvert ( variant ) ); - } - variant = model->data ( model->index ( 0, 0 ), Qt::WhatsThisRole ); - if ( variant.isValid() ) { - Q_ASSERT ( qVariantCanConvert ( variant ) ); - } - - // General Purpose roles that should return a QSize - variant = model->data ( model->index ( 0, 0 ), Qt::SizeHintRole ); - if ( variant.isValid() ) { - Q_ASSERT ( qVariantCanConvert ( variant ) ); - } - - // General Purpose roles that should return a QFont - QVariant fontVariant = model->data ( model->index ( 0, 0 ), Qt::FontRole ); - if ( fontVariant.isValid() ) { - Q_ASSERT ( qVariantCanConvert ( fontVariant ) ); - } - - // Check that the alignment is one we know about - QVariant textAlignmentVariant = model->data ( model->index ( 0, 0 ), Qt::TextAlignmentRole ); - if ( textAlignmentVariant.isValid() ) { - int alignment = textAlignmentVariant.toInt(); - Q_ASSERT ( alignment == ( alignment & ( Qt::AlignHorizontal_Mask | Qt::AlignVertical_Mask ) ) ); - Q_UNUSED(alignment) - } - - // General Purpose roles that should return a QColor - QVariant colorVariant = model->data ( model->index ( 0, 0 ), Qt::BackgroundColorRole ); - if ( colorVariant.isValid() ) { - Q_ASSERT ( qVariantCanConvert ( colorVariant ) ); - } - - colorVariant = model->data ( model->index ( 0, 0 ), Qt::TextColorRole ); - if ( colorVariant.isValid() ) { - Q_ASSERT ( qVariantCanConvert ( colorVariant ) ); - } - - // Check that the "check state" is one we know about. - QVariant checkStateVariant = model->data ( model->index ( 0, 0 ), Qt::CheckStateRole ); - if ( checkStateVariant.isValid() ) { - int state = checkStateVariant.toInt(); - Q_ASSERT ( state == Qt::Unchecked || - state == Qt::PartiallyChecked || - state == Qt::Checked ); - Q_UNUSED(state) - } -} - -/*! - Store what is about to be inserted to make sure it actually happens - - \sa rowsInserted() - */ -void ModelTest::rowsAboutToBeInserted ( const QModelIndex &parent, int start, int end ) -{ -// Q_UNUSED(end); - qDebug() << "rowsAboutToBeInserted" << "start=" << start << "end=" << end << "parent=" << model->data ( parent ).value() - << "current count of parent=" << model->rowCount ( parent ); // << "display of last=" << model->data( model->index(start-1, 0, parent) ); -// qDebug() << model->index(start-1, 0, parent) << model->data( model->index(start-1, 0, parent) ); - Changing c; - c.parent = parent; - c.oldSize = model->rowCount ( parent ); - c.last = model->data ( model->index ( start - 1, 0, parent ) ); - c.next = model->data ( model->index ( start, 0, parent ) ); - insert.push ( c ); -} - -/*! - Confirm that what was said was going to happen actually did - - \sa rowsAboutToBeInserted() - */ -void ModelTest::rowsInserted ( const QModelIndex & parent, int start, int end ) -{ - Changing c = insert.pop(); - Q_ASSERT ( c.parent == parent ); - qDebug() << "rowsInserted" << "start=" << start << "end=" << end << "oldsize=" << c.oldSize - << "parent=" << model->data ( parent ).value() << "current rowcount=" << model->rowCount ( parent ); - - for (int ii=start; ii <= end; ii++) - { - qDebug() << "itemWasInserted:" << model->data ( model->index ( ii, 0, parent )); - } - - - Q_ASSERT ( c.oldSize + ( end - start + 1 ) == model->rowCount ( parent ) ); - Q_ASSERT ( c.last == model->data ( model->index ( start - 1, 0, c.parent ) ) ); - /* - if (c.next != model->data(model->index(end + 1, 0, c.parent))) { - qDebug() << start << end; - for (int i=0; i < model->rowCount(); ++i) - qDebug() << model->index(i, 0).data().toString(); - qDebug() << c.next << model->data(model->index(end + 1, 0, c.parent)); - } - */ - Q_ASSERT ( c.next == model->data ( model->index ( end + 1, 0, c.parent ) ) ); -} - - -void ModelTest::modelAboutToBeReset() -{ - qDebug() << "@@@@@@@@@@@" << "modelAboutToBeReset"; -} - -void ModelTest::modelReset() -{ - qDebug() << "@@@@@@@@@@@" << "modelReset"; -} - -void ModelTest::layoutAboutToBeChanged() -{ - for ( int i = 0; i < qBound ( 0, model->rowCount(), 100 ); ++i ) - changing.append ( QPersistentModelIndex ( model->index ( i, 0 ) ) ); -} - -void ModelTest::layoutChanged() -{ - for ( int i = 0; i < changing.count(); ++i ) { - QPersistentModelIndex p = changing[i]; - Q_ASSERT ( p == model->index ( p.row(), p.column(), p.parent() ) ); - } - changing.clear(); -} - -void ModelTest::rowsAboutToBeMoved(const QModelIndex &srcParent, int start, int end, const QModelIndex &destParent, int destinationRow ) -{ - qDebug() << "rowsAboutToBeMoved" << srcParent << start << end << destParent << destinationRow; - Changing cs; - cs.parent = srcParent; - cs.oldSize = model->rowCount ( srcParent ); - cs.last = model->data ( model->index ( start - 1, 0, srcParent ) ); - cs.next = model->data ( model->index ( end + 1, 0, srcParent ) ); - remove.push ( cs ); - Changing cd; - cd.parent = destParent; - cd.oldSize = model->rowCount ( destParent ); - cd.last = model->data ( model->index ( destinationRow - 1, 0, destParent ) ); - cd.next = model->data ( model->index ( destinationRow, 0, destParent ) ); - insert.push ( cd ); -} - -void ModelTest::rowsMoved(const QModelIndex &srcParent, int start, int end, const QModelIndex &destParent, int destinationRow ) -{ - qDebug() << "rowsMoved" << srcParent << start << end << destParent << destinationRow; - - Changing cd = insert.pop(); - Q_ASSERT ( cd.parent == destParent ); - if (srcParent == destParent) - { - Q_ASSERT ( cd.oldSize == model->rowCount ( destParent ) ); - - // TODO: Find out what I can assert here about last and next. -// Q_ASSERT ( cd.last == model->data ( model->index ( destinationRow - 1, 0, cd.parent ) ) ); -// Q_ASSERT ( cd.next == model->data ( model->index ( destinationRow + (end - start + 1), 0, cd.parent ) ) ); - - - } - else - { - Q_ASSERT ( cd.oldSize + ( end - start + 1 ) == model->rowCount ( destParent ) ); - - Q_ASSERT ( cd.last == model->data ( model->index ( destinationRow - 1, 0, cd.parent ) ) ); - Q_ASSERT ( cd.next == model->data ( model->index ( destinationRow + (end - start + 1), 0, cd.parent ) ) ); - } - Changing cs = remove.pop(); - - Q_ASSERT ( cs.parent == srcParent ); - if (srcParent == destParent) - { - Q_ASSERT ( cs.oldSize == model->rowCount ( srcParent ) ); - } - else - { - Q_ASSERT ( cs.oldSize - ( end - start + 1 ) == model->rowCount ( srcParent ) ); - - Q_ASSERT ( cs.last == model->data ( model->index ( start - 1, 0, srcParent ) ) ); - qDebug() << cs.next << model->data ( model->index ( start, 0, srcParent ) ); - Q_ASSERT ( cs.next == model->data ( model->index ( start, 0, srcParent ) ) ); - } - -} - -/*! - Store what is about to be inserted to make sure it actually happens - - \sa rowsRemoved() - */ -void ModelTest::rowsAboutToBeRemoved ( const QModelIndex &parent, int start, int end ) -{ -qDebug() << "ratbr" << parent << start << end; - for (int ii=start; ii <= end; ii++) - { - qDebug() << "itemwillbe removed:" << model->data ( model->index ( ii, 0, parent )); - } - - - Changing c; - c.parent = parent; - c.oldSize = model->rowCount ( parent ); - c.last = model->data ( model->index ( start - 1, 0, parent ) ); - c.next = model->data ( model->index ( end + 1, 0, parent ) ); - remove.push ( c ); -} - -/*! - Confirm that what was said was going to happen actually did - - \sa rowsAboutToBeRemoved() - */ -void ModelTest::rowsRemoved ( const QModelIndex & parent, int start, int end ) -{ - qDebug() << "rr" << parent << start << end; - Changing c = remove.pop(); - Q_ASSERT ( c.parent == parent ); - Q_ASSERT ( c.oldSize - ( end - start + 1 ) == model->rowCount ( parent ) ); - Q_ASSERT ( c.last == model->data ( model->index ( start - 1, 0, c.parent ) ) ); - Q_ASSERT ( c.next == model->data ( model->index ( start, 0, c.parent ) ) ); -} diff --git a/kasten/controllers/view/structures/modeltest.h b/kasten/controllers/view/structures/modeltest.h deleted file mode 100644 index b267195e..00000000 --- a/kasten/controllers/view/structures/modeltest.h +++ /dev/null @@ -1,79 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2007 Trolltech ASA. All rights reserved. -** -** This file is part of the Qt Concurrent project on Trolltech Labs. -** -** This file may be used under the terms of the GNU General Public -** License version 2.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of -** this file. Please review the following information to ensure GNU -** General Public Licensing requirements will be met: -** http://www.trolltech.com/products/qt/opensource.html -** -** If you are unsure which license is appropriate for your use, please -** review the following information: -** http://www.trolltech.com/products/qt/licensing.html or contact the -** sales department at sales@trolltech.com. -** -** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE -** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. -** -****************************************************************************/ - -#ifndef MODELTEST_H -#define MODELTEST_H - -#include -#include -#include - -class ModelTest : public QObject -{ - Q_OBJECT - -public: - explicit ModelTest( QAbstractItemModel *model, QObject *parent = 0 ); - -private Q_SLOTS: - void nonDestructiveBasicTest(); - void rowCount(); - void columnCount(); - void hasIndex(); - void index(); - void parent(); - void data(); - -protected Q_SLOTS: - void runAllTests(); - void layoutAboutToBeChanged(); - void layoutChanged(); - void modelAboutToBeReset(); - void modelReset(); - void rowsAboutToBeInserted( const QModelIndex &parent, int start, int end ); - void rowsInserted( const QModelIndex & parent, int start, int end ); - void rowsAboutToBeRemoved( const QModelIndex &parent, int start, int end ); - void rowsRemoved( const QModelIndex & parent, int start, int end ); - void rowsAboutToBeMoved ( const QModelIndex &, int, int, const QModelIndex &, int); - void rowsMoved ( const QModelIndex &, int, int, const QModelIndex &, int ); - -private: - void checkChildren( const QModelIndex &parent, int currentDepth = 0 ); - - QAbstractItemModel *model; - - struct Changing { - QModelIndex parent; - int oldSize; - QVariant last; - QVariant next; - }; - QStack insert; - QStack remove; - - bool fetchingMore; - - QList changing; -}; - -#endif diff --git a/kasten/controllers/view/structures/structureview.cpp b/kasten/controllers/view/structures/structureview.cpp index 49e606e3..09bf917d 100644 --- a/kasten/controllers/view/structures/structureview.cpp +++ b/kasten/controllers/view/structures/structureview.cpp @@ -1,308 +1,307 @@ /* * This file is part of the Okteta Kasten Framework, made within the KDE community. * * Copyright 2009, 2010, 2012 Alex Richardson * Copyright 2009 Friedrich W. H. Kossebau * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) version 3, or any * later version accepted by the membership of KDE e.V. (or its * successor approved by the membership of KDE e.V.), which shall * act as a proxy defined in Section 6 of version 3 of the license. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . */ #include "structureview.hpp" // controller #include "structuretreemodel.hpp" #include "structurestool.hpp" #include "structuresmanager.hpp" #include "structureviewitemdelegate.hpp" #include "structlogging.hpp" // settings #include "structureviewpreferences.hpp" #include "settings/structureviewsettingswidget.hpp" #include "settings/structuresmanagerview.hpp" #include "settings/structureaddremovewidget.hpp" #include "script/scriptutils.hpp" #include "script/scriptloggerview.hpp" -// #include "modeltest.hpp" - // KF #include #include #include // Qt #include #include #include #include #include #include #include #include +// #include namespace Kasten { StructureView::StructureView(StructuresTool* tool, QWidget* parent) : QWidget(parent) , mTool(tool) , mDelegate(new StructureViewItemDelegate(this)) , mStructTreeViewFocusChild(nullptr) { QBoxLayout* baseLayout = new QVBoxLayout(this); setLayout(baseLayout); baseLayout->setContentsMargins(0, 0, 0, 0); // table mStructureTreeModel = new StructureTreeModel(mTool, this); - // mModeltest = new ModelTest(mStructureTreeModel, this); + // mModeltester = new QAbstractItemModelTester(mStructureTreeModel, this); mStructTreeView = new QTreeView(this); mStructTreeView->setObjectName(QStringLiteral("StructTree")); mStructTreeView->setRootIsDecorated(true); mStructTreeView->setAlternatingRowColors(true); mStructTreeView->setItemsExpandable(true); mStructTreeView->setUniformRowHeights(true); mStructTreeView->setAllColumnsShowFocus(true); mStructTreeView->setEditTriggers(QAbstractItemView::DoubleClicked | QAbstractItemView::EditKeyPressed); mStructTreeView->setItemDelegate(mDelegate); mStructTreeView->setDragEnabled(false); mStructTreeView->setSortingEnabled(false); mStructTreeView->setModel(mStructureTreeModel); mStructTreeView->setHeaderHidden(false); mStructTreeView->setSortingEnabled(false); mStructTreeView->installEventFilter(this); QHeaderView* header = mStructTreeView->header(); header->setSectionResizeMode(QHeaderView::Interactive); baseLayout->addWidget(mStructTreeView, 10); // settings QBoxLayout* settingsLayout = new QHBoxLayout(); settingsLayout->setContentsMargins(0, 0, 0, 0); baseLayout->addLayout(settingsLayout); QIcon validateIcon = QIcon::fromTheme(QStringLiteral("document-sign")); mValidateButton = new QPushButton(validateIcon, i18nc("@action:button", "Validate"), this); const QString validationToolTip = i18nc("@info:tooltip", "Validate all structures."); mValidateButton->setToolTip(validationToolTip); mValidateButton->setEnabled(false); // no point validating without file open connect(mValidateButton, &QPushButton::clicked, mTool, &StructuresTool::validateAllStructures); connect(mTool, &StructuresTool::byteArrayModelChanged, this, &StructureView::onByteArrayModelChanged); // TODO also disable the button if the structure has no validatable members settingsLayout->addWidget(mValidateButton); mLockStructureButton = new QPushButton(this); mLockStructureButton->setCheckable(true); setLockButtonState(false); mLockStructureButton->setEnabled(false); // won't work at beginning connect(mLockStructureButton, &QPushButton::toggled, this, &StructureView::lockButtonToggled); settingsLayout->addWidget(mLockStructureButton); settingsLayout->addStretch(); // stretch before the settings button QIcon console = QIcon::fromTheme(QStringLiteral("utilities-terminal")); mScriptConsoleButton = new QPushButton(console, i18nc("@action:button", "Script console"), this); mScriptConsoleButton->setToolTip(i18nc("@info:tooltip", "Open script console.")); connect(mScriptConsoleButton, &QPushButton::pressed, this, &StructureView::openScriptConsole); settingsLayout->addWidget(mScriptConsoleButton); QIcon settings = QIcon::fromTheme(QStringLiteral("configure")); mSettingsButton = new QPushButton(settings, i18nc("@action:button", "Settings"), this); const QString settingsTooltip = i18nc("@info:tooltip", "Open settings."); mSettingsButton->setToolTip(settingsTooltip); connect(mSettingsButton, &QPushButton::pressed, this, &StructureView::openSettingsDlg); settingsLayout->addWidget(mSettingsButton); connect(mStructTreeView->selectionModel(), &QItemSelectionModel::currentRowChanged, this, &StructureView::onCurrentRowChanged); connect(mTool, &StructuresTool::cursorIndexChanged, this, &StructureView::onCursorIndexChange); } StructureView::~StructureView() = default; StructuresTool* StructureView::tool() const { return mTool; } void StructureView::onCursorIndexChange() { QModelIndex idx = mStructTreeView->currentIndex(); if (idx.isValid()) { mTool->mark(idx); } } void StructureView::openSettingsDlg() { // An instance of your dialog could be already created and could be cached, // in which case you want to display the cached dialog instead of creating // another one if (KConfigDialog::showDialog(QStringLiteral("Structures Tool Settings"))) { return; } // KConfigDialog didn't find an instance of this dialog, so lets create it : KConfigDialog* dialog = new KConfigDialog(this, QStringLiteral("Structures Tool Settings"), StructureViewPreferences::self()); auto* displaySettings = new StructureViewSettingsWidget(); KPageWidgetItem* displ = dialog->addPage(displaySettings, i18n("Value Display"), QStringLiteral("configure")); // cannot use StructuresManagerView directly as page even if the only element // because KConfigDialogManager only scans the children of the page for kcfg_ elements QWidget* structSelectionPage = new QWidget(); auto* hbox = new QHBoxLayout(); hbox->setContentsMargins(0, 0, 0, 0); structSelectionPage->setLayout(hbox); auto* structureSettings = new StructuresManagerView(mTool, this); structureSettings->setObjectName(QStringLiteral("kcfg_LoadedStructures")); hbox->addWidget(structureSettings); dialog->addPage(structSelectionPage, i18n("Structures management"), QStringLiteral("preferences-plugin")); // User edited the configuration - update your local copies of the configuration data connect(dialog, &KConfigDialog::settingsChanged, mTool, &StructuresTool::setSelectedStructuresInView); // TODO: kconfig_compiler signals work now, use those signals and not the generic KConfigDialog::settingsChanged dialog->setCurrentPage(displ); dialog->show(); } bool StructureView::eventFilter(QObject* object, QEvent* event) { if (object == mStructTreeView) { if (event->type() == QEvent::FocusIn) { const QModelIndex current = mStructTreeView->selectionModel()->currentIndex(); if (current.isValid()) { mTool->mark(current); } else { mTool->unmark(); } setLockButtonState(current); } else if (event->type() == QEvent::FocusOut) { QWidget* treeViewFocusWidget = mStructTreeView->focusWidget(); const bool subChildHasFocus = (treeViewFocusWidget != mStructTreeView); if (subChildHasFocus) { mStructTreeViewFocusChild = treeViewFocusWidget; mStructTreeViewFocusChild->installEventFilter(this); } else { mTool->unmark(); } } } else if (object == mStructTreeViewFocusChild) { // TODO: it is only assumed the edit widget will be removed if it loses the focus if (event->type() == QEvent::FocusOut) { if (!mStructTreeView->hasFocus()) { mTool->unmark(); } mStructTreeViewFocusChild->removeEventFilter(this); mStructTreeViewFocusChild = nullptr; } } return QWidget::eventFilter(object, event); } void StructureView::setLockButtonState(const QModelIndex& current) { // qCDebug(LOG_KASTEN_OKTETA_CONTROLLERS_STRUCTURES) << "setLockButtonState() for" << current; // we don't want the toggled signal here, only when the user clicks the button! QSignalBlocker block(mLockStructureButton); setLockButtonState(mTool->isStructureLocked(current)); mLockStructureButton->setEnabled(mTool->canStructureBeLocked(current)); } void StructureView::onCurrentRowChanged(const QModelIndex& current, const QModelIndex& previous) { Q_UNUSED(previous) if (current.isValid() && mTool->byteArrayModel()) { mTool->mark(current); setLockButtonState(current); } else { mTool->unmark(); } } void StructureView::lockButtonToggled() { // qCDebug(LOG_KASTEN_OKTETA_CONTROLLERS_STRUCTURES) << "Lock button toggled"; setLockButtonState(mLockStructureButton->isChecked()); const QModelIndex current = mStructTreeView->selectionModel()->currentIndex(); if (!current.isValid()) { qCWarning(LOG_KASTEN_OKTETA_CONTROLLERS_STRUCTURES) << "it should not be possible to toggle this button when current index is invalid!"; return; } if (mLockStructureButton->isChecked()) { mTool->lockStructure(current); } else { mTool->unlockStructure(current); } } void StructureView::setLockButtonState(bool structureLocked) { if (structureLocked) { mLockStructureButton->setIcon(QIcon::fromTheme(QStringLiteral("object-locked"))); mLockStructureButton->setText(i18nc("@action:button" " unlock the starting offset of the current structure", "Unlock")); mLockStructureButton->setToolTip(i18nc("@info:tooltip", "Unlock selected structure, i.e. the starting offset is" " always set to the current cursor position.")); } else { mLockStructureButton->setIcon(QIcon::fromTheme(QStringLiteral("object-unlocked"))); mLockStructureButton->setText(i18nc("@action:button" " unlock the starting offset of the current structure", "Lock")); mLockStructureButton->setToolTip(i18nc("@info:tooltip", "Lock selected structure to current offset.")); } mLockStructureButton->setChecked(structureLocked); } void StructureView::openScriptConsole() { QDialog* dialog = new QDialog(this); dialog->setWindowTitle(i18nc("@title:window", "Structures Script Console")); auto* layout = new QVBoxLayout; auto* dialogButtonBox = new QDialogButtonBox; QPushButton* closeButton = dialogButtonBox->addButton(QDialogButtonBox::Close); connect(closeButton, &QPushButton::clicked, dialog, &QDialog::accept); layout->addWidget(new ScriptLoggerView(mTool->allData())); layout->addWidget(dialogButtonBox); dialog->setLayout(layout); dialog->show(); } void StructureView::onByteArrayModelChanged(Okteta::AbstractByteArrayModel* model) { const bool validModel = (model != nullptr); QModelIndex current = mStructTreeView->currentIndex(); mLockStructureButton->setEnabled(mTool->canStructureBeLocked(current)); setLockButtonState(mTool->isStructureLocked(current)); mValidateButton->setEnabled(validModel); } }