From 45b1c4670ff7790f3ebec312c9bbec041ca51b2d Mon Sep 17 00:00:00 2001 From: David Li <dawei.li@gmx.net> Date: Tue, 22 Mar 2016 11:31:32 +0100 Subject: [PATCH] cleaning up commented code --- GUI/coregui/Models/BeamDistributionItem.cpp | 48 ------- GUI/coregui/Models/BeamDistributionItem.h | 4 - GUI/coregui/Models/DistributionItem.cpp | 19 +-- GUI/coregui/Models/DistributionItem.h | 14 +- GUI/coregui/Models/GroupProperty.cpp | 2 - GUI/coregui/Models/IntensityDataItem.cpp | 3 - GUI/coregui/Models/ItemFactory.cpp | 1 - GUI/coregui/Models/JobItem.cpp | 17 --- GUI/coregui/Models/JobModel.cpp | 5 - GUI/coregui/Models/MaterialItem.cpp | 2 +- GUI/coregui/Models/ModelMapper.cpp | 12 +- GUI/coregui/Models/ModelMapper.h | 6 +- GUI/coregui/Models/MultiLayerItem.cpp | 2 +- GUI/coregui/Models/ParameterModelBuilder.cpp | 131 +------------------ GUI/coregui/Models/ParticleCoreShellItem.cpp | 48 +------ GUI/coregui/Models/ParticleCoreShellItem.h | 2 - GUI/coregui/Models/ParticleItem.cpp | 46 +++---- GUI/coregui/Models/PropertyItem.cpp | 17 --- GUI/coregui/Models/PropertyItem.h | 2 - GUI/coregui/Models/SampleModel.cpp | 3 - GUI/coregui/Models/SampleViewProxyModel.cpp | 3 - GUI/coregui/Models/SessionXML.cpp | 45 +------ GUI/coregui/Models/TransformToDomain.cpp | 13 -- Tests/UnitTests/TestGUI/TestMapperForItem.h | 2 +- 24 files changed, 50 insertions(+), 397 deletions(-) diff --git a/GUI/coregui/Models/BeamDistributionItem.cpp b/GUI/coregui/Models/BeamDistributionItem.cpp index c806a20f441..8e824e0cc60 100644 --- a/GUI/coregui/Models/BeamDistributionItem.cpp +++ b/GUI/coregui/Models/BeamDistributionItem.cpp @@ -34,26 +34,6 @@ BeamDistributionItem::BeamDistributionItem(const QString name) setGroupProperty(P_DISTRIBUTION, Constants::DistributionNoneType); } -//FIXME cached values not supported now -//void BeamDistributionItem::onPropertyChange(const QString &name) -//{ -// if(name == P_CACHED_VALUE) { -// DistributionItem *distribution = dynamic_cast<DistributionItem *>(getGroupItem(P_DISTRIBUTION)); -// if(distribution) { -// double cached_value = getRegisteredProperty(P_CACHED_VALUE).toDouble(); -// PropertyAttribute cached_attribute = getPropertyAttribute(P_CACHED_VALUE); -// cached_attribute.setVisible(); -// // do not propagate this change back to me, or I will enter an infinite -// // signal-slot loop -// disconnect(getGroupItem(P_DISTRIBUTION), SIGNAL(propertyChanged(QString)), -// this, SLOT(processSubItemPropertyChanged(QString)) ); -// distribution->init_parameters(cached_value, cached_attribute); -// connect(getGroupItem(P_DISTRIBUTION), SIGNAL(propertyChanged(QString)), -// this, SLOT(processSubItemPropertyChanged(QString)), Qt::UniqueConnection); -// } -// } -//} - //! returns parameter distribution to add into the Simulation std::unique_ptr<ParameterDistribution> BeamDistributionItem::getParameterDistributionForName(const std::string ¶meter_name) @@ -71,8 +51,6 @@ BeamDistributionItem::getParameterDistributionForName(const std::string ¶met sigma_factor = distributionItem->getItemValue( DistributionItem::P_SIGMA_FACTOR).toInt(); } - -// PropertyAttribute cached_attribute = getPropertyAttribute(P_CACHED_VALUE); AttLimits limits; if (modelType() == Constants::BeamWavelengthType) { limits = getItem(P_CACHED_VALUE)->limits(); @@ -90,32 +68,6 @@ BeamDistributionItem::getParameterDistributionForName(const std::string ¶met return P_par_distr; } -////! updates new DistributionItem with cached_value -//void BeamDistributionItem::onSubItemChanged(const QString &propertyName) -//{ -// qDebug() << "BeamWavelengthItem::onSubItemChanged(const QString &propertyName)" << propertyName; -// if(propertyName == P_DISTRIBUTION) { -// DistributionItem *distribution = dynamic_cast<DistributionItem *>(getGroupItem(P_DISTRIBUTION)); -// Q_ASSERT(distribution); -// double cached_value = getRegisteredProperty(P_CACHED_VALUE).toDouble(); -// PropertyAttribute cached_attribute = getPropertyAttribute(P_CACHED_VALUE); -// cached_attribute.setVisible(); -// distribution->init_parameters(cached_value, cached_attribute); -// } -// SessionItem::onSubItemChanged(propertyName); -//} - -//void BeamDistributionItem::onSubItemPropertyChanged(const QString &property_group, const QString &property_name) -//{ -// qDebug() << "BeamWavelengthItem::onSubItemPropertyChanged(const QString &property_group, const QString &property_name)" << property_group << property_name; -// if(property_group == P_DISTRIBUTION && property_name == DistributionNoneItem::P_VALUE) { -// double value_to_cache = getGroupItem(P_DISTRIBUTION)-> -// getRegisteredProperty(DistributionNoneItem::P_VALUE).toDouble(); -// setRegisteredProperty(P_CACHED_VALUE, value_to_cache); -// } -// SessionItem::onSubItemPropertyChanged(property_group, property_name); -//} - std::unique_ptr<IDistribution1D> BeamDistributionItem::createDistribution1D() { std::unique_ptr<IDistribution1D> P_distribution {}; diff --git a/GUI/coregui/Models/BeamDistributionItem.h b/GUI/coregui/Models/BeamDistributionItem.h index b0b4d9f4f07..fe5324bb8f4 100644 --- a/GUI/coregui/Models/BeamDistributionItem.h +++ b/GUI/coregui/Models/BeamDistributionItem.h @@ -33,14 +33,10 @@ public: static const QString P_CACHED_VALUE; explicit BeamDistributionItem(const QString name = QString()); virtual ~BeamDistributionItem(){} -// virtual void onPropertyChange(const QString &name); std::unique_ptr<ParameterDistribution> getParameterDistributionForName( const std::string ¶meter_name); -//protected slots: -// virtual void onSubItemChanged(const QString &propertyName); -// virtual void onSubItemPropertyChanged(const QString &property_group, const QString &property_name); protected: virtual std::unique_ptr<IDistribution1D> createDistribution1D(); diff --git a/GUI/coregui/Models/DistributionItem.cpp b/GUI/coregui/Models/DistributionItem.cpp index 851fa67a5fd..91c08ac2d77 100644 --- a/GUI/coregui/Models/DistributionItem.cpp +++ b/GUI/coregui/Models/DistributionItem.cpp @@ -53,10 +53,9 @@ std::unique_ptr<IDistribution1D> DistributionNoneItem::createDistribution() cons return nullptr; } -void DistributionNoneItem::init_parameters(double value, PropertyAttribute) +void DistributionNoneItem::init_parameters(double value) { setItemValue(DistributionNoneItem::P_VALUE, value); -// setPropertyAttribute(DistributionNoneItem::P_VALUE, attribute); } /* ------------------------------------------------ */ @@ -80,14 +79,12 @@ std::unique_ptr<IDistribution1D> DistributionGateItem::createDistribution() cons return GUIHelpers::make_unique<DistributionGate>(min, max); } -void DistributionGateItem::init_parameters(double value, PropertyAttribute) +void DistributionGateItem::init_parameters(double value) { double sigma(0.1*std::abs(value)); if(sigma == 0.0) sigma = 0.1; setItemValue(P_MIN, value - sigma); -// setPropertyAttribute(P_MIN, attribute); setItemValue(P_MAX, value + sigma); -// setPropertyAttribute(P_MAX, attribute); } /* ------------------------------------------------ */ @@ -111,13 +108,12 @@ std::unique_ptr<IDistribution1D> DistributionLorentzItem::createDistribution() c return GUIHelpers::make_unique<DistributionLorentz>(mean, hwhm); } -void DistributionLorentzItem::init_parameters(double value, PropertyAttribute) +void DistributionLorentzItem::init_parameters(double value) { double sigma(0.1*std::abs(value)); if(sigma == 0.0) sigma = 0.1; setItemValue(P_MEAN, value); -// setPropertyAttribute(P_MEAN, attribute); setItemValue(P_HWHM, sigma); getItem(P_HWHM)->setLimits(AttLimits::lowerLimited(0.0)); } @@ -143,13 +139,12 @@ std::unique_ptr<IDistribution1D> DistributionGaussianItem::createDistribution() return GUIHelpers::make_unique<DistributionGaussian>(mean, std_dev); } -void DistributionGaussianItem::init_parameters(double value, PropertyAttribute) +void DistributionGaussianItem::init_parameters(double value) { double sigma(0.1*std::abs(value)); if(sigma == 0.0) sigma = 0.1; setItemValue(P_MEAN, value); -// setPropertyAttribute(P_MEAN, attribute); setItemValue(P_STD_DEV, sigma); getItem(P_STD_DEV)->setLimits(AttLimits::lowerLimited(0.0)); } @@ -175,13 +170,12 @@ std::unique_ptr<IDistribution1D> DistributionLogNormalItem::createDistribution() return GUIHelpers::make_unique<DistributionLogNormal>(median, scale_par); } -void DistributionLogNormalItem::init_parameters(double value, PropertyAttribute) +void DistributionLogNormalItem::init_parameters(double value) { double sigma(0.1*std::abs(value)); if(sigma == 0.0) sigma = 0.1; setItemValue(P_MEDIAN, value); -// setPropertyAttribute(P_MEDIAN, attribute); setItemValue(P_SCALE_PAR, sigma); getItem(P_SCALE_PAR)->setLimits(AttLimits::lowerLimited(0.0)); } @@ -207,13 +201,12 @@ std::unique_ptr<IDistribution1D> DistributionCosineItem::createDistribution() co return GUIHelpers::make_unique<DistributionCosine>(mean, sigma); } -void DistributionCosineItem::init_parameters(double value, PropertyAttribute) +void DistributionCosineItem::init_parameters(double value) { double sigma(0.1*std::abs(value)); if(sigma == 0.0) sigma = 0.1; setItemValue(P_MEAN, value); -// setPropertyAttribute(P_MEAN, attribute); setItemValue(P_SIGMA, sigma); getItem(P_SIGMA)->setLimits(AttLimits::lowerLimited(0.0)); } diff --git a/GUI/coregui/Models/DistributionItem.h b/GUI/coregui/Models/DistributionItem.h index cbefc8a8008..164ff9b3bbf 100644 --- a/GUI/coregui/Models/DistributionItem.h +++ b/GUI/coregui/Models/DistributionItem.h @@ -32,7 +32,7 @@ public: explicit DistributionItem(const QString name); virtual std::unique_ptr<IDistribution1D> createDistribution() const=0; - virtual void init_parameters(double, PropertyAttribute){} + virtual void init_parameters(double){} protected: void register_number_of_samples(); void register_sigma_factor(); @@ -45,7 +45,7 @@ public: static const QString P_VALUE; explicit DistributionNoneItem(); virtual std::unique_ptr<IDistribution1D> createDistribution() const; - virtual void init_parameters(double value, PropertyAttribute); + virtual void init_parameters(double value); }; @@ -58,7 +58,7 @@ public: explicit DistributionGateItem(); virtual std::unique_ptr<IDistribution1D> createDistribution() const; - virtual void init_parameters(double value, PropertyAttribute); + virtual void init_parameters(double value); }; @@ -71,7 +71,7 @@ public: explicit DistributionLorentzItem(); virtual std::unique_ptr<IDistribution1D> createDistribution() const; - virtual void init_parameters(double value, PropertyAttribute); + virtual void init_parameters(double value); }; @@ -84,7 +84,7 @@ public: explicit DistributionGaussianItem(); virtual std::unique_ptr<IDistribution1D> createDistribution() const; - virtual void init_parameters(double value, PropertyAttribute); + virtual void init_parameters(double value); }; @@ -97,7 +97,7 @@ public: explicit DistributionLogNormalItem(); virtual std::unique_ptr<IDistribution1D> createDistribution() const; - virtual void init_parameters(double value, PropertyAttribute); + virtual void init_parameters(double value); }; @@ -110,7 +110,7 @@ public: explicit DistributionCosineItem(); virtual std::unique_ptr<IDistribution1D> createDistribution() const; - virtual void init_parameters(double value, PropertyAttribute); + virtual void init_parameters(double value); }; #endif // DISTRIBUTIONITEM_H diff --git a/GUI/coregui/Models/GroupProperty.cpp b/GUI/coregui/Models/GroupProperty.cpp index f94b3a797f8..ecd9792974a 100644 --- a/GUI/coregui/Models/GroupProperty.cpp +++ b/GUI/coregui/Models/GroupProperty.cpp @@ -36,8 +36,6 @@ SessionItem *GroupProperty::getCurrentItem() qDebug() << "GroupProperty::getCurrentItem()" << m_groupItem; if(m_groupItem) return m_groupItem->getChildByName(this->getCurrentType()); return 0; -// Q_ASSERT(m_parent); -// return m_parent->getChildByName(this->getCurrentType()); } void GroupProperty::setGroupItem(SessionItem *groupItem) diff --git a/GUI/coregui/Models/IntensityDataItem.cpp b/GUI/coregui/Models/IntensityDataItem.cpp index d1098bacd52..96b5d9a6635 100644 --- a/GUI/coregui/Models/IntensityDataItem.cpp +++ b/GUI/coregui/Models/IntensityDataItem.cpp @@ -85,8 +85,6 @@ void IntensityDataItem::setOutputData(OutputData<double> *data) Q_ASSERT(data); m_data.reset(data); -// blockSignals(true); - // set zoom range of x-axis to min, max values if it was not set already if(getUpperX() < getLowerX()) { setLowerX(getXmin()); @@ -105,7 +103,6 @@ void IntensityDataItem::setOutputData(OutputData<double> *data) if(getYaxisTitle().isEmpty()) setYaxisTitle(QString::fromStdString(m_data->getAxis(BornAgain::Y_AXIS_INDEX)->getName())); -// blockSignals(false); qDebug() << "Emmitting intensityModified();"; emitDataChanged(); } diff --git a/GUI/coregui/Models/ItemFactory.cpp b/GUI/coregui/Models/ItemFactory.cpp index 3d7a53f0c8c..b824880d705 100644 --- a/GUI/coregui/Models/ItemFactory.cpp +++ b/GUI/coregui/Models/ItemFactory.cpp @@ -216,7 +216,6 @@ SessionItem *ItemFactory::createItem(const QString &model_name, SessionItem *ItemFactory::createEmptyItem() { SessionItem *result = new SessionItem("ROOT_ITEM"); - //result->setItemName("ROOT_ITEM"); return result; } diff --git a/GUI/coregui/Models/JobItem.cpp b/GUI/coregui/Models/JobItem.cpp index eed16c4c806..fc5aa648b44 100644 --- a/GUI/coregui/Models/JobItem.cpp +++ b/GUI/coregui/Models/JobItem.cpp @@ -273,22 +273,5 @@ void JobItem::setResults(const GISASSimulation *simulation) Q_ASSERT(intensityItem); JobResultsPresenter::setResults(intensityItem, simulation); - - - -// Q_ASSERT(simulation); -// IntensityDataItem *intensityItem = getIntensityDataItem(); -// Q_ASSERT(intensityItem); -// intensityItem->setNameFromProposed(this->itemName()); - // intensityItem->setResults(simulation); } -//void JobItem::onPropertyChange(const QString &name) -//{ -// if(name == SessionItem::P_NAME) { -// if(IntensityDataItem *intensityDataItem = getIntensityDataItem()) { -// intensityDataItem->setNameFromProposed(itemName()); -// } -// } -//} - diff --git a/GUI/coregui/Models/JobModel.cpp b/GUI/coregui/Models/JobModel.cpp index a6214add7b1..9630848874d 100644 --- a/GUI/coregui/Models/JobModel.cpp +++ b/GUI/coregui/Models/JobModel.cpp @@ -213,11 +213,6 @@ void JobModel::onSelectionChanged(const QItemSelection &selected, const QItemSel qDebug() << "NJobModel::onSelectionChanged -> emiting selectionChanged(0)"; emit selectionChanged(0); } - -// if(!selected.empty() && !selected.first().indexes().empty()) { -// QModelIndex index = selected.first().indexes().at(0); -// emit selectionChanged(getJobItemForIndex(index)); - // } } // called when jobQueueData asks for focus diff --git a/GUI/coregui/Models/MaterialItem.cpp b/GUI/coregui/Models/MaterialItem.cpp index f1cb5991836..c97954c1830 100644 --- a/GUI/coregui/Models/MaterialItem.cpp +++ b/GUI/coregui/Models/MaterialItem.cpp @@ -38,7 +38,7 @@ MaterialItem::MaterialItem() addProperty(P_COLOR, color.getVariant()); addGroupProperty(P_REFRACTIVE_INDEX, Constants::RefractiveIndexType); addProperty(P_IDENTIFIER, QUuid::createUuid().toString()); -// getItem(P_IDENTIFIER)->setVisible(false); + getItem(P_IDENTIFIER)->setVisible(false); } QString MaterialItem::getIdentifier() const diff --git a/GUI/coregui/Models/ModelMapper.cpp b/GUI/coregui/Models/ModelMapper.cpp index 8a11e5d8517..3e656ca17ea 100644 --- a/GUI/coregui/Models/ModelMapper.cpp +++ b/GUI/coregui/Models/ModelMapper.cpp @@ -55,7 +55,7 @@ void ModelMapper::setOnParentChange(std::function<void (SessionItem *)> f) m_onParentChange.push_back(f); } -void ModelMapper::setOnChildrenChange(std::function<void ()> f) +void ModelMapper::setOnChildrenChange(std::function<void(SessionItem *)> f) { m_onChildrenChange.push_back(f); } @@ -141,11 +141,11 @@ void ModelMapper::callOnParentChange(SessionItem *new_parent) } } -void ModelMapper::callOnChildrenChange() +void ModelMapper::callOnChildrenChange(SessionItem *item) { if (m_active && m_onChildrenChange.size() > 0) { for (auto f : m_onChildrenChange) { - f(); + f(item); } } } @@ -216,12 +216,11 @@ void ModelMapper::onRowsInserted(const QModelIndex &parent, int first, int /*las } if (nestling == 1) { - callOnChildrenChange(); + callOnChildrenChange(newChild); // inform siblings about the change // FIXME SessionItems with invalid parent index (i.e. IView's located on top of graphics scene like ParticleView) should be also notified to update the label if(SessionItem *parent = newChild->parent()) { -// QVector<SessionItem *> items = parent->getItems(parent->tagFromItem(newChild)); QVector<SessionItem *> items = parent->getChildrenOfType(newChild->modelType()); foreach(SessionItem *sibling, items) { if(m_item == sibling) callOnSiblingsChange(); @@ -247,11 +246,10 @@ void ModelMapper::onBeginRemoveRows(const QModelIndex &parent, int first, int /* } if (nestling == 0) { - callOnChildrenChange(); + callOnChildrenChange(oldChild); // inform siblings about the change if(SessionItem *parent = oldChild->parent()) { - // QVector<SessionItem *> items = parent->getItems(parent->tagFromItem(newChild)); QVector<SessionItem *> items = parent->getChildrenOfType(oldChild->modelType()); foreach(SessionItem *sibling, items) { if(m_item == sibling) callOnSiblingsChange(); diff --git a/GUI/coregui/Models/ModelMapper.h b/GUI/coregui/Models/ModelMapper.h index 3612fe7da6a..b48a1510e2c 100644 --- a/GUI/coregui/Models/ModelMapper.h +++ b/GUI/coregui/Models/ModelMapper.h @@ -43,7 +43,7 @@ public: void setOnParentChange(std::function<void(SessionItem*)> f); - void setOnChildrenChange(std::function<void(void)> f); + void setOnChildrenChange(std::function<void(SessionItem*)> f); void setOnSiblingsChange(std::function<void(void)> f); @@ -69,7 +69,7 @@ private: void callOnPropertyChange(const QString &name); void callOnChildPropertyChange(SessionItem *item, const QString &name); void callOnParentChange(SessionItem *new_parent); - void callOnChildrenChange(); + void callOnChildrenChange(SessionItem *item); void callOnSiblingsChange(); void callOnAnyChildChange(SessionItem *item); @@ -81,7 +81,7 @@ private: std::vector<std::function<void(QString)>> m_onPropertyChange; std::vector<std::function<void(SessionItem*,QString)>> m_onChildPropertyChange; std::vector<std::function<void(SessionItem*)>> m_onParentChange; - std::vector<std::function<void(void)>> m_onChildrenChange; + std::vector<std::function<void(SessionItem*)>> m_onChildrenChange; std::vector<std::function<void(void)>> m_onSiblingsChange; std::vector<std::function<void(SessionItem*)>> m_onAnyChildChange; }; diff --git a/GUI/coregui/Models/MultiLayerItem.cpp b/GUI/coregui/Models/MultiLayerItem.cpp index a2628f698f7..55cebfd42d5 100644 --- a/GUI/coregui/Models/MultiLayerItem.cpp +++ b/GUI/coregui/Models/MultiLayerItem.cpp @@ -30,7 +30,7 @@ MultiLayerItem::MultiLayerItem() setDefaultTag(T_LAYERS); setItemName(Constants::MultiLayerType); mapper()->setOnChildrenChange( - [this]() + [this](SessionItem*) { updateLayers(); }); diff --git a/GUI/coregui/Models/ParameterModelBuilder.cpp b/GUI/coregui/Models/ParameterModelBuilder.cpp index 60b3099bbf2..78ecef46787 100644 --- a/GUI/coregui/Models/ParameterModelBuilder.cpp +++ b/GUI/coregui/Models/ParameterModelBuilder.cpp @@ -92,80 +92,6 @@ QStandardItem *ParameterModelBuilder::iterateSessionModel(SessionModel *sampleMo InsertRowIntoItem(parentItem, newItem); iterateSessionModel(sampleModel, itemIndex, newItem); } - - - -// qDebug() << " item" << item->modelType() << item->itemName(); -// item->print(); - -// //QStandardItem *standardItem = new QStandardItem(item->itemName()); - -// QList<QByteArray> propertyNameList = item->dynamicPropertyNames(); -// for (int i = 0; i < propertyNameList.length(); ++i) { -// QString propertyName = QString(propertyNameList[i]); -// // qDebug() << " Items: i"<< i << propertyName << -// // "subItems.size" << item->getSubItems().size(); - -// const PropertyAttribute &prop_attribute = item->getPropertyAttribute(propertyName); - -// if (prop_attribute.isHidden() || prop_attribute.isDisabled()) continue; - -// // if(item->getPropertyAttribute(propertyName) & SessionItem::HiddenProperty) -// // continue; - -// QVariant propertyValue = item->property(propertyName.toUtf8().data()); - -// int type = GUIHelpers::getVariantType(propertyValue); -// if (type == QVariant::Double) { -// // qDebug() << " Items: "<<propertyName << -// // propertyValue.toDouble(); -// addPropertyToParameterModel(standardItem, propertyName, propertyName, -// propertyValue, item); - -// } else if (item->isGroupProperty(propertyName)) { -// QMap<QString, SessionItem *> subItems = item->getSubItems(); -// SessionItem *subItem = subItems[propertyName]; - -// // qDebug() << " Item: " << item->itemName() << -// // "SubItem:" << subItem->itemName(); - -// QStandardItem *childStandardItem = new QStandardItem(subItem->itemName()); - -// QList<QByteArray> childPropertyList = subItem->dynamicPropertyNames(); - -// bool isChildPropertyFound = false; - -// for (int j = 0; j < childPropertyList.length(); ++j) { -// QString childPropertyName = QString(childPropertyList[j]); - -// const PropertyAttribute &prop_attribute -// = subItem->getPropertyAttribute(childPropertyName); -// if (prop_attribute.isHidden() || prop_attribute.isDisabled()) -// continue; - -// QVariant childPropertyValue -// = subItem->property(childPropertyName.toUtf8().data()); -// int proValueType = GUIHelpers::getVariantType(childPropertyValue); -// if (proValueType == QVariant::Double) { -// // qDebug() << "Items: "<<prop_name << prop_value.toDouble(); -// isChildPropertyFound = true; -// addPropertyToParameterModel(childStandardItem, childPropertyName, -// childPropertyName, childPropertyValue, -// subItem); -// } -// } -// if (isChildPropertyFound) { -// InsertRowIntoItem(standardItem, childStandardItem); -// } -// } -// } - -// if (parentItem == nullptr) { -// parentItem = standardItem; -// } else { -// InsertRowIntoItem(parentItem, standardItem); -// } - // qDebug() << "iteration called" << i_row; } } @@ -181,62 +107,7 @@ QStandardItem *ParameterModelBuilder::iterateInstrumentModel(InstrumentModel *in QStandardItem *ParameterModelBuilder::iterateInstrumentItem(InstrumentItem *) { - /*QStandardItem *standardItem(0); - BeamItem *beamItem = instrument->getBeamItem(); - if (beamItem) { - standardItem = new QStandardItem(instrument->itemName()); - - // intensity -// addPropertyToParameterModel(standardItem, BeamItem::P_INTENSITY, BeamItem::P_INTENSITY, -// QVariant(beamItem->getIntensity()), beamItem); - - // wavelength, incident and azimuthal angle will be varied only if there is no distribution - // assigned to them - SessionItem *beamWavelength = beamItem->getGroupItem(BeamItem::P_WAVELENGTH); - Q_ASSERT(beamWavelength); - SessionItem *wavelengthDistribution - = beamWavelength->getGroupItem(BeamDistributionItem::P_DISTRIBUTION); - Q_ASSERT(wavelengthDistribution); - if (wavelengthDistribution->modelType() == Constants::DistributionNoneType) { - addPropertyToParameterModel( - standardItem, BeamItem::P_WAVELENGTH, BeamDistributionItem::P_CACHED_VALUE, - beamWavelength->getItemValue(BeamDistributionItem::P_CACHED_VALUE), - beamWavelength); - } else { - addDisabledProperty(standardItem, BeamItem::P_WAVELENGTH); - } - - SessionItem *inclinationAngle - = beamItem->getGroupItem(BeamItem::P_INCLINATION_ANGLE); - Q_ASSERT(inclinationAngle); - SessionItem *inclinationDistribution - = inclinationAngle->getGroupItem(BeamDistributionItem::P_DISTRIBUTION); - Q_ASSERT(inclinationDistribution); - if (inclinationDistribution->modelType() == Constants::DistributionNoneType) { - addPropertyToParameterModel( - standardItem, BeamItem::P_INCLINATION_ANGLE, BeamDistributionItem::P_CACHED_VALUE, - inclinationAngle->getItemValue(BeamDistributionItem::P_CACHED_VALUE), - inclinationAngle); - } else { - addDisabledProperty(standardItem, BeamItem::P_INCLINATION_ANGLE); - } - - SessionItem *azimuthalAngle = beamItem->getGroupItem(BeamItem::P_AZIMUTHAL_ANGLE); - Q_ASSERT(azimuthalAngle); - SessionItem *azimuthalDistribution - = azimuthalAngle->getGroupItem(BeamDistributionItem::P_DISTRIBUTION); - Q_ASSERT(azimuthalDistribution); - if (azimuthalDistribution->modelType() == Constants::DistributionNoneType) { - addPropertyToParameterModel( - standardItem, BeamItem::P_AZIMUTHAL_ANGLE, BeamDistributionItem::P_CACHED_VALUE, - azimuthalAngle->getItemValue(BeamDistributionItem::P_CACHED_VALUE), - azimuthalAngle); - } else { - addDisabledProperty(standardItem, BeamItem::P_AZIMUTHAL_ANGLE); - } - } - - return standardItem;*/ + // TODO take care of instrument parameters, do it somewhat less cumbersome return nullptr; } diff --git a/GUI/coregui/Models/ParticleCoreShellItem.cpp b/GUI/coregui/Models/ParticleCoreShellItem.cpp index b9a817216b1..306fc80f946 100644 --- a/GUI/coregui/Models/ParticleCoreShellItem.cpp +++ b/GUI/coregui/Models/ParticleCoreShellItem.cpp @@ -39,11 +39,10 @@ ParticleCoreShellItem::ParticleCoreShellItem() registerTag(ParticleItem::T_TRANSFORMATION, 0, 1, QStringList() << Constants::TransformationType); RotationTranslator rotation_translator; ModelPath::addParameterTranslator(rotation_translator); - mapper()->setOnPropertyChange( - [this](const QString &name) + mapper()->setOnParentChange( + [this](SessionItem*) { - // FIXME not working now because port is not a property anymore - if (name == "OBSOLETE_P_PORT" && parent()) { + if (parent()) { if (parent()->modelType() == Constants::ParticleCompositionType || parent()->modelType() == Constants::ParticleDistributionType) { setItemValue(ParticleItem::P_ABUNDANCE, 1.0); @@ -73,44 +72,3 @@ std::unique_ptr<ParticleCoreShell> ParticleCoreShellItem::createParticleCoreShel TransformToDomain::setTransformationInfo(P_coreshell.get(), *this); return P_coreshell; } - -void ParticleCoreShellItem::notifyChildParticlePortChanged() -{ - // TODO restore logic -// QVector<SessionItem *> children = childItems(); -// int core_index = -1; -// int shell_index = -1; -// for (int i=0; i<children.size(); ++i) { -// if (children[i]->modelType() == Constants::ParticleType) { -// PortInfo::EPorts port = children[i]->port();/*(PortInfo::EPorts)children[i] -// ->getRegisteredProperty(ParameterizedItem::OBSOLETE_P_PORT).toInt();*/ -// if (port == PortInfo::PORT_0) core_index = i; -// if (port == PortInfo::PORT_1) shell_index = i; -// } -// } -// if (shell_index >= 0 && core_index > shell_index) { -// swapChildren(core_index, shell_index); -// } -} - -//! TODO where is it used? restore logic -//ParameterizedItem::PortInfo::EPorts ParticleCoreShellItem::getFirstAvailableParticlePort() const -//{ -// // Also when no ports are available, return the first port (core particle will then be replaced) -// PortInfo::EPorts result = PortInfo::PORT_0; -// QList<PortInfo::EPorts> used_particle_ports; -// QVector<SessionItem *> children = childItems(); -// for (auto item : children) { -// if (item->modelType() == Constants::ParticleType) { -// PortInfo::EPorts port = item->port(); -//// = (PortInfo::EPorts)item->getRegisteredProperty(ParameterizedItem::OBSOLETE_P_PORT).toInt(); -// used_particle_ports.append(port); -// } -// } -// if (used_particle_ports.size() < 2) { -// if (used_particle_ports.contains(PortInfo::PORT_0)) { -// result = PortInfo::PORT_1; -// } -// } -// return result; -//} diff --git a/GUI/coregui/Models/ParticleCoreShellItem.h b/GUI/coregui/Models/ParticleCoreShellItem.h index 3b422291d6f..213d4b5671b 100644 --- a/GUI/coregui/Models/ParticleCoreShellItem.h +++ b/GUI/coregui/Models/ParticleCoreShellItem.h @@ -33,8 +33,6 @@ public: virtual ~ParticleCoreShellItem() {} std::unique_ptr<ParticleCoreShell> createParticleCoreShell() const; - void notifyChildParticlePortChanged(); - }; #endif diff --git a/GUI/coregui/Models/ParticleItem.cpp b/GUI/coregui/Models/ParticleItem.cpp index 02f5392f55a..2fdbda8899f 100644 --- a/GUI/coregui/Models/ParticleItem.cpp +++ b/GUI/coregui/Models/ParticleItem.cpp @@ -42,11 +42,31 @@ ParticleItem::ParticleItem() PositionTranslator position_translator; ModelPath::addParameterTranslator(position_translator); -// addToValidChildren(Constants::TransformationType, PortInfo::PORT_0, 1); registerTag(T_TRANSFORMATION, 0, 1, QStringList() << Constants::TransformationType); setDefaultTag(T_TRANSFORMATION); RotationTranslator rotation_translator; ModelPath::addParameterTranslator(rotation_translator); + + mapper()->setOnParentChange( + [this](SessionItem*) { + if (parent()) { + if (parent()->modelType() == Constants::ParticleCoreShellType + || parent()->modelType() == Constants::ParticleCompositionType + || parent()->modelType() == Constants::ParticleDistributionType) { + setItemValue(ParticleItem::P_ABUNDANCE, 1.0); + getItem(ParticleItem::P_ABUNDANCE)->setEnabled(false); + if (parent()->modelType() == Constants::ParticleCoreShellType) { + if (parent()->tagFromItem(this) == ParticleCoreShellItem::T_SHELL) { + SessionItem *p_position_item = getGroupItem(ParticleItem::P_POSITION); + p_position_item->setItemValue(VectorItem::P_X, 0.0); + p_position_item->setItemValue(VectorItem::P_Y, 0.0); + p_position_item->setItemValue(VectorItem::P_Z, 0.0); + getItem(ParticleItem::P_POSITION)->setEnabled(false); + } + } + } + } + }); } std::unique_ptr<Particle> ParticleItem::createParticle() const @@ -66,27 +86,3 @@ std::unique_ptr<Particle> ParticleItem::createParticle() const return P_particle; } - -//void ParticleItem::setPort(ParameterizedItem::PortInfo::EPorts nport) -//{ -// if (parent()) { -// if (parent()->modelType() == Constants::ParticleCoreShellType -// || parent()->modelType() == Constants::ParticleCompositionType -// || parent()->modelType() == Constants::ParticleDistributionType) { -// setRegisteredProperty(ParticleItem::P_ABUNDANCE, 1.0); -// getItem(ParticleItem::P_ABUNDANCE)->setEnabled(false); -// int port = int(this->port()); -// if (parent()->modelType() == Constants::ParticleCoreShellType) { -// auto p_coreshell = static_cast<ParticleCoreShellItem*>(parent()); -// p_coreshell->notifyChildParticlePortChanged(); -// if (port == PortInfo::PORT_1) { -// SessionItem *p_position_item = getGroupItem(ParticleItem::P_POSITION); -// p_position_item->setRegisteredProperty(VectorItem::P_X, 0.0); -// p_position_item->setRegisteredProperty(VectorItem::P_Y, 0.0); -// p_position_item->setRegisteredProperty(VectorItem::P_Z, 0.0); -// getItem(ParticleItem::P_POSITION)->setEnabled(false); -// } -// } -// } -// } -//} diff --git a/GUI/coregui/Models/PropertyItem.cpp b/GUI/coregui/Models/PropertyItem.cpp index dede3c27747..e9e339a1841 100644 --- a/GUI/coregui/Models/PropertyItem.cpp +++ b/GUI/coregui/Models/PropertyItem.cpp @@ -20,20 +20,3 @@ PropertyItem::PropertyItem() { } - -/*bool PropertyItem::setData(int column, const QVariant &data) -{ - if (displayName() == SessionItem::P_NAME) { - if (data.toString().isEmpty()) - return false; - if (SessionItem *item = parent()) { - if (SessionItem *item_parent = item->parent()) { - // forbid setting duplicate name - if (item_parent->getChildByName(data.toString())) { - return false; - } - } - } - } - return SessionItem::setData(column, data); -}*/ diff --git a/GUI/coregui/Models/PropertyItem.h b/GUI/coregui/Models/PropertyItem.h index 6fac8f55c0d..48e8116fd74 100644 --- a/GUI/coregui/Models/PropertyItem.h +++ b/GUI/coregui/Models/PropertyItem.h @@ -23,8 +23,6 @@ class BA_CORE_API_ PropertyItem : public SessionItem public: PropertyItem(); - -// bool setData(int column, const QVariant &data); }; #endif diff --git a/GUI/coregui/Models/SampleModel.cpp b/GUI/coregui/Models/SampleModel.cpp index 4ae7eefec66..73fc7a3ce34 100644 --- a/GUI/coregui/Models/SampleModel.cpp +++ b/GUI/coregui/Models/SampleModel.cpp @@ -73,11 +73,8 @@ void SampleModel::exploreForMaterials(const QModelIndex &parentIndex) MaterialProperty material_property = item->getItemValue(LayerItem::P_MATERIAL).value<MaterialProperty>(); if (material_property.getIdentifier() == m_material_identifier) { -// item->setRegisteredProperty(LayerItem::P_MATERIAL, -// material_property.getVariant()); // MaterialProperty of the layer corresponds to the material which just has been changed // To trigger color change in ILayerView we have to trigger propertyChanged - //emit item->propertyChanged(); item->getItem(LayerItem::P_MATERIAL)->emitDataChanged(); } } diff --git a/GUI/coregui/Models/SampleViewProxyModel.cpp b/GUI/coregui/Models/SampleViewProxyModel.cpp index 7e69d646207..a07343bd366 100644 --- a/GUI/coregui/Models/SampleViewProxyModel.cpp +++ b/GUI/coregui/Models/SampleViewProxyModel.cpp @@ -27,7 +27,4 @@ bool SampleViewProxyModel::filterAcceptsRow(int sourceRow, const QModelIndex &so if (!sourceParent.isValid()) return true; return !sourceModel()->data(index, Qt::DisplayRole).isValid(); -// return (type == Constants::MultiLayerType || type == Constants::LayerType || type == Constants::ParticleType -// || type == Constants::ParticleCompositionType || type == Constants::ParticleCoreShellType -// || type == Constants::ParticleDistributionType); } diff --git a/GUI/coregui/Models/SessionXML.cpp b/GUI/coregui/Models/SessionXML.cpp index 848c6cd02db..bc844364ad7 100644 --- a/GUI/coregui/Models/SessionXML.cpp +++ b/GUI/coregui/Models/SessionXML.cpp @@ -51,11 +51,6 @@ void SessionWriter::writeItemAndChildItems(QXmlStreamWriter *writer, const Sessi if (tag == item->parent()->defaultTag()) tag = ""; writer->writeAttribute(SessionXML::TagAttribute, tag); - /*if (item->isRegisteredTag(ParameterizedItem::P_NAME)) { - writer->writeAttribute(SessionXML::ItemNameAttribute, item->itemName()); - } else { - writer->writeAttribute(SessionXML::ParameterNameAttribute, item->itemName()); - }*/ QVector<int> roles = item->getRoles(); foreach(int role, roles) { if (role == Qt::DisplayRole || role == Qt::EditRole) @@ -132,9 +127,6 @@ void SessionReader::readItems(QXmlStreamReader *reader, SessionItem *item, int r qDebug() << "SessionModel::readItems() " << row; if(item) qDebug() << " item" << item->modelType(); const QString modelType = item->model()->getModelTag(); -// bool inside_parameter_tag = false; -// QString parent_parameter_name; -// SessionItem *parent_backup(0); while (!reader->atEnd()) { reader->readNext(); if (reader->isStartElement()) { @@ -142,14 +134,6 @@ void SessionReader::readItems(QXmlStreamReader *reader, SessionItem *item, int r const QString model_type = reader->attributes().value(SessionXML::ModelTypeAttribute).toString(); QString tag = reader->attributes().value(SessionXML::TagAttribute).toString(); - /*QString item_name; - bool setItemName = false; - if (reader->attributes().hasAttribute(SessionXML::ItemNameAttribute)) { - item_name = reader->attributes().value(SessionXML::ItemNameAttribute).toString(); - setItemName = true; - } else { - item_name = reader->attributes().value(SessionXML::ParameterNameAttribute).toString(); - }*/ if (tag == SessionItem::P_NAME) item->setItemName(""); if (model_type == Constants::PropertyType || model_type == Constants::GroupItemType) { @@ -177,23 +161,8 @@ void SessionReader::readItems(QXmlStreamReader *reader, SessionItem *item, int r row = -1; // all but the first item should be appended -// if (inside_parameter_tag) { -// Q_ASSERT(item); -// SessionItem *parent = item; -// item = parent->getGroupItem(parent_parameter_name); -// if(!item) { -// // to provide partial loading of obsolete project files -// QString message = QString("Non existing SubItem '%1' of '%2'") -// .arg(parent_parameter_name).arg(parent->modelType()); -//// report_error(NON_EXISTING_SUBITEM, message); -// parent_backup = parent; -// } -// } else { - -// } } else if (reader->name() == SessionXML::ParameterTag) { - /*parent_parameter_name = */readProperty(reader, item); -// inside_parameter_tag = true; + readProperty(reader, item); } } else if (reader->isEndElement()) { if (reader->name() == SessionXML::ItemTag) { @@ -201,8 +170,6 @@ void SessionReader::readItems(QXmlStreamReader *reader, SessionItem *item, int r item = item->parent(); } else { // handling the case when reading obsolete project file, when SubItem doesn't exist anymore -// item = parent_backup; -// parent_backup = 0; qDebug() << "!!"; } } @@ -210,7 +177,6 @@ void SessionReader::readItems(QXmlStreamReader *reader, SessionItem *item, int r break; } if (reader->name() == SessionXML::ParameterTag) { -// inside_parameter_tag = false; } } } @@ -248,31 +214,26 @@ QString SessionReader::readProperty(QXmlStreamReader *reader, SessionItem *item) double parameter_value = reader->attributes().value(SessionXML::ParameterValueAttribute).toDouble(); variant = parameter_value; -// item->setRegisteredProperty(parameter_name, parameter_value); } else if (parameter_type == "int") { int parameter_value = reader->attributes().value(SessionXML::ParameterValueAttribute).toInt(); variant = parameter_value; -// item->setRegisteredProperty(parameter_name, parameter_value); } else if (parameter_type == "bool") { bool parameter_value = reader->attributes().value(SessionXML::ParameterValueAttribute).toInt(); variant = parameter_value; -// item->setRegisteredProperty(parameter_name, parameter_value); } else if (parameter_type == "QString") { QString parameter_value = reader->attributes().value(SessionXML::ParameterValueAttribute).toString(); variant = parameter_value; -// item->setRegisteredProperty(parameter_name, parameter_value); } else if (parameter_type == "MaterialProperty") { QString identifier = reader->attributes().value(SessionXML::IdentifierAttribute).toString(); MaterialProperty material_property(identifier); variant = material_property.getVariant(); -// item->setProperty(parameter_name.toUtf8().constData(), material_property.getVariant()); } else if (parameter_type == "ComboProperty") { QString parameter_value = reader->attributes().value(SessionXML::ParameterValueAttribute).toString(); @@ -284,7 +245,6 @@ QString SessionReader::readProperty(QXmlStreamReader *reader, SessionItem *item) } combo_property.setCachedValue(parameter_value); variant = combo_property.getVariant(); -// item->setRegisteredProperty(parameter_name, combo_property.getVariant()); } else if (parameter_type == "ScientificDoubleProperty") { double parameter_value = reader->attributes().value(SessionXML::ParameterValueAttribute).toDouble(); @@ -293,7 +253,6 @@ QString SessionReader::readProperty(QXmlStreamReader *reader, SessionItem *item) QVariant v; v.setValue(scdouble_property); variant = v; -// item->setRegisteredProperty(parameter_name, v); } else if (parameter_type == "GroupProperty_t") { QString parameter_value = reader->attributes().value(SessionXML::ParameterValueAttribute).toString(); @@ -308,7 +267,6 @@ QString SessionReader::readProperty(QXmlStreamReader *reader, SessionItem *item) int b = reader->attributes().value(SessionXML::ColorBlueAttribute).toInt(); int a = reader->attributes().value(SessionXML::ColorAlphaAttribute).toInt(); ColorProperty color(QColor(r, g, b, a)); -// item->setRegisteredProperty(parameter_name, color.getVariant()); variant = color.getVariant(); } else if (parameter_type == "AngleProperty") { double parameter_value @@ -317,7 +275,6 @@ QString SessionReader::readProperty(QXmlStreamReader *reader, SessionItem *item) AngleProperty angle_property(parameter_value, Constants::UnitsRadians); angle_property.setUnits(units); variant = angle_property.getVariant(); -// item->setRegisteredProperty(parameter_name, angle_property.getVariant()); } else { diff --git a/GUI/coregui/Models/TransformToDomain.cpp b/GUI/coregui/Models/TransformToDomain.cpp index dbf274379b8..248c26ca7f5 100644 --- a/GUI/coregui/Models/TransformToDomain.cpp +++ b/GUI/coregui/Models/TransformToDomain.cpp @@ -404,19 +404,6 @@ void TransformToDomain::addMasksToSimulation(const SessionItem &detector_item, } -//for (int i_row = m_maskModel->rowCount(m_maskContainerIndex); i_row > 0; --i_row) { -// QModelIndex itemIndex = m_maskModel->index(i_row - 1, 0, m_maskContainerIndex); -// if (MaskItem *item = dynamic_cast<MaskItem *>(m_maskModel->itemForIndex(itemIndex))) { -// Geometry::IShape2D *shape = item->createShape(); -// if (shape) { -// detectorMask.addMask(*shape, -// item->getRegisteredProperty(MaskItem::P_MASK_VALUE).toBool()); -// } -// delete shape; -// } -//} - - void TransformToDomain::setTransformationInfo(IParticle *result, const SessionItem &item) { setPositionInfo(result, item); diff --git a/Tests/UnitTests/TestGUI/TestMapperForItem.h b/Tests/UnitTests/TestGUI/TestMapperForItem.h index 2b54c2a531e..1428ec9dfe7 100644 --- a/Tests/UnitTests/TestGUI/TestMapperForItem.h +++ b/Tests/UnitTests/TestGUI/TestMapperForItem.h @@ -64,7 +64,7 @@ public: m_mapper->setOnChildrenChange( - [this]() + [this](SessionItem*) { onChildrenChange(); }); -- GitLab