Skip to content
Snippets Groups Projects
Commit 7145b8a2 authored by Pospelov, Gennady's avatar Pospelov, Gennady
Browse files

Code cleanup in JobItem: unused methods removed, 'get' prefix removed from some methods.

parent 86943f33
No related branches found
No related tags found
No related merge requests found
......@@ -44,7 +44,7 @@ std::shared_ptr<FitSuite> DomainFittingBuilder::createFitSuite(JobItem *jobItem)
}
const auto simulation = DomainSimulationBuilder::createSimulation(jobItem->multiLayerItem(),
jobItem->instrumentItem(), jobItem->getSimulationOptionsItem());
jobItem->instrumentItem(), jobItem->simulationOptionsItem());
RealDataItem *realDataItem = jobItem->realDataItem();
if(!realDataItem)
......
......@@ -18,14 +18,14 @@
#include "GUIHelpers.h"
#include "InstrumentItems.h"
#include "IntensityDataItem.h"
#include "IntensityDataItem.h"
#include "JobItemFunctions.h"
#include "JobItemUtils.h"
#include "MaskUnitsConverter.h"
#include "MultiLayerItem.h"
#include "ParameterTreeItems.h"
#include "RealDataItem.h"
#include "SimulationOptionsItem.h"
#include "IntensityDataItem.h"
#include "JobItemFunctions.h"
#include "MaskUnitsConverter.h"
#include "item_constants.h"
const QString JobItem::P_IDENTIFIER = "Identifier";
......@@ -47,8 +47,7 @@ const QString JobItem::T_PARAMETER_TREE = "Parameter Tree";
const QString JobItem::T_SIMULATION_OPTIONS = "Simulation Options";
const QString JobItem::T_FIT_SUITE = "Fit Suite";
JobItem::JobItem()
: SessionItem(Constants::JobItemType)
JobItem::JobItem() : SessionItem(Constants::JobItemType)
{
setItemName(Constants::JobItemType);
addProperty(P_IDENTIFIER, QString())->setVisible(false);
......@@ -61,7 +60,7 @@ JobItem::JobItem()
addProperty(P_BEGIN_TIME, QString())->setEditable(false);
addProperty(P_END_TIME, QString())->setEditable(false);
SessionItem *durationItem = addProperty(P_DURATION, QString());
auto durationItem = addProperty(P_DURATION, QString());
durationItem->setEditable(false);
durationItem->setToolTip(QStringLiteral("Duration of DWBA simulation in sec.msec format"));
......@@ -79,12 +78,10 @@ JobItem::JobItem()
registerTag(T_FIT_SUITE, 1, 1, QStringList() << Constants::FitSuiteType);
mapper()->setOnChildPropertyChange(
[this](SessionItem* item, const QString &name)
{
mapper()->setOnChildPropertyChange([this](SessionItem* item, const QString& name) {
if (item->parent() == this && item->modelType() == Constants::IntensityDataType
&& name == IntensityDataItem::P_AXES_UNITS) {
auto intensityItem = dynamic_cast<IntensityDataItem *>(item);
auto intensityItem = dynamic_cast<IntensityDataItem*>(item);
MaskUnitsConverter converter;
converter.convertToNbins(intensityItem);
......@@ -92,21 +89,13 @@ JobItem::JobItem()
JobItemUtils::updateDataAxes(intensityItem, instrumentItem());
converter.convertFromNbins(intensityDataItem());
}
});
mapper()->setOnPropertyChange(
[this](const QString &name){
if(name == P_NAME)
mapper()->setOnPropertyChange([this](const QString& name) {
if (name == P_NAME)
updateIntensityDataFileName();
}
);
}
JobItem::~JobItem()
{
});
}
QString JobItem::getIdentifier() const
......@@ -114,12 +103,12 @@ QString JobItem::getIdentifier() const
return getItemValue(P_IDENTIFIER).toString();
}
void JobItem::setIdentifier(const QString &identifier)
void JobItem::setIdentifier(const QString& identifier)
{
setItemValue(JobItem::P_IDENTIFIER, identifier);
}
IntensityDataItem *JobItem::intensityDataItem()
IntensityDataItem* JobItem::intensityDataItem()
{
return dynamic_cast<IntensityDataItem*>(getItem(T_OUTPUT));
}
......@@ -129,14 +118,14 @@ QString JobItem::getStatus() const
return getItemValue(P_STATUS).toString();
}
void JobItem::setStatus(const QString &status)
void JobItem::setStatus(const QString& status)
{
setItemValue(P_STATUS, status);
if(status == Constants::STATUS_FAILED) {
if(IntensityDataItem *intensityItem = intensityDataItem()) {
if(intensityItem->getOutputData())
if (status == Constants::STATUS_FAILED) {
if (IntensityDataItem* intensityItem = intensityDataItem()) {
if (intensityItem->getOutputData())
intensityItem->getOutputData()->setAllTo(0.0);
emit intensityItem->emitDataChanged();
emit intensityItem->emitDataChanged();
}
}
}
......@@ -168,19 +157,15 @@ bool JobItem::isFailed() const
bool JobItem::isValidForFitting()
{
if(isTag(T_REALDATA) && getItem(T_REALDATA)) {
return true;
} else {
return false;
}
return isTag(T_REALDATA) && getItem(T_REALDATA) ? true : false;
}
void JobItem::setBeginTime(const QString &begin_time)
void JobItem::setBeginTime(const QString& begin_time)
{
setItemValue(P_BEGIN_TIME, begin_time);
}
void JobItem::setEndTime(const QString &end_time)
void JobItem::setEndTime(const QString& end_time)
{
setItemValue(P_END_TIME, end_time);
}
......@@ -189,8 +174,8 @@ void JobItem::setEndTime(const QString &end_time)
void JobItem::setDuration(int duration)
{
QString str;
if(duration != 0)
str.sprintf("%7.3f", duration/1000.);
if (duration != 0)
str.sprintf("%7.3f", duration / 1000.);
setItemValue(P_DURATION, str.simplified());
}
......@@ -199,7 +184,7 @@ QString JobItem::getComments() const
return getItemValue(P_COMMENTS).toString();
}
void JobItem::setComments(const QString &comments)
void JobItem::setComments(const QString& comments)
{
setItemValue(P_COMMENTS, comments);
}
......@@ -214,52 +199,38 @@ void JobItem::setProgress(int progress)
setItemValue(P_PROGRESS, progress);
}
int JobItem::getNumberOfThreads() const
{
return getSimulationOptionsItem()->getNumberOfThreads();
}
void JobItem::setRunPolicy(const QString &run_policy)
{
getSimulationOptionsItem()->setRunPolicy(run_policy);
}
bool JobItem::runImmediately() const
{
return getSimulationOptionsItem()->runImmediately();
return simulationOptionsItem()->runImmediately();
}
bool JobItem::runInBackground() const
{
return getSimulationOptionsItem()->runInBackground();
return simulationOptionsItem()->runInBackground();
}
//! Returns MultiLayerItem of this JobItem, if from_backup=true, then backup'ed version of
//! multilayer will be used
MultiLayerItem *JobItem::multiLayerItem()
MultiLayerItem* JobItem::multiLayerItem()
{
return dynamic_cast<MultiLayerItem*>(getItem(T_SAMPLE));
}
//! Returns InstrumentItem of this JobItem, if from_backup=true, then backup'ed version of
//! the instrument will be used
GISASInstrumentItem *JobItem::instrumentItem()
GISASInstrumentItem* JobItem::instrumentItem()
{
return dynamic_cast<GISASInstrumentItem*>(getItem(T_INSTRUMENT));
}
void JobItem::setResults(const Simulation* simulation)
{
IntensityDataItem *intensityItem = intensityDataItem();
IntensityDataItem* intensityItem = intensityDataItem();
Q_ASSERT(intensityItem);
JobItemUtils::setResults(intensityItem, simulation);
updateIntensityDataFileName();
}
FitSuiteItem *JobItem::fitSuiteItem()
FitSuiteItem* JobItem::fitSuiteItem()
{
return dynamic_cast<FitSuiteItem *>(getItem(JobItem::T_FIT_SUITE));
return dynamic_cast<FitSuiteItem*>(getItem(JobItem::T_FIT_SUITE));
}
ParameterContainerItem* JobItem::parameterContainerItem()
......@@ -268,20 +239,20 @@ ParameterContainerItem* JobItem::parameterContainerItem()
static_cast<const JobItem*>(this)->parameterContainerItem());
}
const ParameterContainerItem *JobItem::parameterContainerItem() const
const ParameterContainerItem* JobItem::parameterContainerItem() const
{
return dynamic_cast<ParameterContainerItem *>(getItem(JobItem::T_PARAMETER_TREE));
return dynamic_cast<ParameterContainerItem*>(getItem(JobItem::T_PARAMETER_TREE));
}
FitParameterContainerItem *JobItem::fitParameterContainerItem()
FitParameterContainerItem* JobItem::fitParameterContainerItem()
{
if(FitSuiteItem *item = fitSuiteItem())
if (FitSuiteItem* item = fitSuiteItem())
return item->fitParameterContainerItem();
return nullptr;
}
RealDataItem *JobItem::realDataItem()
RealDataItem* JobItem::realDataItem()
{
return dynamic_cast<RealDataItem*>(getItem(JobItem::T_REALDATA));
}
......@@ -295,29 +266,23 @@ QString JobItem::presentationType()
void JobItem::updateIntensityDataFileName()
{
if(IntensityDataItem *item = intensityDataItem())
if (IntensityDataItem* item = intensityDataItem())
item->setItemValue(IntensityDataItem::P_FILE_NAME,
JobItemFunctions::jobResultsFileName(*this));
if(RealDataItem *realItem = realDataItem())
if(IntensityDataItem *item = realItem->intensityDataItem())
if (RealDataItem* realItem = realDataItem())
if (IntensityDataItem* item = realItem->intensityDataItem())
item->setItemValue(IntensityDataItem::P_FILE_NAME,
JobItemFunctions::jobReferenceFileName(*this));
}
SimulationOptionsItem *JobItem::getSimulationOptionsItem()
SimulationOptionsItem* JobItem::simulationOptionsItem()
{
return const_cast<SimulationOptionsItem *>(static_cast<const JobItem*>(this)->getSimulationOptionsItem());
return const_cast<SimulationOptionsItem*>(
static_cast<const JobItem*>(this)->simulationOptionsItem());
}
const SimulationOptionsItem *JobItem::getSimulationOptionsItem() const
const SimulationOptionsItem* JobItem::simulationOptionsItem() const
{
const SimulationOptionsItem *result = dynamic_cast<const SimulationOptionsItem *>(getItem(T_SIMULATION_OPTIONS));
if(!result) {
throw GUIHelpers::Error("JobItem::getSimulationOptions() -> Error. "
"Can't get SimulationOptionsItem");
}
return result;
return &item<const SimulationOptionsItem>(T_SIMULATION_OPTIONS);
}
......@@ -48,16 +48,16 @@ public:
static const QString T_PARAMETER_TREE;
static const QString T_SIMULATION_OPTIONS;
static const QString T_FIT_SUITE;
explicit JobItem();
virtual ~JobItem();
JobItem();
QString getIdentifier() const;
void setIdentifier(const QString &identifier);
void setIdentifier(const QString& identifier);
IntensityDataItem *intensityDataItem();
IntensityDataItem* intensityDataItem();
QString getStatus() const;
void setStatus(const QString &status);
void setStatus(const QString& status);
bool isIdle() const;
bool isRunning() const;
......@@ -66,45 +66,41 @@ public:
bool isFailed() const;
bool isValidForFitting();
void setBeginTime(const QString &begin_time);
void setBeginTime(const QString& begin_time);
void setEndTime(const QString &end_time);
void setEndTime(const QString& end_time);
void setDuration(int duration);
QString getComments() const;
void setComments(const QString &comments);
void setComments(const QString& comments);
int getProgress() const;
void setProgress(int progress);
int getNumberOfThreads() const;
void setRunPolicy(const QString &run_policy);
bool runImmediately() const;
bool runInBackground() const;
MultiLayerItem *multiLayerItem();
MultiLayerItem* multiLayerItem();
GISASInstrumentItem *instrumentItem();
GISASInstrumentItem* instrumentItem();
SimulationOptionsItem *getSimulationOptionsItem();
SimulationOptionsItem* simulationOptionsItem();
void setResults(const Simulation *simulation);
void setResults(const Simulation* simulation);
FitSuiteItem *fitSuiteItem();
ParameterContainerItem *parameterContainerItem();
const ParameterContainerItem *parameterContainerItem() const;
FitSuiteItem* fitSuiteItem();
ParameterContainerItem* parameterContainerItem();
const ParameterContainerItem* parameterContainerItem() const;
FitParameterContainerItem *fitParameterContainerItem();
RealDataItem *realDataItem();
FitParameterContainerItem* fitParameterContainerItem();
RealDataItem* realDataItem();
QString presentationType();
private:
void updateIntensityDataFileName();
const SimulationOptionsItem *getSimulationOptionsItem() const;
const SimulationOptionsItem* simulationOptionsItem() const;
};
#endif // JOBITEM_H
......@@ -42,7 +42,7 @@ void JobQueueData::runJob(JobItem* jobItem)
try {
auto simulation = DomainSimulationBuilder::createSimulation(jobItem->multiLayerItem(),
jobItem->instrumentItem(), jobItem->getSimulationOptionsItem());
jobItem->instrumentItem(), jobItem->simulationOptionsItem());
m_simulations[identifier] = simulation.release();
} catch (const std::exception& ex) {
QString message("JobQueueData::runJob() -> Error. "
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment