##// END OF EJS Templates
commit
commit

File last commit:

r684:90684a2a46fa
r684:90684a2a46fa
Show More
VariableController.cpp
442 lines | 16.2 KiB | text/x-c | CppLexer
/ core / src / Variable / VariableController.cpp
The mock plugin can now create data with view operation
r219 #include <Variable/Variable.h>
Implementation of V5 acquisition
r510 #include <Variable/VariableAcquisitionWorker.h>
#include <Variable/VariableCacheStrategy.h>
Alexandre Leroux
Inits variable controller and adds it to the SciQlop app
r106 #include <Variable/VariableController.h>
Alexandre Leroux
Adds Variable model in the Variable controller
r108 #include <Variable/VariableModel.h>
Alexandre Leroux
commit VC
r683 #include <Variable/VariableSynchronizer.h>
Alexandre Leroux
Inits variable controller and adds it to the SciQlop app
r106
Alexandre Leroux
commit processRequest
r682 #include <Data/AcquisitionUtils.h>
Alexandre Leroux
Updates VariableController::createVariable() method...
r154 #include <Data/DataProviderParameters.h>
#include <Data/IDataProvider.h>
#include <Data/IDataSeries.h>
Add implementation of the Var Acquisition waiting
r585 #include <Data/VariableRequest.h>
Time widget is now used with the variable createion request
r179 #include <Time/TimeController.h>
Alexandre Leroux
Updates VariableController::createVariable() method...
r154
Alexandre Leroux
Inits variable controller and adds it to the SciQlop app
r106 #include <QMutex>
#include <QThread>
Alexandre Leroux
Transits tokens in provider requests
r347 #include <QUuid>
Temporal parameters of the selected variables can be updated using the...
r281 #include <QtCore/QItemSelectionModel>
Alexandre Leroux
Inits variable controller and adds it to the SciQlop app
r106
Create a variable notify the variable cache parameter
r209 #include <unordered_map>
Alexandre Leroux
Inits variable controller and adds it to the SciQlop app
r106 Q_LOGGING_CATEGORY(LOG_VariableController, "VariableController")
Implementation of V5 acquisition
r510 namespace {
change grapheRange to graphRange
r516 SqpRange computeSynchroRangeRequested(const SqpRange &varRange, const SqpRange &graphRange,
Implementation of V5 acquisition
r510 const SqpRange &oldGraphRange)
{
Alexandre Leroux
commit processRequest
r682 auto zoomType = AcquisitionUtils::getZoomType(graphRange, oldGraphRange);
Implementation of V5 acquisition
r510
auto varRangeRequested = varRange;
switch (zoomType) {
case AcquisitionZoomType::ZoomIn: {
change grapheRange to graphRange
r516 auto deltaLeft = graphRange.m_TStart - oldGraphRange.m_TStart;
auto deltaRight = oldGraphRange.m_TEnd - graphRange.m_TEnd;
Implementation of V5 acquisition
r510 varRangeRequested.m_TStart += deltaLeft;
varRangeRequested.m_TEnd -= deltaRight;
break;
}
case AcquisitionZoomType::ZoomOut: {
change grapheRange to graphRange
r516 auto deltaLeft = oldGraphRange.m_TStart - graphRange.m_TStart;
auto deltaRight = graphRange.m_TEnd - oldGraphRange.m_TEnd;
Implementation of V5 acquisition
r510 varRangeRequested.m_TStart -= deltaLeft;
varRangeRequested.m_TEnd += deltaRight;
break;
}
case AcquisitionZoomType::PanRight: {
change grapheRange to graphRange
r516 auto deltaRight = graphRange.m_TEnd - oldGraphRange.m_TEnd;
Implementation of V5 acquisition
r510 varRangeRequested.m_TStart += deltaRight;
varRangeRequested.m_TEnd += deltaRight;
break;
}
case AcquisitionZoomType::PanLeft: {
change grapheRange to graphRange
r516 auto deltaLeft = oldGraphRange.m_TStart - graphRange.m_TStart;
Implementation of V5 acquisition
r510 varRangeRequested.m_TStart -= deltaLeft;
varRangeRequested.m_TEnd -= deltaLeft;
break;
}
case AcquisitionZoomType::Unknown: {
qCCritical(LOG_VariableController())
<< VariableController::tr("Impossible to synchronize: zoom type unknown");
break;
}
default:
qCCritical(LOG_VariableController()) << VariableController::tr(
"Impossible to synchronize: zoom type not take into account");
// No action
break;
}
return varRangeRequested;
}
Alexandre Leroux
commit processRequest
r682 } // namespace
Implementation of V5 acquisition
r510
Alexandre Leroux
Inits variable controller and adds it to the SciQlop app
r106 struct VariableController::VariableControllerPrivate {
Alexandre Leroux
Use raw pointer for VariableModel (QObject class)
r148 explicit VariableControllerPrivate(VariableController *parent)
Create a variable notify the variable cache parameter
r209 : m_WorkingMutex{},
m_VariableModel{new VariableModel{parent}},
Temporal parameters of the selected variables can be updated using the...
r281 m_VariableSelectionModel{new QItemSelectionModel{m_VariableModel, parent}},
Implementation of V5 acquisition
r510 m_VariableCacheStrategy{std::make_unique<VariableCacheStrategy>()},
add Skeleton for displaying data which are already in cache
r538 m_VariableAcquisitionWorker{std::make_unique<VariableAcquisitionWorker>()},
Alexandre Leroux
commit VC
r683 m_VariableSynchronizer{std::make_unique<VariableSynchronizer>()},
add Skeleton for displaying data which are already in cache
r538 q{parent}
Implementation of V5 acquisition
r510 {
m_VariableAcquisitionWorker->moveToThread(&m_VariableAcquisitionWorkerThread);
m_VariableAcquisitionWorkerThread.setObjectName("VariableAcquisitionWorkerThread");
}
virtual ~VariableControllerPrivate()
Alexandre Leroux
Inits variable controller and adds it to the SciQlop app
r106 {
Implementation of V5 acquisition
r510 qCDebug(LOG_VariableController()) << tr("VariableControllerPrivate destruction");
m_VariableAcquisitionWorkerThread.quit();
m_VariableAcquisitionWorkerThread.wait();
Alexandre Leroux
Inits variable controller and adds it to the SciQlop app
r106 }
Alexandre Leroux
commit processRequest
r682 void processRequest(std::shared_ptr<Variable> variable, const SqpRange &rangeRequested)
{
Q_ASSERT(variable != nullptr);
Implementation of V5 acquisition
r510
Alexandre Leroux
commit processRequest
r682 if (!m_VariableModel->containsVariable(variable)) {
qCCritical(LOG_VariableController())
<< QObject::tr("Can't process request for variable %1: variable is not registered")
.arg(variable->name());
return;
}
Implementation of V5 acquisition
r510
Alexandre Leroux
commit VC
r683 variable->setRange(rangeRequested);
Alexandre Leroux
commit processRequest
r682 // Gets ranges in/out of variable range
auto requestRange
= m_VariableCacheStrategy->computeStrategyRanges(variable->range(), rangeRequested);
auto notInCacheRanges = variable->provideNotInCacheRangeList(requestRange.second);
// Creates request for out-of-cache ranges
if (!notInCacheRanges.isEmpty()) {
// Gets provider for request
if (auto provider = m_Providers.at(variable)) {
Alexandre Leroux
commit VC
r683 DataProviderParameters providerParameters{std::move(notInCacheRanges),
variable->metadata()};
VariableRequest request{requestRange.first, requestRange.second, provider,
std::move(providerParameters)};
m_VariableAcquisitionWorker->pushVariableRequest(variable, std::move(request));
Alexandre Leroux
commit processRequest
r682 }
Alexandre Leroux
commit VC
r683 // Calls UI update for in-cache range
auto inCacheRanges = variable->provideInCacheRangeList(requestRange.second);
if (!inCacheRanges.isEmpty()) {
emit q->updateVarDisplaying(variable, inCacheRanges.first());
}
Alexandre Leroux
commit processRequest
r682 }
else {
Alexandre Leroux
commit VC
r683 // No request to make: we simply update variable ranges
variable->setCacheRange(requestRange.second);
emit variable->updated();
Alexandre Leroux
commit processRequest
r682 }
}
Implementation of V5 acquisition
r510
Alexandre Leroux
commit processRequest
r682 void registerProvider(std::shared_ptr<IDataProvider> provider)
{
Q_ASSERT(provider != nullptr);
connect(provider.get(), &IDataProvider::dataProvided, m_VariableAcquisitionWorker.get(),
Alexandre Leroux
commit VC
r683 &VariableAcquisitionWorker::onDataAcquired);
Alexandre Leroux
commit processRequest
r682 connect(provider.get(), &IDataProvider::dataProvidedProgress,
m_VariableAcquisitionWorker.get(),
&VariableAcquisitionWorker::onVariableRetrieveDataInProgress);
}
Implementation of V5 acquisition
r510
Alexandre Leroux
Inits variable controller and adds it to the SciQlop app
r106 QMutex m_WorkingMutex;
Alexandre Leroux
Use raw pointer for VariableModel (QObject class)
r148 /// Variable model. The VariableController has the ownership
VariableModel *m_VariableModel;
Temporal parameters of the selected variables can be updated using the...
r281 QItemSelectionModel *m_VariableSelectionModel;
Time widget is now used with the variable createion request
r179
Correction MR
r181 TimeController *m_TimeController{nullptr};
Implementation of V5 acquisition
r510 std::unique_ptr<VariableCacheStrategy> m_VariableCacheStrategy;
std::unique_ptr<VariableAcquisitionWorker> m_VariableAcquisitionWorker;
QThread m_VariableAcquisitionWorkerThread;
The mock plugin can now create data with view operation
r219
Alexandre Leroux
commit VC
r683 /// Handler for variables synchronization
std::unique_ptr<VariableSynchronizer> m_VariableSynchronizer;
Alexandre Leroux
commit processRequest
r682 std::unordered_map<std::shared_ptr<Variable>, std::shared_ptr<IDataProvider> > m_Providers;
add Skeleton for displaying data which are already in cache
r538
VariableController *q;
Alexandre Leroux
Inits variable controller and adds it to the SciQlop app
r106 };
VariableController::VariableController(QObject *parent)
Alexandre Leroux
Use raw pointer for VariableModel (QObject class)
r148 : QObject{parent}, impl{spimpl::make_unique_impl<VariableControllerPrivate>(this)}
Alexandre Leroux
Inits variable controller and adds it to the SciQlop app
r106 {
Alexandre Leroux
temp commit
r680 qCDebug(LOG_VariableController())
<< tr("VariableController construction") << QThread::currentThread();
Implement of the abort download process
r388
connect(impl->m_VariableModel, &VariableModel::abortProgessRequested, this,
&VariableController::onAbortProgressRequested);
Implementation of V5 acquisition
r510
connect(impl->m_VariableAcquisitionWorker.get(), &VariableAcquisitionWorker::dataProvided, this,
&VariableController::onDataProvided);
connect(impl->m_VariableAcquisitionWorker.get(),
&VariableAcquisitionWorker::variableRequestInProgress, this,
&VariableController::onVariableRetrieveDataInProgress);
connect(&impl->m_VariableAcquisitionWorkerThread, &QThread::started,
impl->m_VariableAcquisitionWorker.get(), &VariableAcquisitionWorker::initialize);
connect(&impl->m_VariableAcquisitionWorkerThread, &QThread::finished,
impl->m_VariableAcquisitionWorker.get(), &VariableAcquisitionWorker::finalize);
impl->m_VariableAcquisitionWorkerThread.start();
Alexandre Leroux
Inits variable controller and adds it to the SciQlop app
r106 }
VariableController::~VariableController()
{
Alexandre Leroux
temp commit
r680 qCDebug(LOG_VariableController())
<< tr("VariableController destruction") << QThread::currentThread();
Alexandre Leroux
Inits variable controller and adds it to the SciQlop app
r106 this->waitForFinish();
}
Alexandre Leroux
Updates VariableController::createVariable() method...
r154 VariableModel *VariableController::variableModel() noexcept
Alexandre Leroux
Adds Variable model in the Variable controller
r108 {
Alexandre Leroux
Updates VariableController::createVariable() method...
r154 return impl->m_VariableModel;
Alexandre Leroux
Adds Variable model in the Variable controller
r108 }
Temporal parameters of the selected variables can be updated using the...
r281 QItemSelectionModel *VariableController::variableSelectionModel() noexcept
{
return impl->m_VariableSelectionModel;
}
Time widget is now used with the variable createion request
r179 void VariableController::setTimeController(TimeController *timeController) noexcept
{
impl->m_TimeController = timeController;
}
Alexandre Leroux
Adds 'Duplicate' action on variable menu
r650 std::shared_ptr<Variable>
VariableController::cloneVariable(std::shared_ptr<Variable> variable) noexcept
{
Alexandre Leroux
Creates duplicate only if the variable is in the model
r654 if (impl->m_VariableModel->containsVariable(variable)) {
// Clones variable
auto duplicate = variable->clone();
Alexandre Leroux
Clones variable
r651
Alexandre Leroux
Creates duplicate only if the variable is in the model
r654 // Adds clone to model
impl->m_VariableModel->addVariable(duplicate);
Alexandre Leroux
Adds variable to model
r652
Alexandre Leroux
Generates and registers clone provider
r656 // Registers provider
Alexandre Leroux
commit processRequest
r682 auto variableProvider = impl->m_Providers.at(variable);
Alexandre Leroux
Generates and registers clone provider
r656 auto duplicateProvider = variableProvider != nullptr ? variableProvider->clone() : nullptr;
Alexandre Leroux
commit processRequest
r682 impl->m_Providers[duplicate] = duplicateProvider;
Alexandre Leroux
Generates and registers clone provider
r656 if (duplicateProvider) {
impl->registerProvider(duplicateProvider);
}
Alexandre Leroux
Creates duplicate only if the variable is in the model
r654 return duplicate;
}
else {
qCCritical(LOG_VariableController())
<< tr("Can't create duplicate of variable %1: variable not registered in the model")
.arg(variable->name());
return nullptr;
}
Alexandre Leroux
Adds 'Duplicate' action on variable menu
r650 }
Alexandre Leroux
Variable deletion (1)...
r303 void VariableController::deleteVariable(std::shared_ptr<Variable> variable) noexcept
{
if (!variable) {
qCCritical(LOG_VariableController()) << "Can't delete variable: variable is null";
return;
}
Alexandre Leroux
Variable deletion (6)...
r309 // Spreads in SciQlop that the variable will be deleted, so that potential receivers can
// make some treatments before the deletion
emit variableAboutToBeDeleted(variable);
Alexandre Leroux
Variable deletion (2)...
r304
Alexandre Leroux
commit
r684 // Deletes from synchronization group
impl->m_VariableSynchronizer->removeVariable(variable);
// Cancels pending requests
impl->m_VariableAcquisitionWorker->cancelVariableRequest(variable);
Alexandre Leroux
Variable deletion (2)...
r304 // Deletes provider
Alexandre Leroux
commit processRequest
r682 auto nbProvidersDeleted = impl->m_Providers.erase(variable);
Alexandre Leroux
Variable deletion (2)...
r304 qCDebug(LOG_VariableController())
<< tr("Number of providers deleted for variable %1: %2")
.arg(variable->name(), QString::number(nbProvidersDeleted));
Alexandre Leroux
Variable deletion (1)...
r303
Alexandre Leroux
Variable deletion (2)...
r305
Alexandre Leroux
Variable deletion (3)...
r306 // Deletes from model
impl->m_VariableModel->deleteVariable(variable);
}
Alexandre Leroux
Variable deletion (1)...
r303
void VariableController::deleteVariables(
const QVector<std::shared_ptr<Variable> > &variables) noexcept
{
for (auto variable : qAsConst(variables)) {
deleteVariable(variable);
}
}
Implement of the abort download process
r388 void VariableController::abortProgress(std::shared_ptr<Variable> variable)
{
}
Add test acquisition.
r553 std::shared_ptr<Variable>
VariableController::createVariable(const QString &name, const QVariantHash &metadata,
std::shared_ptr<IDataProvider> provider) noexcept
Alexandre Leroux
Affects model to the Variable Widget
r143 {
Time widget is now used with the variable createion request
r179 if (!impl->m_TimeController) {
qCCritical(LOG_VariableController())
<< tr("Impossible to create variable: The time controller is null");
Add test acquisition.
r553 return nullptr;
Time widget is now used with the variable createion request
r179 }
Implementation of V5 acquisition
r510 auto range = impl->m_TimeController->dateTime();
Alexandre Leroux
Updates variable creation to pass metadata...
r377
Implementation of V5 acquisition
r510 if (auto newVariable = impl->m_VariableModel->createVariable(name, range, metadata)) {
// Associate the provider
Alexandre Leroux
commit VC
r683 auto newVariableProvider = provider != nullptr ? provider->clone() : nullptr;
impl->m_Providers[newVariable] = newVariableProvider;
if (newVariableProvider) {
impl->registerProvider(newVariableProvider);
}
The cache is now updated only if date requested has been successfully...
r293
Alexandre Leroux
commit processRequest
r682 impl->processRequest(newVariable, range);
Add test acquisition.
r553
return newVariable;
Alexandre Leroux
Updates VariableController::createVariable() method...
r154 }
Alexandre Leroux
Affects model to the Variable Widget
r143 }
Change SqpRange for SqpDateTime
r471 void VariableController::onDateTimeOnSelection(const SqpRange &dateTime)
Temporal parameters of the selected variables can be updated using the...
r281 {
Add implementation of the Var Acquisition waiting
r585 // TODO check synchronisation and Rescale
Alexandre Leroux
temp commit
r680 qCDebug(LOG_VariableController())
<< "VariableController::onDateTimeOnSelection" << QThread::currentThread()->objectName();
Temporal parameters of the selected variables can be updated using the...
r281 auto selectedRows = impl->m_VariableSelectionModel->selectedRows();
for (const auto &selectedRow : qAsConst(selectedRows)) {
if (auto selectedVariable = impl->m_VariableModel->variable(selectedRow.row())) {
Implementation of V5 acquisition
r510 selectedVariable->setRange(dateTime);
Alexandre Leroux
commit processRequest
r682 impl->processRequest(selectedVariable, dateTime);
Add comment
r408
// notify that rescale operation has to be done
Add connection logical for the rescale operation
r403 emit rangeChanged(selectedVariable, dateTime);
Temporal parameters of the selected variables can be updated using the...
r281 }
}
}
Alexandre Leroux
commit VC
r683 void VariableController::onDataProvided(std::shared_ptr<Variable> variable, VariableRequest request)
Add implementation of progress bar on variable inspector connected to...
r369 {
Alexandre Leroux
commit VC
r683 Q_ASSERT(variable != nullptr);
if (!impl->m_VariableModel->containsVariable(variable)) {
qCCritical(LOG_VariableController())
<< QObject::tr("Can't update date of variable %1: variable is not registered (anymore)")
.arg(variable->name());
return;
Implementation of V5 acquisition
r510 }
Alexandre Leroux
commit VC
r683
variable->setCacheRange(request.m_CacheRangeRequested);
variable->mergeDataSeries(request.m_Result);
emit variable->updated();
Implementation of V5 acquisition
r510 }
Add implementation of progress bar on variable inspector connected to...
r369
Implementation of V5 acquisition
r510 void VariableController::onVariableRetrieveDataInProgress(QUuid identifier, double progress)
{
Alexandre Leroux
commit VC
r683 /// @todo ALX
// if (auto var = impl->findVariable(identifier)) {
// impl->m_VariableModel->setDataProgress(var, progress);
// }
// else {
// qCCritical(LOG_VariableController())
// << tr("Impossible to notify progression of a null variable");
// }
Add implementation of progress bar on variable inspector connected to...
r369 }
Implement of the abort download process
r388 void VariableController::onAbortProgressRequested(std::shared_ptr<Variable> variable)
{
Alexandre Leroux
commit processRequest
r682 /// @todo ALX
// qCDebug(LOG_VariableController()) << "TORM: VariableController::onAbortProgressRequested"
// << QThread::currentThread()->objectName();
Implement of the abort download process
r388
Alexandre Leroux
commit processRequest
r682 // auto it = impl->m_VariableToIdentifierMap.find(variable);
// if (it != impl->m_VariableToIdentifierMap.cend()) {
// impl->m_VariableToProviderMap.at(variable)->requestDataAborting(it->second);
// }
// else {
// qCWarning(LOG_VariableController())
// << tr("Aborting progression of inexistant variable detected !!!")
// << QThread::currentThread()->objectName();
// }
Implement of the abort download process
r388 }
Implementation of V5 acquisition
r510 void VariableController::onAddSynchronizationGroupId(QUuid synchronizationGroupId)
{
Alexandre Leroux
commit VC
r683 impl->m_VariableSynchronizer->addGroup(synchronizationGroupId);
Implementation of V5 acquisition
r510 }
void VariableController::onRemoveSynchronizationGroupId(QUuid synchronizationGroupId)
{
Alexandre Leroux
commit VC
r683 impl->m_VariableSynchronizer->removeGroup(synchronizationGroupId);
Implementation of V5 acquisition
r510 }
Add synchronization part of v5 acquisition
r511 void VariableController::onAddSynchronized(std::shared_ptr<Variable> variable,
QUuid synchronizationGroupId)
{
Alexandre Leroux
commit VC
r683 impl->m_VariableSynchronizer->addVariable(variable, synchronizationGroupId);
Add synchronization part of v5 acquisition
r511 }
Alexandre Leroux
Handles desynchronisation when removing variable from a graph (1)...
r676 void VariableController::desynchronize(std::shared_ptr<Variable> variable,
QUuid synchronizationGroupId)
{
Alexandre Leroux
commit
r684 // As a variable can't be into more than one synchronization group,we don't need group id here
Q_UNUSED(synchronizationGroupId);
impl->m_VariableSynchronizer->removeVariable(variable);
Alexandre Leroux
Handles desynchronisation when removing variable from a graph (1)...
r676 }
The mock plugin can now create data with view operation
r219
Alexandre Leroux
commit VC
r683 void VariableController::onRequestDataLoading(const QVector<std::shared_ptr<Variable> > &variables,
Implementation of V5 acquisition
r510 const SqpRange &range, const SqpRange &oldRange,
bool synchronise)
The mock plugin can now create data with view operation
r219 {
Alexandre Leroux
commit VC
r683 // Set of variables that have been processed
std::set<std::shared_ptr<Variable> > processedVariables;
std::map<std::shared_ptr<Variable>, SqpRange> oldRanges;
Implementation of V5 acquisition
r510
Alexandre Leroux
commit VC
r683 // Process requests for all variables
Correction for MR
r517 for (const auto &var : variables) {
Alexandre Leroux
commit processRequest
r682 impl->processRequest(var, range);
Alexandre Leroux
commit VC
r683 processedVariables.insert(var);
Implementation of V5 acquisition
r510 }
The mock plugin can now create data with view operation
r219
Alexandre Leroux
commit VC
r683 // Handles synchronisation
Implementation of V5 acquisition
r510 if (synchronise) {
Alexandre Leroux
commit VC
r683 for (const auto &variable : variables) {
// Finds the variables in the same synchronization group
auto synchronizedVariables
= impl->m_VariableSynchronizer->synchronizedVariables(variable);
for (const auto &synchronizedVariable : synchronizedVariables) {
// Processes variable (if it hasn't been already processed)
if (processedVariables.count(synchronizedVariable) == 0) {
auto rangeRequested = computeSynchroRangeRequested(
synchronizedVariable->range(), range, oldRange);
impl->processRequest(synchronizedVariable, rangeRequested);
processedVariables.insert(synchronizedVariable);
Implementation of V5 acquisition
r510 }
}
Fix the cosinus bug....
r276 }
The mock plugin can now create data with view operation
r219 }
}
Alexandre Leroux
Inits variable controller and adds it to the SciQlop app
r106 void VariableController::initialize()
{
qCDebug(LOG_VariableController()) << tr("VariableController init") << QThread::currentThread();
impl->m_WorkingMutex.lock();
qCDebug(LOG_VariableController()) << tr("VariableController init END");
}
void VariableController::finalize()
{
impl->m_WorkingMutex.unlock();
}
void VariableController::waitForFinish()
{
QMutexLocker locker{&impl->m_WorkingMutex};
}