-
Notifications
You must be signed in to change notification settings - Fork 120
Add more representations of unprintable bytes #380
base: master
Are you sure you want to change the base?
Add more representations of unprintable bytes #380
Conversation
*) Convert byte to pretty unicode representation *) Create gui options of default unprintable characters rendering *) Save unprintable mode default settings *) Add icon to view toolbar *) Add instant unprintable mode changing
include/ui/hexedit.h
Outdated
| QScopedPointer<util::encoders::TextEncoder> textEncoder_; | ||
| util::EditEngine edit_engine_; | ||
|
|
||
| QString unprintablesModeString; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a private field, so it should be named unprintables_mode_string_.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
src/ui/hexedit.cc
Outdated
| #include "util/settings/hexedit.h" | ||
| #include "util/settings/theme.h" | ||
|
|
||
| #include <unistd.h> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can't use this header, it's non-standard (and as a result it doesn't compile on Windows, for example).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a debugging leftover, removed.
src/ui/hexedit.cc
Outdated
| }); | ||
| } | ||
|
|
||
| void HexEdit::updateAsciiCache() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please place this method in the same place as it was in the header file.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same for HexEdit::updateHexCache()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
include/util/settings/hexedit.h
Outdated
| void setColumnsNumber(int number); | ||
| bool resizeColumnsToWindowWidth(); | ||
| void setResizeColumnsToWindowWidth(bool on); | ||
| QString unprintablesModes(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IMO it should be unprintablesMode (without s).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, typo. Thanks for catching.
include/util/settings/hexedit.h
Outdated
| bool resizeColumnsToWindowWidth(); | ||
| void setResizeColumnsToWindowWidth(bool on); | ||
| QString unprintablesModes(); | ||
| void setUnprintablesMode(QString mode); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be const QString& mode.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rewritten.
src/ui/hexedit.cc
Outdated
| } | ||
|
|
||
| // ascii-unprintable chars | ||
| char a = (static_cast<char>(byte_val)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This conversion is implementation-defined for byte_val >= 0x80, please wrap the higher values by hand (or create a helper function in veles::utils::).
And yes, this seems to be a general problem with Qt APIs - they use char* everywhere for byte arrays.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
src/ui/hexedit.cc
Outdated
| byte_idx, modified_positions[byte_idx - start_byte]); | ||
| bool redraw_hex = invalidated_rect.intersects(hex_rect); | ||
| bool redraw_ascii = invalidated_rect.intersects(ascii_rect); | ||
| bool redraw_ascii = true; // invalidated_rect.intersects(ascii_rect); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A leftover from debugging? ;)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yup, removed.
src/ui/hexeditwidget.cc
Outdated
| unprintables_menu_.clear(); | ||
| unprintables_menu_.addAction("dots"); | ||
| unprintables_menu_.addSeparator(); | ||
| unprintables_menu_.addAction("windows-1250"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
windows-1250 -> Windows-1250
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rewritten.
src/ui/hexeditwidget.cc
Outdated
| void HexEditWidget::initUnprintablesMenu() { | ||
| unprintables_menu_.clear(); | ||
| unprintables_menu_.addAction("dots"); | ||
| unprintables_menu_.addSeparator(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why a separator here? We have only two options, so it not too useful now ;)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed.
src/ui/hexeditwidget.cc
Outdated
|
|
||
| void HexEditWidget::initUnprintablesMenu() { | ||
| unprintables_menu_.clear(); | ||
| unprintables_menu_.addAction("dots"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
dots -> Dots
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rewritten.
include/ui/hexedit.h
Outdated
| public: | ||
| enum class UnprintablesMode { | ||
| Dots, | ||
| Windows_1250, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use uppercase names (see Google style guide)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
include/ui/hexedit.h
Outdated
| enum class UnprintablesMode { | ||
| Dots, | ||
| Windows_1250, | ||
| }; // do not change the order as settings may invalidate. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please put this comment right after the enum class ... line.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
src/ui/hexedit.cc
Outdated
|
|
||
| void HexEdit::setUnprintablesMode(UnprintablesMode mode) { | ||
| unprintables_mode_ = mode; | ||
| if (mode == UnprintablesMode::Windows_1250 && windows1250_codec_ == nullptr) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You should do this check before assigning to unprintables_mode_.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
src/ui/hexedit.cc
Outdated
| void HexEdit::setUnprintablesMode(UnprintablesMode mode) { | ||
| unprintables_mode_ = mode; | ||
| if (mode == UnprintablesMode::Windows_1250 && windows1250_codec_ == nullptr) { | ||
| QMessageBox::warning(this, "Error", "Windows-1250 is unavailable.", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"Windows-1250 is -> "Windows-1250 encoding is
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
| saveDataToFile(0, edit_engine_.dataSize(), file_name); | ||
| } | ||
|
|
||
| QString HexEdit::unprintablesModeToString(UnprintablesMode mode) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This method can be static.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
src/ui/hexedit.cc
Outdated
|
|
||
| bool is_whitespace = unicode_repr.isSpace() || unicode_repr.isNull(); | ||
|
|
||
| if (is_whitespace || is_undefined_windows1250) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add a check for 0x7f here, it decodes to DEL and it's not printable.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
src/ui/hexedit.cc
Outdated
| } | ||
|
|
||
| // unprintable ASCII chars | ||
| return byte_val >= 0x7f ? windows1250_codec_->toUnicode(&a, 1) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
>= 0x7f -> > 0x7f
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
src/ui/hexeditwidget.cc
Outdated
| QAction* action = new QAction(hex_edit_->unprintablesModeToString(mode), | ||
| &unprintables_menu_); | ||
| connect(action, &QAction::triggered, | ||
| [=]() { this->hex_edit_->setUnprintablesMode(mode); }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please use [this, mode], it's less error-prone and more explicit.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
src/ui/optionsdialog.cc
Outdated
|
|
||
| #include <QMessageBox> | ||
|
|
||
| #include <ui/hexedit.h> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please fix:
- Include grouping
- Use of
<>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
| * | ||
| */ | ||
| #include "util/misc.h" | ||
| #include <cstdint> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fix include grouping.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
mkow
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good now. We can merge after I find a more reasonable icon for the button.
TODO: Find reasonable icon.
This change is