예제 #1
0
 def initPlotSelector(self):
     self._plotListModel = PlotListModel()
     plotSelector = self.getChild('plotSelector')
     plotSelector.setModel(self._plotListModel)
예제 #2
0
class QPlotOptionsWidget(QEditFigureSubWidget):

    properties = (
                'name',
                'nameFont',
                'backgroundColor',
                'plotType',
            )

    def __init__(self, *args):
        QEditFigureSubWidget.__init__(self, *args)
        self._currentPlot = None
    
    def currentPlot(self):
        return self._currentPlot

    def initPlotSelector(self):
        self._plotListModel = PlotListModel()
        plotSelector = self.getChild('plotSelector')
        plotSelector.setModel(self._plotListModel)

    def initSubWidgets(self):
        # Add all the plot widgets to the stack
        self.scatterPlotWidget = QScatterPlotTypeWidget(self, self.getChild('plotTypeStack'))
        scatterPlotWidgetUi = Ui_PlotTypeWidget()
        scatterPlotWidgetUi.setupUi(self.scatterPlotWidget)
        self.scatterPlotWidget.initSubWidgets()
        self.getChild('plotTypeStack').addWidget(self.scatterPlotWidget)
        self.getChild('plotType').addItem('Scatter Plot')

        #self.barPlotWidget = QEditFigureSubWidget(self.getChild('plotTypeStack'))
        self.barPlotWidget = QBarPlotTypeWidget(self, self.getChild('plotTypeStack'))
        barPlotWidgetUi = Ui_PlotTypeWidget()
        barPlotWidgetUi.setupUi(self.barPlotWidget)
        self.barPlotWidget.initSubWidgets()
        self.getChild('plotTypeStack').addWidget(self.barPlotWidget)
        self.getChild('plotType').addItem('Bar Chart')

        self.piePlotWidget = QEditFigureSubWidget(self.getChild('plotTypeStack'))
        piePlotWidgetUi = Ui_PlotTypeWidget()
        piePlotWidgetUi.setupUi(self.piePlotWidget)
        self.getChild('plotTypeStack').addWidget(self.piePlotWidget)
        self.getChild('plotType').addItem('Pie Chart')

        self.getChild('plotType').setCurrentRow(0)

    def changeCurrentPlot(self, index):
        if index < 0:
            return

        self._currentPlot = self._plotListModel.getPlot(index)
        self.getChild('plotSelector').setCurrentIndex(index)
        self.resetUi()
        self.getChild('plotTypeStack').currentWidget().resetUi() # Reset the plot type widget's ui

    def setFigure(self, figure, index=0):
        """
        Set the figure whose plots should be displayed.
        """

        if not figure:
            return

        self._plotListModel.setFigure(figure)
        self._plotListModel.doReset()

        if index >= figure.numPlots():
            index = 0
        
        self.changeCurrentPlot(index)
    
    def refreshPlotSelector(self):
        """
        Refresh the plot selector.  Intended to be used if the number of
        plots on a figure changes, so that we can make sure that the combo box
        is still valid.
        """
        self.setFigure(self._editFigureDialogModule.currentFigure(), self.getChild('plotSelector').currentIndex())

    def saveUi(self):
        """Save the UI data to the current Plot object."""
        
        self.currentPlot().setMultiple(self.getCurrentUi())

    def resetUi(self):
        """
        Set the UI to the current Plot's settings.
        
        Any unknown widget types will be discarded.
        """
        
        self.setCurrentUi(self.currentPlot().properties)

        # Change the plot type widget that is shown based on the type of plot
        # that is currently selected (scatter, pie, etc)
        self.getChild('plotTypeStack').setCurrentIndex(self.getChild('plotType').currentRow())


    def applyClicked(self):
        self.saveUi()
        self.refreshPlotSelector()

    def reload(self):
        self.scatterPlotWidget.reload()