This commit is contained in:
Alex Spataru 2021-02-10 21:03:32 -05:00
parent 093bc10e79
commit 5051795c76
3 changed files with 72 additions and 2 deletions

View File

@ -48,6 +48,8 @@ Control {
property alias dmDataBits: dataBits.currentIndex property alias dmDataBits: dataBits.currentIndex
property alias dmBaudValue: baudRate.currentIndex property alias dmBaudValue: baudRate.currentIndex
property alias dmFlowControl: flowControl.currentIndex property alias dmFlowControl: flowControl.currentIndex
property alias dmStartSequence: startSeqText.text
property alias dmEndSequence: endSeqText.text
property alias appLanguage: languageCombo.currentIndex property alias appLanguage: languageCombo.currentIndex
} }
@ -330,6 +332,38 @@ Control {
model: Cpp_Misc_Translator.availableLanguages model: Cpp_Misc_Translator.availableLanguages
onCurrentIndexChanged: Cpp_Misc_Translator.setLanguage(currentIndex) onCurrentIndexChanged: Cpp_Misc_Translator.setLanguage(currentIndex)
} }
//
// Start sequence
//
Label {
text: qsTr("Start sequence") + ": "
} TextField {
id: startSeqText
Layout.fillWidth: true
placeholderText: "/*"
text: "/*"
onTextChanged: {
if (text !== Cpp_IO_Manager.startSequence)
Cpp_IO_Manager.startSequence = text
}
}
//
// End sequence
//
Label {
text: qsTr("End sequence") + ": "
} TextField {
id: endSeqText
Layout.fillWidth: true
placeholderText: "*/"
text: "*/"
onTextChanged: {
if (text !== Cpp_IO_Manager.finishSequence)
Cpp_IO_Manager.finishSequence = text
}
}
} }
// //

View File

@ -33,6 +33,28 @@ using namespace IO;
*/ */
static Manager *INSTANCE = nullptr; static Manager *INSTANCE = nullptr;
/**
* Adds support for C escape sequences to the given @a str.
* When user inputs "\n" in a textbox, Qt automatically converts that string to "\\n".
* For our purposes, we need to convert "\\n" back to "\n", and so on with the rest of
* the escape sequences supported by C.
*
* TODO: add support for numbers
*/
static QString ADD_ESCAPE_SEQUENCES(const QString &str)
{
auto escapedStr = str;
escapedStr = escapedStr.replace("\\a", "\a");
escapedStr = escapedStr.replace("\\b", "\b");
escapedStr = escapedStr.replace("\\e", "\e");
escapedStr = escapedStr.replace("\\f", "\f");
escapedStr = escapedStr.replace("\\n", "\n");
escapedStr = escapedStr.replace("\\r", "\r");
escapedStr = escapedStr.replace("\\t", "\t");
escapedStr = escapedStr.replace("\\v", "\v");
return escapedStr;
}
/** /**
* Constructor function * Constructor function
*/ */
@ -363,7 +385,10 @@ void Manager::setMaxBufferSize(const int maxBufferSize)
*/ */
void Manager::setStartSequence(const QString &sequence) void Manager::setStartSequence(const QString &sequence)
{ {
m_startSequence = sequence; m_startSequence = ADD_ESCAPE_SEQUENCES(sequence);
if (m_startSequence.isEmpty())
m_startSequence = "/*";
emit startSequenceChanged(); emit startSequenceChanged();
} }
@ -373,7 +398,10 @@ void Manager::setStartSequence(const QString &sequence)
*/ */
void Manager::setFinishSequence(const QString &sequence) void Manager::setFinishSequence(const QString &sequence)
{ {
m_finishSequence = sequence; m_finishSequence = ADD_ESCAPE_SEQUENCES(sequence);
if (m_finishSequence.isEmpty())
m_finishSequence = "/*";
emit finishSequenceChanged(); emit finishSequenceChanged();
} }

View File

@ -52,6 +52,14 @@ class Manager : public QObject
Q_PROPERTY(QString receivedDataLength Q_PROPERTY(QString receivedDataLength
READ receivedDataLength READ receivedDataLength
NOTIFY receivedBytesChanged) NOTIFY receivedBytesChanged)
Q_PROPERTY(QString startSequence
READ startSequence
WRITE setStartSequence
NOTIFY startSequenceChanged)
Q_PROPERTY(QString finishSequence
READ finishSequence
WRITE setFinishSequence
NOTIFY finishSequenceChanged)
// clang-format on // clang-format on
signals: signals: