##// END OF EJS Templates
Next var request parameter is now based on previous request instead of...
Next var request parameter is now based on previous request instead of initial variable parameter

File last commit:

r788:5e7d2f907fac
r807:0f020366c50a
Show More
MockPlugin.cpp
109 lines | 4.4 KiB | text/x-c | CppLexer
#include "MockPlugin.h"
#include "CosinusProvider.h"
#include "MockDefs.h"
#include <DataSource/DataSourceController.h>
#include <DataSource/DataSourceItem.h>
#include <DataSource/DataSourceItemAction.h>
#include <SqpApplication.h>
Q_LOGGING_CATEGORY(LOG_MockPlugin, "MockPlugin")
namespace {
/// Name of the data source
const auto DATA_SOURCE_NAME = QStringLiteral("MMS");
/// Creates the data provider relative to the plugin
std::unique_ptr<IDataProvider> createDataProvider() noexcept
{
return std::make_unique<CosinusProvider>();
}
std::unique_ptr<DataSourceItem> createProductItem(const QVariantHash &data,
const QUuid &dataSourceUid)
{
auto result = std::make_unique<DataSourceItem>(DataSourceItemType::PRODUCT, data);
auto productName = data.value(DataSourceItem::NAME_DATA_KEY).toString();
// Add action to load product from DataSourceController
result->addAction(std::make_unique<DataSourceItemAction>(
QObject::tr("Load %1 product").arg(productName),
[productName, dataSourceUid](DataSourceItem &item) {
if (auto app = sqpApp) {
app->dataSourceController().loadProductItem(dataSourceUid, item);
}
}));
return result;
}
/// Creates the data source item relative to the plugin
std::unique_ptr<DataSourceItem> createDataSourceItem(const QUuid &dataSourceUid) noexcept
{
// Magnetic field products
auto magneticFieldFolder = std::make_unique<DataSourceItem>(DataSourceItemType::NODE,
QStringLiteral("Magnetic field"));
magneticFieldFolder->appendChild(
createProductItem({{DataSourceItem::NAME_DATA_KEY, QStringLiteral("Scalar 10 Hz")},
{COSINUS_TYPE_KEY, "scalar"},
{COSINUS_FREQUENCY_KEY, 10.}},
dataSourceUid));
magneticFieldFolder->appendChild(
createProductItem({{DataSourceItem::NAME_DATA_KEY, QStringLiteral("Scalar 60 Hz")},
{COSINUS_TYPE_KEY, "scalar"},
{COSINUS_FREQUENCY_KEY, 60.}},
dataSourceUid));
magneticFieldFolder->appendChild(
createProductItem({{DataSourceItem::NAME_DATA_KEY, QStringLiteral("Scalar 100 Hz")},
{COSINUS_TYPE_KEY, "scalar"},
{COSINUS_FREQUENCY_KEY, 100.}},
dataSourceUid));
magneticFieldFolder->appendChild(
createProductItem({{DataSourceItem::NAME_DATA_KEY, QStringLiteral("Vector 10 Hz")},
{COSINUS_TYPE_KEY, "vector"},
{COSINUS_FREQUENCY_KEY, 10.}},
dataSourceUid));
magneticFieldFolder->appendChild(
createProductItem({{DataSourceItem::NAME_DATA_KEY, QStringLiteral("Vector 60 Hz")},
{COSINUS_TYPE_KEY, "vector"},
{COSINUS_FREQUENCY_KEY, 60.}},
dataSourceUid));
magneticFieldFolder->appendChild(
createProductItem({{DataSourceItem::NAME_DATA_KEY, QStringLiteral("Vector 100 Hz")},
{COSINUS_TYPE_KEY, "vector"},
{COSINUS_FREQUENCY_KEY, 100.}},
dataSourceUid));
// Electric field products
auto electricFieldFolder = std::make_unique<DataSourceItem>(DataSourceItemType::NODE,
QStringLiteral("Electric field"));
// Root
auto root = std::make_unique<DataSourceItem>(DataSourceItemType::NODE, DATA_SOURCE_NAME);
root->appendChild(std::move(magneticFieldFolder));
root->appendChild(std::move(electricFieldFolder));
return root;
}
} // namespace
void MockPlugin::initialize()
{
if (auto app = sqpApp) {
// Registers to the data source controller
auto &dataSourceController = app->dataSourceController();
auto dataSourceUid = dataSourceController.registerDataSource(DATA_SOURCE_NAME);
// Sets data source tree
dataSourceController.setDataSourceItem(dataSourceUid, createDataSourceItem(dataSourceUid));
// Sets data provider
dataSourceController.setDataProvider(dataSourceUid, createDataProvider());
}
else {
qCWarning(LOG_MockPlugin()) << tr("Can't access to SciQlop application");
}
}