mirror of
https://github.com/Serial-Studio/Serial-Studio.git
synced 2025-01-15 05:22:53 +08:00
Load default frame parser script from resources
This commit is contained in:
parent
b44310e049
commit
58d472495a
@ -179,5 +179,6 @@
|
||||
<file>window-border/restore.svg</file>
|
||||
<file>window-border/unmaximize.svg</file>
|
||||
<file>icons/paste.svg</file>
|
||||
<file>scripts/frame-parser.js</file>
|
||||
</qresource>
|
||||
</RCC>
|
||||
|
20
assets/scripts/frame-parser.js
Normal file
20
assets/scripts/frame-parser.js
Normal file
@ -0,0 +1,20 @@
|
||||
/*
|
||||
* @brief Frame parsing function, you can modify this to suit your needs.
|
||||
*
|
||||
* By customizing this code, you can use a single JSON project file to
|
||||
* process different kinds of frames that are sent by the microcontroller
|
||||
* or any data source that is connected to Serial Studio. Frame parsing code
|
||||
* is specific to every JSON project that you create.
|
||||
*
|
||||
* @param frame string with the latest received frame.
|
||||
* @param separator data separator sequence defined by the JSON project.
|
||||
*
|
||||
* @note. only data that is *inside* the data delimiters will
|
||||
* be processed by the frame parser.
|
||||
*
|
||||
* @note you can safely declare global variables outside the
|
||||
* @c parse() function.
|
||||
*/
|
||||
function parse(frame, separator) {
|
||||
return frame.split(separator);
|
||||
}
|
@ -28,24 +28,6 @@
|
||||
#include <Misc/Utilities.h>
|
||||
#include <Misc/ThemeManager.h>
|
||||
|
||||
static const QString DEFAULT_CODE
|
||||
= "/* \n"
|
||||
" * Frame parsing function, you can modify this to suit your\n"
|
||||
" * needs. By customizing this code, you can use a single JSON\n"
|
||||
" * project file to process different kinds of frames that are\n"
|
||||
" * sent by the microcontroller or device that is connected to\n"
|
||||
" * Serial Studio.\n"
|
||||
" *\n"
|
||||
" * @note only data that is *inside* the data delimiters will\n"
|
||||
" * be processed by this function!\n"
|
||||
" *\n"
|
||||
" * @param frame string with the latest received frame.\n"
|
||||
" * @param separator data sepatator sequence set by the JSON project.\n"
|
||||
" */\n"
|
||||
"function parse(frame, separator) {\n"
|
||||
" return frame.split(separator);\n"
|
||||
"}";
|
||||
|
||||
Project::CodeEditor::CodeEditor()
|
||||
{
|
||||
// Setup syntax highlighter
|
||||
@ -94,7 +76,7 @@ Project::CodeEditor::CodeEditor()
|
||||
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
|
||||
palette.setColor(QPalette::PlaceholderText, theme->consolePlaceholderText());
|
||||
#endif
|
||||
m_textEdit.setPalette(palette);
|
||||
setPalette(palette);
|
||||
|
||||
// Setup layout
|
||||
auto layout = new QVBoxLayout(this);
|
||||
@ -121,7 +103,15 @@ Project::CodeEditor &Project::CodeEditor::instance()
|
||||
|
||||
QString Project::CodeEditor::defaultCode() const
|
||||
{
|
||||
return DEFAULT_CODE;
|
||||
QString code;
|
||||
QFile file(":/scripts/frame-parser.js");
|
||||
if (file.open(QFile::ReadOnly))
|
||||
{
|
||||
code = QString::fromUtf8(file.readAll());
|
||||
file.close();
|
||||
}
|
||||
|
||||
return code;
|
||||
}
|
||||
|
||||
void Project::CodeEditor::displayWindow()
|
||||
@ -143,7 +133,7 @@ void Project::CodeEditor::onNewClicked()
|
||||
}
|
||||
|
||||
// Load default template
|
||||
m_textEdit.setPlainText(DEFAULT_CODE);
|
||||
m_textEdit.setPlainText(defaultCode());
|
||||
save(true);
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user