diff --git a/GUI/coregui/Views/FitWidgets/FitComparisonWidget.cpp b/GUI/coregui/Views/FitWidgets/FitComparisonWidget.cpp index 77cad268b7a5ebcd417c1ae620f7d01300ad95f6..f4d7ec41357a2a3f438ce31220f95629df4d808a 100644 --- a/GUI/coregui/Views/FitWidgets/FitComparisonWidget.cpp +++ b/GUI/coregui/Views/FitWidgets/FitComparisonWidget.cpp @@ -112,7 +112,6 @@ void FitComparisonWidget::subscribeToItem() if (auto simItem = simulatedDataItem()) { simItem->mapper()->setOnValueChange([this]() { calculateRelativeDifference(); }, this); } - calculateRelativeDifference(); m_realDataPlot->setItem(realDataItem()); @@ -149,20 +148,12 @@ void FitComparisonWidget::unsubscribeFromItem() void FitComparisonWidget::onResetViewAction() { - m_comparisonController->setActive(false); - if (auto item = realDataItem()) item->resetView(); - if (auto item = simulatedDataItem()) - item->resetView(); - if (diffItem()) { - diffItem()->resetView(); diffItem()->setLowerAndUpperZ(relative_diff_min, relative_diff_max); } - - m_comparisonController->setActive(true); } void FitComparisonWidget::calculateRelativeDifference() @@ -181,7 +172,6 @@ void FitComparisonWidget::calculateRelativeDifference() diffItem()->yAxisItem()->setItemValue(BasicAxisItem::P_TITLE, simulatedDataItem()->getYaxisTitle()); diffItem()->setLowerAndUpperZ(relative_diff_min, relative_diff_max); diffItem()->setAxesRangeToData(); - } void FitComparisonWidget::unsubscribeFromChildren() diff --git a/GUI/coregui/Views/IntensityDataWidgets/PropertyRepeater.cpp b/GUI/coregui/Views/IntensityDataWidgets/PropertyRepeater.cpp index 50ac83c78e4a674dd98c1590e26cfc614c55e663..f3fcf34f382a769034f727f865427e5860ed2c09 100644 --- a/GUI/coregui/Views/IntensityDataWidgets/PropertyRepeater.cpp +++ b/GUI/coregui/Views/IntensityDataWidgets/PropertyRepeater.cpp @@ -19,9 +19,7 @@ PropertyRepeater::PropertyRepeater(QObject* parent, bool repeat_child_properties : QObject(parent) , m_block_repeater(false) , m_repeat_child_properties(repeat_child_properties) -{ - -} +{} PropertyRepeater::~PropertyRepeater() { @@ -29,16 +27,14 @@ PropertyRepeater::~PropertyRepeater() item->mapper()->unsubscribe(this); } -void PropertyRepeater::addItem(SessionItem* sessionItem, const QStringList& activeProperties) +void PropertyRepeater::addItem(SessionItem* sessionItem) { if (!sessionItem || m_dataItems.contains(sessionItem)) return; - sessionItem->mapper()->setOnItemDestroy([this](SessionItem* item) { m_dataItems.removeAll(item); - m_itemProperties.remove(item); }, this); sessionItem->mapper()->setOnPropertyChange( @@ -50,10 +46,7 @@ void PropertyRepeater::addItem(SessionItem* sessionItem, const QStringList& acti setOnChildPropertyChange(item, name); }, this); } - m_dataItems.push_back(sessionItem); - if (!activeProperties.isEmpty()) - m_itemProperties[sessionItem] = activeProperties; } void PropertyRepeater::clear() @@ -62,7 +55,6 @@ void PropertyRepeater::clear() item->mapper()->unsubscribe(this); m_dataItems.clear(); - m_itemProperties.clear(); } void PropertyRepeater::setActive(bool isActive) @@ -77,19 +69,13 @@ void PropertyRepeater::onPropertyChanged(SessionItem* item, const QString& prope m_block_repeater = true; - if (isPropertyBroadcastAllowed(item, propertyName)) { - QVariant value = item->getItemValue(propertyName); - - for (auto target : targetItems(item)) - if (isPropertyReceiveAllowed(target, propertyName)) - target->setItemValue(propertyName, value); + QVariant value = item->getItemValue(propertyName); + for (auto target : targetItems(item)) { + target->setItemValue(propertyName, value); } - m_block_repeater = false; - } - void PropertyRepeater::setOnChildPropertyChange(SessionItem* item, const QString& propertyName) { if (m_block_repeater) @@ -98,16 +84,11 @@ void PropertyRepeater::setOnChildPropertyChange(SessionItem* item, const QString m_block_repeater = true; SessionItem* sourceItem = item->parent(); - - if (isPropertyBroadcastAllowed(sourceItem, propertyName)) { - QString tag = sourceItem->tagFromItem(item); - QVariant value = item->getItemValue(propertyName); - - for (auto target : targetItems(sourceItem)) - if (isPropertyReceiveAllowed(target, propertyName)) - target->getItem(tag)->setItemValue(propertyName, value); + QString tag = sourceItem->tagFromItem(item); + QVariant value = item->getItemValue(propertyName); + for (auto target : targetItems(sourceItem)) { + target->getItem(tag)->setItemValue(propertyName, value); } - m_block_repeater = false; } @@ -119,21 +100,3 @@ QVector<SessionItem*> PropertyRepeater::targetItems(SessionItem* sourceItem) result.removeAll(sourceItem); return result; } - -//! Returns true if given item is allowed to send updates about property with given name. - -bool PropertyRepeater::isPropertyBroadcastAllowed(SessionItem* item, const QString& propertyName) -{ - auto it = m_itemProperties.find(item); - if (it == m_itemProperties.end()) - return true; // no special wishes, broadcast is allowed - - return it.value().contains(propertyName) ? true : false; -} - -bool PropertyRepeater::isPropertyReceiveAllowed(SessionItem* item, const QString& propertyName) -{ - // for the moment item which is allowed to send notifications on property update - // is also allowed to received updates from other properties - return isPropertyBroadcastAllowed(item, propertyName); -} diff --git a/GUI/coregui/Views/IntensityDataWidgets/PropertyRepeater.h b/GUI/coregui/Views/IntensityDataWidgets/PropertyRepeater.h index 5d41aeedc7c43262cb6f6074ef907e3460da5e45..3836af22296b908fea8e5755addbe60fe8525130 100644 --- a/GUI/coregui/Views/IntensityDataWidgets/PropertyRepeater.h +++ b/GUI/coregui/Views/IntensityDataWidgets/PropertyRepeater.h @@ -32,7 +32,7 @@ public: explicit PropertyRepeater(QObject* parent = nullptr, bool repeat_child_properties = false); ~PropertyRepeater(); - void addItem(SessionItem* sessionItem, const QStringList& activeProperties = QStringList()); + void addItem(SessionItem* sessionItem); void clear(); @@ -41,12 +41,8 @@ private: void onPropertyChanged(SessionItem* item, const QString& propertyName); void setOnChildPropertyChange(SessionItem* item, const QString& propertyName); QVector<SessionItem*> targetItems(SessionItem* sourceItem); - bool isPropertyBroadcastAllowed(SessionItem* item, const QString& propertyName); - bool isPropertyReceiveAllowed(SessionItem* item, const QString& propertyName); QVector<SessionItem*> m_dataItems; - //! List of properties which item is allowed to report to others and receive updates. - QMap<SessionItem*, QStringList> m_itemProperties; bool m_block_repeater; bool m_repeat_child_properties; }; diff --git a/Tests/UnitTests/GUI/TestPropertyRepeater.h b/Tests/UnitTests/GUI/TestPropertyRepeater.h index 7662900b44400a074de12543223d9d946a4fb6bf..86cccf6f0442c632dc6a6901aee12d00a3a326da 100644 --- a/Tests/UnitTests/GUI/TestPropertyRepeater.h +++ b/Tests/UnitTests/GUI/TestPropertyRepeater.h @@ -85,70 +85,6 @@ TEST_F(TestPropertyRepeater, test_threeItems) EXPECT_EQ(item3->getItemValue(BasicAxisItem::P_MAX).toDouble(), 4.0); } -//! Checks if item with active properties specified receives updates only for these properties. - -TEST_F(TestPropertyRepeater, test_filteredBroadcast) -{ - SessionModel model("test"); - - auto item1 = createAxis(model); - auto item2 = createAxis(model); - auto item3 = createAxis(model); - - item1->setItemValue(BasicAxisItem::P_MIN, 0.0); - item2->setItemValue(BasicAxisItem::P_MIN, 0.0); - item3->setItemValue(BasicAxisItem::P_MIN, 0.0); - item1->setItemValue(BasicAxisItem::P_MAX, 1.0); - item2->setItemValue(BasicAxisItem::P_MAX, 1.0); - item3->setItemValue(BasicAxisItem::P_MAX, 1.0); - - QStringList activeProperties = QStringList() << BasicAxisItem::P_MAX; - PropertyRepeater repeater; - repeater.addItem(item1); - repeater.addItem(item2, activeProperties); - repeater.addItem(item3); - - // changing two properties in item2 and checkig that only P_MAX changed in item1 and item3 - item2->setItemValue(BasicAxisItem::P_MIN, 2.0); - item2->setItemValue(BasicAxisItem::P_MAX, 3.0); - - EXPECT_EQ(item1->getItemValue(BasicAxisItem::P_MIN).toDouble(), 0.0); - EXPECT_EQ(item3->getItemValue(BasicAxisItem::P_MIN).toDouble(), 0.0); - EXPECT_EQ(item1->getItemValue(BasicAxisItem::P_MAX).toDouble(), 3.0); - EXPECT_EQ(item3->getItemValue(BasicAxisItem::P_MAX).toDouble(), 3.0); -} - -TEST_F(TestPropertyRepeater, test_filteredReceive) -{ - SessionModel model("test"); - - auto item1 = createAxis(model); - auto item2 = createAxis(model); - auto item3 = createAxis(model); - - item1->setItemValue(BasicAxisItem::P_MIN, 0.0); - item2->setItemValue(BasicAxisItem::P_MIN, 0.0); - item3->setItemValue(BasicAxisItem::P_MIN, 0.0); - item1->setItemValue(BasicAxisItem::P_MAX, 1.0); - item2->setItemValue(BasicAxisItem::P_MAX, 1.0); - item3->setItemValue(BasicAxisItem::P_MAX, 1.0); - - QStringList activeProperties = QStringList() << BasicAxisItem::P_MAX; - PropertyRepeater repeater; - repeater.addItem(item1); - repeater.addItem(item2, activeProperties); - repeater.addItem(item3); - - // changing two properties in item1 and checking that P_MIN of item2 remain intact - item1->setItemValue(BasicAxisItem::P_MIN, 2.0); - item1->setItemValue(BasicAxisItem::P_MAX, 3.0); - - EXPECT_EQ(item2->getItemValue(BasicAxisItem::P_MIN).toDouble(), 0.0); - EXPECT_EQ(item2->getItemValue(BasicAxisItem::P_MAX).toDouble(), 3.0); // remain intact - EXPECT_EQ(item3->getItemValue(BasicAxisItem::P_MIN).toDouble(), 2.0); - EXPECT_EQ(item3->getItemValue(BasicAxisItem::P_MAX).toDouble(), 3.0); -} - //! Checking repeater in "repeat childs properties" mode TEST_F(TestPropertyRepeater, test_repeatAll)