mirror of
https://github.com/Serial-Studio/Serial-Studio.git
synced 2025-01-31 17:42:55 +08:00
Use thread-safe singleton pattern
This commit is contained in:
parent
c84750b280
commit
24792e9686
@ -34,19 +34,15 @@
|
||||
#include <QApplication>
|
||||
#include <QDesktopServices>
|
||||
|
||||
namespace CSV
|
||||
{
|
||||
static Export *EXPORT = Q_NULLPTR;
|
||||
|
||||
/**
|
||||
* Connect JSON Parser & Serial Manager signals to begin registering JSON
|
||||
* dataframes into JSON list.
|
||||
*/
|
||||
Export::Export()
|
||||
CSV::Export::Export()
|
||||
: m_exportEnabled(true)
|
||||
{
|
||||
const auto io = IO::Manager::getInstance();
|
||||
const auto te = Misc::TimerEvents::getInstance();
|
||||
const auto io = &IO::Manager::instance();
|
||||
const auto te = &Misc::TimerEvents::instance();
|
||||
connect(io, &IO::Manager::connectedChanged, this, &Export::closeFile);
|
||||
connect(io, &IO::Manager::frameReceived, this, &Export::registerFrame);
|
||||
connect(te, &Misc::TimerEvents::lowFreqTimeout, this, &Export::writeValues);
|
||||
@ -55,7 +51,7 @@ Export::Export()
|
||||
/**
|
||||
* Close file & finnish write-operations before destroying the class
|
||||
*/
|
||||
Export::~Export()
|
||||
CSV::Export::~Export()
|
||||
{
|
||||
closeFile();
|
||||
}
|
||||
@ -63,18 +59,16 @@ Export::~Export()
|
||||
/**
|
||||
* Returns a pointer to the only instance of this class
|
||||
*/
|
||||
Export *Export::getInstance()
|
||||
CSV::Export &CSV::Export::instance()
|
||||
{
|
||||
if (!EXPORT)
|
||||
EXPORT = new Export;
|
||||
|
||||
return EXPORT;
|
||||
static auto singleton = new Export();
|
||||
return *singleton;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns @c true if the CSV output file is open
|
||||
*/
|
||||
bool Export::isOpen() const
|
||||
bool CSV::Export::isOpen() const
|
||||
{
|
||||
return m_csvFile.isOpen();
|
||||
}
|
||||
@ -82,7 +76,7 @@ bool Export::isOpen() const
|
||||
/**
|
||||
* Returns @c true if CSV export is enabled
|
||||
*/
|
||||
bool Export::exportEnabled() const
|
||||
bool CSV::Export::exportEnabled() const
|
||||
{
|
||||
return m_exportEnabled;
|
||||
}
|
||||
@ -90,7 +84,7 @@ bool Export::exportEnabled() const
|
||||
/**
|
||||
* Open the current CSV file in the Explorer/Finder window
|
||||
*/
|
||||
void Export::openCurrentCsv()
|
||||
void CSV::Export::openCurrentCsv()
|
||||
{
|
||||
if (isOpen())
|
||||
Misc::Utilities::revealFile(m_csvFile.fileName());
|
||||
@ -102,7 +96,7 @@ void Export::openCurrentCsv()
|
||||
/**
|
||||
* Enables or disables data export
|
||||
*/
|
||||
void Export::setExportEnabled(const bool enabled)
|
||||
void CSV::Export::setExportEnabled(const bool enabled)
|
||||
{
|
||||
m_exportEnabled = enabled;
|
||||
Q_EMIT enabledChanged();
|
||||
@ -117,7 +111,7 @@ void Export::setExportEnabled(const bool enabled)
|
||||
/**
|
||||
* Write all remaining JSON frames & close the CSV file
|
||||
*/
|
||||
void Export::closeFile()
|
||||
void CSV::Export::closeFile()
|
||||
{
|
||||
if (isOpen())
|
||||
{
|
||||
@ -135,10 +129,10 @@ void Export::closeFile()
|
||||
* Creates a CSV file based on the JSON frames contained in the JSON list.
|
||||
* @note This function is called periodically every 1 second.
|
||||
*/
|
||||
void Export::writeValues()
|
||||
void CSV::Export::writeValues()
|
||||
{
|
||||
// Get separator sequence
|
||||
const auto sep = IO::Manager::getInstance()->separatorSequence();
|
||||
const auto sep = IO::Manager::instance().separatorSequence();
|
||||
|
||||
// Write each frame
|
||||
for (int i = 0; i < m_frames.count(); ++i)
|
||||
@ -171,10 +165,10 @@ void Export::writeValues()
|
||||
/**
|
||||
* Creates a new CSV file corresponding to the current project title & field count
|
||||
*/
|
||||
void Export::createCsvFile(const CSV::RawFrame &frame)
|
||||
void CSV::Export::createCsvFile(const CSV::RawFrame &frame)
|
||||
{
|
||||
// Get project title
|
||||
const auto projectTitle = UI::Dashboard::getInstance()->title();
|
||||
const auto projectTitle = UI::Dashboard::instance().title();
|
||||
|
||||
// Get file name
|
||||
const QString fileName = frame.rxDateTime.toString("HH-mm-ss") + ".csv";
|
||||
@ -212,7 +206,7 @@ void Export::createCsvFile(const CSV::RawFrame &frame)
|
||||
#endif
|
||||
|
||||
// Get number of fields
|
||||
const auto sep = IO::Manager::getInstance()->separatorSequence();
|
||||
const auto sep = IO::Manager::instance().separatorSequence();
|
||||
const auto fields = QString::fromUtf8(frame.data).split(sep);
|
||||
|
||||
// Add table titles
|
||||
@ -234,11 +228,11 @@ void Export::createCsvFile(const CSV::RawFrame &frame)
|
||||
/**
|
||||
* Appends the latest data from the device to the output buffer
|
||||
*/
|
||||
void Export::registerFrame(const QByteArray &data)
|
||||
void CSV::Export::registerFrame(const QByteArray &data)
|
||||
{
|
||||
// Ignore if device is not connected (we don't want to generate a CSV file when we
|
||||
// are reading another CSV file don't we?)
|
||||
if (!IO::Manager::getInstance()->connected())
|
||||
if (!IO::Manager::instance().connected())
|
||||
return;
|
||||
|
||||
// Ignore if CSV export is disabled
|
||||
@ -251,4 +245,3 @@ void Export::registerFrame(const QByteArray &data)
|
||||
frame.rxDateTime = QDateTime::currentDateTime();
|
||||
m_frames.append(frame);
|
||||
}
|
||||
}
|
||||
|
@ -64,16 +64,21 @@ Q_SIGNALS:
|
||||
void openChanged();
|
||||
void enabledChanged();
|
||||
|
||||
private:
|
||||
explicit Export();
|
||||
Export(Export &&) = delete;
|
||||
Export(const Export &) = delete;
|
||||
Export &operator=(Export &&) = delete;
|
||||
Export &operator=(const Export &) = delete;
|
||||
|
||||
~Export();
|
||||
|
||||
public:
|
||||
static Export *getInstance();
|
||||
static Export &instance();
|
||||
|
||||
bool isOpen() const;
|
||||
bool exportEnabled() const;
|
||||
|
||||
private:
|
||||
Export();
|
||||
~Export();
|
||||
|
||||
public Q_SLOTS:
|
||||
void closeFile();
|
||||
void openCurrentCsv();
|
||||
|
@ -32,14 +32,10 @@
|
||||
#include <IO/Manager.h>
|
||||
#include <Misc/Utilities.h>
|
||||
|
||||
namespace CSV
|
||||
{
|
||||
static Player *PLAYER = Q_NULLPTR;
|
||||
|
||||
/**
|
||||
* Constructor function
|
||||
*/
|
||||
Player::Player()
|
||||
CSV::Player::Player()
|
||||
: m_framePos(0)
|
||||
, m_playing(false)
|
||||
, m_timestamp("")
|
||||
@ -50,18 +46,16 @@ Player::Player()
|
||||
/**
|
||||
* Returns the only instance of the class
|
||||
*/
|
||||
Player *Player::getInstance()
|
||||
CSV::Player &CSV::Player::instance()
|
||||
{
|
||||
if (!PLAYER)
|
||||
PLAYER = new Player;
|
||||
|
||||
return PLAYER;
|
||||
static auto singleton = new Player();
|
||||
return *singleton;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns @c true if an CSV file is open for reading
|
||||
*/
|
||||
bool Player::isOpen() const
|
||||
bool CSV::Player::isOpen() const
|
||||
{
|
||||
return m_csvFile.isOpen();
|
||||
}
|
||||
@ -69,7 +63,7 @@ bool Player::isOpen() const
|
||||
/**
|
||||
* Returns the CSV playback progress in a range from 0.0 to 1.0
|
||||
*/
|
||||
qreal Player::progress() const
|
||||
qreal CSV::Player::progress() const
|
||||
{
|
||||
return ((qreal)framePosition()) / frameCount();
|
||||
}
|
||||
@ -78,7 +72,7 @@ qreal Player::progress() const
|
||||
* Returns @c true if the user is currently re-playing the CSV file at real-time
|
||||
* speed.
|
||||
*/
|
||||
bool Player::isPlaying() const
|
||||
bool CSV::Player::isPlaying() const
|
||||
{
|
||||
return m_playing;
|
||||
}
|
||||
@ -86,7 +80,7 @@ bool Player::isPlaying() const
|
||||
/**
|
||||
* Returns the short filename of the current CSV file
|
||||
*/
|
||||
QString Player::filename() const
|
||||
QString CSV::Player::filename() const
|
||||
{
|
||||
if (isOpen())
|
||||
{
|
||||
@ -102,7 +96,7 @@ QString Player::filename() const
|
||||
* by getting the number of rows of the CSV and substracting 1 (because the
|
||||
* title cells do not count as a valid frame).
|
||||
*/
|
||||
int Player::frameCount() const
|
||||
int CSV::Player::frameCount() const
|
||||
{
|
||||
return m_csvData.count() - 1;
|
||||
}
|
||||
@ -111,7 +105,7 @@ int Player::frameCount() const
|
||||
* Returns the current row that we are using to create the JSON data that is
|
||||
* feed to the JsonParser class.
|
||||
*/
|
||||
int Player::framePosition() const
|
||||
int CSV::Player::framePosition() const
|
||||
{
|
||||
return m_framePos;
|
||||
}
|
||||
@ -119,7 +113,7 @@ int Player::framePosition() const
|
||||
/**
|
||||
* Returns the timestamp of the current data frame / row.
|
||||
*/
|
||||
QString Player::timestamp() const
|
||||
QString CSV::Player::timestamp() const
|
||||
{
|
||||
return m_timestamp;
|
||||
}
|
||||
@ -127,7 +121,7 @@ QString Player::timestamp() const
|
||||
/**
|
||||
* Returns the default path for CSV files
|
||||
*/
|
||||
QString Player::csvFilesPath() const
|
||||
QString CSV::Player::csvFilesPath() const
|
||||
{
|
||||
// Get file name and path
|
||||
// clang-format off
|
||||
@ -147,7 +141,7 @@ QString Player::csvFilesPath() const
|
||||
* Enables CSV playback at 'live' speed (as it happened when CSV file was
|
||||
* saved to the computer).
|
||||
*/
|
||||
void Player::play()
|
||||
void CSV::Player::play()
|
||||
{
|
||||
m_playing = true;
|
||||
Q_EMIT playerStateChanged();
|
||||
@ -157,7 +151,7 @@ void Player::play()
|
||||
* Pauses the CSV playback so that the user can see WTF happened at
|
||||
* certain point of the mission.
|
||||
*/
|
||||
void Player::pause()
|
||||
void CSV::Player::pause()
|
||||
{
|
||||
m_playing = false;
|
||||
Q_EMIT playerStateChanged();
|
||||
@ -166,7 +160,7 @@ void Player::pause()
|
||||
/**
|
||||
* Toggles play/pause state
|
||||
*/
|
||||
void Player::toggle()
|
||||
void CSV::Player::toggle()
|
||||
{
|
||||
m_playing = !m_playing;
|
||||
Q_EMIT playerStateChanged();
|
||||
@ -175,7 +169,7 @@ void Player::toggle()
|
||||
/**
|
||||
* Lets the user select a CSV file
|
||||
*/
|
||||
void Player::openFile()
|
||||
void CSV::Player::openFile()
|
||||
{
|
||||
// clang-format off
|
||||
|
||||
@ -197,7 +191,7 @@ void Player::openFile()
|
||||
* Closes the file & cleans up internal variables. This helps us to reduice
|
||||
* memory usage & prepare the module to load another CSV file.
|
||||
*/
|
||||
void Player::closeFile()
|
||||
void CSV::Player::closeFile()
|
||||
{
|
||||
m_framePos = 0;
|
||||
m_csvFile.close();
|
||||
@ -213,7 +207,7 @@ void Player::closeFile()
|
||||
/**
|
||||
* Reads & processes the next CSV row (until we get to the last row)
|
||||
*/
|
||||
void Player::nextFrame()
|
||||
void CSV::Player::nextFrame()
|
||||
{
|
||||
if (framePosition() < frameCount())
|
||||
{
|
||||
@ -225,7 +219,7 @@ void Player::nextFrame()
|
||||
/**
|
||||
* Reads & processes the previous CSV row (until we get to the first row)
|
||||
*/
|
||||
void Player::previousFrame()
|
||||
void CSV::Player::previousFrame()
|
||||
{
|
||||
if (framePosition() > 0)
|
||||
{
|
||||
@ -239,7 +233,7 @@ void Player::previousFrame()
|
||||
* row. If one of the data rows does not correspond to the title row, the CSV
|
||||
* is considered to be invalid.
|
||||
*/
|
||||
void Player::openFile(const QString &filePath)
|
||||
void CSV::Player::openFile(const QString &filePath)
|
||||
{
|
||||
// File name empty, abort
|
||||
if (filePath.isEmpty())
|
||||
@ -249,8 +243,7 @@ void Player::openFile(const QString &filePath)
|
||||
closeFile();
|
||||
|
||||
// Device is connected, warn user & disconnect
|
||||
const auto sm = IO::Manager::getInstance();
|
||||
if (sm->connected())
|
||||
if (IO::Manager::instance().connected())
|
||||
{
|
||||
auto response = Misc::Utilities::showMessageBox(
|
||||
tr("Serial port open, do you want to continue?"),
|
||||
@ -258,7 +251,7 @@ void Player::openFile(const QString &filePath)
|
||||
"to disconnect from the serial port"),
|
||||
qAppName(), QMessageBox::No | QMessageBox::Yes);
|
||||
if (response == QMessageBox::Yes)
|
||||
sm->disconnectDevice();
|
||||
IO::Manager::instance().disconnectDevice();
|
||||
else
|
||||
return;
|
||||
}
|
||||
@ -328,7 +321,7 @@ void Player::openFile(const QString &filePath)
|
||||
* Reads a specific row from the @a progress range (which can have a value
|
||||
* ranging from 0.0 to 1.0).
|
||||
*/
|
||||
void Player::setProgress(const qreal &progress)
|
||||
void CSV::Player::setProgress(const qreal &progress)
|
||||
{
|
||||
// Ensure that progress value is between 0 and 1
|
||||
auto validProgress = progress;
|
||||
@ -360,7 +353,7 @@ void Player::setProgress(const qreal &progress)
|
||||
* milliseconds between the current row and the next row & schedules a re-call
|
||||
* of this function using a timer.
|
||||
*/
|
||||
void Player::updateData()
|
||||
void CSV::Player::updateData()
|
||||
{
|
||||
// File not open, abort
|
||||
if (!isOpen())
|
||||
@ -376,7 +369,7 @@ void Player::updateData()
|
||||
}
|
||||
|
||||
// Construct frame from CSV and send it to the IO manager
|
||||
IO::Manager::getInstance()->processPayload(getFrame(framePosition() + 1));
|
||||
IO::Manager::instance().processPayload(getFrame(framePosition() + 1));
|
||||
|
||||
// If the user wants to 'play' the CSV, get time difference between this
|
||||
// frame and the next frame & schedule an automated update
|
||||
@ -425,7 +418,7 @@ void Player::updateData()
|
||||
* validation by checking that the timestamp cell has the correct title as the
|
||||
* one used in the @c Export class.
|
||||
*/
|
||||
bool Player::validateRow(const int position)
|
||||
bool CSV::Player::validateRow(const int position)
|
||||
{
|
||||
// Ensure that position is valid
|
||||
if (m_csvData.count() <= position)
|
||||
@ -462,10 +455,10 @@ bool Player::validateRow(const int position)
|
||||
* ignored because it contains the RX date/time, which is used to regulate the interval
|
||||
* at which the frames are parsed.
|
||||
*/
|
||||
QByteArray Player::getFrame(const int row)
|
||||
QByteArray CSV::Player::getFrame(const int row)
|
||||
{
|
||||
QByteArray frame;
|
||||
const auto sep = IO::Manager::getInstance()->separatorSequence();
|
||||
const auto sep = IO::Manager::instance().separatorSequence();
|
||||
|
||||
if (m_csvData.count() > row)
|
||||
{
|
||||
@ -488,7 +481,7 @@ QByteArray Player::getFrame(const int row)
|
||||
* error occurs or the cell does not exist, the value of @a error shall be set
|
||||
* to @c true.
|
||||
*/
|
||||
QString Player::getCellValue(const int row, const int column, bool &error)
|
||||
QString CSV::Player::getCellValue(const int row, const int column, bool &error)
|
||||
{
|
||||
if (m_csvData.count() > row)
|
||||
{
|
||||
@ -503,4 +496,3 @@ QString Player::getCellValue(const int row, const int column, bool &error)
|
||||
error = true;
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
@ -58,8 +58,15 @@ Q_SIGNALS:
|
||||
void timestampChanged();
|
||||
void playerStateChanged();
|
||||
|
||||
private:
|
||||
explicit Player();
|
||||
Player(Player &&) = delete;
|
||||
Player(const Player &) = delete;
|
||||
Player &operator=(Player &&) = delete;
|
||||
Player &operator=(const Player &) = delete;
|
||||
|
||||
public:
|
||||
static Player *getInstance();
|
||||
static Player &instance();
|
||||
|
||||
bool isOpen() const;
|
||||
qreal progress() const;
|
||||
@ -70,9 +77,6 @@ public:
|
||||
QString timestamp() const;
|
||||
QString csvFilesPath() const;
|
||||
|
||||
private:
|
||||
Player();
|
||||
|
||||
public Q_SLOTS:
|
||||
void play();
|
||||
void pause();
|
||||
|
@ -33,10 +33,6 @@
|
||||
#include <Misc/Utilities.h>
|
||||
#include <Misc/TimerEvents.h>
|
||||
|
||||
namespace IO
|
||||
{
|
||||
static Console *CONSOLE = Q_NULLPTR;
|
||||
|
||||
/**
|
||||
* Generates a hexdump of the given data
|
||||
*/
|
||||
@ -82,7 +78,7 @@ static QString HexDump(const char *data, const size_t size)
|
||||
/**
|
||||
* Constructor function
|
||||
*/
|
||||
Console::Console()
|
||||
IO::Console::Console()
|
||||
: m_dataMode(DataMode::DataUTF8)
|
||||
, m_lineEnding(LineEnding::NoLineEnding)
|
||||
, m_displayMode(DisplayMode::DisplayPlainText)
|
||||
@ -96,10 +92,10 @@ Console::Console()
|
||||
clear();
|
||||
|
||||
// Read received data automatically
|
||||
const auto dm = Manager::getInstance();
|
||||
const auto te = Misc::TimerEvents::getInstance();
|
||||
connect(dm, &Manager::dataSent, this, &Console::onDataSent);
|
||||
connect(dm, &Manager::dataReceived, this, &Console::onDataReceived);
|
||||
const auto dm = &Manager::instance();
|
||||
const auto te = &Misc::TimerEvents::instance();
|
||||
connect(dm, &Manager::dataSent, this, &IO::Console::onDataSent);
|
||||
connect(dm, &Manager::dataReceived, this, &IO::Console::onDataReceived);
|
||||
connect(te, SIGNAL(highFreqTimeout()), this, SLOT(displayData()),
|
||||
Qt::QueuedConnection);
|
||||
}
|
||||
@ -107,19 +103,17 @@ Console::Console()
|
||||
/**
|
||||
* Returns the only instance of the class
|
||||
*/
|
||||
Console *Console::getInstance()
|
||||
IO::Console &IO::Console::instance()
|
||||
{
|
||||
if (!CONSOLE)
|
||||
CONSOLE = new Console;
|
||||
|
||||
return CONSOLE;
|
||||
static auto singleton = new Console();
|
||||
return *singleton;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns @c true if the console shall display the commands that the user has sent
|
||||
* to the serial/network device.
|
||||
*/
|
||||
bool Console::echo() const
|
||||
bool IO::Console::echo() const
|
||||
{
|
||||
return m_echo;
|
||||
}
|
||||
@ -128,7 +122,7 @@ bool Console::echo() const
|
||||
* Returns @c true if the vertical position of the console display shall be automatically
|
||||
* moved to show latest data.
|
||||
*/
|
||||
bool Console::autoscroll() const
|
||||
bool IO::Console::autoscroll() const
|
||||
{
|
||||
return m_autoscroll;
|
||||
}
|
||||
@ -136,7 +130,7 @@ bool Console::autoscroll() const
|
||||
/**
|
||||
* Returns @c true if data buffer contains information that the user can export.
|
||||
*/
|
||||
bool Console::saveAvailable() const
|
||||
bool IO::Console::saveAvailable() const
|
||||
{
|
||||
return m_textBuffer.length() > 0;
|
||||
}
|
||||
@ -144,7 +138,7 @@ bool Console::saveAvailable() const
|
||||
/**
|
||||
* Returns @c true if a timestamp should be shown before each displayed data block.
|
||||
*/
|
||||
bool Console::showTimestamp() const
|
||||
bool IO::Console::showTimestamp() const
|
||||
{
|
||||
return m_showTimestamp;
|
||||
}
|
||||
@ -158,7 +152,7 @@ bool Console::showTimestamp() const
|
||||
* and send the appropiate binary data to the target
|
||||
* device.
|
||||
*/
|
||||
Console::DataMode Console::dataMode() const
|
||||
IO::Console::DataMode IO::Console::dataMode() const
|
||||
{
|
||||
return m_dataMode;
|
||||
}
|
||||
@ -171,7 +165,7 @@ Console::DataMode Console::dataMode() const
|
||||
* - @c LineEnding::CarriageReturn, add '\r' to the data sent by the user
|
||||
* - @c LineEnding::BothNewLineAndCarriageReturn add '\r\n' to the data sent by the user
|
||||
*/
|
||||
Console::LineEnding Console::lineEnding() const
|
||||
IO::Console::LineEnding IO::Console::lineEnding() const
|
||||
{
|
||||
return m_lineEnding;
|
||||
}
|
||||
@ -181,7 +175,7 @@ Console::LineEnding Console::lineEnding() const
|
||||
* - @c DisplayMode::DisplayPlainText display incoming data as an UTF-8 stream
|
||||
* - @c DisplayMode::DisplayHexadecimal display incoming data in hexadecimal format
|
||||
*/
|
||||
Console::DisplayMode Console::displayMode() const
|
||||
IO::Console::DisplayMode IO::Console::displayMode() const
|
||||
{
|
||||
return m_displayMode;
|
||||
}
|
||||
@ -193,7 +187,7 @@ Console::DisplayMode Console::displayMode() const
|
||||
* keyboard. This behaviour is managed by the @c historyUp() & @c historyDown()
|
||||
* functions.
|
||||
*/
|
||||
QString Console::currentHistoryString() const
|
||||
QString IO::Console::currentHistoryString() const
|
||||
{
|
||||
if (m_historyItem < m_historyItems.count() && m_historyItem >= 0)
|
||||
return m_historyItems.at(m_historyItem);
|
||||
@ -205,7 +199,7 @@ QString Console::currentHistoryString() const
|
||||
* Returns a list with the available data (sending) modes. This list must be synchronized
|
||||
* with the order of the @c DataMode enums.
|
||||
*/
|
||||
StringList Console::dataModes() const
|
||||
StringList IO::Console::dataModes() const
|
||||
{
|
||||
StringList list;
|
||||
list.append(tr("ASCII"));
|
||||
@ -217,7 +211,7 @@ StringList Console::dataModes() const
|
||||
* Returns a list with the available line endings options. This list must be synchronized
|
||||
* with the order of the @c LineEnding enums.
|
||||
*/
|
||||
StringList Console::lineEndings() const
|
||||
StringList IO::Console::lineEndings() const
|
||||
{
|
||||
StringList list;
|
||||
list.append(tr("No line ending"));
|
||||
@ -231,7 +225,7 @@ StringList Console::lineEndings() const
|
||||
* Returns a list with the available console display modes. This list must be synchronized
|
||||
* with the order of the @c DisplayMode enums.
|
||||
*/
|
||||
StringList Console::displayModes() const
|
||||
StringList IO::Console::displayModes() const
|
||||
{
|
||||
StringList list;
|
||||
list.append(tr("Plain text"));
|
||||
@ -242,7 +236,7 @@ StringList Console::displayModes() const
|
||||
/**
|
||||
* Validates the given @a text and adds space to display the text in a byte-oriented view
|
||||
*/
|
||||
QString Console::formatUserHex(const QString &text)
|
||||
QString IO::Console::formatUserHex(const QString &text)
|
||||
{
|
||||
// Remove spaces & stuff
|
||||
auto data = text.simplified();
|
||||
@ -268,7 +262,7 @@ QString Console::formatUserHex(const QString &text)
|
||||
/**
|
||||
* Allows the user to export the information displayed on the console
|
||||
*/
|
||||
void Console::save()
|
||||
void IO::Console::save()
|
||||
{
|
||||
// No data buffer received, abort
|
||||
if (!saveAvailable())
|
||||
@ -298,7 +292,7 @@ void Console::save()
|
||||
/**
|
||||
* Deletes all the text displayed by the current QML text document
|
||||
*/
|
||||
void Console::clear()
|
||||
void IO::Console::clear()
|
||||
{
|
||||
m_dataBuffer.clear();
|
||||
m_textBuffer.clear();
|
||||
@ -315,7 +309,7 @@ void Console::clear()
|
||||
* The user can navigate the list using the up/down keys. This function allows the user
|
||||
* to navigate the list from most recent command to oldest command.
|
||||
*/
|
||||
void Console::historyUp()
|
||||
void IO::Console::historyUp()
|
||||
{
|
||||
if (m_historyItem > 0)
|
||||
{
|
||||
@ -331,7 +325,7 @@ void Console::historyUp()
|
||||
* The user can navigate the list using the up/down keys. This function allows the user
|
||||
* to navigate the list from oldst command to most recent command.
|
||||
*/
|
||||
void Console::historyDown()
|
||||
void IO::Console::historyDown()
|
||||
{
|
||||
if (m_historyItem < m_historyItems.count() - 1)
|
||||
{
|
||||
@ -347,10 +341,10 @@ void Console::historyDown()
|
||||
* @note @c data is added to the history of sent commands, regardless if the data writing
|
||||
* was successfull or not.
|
||||
*/
|
||||
void Console::send(const QString &data)
|
||||
void IO::Console::send(const QString &data)
|
||||
{
|
||||
// Check conditions
|
||||
if (data.isEmpty() || !Manager::getInstance()->connected())
|
||||
if (data.isEmpty() || !Manager::instance().connected())
|
||||
return;
|
||||
|
||||
// Add user command to history
|
||||
@ -381,14 +375,14 @@ void Console::send(const QString &data)
|
||||
}
|
||||
|
||||
// Write data to device
|
||||
Manager::getInstance()->writeData(bin);
|
||||
Manager::instance().writeData(bin);
|
||||
}
|
||||
|
||||
/**
|
||||
* Enables or disables displaying sent data in the console screen. See @c echo() for more
|
||||
* information.
|
||||
*/
|
||||
void Console::setEcho(const bool enabled)
|
||||
void IO::Console::setEcho(const bool enabled)
|
||||
{
|
||||
m_echo = enabled;
|
||||
Q_EMIT echoChanged();
|
||||
@ -400,7 +394,7 @@ void Console::setEcho(const bool enabled)
|
||||
*
|
||||
* @param fontFamily the font family to use to render the text document
|
||||
*/
|
||||
void Console::print(const QString &fontFamily)
|
||||
void IO::Console::print(const QString &fontFamily)
|
||||
{
|
||||
// Get document font (specified by QML ui)
|
||||
QFont font;
|
||||
@ -429,7 +423,7 @@ void Console::print(const QString &fontFamily)
|
||||
/**
|
||||
* Enables/disables displaying a timestamp of each received data block.
|
||||
*/
|
||||
void Console::setShowTimestamp(const bool enabled)
|
||||
void IO::Console::setShowTimestamp(const bool enabled)
|
||||
{
|
||||
if (showTimestamp() != enabled)
|
||||
{
|
||||
@ -441,7 +435,7 @@ void Console::setShowTimestamp(const bool enabled)
|
||||
/**
|
||||
* Enables/disables autoscrolling of the console text.
|
||||
*/
|
||||
void Console::setAutoscroll(const bool enabled)
|
||||
void IO::Console::setAutoscroll(const bool enabled)
|
||||
{
|
||||
if (autoscroll() != enabled)
|
||||
{
|
||||
@ -453,7 +447,7 @@ void Console::setAutoscroll(const bool enabled)
|
||||
/**
|
||||
* Changes the data mode for user commands. See @c dataMode() for more information.
|
||||
*/
|
||||
void Console::setDataMode(const IO::Console::DataMode &mode)
|
||||
void IO::Console::setDataMode(const IO::Console::DataMode &mode)
|
||||
{
|
||||
m_dataMode = mode;
|
||||
Q_EMIT dataModeChanged();
|
||||
@ -463,7 +457,7 @@ void Console::setDataMode(const IO::Console::DataMode &mode)
|
||||
* Changes line ending mode for sent user commands. See @c lineEnding() for more
|
||||
* information.
|
||||
*/
|
||||
void Console::setLineEnding(const IO::Console::LineEnding &mode)
|
||||
void IO::Console::setLineEnding(const IO::Console::LineEnding &mode)
|
||||
{
|
||||
m_lineEnding = mode;
|
||||
Q_EMIT lineEndingChanged();
|
||||
@ -472,7 +466,7 @@ void Console::setLineEnding(const IO::Console::LineEnding &mode)
|
||||
/**
|
||||
* Changes the display mode of the console. See @c displayMode() for more information.
|
||||
*/
|
||||
void Console::setDisplayMode(const IO::Console::DisplayMode &mode)
|
||||
void IO::Console::setDisplayMode(const IO::Console::DisplayMode &mode)
|
||||
{
|
||||
m_displayMode = mode;
|
||||
Q_EMIT displayModeChanged();
|
||||
@ -482,7 +476,7 @@ void Console::setDisplayMode(const IO::Console::DisplayMode &mode)
|
||||
* Inserts the given @a string into the list of lines of the console, if @a addTimestamp
|
||||
* is set to @c true, an timestamp is added for each line.
|
||||
*/
|
||||
void Console::append(const QString &string, const bool addTimestamp)
|
||||
void IO::Console::append(const QString &string, const bool addTimestamp)
|
||||
{
|
||||
// Abort on empty strings
|
||||
if (string.isEmpty())
|
||||
@ -550,7 +544,7 @@ void Console::append(const QString &string, const bool addTimestamp)
|
||||
* done by the @c dataToString() function, which displays incoming data either in UTF-8
|
||||
* or in hexadecimal mode.
|
||||
*/
|
||||
void Console::displayData()
|
||||
void IO::Console::displayData()
|
||||
{
|
||||
append(dataToString(m_dataBuffer), showTimestamp());
|
||||
m_dataBuffer.clear();
|
||||
@ -561,7 +555,7 @@ void Console::displayData()
|
||||
* done by the @c dataToString() function, which displays incoming data either in UTF-8
|
||||
* or in hexadecimal mode.
|
||||
*/
|
||||
void Console::onDataSent(const QByteArray &data)
|
||||
void IO::Console::onDataSent(const QByteArray &data)
|
||||
{
|
||||
if (echo())
|
||||
append(dataToString(data) + "\n", showTimestamp());
|
||||
@ -571,7 +565,7 @@ void Console::onDataSent(const QByteArray &data)
|
||||
* Adds the given @a data to the incoming data buffer, which is read later by the UI
|
||||
* refresh functions (displayData())
|
||||
*/
|
||||
void Console::onDataReceived(const QByteArray &data)
|
||||
void IO::Console::onDataReceived(const QByteArray &data)
|
||||
{
|
||||
m_dataBuffer.append(data);
|
||||
}
|
||||
@ -579,7 +573,7 @@ void Console::onDataReceived(const QByteArray &data)
|
||||
/**
|
||||
* Registers the given @a command to the list of sent commands.
|
||||
*/
|
||||
void Console::addToHistory(const QString &command)
|
||||
void IO::Console::addToHistory(const QString &command)
|
||||
{
|
||||
// Remove old commands from history
|
||||
while (m_historyItems.count() > 100)
|
||||
@ -594,7 +588,7 @@ void Console::addToHistory(const QString &command)
|
||||
/**
|
||||
* Converts the given @a data in HEX format into real binary data.
|
||||
*/
|
||||
QByteArray Console::hexToBytes(const QString &data)
|
||||
QByteArray IO::Console::hexToBytes(const QString &data)
|
||||
{
|
||||
QString withoutSpaces = data;
|
||||
withoutSpaces.replace(" ", "");
|
||||
@ -615,7 +609,7 @@ QByteArray Console::hexToBytes(const QString &data)
|
||||
* Converts the given @a data to a string according to the console display mode set by the
|
||||
* user.
|
||||
*/
|
||||
QString Console::dataToString(const QByteArray &data)
|
||||
QString IO::Console::dataToString(const QByteArray &data)
|
||||
{
|
||||
switch (displayMode())
|
||||
{
|
||||
@ -634,7 +628,7 @@ QString Console::dataToString(const QByteArray &data)
|
||||
/**
|
||||
* Converts the given @a data into an UTF-8 string
|
||||
*/
|
||||
QString Console::plainTextStr(const QByteArray &data)
|
||||
QString IO::Console::plainTextStr(const QByteArray &data)
|
||||
{
|
||||
QString str = QString::fromUtf8(data);
|
||||
|
||||
@ -647,7 +641,7 @@ QString Console::plainTextStr(const QByteArray &data)
|
||||
/**
|
||||
* Converts the given @a data into a HEX representation string.
|
||||
*/
|
||||
QString Console::hexadecimalStr(const QByteArray &data)
|
||||
QString IO::Console::hexadecimalStr(const QByteArray &data)
|
||||
{
|
||||
// Remove line breaks from data
|
||||
QByteArray copy = data;
|
||||
@ -668,4 +662,3 @@ QString Console::hexadecimalStr(const QByteArray &data)
|
||||
// Return string
|
||||
return str;
|
||||
}
|
||||
}
|
||||
|
@ -85,6 +85,13 @@ Q_SIGNALS:
|
||||
void showTimestampChanged();
|
||||
void stringReceived(const QString &text);
|
||||
|
||||
private:
|
||||
explicit Console();
|
||||
Console(Console &&) = delete;
|
||||
Console(const Console &) = delete;
|
||||
Console &operator=(Console &&) = delete;
|
||||
Console &operator=(const Console &) = delete;
|
||||
|
||||
public:
|
||||
enum class DisplayMode
|
||||
{
|
||||
@ -109,7 +116,7 @@ public:
|
||||
};
|
||||
Q_ENUM(LineEnding)
|
||||
|
||||
static Console *getInstance();
|
||||
static Console &instance();
|
||||
|
||||
bool echo() const;
|
||||
bool autoscroll() const;
|
||||
@ -148,7 +155,6 @@ private Q_SLOTS:
|
||||
void onDataReceived(const QByteArray &data);
|
||||
|
||||
private:
|
||||
Console();
|
||||
QByteArray hexToBytes(const QString &data);
|
||||
QString dataToString(const QByteArray &data);
|
||||
QString plainTextStr(const QByteArray &data);
|
||||
|
@ -25,16 +25,10 @@
|
||||
#include <IO/Manager.h>
|
||||
#include <Misc/Utilities.h>
|
||||
|
||||
namespace IO
|
||||
{
|
||||
namespace DataSources
|
||||
{
|
||||
static Network *NETWORK = Q_NULLPTR;
|
||||
|
||||
/**
|
||||
* Constructor function
|
||||
*/
|
||||
Network::Network()
|
||||
IO::DataSources::Network::Network()
|
||||
: m_hostExists(false)
|
||||
, m_udpMulticast(false)
|
||||
, m_lookupActive(false)
|
||||
@ -44,14 +38,16 @@ Network::Network()
|
||||
setUdpLocalPort(defaultUdpLocalPort());
|
||||
setUdpRemotePort(defaultUdpRemotePort());
|
||||
setSocketType(QAbstractSocket::TcpSocket);
|
||||
connect(&m_tcpSocket, &QTcpSocket::errorOccurred, this, &Network::onErrorOccurred);
|
||||
connect(&m_udpSocket, &QUdpSocket::errorOccurred, this, &Network::onErrorOccurred);
|
||||
connect(&m_tcpSocket, &QTcpSocket::errorOccurred, this,
|
||||
&IO::DataSources::Network::onErrorOccurred);
|
||||
connect(&m_udpSocket, &QUdpSocket::errorOccurred, this,
|
||||
&IO::DataSources::Network::onErrorOccurred);
|
||||
}
|
||||
|
||||
/**
|
||||
* Destructor function
|
||||
*/
|
||||
Network::~Network()
|
||||
IO::DataSources::Network::~Network()
|
||||
{
|
||||
disconnectDevice();
|
||||
}
|
||||
@ -59,18 +55,16 @@ Network::~Network()
|
||||
/**
|
||||
* Returns the only instance of this class
|
||||
*/
|
||||
Network *Network::getInstance()
|
||||
IO::DataSources::Network &IO::DataSources::Network::instance()
|
||||
{
|
||||
if (!NETWORK)
|
||||
NETWORK = new Network;
|
||||
|
||||
return NETWORK;
|
||||
static auto singleton = new Network();
|
||||
return *singleton;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the host address
|
||||
*/
|
||||
QString Network::remoteAddress() const
|
||||
QString IO::DataSources::Network::remoteAddress() const
|
||||
{
|
||||
return m_address;
|
||||
}
|
||||
@ -78,7 +72,7 @@ QString Network::remoteAddress() const
|
||||
/**
|
||||
* Returns the TCP port number
|
||||
*/
|
||||
quint16 Network::tcpPort() const
|
||||
quint16 IO::DataSources::Network::tcpPort() const
|
||||
{
|
||||
return m_tcpPort;
|
||||
}
|
||||
@ -86,7 +80,7 @@ quint16 Network::tcpPort() const
|
||||
/**
|
||||
* Returns the UDP local port number
|
||||
*/
|
||||
quint16 Network::udpLocalPort() const
|
||||
quint16 IO::DataSources::Network::udpLocalPort() const
|
||||
{
|
||||
return m_udpLocalPort;
|
||||
}
|
||||
@ -94,7 +88,7 @@ quint16 Network::udpLocalPort() const
|
||||
/**
|
||||
* Returns the UDP remote port number
|
||||
*/
|
||||
quint16 Network::udpRemotePort() const
|
||||
quint16 IO::DataSources::Network::udpRemotePort() const
|
||||
{
|
||||
return m_udpRemotePort;
|
||||
}
|
||||
@ -103,7 +97,7 @@ quint16 Network::udpRemotePort() const
|
||||
* Returns @c true if the UDP socket is managing a multicasted
|
||||
* connection.
|
||||
*/
|
||||
bool Network::udpMulticast() const
|
||||
bool IO::DataSources::Network::udpMulticast() const
|
||||
{
|
||||
return m_udpMulticast;
|
||||
}
|
||||
@ -111,7 +105,7 @@ bool Network::udpMulticast() const
|
||||
/**
|
||||
* Returns @c true if we are currently performing a DNS lookup
|
||||
*/
|
||||
bool Network::lookupActive() const
|
||||
bool IO::DataSources::Network::lookupActive() const
|
||||
{
|
||||
return m_lookupActive;
|
||||
}
|
||||
@ -120,7 +114,7 @@ bool Network::lookupActive() const
|
||||
* Returns the current socket type as an index of the list returned by the @c socketType
|
||||
* function.
|
||||
*/
|
||||
int Network::socketTypeIndex() const
|
||||
int IO::DataSources::Network::socketTypeIndex() const
|
||||
{
|
||||
switch (socketType())
|
||||
{
|
||||
@ -139,7 +133,7 @@ int Network::socketTypeIndex() const
|
||||
/**
|
||||
* Returns @c true if the port is greater than 0 and the host address is valid.
|
||||
*/
|
||||
bool Network::configurationOk() const
|
||||
bool IO::DataSources::Network::configurationOk() const
|
||||
{
|
||||
return tcpPort() > 0 && m_hostExists;
|
||||
}
|
||||
@ -147,7 +141,7 @@ bool Network::configurationOk() const
|
||||
/**
|
||||
* Returns a list with the available socket types
|
||||
*/
|
||||
StringList Network::socketTypes() const
|
||||
StringList IO::DataSources::Network::socketTypes() const
|
||||
{
|
||||
return StringList { "TCP", "UDP" };
|
||||
}
|
||||
@ -160,7 +154,7 @@ StringList Network::socketTypes() const
|
||||
* @c QAbstractSocket::SctpSocket
|
||||
* @c QAbstractSocket::UnknownSocketType
|
||||
*/
|
||||
QAbstractSocket::SocketType Network::socketType() const
|
||||
QAbstractSocket::SocketType IO::DataSources::Network::socketType() const
|
||||
{
|
||||
return m_socketType;
|
||||
}
|
||||
@ -168,7 +162,7 @@ QAbstractSocket::SocketType Network::socketType() const
|
||||
/**
|
||||
* Attempts to make a connection to the given host, port and TCP/UDP socket type.
|
||||
*/
|
||||
QIODevice *Network::openNetworkPort()
|
||||
QIODevice *IO::DataSources::Network::openNetworkPort()
|
||||
{
|
||||
// Disconnect all sockets
|
||||
disconnectDevice();
|
||||
@ -213,7 +207,7 @@ QIODevice *Network::openNetworkPort()
|
||||
/**
|
||||
* Instructs the module to communicate via a TCP socket.
|
||||
*/
|
||||
void Network::setTcpSocket()
|
||||
void IO::DataSources::Network::setTcpSocket()
|
||||
{
|
||||
setSocketType(QAbstractSocket::TcpSocket);
|
||||
}
|
||||
@ -221,7 +215,7 @@ void Network::setTcpSocket()
|
||||
/**
|
||||
* Instructs the module to communicate via an UDP socket.
|
||||
*/
|
||||
void Network::setUdpSocket()
|
||||
void IO::DataSources::Network::setUdpSocket()
|
||||
{
|
||||
setSocketType(QAbstractSocket::UdpSocket);
|
||||
}
|
||||
@ -229,7 +223,7 @@ void Network::setUdpSocket()
|
||||
/**
|
||||
* Disconnects the TCP/UDP sockets from the host
|
||||
*/
|
||||
void Network::disconnectDevice()
|
||||
void IO::DataSources::Network::disconnectDevice()
|
||||
{
|
||||
m_tcpSocket.abort();
|
||||
m_udpSocket.abort();
|
||||
@ -240,7 +234,7 @@ void Network::disconnectDevice()
|
||||
/**
|
||||
* Changes the TCP socket's @c port number
|
||||
*/
|
||||
void Network::setTcpPort(const quint16 port)
|
||||
void IO::DataSources::Network::setTcpPort(const quint16 port)
|
||||
{
|
||||
m_tcpPort = port;
|
||||
Q_EMIT portChanged();
|
||||
@ -249,7 +243,7 @@ void Network::setTcpPort(const quint16 port)
|
||||
/**
|
||||
* Changes the UDP socket's local @c port number
|
||||
*/
|
||||
void Network::setUdpLocalPort(const quint16 port)
|
||||
void IO::DataSources::Network::setUdpLocalPort(const quint16 port)
|
||||
{
|
||||
m_udpLocalPort = port;
|
||||
Q_EMIT portChanged();
|
||||
@ -258,7 +252,7 @@ void Network::setUdpLocalPort(const quint16 port)
|
||||
/**
|
||||
* Changes the UDP socket's remote @c port number
|
||||
*/
|
||||
void Network::setUdpRemotePort(const quint16 port)
|
||||
void IO::DataSources::Network::setUdpRemotePort(const quint16 port)
|
||||
{
|
||||
m_udpRemotePort = port;
|
||||
Q_EMIT portChanged();
|
||||
@ -267,7 +261,7 @@ void Network::setUdpRemotePort(const quint16 port)
|
||||
/**
|
||||
* Sets the IPv4 or IPv6 address specified by the input string representation
|
||||
*/
|
||||
void Network::setRemoteAddress(const QString &address)
|
||||
void IO::DataSources::Network::setRemoteAddress(const QString &address)
|
||||
{
|
||||
// Check if host name exists
|
||||
if (QHostAddress(address).isNull())
|
||||
@ -288,17 +282,18 @@ void Network::setRemoteAddress(const QString &address)
|
||||
/**
|
||||
* Performs a DNS lookup for the given @a host name
|
||||
*/
|
||||
void Network::lookup(const QString &host)
|
||||
void IO::DataSources::Network::lookup(const QString &host)
|
||||
{
|
||||
m_lookupActive = true;
|
||||
Q_EMIT lookupActiveChanged();
|
||||
QHostInfo::lookupHost(host.simplified(), this, &Network::lookupFinished);
|
||||
QHostInfo::lookupHost(host.simplified(), this,
|
||||
&IO::DataSources::Network::lookupFinished);
|
||||
}
|
||||
|
||||
/**
|
||||
* Enables/Disables multicast connections with the UDP socket.
|
||||
*/
|
||||
void Network::setUdpMulticast(const bool enabled)
|
||||
void IO::DataSources::Network::setUdpMulticast(const bool enabled)
|
||||
{
|
||||
m_udpMulticast = enabled;
|
||||
Q_EMIT udpMulticastChanged();
|
||||
@ -308,7 +303,7 @@ void Network::setUdpMulticast(const bool enabled)
|
||||
* Changes the current socket type given an index of the list returned by the
|
||||
* @c socketType() function.
|
||||
*/
|
||||
void Network::setSocketTypeIndex(const int index)
|
||||
void IO::DataSources::Network::setSocketTypeIndex(const int index)
|
||||
{
|
||||
switch (index)
|
||||
{
|
||||
@ -330,7 +325,7 @@ void Network::setSocketTypeIndex(const int index)
|
||||
* @c QAbstractSocket::UdpSocket
|
||||
* @c QAbstractSocket::UnknownSocketType
|
||||
*/
|
||||
void Network::setSocketType(const QAbstractSocket::SocketType type)
|
||||
void IO::DataSources::Network::setSocketType(const QAbstractSocket::SocketType type)
|
||||
{
|
||||
m_socketType = type;
|
||||
Q_EMIT socketTypeChanged();
|
||||
@ -340,7 +335,7 @@ void Network::setSocketType(const QAbstractSocket::SocketType type)
|
||||
* Sets the host IP address when the lookup finishes.
|
||||
* If the lookup fails, the error code/string shall be shown to the user in a messagebox.
|
||||
*/
|
||||
void Network::lookupFinished(const QHostInfo &info)
|
||||
void IO::DataSources::Network::lookupFinished(const QHostInfo &info)
|
||||
{
|
||||
m_lookupActive = false;
|
||||
Q_EMIT lookupActiveChanged();
|
||||
@ -361,7 +356,8 @@ void Network::lookupFinished(const QHostInfo &info)
|
||||
* This function is called whenever a socket error occurs, it disconnects the socket
|
||||
* from the host and displays the error in a message box.
|
||||
*/
|
||||
void Network::onErrorOccurred(const QAbstractSocket::SocketError socketError)
|
||||
void IO::DataSources::Network::onErrorOccurred(
|
||||
const QAbstractSocket::SocketError socketError)
|
||||
{
|
||||
QString error;
|
||||
if (socketType() == QAbstractSocket::TcpSocket)
|
||||
@ -371,8 +367,6 @@ void Network::onErrorOccurred(const QAbstractSocket::SocketError socketError)
|
||||
else
|
||||
error = QString::number(socketError);
|
||||
|
||||
Manager::getInstance()->disconnectDevice();
|
||||
Manager::instance().disconnectDevice();
|
||||
Misc::Utilities::showMessageBox(tr("Network socket error"), error);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -99,8 +99,17 @@ Q_SIGNALS:
|
||||
void udpMulticastChanged();
|
||||
void lookupActiveChanged();
|
||||
|
||||
private:
|
||||
explicit Network();
|
||||
Network(Network &&) = delete;
|
||||
Network(const Network &) = delete;
|
||||
Network &operator=(Network &&) = delete;
|
||||
Network &operator=(const Network &) = delete;
|
||||
|
||||
~Network();
|
||||
|
||||
public:
|
||||
static Network *getInstance();
|
||||
static Network &instance();
|
||||
|
||||
QString remoteAddress() const;
|
||||
|
||||
@ -142,10 +151,6 @@ private Q_SLOTS:
|
||||
void lookupFinished(const QHostInfo &info);
|
||||
void onErrorOccurred(const QAbstractSocket::SocketError socketError);
|
||||
|
||||
private:
|
||||
Network();
|
||||
~Network();
|
||||
|
||||
private:
|
||||
QString m_address;
|
||||
quint16 m_tcpPort;
|
||||
|
@ -26,16 +26,10 @@
|
||||
#include <Misc/Utilities.h>
|
||||
#include <Misc/TimerEvents.h>
|
||||
|
||||
namespace IO
|
||||
{
|
||||
namespace DataSources
|
||||
{
|
||||
static Serial *SERIAL = Q_NULLPTR;
|
||||
|
||||
/**
|
||||
* Constructor function
|
||||
*/
|
||||
Serial::Serial()
|
||||
IO::DataSources::Serial::Serial()
|
||||
: m_port(Q_NULLPTR)
|
||||
, m_autoReconnect(false)
|
||||
, m_lastSerialDeviceIndex(0)
|
||||
@ -53,7 +47,7 @@ Serial::Serial()
|
||||
setFlowControl(flowControlList().indexOf(tr("None")));
|
||||
|
||||
// Build serial devices list
|
||||
const auto te = Misc::TimerEvents::getInstance();
|
||||
const auto te = &Misc::TimerEvents::instance();
|
||||
connect(te, SIGNAL(lowFreqTimeout()), this, SLOT(refreshSerialDevices()));
|
||||
}
|
||||
|
||||
@ -61,7 +55,7 @@ Serial::Serial()
|
||||
* Destructor function, closes the serial port before exiting the application and saves
|
||||
* the user's baud rate list settings.
|
||||
*/
|
||||
Serial::~Serial()
|
||||
IO::DataSources::Serial::~Serial()
|
||||
{
|
||||
writeSettings();
|
||||
|
||||
@ -72,18 +66,16 @@ Serial::~Serial()
|
||||
/**
|
||||
* Returns the only instance of the class
|
||||
*/
|
||||
Serial *Serial::getInstance()
|
||||
IO::DataSources::Serial &IO::DataSources::Serial::instance()
|
||||
{
|
||||
if (SERIAL == Q_NULLPTR)
|
||||
SERIAL = new Serial;
|
||||
|
||||
return SERIAL;
|
||||
static auto singleton = new Serial();
|
||||
return *singleton;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the pointer to the current serial port handler
|
||||
*/
|
||||
QSerialPort *Serial::port() const
|
||||
QSerialPort *IO::DataSources::Serial::port() const
|
||||
{
|
||||
return m_port;
|
||||
}
|
||||
@ -91,7 +83,7 @@ QSerialPort *Serial::port() const
|
||||
/**
|
||||
* Returns the name of the current serial port device
|
||||
*/
|
||||
QString Serial::portName() const
|
||||
QString IO::DataSources::Serial::portName() const
|
||||
{
|
||||
if (port())
|
||||
return port()->portName();
|
||||
@ -102,7 +94,7 @@ QString Serial::portName() const
|
||||
/**
|
||||
* Returns @c true if auto-reconnect is enabled
|
||||
*/
|
||||
bool Serial::autoReconnect() const
|
||||
bool IO::DataSources::Serial::autoReconnect() const
|
||||
{
|
||||
return m_autoReconnect;
|
||||
}
|
||||
@ -111,7 +103,7 @@ bool Serial::autoReconnect() const
|
||||
* Returns @c true if the user selects the appropiate controls & options to be able
|
||||
* to connect to a serial device
|
||||
*/
|
||||
bool Serial::configurationOk() const
|
||||
bool IO::DataSources::Serial::configurationOk() const
|
||||
{
|
||||
return portIndex() > 0;
|
||||
}
|
||||
@ -119,7 +111,7 @@ bool Serial::configurationOk() const
|
||||
/**
|
||||
* Returns the index of the current serial device selected by the program.
|
||||
*/
|
||||
quint8 Serial::portIndex() const
|
||||
quint8 IO::DataSources::Serial::portIndex() const
|
||||
{
|
||||
return m_portIndex;
|
||||
}
|
||||
@ -128,7 +120,7 @@ quint8 Serial::portIndex() const
|
||||
* Returns the correspoding index of the parity configuration in relation
|
||||
* to the @c StringList returned by the @c parityList() function.
|
||||
*/
|
||||
quint8 Serial::parityIndex() const
|
||||
quint8 IO::DataSources::Serial::parityIndex() const
|
||||
{
|
||||
return m_parityIndex;
|
||||
}
|
||||
@ -137,7 +129,7 @@ quint8 Serial::parityIndex() const
|
||||
* Returns the correspoding index of the data bits configuration in relation
|
||||
* to the @c StringList returned by the @c dataBitsList() function.
|
||||
*/
|
||||
quint8 Serial::dataBitsIndex() const
|
||||
quint8 IO::DataSources::Serial::dataBitsIndex() const
|
||||
{
|
||||
return m_dataBitsIndex;
|
||||
}
|
||||
@ -146,7 +138,7 @@ quint8 Serial::dataBitsIndex() const
|
||||
* Returns the correspoding index of the stop bits configuration in relation
|
||||
* to the @c StringList returned by the @c stopBitsList() function.
|
||||
*/
|
||||
quint8 Serial::stopBitsIndex() const
|
||||
quint8 IO::DataSources::Serial::stopBitsIndex() const
|
||||
{
|
||||
return m_stopBitsIndex;
|
||||
}
|
||||
@ -155,7 +147,7 @@ quint8 Serial::stopBitsIndex() const
|
||||
* Returns the correspoding index of the flow control config. in relation
|
||||
* to the @c StringList returned by the @c flowControlList() function.
|
||||
*/
|
||||
quint8 Serial::flowControlIndex() const
|
||||
quint8 IO::DataSources::Serial::flowControlIndex() const
|
||||
{
|
||||
return m_flowControlIndex;
|
||||
}
|
||||
@ -168,7 +160,7 @@ quint8 Serial::flowControlIndex() const
|
||||
* be "Select Serial Device". This is inteded to make the user interface
|
||||
* a little more friendly.
|
||||
*/
|
||||
StringList Serial::portList() const
|
||||
StringList IO::DataSources::Serial::portList() const
|
||||
{
|
||||
return m_portList;
|
||||
}
|
||||
@ -177,7 +169,7 @@ StringList Serial::portList() const
|
||||
* Returns a list with the available parity configurations.
|
||||
* This function can be used with a combo-box to build UIs.
|
||||
*/
|
||||
StringList Serial::parityList() const
|
||||
StringList IO::DataSources::Serial::parityList() const
|
||||
{
|
||||
StringList list;
|
||||
list.append(tr("None"));
|
||||
@ -192,7 +184,7 @@ StringList Serial::parityList() const
|
||||
* Returns a list with the available baud rate configurations.
|
||||
* This function can be used with a combo-box to build UIs.
|
||||
*/
|
||||
StringList Serial::baudRateList() const
|
||||
StringList IO::DataSources::Serial::baudRateList() const
|
||||
{
|
||||
return m_baudRateList;
|
||||
}
|
||||
@ -201,7 +193,7 @@ StringList Serial::baudRateList() const
|
||||
* Returns a list with the available data bits configurations.
|
||||
* This function can be used with a combo-box to build UIs.
|
||||
*/
|
||||
StringList Serial::dataBitsList() const
|
||||
StringList IO::DataSources::Serial::dataBitsList() const
|
||||
{
|
||||
return StringList { "5", "6", "7", "8" };
|
||||
}
|
||||
@ -210,7 +202,7 @@ StringList Serial::dataBitsList() const
|
||||
* Returns a list with the available stop bits configurations.
|
||||
* This function can be used with a combo-box to build UIs.
|
||||
*/
|
||||
StringList Serial::stopBitsList() const
|
||||
StringList IO::DataSources::Serial::stopBitsList() const
|
||||
{
|
||||
return StringList { "1", "1.5", "2" };
|
||||
}
|
||||
@ -219,7 +211,7 @@ StringList Serial::stopBitsList() const
|
||||
* Returns a list with the available flow control configurations.
|
||||
* This function can be used with a combo-box to build UIs.
|
||||
*/
|
||||
StringList Serial::flowControlList() const
|
||||
StringList IO::DataSources::Serial::flowControlList() const
|
||||
{
|
||||
StringList list;
|
||||
list.append(tr("None"));
|
||||
@ -232,7 +224,7 @@ StringList Serial::flowControlList() const
|
||||
* Returns the current parity configuration used by the serial port
|
||||
* handler object.
|
||||
*/
|
||||
QSerialPort::Parity Serial::parity() const
|
||||
QSerialPort::Parity IO::DataSources::Serial::parity() const
|
||||
{
|
||||
return m_parity;
|
||||
}
|
||||
@ -241,7 +233,7 @@ QSerialPort::Parity Serial::parity() const
|
||||
* Returns the current baud rate configuration used by the serial port
|
||||
* handler object.
|
||||
*/
|
||||
qint32 Serial::baudRate() const
|
||||
qint32 IO::DataSources::Serial::baudRate() const
|
||||
{
|
||||
return m_baudRate;
|
||||
}
|
||||
@ -250,7 +242,7 @@ qint32 Serial::baudRate() const
|
||||
* Returns the current data bits configuration used by the serial port
|
||||
* handler object.
|
||||
*/
|
||||
QSerialPort::DataBits Serial::dataBits() const
|
||||
QSerialPort::DataBits IO::DataSources::Serial::dataBits() const
|
||||
{
|
||||
return m_dataBits;
|
||||
}
|
||||
@ -259,7 +251,7 @@ QSerialPort::DataBits Serial::dataBits() const
|
||||
* Returns the current stop bits configuration used by the serial port
|
||||
* handler object.
|
||||
*/
|
||||
QSerialPort::StopBits Serial::stopBits() const
|
||||
QSerialPort::StopBits IO::DataSources::Serial::stopBits() const
|
||||
{
|
||||
return m_stopBits;
|
||||
}
|
||||
@ -268,7 +260,7 @@ QSerialPort::StopBits Serial::stopBits() const
|
||||
* Returns the current flow control configuration used by the serial
|
||||
* port handler object.
|
||||
*/
|
||||
QSerialPort::FlowControl Serial::flowControl() const
|
||||
QSerialPort::FlowControl IO::DataSources::Serial::flowControl() const
|
||||
{
|
||||
return m_flowControl;
|
||||
}
|
||||
@ -276,7 +268,7 @@ QSerialPort::FlowControl Serial::flowControl() const
|
||||
/**
|
||||
* Tries to open the serial port with the current configuration
|
||||
*/
|
||||
QSerialPort *Serial::openSerialPort()
|
||||
QSerialPort *IO::DataSources::Serial::openSerialPort()
|
||||
{
|
||||
// Ignore the first item of the list (Select Port)
|
||||
auto ports = validPorts();
|
||||
@ -315,7 +307,7 @@ QSerialPort *Serial::openSerialPort()
|
||||
/**
|
||||
* Disconnects from the current serial device and clears temp. data
|
||||
*/
|
||||
void Serial::disconnectDevice()
|
||||
void IO::DataSources::Serial::disconnectDevice()
|
||||
{
|
||||
// Check if serial port pointer is valid
|
||||
if (port() != Q_NULLPTR)
|
||||
@ -337,7 +329,7 @@ void Serial::disconnectDevice()
|
||||
/**
|
||||
* Changes the baud @a rate of the serial port
|
||||
*/
|
||||
void Serial::setBaudRate(const qint32 rate)
|
||||
void IO::DataSources::Serial::setBaudRate(const qint32 rate)
|
||||
{
|
||||
// Asserts
|
||||
Q_ASSERT(rate > 10);
|
||||
@ -357,7 +349,7 @@ void Serial::setBaudRate(const qint32 rate)
|
||||
* Changes the port index value, this value is later used by the @c openSerialPort()
|
||||
* function.
|
||||
*/
|
||||
void Serial::setPortIndex(const quint8 portIndex)
|
||||
void IO::DataSources::Serial::setPortIndex(const quint8 portIndex)
|
||||
{
|
||||
auto portId = portIndex - 1;
|
||||
if (portId >= 0 && portId < validPorts().count())
|
||||
@ -369,10 +361,10 @@ void Serial::setPortIndex(const quint8 portIndex)
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Serial::setParity
|
||||
* @brief IO::DataSources::Serial::setParity
|
||||
* @param parityIndex
|
||||
*/
|
||||
void Serial::setParity(const quint8 parityIndex)
|
||||
void IO::DataSources::Serial::setParity(const quint8 parityIndex)
|
||||
{
|
||||
// Argument verification
|
||||
Q_ASSERT(parityIndex < parityList().count());
|
||||
@ -411,7 +403,7 @@ void Serial::setParity(const quint8 parityIndex)
|
||||
/**
|
||||
* Registers the new baud rate to the list
|
||||
*/
|
||||
void Serial::appendBaudRate(const QString &baudRate)
|
||||
void IO::DataSources::Serial::appendBaudRate(const QString &baudRate)
|
||||
{
|
||||
if (!m_baudRateList.contains(baudRate))
|
||||
{
|
||||
@ -430,7 +422,7 @@ void Serial::appendBaudRate(const QString &baudRate)
|
||||
* @note This function is meant to be used with a combobox in the
|
||||
* QML interface
|
||||
*/
|
||||
void Serial::setDataBits(const quint8 dataBitsIndex)
|
||||
void IO::DataSources::Serial::setDataBits(const quint8 dataBitsIndex)
|
||||
{
|
||||
// Argument verification
|
||||
Q_ASSERT(dataBitsIndex < dataBitsList().count());
|
||||
@ -469,7 +461,7 @@ void Serial::setDataBits(const quint8 dataBitsIndex)
|
||||
* @note This function is meant to be used with a combobox in the
|
||||
* QML interface
|
||||
*/
|
||||
void Serial::setStopBits(const quint8 stopBitsIndex)
|
||||
void IO::DataSources::Serial::setStopBits(const quint8 stopBitsIndex)
|
||||
{
|
||||
// Argument verification
|
||||
Q_ASSERT(stopBitsIndex < stopBitsList().count());
|
||||
@ -502,7 +494,7 @@ void Serial::setStopBits(const quint8 stopBitsIndex)
|
||||
/**
|
||||
* Enables or disables the auto-reconnect feature
|
||||
*/
|
||||
void Serial::setAutoReconnect(const bool autoreconnect)
|
||||
void IO::DataSources::Serial::setAutoReconnect(const bool autoreconnect)
|
||||
{
|
||||
m_autoReconnect = autoreconnect;
|
||||
Q_EMIT autoReconnectChanged();
|
||||
@ -514,7 +506,7 @@ void Serial::setAutoReconnect(const bool autoreconnect)
|
||||
* @note This function is meant to be used with a combobox in the
|
||||
* QML interface
|
||||
*/
|
||||
void Serial::setFlowControl(const quint8 flowControlIndex)
|
||||
void IO::DataSources::Serial::setFlowControl(const quint8 flowControlIndex)
|
||||
{
|
||||
// Argument verification
|
||||
Q_ASSERT(flowControlIndex < flowControlList().count());
|
||||
@ -548,7 +540,7 @@ void Serial::setFlowControl(const quint8 flowControlIndex)
|
||||
* Scans for new serial ports available & generates a StringList with current
|
||||
* serial ports.
|
||||
*/
|
||||
void Serial::refreshSerialDevices()
|
||||
void IO::DataSources::Serial::refreshSerialDevices()
|
||||
{
|
||||
// Create device list, starting with dummy header
|
||||
// (for a more friendly UI when no devices are attached)
|
||||
@ -585,14 +577,14 @@ void Serial::refreshSerialDevices()
|
||||
}
|
||||
|
||||
// Auto reconnect
|
||||
if (Manager::getInstance()->dataSource() == Manager::DataSource::Serial)
|
||||
if (Manager::instance().dataSource() == Manager::DataSource::Serial)
|
||||
{
|
||||
if (autoReconnect() && m_lastSerialDeviceIndex > 0)
|
||||
{
|
||||
if (m_lastSerialDeviceIndex < portList().count())
|
||||
{
|
||||
setPortIndex(m_lastSerialDeviceIndex);
|
||||
Manager::getInstance()->connectDevice();
|
||||
Manager::instance().connectDevice();
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -603,19 +595,19 @@ void Serial::refreshSerialDevices()
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Serial::handleError
|
||||
* @brief IO::DataSources::Serial::handleError
|
||||
* @param error
|
||||
*/
|
||||
void Serial::handleError(QSerialPort::SerialPortError error)
|
||||
void IO::DataSources::Serial::handleError(QSerialPort::SerialPortError error)
|
||||
{
|
||||
if (error != QSerialPort::NoError)
|
||||
Manager::getInstance()->disconnectDevice();
|
||||
Manager::instance().disconnectDevice();
|
||||
}
|
||||
|
||||
/**
|
||||
* Read saved settings (if any)
|
||||
*/
|
||||
void Serial::readSettings()
|
||||
void IO::DataSources::Serial::readSettings()
|
||||
{
|
||||
// Register standard baud rates
|
||||
QStringList stdBaudRates
|
||||
@ -651,7 +643,7 @@ void Serial::readSettings()
|
||||
/**
|
||||
* Save settings between application runs
|
||||
*/
|
||||
void Serial::writeSettings()
|
||||
void IO::DataSources::Serial::writeSettings()
|
||||
{
|
||||
// Sort baud rate list
|
||||
for (auto i = 0; i < m_baudRateList.count() - 1; ++i)
|
||||
@ -680,7 +672,7 @@ void Serial::writeSettings()
|
||||
/**
|
||||
* Returns a list with all the valid serial port objects
|
||||
*/
|
||||
QVector<QSerialPortInfo> Serial::validPorts() const
|
||||
QVector<QSerialPortInfo> IO::DataSources::Serial::validPorts() const
|
||||
{
|
||||
// Search for available ports and add them to the list
|
||||
QVector<QSerialPortInfo> ports;
|
||||
@ -702,5 +694,3 @@ QVector<QSerialPortInfo> Serial::validPorts() const
|
||||
// Return list
|
||||
return ports;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -110,8 +110,17 @@ Q_SIGNALS:
|
||||
void availablePortsChanged();
|
||||
void connectionError(const QString &name);
|
||||
|
||||
private:
|
||||
explicit Serial();
|
||||
Serial(Serial &&) = delete;
|
||||
Serial(const Serial &) = delete;
|
||||
Serial &operator=(Serial &&) = delete;
|
||||
Serial &operator=(const Serial &) = delete;
|
||||
|
||||
~Serial();
|
||||
|
||||
public:
|
||||
static Serial *getInstance();
|
||||
static Serial &instance();
|
||||
|
||||
QString portName() const;
|
||||
QSerialPort *port() const;
|
||||
@ -158,8 +167,6 @@ private Q_SLOTS:
|
||||
void handleError(QSerialPort::SerialPortError error);
|
||||
|
||||
private:
|
||||
Serial();
|
||||
~Serial();
|
||||
QVector<QSerialPortInfo> validPorts() const;
|
||||
|
||||
private:
|
||||
|
@ -30,10 +30,6 @@
|
||||
|
||||
#include <QNetworkDatagram>
|
||||
|
||||
namespace IO
|
||||
{
|
||||
static Manager *MANAGER = Q_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".
|
||||
@ -58,7 +54,7 @@ static QString ADD_ESCAPE_SEQUENCES(const QString &str)
|
||||
/**
|
||||
* Constructor function
|
||||
*/
|
||||
Manager::Manager()
|
||||
IO::Manager::Manager()
|
||||
: m_enableCrc(false)
|
||||
, m_writeEnabled(true)
|
||||
, m_maxBufferSize(1024 * 1024)
|
||||
@ -73,34 +69,27 @@ Manager::Manager()
|
||||
setMaxBufferSize(1024 * 1024);
|
||||
|
||||
// Configure signals/slots
|
||||
const auto serial = DataSources::Serial::getInstance();
|
||||
const auto netwrk = DataSources::Network::getInstance();
|
||||
const auto serial = &DataSources::Serial::instance();
|
||||
const auto netwrk = &DataSources::Network::instance();
|
||||
connect(netwrk, SIGNAL(portChanged()), this, SIGNAL(configurationChanged()));
|
||||
connect(netwrk, SIGNAL(addressChanged()), this, SIGNAL(configurationChanged()));
|
||||
connect(this, SIGNAL(dataSourceChanged()), this, SIGNAL(configurationChanged()));
|
||||
connect(serial, SIGNAL(portIndexChanged()), this, SIGNAL(configurationChanged()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Destructor function
|
||||
*/
|
||||
Manager::~Manager() { }
|
||||
|
||||
/**
|
||||
* Returns the only instance of the class
|
||||
*/
|
||||
Manager *Manager::getInstance()
|
||||
IO::Manager &IO::Manager::instance()
|
||||
{
|
||||
if (!MANAGER)
|
||||
MANAGER = new Manager;
|
||||
|
||||
return MANAGER;
|
||||
static auto singleton = new Manager();
|
||||
return *singleton;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns @c true if a device is connected and its open in read-only mode
|
||||
*/
|
||||
bool Manager::readOnly()
|
||||
bool IO::Manager::readOnly()
|
||||
{
|
||||
return connected() && !m_writeEnabled;
|
||||
}
|
||||
@ -108,7 +97,7 @@ bool Manager::readOnly()
|
||||
/**
|
||||
* Returns @c true if a device is connected and its open in read/write mode
|
||||
*/
|
||||
bool Manager::readWrite()
|
||||
bool IO::Manager::readWrite()
|
||||
{
|
||||
return connected() && m_writeEnabled;
|
||||
}
|
||||
@ -117,18 +106,18 @@ bool Manager::readWrite()
|
||||
* Returns @c true if a device is currently selected and opened or if the MQTT client
|
||||
* is currently connected as a subscriber.
|
||||
*/
|
||||
bool Manager::connected()
|
||||
bool IO::Manager::connected()
|
||||
{
|
||||
if (device())
|
||||
return device()->isOpen();
|
||||
|
||||
return MQTT::Client::getInstance()->isSubscribed();
|
||||
return MQTT::Client::instance().isSubscribed();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns @c true if a device is currently selected
|
||||
*/
|
||||
bool Manager::deviceAvailable()
|
||||
bool IO::Manager::deviceAvailable()
|
||||
{
|
||||
return device() != Q_NULLPTR;
|
||||
}
|
||||
@ -136,12 +125,12 @@ bool Manager::deviceAvailable()
|
||||
/**
|
||||
* Returns @c true if we are able to connect to a device/port with the current config.
|
||||
*/
|
||||
bool Manager::configurationOk() const
|
||||
bool IO::Manager::configurationOk() const
|
||||
{
|
||||
if (dataSource() == DataSource::Serial)
|
||||
return DataSources::Serial::getInstance()->configurationOk();
|
||||
return DataSources::Serial::instance().configurationOk();
|
||||
else if (dataSource() == DataSource::Network)
|
||||
return DataSources::Network::getInstance()->configurationOk();
|
||||
return DataSources::Network::instance().configurationOk();
|
||||
|
||||
return false;
|
||||
}
|
||||
@ -166,7 +155,7 @@ bool Manager::configurationOk() const
|
||||
*
|
||||
* TODO: let the JSON project file define the watchdog timeout time.
|
||||
*/
|
||||
int Manager::watchdogInterval() const
|
||||
int IO::Manager::watchdogInterval() const
|
||||
{
|
||||
return m_watchdog.interval();
|
||||
}
|
||||
@ -176,7 +165,7 @@ int Manager::watchdogInterval() const
|
||||
* memory when a large block of invalid data is received (for example, when the user
|
||||
* selects an invalid baud rate configuration).
|
||||
*/
|
||||
int Manager::maxBufferSize() const
|
||||
int IO::Manager::maxBufferSize() const
|
||||
{
|
||||
return m_maxBufferSize;
|
||||
}
|
||||
@ -187,7 +176,7 @@ int Manager::maxBufferSize() const
|
||||
* @warning you need to check this pointer before using it, it can have a @c Q_NULLPTR
|
||||
* value during normal operations.
|
||||
*/
|
||||
QIODevice *Manager::device()
|
||||
QIODevice *IO::Manager::device()
|
||||
{
|
||||
return m_device;
|
||||
}
|
||||
@ -197,7 +186,7 @@ QIODevice *Manager::device()
|
||||
* - @c DataSource::Serial use a serial port as a data source
|
||||
* - @c DataSource::Network use a network port as a data source
|
||||
*/
|
||||
Manager::DataSource Manager::dataSource() const
|
||||
IO::Manager::DataSource IO::Manager::dataSource() const
|
||||
{
|
||||
return m_dataSource;
|
||||
}
|
||||
@ -207,7 +196,7 @@ Manager::DataSource Manager::dataSource() const
|
||||
* that a frame begins. If the start sequence is empty, then the application shall ignore
|
||||
* incoming data. The only thing that wont ignore the incoming data will be the console.
|
||||
*/
|
||||
QString Manager::startSequence() const
|
||||
QString IO::Manager::startSequence() const
|
||||
{
|
||||
return m_startSequence;
|
||||
}
|
||||
@ -217,7 +206,7 @@ QString Manager::startSequence() const
|
||||
* that a frame ends. If the start sequence is empty, then the application shall ignore
|
||||
* incoming data. The only thing that wont ignore the incoming data will be the console.
|
||||
*/
|
||||
QString Manager::finishSequence() const
|
||||
QString IO::Manager::finishSequence() const
|
||||
{
|
||||
return m_finishSequence;
|
||||
}
|
||||
@ -226,7 +215,7 @@ QString Manager::finishSequence() const
|
||||
* Returns the separator sequence string used by the application to know where to consider
|
||||
* that a data item ends.
|
||||
*/
|
||||
QString Manager::separatorSequence() const
|
||||
QString IO::Manager::separatorSequence() const
|
||||
{
|
||||
return m_separatorSequence;
|
||||
}
|
||||
@ -234,7 +223,7 @@ QString Manager::separatorSequence() const
|
||||
/**
|
||||
* Returns a list with the possible data source options.
|
||||
*/
|
||||
StringList Manager::dataSourcesList() const
|
||||
StringList IO::Manager::dataSourcesList() const
|
||||
{
|
||||
StringList list;
|
||||
list.append(tr("Serial port"));
|
||||
@ -247,7 +236,7 @@ StringList Manager::dataSourcesList() const
|
||||
*
|
||||
* @returns the number of bytes written to the target device
|
||||
*/
|
||||
qint64 Manager::writeData(const QByteArray &data)
|
||||
qint64 IO::Manager::writeData(const QByteArray &data)
|
||||
{
|
||||
if (connected())
|
||||
{
|
||||
@ -256,9 +245,8 @@ qint64 Manager::writeData(const QByteArray &data)
|
||||
// Check which data source to use to write data
|
||||
if (dataSource() == DataSource::Network)
|
||||
{
|
||||
auto network = DataSources::Network::getInstance();
|
||||
|
||||
// Write to UDP socket
|
||||
const auto network = &DataSources::Network::instance();
|
||||
if (network->socketType() == QAbstractSocket::UdpSocket)
|
||||
{
|
||||
bytes = network->udpSocket()->writeDatagram(
|
||||
@ -296,7 +284,7 @@ qint64 Manager::writeData(const QByteArray &data)
|
||||
* Connects/disconnects the application from the currently selected device. This function
|
||||
* is used as a convenience for the connect/disconnect button.
|
||||
*/
|
||||
void Manager::toggleConnection()
|
||||
void IO::Manager::toggleConnection()
|
||||
{
|
||||
if (connected())
|
||||
disconnectDevice();
|
||||
@ -308,18 +296,18 @@ void Manager::toggleConnection()
|
||||
* Closes the currently selected device and tries to open & configure a new connection.
|
||||
* A data source must be selected before calling this function.
|
||||
*/
|
||||
void Manager::connectDevice()
|
||||
void IO::Manager::connectDevice()
|
||||
{
|
||||
// Disconnect previous device (if any)
|
||||
disconnectDevice();
|
||||
|
||||
// Try to open a serial port connection
|
||||
if (dataSource() == DataSource::Serial)
|
||||
setDevice(DataSources::Serial::getInstance()->openSerialPort());
|
||||
setDevice(DataSources::Serial::instance().openSerialPort());
|
||||
|
||||
// Try to open a network connection
|
||||
else if (dataSource() == DataSource::Network)
|
||||
setDevice(DataSources::Network::getInstance()->openNetworkPort());
|
||||
setDevice(DataSources::Network::instance().openNetworkPort());
|
||||
|
||||
// Configure current device
|
||||
if (deviceAvailable())
|
||||
@ -331,7 +319,7 @@ void Manager::connectDevice()
|
||||
|
||||
// Open device
|
||||
if (device()->open(mode))
|
||||
connect(device(), &QIODevice::readyRead, this, &Manager::onDataReceived);
|
||||
connect(device(), &QIODevice::readyRead, this, &IO::Manager::onDataReceived);
|
||||
|
||||
// Error opening the device
|
||||
else
|
||||
@ -345,7 +333,7 @@ void Manager::connectDevice()
|
||||
/**
|
||||
* Disconnects from the current device and clears temp. data
|
||||
*/
|
||||
void Manager::disconnectDevice()
|
||||
void IO::Manager::disconnectDevice()
|
||||
{
|
||||
if (deviceAvailable())
|
||||
{
|
||||
@ -354,9 +342,9 @@ void Manager::disconnectDevice()
|
||||
|
||||
// Call-appropiate interface functions
|
||||
if (dataSource() == DataSource::Serial)
|
||||
DataSources::Serial::getInstance()->disconnectDevice();
|
||||
DataSources::Serial::instance().disconnectDevice();
|
||||
else if (dataSource() == DataSource::Network)
|
||||
DataSources::Network::getInstance()->disconnectDevice();
|
||||
DataSources::Network::instance().disconnectDevice();
|
||||
|
||||
// Update device pointer
|
||||
m_device = Q_NULLPTR;
|
||||
@ -376,7 +364,7 @@ void Manager::disconnectDevice()
|
||||
/**
|
||||
* Enables/disables RW mode
|
||||
*/
|
||||
void Manager::setWriteEnabled(const bool enabled)
|
||||
void IO::Manager::setWriteEnabled(const bool enabled)
|
||||
{
|
||||
m_writeEnabled = enabled;
|
||||
Q_EMIT writeEnabledChanged();
|
||||
@ -386,7 +374,7 @@ void Manager::setWriteEnabled(const bool enabled)
|
||||
* Reads the given payload and emits it as if it were received from a device.
|
||||
* This function is for convenience to interact with other application modules & plugins.
|
||||
*/
|
||||
void Manager::processPayload(const QByteArray &payload)
|
||||
void IO::Manager::processPayload(const QByteArray &payload)
|
||||
{
|
||||
if (!payload.isEmpty())
|
||||
{
|
||||
@ -409,7 +397,7 @@ void Manager::processPayload(const QByteArray &payload)
|
||||
* Changes the maximum permited buffer size. Check the @c maxBufferSize() function for
|
||||
* more information.
|
||||
*/
|
||||
void Manager::setMaxBufferSize(const int maxBufferSize)
|
||||
void IO::Manager::setMaxBufferSize(const int maxBufferSize)
|
||||
{
|
||||
m_maxBufferSize = maxBufferSize;
|
||||
Q_EMIT maxBufferSizeChanged();
|
||||
@ -421,7 +409,7 @@ void Manager::setMaxBufferSize(const int maxBufferSize)
|
||||
* Changes the frame start sequence. Check the @c startSequence() function for more
|
||||
* information.
|
||||
*/
|
||||
void Manager::setStartSequence(const QString &sequence)
|
||||
void IO::Manager::setStartSequence(const QString &sequence)
|
||||
{
|
||||
m_startSequence = ADD_ESCAPE_SEQUENCES(sequence);
|
||||
if (m_startSequence.isEmpty())
|
||||
@ -434,7 +422,7 @@ void Manager::setStartSequence(const QString &sequence)
|
||||
* Changes the frame end sequence. Check the @c finishSequence() function for more
|
||||
* information.
|
||||
*/
|
||||
void Manager::setFinishSequence(const QString &sequence)
|
||||
void IO::Manager::setFinishSequence(const QString &sequence)
|
||||
{
|
||||
m_finishSequence = ADD_ESCAPE_SEQUENCES(sequence);
|
||||
if (m_finishSequence.isEmpty())
|
||||
@ -447,7 +435,7 @@ void Manager::setFinishSequence(const QString &sequence)
|
||||
* Changes the frame separator sequence. Check the @c separatorSequence() function for
|
||||
* more information.
|
||||
*/
|
||||
void Manager::setSeparatorSequence(const QString &sequence)
|
||||
void IO::Manager::setSeparatorSequence(const QString &sequence)
|
||||
{
|
||||
m_separatorSequence = ADD_ESCAPE_SEQUENCES(sequence);
|
||||
if (m_separatorSequence.isEmpty())
|
||||
@ -460,7 +448,7 @@ void Manager::setSeparatorSequence(const QString &sequence)
|
||||
* Changes the expiration interval of the watchdog timer. Check the @c watchdogInterval()
|
||||
* function for more information.
|
||||
*/
|
||||
void Manager::setWatchdogInterval(const int interval)
|
||||
void IO::Manager::setWatchdogInterval(const int interval)
|
||||
{
|
||||
m_watchdog.setInterval(interval);
|
||||
m_watchdog.setTimerType(Qt::PreciseTimer);
|
||||
@ -470,7 +458,7 @@ void Manager::setWatchdogInterval(const int interval)
|
||||
/**
|
||||
* Changes the data source type. Check the @c dataSource() funciton for more information.
|
||||
*/
|
||||
void Manager::setDataSource(const IO::Manager::DataSource &source)
|
||||
void IO::Manager::setDataSource(const IO::Manager::DataSource &source)
|
||||
{
|
||||
// Disconnect current device
|
||||
if (connected())
|
||||
@ -490,7 +478,7 @@ void Manager::setDataSource(const IO::Manager::DataSource &source)
|
||||
*
|
||||
* Implemementation credits: @jpnorair and @alex-spataru
|
||||
*/
|
||||
void Manager::readFrames()
|
||||
void IO::Manager::readFrames()
|
||||
{
|
||||
// No device connected, abort
|
||||
if (!connected())
|
||||
@ -547,7 +535,7 @@ void Manager::readFrames()
|
||||
* Resets the watchdog timer before it expires. Check the @c watchdogInterval() function
|
||||
* for more information.
|
||||
*/
|
||||
void Manager::feedWatchdog()
|
||||
void IO::Manager::feedWatchdog()
|
||||
{
|
||||
m_watchdog.stop();
|
||||
m_watchdog.start();
|
||||
@ -558,7 +546,7 @@ void Manager::feedWatchdog()
|
||||
* registers incoming data to temporary buffer & extracts valid data frames from the
|
||||
* buffer using the @c readFrame() function.
|
||||
*/
|
||||
void Manager::onDataReceived()
|
||||
void IO::Manager::onDataReceived()
|
||||
{
|
||||
// Verify that device is still valid
|
||||
if (!device())
|
||||
@ -571,11 +559,10 @@ void Manager::onDataReceived()
|
||||
// Check if we need to use UDP socket functions
|
||||
if (dataSource() == DataSource::Network)
|
||||
{
|
||||
auto network = DataSources::Network::getInstance();
|
||||
if (network->socketType() == QAbstractSocket::UdpSocket)
|
||||
if (DataSources::Network::instance().socketType() == QAbstractSocket::UdpSocket)
|
||||
{
|
||||
udpConnection = true;
|
||||
const auto udpSocket = network->udpSocket();
|
||||
const auto udpSocket = DataSources::Network::instance().udpSocket();
|
||||
while (udpSocket->hasPendingDatagrams())
|
||||
{
|
||||
QByteArray datagram;
|
||||
@ -615,7 +602,7 @@ void Manager::onDataReceived()
|
||||
* the class when the temporary buffer size exceeds the limit imposed by the
|
||||
* @c maxBufferSize() function.
|
||||
*/
|
||||
void Manager::clearTempBuffer()
|
||||
void IO::Manager::clearTempBuffer()
|
||||
{
|
||||
m_dataBuffer.clear();
|
||||
}
|
||||
@ -624,7 +611,7 @@ void Manager::clearTempBuffer()
|
||||
* Called when the watchdog timer expires. For the moment, this function only clears the
|
||||
* temporary data buffer.
|
||||
*/
|
||||
void Manager::onWatchdogTriggered()
|
||||
void IO::Manager::onWatchdogTriggered()
|
||||
{
|
||||
clearTempBuffer();
|
||||
}
|
||||
@ -633,7 +620,7 @@ void Manager::onWatchdogTriggered()
|
||||
* Changes the target device pointer. Deletion should be handled by the interface
|
||||
* implementation, not by this class.
|
||||
*/
|
||||
void Manager::setDevice(QIODevice *device)
|
||||
void IO::Manager::setDevice(QIODevice *device)
|
||||
{
|
||||
disconnectDevice();
|
||||
m_device = device;
|
||||
@ -649,8 +636,9 @@ void Manager::setDevice(QIODevice *device)
|
||||
* @param cursor master buffer, should start with checksum type header
|
||||
* @param bytes pointer to the number of bytes that we need to chop from the master buffer
|
||||
*/
|
||||
Manager::ValidationStatus Manager::integrityChecks(const QByteArray &frame,
|
||||
const QByteArray &cursor, int *bytes)
|
||||
IO::Manager::ValidationStatus IO::Manager::integrityChecks(const QByteArray &frame,
|
||||
const QByteArray &cursor,
|
||||
int *bytes)
|
||||
{
|
||||
// Get finish sequence as byte array
|
||||
const auto finish = finishSequence().toUtf8();
|
||||
@ -746,4 +734,3 @@ Manager::ValidationStatus Manager::integrityChecks(const QByteArray &frame,
|
||||
// Checksum data incomplete
|
||||
return ValidationStatus::ChecksumIncomplete;
|
||||
}
|
||||
}
|
||||
|
@ -111,6 +111,13 @@ Q_SIGNALS:
|
||||
void dataReceived(const QByteArray &data);
|
||||
void frameReceived(const QByteArray &frame);
|
||||
|
||||
private:
|
||||
explicit Manager();
|
||||
Manager(Manager &&) = delete;
|
||||
Manager(const Manager &) = delete;
|
||||
Manager &operator=(Manager &&) = delete;
|
||||
Manager &operator=(const Manager &) = delete;
|
||||
|
||||
public:
|
||||
enum class DataSource
|
||||
{
|
||||
@ -127,7 +134,7 @@ public:
|
||||
};
|
||||
Q_ENUM(ValidationStatus)
|
||||
|
||||
static Manager *getInstance();
|
||||
static Manager &instance();
|
||||
|
||||
bool readOnly();
|
||||
bool readWrite();
|
||||
@ -170,9 +177,6 @@ private Q_SLOTS:
|
||||
void setDevice(QIODevice *device);
|
||||
|
||||
private:
|
||||
Manager();
|
||||
~Manager();
|
||||
|
||||
ValidationStatus integrityChecks(const QByteArray &frame,
|
||||
const QByteArray &masterBuffer, int *bytesToChop);
|
||||
|
||||
|
@ -24,11 +24,8 @@
|
||||
#include "Generator.h"
|
||||
#include "FrameInfo.h"
|
||||
|
||||
namespace JSON
|
||||
{
|
||||
Dataset::Dataset(QObject *parent)
|
||||
: QObject(parent)
|
||||
, m_fft(false)
|
||||
JSON::Dataset::Dataset()
|
||||
: m_fft(false)
|
||||
, m_led(false)
|
||||
, m_log(false)
|
||||
, m_graph(false)
|
||||
@ -44,12 +41,10 @@ Dataset::Dataset(QObject *parent)
|
||||
{
|
||||
}
|
||||
|
||||
Dataset::~Dataset() { }
|
||||
|
||||
/**
|
||||
* @return @c true if the UI should generate a FFT plot of this dataset
|
||||
*/
|
||||
bool Dataset::fft() const
|
||||
bool JSON::Dataset::fft() const
|
||||
{
|
||||
return m_fft;
|
||||
}
|
||||
@ -57,7 +52,7 @@ bool Dataset::fft() const
|
||||
/**
|
||||
* @return @c true if the UI should generate a LED of this dataset
|
||||
*/
|
||||
bool Dataset::led() const
|
||||
bool JSON::Dataset::led() const
|
||||
{
|
||||
return m_led;
|
||||
}
|
||||
@ -65,7 +60,7 @@ bool Dataset::led() const
|
||||
/**
|
||||
* @return @c true if the UI should generate a logarithmic plot of this dataset
|
||||
*/
|
||||
bool Dataset::log() const
|
||||
bool JSON::Dataset::log() const
|
||||
{
|
||||
return m_log;
|
||||
}
|
||||
@ -73,7 +68,7 @@ bool Dataset::log() const
|
||||
/**
|
||||
* @return @c true if the UI should graph this dataset
|
||||
*/
|
||||
bool Dataset::graph() const
|
||||
bool JSON::Dataset::graph() const
|
||||
{
|
||||
return m_graph;
|
||||
}
|
||||
@ -81,7 +76,7 @@ bool Dataset::graph() const
|
||||
/**
|
||||
* Returns the minimum value of the dataset
|
||||
*/
|
||||
double Dataset::min() const
|
||||
double JSON::Dataset::min() const
|
||||
{
|
||||
return m_min;
|
||||
}
|
||||
@ -89,7 +84,7 @@ double Dataset::min() const
|
||||
/**
|
||||
* Returns the maximum value of the dataset
|
||||
*/
|
||||
double Dataset::max() const
|
||||
double JSON::Dataset::max() const
|
||||
{
|
||||
return m_max;
|
||||
}
|
||||
@ -97,7 +92,7 @@ double Dataset::max() const
|
||||
/**
|
||||
* Returns the alarm level of the dataset
|
||||
*/
|
||||
double Dataset::alarm() const
|
||||
double JSON::Dataset::alarm() const
|
||||
{
|
||||
return m_alarm;
|
||||
}
|
||||
@ -105,7 +100,7 @@ double Dataset::alarm() const
|
||||
/**
|
||||
* @return The title/description of this dataset
|
||||
*/
|
||||
QString Dataset::title() const
|
||||
QString JSON::Dataset::title() const
|
||||
{
|
||||
return m_title;
|
||||
}
|
||||
@ -113,7 +108,7 @@ QString Dataset::title() const
|
||||
/**
|
||||
* @return The value/reading of this dataset
|
||||
*/
|
||||
QString Dataset::value() const
|
||||
QString JSON::Dataset::value() const
|
||||
{
|
||||
return m_value;
|
||||
}
|
||||
@ -121,7 +116,7 @@ QString Dataset::value() const
|
||||
/**
|
||||
* @return The units of this dataset
|
||||
*/
|
||||
QString Dataset::units() const
|
||||
QString JSON::Dataset::units() const
|
||||
{
|
||||
return m_units;
|
||||
}
|
||||
@ -129,7 +124,7 @@ QString Dataset::units() const
|
||||
/**
|
||||
* @return The widget value of this dataset
|
||||
*/
|
||||
QString Dataset::widget() const
|
||||
QString JSON::Dataset::widget() const
|
||||
{
|
||||
return m_widget;
|
||||
}
|
||||
@ -137,7 +132,7 @@ QString Dataset::widget() const
|
||||
/**
|
||||
* Returns the maximum freq. for the FFT transform
|
||||
*/
|
||||
int Dataset::fftSamples() const
|
||||
int JSON::Dataset::fftSamples() const
|
||||
{
|
||||
return qMax(1, m_fftSamples);
|
||||
}
|
||||
@ -145,7 +140,7 @@ int Dataset::fftSamples() const
|
||||
/**
|
||||
* Returns the JSON data that represents this widget
|
||||
*/
|
||||
QJsonObject Dataset::jsonData() const
|
||||
QJsonObject JSON::Dataset::jsonData() const
|
||||
{
|
||||
return m_jsonData;
|
||||
}
|
||||
@ -156,7 +151,7 @@ QJsonObject Dataset::jsonData() const
|
||||
*
|
||||
* @return @c true on read success, @c false on failure
|
||||
*/
|
||||
bool Dataset::read(const QJsonObject &object)
|
||||
bool JSON::Dataset::read(const QJsonObject &object)
|
||||
{
|
||||
if (!object.isEmpty())
|
||||
{
|
||||
@ -195,4 +190,3 @@ bool Dataset::read(const QJsonObject &object)
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -62,11 +62,10 @@ namespace JSON
|
||||
* @note All of the dataset fields are optional, except the "value"
|
||||
* field and the "title" field.
|
||||
*/
|
||||
class Dataset : public QObject
|
||||
class Dataset
|
||||
{
|
||||
public:
|
||||
Dataset(QObject *parent = Q_NULLPTR);
|
||||
~Dataset();
|
||||
Dataset();
|
||||
|
||||
bool fft() const;
|
||||
bool led() const;
|
||||
|
@ -33,10 +33,6 @@
|
||||
#include <QJsonObject>
|
||||
#include <QJsonDocument>
|
||||
|
||||
namespace JSON
|
||||
{
|
||||
static Editor *EDITOR = Q_NULLPTR;
|
||||
|
||||
//----------------------------------------------------------------------------------------
|
||||
// Constructor/deconstructor & singleton
|
||||
//----------------------------------------------------------------------------------------
|
||||
@ -47,7 +43,7 @@ static Editor *EDITOR = Q_NULLPTR;
|
||||
* constructor configures signals/slots with the JSON Generator to share the same JSON
|
||||
* document file.
|
||||
*/
|
||||
Editor::Editor()
|
||||
JSON::Editor::Editor()
|
||||
: m_title("")
|
||||
, m_separator("")
|
||||
, m_frameEndSequence("")
|
||||
@ -55,32 +51,40 @@ Editor::Editor()
|
||||
, m_modified(false)
|
||||
, m_filePath("")
|
||||
{
|
||||
// clang-format off
|
||||
|
||||
// Connect signals/slots
|
||||
connect(this, &Editor::groupChanged, this, &Editor::onGroupChanged);
|
||||
connect(this, &Editor::titleChanged, this, &Editor::onModelChanged);
|
||||
connect(this, &Editor::datasetChanged, this, &Editor::onDatasetChanged);
|
||||
connect(this, &Editor::separatorChanged, this, &Editor::onModelChanged);
|
||||
connect(this, &Editor::groupCountChanged, this, &Editor::onModelChanged);
|
||||
connect(this, &Editor::groupOrderChanged, this, &Editor::onModelChanged);
|
||||
connect(this, &Editor::frameEndSequenceChanged, this, &Editor::onModelChanged);
|
||||
connect(this, &Editor::frameStartSequenceChanged, this, &Editor::onModelChanged);
|
||||
connect(this, &JSON::Editor::groupChanged,
|
||||
this, &JSON::Editor::onGroupChanged);
|
||||
connect(this, &JSON::Editor::titleChanged,
|
||||
this, &JSON::Editor::onModelChanged);
|
||||
connect(this, &JSON::Editor::datasetChanged,
|
||||
this, &JSON::Editor::onDatasetChanged);
|
||||
connect(this, &JSON::Editor::separatorChanged,
|
||||
this, &JSON::Editor::onModelChanged);
|
||||
connect(this, &JSON::Editor::groupCountChanged,
|
||||
this, &JSON::Editor::onModelChanged);
|
||||
connect(this, &JSON::Editor::groupOrderChanged,
|
||||
this, &JSON::Editor::onModelChanged);
|
||||
connect(this, &JSON::Editor::frameEndSequenceChanged,
|
||||
this, &JSON::Editor::onModelChanged);
|
||||
connect(this, &JSON::Editor::frameStartSequenceChanged,
|
||||
this, &JSON::Editor::onModelChanged);
|
||||
|
||||
// Load current JSON map file into C++ model
|
||||
const auto generator = Generator::getInstance();
|
||||
connect(generator, &Generator::jsonFileMapChanged, this, &Editor::onJsonLoaded);
|
||||
}
|
||||
connect(&Generator::instance(), &Generator::jsonFileMapChanged,
|
||||
this, &JSON::Editor::onJsonLoaded);
|
||||
|
||||
Editor::~Editor() { }
|
||||
// clang-format on
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a pointer to the only instance of the editor class.
|
||||
*/
|
||||
Editor *Editor::getInstance()
|
||||
JSON::Editor &JSON::Editor::instance()
|
||||
{
|
||||
if (!EDITOR)
|
||||
EDITOR = new Editor();
|
||||
|
||||
return EDITOR;
|
||||
static auto singleton = new Editor();
|
||||
return *singleton;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------------------
|
||||
@ -92,7 +96,7 @@ Editor *Editor::getInstance()
|
||||
* interface to allow the user to build accelerometer, gyro & map widgets directly from
|
||||
* the UI.
|
||||
*/
|
||||
StringList Editor::availableGroupLevelWidgets()
|
||||
StringList JSON::Editor::availableGroupLevelWidgets()
|
||||
{
|
||||
return StringList { tr("Dataset widgets"), tr("Accelerometer"), tr("Gyroscope"),
|
||||
tr("GPS"), tr("Multiple data plot") };
|
||||
@ -102,7 +106,7 @@ StringList Editor::availableGroupLevelWidgets()
|
||||
* Returns a list with the available dataset-level widgets. This list is used by the user
|
||||
* interface to allow the user to build gauge, bar & compass widgets directly from the UI.
|
||||
*/
|
||||
StringList Editor::availableDatasetLevelWidgets()
|
||||
StringList JSON::Editor::availableDatasetLevelWidgets()
|
||||
{
|
||||
return StringList { tr("None"), tr("Gauge"), tr("Bar/level"), tr("Compass") };
|
||||
}
|
||||
@ -110,7 +114,7 @@ StringList Editor::availableDatasetLevelWidgets()
|
||||
/**
|
||||
* Returns the default path for saving JSON project files
|
||||
*/
|
||||
QString Editor::jsonProjectsPath() const
|
||||
QString JSON::Editor::jsonProjectsPath() const
|
||||
{
|
||||
// Get file name and path
|
||||
QString path = QString("%1/Documents/%2/JSON Projects/")
|
||||
@ -127,7 +131,7 @@ QString Editor::jsonProjectsPath() const
|
||||
/**
|
||||
* Returns the title of the current project
|
||||
*/
|
||||
QString Editor::title() const
|
||||
QString JSON::Editor::title() const
|
||||
{
|
||||
return m_title;
|
||||
}
|
||||
@ -135,7 +139,7 @@ QString Editor::title() const
|
||||
/**
|
||||
* Returns the data separator sequence for the current project.
|
||||
*/
|
||||
QString Editor::separator() const
|
||||
QString JSON::Editor::separator() const
|
||||
{
|
||||
return m_separator;
|
||||
}
|
||||
@ -143,7 +147,7 @@ QString Editor::separator() const
|
||||
/**
|
||||
* Returns the frame end sequence for the current project.
|
||||
*/
|
||||
QString Editor::frameEndSequence() const
|
||||
QString JSON::Editor::frameEndSequence() const
|
||||
{
|
||||
return m_frameEndSequence;
|
||||
}
|
||||
@ -151,7 +155,7 @@ QString Editor::frameEndSequence() const
|
||||
/**
|
||||
* Returns the frame start sequence for the current project.
|
||||
*/
|
||||
QString Editor::frameStartSequence() const
|
||||
QString JSON::Editor::frameStartSequence() const
|
||||
{
|
||||
return m_frameStartSequence;
|
||||
}
|
||||
@ -161,7 +165,7 @@ QString Editor::frameStartSequence() const
|
||||
* used to know if Serial Studio shall prompt the user to save his/her
|
||||
* modifications before closing the editor window.
|
||||
*/
|
||||
bool Editor::modified() const
|
||||
bool JSON::Editor::modified() const
|
||||
{
|
||||
return m_modified;
|
||||
}
|
||||
@ -169,7 +173,7 @@ bool Editor::modified() const
|
||||
/**
|
||||
* Returns the number of groups contained in the current JSON project.
|
||||
*/
|
||||
int Editor::groupCount() const
|
||||
int JSON::Editor::groupCount() const
|
||||
{
|
||||
return m_groups.count();
|
||||
}
|
||||
@ -177,7 +181,7 @@ int Editor::groupCount() const
|
||||
/**
|
||||
* Returns the full path of the current JSON project file.
|
||||
*/
|
||||
QString Editor::jsonFilePath() const
|
||||
QString JSON::Editor::jsonFilePath() const
|
||||
{
|
||||
return m_filePath;
|
||||
}
|
||||
@ -186,7 +190,7 @@ QString Editor::jsonFilePath() const
|
||||
* Returns the simplified file name of the current JSON project file.
|
||||
* This is used to change the title of the Editor window.
|
||||
*/
|
||||
QString Editor::jsonFileName() const
|
||||
QString JSON::Editor::jsonFileName() const
|
||||
{
|
||||
if (!jsonFilePath().isEmpty())
|
||||
{
|
||||
@ -201,7 +205,7 @@ QString Editor::jsonFileName() const
|
||||
* Checks if the current project has been modified and prompts the
|
||||
* user to save his/her changes.
|
||||
*/
|
||||
bool Editor::askSave()
|
||||
bool JSON::Editor::askSave()
|
||||
{
|
||||
if (!modified())
|
||||
return true;
|
||||
@ -224,7 +228,7 @@ bool Editor::askSave()
|
||||
* Validates the configuration of the current JSON project and saves the JSON
|
||||
* document on the hard disk.
|
||||
*/
|
||||
bool Editor::saveJsonFile()
|
||||
bool JSON::Editor::saveJsonFile()
|
||||
{
|
||||
// Validate project title
|
||||
if (title().isEmpty())
|
||||
@ -354,14 +358,14 @@ bool Editor::saveJsonFile()
|
||||
|
||||
// Load JSON file to Serial Studio
|
||||
openJsonFile(file.fileName());
|
||||
Generator::getInstance()->loadJsonMap(file.fileName());
|
||||
Generator::instance().loadJsonMap(file.fileName());
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the number of datasets contained by the given @a group index.
|
||||
*/
|
||||
int Editor::datasetCount(const int group) const
|
||||
int JSON::Editor::datasetCount(const int group) const
|
||||
{
|
||||
if (group < groupCount())
|
||||
return m_groups.at(group)->m_datasets.count();
|
||||
@ -372,7 +376,7 @@ int Editor::datasetCount(const int group) const
|
||||
/**
|
||||
* Returns a pointer to the group object positioned at the given @a index
|
||||
*/
|
||||
JSON::Group *Editor::getGroup(const int index) const
|
||||
JSON::Group *JSON::Editor::getGroup(const int index) const
|
||||
{
|
||||
if (index < groupCount())
|
||||
return m_groups.at(index);
|
||||
@ -384,7 +388,7 @@ JSON::Group *Editor::getGroup(const int index) const
|
||||
* Returns a pointer to the dataset object contained by the @a group at
|
||||
* the given @a index
|
||||
*/
|
||||
JSON::Dataset *Editor::getDataset(const int group, const int index) const
|
||||
JSON::Dataset *JSON::Editor::getDataset(const int group, const int index) const
|
||||
{
|
||||
if (index < datasetCount(group))
|
||||
return getGroup(group)->m_datasets.at(index);
|
||||
@ -395,7 +399,7 @@ JSON::Dataset *Editor::getDataset(const int group, const int index) const
|
||||
/**
|
||||
* Returns the title of the given @a group.
|
||||
*/
|
||||
QString Editor::groupTitle(const int group) const
|
||||
QString JSON::Editor::groupTitle(const int group) const
|
||||
{
|
||||
const auto grp = getGroup(group);
|
||||
if (grp)
|
||||
@ -407,7 +411,7 @@ QString Editor::groupTitle(const int group) const
|
||||
/**
|
||||
* Returns the widget of the given @a group.
|
||||
*/
|
||||
QString Editor::groupWidget(const int group) const
|
||||
QString JSON::Editor::groupWidget(const int group) const
|
||||
{
|
||||
const auto grp = getGroup(group);
|
||||
if (grp)
|
||||
@ -422,7 +426,7 @@ QString Editor::groupWidget(const int group) const
|
||||
* and the order of the widgets returned by the @c availableGroupLevelWidgets()
|
||||
* function.
|
||||
*/
|
||||
int Editor::groupWidgetIndex(const int group) const
|
||||
int JSON::Editor::groupWidgetIndex(const int group) const
|
||||
{
|
||||
const auto grp = getGroup(group);
|
||||
if (grp)
|
||||
@ -452,7 +456,7 @@ int Editor::groupWidgetIndex(const int group) const
|
||||
* @param group index of the group in which the dataset belongs
|
||||
* @param dataset index of the dataset
|
||||
*/
|
||||
int Editor::datasetIndex(const int group, const int dataset) const
|
||||
int JSON::Editor::datasetIndex(const int group, const int dataset) const
|
||||
{
|
||||
const auto set = getDataset(group, dataset);
|
||||
if (set)
|
||||
@ -468,7 +472,7 @@ int Editor::datasetIndex(const int group, const int dataset) const
|
||||
* @param group index of the group in which the dataset belongs
|
||||
* @param dataset index of the dataset
|
||||
*/
|
||||
bool Editor::datasetLED(const int group, const int dataset) const
|
||||
bool JSON::Editor::datasetLED(const int group, const int dataset) const
|
||||
{
|
||||
const auto set = getDataset(group, dataset);
|
||||
if (set)
|
||||
@ -484,7 +488,7 @@ bool Editor::datasetLED(const int group, const int dataset) const
|
||||
* @param group index of the group in which the dataset belongs
|
||||
* @param dataset index of the dataset
|
||||
*/
|
||||
bool Editor::datasetGraph(const int group, const int dataset) const
|
||||
bool JSON::Editor::datasetGraph(const int group, const int dataset) const
|
||||
{
|
||||
const auto set = getDataset(group, dataset);
|
||||
if (set)
|
||||
@ -500,7 +504,7 @@ bool Editor::datasetGraph(const int group, const int dataset) const
|
||||
* @param group index of the group in which the dataset belongs
|
||||
* @param dataset index of the dataset
|
||||
*/
|
||||
bool Editor::datasetFftPlot(const int group, const int dataset) const
|
||||
bool JSON::Editor::datasetFftPlot(const int group, const int dataset) const
|
||||
{
|
||||
const auto set = getDataset(group, dataset);
|
||||
if (set)
|
||||
@ -517,7 +521,7 @@ bool Editor::datasetFftPlot(const int group, const int dataset) const
|
||||
* @param group index of the group in which the dataset belongs
|
||||
* @param dataset index of the dataset
|
||||
*/
|
||||
bool Editor::datasetLogPlot(const int group, const int dataset) const
|
||||
bool JSON::Editor::datasetLogPlot(const int group, const int dataset) const
|
||||
{
|
||||
const auto set = getDataset(group, dataset);
|
||||
if (set)
|
||||
@ -532,7 +536,7 @@ bool Editor::datasetLogPlot(const int group, const int dataset) const
|
||||
* @param group index of the group in which the dataset belongs
|
||||
* @param dataset index of the dataset
|
||||
*/
|
||||
QString Editor::datasetTitle(const int group, const int dataset) const
|
||||
QString JSON::Editor::datasetTitle(const int group, const int dataset) const
|
||||
{
|
||||
const auto set = getDataset(group, dataset);
|
||||
if (set)
|
||||
@ -547,7 +551,7 @@ QString Editor::datasetTitle(const int group, const int dataset) const
|
||||
* @param group index of the group in which the dataset belongs
|
||||
* @param dataset index of the dataset
|
||||
*/
|
||||
QString Editor::datasetUnits(const int group, const int dataset) const
|
||||
QString JSON::Editor::datasetUnits(const int group, const int dataset) const
|
||||
{
|
||||
const auto set = getDataset(group, dataset);
|
||||
if (set)
|
||||
@ -562,7 +566,7 @@ QString Editor::datasetUnits(const int group, const int dataset) const
|
||||
* @param group index of the group in which the dataset belongs
|
||||
* @param dataset index of the dataset
|
||||
*/
|
||||
QString Editor::datasetWidget(const int group, const int dataset) const
|
||||
QString JSON::Editor::datasetWidget(const int group, const int dataset) const
|
||||
{
|
||||
const auto set = getDataset(group, dataset);
|
||||
if (set)
|
||||
@ -579,7 +583,7 @@ QString Editor::datasetWidget(const int group, const int dataset) const
|
||||
* @param group index of the group in which the dataset belongs
|
||||
* @param dataset index of the dataset
|
||||
*/
|
||||
int Editor::datasetWidgetIndex(const int group, const int dataset) const
|
||||
int JSON::Editor::datasetWidgetIndex(const int group, const int dataset) const
|
||||
{
|
||||
const auto widget = datasetWidget(group, dataset);
|
||||
if (widget == "gauge")
|
||||
@ -599,7 +603,7 @@ int Editor::datasetWidgetIndex(const int group, const int dataset) const
|
||||
* @param group index of the group in which the dataset belongs
|
||||
* @param dataset index of the dataset
|
||||
*/
|
||||
QString Editor::datasetWidgetMin(const int group, const int dataset) const
|
||||
QString JSON::Editor::datasetWidgetMin(const int group, const int dataset) const
|
||||
{
|
||||
const auto set = getDataset(group, dataset);
|
||||
if (set)
|
||||
@ -615,7 +619,7 @@ QString Editor::datasetWidgetMin(const int group, const int dataset) const
|
||||
* @param group index of the group in which the dataset belongs
|
||||
* @param dataset index of the dataset
|
||||
*/
|
||||
QString Editor::datasetWidgetMax(const int group, const int dataset) const
|
||||
QString JSON::Editor::datasetWidgetMax(const int group, const int dataset) const
|
||||
{
|
||||
const auto set = getDataset(group, dataset);
|
||||
if (set)
|
||||
@ -630,7 +634,7 @@ QString Editor::datasetWidgetMax(const int group, const int dataset) const
|
||||
* @param group index of the group in which the dataset belongs
|
||||
* @param dataset index of the dataset
|
||||
*/
|
||||
QString Editor::datasetFFTSamples(const int group, const int dataset) const
|
||||
QString JSON::Editor::datasetFFTSamples(const int group, const int dataset) const
|
||||
{
|
||||
const auto set = getDataset(group, dataset);
|
||||
if (set)
|
||||
@ -646,7 +650,7 @@ QString Editor::datasetFFTSamples(const int group, const int dataset) const
|
||||
* @param group index of the group in which the dataset belongs
|
||||
* @param dataset index of the dataset
|
||||
*/
|
||||
QString Editor::datasetWidgetAlarm(const int group, const int dataset) const
|
||||
QString JSON::Editor::datasetWidgetAlarm(const int group, const int dataset) const
|
||||
{
|
||||
const auto set = getDataset(group, dataset);
|
||||
if (set)
|
||||
@ -667,7 +671,7 @@ QString Editor::datasetWidgetAlarm(const int group, const int dataset) const
|
||||
/**
|
||||
* Resets the C++ model used to represent the JSON project file.
|
||||
*/
|
||||
void Editor::newJsonFile()
|
||||
void JSON::Editor::newJsonFile()
|
||||
{
|
||||
// Clear groups list
|
||||
m_groups.clear();
|
||||
@ -691,7 +695,7 @@ void Editor::newJsonFile()
|
||||
* Prompts the user to select a JSON project file & generates the appropiate C++
|
||||
* model that represents the JSON document.
|
||||
*/
|
||||
void Editor::openJsonFile()
|
||||
void JSON::Editor::openJsonFile()
|
||||
{
|
||||
// clang-format off
|
||||
auto path = QFileDialog::getOpenFileName(Q_NULLPTR,
|
||||
@ -712,7 +716,7 @@ void Editor::openJsonFile()
|
||||
* Opens the JSON document at the given @a path & generates the appropiate C++
|
||||
* model that represents the JSON document.
|
||||
*/
|
||||
void Editor::openJsonFile(const QString &path)
|
||||
void JSON::Editor::openJsonFile(const QString &path)
|
||||
{
|
||||
// Open file
|
||||
QFile file(path);
|
||||
@ -728,9 +732,8 @@ void Editor::openJsonFile(const QString &path)
|
||||
return;
|
||||
|
||||
// Let the generator use the given JSON file
|
||||
const auto generator = Generator::getInstance();
|
||||
if (generator->jsonMapFilepath() != path)
|
||||
generator->loadJsonMap(path);
|
||||
if (Generator::instance().jsonMapFilepath() != path)
|
||||
Generator::instance().loadJsonMap(path);
|
||||
|
||||
// Reset C++ model
|
||||
newJsonFile();
|
||||
@ -747,13 +750,12 @@ void Editor::openJsonFile(const QString &path)
|
||||
setFrameStartSequence(JFI_Value(json, "frameStart", "fs").toString());
|
||||
|
||||
// Modify IO manager settings
|
||||
const auto manager = IO::Manager::getInstance();
|
||||
manager->setSeparatorSequence(separator());
|
||||
manager->setFinishSequence(frameEndSequence());
|
||||
manager->setStartSequence(frameStartSequence());
|
||||
IO::Manager::instance().setSeparatorSequence(separator());
|
||||
IO::Manager::instance().setFinishSequence(frameEndSequence());
|
||||
IO::Manager::instance().setStartSequence(frameStartSequence());
|
||||
|
||||
// Set JSON::Generator operation mode to manual
|
||||
JSON::Generator::getInstance()->setOperationMode(JSON::Generator::kManual);
|
||||
JSON::Generator::instance().setOperationMode(JSON::Generator::kManual);
|
||||
|
||||
// Read groups from JSON document
|
||||
auto groups = JFI_Value(json, "groups", "g").toArray();
|
||||
@ -809,7 +811,7 @@ void Editor::openJsonFile(const QString &path)
|
||||
/**
|
||||
* Changes the title of the JSON project file.
|
||||
*/
|
||||
void Editor::setTitle(const QString &title)
|
||||
void JSON::Editor::setTitle(const QString &title)
|
||||
{
|
||||
if (title != m_title)
|
||||
{
|
||||
@ -821,7 +823,7 @@ void Editor::setTitle(const QString &title)
|
||||
/**
|
||||
* Changes the data separator sequence of the JSON project file.
|
||||
*/
|
||||
void Editor::setSeparator(const QString &separator)
|
||||
void JSON::Editor::setSeparator(const QString &separator)
|
||||
{
|
||||
if (separator != m_separator)
|
||||
{
|
||||
@ -833,7 +835,7 @@ void Editor::setSeparator(const QString &separator)
|
||||
/**
|
||||
* Changes the frame end sequence of the JSON project file.
|
||||
*/
|
||||
void Editor::setFrameEndSequence(const QString &sequence)
|
||||
void JSON::Editor::setFrameEndSequence(const QString &sequence)
|
||||
{
|
||||
if (sequence != m_frameEndSequence)
|
||||
{
|
||||
@ -845,7 +847,7 @@ void Editor::setFrameEndSequence(const QString &sequence)
|
||||
/**
|
||||
* Changes the frame start sequence of the JSON project file.
|
||||
*/
|
||||
void Editor::setFrameStartSequence(const QString &sequence)
|
||||
void JSON::Editor::setFrameStartSequence(const QString &sequence)
|
||||
{
|
||||
if (sequence != m_frameStartSequence)
|
||||
{
|
||||
@ -857,7 +859,7 @@ void Editor::setFrameStartSequence(const QString &sequence)
|
||||
/**
|
||||
* Adds a new group to the C++ model that represents the JSON project file.
|
||||
*/
|
||||
void Editor::addGroup()
|
||||
void JSON::Editor::addGroup()
|
||||
{
|
||||
m_groups.append(new Group);
|
||||
setGroupTitle(m_groups.count() - 1, tr("New Group"));
|
||||
@ -869,7 +871,7 @@ void Editor::addGroup()
|
||||
* Removes the given @a group from the C++ model that represents the JSON
|
||||
* project file.
|
||||
*/
|
||||
void Editor::deleteGroup(const int group)
|
||||
void JSON::Editor::deleteGroup(const int group)
|
||||
{
|
||||
const auto grp = getGroup(group);
|
||||
if (grp)
|
||||
@ -889,7 +891,7 @@ void Editor::deleteGroup(const int group)
|
||||
/**
|
||||
* Changes the position of the given @a group in the C++ model.
|
||||
*/
|
||||
void Editor::moveGroupUp(const int group)
|
||||
void JSON::Editor::moveGroupUp(const int group)
|
||||
{
|
||||
if (group > 0)
|
||||
{
|
||||
@ -901,7 +903,7 @@ void Editor::moveGroupUp(const int group)
|
||||
/**
|
||||
* Changes the position of the given @a group in the C++ model.
|
||||
*/
|
||||
void Editor::moveGroupDown(const int group)
|
||||
void JSON::Editor::moveGroupDown(const int group)
|
||||
{
|
||||
if (group < groupCount() - 1)
|
||||
{
|
||||
@ -915,7 +917,7 @@ void Editor::moveGroupDown(const int group)
|
||||
* If necessary, this function shall generate the appropiate datasets
|
||||
* needed to implement the widget (e.g. x,y,z for accelerometer widgets).
|
||||
*/
|
||||
bool Editor::setGroupWidget(const int group, const int widgetId)
|
||||
bool JSON::Editor::setGroupWidget(const int group, const int widgetId)
|
||||
{
|
||||
auto grp = getGroup(group);
|
||||
if (grp)
|
||||
@ -1062,7 +1064,7 @@ bool Editor::setGroupWidget(const int group, const int widgetId)
|
||||
/**
|
||||
* Changes the @a title for the given @a group in the C++ model
|
||||
*/
|
||||
void Editor::setGroupTitle(const int group, const QString &title)
|
||||
void JSON::Editor::setGroupTitle(const int group, const QString &title)
|
||||
{
|
||||
auto grp = getGroup(group);
|
||||
if (grp)
|
||||
@ -1075,7 +1077,7 @@ void Editor::setGroupTitle(const int group, const QString &title)
|
||||
/**
|
||||
* Changes the @a widget for the given @a group in the C++ model
|
||||
*/
|
||||
void Editor::setGroupWidgetData(const int group, const QString &widget)
|
||||
void JSON::Editor::setGroupWidgetData(const int group, const QString &widget)
|
||||
{
|
||||
auto grp = getGroup(group);
|
||||
if (grp)
|
||||
@ -1090,7 +1092,7 @@ void Editor::setGroupWidgetData(const int group, const QString &widget)
|
||||
* index counter (to avoid having datasets that pull data from the
|
||||
* same position in the MCU frame).
|
||||
*/
|
||||
void Editor::addDataset(const int group)
|
||||
void JSON::Editor::addDataset(const int group)
|
||||
{
|
||||
auto grp = getGroup(group);
|
||||
if (grp)
|
||||
@ -1108,7 +1110,7 @@ void Editor::addDataset(const int group)
|
||||
* @param group index of the group in which the dataset belongs
|
||||
* @param dataset index of the dataset
|
||||
*/
|
||||
void Editor::deleteDataset(const int group, const int dataset)
|
||||
void JSON::Editor::deleteDataset(const int group, const int dataset)
|
||||
{
|
||||
const auto set = getDataset(group, dataset);
|
||||
if (set)
|
||||
@ -1131,7 +1133,8 @@ void Editor::deleteDataset(const int group, const int dataset)
|
||||
* @param group index of the group in which the dataset belongs
|
||||
* @param dataset index of the dataset
|
||||
*/
|
||||
void Editor::setDatasetTitle(const int group, const int dataset, const QString &title)
|
||||
void JSON::Editor::setDatasetTitle(const int group, const int dataset,
|
||||
const QString &title)
|
||||
{
|
||||
auto set = getDataset(group, dataset);
|
||||
if (set)
|
||||
@ -1147,7 +1150,8 @@ void Editor::setDatasetTitle(const int group, const int dataset, const QString &
|
||||
* @param group index of the group in which the dataset belongs
|
||||
* @param dataset index of the dataset
|
||||
*/
|
||||
void Editor::setDatasetUnits(const int group, const int dataset, const QString &units)
|
||||
void JSON::Editor::setDatasetUnits(const int group, const int dataset,
|
||||
const QString &units)
|
||||
{
|
||||
auto set = getDataset(group, dataset);
|
||||
if (set)
|
||||
@ -1163,7 +1167,8 @@ void Editor::setDatasetUnits(const int group, const int dataset, const QString &
|
||||
* @param group index of the group in which the dataset belongs
|
||||
* @param dataset index of the dataset
|
||||
*/
|
||||
void Editor::setDatasetIndex(const int group, const int dataset, const int frameIndex)
|
||||
void JSON::Editor::setDatasetIndex(const int group, const int dataset,
|
||||
const int frameIndex)
|
||||
{
|
||||
auto set = getDataset(group, dataset);
|
||||
if (set)
|
||||
@ -1179,7 +1184,8 @@ void Editor::setDatasetIndex(const int group, const int dataset, const int frame
|
||||
* @param group index of the group in which the dataset belongs
|
||||
* @param dataset index of the dataset
|
||||
*/
|
||||
void Editor::setDatasetLED(const int group, const int dataset, const bool generateLED)
|
||||
void JSON::Editor::setDatasetLED(const int group, const int dataset,
|
||||
const bool generateLED)
|
||||
{
|
||||
auto set = getDataset(group, dataset);
|
||||
if (set)
|
||||
@ -1195,7 +1201,8 @@ void Editor::setDatasetLED(const int group, const int dataset, const bool genera
|
||||
* @param group index of the group in which the dataset belongs
|
||||
* @param dataset index of the dataset
|
||||
*/
|
||||
void Editor::setDatasetGraph(const int group, const int dataset, const bool generateGraph)
|
||||
void JSON::Editor::setDatasetGraph(const int group, const int dataset,
|
||||
const bool generateGraph)
|
||||
{
|
||||
auto set = getDataset(group, dataset);
|
||||
if (set)
|
||||
@ -1211,7 +1218,8 @@ void Editor::setDatasetGraph(const int group, const int dataset, const bool gene
|
||||
* @param group index of the group in which the dataset belongs
|
||||
* @param dataset index of the dataset
|
||||
*/
|
||||
void Editor::setDatasetFftPlot(const int group, const int dataset, const bool generateFft)
|
||||
void JSON::Editor::setDatasetFftPlot(const int group, const int dataset,
|
||||
const bool generateFft)
|
||||
{
|
||||
auto set = getDataset(group, dataset);
|
||||
if (set)
|
||||
@ -1227,7 +1235,8 @@ void Editor::setDatasetFftPlot(const int group, const int dataset, const bool ge
|
||||
* @param group index of the group in which the dataset belongs
|
||||
* @param dataset index of the dataset
|
||||
*/
|
||||
void Editor::setDatasetLogPlot(const int group, const int dataset, const bool generateLog)
|
||||
void JSON::Editor::setDatasetLogPlot(const int group, const int dataset,
|
||||
const bool generateLog)
|
||||
{
|
||||
auto set = getDataset(group, dataset);
|
||||
if (set)
|
||||
@ -1244,7 +1253,8 @@ void Editor::setDatasetLogPlot(const int group, const int dataset, const bool ge
|
||||
* @param group index of the group in which the dataset belongs
|
||||
* @param dataset index of the dataset
|
||||
*/
|
||||
void Editor::setDatasetWidget(const int group, const int dataset, const int widgetId)
|
||||
void JSON::Editor::setDatasetWidget(const int group, const int dataset,
|
||||
const int widgetId)
|
||||
{
|
||||
auto set = getDataset(group, dataset);
|
||||
if (set)
|
||||
@ -1274,8 +1284,8 @@ void Editor::setDatasetWidget(const int group, const int dataset, const int widg
|
||||
* @param group index of the group in which the dataset belongs
|
||||
* @param dataset index of the dataset
|
||||
*/
|
||||
void Editor::setDatasetWidgetMin(const int group, const int dataset,
|
||||
const QString &minimum)
|
||||
void JSON::Editor::setDatasetWidgetMin(const int group, const int dataset,
|
||||
const QString &minimum)
|
||||
{
|
||||
auto set = getDataset(group, dataset);
|
||||
if (set)
|
||||
@ -1293,8 +1303,8 @@ void Editor::setDatasetWidgetMin(const int group, const int dataset,
|
||||
* @param group index of the group in which the dataset belongs
|
||||
* @param dataset index of the dataset
|
||||
*/
|
||||
void Editor::setDatasetWidgetMax(const int group, const int dataset,
|
||||
const QString &maximum)
|
||||
void JSON::Editor::setDatasetWidgetMax(const int group, const int dataset,
|
||||
const QString &maximum)
|
||||
{
|
||||
auto set = getDataset(group, dataset);
|
||||
if (set)
|
||||
@ -1310,8 +1320,8 @@ void Editor::setDatasetWidgetMax(const int group, const int dataset,
|
||||
* @param group index of the group in which the dataset belongs
|
||||
* @param dataset index of the dataset
|
||||
*/
|
||||
void Editor::setDatasetWidgetData(const int group, const int dataset,
|
||||
const QString &widget)
|
||||
void JSON::Editor::setDatasetWidgetData(const int group, const int dataset,
|
||||
const QString &widget)
|
||||
{
|
||||
auto set = getDataset(group, dataset);
|
||||
if (set)
|
||||
@ -1329,8 +1339,8 @@ void Editor::setDatasetWidgetData(const int group, const int dataset,
|
||||
* @param group index of the group in which the dataset belongs
|
||||
* @param dataset index of the dataset
|
||||
*/
|
||||
void Editor::setDatasetWidgetAlarm(const int group, const int dataset,
|
||||
const QString &alarm)
|
||||
void JSON::Editor::setDatasetWidgetAlarm(const int group, const int dataset,
|
||||
const QString &alarm)
|
||||
{
|
||||
auto set = getDataset(group, dataset);
|
||||
if (set)
|
||||
@ -1346,8 +1356,8 @@ void Editor::setDatasetWidgetAlarm(const int group, const int dataset,
|
||||
* @param group index of the group in which the dataset belongs
|
||||
* @param dataset index of the dataset
|
||||
*/
|
||||
void Editor::setDatasetFFTSamples(const int group, const int dataset,
|
||||
const QString &samples)
|
||||
void JSON::Editor::setDatasetFFTSamples(const int group, const int dataset,
|
||||
const QString &samples)
|
||||
{
|
||||
auto set = getDataset(group, dataset);
|
||||
if (set)
|
||||
@ -1366,7 +1376,7 @@ void Editor::setDatasetFFTSamples(const int group, const int dataset,
|
||||
* This flag is used to know if we should ask the user to save
|
||||
* his/her modifications to the project file.
|
||||
*/
|
||||
void Editor::setModified(const bool modified)
|
||||
void JSON::Editor::setModified(const bool modified)
|
||||
{
|
||||
m_modified = modified;
|
||||
Q_EMIT modifiedChanged();
|
||||
@ -1376,17 +1386,17 @@ void Editor::setModified(const bool modified)
|
||||
* Ensures that the JSON project file is the same as the one used by
|
||||
* the JSON Generator class.
|
||||
*/
|
||||
void Editor::onJsonLoaded()
|
||||
void JSON::Editor::onJsonLoaded()
|
||||
{
|
||||
if (jsonFilePath() != Generator::getInstance()->jsonMapFilepath())
|
||||
openJsonFile(Generator::getInstance()->jsonMapFilepath());
|
||||
if (jsonFilePath() != Generator::instance().jsonMapFilepath())
|
||||
openJsonFile(Generator::instance().jsonMapFilepath());
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the modified flag to @c true when the user adds/removes/moves
|
||||
* one of the groups contained in the JSON project.
|
||||
*/
|
||||
void Editor::onModelChanged()
|
||||
void JSON::Editor::onModelChanged()
|
||||
{
|
||||
setModified(true);
|
||||
}
|
||||
@ -1395,7 +1405,7 @@ void Editor::onModelChanged()
|
||||
* Sets the modified flag to @c true when the user changes the title
|
||||
* or the widget of one of the groups contained in the JSON project.
|
||||
*/
|
||||
void Editor::onGroupChanged(const int group)
|
||||
void JSON::Editor::onGroupChanged(const int group)
|
||||
{
|
||||
(void)group;
|
||||
setModified(true);
|
||||
@ -1408,7 +1418,7 @@ void Editor::onGroupChanged(const int group)
|
||||
* @param group index of the group in which the dataset belongs
|
||||
* @param dataset index of the dataset
|
||||
*/
|
||||
void Editor::onDatasetChanged(const int group, const int dataset)
|
||||
void JSON::Editor::onDatasetChanged(const int group, const int dataset)
|
||||
{
|
||||
(void)group;
|
||||
(void)dataset;
|
||||
@ -1422,7 +1432,7 @@ void Editor::onDatasetChanged(const int group, const int dataset)
|
||||
* This function is used when registering new datasets, so that
|
||||
* the user does not need to manually specify dataset indexes.
|
||||
*/
|
||||
int Editor::nextDatasetIndex()
|
||||
int JSON::Editor::nextDatasetIndex()
|
||||
{
|
||||
int maxIndex = 1;
|
||||
for (int i = 0; i < groupCount(); ++i)
|
||||
@ -1440,4 +1450,3 @@ int Editor::nextDatasetIndex()
|
||||
|
||||
return maxIndex;
|
||||
}
|
||||
}
|
||||
|
@ -85,8 +85,15 @@ Q_SIGNALS:
|
||||
void groupChanged(const int group);
|
||||
void datasetChanged(const int group, const int dataset);
|
||||
|
||||
private:
|
||||
explicit Editor();
|
||||
Editor(Editor &&) = delete;
|
||||
Editor(const Editor &) = delete;
|
||||
Editor &operator=(Editor &&) = delete;
|
||||
Editor &operator=(const Editor &) = delete;
|
||||
|
||||
public:
|
||||
static Editor *getInstance();
|
||||
static Editor &instance();
|
||||
|
||||
Q_INVOKABLE StringList availableGroupLevelWidgets();
|
||||
Q_INVOKABLE StringList availableDatasetLevelWidgets();
|
||||
@ -170,9 +177,6 @@ private Q_SLOTS:
|
||||
void onDatasetChanged(const int group, const int dataset);
|
||||
|
||||
private:
|
||||
Editor();
|
||||
~Editor();
|
||||
|
||||
int nextDatasetIndex();
|
||||
|
||||
private:
|
||||
|
@ -23,32 +23,21 @@
|
||||
#include "Frame.h"
|
||||
#include "FrameInfo.h"
|
||||
|
||||
namespace JSON
|
||||
{
|
||||
|
||||
/**
|
||||
* Constructor function
|
||||
*/
|
||||
Frame::Frame(QObject *parent)
|
||||
: QObject(parent)
|
||||
, m_title("")
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Destructor function, free memory used by the @c Group objects before destroying an
|
||||
* instance of this class.
|
||||
*/
|
||||
Frame::~Frame()
|
||||
JSON::Frame::~Frame()
|
||||
{
|
||||
clear();
|
||||
qDeleteAll(m_groups);
|
||||
m_groups.clear();
|
||||
}
|
||||
|
||||
/**
|
||||
* Resets the frame title and frees the memory used by the @c Group objects associated
|
||||
* to the instance of the @c Frame object.
|
||||
*/
|
||||
void Frame::clear()
|
||||
void JSON::Frame::clear()
|
||||
{
|
||||
m_title = "";
|
||||
qDeleteAll(m_groups);
|
||||
@ -58,7 +47,7 @@ void Frame::clear()
|
||||
/**
|
||||
* Returns the title of the frame.
|
||||
*/
|
||||
QString Frame::title() const
|
||||
QString JSON::Frame::title() const
|
||||
{
|
||||
return m_title;
|
||||
}
|
||||
@ -66,7 +55,7 @@ QString Frame::title() const
|
||||
/**
|
||||
* Returns the number of groups contained in the frame.
|
||||
*/
|
||||
int Frame::groupCount() const
|
||||
int JSON::Frame::groupCount() const
|
||||
{
|
||||
return m_groups.count();
|
||||
}
|
||||
@ -74,7 +63,7 @@ int Frame::groupCount() const
|
||||
/**
|
||||
* Returns a vector of pointers to the @c Group objects associated to this frame.
|
||||
*/
|
||||
QVector<Group *> Frame::groups() const
|
||||
QVector<JSON::Group *> JSON::Frame::groups() const
|
||||
{
|
||||
return m_groups;
|
||||
}
|
||||
@ -85,7 +74,7 @@ QVector<Group *> Frame::groups() const
|
||||
*
|
||||
* @return @c true on success, @c false on failure
|
||||
*/
|
||||
bool Frame::read(const QJsonObject &object)
|
||||
bool JSON::Frame::read(const QJsonObject &object)
|
||||
{
|
||||
// Rest frame data
|
||||
clear();
|
||||
@ -103,7 +92,7 @@ bool Frame::read(const QJsonObject &object)
|
||||
// Generate groups & datasets from data frame
|
||||
for (auto i = 0; i < groups.count(); ++i)
|
||||
{
|
||||
Group *group = new Group(this);
|
||||
Group *group = new Group();
|
||||
if (group->read(groups.at(i).toObject()))
|
||||
m_groups.append(group);
|
||||
else
|
||||
@ -122,11 +111,10 @@ bool Frame::read(const QJsonObject &object)
|
||||
/**
|
||||
* @return The group at the given @a index,vreturns @c Q_NULLPTR on invalid index
|
||||
*/
|
||||
JSON::Group *Frame::getGroup(const int index)
|
||||
JSON::Group *JSON::Frame::getGroup(const int index)
|
||||
{
|
||||
if (index < groupCount() && index >= 0)
|
||||
return m_groups.at(index);
|
||||
|
||||
return Q_NULLPTR;
|
||||
}
|
||||
}
|
||||
|
@ -52,10 +52,9 @@ namespace JSON
|
||||
* frame.
|
||||
* 9) UI dashboard updates the widgets with the C++ model provided by this class.
|
||||
*/
|
||||
class Frame : public QObject
|
||||
class Frame
|
||||
{
|
||||
public:
|
||||
Frame(QObject *parent = nullptr);
|
||||
~Frame();
|
||||
|
||||
void clear();
|
||||
|
@ -33,20 +33,16 @@
|
||||
#include <QFileDialog>
|
||||
#include <QRegularExpression>
|
||||
|
||||
namespace JSON
|
||||
{
|
||||
static Generator *GENERATOR = Q_NULLPTR;
|
||||
|
||||
/**
|
||||
* Initializes the JSON Parser class and connects appropiate SIGNALS/SLOTS
|
||||
*/
|
||||
Generator::Generator()
|
||||
JSON::Generator::Generator()
|
||||
: m_frameCount(0)
|
||||
, m_opMode(kAutomatic)
|
||||
, m_processInSeparateThread(false)
|
||||
{
|
||||
const auto io = IO::Manager::getInstance();
|
||||
const auto cp = CSV::Player::getInstance();
|
||||
const auto io = &IO::Manager::instance();
|
||||
const auto cp = &CSV::Player::instance();
|
||||
connect(cp, SIGNAL(openChanged()), this, SLOT(reset()));
|
||||
connect(io, SIGNAL(deviceChanged()), this, SLOT(reset()));
|
||||
connect(io, SIGNAL(frameReceived(QByteArray)), this, SLOT(readData(QByteArray)));
|
||||
@ -57,18 +53,16 @@ Generator::Generator()
|
||||
/**
|
||||
* Returns the only instance of the class
|
||||
*/
|
||||
Generator *Generator::getInstance()
|
||||
JSON::Generator &JSON::Generator::instance()
|
||||
{
|
||||
if (!GENERATOR)
|
||||
GENERATOR = new Generator();
|
||||
|
||||
return GENERATOR;
|
||||
static auto singleton = new Generator();
|
||||
return *singleton;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the JSON map data from the loaded file as a string
|
||||
*/
|
||||
QString Generator::jsonMapData() const
|
||||
QString JSON::Generator::jsonMapData() const
|
||||
{
|
||||
return m_jsonMapData;
|
||||
}
|
||||
@ -76,7 +70,7 @@ QString Generator::jsonMapData() const
|
||||
/**
|
||||
* Returns the file name (e.g. "JsonMap.json") of the loaded JSON map file
|
||||
*/
|
||||
QString Generator::jsonMapFilename() const
|
||||
QString JSON::Generator::jsonMapFilename() const
|
||||
{
|
||||
if (m_jsonMap.isOpen())
|
||||
{
|
||||
@ -90,7 +84,7 @@ QString Generator::jsonMapFilename() const
|
||||
/**
|
||||
* Returns the file path of the loaded JSON map file
|
||||
*/
|
||||
QString Generator::jsonMapFilepath() const
|
||||
QString JSON::Generator::jsonMapFilepath() const
|
||||
{
|
||||
if (m_jsonMap.isOpen())
|
||||
{
|
||||
@ -104,7 +98,7 @@ QString Generator::jsonMapFilepath() const
|
||||
/**
|
||||
* Returns the operation mode
|
||||
*/
|
||||
Generator::OperationMode Generator::operationMode() const
|
||||
JSON::Generator::OperationMode JSON::Generator::operationMode() const
|
||||
{
|
||||
return m_opMode;
|
||||
}
|
||||
@ -112,7 +106,7 @@ Generator::OperationMode Generator::operationMode() const
|
||||
/**
|
||||
* Returns @c true if JSON frames shall be generated in a separate thread
|
||||
*/
|
||||
bool Generator::processFramesInSeparateThread() const
|
||||
bool JSON::Generator::processFramesInSeparateThread() const
|
||||
{
|
||||
return m_processInSeparateThread;
|
||||
}
|
||||
@ -120,12 +114,12 @@ bool Generator::processFramesInSeparateThread() const
|
||||
/**
|
||||
* Creates a file dialog & lets the user select the JSON file map
|
||||
*/
|
||||
void Generator::loadJsonMap()
|
||||
void JSON::Generator::loadJsonMap()
|
||||
{
|
||||
// clang-format off
|
||||
auto file = QFileDialog::getOpenFileName(Q_NULLPTR,
|
||||
tr("Select JSON map file"),
|
||||
Editor::getInstance()->jsonProjectsPath(),
|
||||
Editor::instance().jsonProjectsPath(),
|
||||
tr("JSON files") + " (*.json)");
|
||||
// clang-format on
|
||||
|
||||
@ -136,7 +130,7 @@ void Generator::loadJsonMap()
|
||||
/**
|
||||
* Opens, validates & loads into memory the JSON file in the given @a path.
|
||||
*/
|
||||
void Generator::loadJsonMap(const QString &path)
|
||||
void JSON::Generator::loadJsonMap(const QString &path)
|
||||
{
|
||||
// Validate path
|
||||
if (path.isEmpty())
|
||||
@ -203,7 +197,7 @@ void Generator::loadJsonMap(const QString &path)
|
||||
* @c kAutomatic serial data contains the JSON data frame, good for simple
|
||||
* applications or for prototyping.
|
||||
*/
|
||||
void Generator::setOperationMode(const JSON::Generator::OperationMode &mode)
|
||||
void JSON::Generator::setOperationMode(const JSON::Generator::OperationMode &mode)
|
||||
{
|
||||
m_opMode = mode;
|
||||
Q_EMIT operationModeChanged();
|
||||
@ -212,7 +206,7 @@ void Generator::setOperationMode(const JSON::Generator::OperationMode &mode)
|
||||
/**
|
||||
* Enables or disables multi-threaded frame processing
|
||||
*/
|
||||
void Generator::setProcessFramesInSeparateThread(const bool threaded)
|
||||
void JSON::Generator::setProcessFramesInSeparateThread(const bool threaded)
|
||||
{
|
||||
m_processInSeparateThread = threaded;
|
||||
Q_EMIT processFramesInSeparateThreadChanged();
|
||||
@ -221,7 +215,7 @@ void Generator::setProcessFramesInSeparateThread(const bool threaded)
|
||||
/**
|
||||
* Loads the last saved JSON map file (if any)
|
||||
*/
|
||||
void Generator::readSettings()
|
||||
void JSON::Generator::readSettings()
|
||||
{
|
||||
auto path = m_settings.value("json_map_location", "").toString();
|
||||
if (!path.isEmpty())
|
||||
@ -234,11 +228,11 @@ void Generator::readSettings()
|
||||
*
|
||||
* Read the "FrameInfo.h" file for more information.
|
||||
*/
|
||||
void Generator::loadJFI(const JFI_Object &info)
|
||||
void JSON::Generator::loadJFI(const JFI_Object &info)
|
||||
{
|
||||
const bool csvOpen = CSV::Player::getInstance()->isOpen();
|
||||
const bool devOpen = IO::Manager::getInstance()->connected();
|
||||
const bool mqttSub = MQTT::Client::getInstance()->isSubscribed();
|
||||
const bool csvOpen = CSV::Player::instance().isOpen();
|
||||
const bool devOpen = IO::Manager::instance().connected();
|
||||
const bool mqttSub = MQTT::Client::instance().isSubscribed();
|
||||
|
||||
if (csvOpen || devOpen || mqttSub)
|
||||
Q_EMIT jsonChanged(info);
|
||||
@ -250,7 +244,7 @@ void Generator::loadJFI(const JFI_Object &info)
|
||||
/**
|
||||
* Saves the location of the last valid JSON map file that was opened (if any)
|
||||
*/
|
||||
void Generator::writeSettings(const QString &path)
|
||||
void JSON::Generator::writeSettings(const QString &path)
|
||||
{
|
||||
m_settings.setValue("json_map_location", path);
|
||||
}
|
||||
@ -258,7 +252,7 @@ void Generator::writeSettings(const QString &path)
|
||||
/**
|
||||
* Create a new JFI event with the given @a JSON document and increment the frame count
|
||||
*/
|
||||
void Generator::loadJSON(const QJsonDocument &json)
|
||||
void JSON::Generator::loadJSON(const QJsonDocument &json)
|
||||
{
|
||||
m_frameCount++;
|
||||
auto jfi = JFI_CreateNew(m_frameCount, QDateTime::currentDateTime(), json);
|
||||
@ -268,7 +262,7 @@ void Generator::loadJSON(const QJsonDocument &json)
|
||||
/**
|
||||
* Resets all the statistics related to the current device and the JSON map file
|
||||
*/
|
||||
void Generator::reset()
|
||||
void JSON::Generator::reset()
|
||||
{
|
||||
m_frameCount = 0;
|
||||
Q_EMIT jsonChanged(JFI_Empty());
|
||||
@ -287,7 +281,7 @@ void Generator::reset()
|
||||
* If JSON parsing is successfull, then the class shall notify the rest of the
|
||||
* application in order to process packet data.
|
||||
*/
|
||||
void Generator::readData(const QByteArray &data)
|
||||
void JSON::Generator::readData(const QByteArray &data)
|
||||
{
|
||||
// Data empty, abort
|
||||
if (data.isEmpty())
|
||||
@ -301,7 +295,7 @@ void Generator::readData(const QByteArray &data)
|
||||
{
|
||||
// clang-format off
|
||||
QThread *thread = new QThread;
|
||||
JSONWorker *worker = new JSONWorker(data,
|
||||
Worker *worker = new Worker(data,
|
||||
m_frameCount,
|
||||
QDateTime::currentDateTime());
|
||||
worker->moveToThread(thread);
|
||||
@ -311,7 +305,7 @@ void Generator::readData(const QByteArray &data)
|
||||
connect(worker, SIGNAL(finished()), thread, SLOT(quit()));
|
||||
connect(worker, SIGNAL(finished()), worker, SLOT(deleteLater()));
|
||||
connect(thread, SIGNAL(finished()), thread, SLOT(deleteLater()));
|
||||
connect(worker, &JSONWorker::jsonReady, this, &Generator::loadJFI);
|
||||
connect(worker, &JSON::Worker::jsonReady, this, &JSON::Generator::loadJFI);
|
||||
thread->start();
|
||||
}
|
||||
|
||||
@ -324,15 +318,15 @@ void Generator::readData(const QByteArray &data)
|
||||
* Reads the frame & inserts its values on the JSON map, and/or extracts the JSON frame
|
||||
* directly from the serial data.
|
||||
*/
|
||||
void Generator::processFrame(const QByteArray &data, const quint64 frame,
|
||||
const QDateTime &time)
|
||||
void JSON::Generator::processFrame(const QByteArray &data, const quint64 frame,
|
||||
const QDateTime &time)
|
||||
{
|
||||
// Init variables
|
||||
QJsonParseError error;
|
||||
QJsonDocument document;
|
||||
|
||||
// Serial device sends JSON (auto mode)
|
||||
if (operationMode() == Generator::kAutomatic)
|
||||
if (operationMode() == JSON::Generator::kAutomatic)
|
||||
document = QJsonDocument::fromJson(data, &error);
|
||||
|
||||
// We need to use a map file, check if its loaded & replace values into map
|
||||
@ -344,7 +338,7 @@ void Generator::processFrame(const QByteArray &data, const quint64 frame,
|
||||
|
||||
// Separate incoming data & add it to the JSON map
|
||||
auto json = jsonMapData();
|
||||
auto sepr = IO::Manager::getInstance()->separatorSequence();
|
||||
auto sepr = IO::Manager::instance().separatorSequence();
|
||||
auto list = QString::fromUtf8(data).split(sepr);
|
||||
for (int i = 0; i < list.count(); ++i)
|
||||
json.replace(QString("\"%%1\"").arg(i + 1), "\"" + list.at(i) + "\"");
|
||||
@ -402,7 +396,7 @@ void Generator::processFrame(const QByteArray &data, const quint64 frame,
|
||||
* Constructor function, stores received frame data & the date/time that the frame data
|
||||
* was received.
|
||||
*/
|
||||
JSONWorker::JSONWorker(const QByteArray &data, const quint64 frame, const QDateTime &time)
|
||||
JSON::Worker::Worker(const QByteArray &data, const quint64 frame, const QDateTime &time)
|
||||
: m_time(time)
|
||||
, m_data(data)
|
||||
, m_frame(frame)
|
||||
@ -413,27 +407,26 @@ JSONWorker::JSONWorker(const QByteArray &data, const quint64 frame, const QDateT
|
||||
* Reads the frame & inserts its values on the JSON map, and/or extracts the JSON frame
|
||||
* directly from the serial data.
|
||||
*/
|
||||
void JSONWorker::process()
|
||||
void JSON::Worker::process()
|
||||
{
|
||||
// Init variables
|
||||
QJsonParseError error;
|
||||
QJsonDocument document;
|
||||
|
||||
// Serial device sends JSON (auto mode)
|
||||
const auto generator = Generator::getInstance();
|
||||
if (generator->operationMode() == Generator::kAutomatic)
|
||||
if (Generator::instance().operationMode() == Generator::kAutomatic)
|
||||
document = QJsonDocument::fromJson(m_data, &error);
|
||||
|
||||
// We need to use a map file, check if its loaded & replace values into map
|
||||
else
|
||||
{
|
||||
// Empty JSON map data
|
||||
if (generator->jsonMapData().isEmpty())
|
||||
if (Generator::instance().jsonMapData().isEmpty())
|
||||
return;
|
||||
|
||||
// Separate incoming data & add it to the JSON map
|
||||
auto json = generator->jsonMapData();
|
||||
const auto sepr = IO::Manager::getInstance()->separatorSequence();
|
||||
auto json = Generator::instance().jsonMapData();
|
||||
const auto sepr = IO::Manager::instance().separatorSequence();
|
||||
const auto list = QString::fromUtf8(m_data).split(sepr);
|
||||
for (int i = 0; i < list.count(); ++i)
|
||||
json.replace(QString("\"%%1\"").arg(i + 1), "\"" + list.at(i) + "\"");
|
||||
@ -485,4 +478,3 @@ void JSONWorker::process()
|
||||
// Delete object in 500 ms
|
||||
QTimer::singleShot(500, this, SIGNAL(finished()));
|
||||
}
|
||||
}
|
||||
|
@ -43,7 +43,7 @@ namespace JSON
|
||||
* This code is executed on another thread in order to avoid blocking the
|
||||
* user interface.
|
||||
*/
|
||||
class JSONWorker : public QObject
|
||||
class Worker : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
@ -52,7 +52,7 @@ Q_SIGNALS:
|
||||
void jsonReady(const JFI_Object &info);
|
||||
|
||||
public:
|
||||
JSONWorker(const QByteArray &data, const quint64 frame, const QDateTime &time);
|
||||
Worker(const QByteArray &data, const quint64 frame, const QDateTime &time);
|
||||
|
||||
public Q_SLOTS:
|
||||
void process();
|
||||
@ -111,6 +111,13 @@ Q_SIGNALS:
|
||||
void jsonChanged(const JFI_Object &info);
|
||||
void processFramesInSeparateThreadChanged();
|
||||
|
||||
private:
|
||||
explicit Generator();
|
||||
Generator(Generator &&) = delete;
|
||||
Generator(const Generator &) = delete;
|
||||
Generator &operator=(Generator &&) = delete;
|
||||
Generator &operator=(const Generator &) = delete;
|
||||
|
||||
public:
|
||||
enum OperationMode
|
||||
{
|
||||
@ -119,8 +126,7 @@ public:
|
||||
};
|
||||
Q_ENUM(OperationMode)
|
||||
|
||||
public:
|
||||
static Generator *getInstance();
|
||||
static Generator &instance();
|
||||
|
||||
QString jsonMapData() const;
|
||||
QString jsonMapFilename() const;
|
||||
@ -134,9 +140,6 @@ public Q_SLOTS:
|
||||
void setProcessFramesInSeparateThread(const bool threaded);
|
||||
void setOperationMode(const JSON::Generator::OperationMode &mode);
|
||||
|
||||
private:
|
||||
Generator();
|
||||
|
||||
public Q_SLOTS:
|
||||
void readSettings();
|
||||
void loadJFI(const JFI_Object &object);
|
||||
|
@ -24,20 +24,10 @@
|
||||
#include "Dataset.h"
|
||||
#include "FrameInfo.h"
|
||||
|
||||
namespace JSON
|
||||
{
|
||||
|
||||
Group::Group(QObject *parent)
|
||||
: QObject(parent)
|
||||
, m_title("")
|
||||
, m_widget("")
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Destructor function
|
||||
*/
|
||||
Group::~Group()
|
||||
JSON::Group::~Group()
|
||||
{
|
||||
qDeleteAll(m_datasets);
|
||||
m_datasets.clear();
|
||||
@ -46,7 +36,7 @@ Group::~Group()
|
||||
/**
|
||||
* @return The title/description of this group
|
||||
*/
|
||||
QString Group::title() const
|
||||
QString JSON::Group::title() const
|
||||
{
|
||||
return m_title;
|
||||
}
|
||||
@ -54,7 +44,7 @@ QString Group::title() const
|
||||
/**
|
||||
* @return The widget type of this group (if any)
|
||||
*/
|
||||
QString Group::widget() const
|
||||
QString JSON::Group::widget() const
|
||||
{
|
||||
return m_widget;
|
||||
}
|
||||
@ -62,7 +52,7 @@ QString Group::widget() const
|
||||
/**
|
||||
* @return The number of datasets inside this group
|
||||
*/
|
||||
int Group::datasetCount() const
|
||||
int JSON::Group::datasetCount() const
|
||||
{
|
||||
return m_datasets.count();
|
||||
}
|
||||
@ -70,7 +60,7 @@ int Group::datasetCount() const
|
||||
/**
|
||||
* @return A list with all the dataset objects contained in this group
|
||||
*/
|
||||
QVector<Dataset *> &Group::datasets()
|
||||
QVector<JSON::Dataset *> &JSON::Group::datasets()
|
||||
{
|
||||
return m_datasets;
|
||||
}
|
||||
@ -78,7 +68,7 @@ QVector<Dataset *> &Group::datasets()
|
||||
/**
|
||||
* @return The dataset at the given @a index,vreturns @c Q_NULLPTR on invalid index
|
||||
*/
|
||||
JSON::Dataset *Group::getDataset(const int index)
|
||||
JSON::Dataset *JSON::Group::getDataset(const int index)
|
||||
{
|
||||
if (index < datasetCount() && index >= 0)
|
||||
return m_datasets.at(index);
|
||||
@ -92,7 +82,7 @@ JSON::Dataset *Group::getDataset(const int index)
|
||||
*
|
||||
* @return @c true on success, @c false on failure
|
||||
*/
|
||||
bool Group::read(const QJsonObject &object)
|
||||
bool JSON::Group::read(const QJsonObject &object)
|
||||
{
|
||||
if (!object.isEmpty())
|
||||
{
|
||||
@ -111,7 +101,7 @@ bool Group::read(const QJsonObject &object)
|
||||
const auto object = array.at(i).toObject();
|
||||
if (!object.isEmpty())
|
||||
{
|
||||
Dataset *dataset = new Dataset(this);
|
||||
Dataset *dataset = new Dataset();
|
||||
if (dataset->read(object))
|
||||
m_datasets.append(dataset);
|
||||
else
|
||||
@ -125,4 +115,3 @@ bool Group::read(const QJsonObject &object)
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -57,10 +57,9 @@ namespace JSON
|
||||
* - Widget
|
||||
* - A vector of datasets
|
||||
*/
|
||||
class Group : public QObject
|
||||
class Group
|
||||
{
|
||||
public:
|
||||
Group(QObject *parent = Q_NULLPTR);
|
||||
~Group();
|
||||
|
||||
QString title() const;
|
||||
|
@ -29,14 +29,10 @@
|
||||
#include <Misc/Utilities.h>
|
||||
#include <Misc/TimerEvents.h>
|
||||
|
||||
namespace MQTT
|
||||
{
|
||||
static Client *CLIENT = Q_NULLPTR;
|
||||
|
||||
/**
|
||||
* Constructor function
|
||||
*/
|
||||
Client::Client()
|
||||
MQTT::Client::Client()
|
||||
: m_topic("")
|
||||
, m_lookupActive(false)
|
||||
, m_sentMessages(0)
|
||||
@ -47,17 +43,17 @@ Client::Client()
|
||||
regenerateClient();
|
||||
|
||||
// Send data periodically & reset statistics when disconnected/connected to a device
|
||||
const auto io = IO::Manager::getInstance();
|
||||
const auto te = Misc::TimerEvents::getInstance();
|
||||
connect(te, &Misc::TimerEvents::lowFreqTimeout, this, &Client::sendData);
|
||||
connect(io, &IO::Manager::frameReceived, this, &Client::onFrameReceived);
|
||||
connect(io, &IO::Manager::connectedChanged, this, &Client::resetStatistics);
|
||||
const auto io = &IO::Manager::instance();
|
||||
const auto te = &Misc::TimerEvents::instance();
|
||||
connect(te, &Misc::TimerEvents::lowFreqTimeout, this, &MQTT::Client::sendData);
|
||||
connect(io, &IO::Manager::frameReceived, this, &MQTT::Client::onFrameReceived);
|
||||
connect(io, &IO::Manager::connectedChanged, this, &MQTT::Client::resetStatistics);
|
||||
}
|
||||
|
||||
/**
|
||||
* Destructor function
|
||||
*/
|
||||
Client::~Client()
|
||||
MQTT::Client::~Client()
|
||||
{
|
||||
disconnectFromHost();
|
||||
delete m_client;
|
||||
@ -66,12 +62,10 @@ Client::~Client()
|
||||
/**
|
||||
* Returns a pointer to the only instance of this class
|
||||
*/
|
||||
Client *Client::getInstance()
|
||||
MQTT::Client &MQTT::Client::instance()
|
||||
{
|
||||
if (!CLIENT)
|
||||
CLIENT = new Client;
|
||||
|
||||
return CLIENT;
|
||||
static auto singleton = new Client();
|
||||
return *singleton;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -80,7 +74,7 @@ Client *Client::getInstance()
|
||||
* - 1: at least once
|
||||
* - 2: exactly once
|
||||
*/
|
||||
quint8 Client::qos() const
|
||||
quint8 MQTT::Client::qos() const
|
||||
{
|
||||
Q_ASSERT(m_client);
|
||||
return m_client->willQos();
|
||||
@ -89,7 +83,7 @@ quint8 Client::qos() const
|
||||
/**
|
||||
* Returns @c true if the retain flag is enabled
|
||||
*/
|
||||
bool Client::retain() const
|
||||
bool MQTT::Client::retain() const
|
||||
{
|
||||
Q_ASSERT(m_client);
|
||||
return m_client->willRetain();
|
||||
@ -98,7 +92,7 @@ bool Client::retain() const
|
||||
/**
|
||||
* Returns the TCP port number used for the MQTT connection
|
||||
*/
|
||||
quint16 Client::port() const
|
||||
quint16 MQTT::Client::port() const
|
||||
{
|
||||
Q_ASSERT(m_client);
|
||||
return m_client->port();
|
||||
@ -107,7 +101,7 @@ quint16 Client::port() const
|
||||
/**
|
||||
* Returns the MQTT topic used
|
||||
*/
|
||||
QString Client::topic() const
|
||||
QString MQTT::Client::topic() const
|
||||
{
|
||||
return m_topic;
|
||||
}
|
||||
@ -115,7 +109,7 @@ QString Client::topic() const
|
||||
/**
|
||||
* Returns the selected SSL/TLS protocol index
|
||||
*/
|
||||
int Client::sslProtocol() const
|
||||
int MQTT::Client::sslProtocol() const
|
||||
{
|
||||
return m_sslProtocol;
|
||||
}
|
||||
@ -124,7 +118,7 @@ int Client::sslProtocol() const
|
||||
* Returns the index of the MQTT version, corresponding to the list returned by the
|
||||
* @c mqttVersions() function.
|
||||
*/
|
||||
int Client::mqttVersion() const
|
||||
int MQTT::Client::mqttVersion() const
|
||||
{
|
||||
Q_ASSERT(m_client);
|
||||
|
||||
@ -145,7 +139,7 @@ int Client::mqttVersion() const
|
||||
/**
|
||||
* Returns @c true if SSL/TLS is enabled
|
||||
*/
|
||||
bool Client::sslEnabled() const
|
||||
bool MQTT::Client::sslEnabled() const
|
||||
{
|
||||
return m_sslEnabled;
|
||||
}
|
||||
@ -155,7 +149,7 @@ bool Client::sslEnabled() const
|
||||
* - Publisher
|
||||
* - Subscriber
|
||||
*/
|
||||
int Client::clientMode() const
|
||||
int MQTT::Client::clientMode() const
|
||||
{
|
||||
return m_clientMode;
|
||||
}
|
||||
@ -163,7 +157,7 @@ int Client::clientMode() const
|
||||
/**
|
||||
* Returns the MQTT username
|
||||
*/
|
||||
QString Client::username() const
|
||||
QString MQTT::Client::username() const
|
||||
{
|
||||
Q_ASSERT(m_client);
|
||||
return m_client->username();
|
||||
@ -172,7 +166,7 @@ QString Client::username() const
|
||||
/**
|
||||
* Returns the MQTT password
|
||||
*/
|
||||
QString Client::password() const
|
||||
QString MQTT::Client::password() const
|
||||
{
|
||||
Q_ASSERT(m_client);
|
||||
return QString::fromUtf8(m_client->password());
|
||||
@ -181,7 +175,7 @@ QString Client::password() const
|
||||
/**
|
||||
* Returns the IP address of the MQTT broker/server
|
||||
*/
|
||||
QString Client::host() const
|
||||
QString MQTT::Client::host() const
|
||||
{
|
||||
Q_ASSERT(m_client);
|
||||
return m_client->hostName();
|
||||
@ -190,7 +184,7 @@ QString Client::host() const
|
||||
/**
|
||||
* Returns the keep-alive timeout interval used by the MQTT client.
|
||||
*/
|
||||
quint16 Client::keepAlive() const
|
||||
quint16 MQTT::Client::keepAlive() const
|
||||
{
|
||||
Q_ASSERT(m_client);
|
||||
return m_client->keepAlive();
|
||||
@ -200,7 +194,7 @@ quint16 Client::keepAlive() const
|
||||
* Returns @c true if the MQTT module is currently performing a DNS lookup of the MQTT
|
||||
* broker/server domain.
|
||||
*/
|
||||
bool Client::lookupActive() const
|
||||
bool MQTT::Client::lookupActive() const
|
||||
{
|
||||
return m_lookupActive;
|
||||
}
|
||||
@ -209,7 +203,7 @@ bool Client::lookupActive() const
|
||||
* Returns @c true if the MQTT module is connected to the broker, the topic is not empty
|
||||
* and the client is configured to act as an MQTT subscriber.
|
||||
*/
|
||||
bool Client::isSubscribed() const
|
||||
bool MQTT::Client::isSubscribed() const
|
||||
{
|
||||
return isConnectedToHost() && !topic().isEmpty() && clientMode() == ClientSubscriber;
|
||||
}
|
||||
@ -217,7 +211,7 @@ bool Client::isSubscribed() const
|
||||
/**
|
||||
* Returns @c true if the MQTT module is connected to a MQTT broker/server.
|
||||
*/
|
||||
bool Client::isConnectedToHost() const
|
||||
bool MQTT::Client::isConnectedToHost() const
|
||||
{
|
||||
Q_ASSERT(m_client);
|
||||
return m_client->isConnectedToHost();
|
||||
@ -226,7 +220,7 @@ bool Client::isConnectedToHost() const
|
||||
/**
|
||||
* Returns a list with the available quality-of-service modes.
|
||||
*/
|
||||
StringList Client::qosLevels() const
|
||||
StringList MQTT::Client::qosLevels() const
|
||||
{
|
||||
// clang-format off
|
||||
return StringList {
|
||||
@ -240,7 +234,7 @@ StringList Client::qosLevels() const
|
||||
/**
|
||||
* Returns a list with the available client operation modes.
|
||||
*/
|
||||
StringList Client::clientModes() const
|
||||
StringList MQTT::Client::clientModes() const
|
||||
{
|
||||
return StringList { tr("Publisher"), tr("Subscriber") };
|
||||
}
|
||||
@ -248,7 +242,7 @@ StringList Client::clientModes() const
|
||||
/**
|
||||
* Returns a list with the supported MQTT versions
|
||||
*/
|
||||
StringList Client::mqttVersions() const
|
||||
StringList MQTT::Client::mqttVersions() const
|
||||
{
|
||||
return StringList { "MQTT 3.1.0", "MQTT 3.1.1" };
|
||||
}
|
||||
@ -256,7 +250,7 @@ StringList Client::mqttVersions() const
|
||||
/**
|
||||
* Returns a list with the supported SSL/TLS protocols
|
||||
*/
|
||||
StringList Client::sslProtocols() const
|
||||
StringList MQTT::Client::sslProtocols() const
|
||||
{
|
||||
return StringList {
|
||||
tr("System default"), "TLS v1.0", "TLS v1.1", "TLS v1.2",
|
||||
@ -267,7 +261,7 @@ StringList Client::sslProtocols() const
|
||||
/**
|
||||
* Returns the path of the currently loaded *.ca file
|
||||
*/
|
||||
QString Client::caFilePath() const
|
||||
QString MQTT::Client::caFilePath() const
|
||||
{
|
||||
return m_caFilePath;
|
||||
}
|
||||
@ -276,7 +270,7 @@ QString Client::caFilePath() const
|
||||
* Prompts the user to select a *.ca file and loads the certificate
|
||||
* into the SSL configuration.
|
||||
*/
|
||||
void Client::loadCaFile()
|
||||
void MQTT::Client::loadCaFile()
|
||||
{
|
||||
// Prompt user to select a CA file
|
||||
auto path
|
||||
@ -289,7 +283,7 @@ void Client::loadCaFile()
|
||||
/**
|
||||
* Tries to establish a TCP connection with the MQTT broker/server.
|
||||
*/
|
||||
void Client::connectToHost()
|
||||
void MQTT::Client::connectToHost()
|
||||
{
|
||||
Q_ASSERT(m_client);
|
||||
m_client->connectToHost();
|
||||
@ -299,7 +293,7 @@ void Client::connectToHost()
|
||||
* Connects/disconnects the application from the current MQTT broker. This function is
|
||||
* used as a convenience for the connect/disconnect button.
|
||||
*/
|
||||
void Client::toggleConnection()
|
||||
void MQTT::Client::toggleConnection()
|
||||
{
|
||||
if (isConnectedToHost())
|
||||
disconnectFromHost();
|
||||
@ -310,7 +304,7 @@ void Client::toggleConnection()
|
||||
/**
|
||||
* Disconnects from the MQTT broker/server
|
||||
*/
|
||||
void Client::disconnectFromHost()
|
||||
void MQTT::Client::disconnectFromHost()
|
||||
{
|
||||
Q_ASSERT(m_client);
|
||||
m_client->disconnectFromHost();
|
||||
@ -319,7 +313,7 @@ void Client::disconnectFromHost()
|
||||
/**
|
||||
* Changes the quality of service level of the MQTT client.
|
||||
*/
|
||||
void Client::setQos(const quint8 qos)
|
||||
void MQTT::Client::setQos(const quint8 qos)
|
||||
{
|
||||
Q_ASSERT(m_client);
|
||||
m_client->setWillQos(qos);
|
||||
@ -329,17 +323,17 @@ void Client::setQos(const quint8 qos)
|
||||
/**
|
||||
* Performs a DNS lookup for the given @a host name
|
||||
*/
|
||||
void Client::lookup(const QString &host)
|
||||
void MQTT::Client::lookup(const QString &host)
|
||||
{
|
||||
m_lookupActive = true;
|
||||
Q_EMIT lookupActiveChanged();
|
||||
QHostInfo::lookupHost(host.simplified(), this, &Client::lookupFinished);
|
||||
QHostInfo::lookupHost(host.simplified(), this, &MQTT::Client::lookupFinished);
|
||||
}
|
||||
|
||||
/**
|
||||
* Changes the TCP port number used for the MQTT communications.
|
||||
*/
|
||||
void Client::setPort(const quint16 port)
|
||||
void MQTT::Client::setPort(const quint16 port)
|
||||
{
|
||||
Q_ASSERT(m_client);
|
||||
m_client->setPort(port);
|
||||
@ -349,7 +343,7 @@ void Client::setPort(const quint16 port)
|
||||
/**
|
||||
* Changes the IP address of the MQTT broker/host
|
||||
*/
|
||||
void Client::setHost(const QString &host)
|
||||
void MQTT::Client::setHost(const QString &host)
|
||||
{
|
||||
Q_ASSERT(m_client);
|
||||
m_client->setHostName(host);
|
||||
@ -360,7 +354,7 @@ void Client::setHost(const QString &host)
|
||||
* If set to @c true, the @c retain flag shall be appended to the MQTT message so that
|
||||
* new clients connecting to the broker will immediately receive the last "good" message.
|
||||
*/
|
||||
void Client::setRetain(const bool retain)
|
||||
void MQTT::Client::setRetain(const bool retain)
|
||||
{
|
||||
Q_ASSERT(m_client);
|
||||
m_client->setWillRetain(retain);
|
||||
@ -372,7 +366,7 @@ void Client::setRetain(const bool retain)
|
||||
* - Publisher
|
||||
* - Subscriber
|
||||
*/
|
||||
void Client::setClientMode(const int mode)
|
||||
void MQTT::Client::setClientMode(const int mode)
|
||||
{
|
||||
m_clientMode = static_cast<MQTTClientMode>(mode);
|
||||
Q_EMIT clientModeChanged();
|
||||
@ -381,7 +375,7 @@ void Client::setClientMode(const int mode)
|
||||
/**
|
||||
* Changes the MQTT topic used by the client.
|
||||
*/
|
||||
void Client::setTopic(const QString &topic)
|
||||
void MQTT::Client::setTopic(const QString &topic)
|
||||
{
|
||||
m_topic = topic;
|
||||
Q_EMIT topicChanged();
|
||||
@ -391,7 +385,7 @@ void Client::setTopic(const QString &topic)
|
||||
* Reads the CA file in the given @a path and loads it into the
|
||||
* SSL configuration handler for the MQTT connection.
|
||||
*/
|
||||
void Client::loadCaFile(const QString &path)
|
||||
void MQTT::Client::loadCaFile(const QString &path)
|
||||
{
|
||||
// Save *.ca file path
|
||||
m_caFilePath = path;
|
||||
@ -426,7 +420,7 @@ void Client::loadCaFile(const QString &path)
|
||||
/**
|
||||
* Changes the SSL protocol version to use for the MQTT connection.
|
||||
*/
|
||||
void Client::setSslProtocol(const int index)
|
||||
void MQTT::Client::setSslProtocol(const int index)
|
||||
{
|
||||
switch (index)
|
||||
{
|
||||
@ -465,7 +459,7 @@ void Client::setSslProtocol(const int index)
|
||||
/**
|
||||
* Enables/disables SSL/TLS communications with the MQTT broker
|
||||
*/
|
||||
void Client::setSslEnabled(const bool enabled)
|
||||
void MQTT::Client::setSslEnabled(const bool enabled)
|
||||
{
|
||||
m_sslEnabled = enabled;
|
||||
regenerateClient();
|
||||
@ -475,7 +469,7 @@ void Client::setSslEnabled(const bool enabled)
|
||||
/**
|
||||
* Changes the username used to connect to the MQTT broker/server
|
||||
*/
|
||||
void Client::setUsername(const QString &username)
|
||||
void MQTT::Client::setUsername(const QString &username)
|
||||
{
|
||||
Q_ASSERT(m_client);
|
||||
m_client->setUsername(username);
|
||||
@ -485,7 +479,7 @@ void Client::setUsername(const QString &username)
|
||||
/**
|
||||
* Changes the password used to connect to the MQTT broker/server
|
||||
*/
|
||||
void Client::setPassword(const QString &password)
|
||||
void MQTT::Client::setPassword(const QString &password)
|
||||
{
|
||||
Q_ASSERT(m_client);
|
||||
m_client->setPassword(password.toUtf8());
|
||||
@ -497,7 +491,7 @@ void Client::setPassword(const QString &password)
|
||||
* the Client finishes transmitting one Control Packet and the point it starts sending the
|
||||
* next packet.
|
||||
*/
|
||||
void Client::setKeepAlive(const quint16 keepAlive)
|
||||
void MQTT::Client::setKeepAlive(const quint16 keepAlive)
|
||||
{
|
||||
Q_ASSERT(m_client);
|
||||
m_client->setKeepAlive(keepAlive);
|
||||
@ -507,7 +501,7 @@ void Client::setKeepAlive(const quint16 keepAlive)
|
||||
/**
|
||||
* Changes the MQTT version used to connect to the MQTT broker/server
|
||||
*/
|
||||
void Client::setMqttVersion(const int versionIndex)
|
||||
void MQTT::Client::setMqttVersion(const int versionIndex)
|
||||
{
|
||||
Q_ASSERT(m_client);
|
||||
|
||||
@ -529,7 +523,7 @@ void Client::setMqttVersion(const int versionIndex)
|
||||
/**
|
||||
* Publishes all the received data to the MQTT broker
|
||||
*/
|
||||
void Client::sendData()
|
||||
void MQTT::Client::sendData()
|
||||
{
|
||||
Q_ASSERT(m_client);
|
||||
|
||||
@ -556,7 +550,7 @@ void Client::sendData()
|
||||
/**
|
||||
* Clears the JSON frames & sets the sent messages to 0
|
||||
*/
|
||||
void Client::resetStatistics()
|
||||
void MQTT::Client::resetStatistics()
|
||||
{
|
||||
m_sentMessages = 0;
|
||||
m_frames.clear();
|
||||
@ -565,7 +559,7 @@ void Client::resetStatistics()
|
||||
/**
|
||||
* Subscribe/unsubscripe to the set MQTT topic when the connection state is changed.
|
||||
*/
|
||||
void Client::onConnectedChanged()
|
||||
void MQTT::Client::onConnectedChanged()
|
||||
{
|
||||
Q_ASSERT(m_client);
|
||||
|
||||
@ -579,7 +573,7 @@ void Client::onConnectedChanged()
|
||||
* Sets the host IP address when the lookup finishes.
|
||||
* If the lookup fails, the error code/string shall be shown to the user in a messagebox.
|
||||
*/
|
||||
void Client::lookupFinished(const QHostInfo &info)
|
||||
void MQTT::Client::lookupFinished(const QHostInfo &info)
|
||||
{
|
||||
m_lookupActive = false;
|
||||
Q_EMIT lookupActiveChanged();
|
||||
@ -600,7 +594,7 @@ void Client::lookupFinished(const QHostInfo &info)
|
||||
/**
|
||||
* Displays any MQTT-related error with a GUI message-box
|
||||
*/
|
||||
void Client::onError(const QMQTT::ClientError error)
|
||||
void MQTT::Client::onError(const QMQTT::ClientError error)
|
||||
{
|
||||
QString str;
|
||||
|
||||
@ -709,10 +703,10 @@ void Client::onError(const QMQTT::ClientError error)
|
||||
* Registers the given @a frame data to the list of frames that shall be published
|
||||
* to the MQTT broker/server
|
||||
*/
|
||||
void Client::onFrameReceived(const QByteArray &frame)
|
||||
void MQTT::Client::onFrameReceived(const QByteArray &frame)
|
||||
{
|
||||
// Ignore if device is not connected
|
||||
if (!IO::Manager::getInstance()->connected())
|
||||
if (!IO::Manager::instance().connected())
|
||||
return;
|
||||
|
||||
// Ignore if mode is not set to publisher
|
||||
@ -728,7 +722,7 @@ void Client::onFrameReceived(const QByteArray &frame)
|
||||
* Displays the SSL errors that occur and allows the user to decide if he/she wants to
|
||||
* ignore those errors.
|
||||
*/
|
||||
void Client::onSslErrors(const QList<QSslError> &errors)
|
||||
void MQTT::Client::onSslErrors(const QList<QSslError> &errors)
|
||||
{
|
||||
Q_ASSERT(m_client);
|
||||
|
||||
@ -752,7 +746,7 @@ void Client::onSslErrors(const QList<QSslError> &errors)
|
||||
* Reads the given MQTT @a message and instructs the @c IO::Manager module to process
|
||||
* received data directly.
|
||||
*/
|
||||
void Client::onMessageReceived(const QMQTT::Message &message)
|
||||
void MQTT::Client::onMessageReceived(const QMQTT::Message &message)
|
||||
{
|
||||
// Ignore if client mode is not set to suscriber
|
||||
if (clientMode() != ClientSubscriber)
|
||||
@ -771,14 +765,14 @@ void Client::onMessageReceived(const QMQTT::Message &message)
|
||||
mpayld.append('\n');
|
||||
|
||||
// Let IO manager process incoming data
|
||||
IO::Manager::getInstance()->processPayload(mpayld);
|
||||
IO::Manager::instance().processPayload(mpayld);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new MQTT client instance, this approach is required in order to allow
|
||||
* the MQTT module to support both non-encrypted and TLS connections.
|
||||
*/
|
||||
void Client::regenerateClient()
|
||||
void MQTT::Client::regenerateClient()
|
||||
{
|
||||
// Init. default MQTT configuration
|
||||
quint8 qos = 0;
|
||||
@ -831,12 +825,20 @@ void Client::regenerateClient()
|
||||
m_client->setPassword(password.toUtf8());
|
||||
|
||||
// Connect signals/slots
|
||||
connect(m_client, &QMQTT::Client::error, this, &Client::onError);
|
||||
connect(m_client, &QMQTT::Client::sslErrors, this, &Client::onSslErrors);
|
||||
connect(m_client, &QMQTT::Client::received, this, &Client::onMessageReceived);
|
||||
connect(m_client, &QMQTT::Client::connected, this, &Client::connectedChanged);
|
||||
connect(m_client, &QMQTT::Client::connected, this, &Client::onConnectedChanged);
|
||||
connect(m_client, &QMQTT::Client::disconnected, this, &Client::connectedChanged);
|
||||
connect(m_client, &QMQTT::Client::disconnected, this, &Client::onConnectedChanged);
|
||||
}
|
||||
// clang-format off
|
||||
connect(m_client, &QMQTT::Client::error,
|
||||
this, &MQTT::Client::onError);
|
||||
connect(m_client, &QMQTT::Client::sslErrors,
|
||||
this, &MQTT::Client::onSslErrors);
|
||||
connect(m_client, &QMQTT::Client::received,
|
||||
this, &MQTT::Client::onMessageReceived);
|
||||
connect(m_client, &QMQTT::Client::connected,
|
||||
this, &MQTT::Client::connectedChanged);
|
||||
connect(m_client, &QMQTT::Client::connected,
|
||||
this, &MQTT::Client::onConnectedChanged);
|
||||
connect(m_client, &QMQTT::Client::disconnected,
|
||||
this, &MQTT::Client::connectedChanged);
|
||||
connect(m_client, &QMQTT::Client::disconnected,
|
||||
this, &MQTT::Client::onConnectedChanged);
|
||||
// clang-format on
|
||||
}
|
||||
|
@ -155,8 +155,17 @@ Q_SIGNALS:
|
||||
void mqttVersionChanged();
|
||||
void lookupActiveChanged();
|
||||
|
||||
private:
|
||||
explicit Client();
|
||||
Client(Client &&) = delete;
|
||||
Client(const Client &) = delete;
|
||||
Client &operator=(Client &&) = delete;
|
||||
Client &operator=(const Client &) = delete;
|
||||
|
||||
~Client();
|
||||
|
||||
public:
|
||||
static Client *getInstance();
|
||||
static Client &instance();
|
||||
|
||||
quint8 qos() const;
|
||||
bool retain() const;
|
||||
@ -203,10 +212,6 @@ public Q_SLOTS:
|
||||
void setKeepAlive(const quint16 keepAlive);
|
||||
void setMqttVersion(const int versionIndex);
|
||||
|
||||
private:
|
||||
Client();
|
||||
~Client();
|
||||
|
||||
private Q_SLOTS:
|
||||
void sendData();
|
||||
void resetStatistics();
|
||||
|
@ -27,11 +27,7 @@
|
||||
# include <kdmactouchbar.h>
|
||||
#endif
|
||||
|
||||
namespace Misc
|
||||
{
|
||||
static MacExtras *MAC_EXTRAS = Q_NULLPTR;
|
||||
|
||||
MacExtras::MacExtras()
|
||||
Misc::MacExtras::MacExtras()
|
||||
{
|
||||
#ifdef Q_OS_MAC
|
||||
// Configure action strings
|
||||
@ -64,43 +60,40 @@ MacExtras::MacExtras()
|
||||
bar->addAction(&m_dashboardAction);
|
||||
|
||||
// Re-translate buttons when language is changed
|
||||
connect(Translator::getInstance(), SIGNAL(languageChanged()), this,
|
||||
connect(&Translator::instance(), SIGNAL(languageChanged()), this,
|
||||
SLOT(updateButtonText()));
|
||||
#endif
|
||||
}
|
||||
|
||||
MacExtras *MacExtras::getInstance()
|
||||
Misc::MacExtras &Misc::MacExtras::instance()
|
||||
{
|
||||
if (!MAC_EXTRAS)
|
||||
MAC_EXTRAS = new MacExtras;
|
||||
|
||||
return MAC_EXTRAS;
|
||||
static auto singleton = new MacExtras();
|
||||
return *singleton;
|
||||
}
|
||||
|
||||
void MacExtras::setSetupChecked(const bool checked)
|
||||
void Misc::MacExtras::setSetupChecked(const bool checked)
|
||||
{
|
||||
m_setupAction.setChecked(checked);
|
||||
}
|
||||
|
||||
void MacExtras::setConsoleChecked(const bool checked)
|
||||
void Misc::MacExtras::setConsoleChecked(const bool checked)
|
||||
{
|
||||
m_consoleAction.setChecked(checked);
|
||||
}
|
||||
|
||||
void MacExtras::setDashboardChecked(const bool checked)
|
||||
void Misc::MacExtras::setDashboardChecked(const bool checked)
|
||||
{
|
||||
m_dashboardAction.setChecked(checked);
|
||||
}
|
||||
|
||||
void MacExtras::setDashboardEnabled(const bool enabled)
|
||||
void Misc::MacExtras::setDashboardEnabled(const bool enabled)
|
||||
{
|
||||
m_dashboardAction.setEnabled(enabled);
|
||||
}
|
||||
|
||||
void MacExtras::updateButtonText()
|
||||
void Misc::MacExtras::updateButtonText()
|
||||
{
|
||||
m_setupAction.setText(tr("Setup"));
|
||||
m_consoleAction.setText(tr("Console"));
|
||||
m_dashboardAction.setText(tr("Dashboard"));
|
||||
}
|
||||
}
|
||||
|
@ -44,8 +44,15 @@ Q_SIGNALS:
|
||||
void consoleClicked();
|
||||
void dashboardClicked();
|
||||
|
||||
private:
|
||||
explicit MacExtras();
|
||||
MacExtras(MacExtras &&) = delete;
|
||||
MacExtras(const MacExtras &) = delete;
|
||||
MacExtras &operator=(MacExtras &&) = delete;
|
||||
MacExtras &operator=(const MacExtras &) = delete;
|
||||
|
||||
public:
|
||||
static MacExtras *getInstance();
|
||||
static MacExtras &instance();
|
||||
|
||||
public Q_SLOTS:
|
||||
void setSetupChecked(const bool checked);
|
||||
@ -56,9 +63,6 @@ public Q_SLOTS:
|
||||
private Q_SLOTS:
|
||||
void updateButtonText();
|
||||
|
||||
private:
|
||||
MacExtras();
|
||||
|
||||
private:
|
||||
QAction m_setupAction;
|
||||
QAction m_consoleAction;
|
||||
|
@ -64,7 +64,7 @@
|
||||
Misc::ModuleManager::ModuleManager()
|
||||
{
|
||||
// Init translator (so that splash screen displays text in user's language)
|
||||
(void)Misc::Translator::getInstance();
|
||||
(void)Misc::Translator::instance();
|
||||
|
||||
// Load Roboto fonts from resources
|
||||
QFontDatabase::addApplicationFont(":/fonts/Roboto-Bold.ttf");
|
||||
@ -135,8 +135,6 @@ void Misc::ModuleManager::configureUpdater()
|
||||
void Misc::ModuleManager::registerQmlTypes()
|
||||
{
|
||||
qRegisterMetaType<JFI_Object>("JFI_Object");
|
||||
qmlRegisterType<JSON::Group>("SerialStudio", 1, 0, "Group");
|
||||
qmlRegisterType<JSON::Dataset>("SerialStudio", 1, 0, "Dataset");
|
||||
qmlRegisterType<Widgets::Terminal>("SerialStudio", 1, 0, "Terminal");
|
||||
qmlRegisterType<UI::DashboardWidget>("SerialStudio", 1, 0, "DashboardWidget");
|
||||
}
|
||||
@ -165,23 +163,25 @@ void Misc::ModuleManager::initializeQmlInterface()
|
||||
{
|
||||
// Initialize modules
|
||||
setSplashScreenMessage(tr("Initializing modules..."));
|
||||
const auto csvExport = CSV::Export::getInstance();
|
||||
const auto csvPlayer = CSV::Player::getInstance();
|
||||
const auto ioManager = IO::Manager::getInstance();
|
||||
const auto ioConsole = IO::Console::getInstance();
|
||||
const auto csvExport = &CSV::Export::instance();
|
||||
const auto csvPlayer = &CSV::Player::instance();
|
||||
const auto ioManager = &IO::Manager::instance();
|
||||
const auto ioConsole = &IO::Console::instance();
|
||||
const auto jsonEditor = &JSON::Editor::instance();
|
||||
const auto mqttClient = &MQTT::Client::instance();
|
||||
const auto uiDashboard = &UI::Dashboard::instance();
|
||||
const auto jsonGenerator = &JSON::Generator::instance();
|
||||
const auto pluginsBridge = &Plugins::Server::instance();
|
||||
const auto miscUtilities = &Misc::Utilities::instance();
|
||||
const auto miscMacExtras = &Misc::MacExtras::instance();
|
||||
const auto miscTranslator = &Misc::Translator::instance();
|
||||
const auto ioSerial = &IO::DataSources::Serial::instance();
|
||||
const auto miscTimerEvents = &Misc::TimerEvents::instance();
|
||||
const auto ioNetwork = &IO::DataSources::Network::instance();
|
||||
const auto miscThemeManager = &Misc::ThemeManager::instance();
|
||||
|
||||
// Initialize third-party modules
|
||||
const auto updater = QSimpleUpdater::getInstance();
|
||||
const auto jsonEditor = JSON::Editor::getInstance();
|
||||
const auto mqttClient = MQTT::Client::getInstance();
|
||||
const auto uiDashboard = UI::Dashboard::getInstance();
|
||||
const auto jsonGenerator = JSON::Generator::getInstance();
|
||||
const auto pluginsBridge = Plugins::Server::getInstance();
|
||||
const auto miscUtilities = Misc::Utilities::getInstance();
|
||||
const auto miscMacExtras = Misc::MacExtras::getInstance();
|
||||
const auto miscTranslator = Misc::Translator::getInstance();
|
||||
const auto ioSerial = IO::DataSources::Serial::getInstance();
|
||||
const auto miscTimerEvents = Misc::TimerEvents::getInstance();
|
||||
const auto ioNetwork = IO::DataSources::Network::getInstance();
|
||||
const auto miscThemeManager = Misc::ThemeManager::getInstance();
|
||||
|
||||
// Operating system flags
|
||||
bool isWin = false;
|
||||
@ -276,9 +276,9 @@ void Misc::ModuleManager::setSplashScreenMessage(const QString &message)
|
||||
*/
|
||||
void Misc::ModuleManager::onQuit()
|
||||
{
|
||||
Plugins::Server::getInstance()->removeConnection();
|
||||
CSV::Export::getInstance()->closeFile();
|
||||
CSV::Player::getInstance()->closeFile();
|
||||
IO::Manager::getInstance()->disconnectDevice();
|
||||
Misc::TimerEvents::getInstance()->stopTimers();
|
||||
CSV::Export::instance().closeFile();
|
||||
CSV::Player::instance().closeFile();
|
||||
IO::Manager::instance().disconnectDevice();
|
||||
Misc::TimerEvents::instance().stopTimers();
|
||||
Plugins::Server::instance().removeConnection();
|
||||
}
|
||||
|
@ -33,15 +33,11 @@
|
||||
#include <QApplication>
|
||||
#include <QJsonDocument>
|
||||
|
||||
namespace Misc
|
||||
{
|
||||
static ThemeManager *THEME_MANAGER = Q_NULLPTR;
|
||||
|
||||
/**
|
||||
* Constructor function, searches for available themes & loads
|
||||
* the theme variant selected by the user.
|
||||
*/
|
||||
ThemeManager::ThemeManager()
|
||||
Misc::ThemeManager::ThemeManager()
|
||||
{
|
||||
populateThemes();
|
||||
loadTheme(m_settings.value("themeId", 0).toInt());
|
||||
@ -50,18 +46,16 @@ ThemeManager::ThemeManager()
|
||||
/**
|
||||
* Returns a pointer to the only instance of this class
|
||||
*/
|
||||
ThemeManager *ThemeManager::getInstance()
|
||||
Misc::ThemeManager &Misc::ThemeManager::instance()
|
||||
{
|
||||
if (!THEME_MANAGER)
|
||||
THEME_MANAGER = new ThemeManager;
|
||||
|
||||
return THEME_MANAGER;
|
||||
static auto singleton = new ThemeManager();
|
||||
return *singleton;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the ID of the theme that the user has selected.
|
||||
*/
|
||||
int ThemeManager::themeId() const
|
||||
int Misc::ThemeManager::themeId() const
|
||||
{
|
||||
return m_themeId;
|
||||
}
|
||||
@ -76,7 +70,7 @@ int ThemeManager::themeId() const
|
||||
* Unfortunately, an app restart is required because the application
|
||||
* palette must be set before the GUI is initialized.
|
||||
*/
|
||||
void ThemeManager::setTheme(const int id)
|
||||
void Misc::ThemeManager::setTheme(const int id)
|
||||
{
|
||||
// Validate theme ID
|
||||
if (id >= m_availableThemesPaths.count())
|
||||
@ -104,7 +98,7 @@ void ThemeManager::setTheme(const int id)
|
||||
* The colors are then "extracted" from the JSON file & loaded into the
|
||||
* class, which is later used to set the colors of the QML user interface.
|
||||
*/
|
||||
void ThemeManager::loadTheme(const int id)
|
||||
void Misc::ThemeManager::loadTheme(const int id)
|
||||
{
|
||||
// Validate theme ID
|
||||
if (id >= m_availableThemesPaths.count())
|
||||
@ -212,7 +206,7 @@ void ThemeManager::loadTheme(const int id)
|
||||
* folder.
|
||||
* @note theme definitions are bundled during the compilatopn process.
|
||||
*/
|
||||
void ThemeManager::populateThemes()
|
||||
void Misc::ThemeManager::populateThemes()
|
||||
{
|
||||
// Clear available thems
|
||||
m_availableThemes.clear();
|
||||
@ -248,248 +242,247 @@ void ThemeManager::populateThemes()
|
||||
// Dumb access functions
|
||||
//----------------------------------------------------------------------------------------
|
||||
|
||||
bool ThemeManager::titlebarSeparator() const
|
||||
bool Misc::ThemeManager::titlebarSeparator() const
|
||||
{
|
||||
return m_titlebarSeparator;
|
||||
}
|
||||
|
||||
QColor ThemeManager::base() const
|
||||
QColor Misc::ThemeManager::base() const
|
||||
{
|
||||
return m_base;
|
||||
}
|
||||
|
||||
QColor ThemeManager::link() const
|
||||
QColor Misc::ThemeManager::link() const
|
||||
{
|
||||
return m_link;
|
||||
}
|
||||
|
||||
QColor ThemeManager::button() const
|
||||
QColor Misc::ThemeManager::button() const
|
||||
{
|
||||
return m_button;
|
||||
}
|
||||
|
||||
QColor ThemeManager::window() const
|
||||
QColor Misc::ThemeManager::window() const
|
||||
{
|
||||
return m_window;
|
||||
}
|
||||
|
||||
QColor ThemeManager::text() const
|
||||
QColor Misc::ThemeManager::text() const
|
||||
{
|
||||
return m_text;
|
||||
}
|
||||
|
||||
QColor ThemeManager::midlight() const
|
||||
QColor Misc::ThemeManager::midlight() const
|
||||
{
|
||||
return m_midlight;
|
||||
}
|
||||
|
||||
QColor ThemeManager::highlight() const
|
||||
QColor Misc::ThemeManager::highlight() const
|
||||
{
|
||||
return m_highlight;
|
||||
}
|
||||
|
||||
QColor ThemeManager::brightText() const
|
||||
QColor Misc::ThemeManager::brightText() const
|
||||
{
|
||||
return m_brightText;
|
||||
}
|
||||
|
||||
QColor ThemeManager::buttonText() const
|
||||
QColor Misc::ThemeManager::buttonText() const
|
||||
{
|
||||
return m_buttonText;
|
||||
}
|
||||
|
||||
QColor ThemeManager::windowText() const
|
||||
QColor Misc::ThemeManager::windowText() const
|
||||
{
|
||||
return m_windowText;
|
||||
}
|
||||
|
||||
QColor ThemeManager::tooltipText() const
|
||||
QColor Misc::ThemeManager::tooltipText() const
|
||||
{
|
||||
return m_tooltipText;
|
||||
}
|
||||
|
||||
QColor ThemeManager::tooltipBase() const
|
||||
QColor Misc::ThemeManager::tooltipBase() const
|
||||
{
|
||||
return m_tooltipBase;
|
||||
}
|
||||
|
||||
QColor ThemeManager::highlightedText() const
|
||||
QColor Misc::ThemeManager::highlightedText() const
|
||||
{
|
||||
return m_highlightedText;
|
||||
}
|
||||
|
||||
QColor ThemeManager::highlightedTextAlternative() const
|
||||
QColor Misc::ThemeManager::highlightedTextAlternative() const
|
||||
{
|
||||
return m_highlightedTextAlternative;
|
||||
}
|
||||
|
||||
QColor ThemeManager::placeholderText() const
|
||||
QColor Misc::ThemeManager::placeholderText() const
|
||||
{
|
||||
return m_placeholderText;
|
||||
}
|
||||
|
||||
QColor ThemeManager::toolbarGradient1() const
|
||||
QColor Misc::ThemeManager::toolbarGradient1() const
|
||||
{
|
||||
return m_toolbarGradient1;
|
||||
}
|
||||
|
||||
QColor ThemeManager::toolbarGradient2() const
|
||||
QColor Misc::ThemeManager::toolbarGradient2() const
|
||||
{
|
||||
return m_toolbarGradient2;
|
||||
}
|
||||
|
||||
QColor ThemeManager::menubarText() const
|
||||
QColor Misc::ThemeManager::menubarText() const
|
||||
{
|
||||
return m_menubarText;
|
||||
}
|
||||
|
||||
QColor ThemeManager::dialogBackground() const
|
||||
QColor Misc::ThemeManager::dialogBackground() const
|
||||
{
|
||||
return m_dialogBackground;
|
||||
}
|
||||
|
||||
QColor ThemeManager::consoleText() const
|
||||
QColor Misc::ThemeManager::consoleText() const
|
||||
{
|
||||
return m_consoleText;
|
||||
}
|
||||
|
||||
QColor ThemeManager::consoleBase() const
|
||||
QColor Misc::ThemeManager::consoleBase() const
|
||||
{
|
||||
return m_consoleBase;
|
||||
}
|
||||
|
||||
QColor ThemeManager::consoleButton() const
|
||||
QColor Misc::ThemeManager::consoleButton() const
|
||||
{
|
||||
return m_consoleButton;
|
||||
}
|
||||
|
||||
QColor ThemeManager::consoleWindow() const
|
||||
QColor Misc::ThemeManager::consoleWindow() const
|
||||
{
|
||||
return m_consoleWindow;
|
||||
}
|
||||
|
||||
QColor ThemeManager::consoleHighlight() const
|
||||
QColor Misc::ThemeManager::consoleHighlight() const
|
||||
{
|
||||
return m_consoleHighlight;
|
||||
}
|
||||
|
||||
QColor ThemeManager::consoleHighlightedText() const
|
||||
QColor Misc::ThemeManager::consoleHighlightedText() const
|
||||
{
|
||||
return m_consoleHighlightedText;
|
||||
}
|
||||
|
||||
QColor ThemeManager::consolePlaceholderText() const
|
||||
QColor Misc::ThemeManager::consolePlaceholderText() const
|
||||
{
|
||||
return m_consolePlaceholderText;
|
||||
}
|
||||
|
||||
QColor ThemeManager::windowBackground() const
|
||||
QColor Misc::ThemeManager::windowBackground() const
|
||||
{
|
||||
return m_windowBackground;
|
||||
}
|
||||
|
||||
QColor ThemeManager::windowGradient1() const
|
||||
QColor Misc::ThemeManager::windowGradient1() const
|
||||
{
|
||||
return m_windowGradient1;
|
||||
}
|
||||
|
||||
QColor ThemeManager::windowGradient2() const
|
||||
QColor Misc::ThemeManager::windowGradient2() const
|
||||
{
|
||||
return m_windowGradient2;
|
||||
}
|
||||
|
||||
QColor ThemeManager::alternativeHighlight() const
|
||||
QColor Misc::ThemeManager::alternativeHighlight() const
|
||||
{
|
||||
return m_alternativeHighlight;
|
||||
}
|
||||
|
||||
QColor ThemeManager::setupPanelBackground() const
|
||||
QColor Misc::ThemeManager::setupPanelBackground() const
|
||||
{
|
||||
return m_setupPanelBackground;
|
||||
}
|
||||
|
||||
QColor ThemeManager::widgetTextPrimary() const
|
||||
QColor Misc::ThemeManager::widgetTextPrimary() const
|
||||
{
|
||||
return m_widgetTextPrimary;
|
||||
}
|
||||
|
||||
QColor ThemeManager::widgetTextSecondary() const
|
||||
QColor Misc::ThemeManager::widgetTextSecondary() const
|
||||
{
|
||||
return m_widgetTextSecondary;
|
||||
}
|
||||
|
||||
QColor ThemeManager::widgetWindowBackground() const
|
||||
QColor Misc::ThemeManager::widgetWindowBackground() const
|
||||
{
|
||||
return m_widgetWindowBackground;
|
||||
}
|
||||
|
||||
QColor ThemeManager::widgetWindowBorder() const
|
||||
QColor Misc::ThemeManager::widgetWindowBorder() const
|
||||
{
|
||||
return m_widgetWindowBorder;
|
||||
}
|
||||
|
||||
QColor ThemeManager::paneWindowBackground() const
|
||||
QColor Misc::ThemeManager::paneWindowBackground() const
|
||||
{
|
||||
return m_paneWindowBackground;
|
||||
}
|
||||
|
||||
QColor ThemeManager::ledEnabled() const
|
||||
QColor Misc::ThemeManager::ledEnabled() const
|
||||
{
|
||||
return m_ledEnabled;
|
||||
}
|
||||
|
||||
QColor ThemeManager::ledDisabled() const
|
||||
QColor Misc::ThemeManager::ledDisabled() const
|
||||
{
|
||||
return m_ledDisabled;
|
||||
}
|
||||
|
||||
QColor ThemeManager::csvCheckbox() const
|
||||
QColor Misc::ThemeManager::csvCheckbox() const
|
||||
{
|
||||
return m_csvCheckbox;
|
||||
}
|
||||
|
||||
QColor ThemeManager::widgetForegroundPrimary() const
|
||||
QColor Misc::ThemeManager::widgetForegroundPrimary() const
|
||||
{
|
||||
return m_widgetForegroundPrimary;
|
||||
}
|
||||
|
||||
QColor ThemeManager::widgetForegroundSecondary() const
|
||||
QColor Misc::ThemeManager::widgetForegroundSecondary() const
|
||||
{
|
||||
return m_widgetForegroundSecondary;
|
||||
}
|
||||
|
||||
QColor ThemeManager::widgetIndicator() const
|
||||
QColor Misc::ThemeManager::widgetIndicator() const
|
||||
{
|
||||
return m_widgetIndicator;
|
||||
}
|
||||
|
||||
QColor ThemeManager::widgetControlBackground() const
|
||||
QColor Misc::ThemeManager::widgetControlBackground() const
|
||||
{
|
||||
return m_widgetControlBackground;
|
||||
}
|
||||
|
||||
QColor ThemeManager::connectButtonChecked() const
|
||||
QColor Misc::ThemeManager::connectButtonChecked() const
|
||||
{
|
||||
return m_connectButtonChecked;
|
||||
}
|
||||
|
||||
QColor ThemeManager::connectButtonUnchecked() const
|
||||
QColor Misc::ThemeManager::connectButtonUnchecked() const
|
||||
{
|
||||
return m_connectButtonUnchecked;
|
||||
}
|
||||
|
||||
QColor ThemeManager::mqttButton() const
|
||||
QColor Misc::ThemeManager::mqttButton() const
|
||||
{
|
||||
return m_mqttButton;
|
||||
}
|
||||
|
||||
StringList ThemeManager::widgetColors() const
|
||||
StringList Misc::ThemeManager::widgetColors() const
|
||||
{
|
||||
return m_widgetColors;
|
||||
}
|
||||
|
||||
StringList ThemeManager::availableThemes() const
|
||||
StringList Misc::ThemeManager::availableThemes() const
|
||||
{
|
||||
return m_availableThemes;
|
||||
}
|
||||
}
|
||||
|
@ -199,8 +199,15 @@ Q_SIGNALS:
|
||||
void themeChanged();
|
||||
void availableThemesChanged();
|
||||
|
||||
private:
|
||||
explicit ThemeManager();
|
||||
ThemeManager(ThemeManager &&) = delete;
|
||||
ThemeManager(const ThemeManager &) = delete;
|
||||
ThemeManager &operator=(ThemeManager &&) = delete;
|
||||
ThemeManager &operator=(const ThemeManager &) = delete;
|
||||
|
||||
public:
|
||||
static ThemeManager *getInstance();
|
||||
static ThemeManager &instance();
|
||||
|
||||
int themeId() const;
|
||||
|
||||
@ -262,9 +269,6 @@ private Q_SLOTS:
|
||||
void populateThemes();
|
||||
void loadTheme(const int id);
|
||||
|
||||
private:
|
||||
ThemeManager();
|
||||
|
||||
private:
|
||||
int m_themeId;
|
||||
QSettings m_settings;
|
||||
|
@ -24,14 +24,6 @@
|
||||
|
||||
#include <QtMath>
|
||||
|
||||
namespace Misc
|
||||
{
|
||||
|
||||
/**
|
||||
* Pointer to the only instance of the class
|
||||
*/
|
||||
static TimerEvents *TIMER_EVENTS = Q_NULLPTR;
|
||||
|
||||
/**
|
||||
* Converts the given @a hz to milliseconds
|
||||
*/
|
||||
@ -45,32 +37,31 @@ static int HZ_TO_MS(const int hz)
|
||||
/**
|
||||
* Constructor function
|
||||
*/
|
||||
TimerEvents::TimerEvents()
|
||||
Misc::TimerEvents::TimerEvents()
|
||||
{
|
||||
// Configure timeout intevals
|
||||
m_timerLowFreq.setInterval(HZ_TO_MS(1));
|
||||
m_timerHighFreq.setInterval(HZ_TO_MS(20));
|
||||
|
||||
// Configure signals/slots
|
||||
connect(&m_timerLowFreq, &QTimer::timeout, this, &TimerEvents::lowFreqTimeout);
|
||||
connect(&m_timerHighFreq, &QTimer::timeout, this, &TimerEvents::highFreqTimeout);
|
||||
connect(&m_timerLowFreq, &QTimer::timeout, this, &Misc::TimerEvents::lowFreqTimeout);
|
||||
connect(&m_timerHighFreq, &QTimer::timeout, this,
|
||||
&Misc::TimerEvents::highFreqTimeout);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a pointer to the only instance of the class
|
||||
*/
|
||||
TimerEvents *TimerEvents::getInstance()
|
||||
Misc::TimerEvents &Misc::TimerEvents::instance()
|
||||
{
|
||||
if (!TIMER_EVENTS)
|
||||
TIMER_EVENTS = new TimerEvents;
|
||||
|
||||
return TIMER_EVENTS;
|
||||
static auto singleton = new TimerEvents();
|
||||
return *singleton;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the target UI refresh frequency
|
||||
*/
|
||||
int TimerEvents::highFreqTimeoutHz() const
|
||||
int Misc::TimerEvents::highFreqTimeoutHz() const
|
||||
{
|
||||
return HZ_TO_MS(m_timerHighFreq.interval());
|
||||
}
|
||||
@ -78,7 +69,7 @@ int TimerEvents::highFreqTimeoutHz() const
|
||||
/**
|
||||
* Stops all the timers of this module
|
||||
*/
|
||||
void TimerEvents::stopTimers()
|
||||
void Misc::TimerEvents::stopTimers()
|
||||
{
|
||||
m_timerLowFreq.stop();
|
||||
m_timerHighFreq.stop();
|
||||
@ -87,7 +78,7 @@ void TimerEvents::stopTimers()
|
||||
/**
|
||||
* Starts all the timer of the module
|
||||
*/
|
||||
void TimerEvents::startTimers()
|
||||
void Misc::TimerEvents::startTimers()
|
||||
{
|
||||
m_timerLowFreq.start();
|
||||
m_timerHighFreq.start();
|
||||
@ -96,7 +87,7 @@ void TimerEvents::startTimers()
|
||||
/**
|
||||
* Updates the target UI refresh frequency
|
||||
*/
|
||||
void TimerEvents::setHighFreqTimeout(const int hz)
|
||||
void Misc::TimerEvents::setHighFreqTimeout(const int hz)
|
||||
{
|
||||
if (hz > 0)
|
||||
{
|
||||
@ -110,4 +101,3 @@ void TimerEvents::setHighFreqTimeout(const int hz)
|
||||
Q_EMIT highFreqTimeoutChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -53,8 +53,15 @@ Q_SIGNALS:
|
||||
void highFreqTimeout();
|
||||
void highFreqTimeoutChanged();
|
||||
|
||||
private:
|
||||
explicit TimerEvents();
|
||||
TimerEvents(TimerEvents &&) = delete;
|
||||
TimerEvents(const TimerEvents &) = delete;
|
||||
TimerEvents &operator=(TimerEvents &&) = delete;
|
||||
TimerEvents &operator=(const TimerEvents &) = delete;
|
||||
|
||||
public:
|
||||
static TimerEvents *getInstance();
|
||||
static TimerEvents &instance();
|
||||
int highFreqTimeoutHz() const;
|
||||
|
||||
public Q_SLOTS:
|
||||
@ -62,9 +69,6 @@ public Q_SLOTS:
|
||||
void startTimers();
|
||||
void setHighFreqTimeout(const int hz);
|
||||
|
||||
private:
|
||||
TimerEvents();
|
||||
|
||||
private:
|
||||
QTimer m_timerLowFreq;
|
||||
QTimer m_timerHighFreq;
|
||||
|
@ -22,14 +22,10 @@
|
||||
|
||||
#include "Translator.h"
|
||||
|
||||
namespace Misc
|
||||
{
|
||||
static Translator *TRANSLATOR = Q_NULLPTR;
|
||||
|
||||
/**
|
||||
* Constructor function
|
||||
*/
|
||||
Translator::Translator()
|
||||
Misc::Translator::Translator()
|
||||
{
|
||||
setLanguage(m_settings.value("language", systemLanguage()).toInt());
|
||||
}
|
||||
@ -37,19 +33,17 @@ Translator::Translator()
|
||||
/**
|
||||
* Returns the only instance of the class
|
||||
*/
|
||||
Translator *Translator::getInstance()
|
||||
Misc::Translator &Misc::Translator::instance()
|
||||
{
|
||||
if (!TRANSLATOR)
|
||||
TRANSLATOR = new Translator;
|
||||
|
||||
return TRANSLATOR;
|
||||
static auto singleton = new Translator();
|
||||
return *singleton;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the current language ID, which corresponds to the indexes of the
|
||||
* languages returned by the \c availableLanguages() function.
|
||||
*/
|
||||
int Translator::language() const
|
||||
int Misc::Translator::language() const
|
||||
{
|
||||
return m_language;
|
||||
}
|
||||
@ -58,7 +52,7 @@ int Translator::language() const
|
||||
* Returns the appropiate language ID based on the current locale settings of
|
||||
* the host's operating system.
|
||||
*/
|
||||
int Translator::systemLanguage() const
|
||||
int Misc::Translator::systemLanguage() const
|
||||
{
|
||||
int lang;
|
||||
switch (QLocale::system().language())
|
||||
@ -89,7 +83,7 @@ int Translator::systemLanguage() const
|
||||
/**
|
||||
* Returns the welcome text displayed on the console
|
||||
*/
|
||||
QString Translator::welcomeConsoleText() const
|
||||
QString Misc::Translator::welcomeConsoleText() const
|
||||
{
|
||||
QString lang;
|
||||
switch (language())
|
||||
@ -128,7 +122,7 @@ QString Translator::welcomeConsoleText() const
|
||||
/**
|
||||
* Returns the acknowledgements text.
|
||||
*/
|
||||
QString Translator::acknowledgementsText() const
|
||||
QString Misc::Translator::acknowledgementsText() const
|
||||
{
|
||||
QString text = "";
|
||||
QFile file(":/messages/Acknowledgements.txt");
|
||||
@ -144,7 +138,7 @@ QString Translator::acknowledgementsText() const
|
||||
/**
|
||||
* Returns a list with the available translation languages.
|
||||
*/
|
||||
StringList Translator::availableLanguages() const
|
||||
StringList Misc::Translator::availableLanguages() const
|
||||
{
|
||||
return StringList { "English", "Español", "简体中文", "Deutsch", "Русский" };
|
||||
}
|
||||
@ -156,7 +150,7 @@ StringList Translator::availableLanguages() const
|
||||
* @param language language ID based on the indexes of the \a
|
||||
* availableLanguages() function
|
||||
*/
|
||||
void Translator::setLanguage(const int language)
|
||||
void Misc::Translator::setLanguage(const int language)
|
||||
{
|
||||
QString langName;
|
||||
QLocale locale;
|
||||
@ -202,7 +196,7 @@ void Translator::setLanguage(const int language)
|
||||
* @param language name of the *.qm file to load from the "translations"
|
||||
* directory inside the application's resources
|
||||
*/
|
||||
void Translator::setLanguage(const QLocale &locale, const QString &language)
|
||||
void Misc::Translator::setLanguage(const QLocale &locale, const QString &language)
|
||||
{
|
||||
qApp->removeTranslator(&m_translator);
|
||||
if (m_translator.load(locale, ":/translations/" + language + ".qm"))
|
||||
@ -211,4 +205,3 @@ void Translator::setLanguage(const QLocale &locale, const QString &language)
|
||||
Q_EMIT languageChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -57,10 +57,14 @@ Q_SIGNALS:
|
||||
void languageChanged();
|
||||
|
||||
private:
|
||||
Translator();
|
||||
explicit Translator();
|
||||
Translator(Translator &&) = delete;
|
||||
Translator(const Translator &) = delete;
|
||||
Translator &operator=(Translator &&) = delete;
|
||||
Translator &operator=(const Translator &) = delete;
|
||||
|
||||
public:
|
||||
static Translator *getInstance();
|
||||
static Translator &instance();
|
||||
|
||||
int language() const;
|
||||
int systemLanguage() const;
|
||||
|
@ -33,19 +33,13 @@
|
||||
|
||||
#include <AppInfo.h>
|
||||
|
||||
namespace Misc
|
||||
Misc::Utilities &Misc::Utilities::instance()
|
||||
{
|
||||
static Utilities *UTILITIES = Q_NULLPTR;
|
||||
|
||||
Utilities *Utilities::getInstance()
|
||||
{
|
||||
if (!UTILITIES)
|
||||
UTILITIES = new Utilities;
|
||||
|
||||
return UTILITIES;
|
||||
static auto singleton = new Utilities();
|
||||
return *singleton;
|
||||
}
|
||||
|
||||
void Utilities::rebootApplication()
|
||||
void Misc::Utilities::rebootApplication()
|
||||
{
|
||||
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
|
||||
qApp->exit();
|
||||
@ -61,7 +55,7 @@ void Utilities::rebootApplication()
|
||||
#endif
|
||||
}
|
||||
|
||||
bool Utilities::askAutomaticUpdates()
|
||||
bool Misc::Utilities::askAutomaticUpdates()
|
||||
{
|
||||
const int result = showMessageBox(tr("Check for updates automatically?"),
|
||||
tr("Should %1 automatically check for updates? "
|
||||
@ -75,9 +69,9 @@ bool Utilities::askAutomaticUpdates()
|
||||
/**
|
||||
* Shows a macOS-like message box with the given properties
|
||||
*/
|
||||
int Utilities::showMessageBox(const QString &text, const QString &informativeText,
|
||||
const QString &windowTitle,
|
||||
const QMessageBox::StandardButtons &bt)
|
||||
int Misc::Utilities::showMessageBox(const QString &text, const QString &informativeText,
|
||||
const QString &windowTitle,
|
||||
const QMessageBox::StandardButtons &bt)
|
||||
{
|
||||
// Get app icon
|
||||
auto icon = QPixmap(APP_ICON).scaled(64, 64, Qt::IgnoreAspectRatio,
|
||||
@ -98,7 +92,7 @@ int Utilities::showMessageBox(const QString &text, const QString &informativeTex
|
||||
/**
|
||||
* Displays the about Qt dialog
|
||||
*/
|
||||
void Utilities::aboutQt()
|
||||
void Misc::Utilities::aboutQt()
|
||||
{
|
||||
qApp->aboutQt();
|
||||
}
|
||||
@ -111,7 +105,7 @@ void Utilities::aboutQt()
|
||||
* Hacking details:
|
||||
* http://stackoverflow.com/questions/3490336/how-to-reveal-in-finder-or-show-in-explorer-with-qt
|
||||
*/
|
||||
void Utilities::revealFile(const QString &pathToReveal)
|
||||
void Misc::Utilities::revealFile(const QString &pathToReveal)
|
||||
{
|
||||
#if defined(Q_OS_WIN)
|
||||
QStringList param;
|
||||
@ -135,4 +129,3 @@ void Utilities::revealFile(const QString &pathToReveal)
|
||||
QDesktopServices::openUrl(QUrl::fromLocalFile(pathToReveal));
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
@ -43,7 +43,7 @@ class Utilities : public QObject
|
||||
|
||||
public:
|
||||
// clang-format off
|
||||
static Utilities* getInstance();
|
||||
static Utilities &instance();
|
||||
static void rebootApplication();
|
||||
Q_INVOKABLE bool askAutomaticUpdates();
|
||||
static int showMessageBox(const QString &text,
|
||||
|
@ -31,31 +31,32 @@
|
||||
#include <Misc/Utilities.h>
|
||||
#include <Misc/TimerEvents.h>
|
||||
|
||||
namespace Plugins
|
||||
{
|
||||
static Server *SERVER = Q_NULLPTR;
|
||||
|
||||
/**
|
||||
* Constructor function
|
||||
*/
|
||||
Server::Server()
|
||||
Plugins::Server::Server()
|
||||
: m_enabled(false)
|
||||
{
|
||||
// Set internal variables
|
||||
m_enabled = false;
|
||||
// clang-format off
|
||||
|
||||
// Send processed data at 1 Hz
|
||||
const auto ge = JSON::Generator::getInstance();
|
||||
const auto te = Misc::TimerEvents::getInstance();
|
||||
connect(ge, &JSON::Generator::jsonChanged, this, &Server::registerFrame);
|
||||
connect(te, &Misc::TimerEvents::highFreqTimeout, this, &Server::sendProcessedData,
|
||||
connect(&JSON::Generator::instance(), &JSON::Generator::jsonChanged,
|
||||
this, &Plugins::Server::registerFrame);
|
||||
connect(&Misc::TimerEvents::instance(), &Misc::TimerEvents::highFreqTimeout,
|
||||
this, &Plugins::Server::sendProcessedData,
|
||||
Qt::QueuedConnection);
|
||||
|
||||
// Send I/O "raw" data directly
|
||||
const auto io = IO::Manager::getInstance();
|
||||
connect(io, &IO::Manager::dataReceived, this, &Server::sendRawData);
|
||||
connect(&IO::Manager::instance(), &IO::Manager::dataReceived,
|
||||
this, &Plugins::Server::sendRawData);
|
||||
|
||||
// Configure TCP server
|
||||
connect(&m_server, &QTcpServer::newConnection, this, &Server::acceptConnection);
|
||||
connect(&m_server, &QTcpServer::newConnection,
|
||||
this, &Plugins::Server::acceptConnection);
|
||||
|
||||
// clang-format on
|
||||
|
||||
// Begin listening on TCP port
|
||||
if (!m_server.listen(QHostAddress::Any, PLUGINS_TCP_PORT))
|
||||
{
|
||||
Misc::Utilities::showMessageBox(tr("Unable to start plugin TCP server"),
|
||||
@ -67,7 +68,7 @@ Server::Server()
|
||||
/**
|
||||
* Destructor function
|
||||
*/
|
||||
Server::~Server()
|
||||
Plugins::Server::~Server()
|
||||
{
|
||||
m_server.close();
|
||||
}
|
||||
@ -75,18 +76,16 @@ Server::~Server()
|
||||
/**
|
||||
* Returns a pointer to the only instance of the class
|
||||
*/
|
||||
Server *Server::getInstance()
|
||||
Plugins::Server &Plugins::Server::instance()
|
||||
{
|
||||
if (!SERVER)
|
||||
SERVER = new Server;
|
||||
|
||||
return SERVER;
|
||||
static auto singleton = new Server();
|
||||
return *singleton;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns @c true if the plugin sub-system is enabled
|
||||
*/
|
||||
bool Server::enabled() const
|
||||
bool Plugins::Server::enabled() const
|
||||
{
|
||||
return m_enabled;
|
||||
}
|
||||
@ -94,7 +93,7 @@ bool Server::enabled() const
|
||||
/**
|
||||
* Disconnects the socket used for communicating with plugins.
|
||||
*/
|
||||
void Server::removeConnection()
|
||||
void Plugins::Server::removeConnection()
|
||||
{
|
||||
// Get caller socket
|
||||
auto socket = static_cast<QTcpSocket *>(QObject::sender());
|
||||
@ -119,7 +118,7 @@ void Server::removeConnection()
|
||||
/**
|
||||
* Enables/disables the plugin subsystem
|
||||
*/
|
||||
void Server::setEnabled(const bool enabled)
|
||||
void Plugins::Server::setEnabled(const bool enabled)
|
||||
{
|
||||
// Change value
|
||||
m_enabled = enabled;
|
||||
@ -146,20 +145,20 @@ void Server::setEnabled(const bool enabled)
|
||||
/**
|
||||
* Process incoming data and writes it directly to the connected I/O device
|
||||
*/
|
||||
void Server::onDataReceived()
|
||||
void Plugins::Server::onDataReceived()
|
||||
{
|
||||
// Get caller socket
|
||||
auto socket = static_cast<QTcpSocket *>(QObject::sender());
|
||||
|
||||
// Write incoming data to manager
|
||||
if (enabled() && socket)
|
||||
IO::Manager::getInstance()->writeData(socket->readAll());
|
||||
IO::Manager::instance().writeData(socket->readAll());
|
||||
}
|
||||
|
||||
/**
|
||||
* Configures incoming connection requests
|
||||
*/
|
||||
void Server::acceptConnection()
|
||||
void Plugins::Server::acceptConnection()
|
||||
{
|
||||
// Get & validate socket
|
||||
auto socket = m_server.nextPendingConnection();
|
||||
@ -183,9 +182,9 @@ void Server::acceptConnection()
|
||||
}
|
||||
|
||||
// Connect socket signals/slots
|
||||
connect(socket, &QTcpSocket::readyRead, this, &Server::onDataReceived);
|
||||
connect(socket, &QTcpSocket::errorOccurred, this, &Server::onErrorOccurred);
|
||||
connect(socket, &QTcpSocket::disconnected, this, &Server::removeConnection);
|
||||
connect(socket, &QTcpSocket::readyRead, this, &Plugins::Server::onDataReceived);
|
||||
connect(socket, &QTcpSocket::errorOccurred, this, &Plugins::Server::onErrorOccurred);
|
||||
connect(socket, &QTcpSocket::disconnected, this, &Plugins::Server::removeConnection);
|
||||
|
||||
// Add socket to sockets list
|
||||
m_sockets.append(socket);
|
||||
@ -197,7 +196,7 @@ void Server::acceptConnection()
|
||||
* - RX timestamp
|
||||
* - Frame JSON data
|
||||
*/
|
||||
void Server::sendProcessedData()
|
||||
void Plugins::Server::sendProcessedData()
|
||||
{
|
||||
// Stop if system is not enabled
|
||||
if (!enabled())
|
||||
@ -251,7 +250,7 @@ void Server::sendProcessedData()
|
||||
* Encodes the given @a data in Base64 and sends it through the TCP socket connected
|
||||
* to the localhost.
|
||||
*/
|
||||
void Server::sendRawData(const QByteArray &data)
|
||||
void Plugins::Server::sendRawData(const QByteArray &data)
|
||||
{
|
||||
// Stop if system is not enabled
|
||||
if (!enabled())
|
||||
@ -284,7 +283,7 @@ void Server::sendRawData(const QByteArray &data)
|
||||
* Obtains the latest JSON dataframe & appends it to the JSON list, which is later read
|
||||
* and sent by the @c sendProcessedData() function.
|
||||
*/
|
||||
void Server::registerFrame(const JFI_Object &frameInfo)
|
||||
void Plugins::Server::registerFrame(const JFI_Object &frameInfo)
|
||||
{
|
||||
m_frames.append(frameInfo);
|
||||
}
|
||||
@ -293,7 +292,7 @@ void Server::registerFrame(const JFI_Object &frameInfo)
|
||||
* This function is called whenever a socket error occurs, it disconnects the socket
|
||||
* from the host and displays the error in a message box.
|
||||
*/
|
||||
void Server::onErrorOccurred(const QAbstractSocket::SocketError socketError)
|
||||
void Plugins::Server::onErrorOccurred(const QAbstractSocket::SocketError socketError)
|
||||
{
|
||||
// Get caller socket
|
||||
auto socket = static_cast<QTcpSocket *>(QObject::sender());
|
||||
@ -304,4 +303,3 @@ void Server::onErrorOccurred(const QAbstractSocket::SocketError socketError)
|
||||
else
|
||||
qDebug() << socketError;
|
||||
}
|
||||
}
|
||||
|
@ -63,8 +63,17 @@ class Server : public QObject
|
||||
Q_SIGNALS:
|
||||
void enabledChanged();
|
||||
|
||||
private:
|
||||
explicit Server();
|
||||
Server(Server &&) = delete;
|
||||
Server(const Server &) = delete;
|
||||
Server &operator=(Server &&) = delete;
|
||||
Server &operator=(const Server &) = delete;
|
||||
|
||||
~Server();
|
||||
|
||||
public:
|
||||
static Server *getInstance();
|
||||
static Server &instance();
|
||||
bool enabled() const;
|
||||
|
||||
public Q_SLOTS:
|
||||
@ -79,10 +88,6 @@ private Q_SLOTS:
|
||||
void registerFrame(const JFI_Object &frameInfo);
|
||||
void onErrorOccurred(const QAbstractSocket::SocketError socketError);
|
||||
|
||||
private:
|
||||
Server();
|
||||
~Server();
|
||||
|
||||
private:
|
||||
bool m_enabled;
|
||||
QTcpServer m_server;
|
||||
|
@ -30,11 +30,6 @@
|
||||
|
||||
#include "Dashboard.h"
|
||||
|
||||
namespace UI
|
||||
{
|
||||
|
||||
static Dashboard *DASHBOARD = Q_NULLPTR;
|
||||
|
||||
//----------------------------------------------------------------------------------------
|
||||
// Constructor/deconstructor & singleton
|
||||
//----------------------------------------------------------------------------------------
|
||||
@ -42,14 +37,14 @@ static Dashboard *DASHBOARD = Q_NULLPTR;
|
||||
/**
|
||||
* Constructor of the class.
|
||||
*/
|
||||
Dashboard::Dashboard()
|
||||
UI::Dashboard::Dashboard()
|
||||
: m_points(100)
|
||||
, m_precision(2)
|
||||
{
|
||||
const auto cp = CSV::Player::getInstance();
|
||||
const auto io = IO::Manager::getInstance();
|
||||
const auto ge = JSON::Generator::getInstance();
|
||||
const auto te = Misc::TimerEvents::getInstance();
|
||||
const auto cp = &CSV::Player::instance();
|
||||
const auto io = &IO::Manager::instance();
|
||||
const auto ge = &JSON::Generator::instance();
|
||||
const auto te = &Misc::TimerEvents::instance();
|
||||
|
||||
// clang-format off
|
||||
connect(cp, SIGNAL(openChanged()),
|
||||
@ -65,42 +60,40 @@ Dashboard::Dashboard()
|
||||
this, SLOT(resetData()),
|
||||
Qt::QueuedConnection);
|
||||
connect(ge, &JSON::Generator::jsonChanged,
|
||||
this, &Dashboard::processLatestJSON);
|
||||
this, &UI::Dashboard::processLatestJSON);
|
||||
// clang-format on
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a pointer to the only instance of the class.
|
||||
*/
|
||||
Dashboard *Dashboard::getInstance()
|
||||
UI::Dashboard &UI::Dashboard::instance()
|
||||
{
|
||||
if (!DASHBOARD)
|
||||
DASHBOARD = new Dashboard();
|
||||
|
||||
return DASHBOARD;
|
||||
static auto singleton = new Dashboard();
|
||||
return *singleton;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------------------
|
||||
// Group/Dataset access functions
|
||||
//----------------------------------------------------------------------------------------
|
||||
|
||||
QFont Dashboard::monoFont() const
|
||||
QFont UI::Dashboard::monoFont() const
|
||||
{
|
||||
return QFont("Roboto Mono");
|
||||
}
|
||||
|
||||
// clang-format off
|
||||
JSON::Group *Dashboard::getLED(const int index) { return getGroupWidget(m_ledWidgets, index); }
|
||||
JSON::Group *Dashboard::getGPS(const int index) { return getGroupWidget(m_gpsWidgets, index); }
|
||||
JSON::Dataset *Dashboard::getBar(const int index) { return getDatasetWidget(m_barWidgets, index); }
|
||||
JSON::Dataset *Dashboard::getFFT(const int index) { return getDatasetWidget(m_fftWidgets, index); }
|
||||
JSON::Dataset *Dashboard::getPlot(const int index) { return getDatasetWidget(m_plotWidgets, index); }
|
||||
JSON::Group *Dashboard::getGroups(const int index) { return getGroupWidget(m_groupWidgets, index); }
|
||||
JSON::Dataset *Dashboard::getGauge(const int index) { return getDatasetWidget(m_gaugeWidgets, index); }
|
||||
JSON::Group *Dashboard::getGyroscope(const int index) { return getGroupWidget(m_gyroscopeWidgets, index); }
|
||||
JSON::Dataset *Dashboard::getCompass(const int index) { return getDatasetWidget(m_compassWidgets, index); }
|
||||
JSON::Group *Dashboard::getMultiplot(const int index) { return getGroupWidget(m_multiPlotWidgets, index); }
|
||||
JSON::Group *Dashboard::getAccelerometer(const int index) { return getGroupWidget(m_accelerometerWidgets, index); }
|
||||
JSON::Group *UI::Dashboard::getLED(const int index) { return getGroupWidget(m_ledWidgets, index); }
|
||||
JSON::Group *UI::Dashboard::getGPS(const int index) { return getGroupWidget(m_gpsWidgets, index); }
|
||||
JSON::Dataset *UI::Dashboard::getBar(const int index) { return getDatasetWidget(m_barWidgets, index); }
|
||||
JSON::Dataset *UI::Dashboard::getFFT(const int index) { return getDatasetWidget(m_fftWidgets, index); }
|
||||
JSON::Dataset *UI::Dashboard::getPlot(const int index) { return getDatasetWidget(m_plotWidgets, index); }
|
||||
JSON::Group *UI::Dashboard::getGroups(const int index) { return getGroupWidget(m_groupWidgets, index); }
|
||||
JSON::Dataset *UI::Dashboard::getGauge(const int index) { return getDatasetWidget(m_gaugeWidgets, index); }
|
||||
JSON::Group *UI::Dashboard::getGyroscope(const int index) { return getGroupWidget(m_gyroscopeWidgets, index); }
|
||||
JSON::Dataset *UI::Dashboard::getCompass(const int index) { return getDatasetWidget(m_compassWidgets, index); }
|
||||
JSON::Group *UI::Dashboard::getMultiplot(const int index) { return getGroupWidget(m_multiPlotWidgets, index); }
|
||||
JSON::Group *UI::Dashboard::getAccelerometer(const int index) { return getGroupWidget(m_accelerometerWidgets, index); }
|
||||
// clang-format on
|
||||
|
||||
//----------------------------------------------------------------------------------------
|
||||
@ -110,7 +103,7 @@ JSON::Group *Dashboard::getAccelerometer(const int index) { return getGroupWidge
|
||||
/**
|
||||
* Returns the title of the current JSON project/frame.
|
||||
*/
|
||||
QString Dashboard::title()
|
||||
QString UI::Dashboard::title()
|
||||
{
|
||||
return m_latestFrame.title();
|
||||
}
|
||||
@ -118,7 +111,7 @@ QString Dashboard::title()
|
||||
/**
|
||||
* Returns @c true if there is any data available to generate the QML dashboard.
|
||||
*/
|
||||
bool Dashboard::available()
|
||||
bool UI::Dashboard::available()
|
||||
{
|
||||
return totalWidgetCount() > 0;
|
||||
}
|
||||
@ -126,7 +119,7 @@ bool Dashboard::available()
|
||||
/**
|
||||
* Returns the number of points displayed by the graphs
|
||||
*/
|
||||
int Dashboard::points() const
|
||||
int UI::Dashboard::points() const
|
||||
{
|
||||
return m_points;
|
||||
}
|
||||
@ -134,7 +127,7 @@ int Dashboard::points() const
|
||||
/**
|
||||
* Returns the number of decimal digits displayed by the widgets
|
||||
*/
|
||||
int Dashboard::precision() const
|
||||
int UI::Dashboard::precision() const
|
||||
{
|
||||
return m_precision;
|
||||
}
|
||||
@ -143,7 +136,7 @@ int Dashboard::precision() const
|
||||
* Returns @c true if the current JSON frame is valid and ready-to-use by the QML
|
||||
* interface.
|
||||
*/
|
||||
bool Dashboard::frameValid() const
|
||||
bool UI::Dashboard::frameValid() const
|
||||
{
|
||||
return m_latestFrame.isValid();
|
||||
}
|
||||
@ -162,7 +155,7 @@ bool Dashboard::frameValid() const
|
||||
* be careful to sincronize the order of the widgets in order to allow the global-index
|
||||
* system to work correctly.
|
||||
*/
|
||||
int Dashboard::totalWidgetCount() const
|
||||
int UI::Dashboard::totalWidgetCount() const
|
||||
{
|
||||
// clang-format off
|
||||
const int count =
|
||||
@ -183,17 +176,17 @@ int Dashboard::totalWidgetCount() const
|
||||
}
|
||||
|
||||
// clang-format off
|
||||
int Dashboard::gpsCount() const { return m_gpsWidgets.count(); }
|
||||
int Dashboard::ledCount() const { return m_ledWidgets.count(); }
|
||||
int Dashboard::barCount() const { return m_barWidgets.count(); }
|
||||
int Dashboard::fftCount() const { return m_fftWidgets.count(); }
|
||||
int Dashboard::plotCount() const { return m_plotWidgets.count(); }
|
||||
int Dashboard::gaugeCount() const { return m_gaugeWidgets.count(); }
|
||||
int Dashboard::groupCount() const { return m_groupWidgets.count(); }
|
||||
int Dashboard::compassCount() const { return m_compassWidgets.count(); }
|
||||
int Dashboard::gyroscopeCount() const { return m_gyroscopeWidgets.count(); }
|
||||
int Dashboard::multiPlotCount() const { return m_multiPlotWidgets.count(); }
|
||||
int Dashboard::accelerometerCount() const { return m_accelerometerWidgets.count(); }
|
||||
int UI::Dashboard::gpsCount() const { return m_gpsWidgets.count(); }
|
||||
int UI::Dashboard::ledCount() const { return m_ledWidgets.count(); }
|
||||
int UI::Dashboard::barCount() const { return m_barWidgets.count(); }
|
||||
int UI::Dashboard::fftCount() const { return m_fftWidgets.count(); }
|
||||
int UI::Dashboard::plotCount() const { return m_plotWidgets.count(); }
|
||||
int UI::Dashboard::gaugeCount() const { return m_gaugeWidgets.count(); }
|
||||
int UI::Dashboard::groupCount() const { return m_groupWidgets.count(); }
|
||||
int UI::Dashboard::compassCount() const { return m_compassWidgets.count(); }
|
||||
int UI::Dashboard::gyroscopeCount() const { return m_gyroscopeWidgets.count(); }
|
||||
int UI::Dashboard::multiPlotCount() const { return m_multiPlotWidgets.count(); }
|
||||
int UI::Dashboard::accelerometerCount() const { return m_accelerometerWidgets.count(); }
|
||||
// clang-format on
|
||||
|
||||
//----------------------------------------------------------------------------------------
|
||||
@ -207,7 +200,7 @@ int Dashboard::accelerometerCount() const { return m_accelerometerWidgets.count(
|
||||
* We need to be careful to sincronize the order of the widgets in order to allow
|
||||
* the global-index system to work correctly.
|
||||
*/
|
||||
StringList Dashboard::widgetTitles() const
|
||||
StringList UI::Dashboard::widgetTitles() const
|
||||
{
|
||||
// Warning: maintain same order as the view option repeaters in ViewOptions.qml!
|
||||
|
||||
@ -244,7 +237,7 @@ StringList Dashboard::widgetTitles() const
|
||||
* We need to be careful to sincronize the order of the widgets in order to allow
|
||||
* the global-index system to work correctly.
|
||||
*/
|
||||
int Dashboard::relativeIndex(const int globalIndex) const
|
||||
int UI::Dashboard::relativeIndex(const int globalIndex) const
|
||||
{
|
||||
//
|
||||
// Warning: relative widget index should be calculated using the same order as defined
|
||||
@ -327,7 +320,7 @@ int Dashboard::relativeIndex(const int globalIndex) const
|
||||
* We need to be careful to sincronize the order of the widgets in order to allow
|
||||
* the global-index system to work correctly.
|
||||
*/
|
||||
bool Dashboard::widgetVisible(const int globalIndex) const
|
||||
bool UI::Dashboard::widgetVisible(const int globalIndex) const
|
||||
{
|
||||
bool visible = false;
|
||||
auto index = relativeIndex(globalIndex);
|
||||
@ -391,7 +384,7 @@ bool Dashboard::widgetVisible(const int globalIndex) const
|
||||
* We need to be careful to sincronize the order of the widgets in order to allow
|
||||
* the global-index system to work correctly.
|
||||
*/
|
||||
QString Dashboard::widgetIcon(const int globalIndex) const
|
||||
QString UI::Dashboard::widgetIcon(const int globalIndex) const
|
||||
{
|
||||
switch (widgetType(globalIndex))
|
||||
{
|
||||
@ -464,7 +457,7 @@ QString Dashboard::widgetIcon(const int globalIndex) const
|
||||
* We need to be careful to sincronize the order of the widgets in order to allow
|
||||
* the global-index system to work correctly.
|
||||
*/
|
||||
UI::Dashboard::WidgetType Dashboard::widgetType(const int globalIndex) const
|
||||
UI::Dashboard::WidgetType UI::Dashboard::widgetType(const int globalIndex) const
|
||||
{
|
||||
//
|
||||
// Warning: relative widget index should be calculated using the same order as defined
|
||||
@ -539,17 +532,17 @@ UI::Dashboard::WidgetType Dashboard::widgetType(const int globalIndex) const
|
||||
//----------------------------------------------------------------------------------------
|
||||
|
||||
// clang-format off
|
||||
bool Dashboard::barVisible(const int index) const { return getVisibility(m_barVisibility, index); }
|
||||
bool Dashboard::fftVisible(const int index) const { return getVisibility(m_fftVisibility, index); }
|
||||
bool Dashboard::gpsVisible(const int index) const { return getVisibility(m_gpsVisibility, index); }
|
||||
bool Dashboard::ledVisible(const int index) const { return getVisibility(m_ledVisibility, index); }
|
||||
bool Dashboard::plotVisible(const int index) const { return getVisibility(m_plotVisibility, index); }
|
||||
bool Dashboard::groupVisible(const int index) const { return getVisibility(m_groupVisibility, index); }
|
||||
bool Dashboard::gaugeVisible(const int index) const { return getVisibility(m_gaugeVisibility, index); }
|
||||
bool Dashboard::compassVisible(const int index) const { return getVisibility(m_compassVisibility, index); }
|
||||
bool Dashboard::gyroscopeVisible(const int index) const { return getVisibility(m_gyroscopeVisibility, index); }
|
||||
bool Dashboard::multiPlotVisible(const int index) const { return getVisibility(m_multiPlotVisibility, index); }
|
||||
bool Dashboard::accelerometerVisible(const int index) const { return getVisibility(m_accelerometerVisibility, index); }
|
||||
bool UI::Dashboard::barVisible(const int index) const { return getVisibility(m_barVisibility, index); }
|
||||
bool UI::Dashboard::fftVisible(const int index) const { return getVisibility(m_fftVisibility, index); }
|
||||
bool UI::Dashboard::gpsVisible(const int index) const { return getVisibility(m_gpsVisibility, index); }
|
||||
bool UI::Dashboard::ledVisible(const int index) const { return getVisibility(m_ledVisibility, index); }
|
||||
bool UI::Dashboard::plotVisible(const int index) const { return getVisibility(m_plotVisibility, index); }
|
||||
bool UI::Dashboard::groupVisible(const int index) const { return getVisibility(m_groupVisibility, index); }
|
||||
bool UI::Dashboard::gaugeVisible(const int index) const { return getVisibility(m_gaugeVisibility, index); }
|
||||
bool UI::Dashboard::compassVisible(const int index) const { return getVisibility(m_compassVisibility, index); }
|
||||
bool UI::Dashboard::gyroscopeVisible(const int index) const { return getVisibility(m_gyroscopeVisibility, index); }
|
||||
bool UI::Dashboard::multiPlotVisible(const int index) const { return getVisibility(m_multiPlotVisibility, index); }
|
||||
bool UI::Dashboard::accelerometerVisible(const int index) const { return getVisibility(m_accelerometerVisibility, index); }
|
||||
// clang-format on
|
||||
|
||||
//----------------------------------------------------------------------------------------
|
||||
@ -557,24 +550,24 @@ bool Dashboard::accelerometerVisible(const int index) const { return getVisibili
|
||||
//----------------------------------------------------------------------------------------
|
||||
|
||||
// clang-format off
|
||||
StringList Dashboard::gpsTitles() const { return groupTitles(m_gpsWidgets); }
|
||||
StringList Dashboard::ledTitles() const { return groupTitles(m_ledWidgets); }
|
||||
StringList Dashboard::groupTitles() const { return groupTitles(m_groupWidgets); }
|
||||
StringList Dashboard::barTitles() const { return datasetTitles(m_barWidgets); }
|
||||
StringList Dashboard::fftTitles() const { return datasetTitles(m_fftWidgets); }
|
||||
StringList Dashboard::plotTitles() const { return datasetTitles(m_plotWidgets); }
|
||||
StringList Dashboard::gaugeTitles() const { return datasetTitles(m_gaugeWidgets); }
|
||||
StringList Dashboard::compassTitles() const { return datasetTitles(m_compassWidgets); }
|
||||
StringList Dashboard::gyroscopeTitles() const { return groupTitles(m_gyroscopeWidgets); }
|
||||
StringList Dashboard::multiPlotTitles() const { return groupTitles(m_multiPlotWidgets); }
|
||||
StringList Dashboard::accelerometerTitles() const { return groupTitles(m_accelerometerWidgets); }
|
||||
StringList UI::Dashboard::gpsTitles() const { return groupTitles(m_gpsWidgets); }
|
||||
StringList UI::Dashboard::ledTitles() const { return groupTitles(m_ledWidgets); }
|
||||
StringList UI::Dashboard::groupTitles() const { return groupTitles(m_groupWidgets); }
|
||||
StringList UI::Dashboard::barTitles() const { return datasetTitles(m_barWidgets); }
|
||||
StringList UI::Dashboard::fftTitles() const { return datasetTitles(m_fftWidgets); }
|
||||
StringList UI::Dashboard::plotTitles() const { return datasetTitles(m_plotWidgets); }
|
||||
StringList UI::Dashboard::gaugeTitles() const { return datasetTitles(m_gaugeWidgets); }
|
||||
StringList UI::Dashboard::compassTitles() const { return datasetTitles(m_compassWidgets); }
|
||||
StringList UI::Dashboard::gyroscopeTitles() const { return groupTitles(m_gyroscopeWidgets); }
|
||||
StringList UI::Dashboard::multiPlotTitles() const { return groupTitles(m_multiPlotWidgets); }
|
||||
StringList UI::Dashboard::accelerometerTitles() const { return groupTitles(m_accelerometerWidgets); }
|
||||
// clang-format on
|
||||
|
||||
//----------------------------------------------------------------------------------------
|
||||
// Plot & widget options
|
||||
//----------------------------------------------------------------------------------------
|
||||
|
||||
void Dashboard::setPoints(const int points)
|
||||
void UI::Dashboard::setPoints(const int points)
|
||||
{
|
||||
if (m_points != points)
|
||||
{
|
||||
@ -595,7 +588,7 @@ void Dashboard::setPoints(const int points)
|
||||
}
|
||||
}
|
||||
|
||||
void Dashboard::setPrecision(const int precision)
|
||||
void UI::Dashboard::setPrecision(const int precision)
|
||||
{
|
||||
if (m_precision != precision)
|
||||
{
|
||||
@ -609,17 +602,17 @@ void Dashboard::setPrecision(const int precision)
|
||||
//----------------------------------------------------------------------------------------
|
||||
|
||||
// clang-format off
|
||||
void Dashboard::setBarVisible(const int i, const bool v) { setVisibility(m_barVisibility, i, v); }
|
||||
void Dashboard::setFFTVisible(const int i, const bool v) { setVisibility(m_fftVisibility, i, v); }
|
||||
void Dashboard::setGpsVisible(const int i, const bool v) { setVisibility(m_gpsVisibility, i, v); }
|
||||
void Dashboard::setLedVisible(const int i, const bool v) { setVisibility(m_ledVisibility, i, v); }
|
||||
void Dashboard::setPlotVisible(const int i, const bool v) { setVisibility(m_plotVisibility, i, v); }
|
||||
void Dashboard::setGroupVisible(const int i, const bool v) { setVisibility(m_groupVisibility, i, v); }
|
||||
void Dashboard::setGaugeVisible(const int i, const bool v) { setVisibility(m_gaugeVisibility, i, v); }
|
||||
void Dashboard::setCompassVisible(const int i, const bool v) { setVisibility(m_compassVisibility, i, v); }
|
||||
void Dashboard::setGyroscopeVisible(const int i, const bool v) { setVisibility(m_gyroscopeVisibility, i, v); }
|
||||
void Dashboard::setMultiplotVisible(const int i, const bool v) { setVisibility(m_multiPlotVisibility, i, v); }
|
||||
void Dashboard::setAccelerometerVisible(const int i, const bool v) { setVisibility(m_accelerometerVisibility, i, v); }
|
||||
void UI::Dashboard::setBarVisible(const int i, const bool v) { setVisibility(m_barVisibility, i, v); }
|
||||
void UI::Dashboard::setFFTVisible(const int i, const bool v) { setVisibility(m_fftVisibility, i, v); }
|
||||
void UI::Dashboard::setGpsVisible(const int i, const bool v) { setVisibility(m_gpsVisibility, i, v); }
|
||||
void UI::Dashboard::setLedVisible(const int i, const bool v) { setVisibility(m_ledVisibility, i, v); }
|
||||
void UI::Dashboard::setPlotVisible(const int i, const bool v) { setVisibility(m_plotVisibility, i, v); }
|
||||
void UI::Dashboard::setGroupVisible(const int i, const bool v) { setVisibility(m_groupVisibility, i, v); }
|
||||
void UI::Dashboard::setGaugeVisible(const int i, const bool v) { setVisibility(m_gaugeVisibility, i, v); }
|
||||
void UI::Dashboard::setCompassVisible(const int i, const bool v) { setVisibility(m_compassVisibility, i, v); }
|
||||
void UI::Dashboard::setGyroscopeVisible(const int i, const bool v) { setVisibility(m_gyroscopeVisibility, i, v); }
|
||||
void UI::Dashboard::setMultiplotVisible(const int i, const bool v) { setVisibility(m_multiPlotVisibility, i, v); }
|
||||
void UI::Dashboard::setAccelerometerVisible(const int i, const bool v) { setVisibility(m_accelerometerVisibility, i, v); }
|
||||
// clang-format on
|
||||
|
||||
//----------------------------------------------------------------------------------------
|
||||
@ -630,7 +623,7 @@ void Dashboard::setAccelerometerVisible(const int i, const bool v) { setVisibili
|
||||
* Removes all available data from the UI when the device is disconnected or the CSV
|
||||
* file is closed.
|
||||
*/
|
||||
void Dashboard::resetData()
|
||||
void UI::Dashboard::resetData()
|
||||
{
|
||||
// Make latest frame invalid
|
||||
m_jsonList.clear();
|
||||
@ -677,7 +670,7 @@ void Dashboard::resetData()
|
||||
/**
|
||||
* Interprets the most recent JSON frame & signals the UI to regenerate itself.
|
||||
*/
|
||||
void Dashboard::updateData()
|
||||
void UI::Dashboard::updateData()
|
||||
{
|
||||
// Check if we have anything to read
|
||||
if (m_jsonList.isEmpty())
|
||||
@ -785,7 +778,7 @@ void Dashboard::updateData()
|
||||
Q_EMIT updated();
|
||||
}
|
||||
|
||||
void Dashboard::updatePlots()
|
||||
void UI::Dashboard::updatePlots()
|
||||
{
|
||||
// Initialize arrays that contain pointers to the
|
||||
// datasets that need to be plotted.
|
||||
@ -878,7 +871,7 @@ void Dashboard::updatePlots()
|
||||
* Registers the JSON frame to the list of JSON frame vectors, which is later used to
|
||||
* update widgets & graphs
|
||||
*/
|
||||
void Dashboard::processLatestJSON(const JFI_Object &frameInfo)
|
||||
void UI::Dashboard::processLatestJSON(const JFI_Object &frameInfo)
|
||||
{
|
||||
m_jsonList.append(frameInfo);
|
||||
}
|
||||
@ -893,7 +886,7 @@ void Dashboard::processLatestJSON(const JFI_Object &frameInfo)
|
||||
* @note We return a vector with a single group item because we want to display a title on
|
||||
* the window without breaking the current software architecture.
|
||||
*/
|
||||
QVector<JSON::Group *> Dashboard::getLEDWidgets() const
|
||||
QVector<JSON::Group *> UI::Dashboard::getLEDWidgets() const
|
||||
{
|
||||
QVector<JSON::Dataset *> widgets;
|
||||
Q_FOREACH (auto group, m_latestFrame.groups())
|
||||
@ -920,7 +913,7 @@ QVector<JSON::Group *> Dashboard::getLEDWidgets() const
|
||||
/**
|
||||
* Returns a vector with all the datasets that need to be shown in the FFT widgets.
|
||||
*/
|
||||
QVector<JSON::Dataset *> Dashboard::getFFTWidgets() const
|
||||
QVector<JSON::Dataset *> UI::Dashboard::getFFTWidgets() const
|
||||
{
|
||||
QVector<JSON::Dataset *> widgets;
|
||||
Q_FOREACH (auto group, m_latestFrame.groups())
|
||||
@ -938,7 +931,7 @@ QVector<JSON::Dataset *> Dashboard::getFFTWidgets() const
|
||||
/**
|
||||
* Returns a vector with all the datasets that need to be plotted.
|
||||
*/
|
||||
QVector<JSON::Dataset *> Dashboard::getPlotWidgets() const
|
||||
QVector<JSON::Dataset *> UI::Dashboard::getPlotWidgets() const
|
||||
{
|
||||
QVector<JSON::Dataset *> widgets;
|
||||
Q_FOREACH (auto group, m_latestFrame.groups())
|
||||
@ -957,7 +950,7 @@ QVector<JSON::Dataset *> Dashboard::getPlotWidgets() const
|
||||
* Returns a vector with all the groups that implement the widget with the specied
|
||||
* @a handle.
|
||||
*/
|
||||
QVector<JSON::Group *> Dashboard::getWidgetGroups(const QString &handle) const
|
||||
QVector<JSON::Group *> UI::Dashboard::getWidgetGroups(const QString &handle) const
|
||||
{
|
||||
QVector<JSON::Group *> widgets;
|
||||
Q_FOREACH (auto group, m_latestFrame.groups())
|
||||
@ -973,7 +966,7 @@ QVector<JSON::Group *> Dashboard::getWidgetGroups(const QString &handle) const
|
||||
* Returns a vector with all the datasets that implement a widget with the specified
|
||||
* @a handle.
|
||||
*/
|
||||
QVector<JSON::Dataset *> Dashboard::getWidgetDatasets(const QString &handle) const
|
||||
QVector<JSON::Dataset *> UI::Dashboard::getWidgetDatasets(const QString &handle) const
|
||||
{
|
||||
QVector<JSON::Dataset *> widgets;
|
||||
Q_FOREACH (auto group, m_latestFrame.groups())
|
||||
@ -991,7 +984,7 @@ QVector<JSON::Dataset *> Dashboard::getWidgetDatasets(const QString &handle) con
|
||||
/**
|
||||
* Returns the titles of the datasets contained in the specified @a vector.
|
||||
*/
|
||||
StringList Dashboard::datasetTitles(const QVector<JSON::Dataset *> &vector) const
|
||||
StringList UI::Dashboard::datasetTitles(const QVector<JSON::Dataset *> &vector) const
|
||||
{
|
||||
StringList list;
|
||||
Q_FOREACH (auto set, vector)
|
||||
@ -1003,7 +996,7 @@ StringList Dashboard::datasetTitles(const QVector<JSON::Dataset *> &vector) cons
|
||||
/**
|
||||
* Returns the titles of the groups contained in the specified @a vector.
|
||||
*/
|
||||
StringList Dashboard::groupTitles(const QVector<JSON::Group *> &vector) const
|
||||
StringList UI::Dashboard::groupTitles(const QVector<JSON::Group *> &vector) const
|
||||
{
|
||||
StringList list;
|
||||
Q_FOREACH (auto group, vector)
|
||||
@ -1016,7 +1009,7 @@ StringList Dashboard::groupTitles(const QVector<JSON::Group *> &vector) const
|
||||
* Returns @c true if the widget at the specifed @a index of the @a vector should be
|
||||
* displayed in the QML user interface.
|
||||
*/
|
||||
bool Dashboard::getVisibility(const QVector<bool> &vector, const int index) const
|
||||
bool UI::Dashboard::getVisibility(const QVector<bool> &vector, const int index) const
|
||||
{
|
||||
if (index < vector.count())
|
||||
return vector[index];
|
||||
@ -1029,7 +1022,8 @@ bool Dashboard::getVisibility(const QVector<bool> &vector, const int index) cons
|
||||
* vector. Calling this function with @a visible set to @c false will hide the widget in
|
||||
* the QML user interface.
|
||||
*/
|
||||
void Dashboard::setVisibility(QVector<bool> &vector, const int index, const bool visible)
|
||||
void UI::Dashboard::setVisibility(QVector<bool> &vector, const int index,
|
||||
const bool visible)
|
||||
{
|
||||
if (index < vector.count())
|
||||
{
|
||||
@ -1042,8 +1036,8 @@ void Dashboard::setVisibility(QVector<bool> &vector, const int index, const bool
|
||||
* Returns a pointer to the group at the specified @a index of the given @a vector.
|
||||
* If the @a index is invalid, then this function shall return a NULL pointer.
|
||||
*/
|
||||
JSON::Group *Dashboard::getGroupWidget(const QVector<JSON::Group *> &vector,
|
||||
const int index)
|
||||
JSON::Group *UI::Dashboard::getGroupWidget(const QVector<JSON::Group *> &vector,
|
||||
const int index)
|
||||
{
|
||||
if (index < vector.count())
|
||||
return vector.at(index);
|
||||
@ -1055,12 +1049,11 @@ JSON::Group *Dashboard::getGroupWidget(const QVector<JSON::Group *> &vector,
|
||||
* Returns a pointer to the dataset at the specified @a index of the given @a vector.
|
||||
* If the @a index is invalid, then this function shall return a NULL pointer.
|
||||
*/
|
||||
JSON::Dataset *Dashboard::getDatasetWidget(const QVector<JSON::Dataset *> &vector,
|
||||
const int index)
|
||||
JSON::Dataset *UI::Dashboard::getDatasetWidget(const QVector<JSON::Dataset *> &vector,
|
||||
const int index)
|
||||
{
|
||||
if (index < vector.count())
|
||||
return vector.at(index);
|
||||
|
||||
return Q_NULLPTR;
|
||||
}
|
||||
}
|
||||
|
@ -154,6 +154,13 @@ Q_SIGNALS:
|
||||
void widgetCountChanged();
|
||||
void widgetVisibilityChanged();
|
||||
|
||||
private:
|
||||
explicit Dashboard();
|
||||
Dashboard(Dashboard &&) = delete;
|
||||
Dashboard(const Dashboard &) = delete;
|
||||
Dashboard &operator=(Dashboard &&) = delete;
|
||||
Dashboard &operator=(const Dashboard &) = delete;
|
||||
|
||||
public:
|
||||
enum class WidgetType
|
||||
{
|
||||
@ -172,7 +179,7 @@ public:
|
||||
};
|
||||
Q_ENUM(WidgetType)
|
||||
|
||||
static Dashboard *getInstance();
|
||||
static Dashboard &instance();
|
||||
|
||||
QFont monoFont() const;
|
||||
JSON::Group *getLED(const int index);
|
||||
@ -262,8 +269,6 @@ private Q_SLOTS:
|
||||
void processLatestJSON(const JFI_Object &frameInfo);
|
||||
|
||||
private:
|
||||
Dashboard();
|
||||
|
||||
QVector<JSON::Group *> getLEDWidgets() const;
|
||||
QVector<JSON::Dataset *> getFFTWidgets() const;
|
||||
QVector<JSON::Dataset *> getPlotWidgets() const;
|
||||
|
@ -48,7 +48,7 @@ DashboardWidget::DashboardWidget(QQuickItem *parent)
|
||||
, m_isExternalWindow(false)
|
||||
{
|
||||
// clang-format off
|
||||
connect(Dashboard::getInstance(), &Dashboard::widgetVisibilityChanged,
|
||||
connect(&Dashboard::instance(), &Dashboard::widgetVisibilityChanged,
|
||||
this, &DashboardWidget::updateWidgetVisible);
|
||||
// clang-format on
|
||||
}
|
||||
@ -77,7 +77,7 @@ int DashboardWidget::widgetIndex() const
|
||||
*/
|
||||
int DashboardWidget::relativeIndex() const
|
||||
{
|
||||
return UI::Dashboard::getInstance()->relativeIndex(widgetIndex());
|
||||
return UI::Dashboard::instance().relativeIndex(widgetIndex());
|
||||
}
|
||||
|
||||
/**
|
||||
@ -93,7 +93,7 @@ bool DashboardWidget::widgetVisible() const
|
||||
*/
|
||||
QString DashboardWidget::widgetIcon() const
|
||||
{
|
||||
return UI::Dashboard::getInstance()->widgetIcon(widgetIndex());
|
||||
return UI::Dashboard::instance().widgetIcon(widgetIndex());
|
||||
}
|
||||
|
||||
/**
|
||||
@ -103,7 +103,7 @@ QString DashboardWidget::widgetTitle() const
|
||||
{
|
||||
if (widgetIndex() >= 0)
|
||||
{
|
||||
auto titles = UI::Dashboard::getInstance()->widgetTitles();
|
||||
auto titles = UI::Dashboard::instance().widgetTitles();
|
||||
if (widgetIndex() < titles.count())
|
||||
return titles.at(widgetIndex());
|
||||
}
|
||||
@ -128,7 +128,7 @@ bool DashboardWidget::isExternalWindow() const
|
||||
*/
|
||||
UI::Dashboard::WidgetType DashboardWidget::widgetType() const
|
||||
{
|
||||
return UI::Dashboard::getInstance()->widgetType(widgetIndex());
|
||||
return UI::Dashboard::instance().widgetType(widgetIndex());
|
||||
}
|
||||
|
||||
/**
|
||||
@ -148,7 +148,7 @@ void DashboardWidget::setVisible(const bool visible)
|
||||
*/
|
||||
void DashboardWidget::setWidgetIndex(const int index)
|
||||
{
|
||||
if (index < UI::Dashboard::getInstance()->totalWidgetCount() && index >= 0)
|
||||
if (index < UI::Dashboard::instance().totalWidgetCount() && index >= 0)
|
||||
{
|
||||
// Update widget index
|
||||
m_index = index;
|
||||
@ -231,7 +231,7 @@ void DashboardWidget::setIsExternalWindow(const bool isWindow)
|
||||
*/
|
||||
void DashboardWidget::updateWidgetVisible()
|
||||
{
|
||||
bool visible = UI::Dashboard::getInstance()->widgetVisible(widgetIndex());
|
||||
bool visible = UI::Dashboard::instance().widgetVisible(widgetIndex());
|
||||
|
||||
if (widgetVisible() != visible && !isExternalWindow())
|
||||
{
|
||||
|
@ -56,7 +56,7 @@ DeclarativeWidget::DeclarativeWidget(QQuickItem *parent)
|
||||
setFlag(ItemIsFocusScope, true);
|
||||
setFlag(ItemAcceptsInputMethod, true);
|
||||
setAcceptedMouseButtons(Qt::AllButtons);
|
||||
setFillColor(Misc::ThemeManager::getInstance()->base());
|
||||
setFillColor(Misc::ThemeManager::instance().base());
|
||||
|
||||
// clang-format off
|
||||
connect(this, &QQuickPaintedItem::widthChanged,
|
||||
|
@ -27,18 +27,15 @@
|
||||
#include <QtMath>
|
||||
#include <QResizeEvent>
|
||||
|
||||
namespace Widgets
|
||||
{
|
||||
|
||||
/**
|
||||
* Constructor function, configures widget style & signal/slot connections.
|
||||
*/
|
||||
Accelerometer::Accelerometer(const int index)
|
||||
Widgets::Accelerometer::Accelerometer(const int index)
|
||||
: m_index(index)
|
||||
{
|
||||
// Get pointers to Serial Studio modules
|
||||
const auto dash = UI::Dashboard::getInstance();
|
||||
const auto theme = Misc::ThemeManager::getInstance();
|
||||
const auto dash = &UI::Dashboard::instance();
|
||||
const auto theme = &Misc::ThemeManager::instance();
|
||||
|
||||
// Invalid index, abort initialization
|
||||
if (m_index < 0 || m_index >= dash->accelerometerCount())
|
||||
@ -81,14 +78,14 @@ Accelerometer::Accelerometer(const int index)
|
||||
* If the widget is disabled (e.g. the user hides it, or the external
|
||||
* window is hidden), then the widget shall ignore the update request.
|
||||
*/
|
||||
void Accelerometer::updateData()
|
||||
void Widgets::Accelerometer::updateData()
|
||||
{
|
||||
// Widget not enabled, do nothing
|
||||
if (!isEnabled())
|
||||
return;
|
||||
|
||||
// Update accelerometer values
|
||||
const auto accelerometer = UI::Dashboard::getInstance()->getAccelerometer(m_index);
|
||||
const auto accelerometer = UI::Dashboard::instance().getAccelerometer(m_index);
|
||||
if (accelerometer)
|
||||
{
|
||||
if (accelerometer->datasetCount() != 3)
|
||||
@ -118,10 +115,9 @@ void Accelerometer::updateData()
|
||||
|
||||
m_gauge.setValue(G);
|
||||
setValue(QString("%1 G").arg(
|
||||
QString::number(G, 'f', UI::Dashboard::getInstance()->precision())));
|
||||
QString::number(G, 'f', UI::Dashboard::instance().precision())));
|
||||
|
||||
// Repaint widget
|
||||
Q_EMIT updated();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -26,18 +26,15 @@
|
||||
|
||||
#include <QResizeEvent>
|
||||
|
||||
namespace Widgets
|
||||
{
|
||||
|
||||
/**
|
||||
* Constructor function, configures widget style & signal/slot connections.
|
||||
*/
|
||||
Bar::Bar(const int index)
|
||||
Widgets::Bar::Bar(const int index)
|
||||
: m_index(index)
|
||||
{
|
||||
// Get pointers to serial studio modules
|
||||
const auto dash = UI::Dashboard::getInstance();
|
||||
const auto theme = Misc::ThemeManager::getInstance();
|
||||
const auto dash = &UI::Dashboard::instance();
|
||||
const auto theme = &Misc::ThemeManager::instance();
|
||||
|
||||
// Invalid index, abort initialization
|
||||
if (m_index < 0 || m_index >= dash->barCount())
|
||||
@ -68,7 +65,7 @@ Bar::Bar(const int index)
|
||||
m_thermo.setFillBrush(QBrush(QColor(color)));
|
||||
|
||||
// Get initial properties from dataset
|
||||
const auto dataset = UI::Dashboard::getInstance()->getBar(m_index);
|
||||
const auto dataset = UI::Dashboard::instance().getBar(m_index);
|
||||
if (dataset)
|
||||
{
|
||||
m_thermo.setAlarmLevel(dataset->alarm());
|
||||
@ -91,20 +88,20 @@ Bar::Bar(const int index)
|
||||
* If the widget is disabled (e.g. the user hides it, or the external
|
||||
* window is hidden), then the widget shall ignore the update request.
|
||||
*/
|
||||
void Bar::updateData()
|
||||
void Widgets::Bar::updateData()
|
||||
{
|
||||
// Widget not enabled, do nothing
|
||||
if (!isEnabled())
|
||||
return;
|
||||
|
||||
// Update bar level
|
||||
const auto dataset = UI::Dashboard::getInstance()->getBar(m_index);
|
||||
const auto dataset = UI::Dashboard::instance().getBar(m_index);
|
||||
if (dataset)
|
||||
{
|
||||
const auto value = dataset->value().toDouble();
|
||||
m_thermo.setValue(value);
|
||||
setValue(QString("%1 %2").arg(
|
||||
QString::number(value, 'f', UI::Dashboard::getInstance()->precision()),
|
||||
QString::number(value, 'f', UI::Dashboard::instance().precision()),
|
||||
dataset->units()));
|
||||
|
||||
// Repaint widget
|
||||
@ -115,8 +112,7 @@ void Bar::updateData()
|
||||
/**
|
||||
* Resizes the thermo to fit the size of the parent window.
|
||||
*/
|
||||
void Bar::onResized()
|
||||
void Widgets::Bar::onResized()
|
||||
{
|
||||
m_thermo.setPipeWidth(width() * 0.25);
|
||||
}
|
||||
}
|
||||
|
@ -38,7 +38,7 @@ BaseWidget::BaseWidget()
|
||||
|
||||
// Set window palette
|
||||
QPalette palette;
|
||||
const auto theme = Misc::ThemeManager::getInstance();
|
||||
const auto theme = &Misc::ThemeManager::instance();
|
||||
palette.setColor(QPalette::Base, theme->widgetWindowBackground());
|
||||
palette.setColor(QPalette::Window, theme->widgetWindowBackground());
|
||||
setPalette(palette);
|
||||
@ -102,8 +102,8 @@ void BaseWidget::resizeEvent(QResizeEvent *event)
|
||||
auto height = event->size().height() - 48;
|
||||
|
||||
// Get fonts & calculate size
|
||||
auto labelFont = UI::Dashboard::getInstance()->monoFont();
|
||||
auto gaugeFont = UI::Dashboard::getInstance()->monoFont();
|
||||
auto labelFont = UI::Dashboard::instance().monoFont();
|
||||
auto gaugeFont = UI::Dashboard::instance().monoFont();
|
||||
labelFont.setPixelSize(qMax(8, width / 18));
|
||||
gaugeFont.setPixelSize(qMax(8, width / 24));
|
||||
|
||||
|
@ -28,18 +28,15 @@
|
||||
#include <QwtCompassScaleDraw>
|
||||
#include <QwtCompassMagnetNeedle>
|
||||
|
||||
namespace Widgets
|
||||
{
|
||||
|
||||
/**
|
||||
* Constructor function, configures widget style & signal/slot connections.
|
||||
*/
|
||||
Compass::Compass(const int index)
|
||||
Widgets::Compass::Compass(const int index)
|
||||
: m_index(index)
|
||||
{
|
||||
// Get pointers to serial studio modules
|
||||
const auto dash = UI::Dashboard::getInstance();
|
||||
const auto theme = Misc::ThemeManager::getInstance();
|
||||
const auto dash = &UI::Dashboard::instance();
|
||||
const auto theme = &Misc::ThemeManager::instance();
|
||||
|
||||
// Invalid index, abort initialization
|
||||
if (m_index < 0 || m_index >= dash->compassCount())
|
||||
@ -80,19 +77,19 @@ Compass::Compass(const int index)
|
||||
* If the widget is disabled (e.g. the user hides it, or the external
|
||||
* window is hidden), then the widget shall ignore the update request.
|
||||
*/
|
||||
void Compass::update()
|
||||
void Widgets::Compass::update()
|
||||
{
|
||||
// Widget not enabled, do nothing
|
||||
if (!isEnabled())
|
||||
return;
|
||||
|
||||
// Update compass heading
|
||||
const auto dataset = UI::Dashboard::getInstance()->getCompass(m_index);
|
||||
const auto dataset = UI::Dashboard::instance().getCompass(m_index);
|
||||
if (dataset)
|
||||
{
|
||||
auto value = dataset->value().toDouble();
|
||||
auto text = QString("%1°").arg(
|
||||
QString::number(value, 'f', UI::Dashboard::getInstance()->precision()));
|
||||
QString::number(value, 'f', UI::Dashboard::instance().precision()));
|
||||
m_compass.setValue(value);
|
||||
|
||||
if (text.length() == 2)
|
||||
@ -106,4 +103,3 @@ void Compass::update()
|
||||
Q_EMIT updated();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -27,8 +27,6 @@
|
||||
#include <QResizeEvent>
|
||||
#include <QRegularExpression>
|
||||
|
||||
namespace Widgets
|
||||
{
|
||||
#define EXEC_EVENT(pointer, function, event) \
|
||||
if (pointer) \
|
||||
{ \
|
||||
@ -44,12 +42,12 @@ namespace Widgets
|
||||
/**
|
||||
* Generates the user interface elements & layout
|
||||
*/
|
||||
DataGroup::DataGroup(const int index)
|
||||
Widgets::DataGroup::DataGroup(const int index)
|
||||
: m_index(index)
|
||||
{
|
||||
// Get pointers to serial studio modules
|
||||
const auto dash = UI::Dashboard::getInstance();
|
||||
const auto theme = Misc::ThemeManager::getInstance();
|
||||
const auto dash = &UI::Dashboard::instance();
|
||||
const auto theme = &Misc::ThemeManager::instance();
|
||||
|
||||
// Invalid index, abort initialization
|
||||
if (m_index < 0 || m_index >= dash->groupCount())
|
||||
@ -165,7 +163,7 @@ DataGroup::DataGroup(const int index)
|
||||
/**
|
||||
* Frees the memory allocated for each label that represents a dataset
|
||||
*/
|
||||
DataGroup::~DataGroup()
|
||||
Widgets::DataGroup::~DataGroup()
|
||||
{
|
||||
Q_FOREACH (auto icon, m_icons)
|
||||
delete icon;
|
||||
@ -191,14 +189,14 @@ DataGroup::~DataGroup()
|
||||
* If the widget is disabled (e.g. the user hides it, or the external
|
||||
* window is hidden), then the widget shall ignore the update request.
|
||||
*/
|
||||
void DataGroup::updateData()
|
||||
void Widgets::DataGroup::updateData()
|
||||
{
|
||||
// Widget not enabled, do nothing
|
||||
if (!isEnabled())
|
||||
return;
|
||||
|
||||
// Get group pointer
|
||||
const auto dash = UI::Dashboard::getInstance();
|
||||
const auto dash = &UI::Dashboard::instance();
|
||||
const auto group = dash->getGroups(m_index);
|
||||
if (!group)
|
||||
return;
|
||||
@ -233,10 +231,10 @@ void DataGroup::updateData()
|
||||
/**
|
||||
* Changes the size of the labels when the widget is resized
|
||||
*/
|
||||
void DataGroup::resizeEvent(QResizeEvent *event)
|
||||
void Widgets::DataGroup::resizeEvent(QResizeEvent *event)
|
||||
{
|
||||
auto width = event->size().width();
|
||||
QFont font = UI::Dashboard::getInstance()->monoFont();
|
||||
QFont font = UI::Dashboard::instance().monoFont();
|
||||
QFont icon = font;
|
||||
QFont valueFont = font;
|
||||
icon.setPixelSize(qMax(8, width / 16));
|
||||
@ -254,28 +252,27 @@ void DataGroup::resizeEvent(QResizeEvent *event)
|
||||
event->accept();
|
||||
}
|
||||
|
||||
void DataGroup::wheelEvent(QWheelEvent *event)
|
||||
void Widgets::DataGroup::wheelEvent(QWheelEvent *event)
|
||||
{
|
||||
EXEC_EVENT(m_scrollArea, wheelEvent, event);
|
||||
}
|
||||
|
||||
void DataGroup::mouseMoveEvent(QMouseEvent *event)
|
||||
void Widgets::DataGroup::mouseMoveEvent(QMouseEvent *event)
|
||||
{
|
||||
EXEC_EVENT(m_scrollArea, mouseMoveEvent, event);
|
||||
}
|
||||
|
||||
void DataGroup::mousePressEvent(QMouseEvent *event)
|
||||
void Widgets::DataGroup::mousePressEvent(QMouseEvent *event)
|
||||
{
|
||||
EXEC_EVENT(m_scrollArea, mousePressEvent, event);
|
||||
}
|
||||
|
||||
void DataGroup::mouseReleaseEvent(QMouseEvent *event)
|
||||
void Widgets::DataGroup::mouseReleaseEvent(QMouseEvent *event)
|
||||
{
|
||||
EXEC_EVENT(m_scrollArea, mouseReleaseEvent, event);
|
||||
}
|
||||
|
||||
void DataGroup::mouseDoubleClickEvent(QMouseEvent *event)
|
||||
void Widgets::DataGroup::mouseDoubleClickEvent(QMouseEvent *event)
|
||||
{
|
||||
EXEC_EVENT(m_scrollArea, mouseDoubleClickEvent, event);
|
||||
}
|
||||
}
|
||||
|
@ -24,19 +24,16 @@
|
||||
#include "UI/Dashboard.h"
|
||||
#include "Misc/ThemeManager.h"
|
||||
|
||||
namespace Widgets
|
||||
{
|
||||
|
||||
/**
|
||||
* Constructor function, configures widget style & signal/slot connections.
|
||||
*/
|
||||
FFTPlot::FFTPlot(const int index)
|
||||
Widgets::FFTPlot::FFTPlot(const int index)
|
||||
: m_size(0)
|
||||
, m_index(index)
|
||||
{
|
||||
// Get pointers to serial studio modules
|
||||
const auto dash = UI::Dashboard::getInstance();
|
||||
const auto theme = Misc::ThemeManager::getInstance();
|
||||
const auto dash = &UI::Dashboard::instance();
|
||||
const auto theme = &Misc::ThemeManager::instance();
|
||||
|
||||
// Initialize pointers to NULL
|
||||
m_fft = Q_NULLPTR;
|
||||
@ -90,7 +87,7 @@ FFTPlot::FFTPlot(const int index)
|
||||
m_curve.setPen(QColor(color), 2, Qt::SolidLine);
|
||||
|
||||
// Get dataset max freq. & calculate fft size
|
||||
const auto dataset = UI::Dashboard::getInstance()->getFFT(m_index);
|
||||
const auto dataset = UI::Dashboard::instance().getFFT(m_index);
|
||||
if (dataset)
|
||||
{
|
||||
// Calculate FFT size
|
||||
@ -137,7 +134,7 @@ FFTPlot::FFTPlot(const int index)
|
||||
/**
|
||||
* Destructor function
|
||||
*/
|
||||
FFTPlot::~FFTPlot()
|
||||
Widgets::FFTPlot::~FFTPlot()
|
||||
{
|
||||
free(m_fft);
|
||||
free(m_samples);
|
||||
@ -153,14 +150,14 @@ FFTPlot::~FFTPlot()
|
||||
* window is hidden), then the new data shall be saved to the plot
|
||||
* vector, but the widget shall not be redrawn.
|
||||
*/
|
||||
void FFTPlot::updateData()
|
||||
void Widgets::FFTPlot::updateData()
|
||||
{
|
||||
// Verify that FFT sample arrays are valid
|
||||
if (!m_samples || !m_fft)
|
||||
return;
|
||||
|
||||
// Replot
|
||||
const auto plotData = UI::Dashboard::getInstance()->fftPlotValues();
|
||||
const auto plotData = UI::Dashboard::instance().fftPlotValues();
|
||||
if (plotData->count() > m_index)
|
||||
{
|
||||
// Copy data to samples array
|
||||
@ -178,4 +175,3 @@ void FFTPlot::updateData()
|
||||
Q_EMIT updated();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -27,17 +27,15 @@
|
||||
|
||||
#include <googlemapadapter.h>
|
||||
|
||||
namespace Widgets
|
||||
{
|
||||
/**
|
||||
* Generates the user interface elements & layout
|
||||
*/
|
||||
GPS::GPS(const int index)
|
||||
Widgets::GPS::GPS(const int index)
|
||||
: m_index(index)
|
||||
{
|
||||
// Get pointers to serial studio modules
|
||||
const auto dash = UI::Dashboard::getInstance();
|
||||
const auto theme = Misc::ThemeManager::getInstance();
|
||||
const auto dash = &UI::Dashboard::instance();
|
||||
const auto theme = &Misc::ThemeManager::instance();
|
||||
|
||||
// Invalid index, abort initialization
|
||||
if (m_index < 0 || m_index >= dash->gpsCount())
|
||||
@ -111,14 +109,14 @@ GPS::GPS(const int index)
|
||||
* If the widget is disabled (e.g. the user hides it, or the external
|
||||
* window is hidden), then the widget shall ignore the update request.
|
||||
*/
|
||||
void GPS::updateData()
|
||||
void Widgets::GPS::updateData()
|
||||
{
|
||||
// Widget not enabled, do nothing
|
||||
if (!isEnabled())
|
||||
return;
|
||||
|
||||
// Get group pointer
|
||||
const auto dash = UI::Dashboard::getInstance();
|
||||
const auto dash = &UI::Dashboard::instance();
|
||||
const auto group = dash->getGPS(m_index);
|
||||
if (!group)
|
||||
return;
|
||||
@ -161,7 +159,7 @@ void GPS::updateData()
|
||||
/**
|
||||
* Changes the size of the map when the widget is resized
|
||||
*/
|
||||
void GPS::resizeEvent(QResizeEvent *event)
|
||||
void Widgets::GPS::resizeEvent(QResizeEvent *event)
|
||||
{
|
||||
const auto width = event->size().width();
|
||||
const auto height = event->size().height();
|
||||
@ -172,7 +170,7 @@ void GPS::resizeEvent(QResizeEvent *event)
|
||||
/**
|
||||
* Manually calls the zoom in / zoom out button clicks when the user presses on the widget
|
||||
*/
|
||||
void GPS::mousePressEvent(QMouseEvent *event)
|
||||
void Widgets::GPS::mousePressEvent(QMouseEvent *event)
|
||||
{
|
||||
// Get x and y coordinates relative to title widget
|
||||
auto x = event->x() - m_titleWidget.x();
|
||||
@ -195,4 +193,3 @@ void GPS::mousePressEvent(QMouseEvent *event)
|
||||
// Accept event
|
||||
event->accept();
|
||||
}
|
||||
}
|
||||
|
@ -24,18 +24,15 @@
|
||||
#include "UI/Dashboard.h"
|
||||
#include "Misc/ThemeManager.h"
|
||||
|
||||
namespace Widgets
|
||||
{
|
||||
|
||||
/**
|
||||
* Constructor function, configures widget style & signal/slot connections.
|
||||
*/
|
||||
Gauge::Gauge(const int index)
|
||||
Widgets::Gauge::Gauge(const int index)
|
||||
: m_index(index)
|
||||
{
|
||||
// Get pointers to Serial Studio modules
|
||||
const auto dash = UI::Dashboard::getInstance();
|
||||
const auto theme = Misc::ThemeManager::getInstance();
|
||||
const auto dash = &UI::Dashboard::instance();
|
||||
const auto theme = &Misc::ThemeManager::instance();
|
||||
|
||||
// Invalid index, abort initialization
|
||||
if (m_index < 0 || m_index >= dash->gaugeCount())
|
||||
@ -81,23 +78,22 @@ Gauge::Gauge(const int index)
|
||||
* If the widget is disabled (e.g. the user hides it, or the external
|
||||
* window is hidden), then the widget shall ignore the update request.
|
||||
*/
|
||||
void Gauge::updateData()
|
||||
void Widgets::Gauge::updateData()
|
||||
{
|
||||
// Widget not enabled, do nothing
|
||||
if (!isEnabled())
|
||||
return;
|
||||
|
||||
// Update gauge value
|
||||
const auto dataset = UI::Dashboard::getInstance()->getGauge(m_index);
|
||||
const auto dataset = UI::Dashboard::instance().getGauge(m_index);
|
||||
if (dataset)
|
||||
{
|
||||
const auto value = dataset->value().toDouble();
|
||||
m_gauge.setValue(dataset->value().toDouble());
|
||||
setValue(QString("%1 %2").arg(
|
||||
QString::number(value, 'f', UI::Dashboard::getInstance()->precision()),
|
||||
QString::number(value, 'f', UI::Dashboard::instance().precision()),
|
||||
dataset->units()));
|
||||
|
||||
Q_EMIT updated();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -26,19 +26,16 @@
|
||||
|
||||
#include <QResizeEvent>
|
||||
|
||||
namespace Widgets
|
||||
{
|
||||
|
||||
/**
|
||||
* Constructor function, configures widget style & signal/slot connections.
|
||||
*/
|
||||
Gyroscope::Gyroscope(const int index)
|
||||
Widgets::Gyroscope::Gyroscope(const int index)
|
||||
: m_index(index)
|
||||
, m_displayNum(0)
|
||||
{
|
||||
// Get pointers to Serial Studio modules
|
||||
const auto dash = UI::Dashboard::getInstance();
|
||||
const auto theme = Misc::ThemeManager::getInstance();
|
||||
const auto dash = &UI::Dashboard::instance();
|
||||
const auto theme = &Misc::ThemeManager::instance();
|
||||
|
||||
// Invalid index, abort initialization
|
||||
if (m_index < 0 || m_index >= dash->gyroscopeCount())
|
||||
@ -69,14 +66,14 @@ Gyroscope::Gyroscope(const int index)
|
||||
* If the widget is disabled (e.g. the user hides it, or the external
|
||||
* window is hidden), then the widget shall ignore the update request.
|
||||
*/
|
||||
void Gyroscope::updateData()
|
||||
void Widgets::Gyroscope::updateData()
|
||||
{
|
||||
// Widget not enabled, do nothing
|
||||
if (!isEnabled())
|
||||
return;
|
||||
|
||||
// Update gyroscope values
|
||||
const auto dash = UI::Dashboard::getInstance();
|
||||
const auto dash = &UI::Dashboard::instance();
|
||||
const auto gyro = dash->getGyroscope(m_index);
|
||||
if (gyro)
|
||||
{
|
||||
@ -110,7 +107,7 @@ void Gyroscope::updateData()
|
||||
}
|
||||
}
|
||||
|
||||
void Gyroscope::updateLabel()
|
||||
void Widgets::Gyroscope::updateLabel()
|
||||
{
|
||||
switch (m_displayNum)
|
||||
{
|
||||
@ -129,4 +126,3 @@ void Gyroscope::updateLabel()
|
||||
if (m_displayNum > 2)
|
||||
m_displayNum = 0;
|
||||
}
|
||||
}
|
||||
|
@ -26,18 +26,15 @@
|
||||
|
||||
#include <QResizeEvent>
|
||||
|
||||
namespace Widgets
|
||||
{
|
||||
|
||||
/**
|
||||
* Generates the user interface elements & layout
|
||||
*/
|
||||
LEDPanel::LEDPanel(const int index)
|
||||
Widgets::LEDPanel::LEDPanel(const int index)
|
||||
: m_index(index)
|
||||
{
|
||||
// Get pointers to serial studio modules
|
||||
const auto dash = UI::Dashboard::getInstance();
|
||||
const auto theme = Misc::ThemeManager::getInstance();
|
||||
const auto dash = &UI::Dashboard::instance();
|
||||
const auto theme = &Misc::ThemeManager::instance();
|
||||
|
||||
// Invalid index, abort initialization
|
||||
if (m_index < 0 || m_index >= dash->ledCount())
|
||||
@ -131,7 +128,7 @@ LEDPanel::LEDPanel(const int index)
|
||||
/**
|
||||
* Frees the memory allocated for each label and LED that represents a dataset
|
||||
*/
|
||||
LEDPanel::~LEDPanel()
|
||||
Widgets::LEDPanel::~LEDPanel()
|
||||
{
|
||||
Q_FOREACH (auto led, m_leds)
|
||||
delete led;
|
||||
@ -151,14 +148,14 @@ LEDPanel::~LEDPanel()
|
||||
* If the widget is disabled (e.g. the user hides it, or the external
|
||||
* window is hidden), then the widget shall ignore the update request.
|
||||
*/
|
||||
void LEDPanel::updateData()
|
||||
void Widgets::LEDPanel::updateData()
|
||||
{
|
||||
// Widget not enabled, do nothing
|
||||
if (!isEnabled())
|
||||
return;
|
||||
|
||||
// Get group pointer
|
||||
const auto dash = UI::Dashboard::getInstance();
|
||||
const auto dash = &UI::Dashboard::instance();
|
||||
const auto group = dash->getLED(m_index);
|
||||
if (!group)
|
||||
return;
|
||||
@ -186,10 +183,10 @@ void LEDPanel::updateData()
|
||||
/**
|
||||
* Changes the size of the labels when the widget is resized
|
||||
*/
|
||||
void LEDPanel::resizeEvent(QResizeEvent *event)
|
||||
void Widgets::LEDPanel::resizeEvent(QResizeEvent *event)
|
||||
{
|
||||
const auto width = event->size().width();
|
||||
QFont font = UI::Dashboard::getInstance()->monoFont();
|
||||
QFont font = UI::Dashboard::instance().monoFont();
|
||||
font.setPixelSize(qMax(8, width / 24));
|
||||
const auto fHeight = QFontMetrics(font).height() * 1.5;
|
||||
|
||||
@ -201,4 +198,3 @@ void LEDPanel::resizeEvent(QResizeEvent *event)
|
||||
|
||||
event->accept();
|
||||
}
|
||||
}
|
||||
|
@ -25,18 +25,15 @@
|
||||
#include "UI/Dashboard.h"
|
||||
#include "Misc/ThemeManager.h"
|
||||
|
||||
namespace Widgets
|
||||
{
|
||||
|
||||
/**
|
||||
* Constructor function, configures widget style & signal/slot connections.
|
||||
*/
|
||||
MultiPlot::MultiPlot(const int index)
|
||||
Widgets::MultiPlot::MultiPlot(const int index)
|
||||
: m_index(index)
|
||||
{
|
||||
// Get pointers to serial studio modules
|
||||
const auto dash = UI::Dashboard::getInstance();
|
||||
const auto theme = Misc::ThemeManager::getInstance();
|
||||
const auto dash = &UI::Dashboard::instance();
|
||||
const auto theme = &Misc::ThemeManager::instance();
|
||||
|
||||
// Invalid index, abort initialization
|
||||
if (m_index < 0 || m_index >= dash->multiPlotCount())
|
||||
@ -137,10 +134,10 @@ MultiPlot::MultiPlot(const int index)
|
||||
* window is hidden), then the new data shall be saved to the plot
|
||||
* vectors, but the widget shall not be redrawn.
|
||||
*/
|
||||
void MultiPlot::updateData()
|
||||
void Widgets::MultiPlot::updateData()
|
||||
{
|
||||
// Get group
|
||||
const auto group = UI::Dashboard::getInstance()->getMultiplot(m_index);
|
||||
const auto group = UI::Dashboard::instance().getMultiplot(m_index);
|
||||
if (!group)
|
||||
return;
|
||||
|
||||
@ -188,14 +185,14 @@ void MultiPlot::updateData()
|
||||
/**
|
||||
* Updates the number of horizontal divisions of the plot
|
||||
*/
|
||||
void MultiPlot::updateRange()
|
||||
void Widgets::MultiPlot::updateRange()
|
||||
{
|
||||
// Get pointer to dashboard manager
|
||||
const auto dash = UI::Dashboard::getInstance();
|
||||
const auto dash = &UI::Dashboard::instance();
|
||||
|
||||
// Set number of points
|
||||
m_yData.clear();
|
||||
const auto group = UI::Dashboard::getInstance()->getMultiplot(m_index);
|
||||
const auto group = UI::Dashboard::instance().getMultiplot(m_index);
|
||||
for (int i = 0; i < dash->points(); ++i)
|
||||
{
|
||||
m_yData.append(PlotData());
|
||||
@ -212,4 +209,3 @@ void MultiPlot::updateRange()
|
||||
// Repaint widget
|
||||
Q_EMIT updated();
|
||||
}
|
||||
}
|
||||
|
@ -25,21 +25,18 @@
|
||||
#include "UI/Dashboard.h"
|
||||
#include "Misc/ThemeManager.h"
|
||||
|
||||
namespace Widgets
|
||||
{
|
||||
|
||||
/**
|
||||
* Constructor function, configures widget style & signal/slot connections.
|
||||
*/
|
||||
Plot::Plot(const int index)
|
||||
Widgets::Plot::Plot(const int index)
|
||||
: m_index(index)
|
||||
, m_min(INT_MAX)
|
||||
, m_max(INT_MIN)
|
||||
, m_autoscale(true)
|
||||
{
|
||||
// Get pointers to serial studio modules
|
||||
const auto dash = UI::Dashboard::getInstance();
|
||||
const auto theme = Misc::ThemeManager::getInstance();
|
||||
const auto dash = &UI::Dashboard::instance();
|
||||
const auto theme = &Misc::ThemeManager::instance();
|
||||
|
||||
// Invalid index, abort initialization
|
||||
if (m_index < 0 || m_index >= dash->plotCount())
|
||||
@ -90,7 +87,7 @@ Plot::Plot(const int index)
|
||||
m_curve.setPen(QColor(color), 2, Qt::SolidLine);
|
||||
|
||||
// Get dataset units
|
||||
const auto dataset = UI::Dashboard::getInstance()->getPlot(m_index);
|
||||
const auto dataset = UI::Dashboard::instance().getPlot(m_index);
|
||||
if (dataset)
|
||||
{
|
||||
// Update graph scale
|
||||
@ -135,14 +132,14 @@ Plot::Plot(const int index)
|
||||
* window is hidden), then the new data shall be saved to the plot
|
||||
* vector, but the widget shall not be redrawn.
|
||||
*/
|
||||
void Plot::updateData()
|
||||
void Widgets::Plot::updateData()
|
||||
{
|
||||
// Widget not enabled, do not redraw
|
||||
if (!isEnabled())
|
||||
return;
|
||||
|
||||
// Get new data
|
||||
const auto plotData = UI::Dashboard::getInstance()->linearPlotValues();
|
||||
const auto plotData = UI::Dashboard::instance().linearPlotValues();
|
||||
if (plotData->count() > m_index)
|
||||
{
|
||||
// Check if we need to update graph scale
|
||||
@ -214,10 +211,10 @@ void Plot::updateData()
|
||||
/**
|
||||
* Updates the number of horizontal divisions of the plot
|
||||
*/
|
||||
void Plot::updateRange()
|
||||
void Widgets::Plot::updateRange()
|
||||
{
|
||||
// Get pointer to dashboard manager
|
||||
const auto dash = UI::Dashboard::getInstance();
|
||||
const auto dash = &UI::Dashboard::instance();
|
||||
|
||||
// Clear Y-axis data
|
||||
PlotData tempYData;
|
||||
@ -232,4 +229,3 @@ void Plot::updateRange()
|
||||
// Repaint widget
|
||||
Q_EMIT updated();
|
||||
}
|
||||
}
|
||||
|
@ -27,9 +27,6 @@
|
||||
|
||||
#include "Terminal.h"
|
||||
|
||||
namespace Widgets
|
||||
{
|
||||
|
||||
//----------------------------------------------------------------------------------------
|
||||
// QML PlainTextEdit implementation
|
||||
//----------------------------------------------------------------------------------------
|
||||
@ -37,7 +34,7 @@ namespace Widgets
|
||||
/**
|
||||
* Constructor function
|
||||
*/
|
||||
Terminal::Terminal(QQuickItem *parent)
|
||||
Widgets::Terminal::Terminal(QQuickItem *parent)
|
||||
: UI::DeclarativeWidget(parent)
|
||||
, m_autoscroll(true)
|
||||
, m_emulateVt100(false)
|
||||
@ -53,7 +50,7 @@ Terminal::Terminal(QQuickItem *parent)
|
||||
|
||||
// Set widget palette
|
||||
QPalette palette;
|
||||
const auto theme = Misc::ThemeManager::getInstance();
|
||||
const auto theme = &Misc::ThemeManager::instance();
|
||||
palette.setColor(QPalette::Text, theme->consoleText());
|
||||
palette.setColor(QPalette::Base, theme->consoleBase());
|
||||
palette.setColor(QPalette::Button, theme->consoleButton());
|
||||
@ -66,8 +63,8 @@ Terminal::Terminal(QQuickItem *parent)
|
||||
m_textEdit.setPalette(palette);
|
||||
|
||||
// Connect console signals (doing this on QML uses about 50% of UI thread time)
|
||||
const auto console = IO::Console::getInstance();
|
||||
connect(console, &IO::Console::stringReceived, this, &Terminal::insertText);
|
||||
const auto console = &IO::Console::instance();
|
||||
connect(console, &IO::Console::stringReceived, this, &Widgets::Terminal::insertText);
|
||||
|
||||
// React to widget events
|
||||
connect(&m_textEdit, SIGNAL(copyAvailable(bool)), this, SLOT(setCopyAvailable(bool)));
|
||||
@ -76,7 +73,7 @@ Terminal::Terminal(QQuickItem *parent)
|
||||
/**
|
||||
* Returns the font used by the QPlainTextEdit widget
|
||||
*/
|
||||
QFont Terminal::font() const
|
||||
QFont Widgets::Terminal::font() const
|
||||
{
|
||||
return m_textEdit.font();
|
||||
}
|
||||
@ -84,7 +81,7 @@ QFont Terminal::font() const
|
||||
/**
|
||||
* Returns the plain text of the QPlainTextEdit widget
|
||||
*/
|
||||
QString Terminal::text() const
|
||||
QString Widgets::Terminal::text() const
|
||||
{
|
||||
return m_textEdit.toPlainText();
|
||||
}
|
||||
@ -92,7 +89,7 @@ QString Terminal::text() const
|
||||
/**
|
||||
* Returns @c true if the text document is empty
|
||||
*/
|
||||
bool Terminal::empty() const
|
||||
bool Widgets::Terminal::empty() const
|
||||
{
|
||||
return m_textEdit.document()->isEmpty();
|
||||
}
|
||||
@ -100,7 +97,7 @@ bool Terminal::empty() const
|
||||
/**
|
||||
* Returns @c true if the widget is set to read-only
|
||||
*/
|
||||
bool Terminal::readOnly() const
|
||||
bool Widgets::Terminal::readOnly() const
|
||||
{
|
||||
return m_textEdit.isReadOnly();
|
||||
}
|
||||
@ -109,7 +106,7 @@ bool Terminal::readOnly() const
|
||||
* Returns @c true if the widget shall scroll automatically to the bottom when new
|
||||
* text is appended to the widget.
|
||||
*/
|
||||
bool Terminal::autoscroll() const
|
||||
bool Widgets::Terminal::autoscroll() const
|
||||
{
|
||||
return m_autoscroll;
|
||||
}
|
||||
@ -117,7 +114,7 @@ bool Terminal::autoscroll() const
|
||||
/**
|
||||
* Returns the palette used by the QPlainTextEdit widget
|
||||
*/
|
||||
QPalette Terminal::palette() const
|
||||
QPalette Widgets::Terminal::palette() const
|
||||
{
|
||||
return m_textEdit.palette();
|
||||
}
|
||||
@ -126,7 +123,7 @@ QPalette Terminal::palette() const
|
||||
* Returns the wrap mode of the QPlainTextEdit casted to an integer type (so that it
|
||||
* can be used from the QML interface).
|
||||
*/
|
||||
int Terminal::wordWrapMode() const
|
||||
int Widgets::Terminal::wordWrapMode() const
|
||||
{
|
||||
return static_cast<int>(m_textEdit.wordWrapMode());
|
||||
}
|
||||
@ -134,7 +131,7 @@ int Terminal::wordWrapMode() const
|
||||
/**
|
||||
* Returns the width of the vertical scrollbar
|
||||
*/
|
||||
int Terminal::scrollbarWidth() const
|
||||
int Widgets::Terminal::scrollbarWidth() const
|
||||
{
|
||||
return m_textEdit.verticalScrollBar()->width();
|
||||
}
|
||||
@ -143,7 +140,7 @@ int Terminal::scrollbarWidth() const
|
||||
* Returns @c true if the user is able to copy any text from the document. This value is
|
||||
* updated through the copyAvailable() signal sent by the QPlainTextEdit.
|
||||
*/
|
||||
bool Terminal::copyAvailable() const
|
||||
bool Widgets::Terminal::copyAvailable() const
|
||||
{
|
||||
return m_copyAvailable;
|
||||
}
|
||||
@ -151,7 +148,7 @@ bool Terminal::copyAvailable() const
|
||||
/**
|
||||
* Returns @c true if the QPlainTextEdit widget is enabled
|
||||
*/
|
||||
bool Terminal::widgetEnabled() const
|
||||
bool Widgets::Terminal::widgetEnabled() const
|
||||
{
|
||||
return m_textEdit.isEnabled();
|
||||
}
|
||||
@ -162,7 +159,7 @@ bool Terminal::widgetEnabled() const
|
||||
* the end of the document. Otherwise, if set to false, the plain text edit scrolls the
|
||||
* smallest amount possible to ensure the cursor is visible.
|
||||
*/
|
||||
bool Terminal::centerOnScroll() const
|
||||
bool Widgets::Terminal::centerOnScroll() const
|
||||
{
|
||||
return m_textEdit.centerOnScroll();
|
||||
}
|
||||
@ -171,7 +168,7 @@ bool Terminal::centerOnScroll() const
|
||||
* Returns true if the control shall parse basic VT-100 escape secuences. This can be
|
||||
* useful if you need to interface with a shell/CLI from Serial Studio.
|
||||
*/
|
||||
bool Terminal::vt100emulation() const
|
||||
bool Widgets::Terminal::vt100emulation() const
|
||||
{
|
||||
return m_emulateVt100;
|
||||
}
|
||||
@ -181,7 +178,7 @@ bool Terminal::vt100emulation() const
|
||||
* Users are only able to undo or redo actions if this property is true, and if there is
|
||||
* an action that can be undone (or redone).
|
||||
*/
|
||||
bool Terminal::undoRedoEnabled() const
|
||||
bool Widgets::Terminal::undoRedoEnabled() const
|
||||
{
|
||||
return m_textEdit.isUndoRedoEnabled();
|
||||
}
|
||||
@ -196,7 +193,7 @@ bool Terminal::undoRedoEnabled() const
|
||||
* A negative or zero value specifies that the document may contain an unlimited amount
|
||||
* of blocks.
|
||||
*/
|
||||
int Terminal::maximumBlockCount() const
|
||||
int Widgets::Terminal::maximumBlockCount() const
|
||||
{
|
||||
return m_textEdit.maximumBlockCount();
|
||||
}
|
||||
@ -207,7 +204,7 @@ int Terminal::maximumBlockCount() const
|
||||
* Setting this property makes the editor display a grayed-out placeholder text as long as
|
||||
* the document is empty.
|
||||
*/
|
||||
QString Terminal::placeholderText() const
|
||||
QString Widgets::Terminal::placeholderText() const
|
||||
{
|
||||
return m_textEdit.placeholderText();
|
||||
}
|
||||
@ -215,7 +212,7 @@ QString Terminal::placeholderText() const
|
||||
/**
|
||||
* Returns the pointer to the text document
|
||||
*/
|
||||
QTextDocument *Terminal::document() const
|
||||
QTextDocument *Widgets::Terminal::document() const
|
||||
{
|
||||
return m_textEdit.document();
|
||||
}
|
||||
@ -223,7 +220,7 @@ QTextDocument *Terminal::document() const
|
||||
/**
|
||||
* Copies any selected text to the clipboard.
|
||||
*/
|
||||
void Terminal::copy()
|
||||
void Widgets::Terminal::copy()
|
||||
{
|
||||
m_textEdit.copy();
|
||||
}
|
||||
@ -231,7 +228,7 @@ void Terminal::copy()
|
||||
/**
|
||||
* Deletes all the text in the text edit.
|
||||
*/
|
||||
void Terminal::clear()
|
||||
void Widgets::Terminal::clear()
|
||||
{
|
||||
m_textEdit.clear();
|
||||
updateScrollbarVisibility();
|
||||
@ -243,7 +240,7 @@ void Terminal::clear()
|
||||
/**
|
||||
* Selects all the text of the text edit.
|
||||
*/
|
||||
void Terminal::selectAll()
|
||||
void Widgets::Terminal::selectAll()
|
||||
{
|
||||
m_textEdit.selectAll();
|
||||
update();
|
||||
@ -252,7 +249,7 @@ void Terminal::selectAll()
|
||||
/**
|
||||
* Clears the text selection
|
||||
*/
|
||||
void Terminal::clearSelection()
|
||||
void Widgets::Terminal::clearSelection()
|
||||
{
|
||||
auto cursor = QTextCursor(m_textEdit.document());
|
||||
cursor.clearSelection();
|
||||
@ -267,7 +264,7 @@ void Terminal::clearSelection()
|
||||
* In a read-only text edit the user can only navigate through the text and select text;
|
||||
* modifying the text is not possible.
|
||||
*/
|
||||
void Terminal::setReadOnly(const bool ro)
|
||||
void Widgets::Terminal::setReadOnly(const bool ro)
|
||||
{
|
||||
m_textEdit.setReadOnly(ro);
|
||||
update();
|
||||
@ -278,7 +275,7 @@ void Terminal::setReadOnly(const bool ro)
|
||||
/**
|
||||
* Changes the font used to display the text of the text edit.
|
||||
*/
|
||||
void Terminal::setFont(const QFont &font)
|
||||
void Widgets::Terminal::setFont(const QFont &font)
|
||||
{
|
||||
m_textEdit.setFont(font);
|
||||
updateScrollbarVisibility();
|
||||
@ -293,7 +290,7 @@ void Terminal::setFont(const QFont &font)
|
||||
* If @c autoscroll() is enabled, this function shall also update the scrollbar position
|
||||
* to scroll to the bottom of the text.
|
||||
*/
|
||||
void Terminal::append(const QString &text)
|
||||
void Widgets::Terminal::append(const QString &text)
|
||||
{
|
||||
m_textEdit.appendPlainText(text);
|
||||
updateScrollbarVisibility();
|
||||
@ -311,7 +308,7 @@ void Terminal::append(const QString &text)
|
||||
* If @c autoscroll() is enabled, this function shall also update the scrollbar position
|
||||
* to scroll to the bottom of the text.
|
||||
*/
|
||||
void Terminal::setText(const QString &text)
|
||||
void Widgets::Terminal::setText(const QString &text)
|
||||
{
|
||||
m_textEdit.setPlainText(text);
|
||||
updateScrollbarVisibility();
|
||||
@ -326,7 +323,7 @@ void Terminal::setText(const QString &text)
|
||||
/**
|
||||
* Changes the width of the vertical scrollbar
|
||||
*/
|
||||
void Terminal::setScrollbarWidth(const int width)
|
||||
void Widgets::Terminal::setScrollbarWidth(const int width)
|
||||
{
|
||||
auto bar = m_textEdit.verticalScrollBar();
|
||||
bar->setFixedWidth(width);
|
||||
@ -338,7 +335,7 @@ void Terminal::setScrollbarWidth(const int width)
|
||||
/**
|
||||
* Changes the @c QPalette of the text editor widget and its children.
|
||||
*/
|
||||
void Terminal::setPalette(const QPalette &palette)
|
||||
void Widgets::Terminal::setPalette(const QPalette &palette)
|
||||
{
|
||||
m_textEdit.setPalette(palette);
|
||||
update();
|
||||
@ -349,7 +346,7 @@ void Terminal::setPalette(const QPalette &palette)
|
||||
/**
|
||||
* Enables or disables the text editor widget.
|
||||
*/
|
||||
void Terminal::setWidgetEnabled(const bool enabled)
|
||||
void Widgets::Terminal::setWidgetEnabled(const bool enabled)
|
||||
{
|
||||
m_textEdit.setEnabled(enabled);
|
||||
update();
|
||||
@ -362,7 +359,7 @@ void Terminal::setWidgetEnabled(const bool enabled)
|
||||
* vertical scrollbar shall automatically scroll to the end of the document when the
|
||||
* text of the text editor is changed.
|
||||
*/
|
||||
void Terminal::setAutoscroll(const bool enabled)
|
||||
void Widgets::Terminal::setAutoscroll(const bool enabled)
|
||||
{
|
||||
// Change internal variables
|
||||
m_autoscroll = enabled;
|
||||
@ -373,7 +370,7 @@ void Terminal::setAutoscroll(const bool enabled)
|
||||
scrollToBottom(true);
|
||||
|
||||
// Update console configuration
|
||||
IO::Console::getInstance()->setAutoscroll(enabled);
|
||||
IO::Console::instance().setAutoscroll(enabled);
|
||||
|
||||
// Update UI
|
||||
update();
|
||||
@ -383,7 +380,7 @@ void Terminal::setAutoscroll(const bool enabled)
|
||||
/**
|
||||
* Inserts the given @a text directly, no additional line breaks added.
|
||||
*/
|
||||
void Terminal::insertText(const QString &text)
|
||||
void Widgets::Terminal::insertText(const QString &text)
|
||||
{
|
||||
if (widgetEnabled())
|
||||
addText(text, vt100emulation());
|
||||
@ -394,7 +391,7 @@ void Terminal::insertText(const QString &text)
|
||||
*
|
||||
* This property holds the mode QPlainTextEdit will use when wrapping text by words.
|
||||
*/
|
||||
void Terminal::setWordWrapMode(const int mode)
|
||||
void Widgets::Terminal::setWordWrapMode(const int mode)
|
||||
{
|
||||
m_textEdit.setWordWrapMode(static_cast<QTextOption::WrapMode>(mode));
|
||||
updateScrollbarVisibility();
|
||||
@ -409,7 +406,7 @@ void Terminal::setWordWrapMode(const int mode)
|
||||
* the end of the document. Otherwise, if set to false, the plain text edit scrolls the
|
||||
* smallest amount possible to ensure the cursor is visible.
|
||||
*/
|
||||
void Terminal::setCenterOnScroll(const bool enabled)
|
||||
void Widgets::Terminal::setCenterOnScroll(const bool enabled)
|
||||
{
|
||||
m_textEdit.setCenterOnScroll(enabled);
|
||||
update();
|
||||
@ -422,7 +419,7 @@ void Terminal::setCenterOnScroll(const bool enabled)
|
||||
* interfacing through network ports or interfacing with a MCU that implements some
|
||||
* kind of shell.
|
||||
*/
|
||||
void Terminal::setVt100Emulation(const bool enabled)
|
||||
void Widgets::Terminal::setVt100Emulation(const bool enabled)
|
||||
{
|
||||
m_emulateVt100 = enabled;
|
||||
Q_EMIT vt100EmulationChanged();
|
||||
@ -431,7 +428,7 @@ void Terminal::setVt100Emulation(const bool enabled)
|
||||
/**
|
||||
* Enables/disables undo/redo history support.
|
||||
*/
|
||||
void Terminal::setUndoRedoEnabled(const bool enabled)
|
||||
void Widgets::Terminal::setUndoRedoEnabled(const bool enabled)
|
||||
{
|
||||
m_textEdit.setUndoRedoEnabled(enabled);
|
||||
update();
|
||||
@ -443,7 +440,7 @@ void Terminal::setUndoRedoEnabled(const bool enabled)
|
||||
* Changes the placeholder text of the text editor. The placeholder text is only displayed
|
||||
* when the document is empty.
|
||||
*/
|
||||
void Terminal::setPlaceholderText(const QString &text)
|
||||
void Widgets::Terminal::setPlaceholderText(const QString &text)
|
||||
{
|
||||
m_textEdit.setPlaceholderText(text);
|
||||
update();
|
||||
@ -454,7 +451,7 @@ void Terminal::setPlaceholderText(const QString &text)
|
||||
/**
|
||||
* Moves the position of the vertical scrollbar to the end of the document.
|
||||
*/
|
||||
void Terminal::scrollToBottom(const bool repaint)
|
||||
void Widgets::Terminal::scrollToBottom(const bool repaint)
|
||||
{
|
||||
// Get scrollbar pointer, calculate line count & visible text lines
|
||||
auto *bar = m_textEdit.verticalScrollBar();
|
||||
@ -488,7 +485,7 @@ void Terminal::scrollToBottom(const bool repaint)
|
||||
* A negative or zero value specifies that the document may contain an unlimited amount of
|
||||
* blocks.
|
||||
*/
|
||||
void Terminal::setMaximumBlockCount(const int maxBlockCount)
|
||||
void Widgets::Terminal::setMaximumBlockCount(const int maxBlockCount)
|
||||
{
|
||||
m_textEdit.setMaximumBlockCount(maxBlockCount);
|
||||
update();
|
||||
@ -499,7 +496,7 @@ void Terminal::setMaximumBlockCount(const int maxBlockCount)
|
||||
/**
|
||||
* Hides or shows the scrollbar
|
||||
*/
|
||||
void Terminal::updateScrollbarVisibility()
|
||||
void Widgets::Terminal::updateScrollbarVisibility()
|
||||
{
|
||||
// Get current line count & visible lines
|
||||
auto lineCount = m_textEdit.document()->blockCount();
|
||||
@ -518,7 +515,7 @@ void Terminal::updateScrollbarVisibility()
|
||||
* Updates the value of copy-available. This function is automatically called by the text
|
||||
* editor widget when the user makes any text selection/deselection.
|
||||
*/
|
||||
void Terminal::setCopyAvailable(const bool yes)
|
||||
void Widgets::Terminal::setCopyAvailable(const bool yes)
|
||||
{
|
||||
m_copyAvailable = yes;
|
||||
Q_EMIT copyAvailableChanged();
|
||||
@ -527,7 +524,7 @@ void Terminal::setCopyAvailable(const bool yes)
|
||||
/**
|
||||
* Inserts the given @a text directly, no additional line breaks added.
|
||||
*/
|
||||
void Terminal::addText(const QString &text, const bool enableVt100)
|
||||
void Widgets::Terminal::addText(const QString &text, const bool enableVt100)
|
||||
{
|
||||
// Get text to insert
|
||||
QString textToInsert = text;
|
||||
@ -555,7 +552,7 @@ void Terminal::addText(const QString &text, const bool enableVt100)
|
||||
* Processes the given @a data to remove the escape sequences from the text using code
|
||||
* from Qt Creator output terminal. Check the next code block for more info.
|
||||
*/
|
||||
QString Terminal::vt100Processing(const QString &data)
|
||||
QString Widgets::Terminal::vt100Processing(const QString &data)
|
||||
{
|
||||
auto formattedText = m_escapeCodeHandler.parseText(FormattedText(data));
|
||||
const QString cleanLine = std::accumulate(
|
||||
@ -593,7 +590,8 @@ static QColor ansiColor(uint code)
|
||||
return QColor(red, green, blue);
|
||||
}
|
||||
|
||||
QVector<FormattedText> AnsiEscapeCodeHandler::parseText(const FormattedText &input)
|
||||
QVector<Widgets::FormattedText>
|
||||
Widgets::AnsiEscapeCodeHandler::parseText(const FormattedText &input)
|
||||
{
|
||||
enum AnsiEscapeCodes
|
||||
{
|
||||
@ -895,19 +893,18 @@ QVector<FormattedText> AnsiEscapeCodeHandler::parseText(const FormattedText &inp
|
||||
return outputData;
|
||||
}
|
||||
|
||||
void AnsiEscapeCodeHandler::setTextEdit(QPlainTextEdit *widget)
|
||||
void Widgets::AnsiEscapeCodeHandler::setTextEdit(QPlainTextEdit *widget)
|
||||
{
|
||||
textEdit = widget;
|
||||
}
|
||||
|
||||
void AnsiEscapeCodeHandler::endFormatScope()
|
||||
void Widgets::AnsiEscapeCodeHandler::endFormatScope()
|
||||
{
|
||||
m_previousFormatClosed = true;
|
||||
}
|
||||
|
||||
void AnsiEscapeCodeHandler::setFormatScope(const QTextCharFormat &charFormat)
|
||||
void Widgets::AnsiEscapeCodeHandler::setFormatScope(const QTextCharFormat &charFormat)
|
||||
{
|
||||
m_previousFormat = charFormat;
|
||||
m_previousFormatClosed = false;
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user