Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
53 commits
Select commit Hold shift + click to select a range
98a35d5
initial state for copying from local disk to sasview plot_refactoring…
juliuskarliczek Jun 27, 2024
97b8834
logic for checking if a dataset is a 2d dataset. inside subtabs, a lo…
juliuskarliczek Jun 27, 2024
4addf22
change drop acceptance of plottreewidget: now only the items that can…
juliuskarliczek Jun 27, 2024
17ccd49
plottreewidget now represents 2d data as supposed to be. plotting fun…
juliuskarliczek Jun 28, 2024
6948306
implemented 2d plotting logic
juliuskarliczek Jun 28, 2024
640158e
add dock widget logic for subtabs
juliuskarliczek Jul 10, 2024
075c1e6
added plotting changes: one big plot in the middle and other small pl…
juliuskarliczek Jul 11, 2024
c3966d0
dropping logic: plotwindow will now show the specific pages that a mo…
juliuskarliczek Jul 12, 2024
55d25ca
add txts from meeting notes and sketches
juliuskarliczek Jul 23, 2024
45c7979
Non logic changing changes for DataCollector.py. Docstrings, changing…
juliuskarliczek Jul 29, 2024
ace9fd7
Rename get_fitpage_fp and get_fitpage_id to get_fitpage_by_fp and get…
juliuskarliczek Jul 29, 2024
923e009
use find_object_by_property in DataCollector.py to iterate over the l…
juliuskarliczek Jul 29, 2024
e976012
update datasets to be privite with _datasets and use property decorat…
juliuskarliczek Jul 29, 2024
7f7d556
Stop Mainwindow.py from being executed every time it is imported. Wra…
juliuskarliczek Jul 29, 2024
7ff2995
update txt
juliuskarliczek Jul 30, 2024
eda0367
change method header, because main window is already a class variable
juliuskarliczek Aug 1, 2024
535fe1f
remove unused commented section from earlier tests in RandomDatasetCr…
juliuskarliczek Aug 1, 2024
5793546
add docstrings for RandomDatasetCreator.py
juliuskarliczek Aug 1, 2024
8f6ff13
docstring Dataset.py
juliuskarliczek Aug 1, 2024
e802320
docstrings and bettercomments for DataViewer.py. Fixed small issue fo…
juliuskarliczek Aug 2, 2024
9169170
forgot to commit the mainwindow.py one commit earlier
juliuskarliczek Aug 2, 2024
2ae6096
Comments for MainWindow.py. Small change for one method call from onC…
juliuskarliczek Aug 2, 2024
9e16dbf
make colormaps applicable to 2d plots
juliuskarliczek Aug 5, 2024
4c4b908
delete print statement
juliuskarliczek Aug 5, 2024
f72b66a
DataTreeWidget: add docstrings and type specifics for method headers
juliuskarliczek Aug 6, 2024
1263a16
Dataset.py: Add type specifics to method parameters. Add return types…
juliuskarliczek Aug 7, 2024
761fa29
Add properties to a lot of classes and change the method calling
juliuskarliczek Aug 7, 2024
28f015c
move Ui files to ui folder and change imports
juliuskarliczek Aug 7, 2024
e53fac1
remove *ui.ui and *ui.py files from main folder
juliuskarliczek Aug 7, 2024
858c4bf
add UI folder and *UI.ui files in there
juliuskarliczek Aug 7, 2024
af7683a
add docstring FitPage.py
juliuskarliczek Aug 7, 2024
b1a2d40
FitPage.py change identifier to be a property
juliuskarliczek Aug 7, 2024
49b242b
update identifier comment FitPage.py
juliuskarliczek Aug 7, 2024
a234e0e
change method parameter type specification and return type specification
juliuskarliczek Aug 7, 2024
5af05c8
remove unnecessary imports
juliuskarliczek Aug 7, 2024
afa5f77
Docstrings for PlotTreeItems.py and little formatting typo in SubTabs.py
juliuskarliczek Aug 7, 2024
72663fa
formatting stuff SubTabs.py. remove unused method for returning the f…
juliuskarliczek Aug 8, 2024
116d599
Comments and docstrings for SubTabs.py
juliuskarliczek Aug 8, 2024
f3436ea
Add gray out on dock out mechanism
juliuskarliczek Aug 9, 2024
f4ab642
property call typo correction
juliuskarliczek Aug 9, 2024
9e1c1dd
update dataviewer, so that the datatreewidget does not produce double…
juliuskarliczek Aug 16, 2024
4b68fdd
implement correct bookkeeping for plottreewidget when closing a tab
juliuskarliczek Aug 16, 2024
f565245
update agenda.txt
juliuskarliczek Aug 19, 2024
9f54b25
update agenda.txt
juliuskarliczek Aug 20, 2024
2cab430
update agenda.txt again
juliuskarliczek Aug 20, 2024
fde0ea2
reworked Agenda.txt
juliuskarliczek Sep 10, 2024
b957ffe
update the agenda more and delete unnecessary variables in MainWindow.py
juliuskarliczek Sep 23, 2024
33831fe
add comments regarding type_nums it PlotTreeItems.py
juliuskarliczek Sep 24, 2024
d47d4ac
change redrawAll to redraw for appropriate naming
juliuskarliczek Sep 24, 2024
9e4a8d8
PlotTreeWidget.py comments
juliuskarliczek Sep 26, 2024
a21ebe2
PlotTreeWidget.py comment correction
juliuskarliczek Sep 26, 2024
4faa78b
Add larger documentation file to plotting_refactor/notes_and_sketches
juliuskarliczek Sep 26, 2024
5612e33
Fixes linting errors
DrPaulSharp Oct 17, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
118 changes: 118 additions & 0 deletions plotting_refactor/DataCollector.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
import RandomDatasetCreator
from Dataset import Dataset
from PySide6 import QtWidgets


