File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -222,14 +222,22 @@ Control {
222222 // Validate hex strings
223223 //
224224 validator: RegExpValidator {
225- regExp: hexCheckbox .checked ? / ^ [a-fA-F0-9 ] + $ / : / [\s\S ] * /
225+ regExp: hexCheckbox .checked ? / ^ (?:( [a-f0-9 ] {2} ) \s * ) + $ / i : / [\s\S ] * /
226226 }
227227
228228 //
229229 // Send data on <enter>
230230 //
231231 Keys .onReturnPressed : root .sendData ()
232232
233+ //
234+ // Add space automatically in hex view
235+ //
236+ onTextChanged: {
237+ if (hexCheckbox .checked )
238+ send .text = Cpp_IO_Console .formatUserHex (send .text )
239+ }
240+
233241 //
234242 // Navigate command history upwards with <up>
235243 //
Original file line number Diff line number Diff line change @@ -197,6 +197,32 @@ QStringList Console::displayModes() const
197197 return list;
198198}
199199
200+ /* *
201+ * Validates the given @a text and adds space to display the text in a byte-oriented view
202+ */
203+ QString Console::formatUserHex (const QString &text)
204+ {
205+ // Remove spaces & stuff
206+ auto data = text.simplified ();
207+ data = data.replace (" " , " " );
208+
209+ // Convert to hex string with spaces between bytes
210+ QString str;
211+ for (int i = 0 ; i < data.length (); ++i)
212+ {
213+ str.append (data.at (i));
214+ if ((i + 1 ) % 2 == 0 && i > 0 )
215+ str.append (" " );
216+ }
217+
218+ // Chop last space
219+ while (str.endsWith (" " ))
220+ str.chop (1 );
221+
222+ // Return string
223+ return str;
224+ }
225+
200226/* *
201227 * Allows the user to export the information displayed on the console
202228 */
Original file line number Diff line number Diff line change @@ -115,6 +115,7 @@ class Console : public QObject
115115 Q_INVOKABLE QStringList dataModes () const ;
116116 Q_INVOKABLE QStringList lineEndings () const ;
117117 Q_INVOKABLE QStringList displayModes () const ;
118+ Q_INVOKABLE QString formatUserHex (const QString &text);
118119
119120public slots:
120121 void save ();
You can’t perform that action at this time.
0 commit comments