# Path: friture/bar_label.py
# class BarLabel(QtCore.QObject):
#     x_changed = QtCore.pyqtSignal()
#     y_changed = QtCore.pyqtSignal()
#     unscaled_x_changed = QtCore.pyqtSignal()
# 
#     def __init__(self, parent=None):
#         super().__init__(parent)
# 
#         self._x = 0.
#         self._y = 0.
#         self._unscaled_x = ""
# 
#     def setData(self, x, unscaled_x, y):
#         if self._x != x:
#             self._x = x
#             self.x_changed.emit()
# 
#         if self._unscaled_x != unscaled_x:
#             self._unscaled_x = unscaled_x
#             self.unscaled_x_changed.emit()
# 
#         if self._y != y:
#             self._y = y
#             self.y_changed.emit()
# 
#     @pyqtProperty(float, notify=x_changed)
#     def x(self):
#         return self._x
# 
#     @pyqtProperty(float, notify=y_changed)
#     def y(self):
#         return self._y
# 
#     @pyqtProperty(str, notify=unscaled_x_changed)
#     def unscaled_x(self):
#         return self._unscaled_x
# 
# Path: friture/scope_data.py
# class Scope_Data(QtCore.QObject):
#     show_legend_changed = QtCore.pyqtSignal(bool) 
#     plot_items_changed = QtCore.pyqtSignal()
# 
#     def __init__(self, parent=None):
#         super().__init__(parent)
# 
#         self._plot_items = []
#         self._horizontal_axis = Axis(self)
#         self._vertical_axis = Axis(self)
#         self._show_legend = True
# 
#     @pyqtProperty(QQmlListProperty, notify=plot_items_changed)
#     def plot_items(self):
#         return QQmlListProperty(Curve, self, self._plot_items)
#     
#     def insert_plot_item(self, index, plot_item):
#         self._plot_items.insert(index, plot_item)
#         self.plot_items_changed.emit()
#     
#     def add_plot_item(self, plot_item):
#         self._plot_items.append(plot_item)
#         plot_item.setParent(self) # take ownership
#         self.plot_items_changed.emit()
# 
#     def remove_plot_item(self, plot_item):
#         self._plot_items.remove(plot_item)
#         self.plot_items_changed.emit()
# 
#     @pyqtProperty(Axis, constant=True)
#     def horizontal_axis(self):
#         return self._horizontal_axis
# 
#     @pyqtProperty(Axis, constant=True)
#     def vertical_axis(self):
#         return self._vertical_axis
#     
#     @pyqtProperty(bool, notify=show_legend_changed)
#     def show_legend(self):
#         return self._show_legend
#     
#     @show_legend.setter
#     def show_legend(self, show_legend):
#         if self._show_legend != show_legend:
#             self._show_legend = show_legend
#             self.show_legend_changed.emit(show_legend)


from PyQt5 import QtCore
from PyQt5.QtCore import pyqtProperty
from PyQt5.QtQml import QQmlListProperty
from friture.bar_label import BarLabel
from friture.scope_data import Scope_Data
# You should have received a copy of the GNU General Public License
# along with Friture.  If not, see <http://www.gnu.org/licenses/>.



class HistPlot_Data(Scope_Data):
    bar_labels_changed = QtCore.pyqtSignal()
    bar_labels_x_distance_changed = QtCore.pyqtSignal()

    def __init__(self, parent=None):
        super().__init__(parent)

        self._bar_labels = []
        self._bar_labels_x_distance = 0.
    
    def setBarLabels(self, x, unscaled_x, y):
        x_distance = x[1] - x[0]
        if self._bar_labels_x_distance != x_distance:
            self._bar_labels_x_distance = x_distance
            self.bar_labels_x_distance_changed.emit()

        label_count = x.shape[0]
        
        # never display more than 60 labels
        # it is not useful visually
        # and the loop to build them would be too slow
        if label_count > 60:
            label_count = 0

        if label_count != len(self._bar_labels):

