File indexing completed on 2024-04-21 16:34:02
0001 /* 0002 This file is part of the Okteta Gui library, made within the KDE community. 0003 0004 SPDX-FileCopyrightText: 2003, 2008-2009 Friedrich W. H. Kossebau <kossebau@kde.org> 0005 0006 SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL 0007 */ 0008 0009 #ifndef OKTETA_BYTEARRAYTABLERANGES_HPP 0010 #define OKTETA_BYTEARRAYTABLERANGES_HPP 0011 0012 // lib 0013 #include "oktetagui_export.hpp" 0014 #include "selection.hpp" 0015 #include "coordrangelist.hpp" 0016 // Okteta core 0017 #include <Okteta/AddressRange> 0018 // Qt 0019 #include <QScopedPointer> 0020 0021 namespace Okteta { 0022 class ArrayChangeMetricsList; 0023 class ByteArrayTableLayout; 0024 class ByteArrayTableRangesPrivate; 0025 0026 /** a class to control all the ranges like marking and selections 0027 * holds also all modified ranges and merges them so a repaint can take its info from here 0028 * 0029 * @author Friedrich W. H. Kossebau 0030 */ 0031 // TODO: split info about ranges from info about dirty ranges into a second class 0032 class OKTETAGUI_EXPORT ByteArrayTableRanges 0033 { 0034 public: 0035 explicit ByteArrayTableRanges(ByteArrayTableLayout* layout); 0036 ByteArrayTableRanges(const ByteArrayTableRanges&) = delete; 0037 0038 ~ByteArrayTableRanges(); 0039 0040 ByteArrayTableRanges& operator=(const ByteArrayTableRanges&) = delete; 0041 0042 public: // modifcation access 0043 void setMarking(const AddressRange& marking); 0044 void setSelectionStart(Address startIndex); 0045 void setSelectionEnd(Address startIndex); 0046 void setSelection(const AddressRange& selection); 0047 /** */ 0048 void setFirstWordSelection(const AddressRange& selection); 0049 /** */ 0050 void ensureWordSelectionForward(bool Forward); 0051 0052 /** removes selection with id and returns it */ 0053 AddressRange removeSelection(int id = 0); 0054 /** removes all but the standard selection and returns true if something changed */ 0055 void removeFurtherSelections(); 0056 0057 /** assumes all added lines to overlap */ 0058 void addChangedOffsetLines(const LineRange& changesLines); 0059 0060 void addChangedRange(const AddressRange& range); 0061 void addChangedRange(Address start, Address end); 0062 void addChangedRange(const CoordRange& range); 0063 void adaptToChanges(const ArrayChangeMetricsList& changeList, Size oldLength); 0064 void resetChangedRanges(); 0065 0066 void takeHasSelectionChanged(bool* hasSelectionChanged, bool* selectionChanged); 0067 void setModified(bool M = true); 0068 /** removes all ranges */ 0069 void reset(); 0070 0071 public: // value access 0072 int noOfSelections() const; 0073 Address selectionStart() const; 0074 Address selectionEnd() const; 0075 AddressRange selection() const; 0076 AddressRange firstWordSelection() const; 0077 Size selectionLength() const; 0078 AddressRange marking() const; 0079 bool isModified() const; 0080 LineRange changedOffsetLines() const; 0081 0082 public: // calculated logic access 0083 bool hasSelection() const; 0084 bool hasMarking() const; 0085 bool selectionStarted() const; 0086 bool selectionJustStarted() const; 0087 bool hasFirstWordSelection() const; 0088 bool selectionIncludes(Address index) const; 0089 bool markingIncludes(Address index) const; 0090 // TODO: next three are deprecated 0091 bool overlapsSelection(Address FirstIndex, Address LastIndex, Address* SI, Address* EI) const; 0092 bool overlapsMarking(Address FirstIndex, Address LastIndex, Address* SI, Address* EI) const; 0093 // bool overlapsChanges( int FirstIndex, int LastIndex, int *SI, int *EI ) const; 0094 // bool overlapsChanges( AddressRange Indizes, AddressRange *ChangedRange ) const; 0095 bool overlapsChanges(const CoordRange& range, CoordRange* ChangedRange) const; 0096 const AddressRange* firstOverlappingSelection(const AddressRange& range) const; 0097 const AddressRange* overlappingMarking(const AddressRange& range) const; 0098 0099 private: 0100 /** true if something changed */ 0101 bool mModified = false; 0102 0103 AddressRange mMarking; 0104 Selection mSelection; 0105 /** memories first selected word on wordwise selection */ 0106 AddressRange FirstWordSelection; 0107 0108 /** lines that were added or removed */ 0109 LineRange mChangedOffsetLines; 0110 0111 CoordRangeList ChangedRanges; 0112 0113 const QScopedPointer<ByteArrayTableRangesPrivate> d_ptr; 0114 Q_DECLARE_PRIVATE(ByteArrayTableRanges) 0115 }; 0116 0117 inline int ByteArrayTableRanges::noOfSelections() const { return 1; } 0118 0119 inline Address ByteArrayTableRanges::selectionStart() const { return mSelection.start(); } 0120 inline Address ByteArrayTableRanges::selectionEnd() const { return mSelection.end(); } 0121 inline AddressRange ByteArrayTableRanges::selection() const { return mSelection.range(); } 0122 inline AddressRange ByteArrayTableRanges::firstWordSelection() const { return FirstWordSelection; } 0123 inline Size ByteArrayTableRanges::selectionLength() const { return mSelection.range().width(); } 0124 inline AddressRange ByteArrayTableRanges::marking() const { return mMarking; } 0125 inline bool ByteArrayTableRanges::isModified() const { return mModified; } 0126 inline LineRange ByteArrayTableRanges::changedOffsetLines() const { return mChangedOffsetLines; } 0127 0128 inline bool ByteArrayTableRanges::hasSelection() const { return mSelection.isValid(); } 0129 inline bool ByteArrayTableRanges::selectionStarted() const { return mSelection.started(); } 0130 inline bool ByteArrayTableRanges::selectionJustStarted() const { return mSelection.justStarted(); } 0131 inline bool ByteArrayTableRanges::hasFirstWordSelection() const { return FirstWordSelection.isValid(); } 0132 inline bool ByteArrayTableRanges::hasMarking() const { return mMarking.isValid(); } 0133 inline bool ByteArrayTableRanges::selectionIncludes(Address index) const { return mSelection.range().includes(index); } 0134 inline bool ByteArrayTableRanges::markingIncludes(Address index) const { return mMarking.includes(index); } 0135 0136 inline void ByteArrayTableRanges::setModified(bool M) { mModified = M; } 0137 0138 } 0139 0140 #endif