MockPlugin.cpp
81 lines
| 2.8 KiB
| text/x-c
|
CppLexer
Alexandre Leroux
|
r129 | #include "MockPlugin.h" | ||
#include "CosinusProvider.h" | ||||
Alexandre Leroux
|
r99 | |||
#include <DataSource/DataSourceController.h> | ||||
#include <DataSource/DataSourceItem.h> | ||||
Alexandre Leroux
|
r146 | #include <DataSource/DataSourceItemAction.h> | ||
Alexandre Leroux
|
r99 | |||
#include <SqpApplication.h> | ||||
Q_LOGGING_CATEGORY(LOG_MockPlugin, "MockPlugin") | ||||
namespace { | ||||
/// Name of the data source | ||||
const auto DATA_SOURCE_NAME = QStringLiteral("MMS"); | ||||
Alexandre Leroux
|
r129 | /// Creates the data provider relative to the plugin | ||
std::unique_ptr<IDataProvider> createDataProvider() noexcept | ||||
Alexandre Leroux
|
r99 | { | ||
Alexandre Leroux
|
r129 | return std::make_unique<CosinusProvider>(); | ||
Alexandre Leroux
|
r99 | } | ||
Alexandre Leroux
|
r167 | std::unique_ptr<DataSourceItem> createProductItem(const QString &productName, | ||
const QUuid &dataSourceUid) | ||||
Alexandre Leroux
|
r146 | { | ||
auto result = std::make_unique<DataSourceItem>(DataSourceItemType::PRODUCT, | ||||
QVector<QVariant>{productName}); | ||||
// Add action to load product from DataSourceController | ||||
result->addAction(std::make_unique<DataSourceItemAction>( | ||||
Alexandre Leroux
|
r167 | QObject::tr("Load %1 product").arg(productName), | ||
[productName, dataSourceUid](DataSourceItem &item) { | ||||
Alexandre Leroux
|
r146 | if (auto app = sqpApp) { | ||
Alexandre Leroux
|
r167 | app->dataSourceController().loadProductItem(dataSourceUid, item); | ||
Alexandre Leroux
|
r146 | } | ||
})); | ||||
return result; | ||||
} | ||||
Alexandre Leroux
|
r129 | /// Creates the data source item relative to the plugin | ||
Alexandre Leroux
|
r167 | std::unique_ptr<DataSourceItem> createDataSourceItem(const QUuid &dataSourceUid) noexcept | ||
Alexandre Leroux
|
r99 | { | ||
// Magnetic field products | ||||
auto magneticFieldFolder = std::make_unique<DataSourceItem>( | ||||
DataSourceItemType::NODE, QVector<QVariant>{QStringLiteral("Magnetic field")}); | ||||
Alexandre Leroux
|
r167 | magneticFieldFolder->appendChild(createProductItem(QStringLiteral("FGM"), dataSourceUid)); | ||
magneticFieldFolder->appendChild(createProductItem(QStringLiteral("SC"), dataSourceUid)); | ||||
Alexandre Leroux
|
r99 | |||
// Electric field products | ||||
auto electricFieldFolder = std::make_unique<DataSourceItem>( | ||||
DataSourceItemType::NODE, QVector<QVariant>{QStringLiteral("Electric field")}); | ||||
// Root | ||||
auto root = std::make_unique<DataSourceItem>(DataSourceItemType::NODE, | ||||
QVector<QVariant>{DATA_SOURCE_NAME}); | ||||
root->appendChild(std::move(magneticFieldFolder)); | ||||
root->appendChild(std::move(electricFieldFolder)); | ||||
Alexandre Leroux
|
r129 | 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 | ||||
Alexandre Leroux
|
r167 | dataSourceController.setDataSourceItem(dataSourceUid, createDataSourceItem(dataSourceUid)); | ||
Alexandre Leroux
|
r129 | |||
// Sets data provider | ||||
dataSourceController.setDataProvider(dataSourceUid, createDataProvider()); | ||||
} | ||||
else { | ||||
qCWarning(LOG_MockPlugin()) << tr("Can't access to SciQlop application"); | ||||
} | ||||
Alexandre Leroux
|
r99 | } | ||