# Path: friture/bar_label.py
# class BarLabel(QtCore.QObject):
#     x_changed = QtCore.pyqtSignal()
#     y_changed = QtCore.pyqtSignal()
#     unscaled_x_changed = QtCore.pyqtSignal()
# 
#     def __init__(self, parent=None):
#         super().__init__(parent)
# 
#         self._x = 0.
#         self._y = 0.
#         self._unscaled_x = ""
# 
#     def setData(self, x, unscaled_x, y):
#         if self._x != x:
#             self._x = x
#             self.x_changed.emit()
# 
#         if self._unscaled_x != unscaled_x:
#             self._unscaled_x = unscaled_x
#             self.unscaled_x_changed.emit()
# 
#         if self._y != y:
#             self._y = y
#             self.y_changed.emit()
# 
#     @pyqtProperty(float, notify=x_changed)
#     def x(self):
#         return self._x
# 
#     @pyqtProperty(float, notify=y_changed)
#     def y(self):
#         return self._y
# 
#     @pyqtProperty(str, notify=unscaled_x_changed)
#     def unscaled_x(self):
#         return self._unscaled_x
# 
# Path: friture/scope_data.py
# class Scope_Data(QtCore.QObject):
#     show_legend_changed = QtCore.pyqtSignal(bool) 
#     plot_items_changed = QtCore.pyqtSignal()
# 
#     def __init__(self, parent=None):
#         super().__init__(parent)
# 
#         self._plot_items = []
#         self._horizontal_axis = Axis(self)
#         self._vertical_axis = Axis(self)
#         self._show_legend = True
# 
#     @pyqtProperty(QQmlListProperty, notify=plot_items_changed)
#     def plot_items(self):
#         return QQmlListProperty(Curve, self, self._plot_items)
#     
#     def insert_plot_item(self, index, plot_item):
#         self._plot_items.insert(index, plot_item)
#         self.plot_items_changed.emit()
#     
#     def add_plot_item(self, plot_item):
#         self._plot_items.append(plot_item)
#         plot_item.setParent(self) # take ownership
#         self.plot_items_changed.emit()
# 
#     def remove_plot_item(self, plot_item):
#         self._plot_items.remove(plot_item)
#         self.plot_items_changed.emit()
# 
#     @pyqtProperty(Axis, constant=True)
#     def horizontal_axis(self):
#         return self._horizontal_axis
# 
#     @pyqtProperty(Axis, constant=True)
#     def vertical_axis(self):
#         return self._vertical_axis
#     
#     @pyqtProperty(bool, notify=show_legend_changed)
#     def show_legend(self):
#         return self._show_legend
#     
#     @show_legend.setter
#     def show_legend(self, show_legend):
#         if self._show_legend != show_legend:
#             self._show_legend = show_legend
#             self.show_legend_changed.emit(show_legend)


# Path: friture/histplot_data.py
from PyQt5 import QtCore
from PyQt5.QtCore import pyqtProperty
from PyQt5.QtQml import QQmlListProperty
from friture.bar_label import BarLabel
from friture.scope_data import Scope_Data

# You should have received a copy of the GNU General Public License
# along with Friture.  If not, see <http://www.gnu.org/licenses/>.



class HistPlot_Data(Scope_Data):
    bar_labels_changed = QtCore.pyqtSignal()
    bar_labels_x_distance_changed = QtCore.pyqtSignal()

    def __init__(self, parent=None):
        super().__init__(parent)

        self._bar_labels = []
        self._bar_labels_x_distance = 0.
    
    def setBarLabels(self, x, unscaled_x, y):
        x_distance = x[1] - x[0]
        if self._bar_labels_x_distance != x_distance:
            self._bar_labels_x_distance = x_distance
            self.bar_labels_x_distance_changed.emit()

        label_count = x.shape[0]
        
        # never display more than 60 labels
        # it is not useful visually
        # and the loop to build them would be too slow
        if label_count > 60:
            label_count = 0

        if label_count != len(self._bar_labels):

            self._bar_labels = [BarLabel(self) for i in range(label_count)]