Skip to content

Commit 4429965

Browse files
committed
fix: 优化修复元数据标注合并可视化相关问题;
1 parent c1689b1 commit 4429965

12 files changed

Lines changed: 197 additions & 142 deletions

3rdparty/QHexView/document/commands/baseaddrcommand.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,7 @@ int BaseAddrCommand::id() const { return UndoID_SetBaseAddr; }
4141

4242
bool BaseAddrCommand::mergeWith(const QUndoCommand *other) {
4343
auto ucmd = static_cast<const BaseAddrCommand *>(other);
44-
if (ucmd && ucmd->m_doc == this->m_doc) {
45-
this->m_new = ucmd->m_new;
46-
setText(constructText(this->m_old, this->m_new));
44+
if (ucmd && this->m_new == ucmd->m_new) {
4745
return true;
4846
}
4947
return false;

3rdparty/QHexView/document/commands/bookmark/bookmarkaddcommand.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,7 @@ int BookMarkAddCommand::id() const { return UndoID_BookMarkAdd; }
3737
bool BookMarkAddCommand::mergeWith(const QUndoCommand *other) {
3838
auto ucmd = static_cast<const BookMarkAddCommand *>(other);
3939
if (ucmd) {
40-
if (this->m_pos == ucmd->m_pos) {
41-
this->m_comment = m_comment;
40+
if (this->m_pos == ucmd->m_pos && this->m_comment == m_comment) {
4241
return true;
4342
}
4443
}

3rdparty/QHexView/document/commands/bookmark/bookmarkreplacecommand.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,7 @@ int BookMarkReplaceCommand::id() const { return UndoID_BookMarkReplace; }
4040
bool BookMarkReplaceCommand::mergeWith(const QUndoCommand *other) {
4141
auto ucmd = static_cast<const BookMarkReplaceCommand *>(other);
4242
if (ucmd) {
43-
if (this->m_pos == ucmd->m_pos) {
44-
this->m_comment = m_comment;
43+
if (this->m_pos == ucmd->m_pos && this->m_comment == m_comment) {
4544
return true;
4645
}
4746
}

3rdparty/QHexView/document/commands/meta/metaaddcommand.cpp

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121

2222
#include "metaaddcommand.h"
2323

24+
namespace {
2425
inline QString constructText(const QHexMetadataItem &meta) {
2526
auto buffer = QStringLiteral("[M+] {pos: %1-0x%2} {len: %3-0x%4} ")
2627
.arg(QString::number(meta.begin),
@@ -38,6 +39,7 @@ inline QString constructText(const QHexMetadataItem &meta) {
3839
}
3940
return buffer;
4041
}
42+
} // namespace
4143

4244
MetaAddCommand::MetaAddCommand(QHexMetadata *hexmeta,
4345
const QHexMetadataItem &meta,
@@ -55,22 +57,14 @@ int MetaAddCommand::id() const { return UndoID_MetaAdd; }
5557
bool MetaAddCommand::mergeWith(const QUndoCommand *other) {
5658
auto ucmd = static_cast<const MetaAddCommand *>(other);
5759
if (ucmd) {
58-
if (this->m_meta.foreground == ucmd->m_meta.foreground &&
59-
this->m_meta.background == ucmd->m_meta.background &&
60-
this->m_meta.comment == ucmd->m_meta.comment) {
61-
auto r = this->m_meta.mergeRegionWithoutMetaCheck(ucmd->m_meta);
62-
if (r) {
63-
setText(constructText(this->m_meta));
64-
}
65-
return r;
66-
}
60+
return this->m_meta == ucmd->m_meta;
6761
}
6862
return false;
6963
}
7064

7165
void MetaAddCommand::undo() {
7266
m_hexmeta->removeMetadata(m_meta.begin, m_meta.end);
73-
for (const auto &meta : _brokenMetas) {
67+
for (const auto &meta : std::as_const(_brokenMetas)) {
7468
m_hexmeta->metadata(meta.begin, meta.end, meta.foreground,
7569
meta.background, meta.comment);
7670
}

3rdparty/QHexView/document/commands/meta/metaaddcommand.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ class MetaAddCommand : public MetaCommand {
3939
virtual bool mergeWith(const QUndoCommand *other) override;
4040

4141
private:
42-
const QVector<QHexMetadataItem> _brokenMetas;
42+
QVector<QHexMetadataItem> _brokenMetas;
4343
};
4444

4545
#endif // METAADDCOMMAND_H

3rdparty/QHexView/document/commands/meta/metaremovecommand.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121

2222
#include "metaremovecommand.h"
2323

24+
namespace {
2425
inline QString constructText(const QHexMetadataItem &meta) {
2526
auto buffer = QStringLiteral("[M-] {pos: %1-0x%2} ")
2627
.arg(QString::number(meta.begin),
@@ -36,6 +37,7 @@ inline QString constructText(const QHexMetadataItem &meta) {
3637
}
3738
return buffer;
3839
}
40+
} // namespace
3941

4042
MetaRemoveCommand::MetaRemoveCommand(QHexMetadata *hexmeta,
4143
const QHexMetadataItem &meta,
@@ -49,7 +51,8 @@ int MetaRemoveCommand::id() const { return UndoID_MetaRemove; }
4951
bool MetaRemoveCommand::mergeWith(const QUndoCommand *other) {
5052
auto ucmd = static_cast<const MetaRemoveCommand *>(other);
5153
if (ucmd) {
52-
return this->m_meta == ucmd->m_meta;
54+
return this->m_meta.begin == ucmd->m_meta.begin &&
55+
this->m_meta.end == ucmd->m_meta.end;
5356
}
5457
return false;
5558
}

3rdparty/QHexView/document/commands/meta/metaremoveposcommand.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,12 @@
2121

2222
#include "metaremoveposcommand.h"
2323

24+
namespace {
2425
inline QString constructText(qsizetype pos) {
2526
return QStringLiteral("[M-] {pos: %1-0x%2} ")
2627
.arg(QString::number(pos), QString::number(pos, 16).toUpper());
2728
}
29+
} // namespace
2830

2931
MetaRemovePosCommand::MetaRemovePosCommand(QHexMetadata *hexmeta, qsizetype pos,
3032
QUndoCommand *parent)
@@ -42,9 +44,7 @@ int MetaRemovePosCommand::id() const { return UndoID_MetaRemovePos; }
4244
bool MetaRemovePosCommand::mergeWith(const QUndoCommand *other) {
4345
auto ucmd = static_cast<const MetaRemovePosCommand *>(other);
4446
if (ucmd) {
45-
if (this->m_pos == ucmd->m_pos) {
46-
return true;
47-
}
47+
return this->m_pos == ucmd->m_pos;
4848
}
4949
return false;
5050
}

3rdparty/QHexView/document/commands/meta/metareplacecommand.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121

2222
#include "metareplacecommand.h"
2323

24+
namespace {
2425
inline QString constructText(const QHexMetadataItem &meta,
2526
const QHexMetadataItem &oldmeta) {
2627
auto buffer = QStringLiteral("[M*] {pos: %1-0x%2} ")
@@ -62,6 +63,7 @@ inline QString constructText(const QHexMetadataItem &meta,
6263

6364
return buffer;
6465
}
66+
} // namespace
6567

6668
MetaReplaceCommand::MetaReplaceCommand(QHexMetadata *hexmeta,
6769
const QHexMetadataItem &meta,
@@ -79,9 +81,7 @@ int MetaReplaceCommand::id() const { return UndoID_MetaReplace; }
7981
bool MetaReplaceCommand::mergeWith(const QUndoCommand *other) {
8082
auto ucmd = static_cast<const MetaReplaceCommand *>(other);
8183
if (ucmd) {
82-
if (this->m_old == ucmd->m_old) {
83-
this->m_meta = ucmd->m_meta;
84-
setText(constructText(this->m_meta, this->m_old));
84+
if (this->m_meta == ucmd->m_meta) {
8585
return true;
8686
}
8787
}

3rdparty/QHexView/document/qhexcursor.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ struct QHexPosition {
8080
};
8181
Q_DECLARE_METATYPE(QHexPosition)
8282

83-
struct QHexSelection : QHexRegionObject<QHexPosition, QHexSelection> {
83+
struct QHexSelection final : QHexRegionObject<QHexPosition, QHexSelection> {
8484
inline QHexSelection() = default;
8585

8686
inline explicit QHexSelection(const QHexPosition &begin,

3rdparty/QHexView/document/qhexmetadata.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -405,7 +405,7 @@ QVector<QHexMetadataItem> QHexMetadata::removeAdjust(qsizetype offset,
405405
}
406406
if (meta.begin <= offset && meta.end > offset) {
407407
if (meta.begin > meta.end - length) {
408-
meta.flag = true;
408+
meta.adjflag = true;
409409
} else {
410410
meta.end -= length;
411411
}
@@ -415,7 +415,7 @@ QVector<QHexMetadataItem> QHexMetadata::removeAdjust(qsizetype offset,
415415
}
416416
});
417417

418-
auto rmfn = [](const QHexMetadataItem &meta) { return meta.flag; };
418+
auto rmfn = [](const QHexMetadataItem &meta) { return meta.adjflag; };
419419

420420
std::copy_if(
421421
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
@@ -435,7 +435,7 @@ QVector<QHexMetadataItem> QHexMetadata::removeAdjust(qsizetype offset,
435435
Q_EMIT metadataChanged();
436436

437437
QtConcurrent::blockingMap(
438-
rmmetas, [](QHexMetadataItem &meta) { meta.flag = false; });
438+
rmmetas, [](QHexMetadataItem &meta) { meta.adjflag = false; });
439439
}
440440

441441
return rmmetas;
@@ -550,7 +550,6 @@ void QHexMetadata::addMetadata(const QHexMetadataItem &mi) {
550550
for (const auto &idx : r.inserted) {
551551
addMetaLines(m_metadata.at(idx));
552552
}
553-
addMetaLines(mi);
554553
}
555554

556555
void QHexMetadata::addMetaLines(const QHexMetadataItem &mi) {

0 commit comments

Comments
 (0)