mirror of
https://github.com/Serial-Studio/Serial-Studio.git
synced 2025-01-15 05:22:53 +08:00
Implement #31
This commit is contained in:
parent
093bc10e79
commit
5051795c76
@ -48,6 +48,8 @@ Control {
|
||||
property alias dmDataBits: dataBits.currentIndex
|
||||
property alias dmBaudValue: baudRate.currentIndex
|
||||
property alias dmFlowControl: flowControl.currentIndex
|
||||
property alias dmStartSequence: startSeqText.text
|
||||
property alias dmEndSequence: endSeqText.text
|
||||
property alias appLanguage: languageCombo.currentIndex
|
||||
}
|
||||
|
||||
@ -330,6 +332,38 @@ Control {
|
||||
model: Cpp_Misc_Translator.availableLanguages
|
||||
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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
|
@ -33,6 +33,28 @@ using namespace IO;
|
||||
*/
|
||||
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
|
||||
*/
|
||||
@ -363,7 +385,10 @@ void Manager::setMaxBufferSize(const int maxBufferSize)
|
||||
*/
|
||||
void Manager::setStartSequence(const QString &sequence)
|
||||
{
|
||||
m_startSequence = sequence;
|
||||
m_startSequence = ADD_ESCAPE_SEQUENCES(sequence);
|
||||
if (m_startSequence.isEmpty())
|
||||
m_startSequence = "/*";
|
||||
|
||||
emit startSequenceChanged();
|
||||
}
|
||||
|
||||
@ -373,7 +398,10 @@ void Manager::setStartSequence(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();
|
||||
}
|
||||
|
||||
|
@ -52,6 +52,14 @@ class Manager : public QObject
|
||||
Q_PROPERTY(QString receivedDataLength
|
||||
READ receivedDataLength
|
||||
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
|
||||
|
||||
signals:
|
||||
|
Loading…
x
Reference in New Issue
Block a user