diff --git a/GUI/coregui/Models/DataItem1DView.cpp b/GUI/coregui/Models/DataItem1DView.cpp index c860b6c0a740fa70a6fe2cf608d7d1c6cd995b61..a436b45d2eb506600a63b23ce3e68a6bf0730659 100644 --- a/GUI/coregui/Models/DataItem1DView.cpp +++ b/GUI/coregui/Models/DataItem1DView.cpp @@ -54,8 +54,7 @@ DataItem1DView::DataItem1DView() item->setValue(true); item->setVisible(false); - registerTag(T_DATA_PROPERTIES, 0, -1, QStringList() << Constants::DataPropertyContainerType); - insertItem(-1, new DataPropertyContainer, T_DATA_PROPERTIES); + registerTag(T_DATA_PROPERTIES, 1, 1, QStringList() << Constants::DataPropertyContainerType); ComboProperty combo = ComboProperty() << Constants::UnitsNbins; addProperty(P_AXES_UNITS, combo.variant()); @@ -75,11 +74,6 @@ DataItem1DView::DataItem1DView() setYaxisTitle(y_axis_default_name); } -void DataItem1DView::addItem(DataItem* item) -{ - propertyContainerItem()->addItem(item); -} - int DataItem1DView::getNbins() const { return xAxisItem()->getItemValue(BasicAxisItem::P_NBINS).toInt(); @@ -136,10 +130,14 @@ void DataItem1DView::setAxesRangeToData() const auto data = DataViewUtils::getTranslatedData(this, propertyContainerItem()->basicDataItem()); - double xmin = data ? data->getAxis(BornAgain::X_AXIS_INDEX).getMin() : default_min; - double xmax = data ? data->getAxis(BornAgain::X_AXIS_INDEX).getMax() : default_max; - setLowerX(xmin); - setUpperX(xmax); + // For data loading from disk: items appear earlier than + // actual data. + if (!data) + return; + + setLowerX(data->getAxis(BornAgain::X_AXIS_INDEX).getMin()); + setUpperX(data->getAxis(BornAgain::X_AXIS_INDEX).getMax()); + auto data_range = dataRange(data.get()); setLowerY(data_range.first); diff --git a/GUI/coregui/Models/DataItem1DView.h b/GUI/coregui/Models/DataItem1DView.h index d556e7e98b4b25ee1d61be73536478e10c10315d..c058a8a52a7aa4c645bbe1d98b5e5a3581910393 100644 --- a/GUI/coregui/Models/DataItem1DView.h +++ b/GUI/coregui/Models/DataItem1DView.h @@ -40,8 +40,6 @@ public: DataItem1DView(); - void addItem(DataItem* item); - //! Number of bins in data int getNbins() const; diff --git a/GUI/coregui/Models/DataViewUtils.cpp b/GUI/coregui/Models/DataViewUtils.cpp index e09edfc06c9b6596e88e03b66a579214f028b172..9e7617da2281a602aa78e4da73cd1d6038afa01d 100644 --- a/GUI/coregui/Models/DataViewUtils.cpp +++ b/GUI/coregui/Models/DataViewUtils.cpp @@ -8,6 +8,7 @@ #include "IUnitConverter.h" #include "JobItem.h" #include "OutputData.h" +#include "DataPropertyContainer.h" #include "RealDataItem.h" #include "SessionModel.h" #include "UnitConverterUtils.h" @@ -63,10 +64,14 @@ void DataViewUtils::initDataView(JobItem* job_item) SessionModel* model = job_item->model(); auto view_item = dynamic_cast<DataItem1DView*>(model->insertNewItem( Constants::DataItem1DViewType, job_item->index(), -1, JobItem::T_DATAVIEW)); - assert(view_item); - view_item->addItem(job_item->realDataItem()->dataItem()); - view_item->addItem(job_item->dataItem()); + + auto property_container = dynamic_cast<DataPropertyContainer*>(model->insertNewItem( + Constants::DataPropertyContainerType, view_item->index(), -1, DataItem1DView::T_DATA_PROPERTIES)); + assert(property_container); + + property_container->addItem(job_item->realDataItem()->dataItem()); + property_container->addItem(job_item->dataItem()); // also triggers DataItem1DView::setAxesRangeToData and DataViewUtils::updateAxesTitle by // setting new value of P_AXES_UNITS. diff --git a/GUI/coregui/Views/FitWidgets/FitComparisonViewController.cpp b/GUI/coregui/Views/FitWidgets/FitComparisonViewController.cpp index 3c63f1dfa962c21d0837114d3ea7fbdc819bc5d1..5208dc248b9b4157af54ab2ea7bc41baed7b0e62 100644 --- a/GUI/coregui/Views/FitWidgets/FitComparisonViewController.cpp +++ b/GUI/coregui/Views/FitWidgets/FitComparisonViewController.cpp @@ -1,6 +1,7 @@ #include "FitComparisonViewController.h" #include "AxesItems.h" #include "DataItem.h" +#include "DataPropertyContainer.h" #include "DataItem1DView.h" #include "IntensityDataFunctions.h" #include "JobItem.h" @@ -21,7 +22,10 @@ FitComparison1DViewController::FitComparison1DViewController(QObject* parent) m_diff_item_controller->model()->insertNewItem(Constants::DataItem1DViewType))), m_appearanceRepeater(new PropertyRepeater(this)), m_xAxisRepeater(new PropertyRepeater(this)) { - m_diff_view_item->addItem(m_diff_item_controller->diffItem()); + auto container = m_diff_view_item->model()->insertNewItem(Constants::DataPropertyContainerType, + m_diff_view_item->index(), -1, + DataItem1DView::T_DATA_PROPERTIES); + dynamic_cast<DataPropertyContainer*>(container)->addItem(m_diff_item_controller->diffItem()); } DataItem1DView* FitComparison1DViewController::diffItemView() @@ -38,6 +42,8 @@ void FitComparison1DViewController::setItem(JobItem* job_item) diffItemView()->setJobItem(job_item); auto job_data_view = job_item->dataItemView(); + auto units_value = job_data_view->getItemValue(DataItem1DView::P_AXES_UNITS); + diffItemView()->setItemValue(DataItem1DView::P_AXES_UNITS, units_value); m_appearanceRepeater->addItem(job_data_view); m_appearanceRepeater->addItem(diffItemView()); diff --git a/GUI/coregui/Views/TestView.cpp b/GUI/coregui/Views/TestView.cpp index 0fd40b8f42af059c8463db8754436ee00e1c0668..33c108062b3693484dfd01cbd608fc51e72f23a9 100644 --- a/GUI/coregui/Views/TestView.cpp +++ b/GUI/coregui/Views/TestView.cpp @@ -16,6 +16,7 @@ #include "AccordionWidget.h" #include "ApplicationModels.h" #include "DataItem1DView.h" +#include "DataPropertyContainer.h" #include "JobModel.h" #include "JobItem.h" #include "MaskEditor.h" @@ -209,8 +210,10 @@ void TestView::test_specular_data_widget() // creating data view auto data_view = new DataItem1DView(); job_item->insertItem(-1, data_view, JobItem::T_DATAVIEW); - data_view->addItem(job_item->realDataItem()->dataItem()); - data_view->addItem(job_item->dataItem()); + data_view->insertItem(-1, new DataPropertyContainer, DataItem1DView::T_DATA_PROPERTIES); + auto& container = data_view->item<DataPropertyContainer>(DataItem1DView::T_DATA_PROPERTIES); + container.addItem(job_item->realDataItem()->dataItem()); + container.addItem(job_item->dataItem()); QVBoxLayout* layout = new QVBoxLayout; layout->setMargin(0);