@@ -187,8 +187,7 @@ QHexView::QHexView(QWidget *parent)
187187
188188 connect (m_blinktimer, &QTimer::timeout, this , &QHexView::blinkCursor);
189189
190- this ->setDocument (QSharedPointer<QHexDocument>(
191- QHexDocument::fromInternalBuffer<QMemoryBuffer>(false )));
190+ resetDocument ();
192191}
193192
194193QHexView::~QHexView () { m_blinktimer->stop (); }
@@ -243,6 +242,11 @@ void QHexView::setDocument(const QSharedPointer<QHexDocument> &document,
243242 this ->viewport ()->update ();
244243}
245244
245+ void QHexView::resetDocument () {
246+ this ->setDocument (QSharedPointer<QHexDocument>(
247+ QHexDocument::fromInternalBuffer<QMemoryBuffer>(false )));
248+ }
249+
246250bool QHexView::event (QEvent *e) {
247251 if (m_renderer && (e->type () == QEvent::FontChange)) {
248252 m_renderer->updateMetrics (QFontMetricsF (this ->font ()));
@@ -362,8 +366,13 @@ qsizetype QHexView::findPrevious(qsizetype begin, const QByteArray &ba) {
362366}
363367
364368bool QHexView::RemoveSelection (int nibbleindex) {
365- if (!m_cursor->hasSelection ())
369+ if (isReadOnly () || isKeepSize ()) {
370+ return false ;
371+ }
372+
373+ if (!m_cursor->hasSelection ()) {
366374 return true ;
375+ }
367376
368377 auto total = m_cursor->selectionCount ();
369378 auto msg = QStringLiteral (" [H-G] {cnt: %1}" ).arg (total);
@@ -998,20 +1007,17 @@ bool QHexView::processAction(QHexCursor *cur, QKeyEvent *e) {
9981007 if (isKeepSize ()) {
9991008 if (cur->insertionMode () == QHexCursor::OverwriteMode) {
10001009 if (e->key () == Qt::Key_Backspace)
1001- m_document->Replace (m_cursor,
1002- cur->position ().offset () - 1 ,
1010+ m_document->Replace (m_cursor, pos.offset () - 1 ,
10031011 uchar (0 ), 0 );
10041012 else
1005- m_document->Replace (m_cursor, cur-> position () .offset (),
1006- uchar ( 0 ), 0 );
1013+ m_document->Replace (m_cursor, pos .offset (), uchar ( 0 ),
1014+ 0 );
10071015 }
10081016 } else {
10091017 if (e->key () == Qt::Key_Backspace)
1010- m_document->Remove (m_cursor, cur->position ().offset () - 1 ,
1011- 1 , 1 );
1018+ m_document->Remove (m_cursor, pos.offset () - 1 , 1 , 1 );
10121019 else
1013- m_document->Remove (m_cursor, cur->position ().offset (), 1 ,
1014- 0 );
1020+ m_document->Remove (m_cursor, pos.offset (), 1 , 0 );
10151021 }
10161022
10171023 } else {
0 commit comments