class DataCollector:
"""
This class keeps track of all generated datasets. When the update_dataset is called through onCalculate
from MainWindow, either a new dataset can be created or the existing dataset is adjusted with respect to
the currently displayed SpinBox Values from the Fitpage.
"""
def __init__(self):
self._datasets: list[Dataset] = []
self.datasetcreator = RandomDatasetCreator.DatasetCreator()

def update_dataset(self, main_window: QtWidgets.QMainWindow, fitpage_index: int,
create_fit: bool, checked_2d: bool):
"""
Search for an existing dataset saved in here. If no dataset for the corresponding fitpage exists: create new
data.
"""

# search for an existing dataset with the right fitpage_index
existing_dataset_index = -1
for i, dataset in enumerate(self._datasets):
if dataset.fitpage_index == fitpage_index:
existing_dataset_index = i

if existing_dataset_index == -1:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add new line between blocks, if you like

# create new dataset in case it does not exist
x_data, y_data, y_fit = self.simulate_data(main_window, create_fit, checked_2d)
plotpage_index = -1

dataset = Dataset(fitpage_index, x_data, y_data, y_fit, checked_2d, plotpage_index)
self._datasets.append(dataset)
else:
# update values for existing dataset with respect to the number boxes in the fitpage
x_data, y_data, y_fit = self.simulate_data(main_window, create_fit, checked_2d)
self._datasets[existing_dataset_index].x_data = x_data
self._datasets[existing_dataset_index].y_data = y_data
self._datasets[existing_dataset_index].y_fit = y_fit
self._datasets[existing_dataset_index].is_data_2d = checked_2d

def simulate_data(self, main_window: QtWidgets.QMainWindow, create_fit: bool, checked_2d: bool):
"""
Collect all information from the FitPage from the MainWindow hat is needed to calculate the test data.
Feed this information to the DatasetCreator and return the values.
"""
combobox_index = main_window.fittingTabs.currentWidget().get_combobox_index()
param_scale = main_window.fittingTabs.currentWidget().doubleSpinBox_scale.value()
param_radius = main_window.fittingTabs.currentWidget().doubleSpinBox_radius.value()
param_height = main_window.fittingTabs.currentWidget().doubleSpinBox_height.value()

x_data, y_data, y_fit = self.datasetcreator.createRandomDataset(param_scale, param_radius, param_height,
combobox_index, create_fit, checked_2d)

return x_data, y_data, y_fit

@property
def datasets(self) -> list:
return self._datasets

def find_object_by_property(self, obj_list: list, property_name: str, property_value: int):
for obj in obj_list:
if hasattr(obj, property_name) and getattr(obj, property_name) == property_value:
return obj

return None

def get_data_by_fp(self, fitpage_index: int) -> Dataset:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A better name would just be data_by_id

