Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 18 additions & 9 deletions src/main_window.cpp
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are plugins that do not contain a Component class because they do not hook into the real-time system for computations. These plugins are default constructed with ID=0. Due to this limitation, we ignore the ID and instead just use a simple count, because otherwise those plugins would be ignored.

Plugin IDs are meant to be independent between sessions, and propagating this information in the settings could be an issue as well. This is another reason why we avoid assigning IDs on the settings file

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After thinking about it there is no harm in using the plugin's actual ID to keep track of it's identity, however there would have to be a way to store the identity of those plugins that do not contain a component. One way to do this is to store negative numbers instead for those types of widgets.

Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,11 @@ QDataStream& operator<<(QDataStream& out, const plugin_connection& conn)

QDataStream& operator>>(QDataStream& in, plugin_connection& conn)
{
in >> conn.dest_port;
in >> conn.dest_id;
in >> conn.src_port;
in >> conn.src_id; // Match order of << operator
in >> conn.src_direction;
in >> conn.src_id;
in >> conn.src_port;
in >> conn.dest_id;
in >> conn.dest_port;
return in;
}

Expand Down Expand Up @@ -534,7 +534,7 @@ void MainWindow::saveDAQSettings(QSettings& userprefs)
}

void MainWindow::loadDAQSettings(
QSettings& userprefs, std::unordered_map<size_t, IO::Block*> block_cache)
QSettings& userprefs, std::unordered_map<size_t, IO::Block*>& block_cache)
{
userprefs.beginGroup("DAQs");
Event::Object get_devices_event(Event::Type::DAQ_DEVICE_QUERY_EVENT);
Expand Down Expand Up @@ -664,9 +664,16 @@ void MainWindow::saveWidgetSettings(QSettings& userprefs)
this->event_manager->postEvent(&loaded_plugins_query);
const auto plugin_list = std::any_cast<std::vector<const Widgets::Plugin*>>(
loaded_plugins_query.getParam("plugins"));
int widget_count = 0;
for (const auto& entry : plugin_list) {
userprefs.beginGroup(QString::number(widget_count++));
// entry->getID, 0 index occupied by a System Plugin
// block_cache[0] 0 index occupied by the Device
// connections from 0(device) to any plugin will crash.
// So skip the 0 index in widgets, don't save System Plugins
if (entry->getID() == 0)
{
continue;
}
userprefs.beginGroup(QString::number(entry->getID()));
userprefs.setValue("library", QString::fromStdString(entry->getLibrary()));
userprefs.beginGroup("standardParams");
entry->saveParameterSettings(userprefs);
Expand All @@ -680,7 +687,7 @@ void MainWindow::saveWidgetSettings(QSettings& userprefs)
}

void MainWindow::loadWidgetSettings(
QSettings& userprefs, std::unordered_map<size_t, IO::Block*> block_cache)
QSettings& userprefs, std::unordered_map<size_t, IO::Block*>& block_cache)
{
userprefs.beginGroup("Widgets");
QString plugin_name;
Expand Down Expand Up @@ -734,7 +741,7 @@ void MainWindow::saveConnectionSettings(QSettings& userprefs)
}

void MainWindow::loadConnectionSettings(
QSettings& userprefs, std::unordered_map<size_t, IO::Block*> block_cache)
QSettings& userprefs, std::unordered_map<size_t, IO::Block*>& block_cache)
{
///////////////////// Load connections /////////////////////////
RT::block_connection_t connection;
Expand Down Expand Up @@ -836,6 +843,8 @@ void MainWindow::saveSettings()
this->saveDAQSettings(workspaceprefs);

this->saveWidgetSettings(workspaceprefs);

this->saveConnectionSettings(workspaceprefs);

userprefs.endGroup(); // Workspaces
}
Expand Down
6 changes: 3 additions & 3 deletions src/main_window.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -178,13 +178,13 @@ private slots:
inline void loadPeriodSettings(QSettings& userprefs);
inline void saveDAQSettings(QSettings& userprefs);
inline void loadDAQSettings(
QSettings& userprefs, std::unordered_map<size_t, IO::Block*> block_cache);
QSettings& userprefs, std::unordered_map<size_t, IO::Block*>& block_cache);
inline void saveWidgetSettings(QSettings& userprefs);
inline void loadWidgetSettings(
QSettings& userprefs, std::unordered_map<size_t, IO::Block*> block_cache);
QSettings& userprefs, std::unordered_map<size_t, IO::Block*>& block_cache);
inline void saveConnectionSettings(QSettings& userprefs);
inline void loadConnectionSettings(
QSettings& userprefs, std::unordered_map<size_t, IO::Block*> block_cache);
QSettings& userprefs, std::unordered_map<size_t, IO::Block*>& block_cache);
Event::Manager* event_manager;
QMdiArea* mdiArea = nullptr;
QList<QMdiSubWindow*> subWindows;
Expand Down