##// END OF EJS Templates
Prevent the creation of events with the same product on 2 graphs
Prevent the creation of events with the same product on 2 graphs

File last commit:

r1036:9c3bb5e93c54
r1265:0d00e9724fb8
Show More
DataSourceController.cpp
169 lines | 5.8 KiB | text/x-c | CppLexer
/ core / src / DataSource / DataSourceController.cpp
Alexandre Leroux
Minor fixes
r171 #include "DataSource/DataSourceController.h"
#include "DataSource/DataSourceItem.h"
Initialisation de l'application multithread avec le spimpl....
r21
Alexandre Leroux
Adds method for registering a data provider in the data source controller
r127 #include <Data/IDataProvider.h>
Initialisation de l'application multithread avec le spimpl....
r21 #include <QMutex>
#include <QThread>
Drop of product in variables
r870 #include <QDataStream>
Ajout du logger compatible Linux à la compilation.
r25 #include <QDir>
#include <QStandardPaths>
Q_LOGGING_CATEGORY(LOG_DataSourceController, "DataSourceController")
Initialisation de l'application multithread avec le spimpl....
r21
class DataSourceController::DataSourceControllerPrivate {
public:
QMutex m_WorkingMutex;
Alexandre Leroux
Implements the method for setting data source structure
r37 /// Data sources registered
Alexandre Leroux
Enables the registration of a data source in the controller
r36 QHash<QUuid, QString> m_DataSources;
Alexandre Leroux
Implements the method for setting data source structure
r37 /// Data sources structures
std::map<QUuid, std::unique_ptr<DataSourceItem> > m_DataSourceItems;
Alexandre Leroux
Adds method for registering a data provider in the data source controller
r127 /// Data providers registered
Alexandre Leroux
Updates DataSourceController::loadProductItem() method...
r167 /// @remarks Data providers are stored as shared_ptr as they can be sent to a variable and
/// continue to live without necessarily the data source controller
std::map<QUuid, std::shared_ptr<IDataProvider> > m_DataProviders;
Drop of product in variables
r870
// Search for the first datasource item matching the specified data
DataSourceItem *findDataSourceItem(const QVariantHash &data)
{
DataSourceItem *sourceItem = nullptr;
for (const auto &item : m_DataSourceItems) {
sourceItem = item.second->findItem(data, true);
if (sourceItem) {
break;
}
}
return sourceItem;
}
Initialisation de l'application multithread avec le spimpl....
r21 };
DataSourceController::DataSourceController(QObject *parent)
: impl{spimpl::make_unique_impl<DataSourceControllerPrivate>()}
{
Remove coverage from windows build...
r76 qCDebug(LOG_DataSourceController()) << tr("DataSourceController construction")
<< QThread::currentThread();
Initialisation de l'application multithread avec le spimpl....
r21 }
DataSourceController::~DataSourceController()
{
Remove coverage from windows build...
r76 qCDebug(LOG_DataSourceController()) << tr("DataSourceController destruction")
<< QThread::currentThread();
Initialisation de l'application multithread avec le spimpl....
r21 this->waitForFinish();
}
Alexandre Leroux
Enables the registration of a data source in the controller
r36 QUuid DataSourceController::registerDataSource(const QString &dataSourceName) noexcept
{
auto dataSourceUid = QUuid::createUuid();
impl->m_DataSources.insert(dataSourceUid, dataSourceName);
return dataSourceUid;
}
Alexandre Leroux
Implements the method for setting data source structure
r37 void DataSourceController::setDataSourceItem(
const QUuid &dataSourceUid, std::unique_ptr<DataSourceItem> dataSourceItem) noexcept
{
Alexandre Leroux
Minor fix
r357 if (!dataSourceItem) {
qCWarning(LOG_DataSourceController())
<< tr("Data source item can't be registered (null item)");
return;
}
Alexandre Leroux
Implements the method for setting data source structure
r37 if (impl->m_DataSources.contains(dataSourceUid)) {
Alexandre Leroux
Updates DataSourceController::loadProductItem() method...
r167 // The data provider is implicitly converted to a shared_ptr
Alexandre Leroux
Implements the method for setting data source structure
r37 impl->m_DataSourceItems.insert(std::make_pair(dataSourceUid, std::move(dataSourceItem)));
// Retrieves the data source item to emit the signal with it
auto it = impl->m_DataSourceItems.find(dataSourceUid);
if (it != impl->m_DataSourceItems.end()) {
Alexandre Leroux
Change signal/slot signature for data source
r92 emit dataSourceItemSet(it->second.get());
Alexandre Leroux
Implements the method for setting data source structure
r37 }
}
else {
qCWarning(LOG_DataSourceController()) << tr("Can't set data source item for uid %1 : no "
"data source has been registered with the uid")
.arg(dataSourceUid.toString());
}
}
Alexandre Leroux
Adds method for registering a data provider in the data source controller
r127 void DataSourceController::setDataProvider(const QUuid &dataSourceUid,
std::unique_ptr<IDataProvider> dataProvider) noexcept
{
if (impl->m_DataSources.contains(dataSourceUid)) {
impl->m_DataProviders.insert(std::make_pair(dataSourceUid, std::move(dataProvider)));
}
else {
qCWarning(LOG_DataSourceController()) << tr("Can't set data provider for uid %1 : no data "
"source has been registered with the uid")
.arg(dataSourceUid.toString());
}
}
Alexandre Leroux
Updates DataSourceController::loadProductItem() method...
r167 void DataSourceController::loadProductItem(const QUuid &dataSourceUid,
const DataSourceItem &productItem) noexcept
Alexandre Leroux
Adds action in the mock plugin to load products
r146 {
Alexandre Leroux
Amda provider update (3)...
r414 if (productItem.type() == DataSourceItemType::PRODUCT
|| productItem.type() == DataSourceItemType::COMPONENT) {
Alexandre Leroux
Implements DataSourceController::loadProductItem() method
r168 /// Retrieves the data provider of the data source (if any)
auto it = impl->m_DataProviders.find(dataSourceUid);
auto dataProvider = (it != impl->m_DataProviders.end()) ? it->second : nullptr;
Alexandre Leroux
Makes the connection between Data source controller and Variable controller...
r169
Alexandre Leroux
Sets the name of the plugin for products and components...
r1036 emit variableCreationRequested(productItem.name(), productItem.data(), dataProvider);
Alexandre Leroux
Implements DataSourceController::loadProductItem() method
r168 }
else {
qCWarning(LOG_DataSourceController()) << tr("Can't load an item that is not a product");
}
Alexandre Leroux
Adds action in the mock plugin to load products
r146 }
Drop of variable, graph and zones on the time widget
r878 QByteArray DataSourceController::mimeDataForProductsData(const QVariantList &productsData)
Drag of product
r868 {
QByteArray encodedData;
QDataStream stream{&encodedData, QIODevice::WriteOnly};
stream << productsData;
return encodedData;
}
Drop of variable, graph and zones on the time widget
r878 QVariantList DataSourceController::productsDataForMimeData(const QByteArray &mimeData)
Drag of product
r868 {
QDataStream stream{mimeData};
QVariantList productList;
stream >> productList;
return productList;
}
Initialisation de l'application multithread avec le spimpl....
r21 void DataSourceController::initialize()
{
Remove coverage from windows build...
r76 qCDebug(LOG_DataSourceController()) << tr("DataSourceController init")
<< QThread::currentThread();
Initialisation de l'application multithread avec le spimpl....
r21 impl->m_WorkingMutex.lock();
Alexandre Leroux
Minor fixes...
r32 qCDebug(LOG_DataSourceController()) << tr("DataSourceController init END");
Initialisation de l'application multithread avec le spimpl....
r21 }
void DataSourceController::finalize()
{
impl->m_WorkingMutex.unlock();
}
Drop of product in variables
r870 void DataSourceController::requestVariable(const QVariantHash &productData)
{
Improves reliability
r874 auto sourceItem = impl->findDataSourceItem(productData);
Drop of product in variables
r870
if (sourceItem) {
auto sourceName = sourceItem->rootItem().name();
auto sourceId = impl->m_DataSources.key(sourceName);
loadProductItem(sourceId, *sourceItem);
}
else {
qCWarning(LOG_DataSourceController()) << tr("requestVariable, product data not found");
}
}
Initialisation de l'application multithread avec le spimpl....
r21 void DataSourceController::waitForFinish()
{
Alexandre Leroux
Minor fixes...
r32 QMutexLocker locker{&impl->m_WorkingMutex};
Initialisation de l'application multithread avec le spimpl....
r21 }