"""
Get the dataset for a certain fitpage
"""
return self.find_object_by_property(self._datasets, "fitpage_index", fitpage_index)

def get_data_by_id(self, data_id: int) -> Dataset:
"""
Get the dataset for certain id
"""
return self.find_object_by_property(self._datasets, "data_id", data_id)

def get_x_data(self, fitpage_index: int) -> list:
"""
Get x data for certain fitpage index
"""
dataset = self.find_object_by_property(self._datasets, "fitpage_index", fitpage_index)
return dataset.x_data

def get_y_data(self, fitpage_index: int) -> list:
"""
Get y data for certain fitpage index
"""
dataset = self.find_object_by_property(self._datasets, "fitpage_index", fitpage_index)
return dataset.y_data

def get_y_fit_data(self, fitpage_index: int) -> list:
"""
Get y fit data for certain fitpage index
"""
dataset = self.find_object_by_property(self._datasets, "fitpage_index", fitpage_index)
return dataset.y_fit

def get_plotpage_index(self, fitpage_index: int) -> int:
"""
Get the plotpage index for a certain fitpage index: Plotpage index refers to the index of the major tabs in
the plotting widget in which the data is displayed.
"""
dataset = self.find_object_by_property(self._datasets, "fitpage_index", fitpage_index)
return dataset.plotpage_index

def set_plot_index(self, fitpage_index: int, plot_index: int):
"""
Set the plotpage index for the dataset for a certain fitpage index. Plotpage index refers to the index of the
major tabs in the plotting widget in which the data is displayed.
"""
dataset = self.find_object_by_property(self._datasets, "fitpage_index", fitpage_index)
dataset.plotpage_index = plot_index

29 changes: 29 additions & 0 deletions plotting_refactor/DataTreeItems.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
from PySide6.QtWidgets import QTreeWidgetItem


class PlotPageItem(QTreeWidgetItem):
def __init__(self, parent, name, fitpage_index, data_id):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

types

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Docstring

super().__init__(parent, name)
self._fitpage_index = fitpage_index
self._data_id = data_id
super().setData(0, 1, self)

@property
def fitpage_index(self):
return self._fitpage_index

@property
def data_id(self):
return self._data_id

class DataItem(PlotPageItem):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These do not need to inherit from one another. The DataItem instances should be held within a PlotPageItem instead.

def __init__(self, parent, name, fitpage_index, data_id, type_num):
super().__init__(parent, name, fitpage_index, data_id)
# self.type_num saves if the item is a data item or a fit item in the tree widget
# identifier=1 is for data and identifier=2 is for fit identifier=3 is for residuals
self._type_num = type_num

@property
def type_num(self):
return self._type_num

35 changes: 35 additions & 0 deletions plotting_refactor/DataTreeWidget.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
from DataTreeItems import DataItem
from PySide6.QtCore import QByteArray, QMimeData, QRect, Qt
from PySide6.QtGui import QDrag
from PySide6.QtWidgets import QTreeWidget


class DataTreeWidget(QTreeWidget):
"""
Tree widget that is appearing in the DataViewer. It represents data stored in the DataCollector by objects from
DataTreeItems. Instantiating of these DataTreeItems happens in the DataViewer.
"""
def __init__(self, dataviewer, datacollector):
super().__init__(parent=dataviewer)
self.datacollector = datacollector
self.setGeometry(QRect(10, 10, 391, 312))
self.setDragEnabled(True)
self.setColumnCount(1)
self.setHeaderLabels(["Data Name"])

def startDrag(self, supportedActions: Qt.DropAction):
"""
Overwriting the startDrag from the normal QTreeWidget. When dragging the QTreeWidgetItem to another plot,
mimetypes ID and Type are used to store the dataset.data_id and the type_num. Type_num represents if the
item is a data, fit or residuals item.
"""
item = self.currentItem()
if item:
if isinstance(item.data(0, 1), DataItem):
drag = QDrag(self)
mimeData = QMimeData()
mimeData.setData('ID', QByteArray(str(item.data(0, 1).data_id)))
mimeData.setData('Type', QByteArray(str(item.data(0, 1).type_num)))

drag.setMimeData(mimeData)
drag.exec(supportedActions)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you drag these objects to places outside the window, what happens then?

Loading