mirror of
https://github.com/LongSoft/UEFITool.git
synced 2024-11-24 08:58:23 +08:00
Apply hex cleaning to search dialog paste operations
- Permits pasting to 'GUID' search directly from cpp representation - Provides hex cleaning (e.g. auto-remove 0x) in 'Hex pattern' search as well
This commit is contained in:
parent
71a7336730
commit
1d560bd0be
@ -32,7 +32,7 @@ SET(PROJECT_SOURCES
|
|||||||
uefitool.cpp
|
uefitool.cpp
|
||||||
searchdialog.cpp
|
searchdialog.cpp
|
||||||
hexviewdialog.cpp
|
hexviewdialog.cpp
|
||||||
guidlineedit.cpp
|
hexlineedit.cpp
|
||||||
ffsfinder.cpp
|
ffsfinder.cpp
|
||||||
hexspinbox.cpp
|
hexspinbox.cpp
|
||||||
qhexedit2/qhexedit.cpp
|
qhexedit2/qhexedit.cpp
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
/* guidlineedit.cpp
|
/* hexlineedit.cpp
|
||||||
|
|
||||||
Copyright (c) 2014, Nikolaj Schlej. All rights reserved.
|
Copyright (c) 2014, Nikolaj Schlej. All rights reserved.
|
||||||
This program and the accompanying materials
|
This program and the accompanying materials
|
||||||
@ -11,25 +11,34 @@
|
|||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "guidlineedit.h"
|
#include "hexlineedit.h"
|
||||||
|
|
||||||
GuidLineEdit::GuidLineEdit(QWidget * parent)
|
#if QT_VERSION_MAJOR >= 6
|
||||||
|
#include <QRegularExpression>
|
||||||
|
#else
|
||||||
|
#include <QRegExp>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
HexLineEdit::HexLineEdit(QWidget * parent)
|
||||||
:QLineEdit(parent)
|
:QLineEdit(parent)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
GuidLineEdit::GuidLineEdit(const QString & contents, QWidget * parent)
|
HexLineEdit::HexLineEdit(const QString & contents, QWidget * parent)
|
||||||
:QLineEdit(contents, parent)
|
:QLineEdit(contents, parent)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
GuidLineEdit::~GuidLineEdit()
|
HexLineEdit::~HexLineEdit()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
void GuidLineEdit::keyPressEvent(QKeyEvent * event)
|
void HexLineEdit::keyPressEvent(QKeyEvent * event)
|
||||||
{
|
{
|
||||||
if (event == QKeySequence::Delete || event->key() == Qt::Key_Backspace)
|
QClipboard *clipboard;
|
||||||
|
QString originalText;
|
||||||
|
|
||||||
|
if (m_editAsGuid && (event == QKeySequence::Delete || event->key() == Qt::Key_Backspace))
|
||||||
{
|
{
|
||||||
int pos = cursorPosition();
|
int pos = cursorPosition();
|
||||||
if (event->key() == Qt::Key_Backspace && pos > 0) {
|
if (event->key() == Qt::Key_Backspace && pos > 0) {
|
||||||
@ -56,7 +65,25 @@ void GuidLineEdit::keyPressEvent(QKeyEvent * event)
|
|||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (event == QKeySequence::Paste)
|
||||||
|
{
|
||||||
|
clipboard = QApplication::clipboard();
|
||||||
|
originalText = clipboard->text();
|
||||||
|
QString cleanedHex = QString(originalText).replace(QString("0x"), QString(""), Qt::CaseInsensitive);
|
||||||
|
#if QT_VERSION_MAJOR >= 6
|
||||||
|
cleanedHex.remove(QRegularExpression("[^a-fA-F\\d]+"));
|
||||||
|
#else
|
||||||
|
cleanedHex.remove(QRegExp("[^a-fA-F\\d]+"));
|
||||||
|
#endif
|
||||||
|
clipboard->setText(cleanedHex);
|
||||||
|
}
|
||||||
|
|
||||||
// Call original event handler
|
// Call original event handler
|
||||||
QLineEdit::keyPressEvent(event);
|
QLineEdit::keyPressEvent(event);
|
||||||
|
|
||||||
|
if (event == QKeySequence::Paste)
|
||||||
|
{
|
||||||
|
clipboard->setText(originalText);
|
||||||
|
}
|
||||||
}
|
}
|
@ -1,4 +1,4 @@
|
|||||||
/* guidlineedit.h
|
/* hexlineedit.h
|
||||||
|
|
||||||
Copyright (c) 2014, Nikolaj Schlej. All rights reserved.
|
Copyright (c) 2014, Nikolaj Schlej. All rights reserved.
|
||||||
This program and the accompanying materials
|
This program and the accompanying materials
|
||||||
@ -11,9 +11,11 @@
|
|||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef GUIDLINEEDIT_H
|
#ifndef HEXLINEEDIT_H
|
||||||
#define GUIDLINEEDIT_H
|
#define HEXLINEEDIT_H
|
||||||
|
|
||||||
|
#include <QApplication>
|
||||||
|
#include <QClipboard>
|
||||||
#include <QLineEdit>
|
#include <QLineEdit>
|
||||||
#include <QKeyEvent>
|
#include <QKeyEvent>
|
||||||
#include <QKeySequence>
|
#include <QKeySequence>
|
||||||
@ -21,16 +23,29 @@
|
|||||||
|
|
||||||
#include "../common/basetypes.h"
|
#include "../common/basetypes.h"
|
||||||
|
|
||||||
class GuidLineEdit : public QLineEdit
|
class HexLineEdit : public QLineEdit
|
||||||
{
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
Q_PROPERTY(bool editAsGuid READ editAsGuid WRITE setEditAsGuid)
|
||||||
|
|
||||||
public:
|
public:
|
||||||
GuidLineEdit(QWidget * parent = 0);
|
HexLineEdit(QWidget * parent = 0);
|
||||||
GuidLineEdit(const QString & contents, QWidget * parent = 0);
|
HexLineEdit(const QString & contents, QWidget * parent = 0);
|
||||||
~GuidLineEdit();
|
~HexLineEdit();
|
||||||
|
|
||||||
|
void setEditAsGuid(bool editAsGuid)
|
||||||
|
{
|
||||||
|
m_editAsGuid = editAsGuid;
|
||||||
|
}
|
||||||
|
bool editAsGuid() const
|
||||||
|
{ return m_editAsGuid; }
|
||||||
|
|
||||||
|
private:
|
||||||
|
bool m_editAsGuid;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void keyPressEvent(QKeyEvent * event);
|
void keyPressEvent(QKeyEvent * event);
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // GUIDLINEEDIT_H
|
#endif // HEXLINEEDIT_H
|
@ -35,7 +35,10 @@
|
|||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item row="0" column="1">
|
<item row="0" column="1">
|
||||||
<widget class="QLineEdit" name="hexEdit">
|
<widget class="HexLineEdit" name="hexEdit">
|
||||||
|
<property name="editAsGuid">
|
||||||
|
<bool>false</bool>
|
||||||
|
</property>
|
||||||
<property name="inputMask">
|
<property name="inputMask">
|
||||||
<string/>
|
<string/>
|
||||||
</property>
|
</property>
|
||||||
@ -89,7 +92,10 @@
|
|||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item row="0" column="1">
|
<item row="0" column="1">
|
||||||
<widget class="GuidLineEdit" name="guidEdit">
|
<widget class="HexLineEdit" name="guidEdit">
|
||||||
|
<property name="editAsGuid">
|
||||||
|
<bool>true</bool>
|
||||||
|
</property>
|
||||||
<property name="inputMask">
|
<property name="inputMask">
|
||||||
<string>xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx</string>
|
<string>xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx</string>
|
||||||
</property>
|
</property>
|
||||||
@ -241,9 +247,9 @@
|
|||||||
</widget>
|
</widget>
|
||||||
<customwidgets>
|
<customwidgets>
|
||||||
<customwidget>
|
<customwidget>
|
||||||
<class>GuidLineEdit</class>
|
<class>HexLineEdit</class>
|
||||||
<extends>QLineEdit</extends>
|
<extends>QLineEdit</extends>
|
||||||
<header>guidlineedit.h</header>
|
<header>hexlineedit.h</header>
|
||||||
</customwidget>
|
</customwidget>
|
||||||
</customwidgets>
|
</customwidgets>
|
||||||
<tabstops>
|
<tabstops>
|
||||||
|
@ -15,7 +15,7 @@ HEADERS += uefitool.h \
|
|||||||
hexviewdialog.h \
|
hexviewdialog.h \
|
||||||
gotobasedialog.h \
|
gotobasedialog.h \
|
||||||
gotoaddressdialog.h \
|
gotoaddressdialog.h \
|
||||||
guidlineedit.h \
|
hexlineedit.h \
|
||||||
ffsfinder.h \
|
ffsfinder.h \
|
||||||
hexspinbox.h \
|
hexspinbox.h \
|
||||||
../common/fitparser.h \
|
../common/fitparser.h \
|
||||||
@ -69,7 +69,7 @@ SOURCES += uefitool_main.cpp \
|
|||||||
uefitool.cpp \
|
uefitool.cpp \
|
||||||
searchdialog.cpp \
|
searchdialog.cpp \
|
||||||
hexviewdialog.cpp \
|
hexviewdialog.cpp \
|
||||||
guidlineedit.cpp \
|
hexlineedit.cpp \
|
||||||
ffsfinder.cpp \
|
ffsfinder.cpp \
|
||||||
hexspinbox.cpp \
|
hexspinbox.cpp \
|
||||||
../common/fitparser.cpp \
|
../common/fitparser.cpp \
|
||||||
|
Loading…
Reference in New Issue
Block a user