Changeset 8315:7d886b606481 in orange


Ignore:
Timestamp:
06/13/11 14:40:29 (3 years ago)
Author:
Noughmad <Noughmad@…>
Branch:
default
Convert:
a250ba38901bc83bab9f0d7fcaf57e1284c4c2ed
Message:

Support for Rectangle selection and sending selected data

Location:
orange/OrangeWidgets
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • orange/OrangeWidgets/OWGraphQt.py

    r8314 r8315  
    2828    .. method graph_area_rect() 
    2929        Return the QRectF of the area where data is plotted (without axes) 
     30         
     31    .. method send_data(): 
     32        This method is not defined here, it is up to subclasses to implement it.  
     33        It should send selected examples to the next widget 
    3034""" 
    3135 
     
    7680                                "activateZooming" : "activate_zooming",  
    7781                                "activateRectangleSelection" : "activate_rectangle_selection",  
    78                                 "activatePolygonSelection" : "activate_polygon_selection" 
     82                                "activatePolygonSelection" : "activate_polygon_selection",  
     83                                "getSelectedPoints" : "get_selected_points" 
    7984                                }) 
    8085class OWGraph(QGraphicsView): 
     
    118123        self.selection_items = [] 
    119124        self._current_ps_item = None 
     125        self.auto_send_selection_callback = None 
     126         
    120127        self.curves = [] 
    121128        self.data_range = {xBottom : (0, 1), yLeft : (0, 1)} 
     
    143150         
    144151    selectionCurveList = deprecated_attribute("selectionCurveList", "selection_items") 
     152    autoSendSelectionCallback = deprecated_attribute("autoSendSelectionCallback", "auto_send_selection_callback") 
    145153     
    146154    def __setattr__(self, name, value): 
     
    430438        if self._pressed_mouse_button == Qt.LeftButton: 
    431439            point = self.map_from_widget(event.pos()) 
    432             if self.state == SELECT_RECTANGLE and self.graph_area.contains(point): 
     440            if self.state == SELECT_RECTANGLE and self._current_ps_item and self.graph_area.contains(point): 
    433441                self._current_ps_item.setRect(QRectF(self._selection_start_point, point)) 
    434442             
     
    444452            self.selection_items.append(self._current_ps_item) 
    445453            self._current_ps_item = None 
     454            if self.auto_send_selection_callback:  
     455                self.auto_send_selection_callback() 
     456            
    446457     
    447458    def mouseStaticClick(self, event): 
     
    471482                    self.canvas.removeItem(i) 
    472483                    self.selection_items.remove(i) 
     484                    if self.auto_send_selection_callback:  
     485                        self.auto_send_selection_callback() 
    473486                    break 
    474487            self.selection_items.reverse() 
     
    527540    def map_from_widget(self, point): 
    528541        return QPointF(point) - QPointF(self.contentsRect().topLeft()) - self.graph_item.pos() 
     542         
     543    def get_selected_points(self, xData, yData, validData): 
     544        reg = QRegion() 
     545        selected = [] 
     546        unselected = [] 
     547        for i in self.selection_items: 
     548            reg = reg.united(i.rect().toRect()) 
     549        for j in range(len(xData)): 
     550            (x, y) = self.map_to_graph( (xData[j], yData[j]) ) 
     551            p = QPointF(x, y).toPoint() 
     552            sel = reg.contains(p) 
     553            selected.append(sel) 
     554            unselected.append(not sel) 
     555        return selected, unselected 
  • orange/OrangeWidgets/OWToolbars.py

    r8042 r8315  
    5656                 ("Remove last selection", "buttonRemoveLastSelection", "removeLastSelection", QIcon(dlg_undo), None, 0), 
    5757                 ("Remove all selections", "buttonRemoveAllSelections", "removeAllSelections", QIcon(dlg_clear), None, 0), 
    58                  ("Send selections", "buttonSendSelections", "sendData", QIcon(dlg_send), None, 0), 
     58                 ("Send selections", "buttonSendSelections", "sendSelections", QIcon(dlg_send), None, 0), 
    5959                 ("Zoom to extent", "buttonZoomExtent", "zoomExtent", QIcon(dlg_zoom_extent), None, 0), 
    6060                 ("Zoom selection", "buttonZoomSelection", "zoomSelection", QIcon(dlg_zoom_selection), None, 0) 
     
    103103                    if ff and ff[5]: 
    104104                        getattr(tbar, ff[1]).setChecked(self == tbar and fi == b) 
    105         getattr(self.graph, f[2])() 
     105         
     106        if hasattr(self.graph, f[2]): 
     107            getattr(self.graph, f[2])() 
     108        elif hasattr(self.widget, f[2]): 
     109            getattr(self.widget, f[2])() 
    106110 
    107111        cursor = f[4] 
     
    131135                 ("Remove last selection", "buttonRemoveLastSelection", "removeLastSelection", QIcon(dlg_undo), None, 0, "select"), 
    132136                 ("Remove all selections", "buttonRemoveAllSelections", "removeAllSelections", QIcon(dlg_clear), None, 0, "select"), 
    133                  ("Send selections", "buttonSendSelections", "sendData", QIcon(dlg_send), None, 0, "select"), 
     137                 ("Send selections", "buttonSendSelections", "sendSelections", QIcon(dlg_send), None, 0, "select"), 
    134138                 ("Zoom to extent", "buttonZoomExtent", "zoomExtent", QIcon(dlg_zoom_extent), None, 0, "navigate"), 
    135139                 ("Zoom selection", "buttonZoomSelection", "zoomSelection", QIcon(dlg_zoom_selection), None, 0, "navigate") 
     
    183187                    #    getattr(self.select, ff[1]).setChecked(fi == b) 
    184188                 
    185         try: 
     189        if hasattr(self.graph, f[2]): 
    186190            getattr(self.graph, f[2])() 
    187         except: 
     191        elif hasattr(self.widget, f[2]): 
    188192            getattr(self.widget, f[2])() 
    189193 
Note: See TracChangeset for help on using the changeset viewer.