Changeset 8313:fb079a26cd2c in orange


Ignore:
Timestamp:
06/13/11 11:39:05 (3 years ago)
Author:
Noughmad <Noughmad@…>
Branch:
default
Convert:
c7dc283d8b474f4b1835add94977d49ce70df3fc
Message:

Use Qt for clipping data and selection curves, makes zooming even faster

Files:
3 edited

Legend:

Unmodified
Added
Removed
  • orange/OrangeWidgets/Graph/axis.py

    r8309 r8313  
    148148        del self.tick_items[:] 
    149149        min, max, step = self.scale 
    150         self.transform = QTransform().translate(-self.x(), -self.y()) * self.zoom_transform * QTransform().translate(self.x(), self.y()) 
     150        ## Warning: The following line make a separation between X and Y axes. 
     151        ## TODO: Figure out the general case, and determine what to do for non-cartesian axes. 
     152        self.transform = QTransform().translate(-self.line.x1(), -self.line.y2()) * self.zoom_transform * QTransform().translate(self.line.x1(), self.line.y2()) 
    151153        ratio = self.transform.map(self.line).length() / self.line.length() 
    152154        qDebug('Axis zoom ratio = ' + str(ratio)) 
     
    222224        min, max, step = self.scale 
    223225        line_point = self.line.pointAt( (x-min)/(max-min) ) 
    224         end_point = line_point * self.zoom_transform 
     226        end_point = line_point * self.transform 
    225227        return self.projection(end_point, self.line) 
    226228         
  • orange/OrangeWidgets/OWGraphQt.py

    r8312 r8313  
    8888        self.setScene(self.canvas) 
    8989        self.setRenderHints(QPainter.Antialiasing | QPainter.TextAntialiasing) 
     90        self.graph_item = QGraphicsRectItem(scene=self.canvas) 
     91        self.graph_item.setPen(QPen(Qt.NoPen)) 
     92        self.graph_item.setFlag(QGraphicsItem.ItemClipsChildrenToShape, True) 
    9093         
    9194        self._legend = legend.Legend(self.canvas) 
     
    265268                 lineWidth = 1, pen = None, autoScale = 0, antiAlias = None, penAlpha = 255, brushAlpha = 255): 
    266269         
    267         c = curve.Curve() 
     270        c = curve.Curve(parent=self.graph_item) 
    268271        c.name = name 
    269272        c.setAutoUpdate(False) 
     
    294297     
    295298    def update_layout(self): 
    296         graph_rect = QRectF(self.childrenRect()) 
     299        graph_rect = QRectF(self.contentsRect()) 
    297300        m = self.graph_margin 
    298301        graph_rect.adjust(m, m, -m, -m) 
     
    310313         
    311314        if self.show_legend: 
     315            ## TODO: Figure out a good placement for the legend, possibly outside the graph area 
    312316            self._legend.setPos(graph_rect.topRight() - QPointF(100, 0)) 
    313317            self._legend.show() 
     
    350354                 
    351355        self.graph_area = QRectF(graph_rect) 
     356        p = self.graph_area.topLeft() 
     357        self.graph_area.translate(-p.x(), -p.y()) 
     358        self.graph_item.setRect(self.graph_area) 
     359        self.graph_item.setPos(p) 
     360         
    352361        self.update_axes(axis_rects) 
    353362         
     
    372381            a.zoom_transform = self.zoom_transform 
    373382            a.update() 
     383             
     384        for i in self.selection_items: 
     385            i.setTransform(self.zoom_transform) 
    374386        self.setSceneRect(self.canvas.itemsBoundingRect()) 
    375387         
     
    413425        self.static_click = True 
    414426        self._pressed_mouse_button = event.button() 
    415         if event.button() == Qt.LeftButton and self.state == SELECT_RECTANGLE: 
     427        point = self.map_from_widget(event.pos()) 
     428        if event.button() == Qt.LeftButton and self.state == SELECT_RECTANGLE and self.graph_area.contains(point): 
    416429            qDebug('Press: ' + repr(event.button())) 
    417             self._selection_start_point = QPointF(event.pos()) 
    418             self._current_ps_item = QGraphicsRectItem() 
    419             self.canvas.addItem(self._current_ps_item) 
     430            self._selection_start_point = self.map_from_widget(event.pos()) 
     431            self._current_ps_item = QGraphicsRectItem(parent=self.graph_item, scene=self.canvas) 
    420432             
    421433    def mouseMoveEvent(self, event): 
     
    427439        qDebug('Move: ' + repr(event.button())) 
    428440        if self._pressed_mouse_button == Qt.LeftButton: 
    429             if self.state == SELECT_RECTANGLE: 
     441            point = self.map_from_widget(event.pos()) 
     442            if self.state == SELECT_RECTANGLE and self.graph_area.contains(point): 
    430443                qDebug('Move move event') 
    431                 self._current_ps_item.setRect(QRectF(self._selection_start_point, QPointF(event.pos()))) 
     444                self._current_ps_item.setRect(QRectF(self._selection_start_point, point)) 
    432445             
    433446    def mouseReleaseEvent(self, event): 
     
    445458     
    446459    def mouseStaticClick(self, event): 
     460        point = self.map_from_widget(event.pos()) 
    447461        if self.state == ZOOMING: 
    448462            t, ok = self.zoom_transform.inverted() 
    449             p = QPointF(event.pos()) * t 
     463            p = point * t 
    450464            if event.button() == Qt.LeftButton: 
    451465                end_zoom_factor = self._zoom_factor * 2 
     
    461475            return True 
    462476        elif self.state == SELECT_POLYGON and event.button() == Qt.LeftButton: 
    463             self._current_ps_polygon.addPoint(QPointF(event.pos())) 
     477            self._current_ps_polygon.addPoint(point) 
    464478            self._current_ps_item.setPolygon(self._current_ps_polygon) 
    465479        elif (self.state == SELECT_RECTANGLE or self.state == SELECT_POLYGON) and event.button() == Qt.RightButton: 
    466480            self.selection_items.reverse() 
    467481            for i in self.selection_items: 
    468                 if i.shape().contains(QPointF(event.pos())): 
     482                if i.shape().contains(point): 
    469483                    self.canvas.removeItem(i) 
    470484                    self.selection_items.remove(i) 
     
    522536    def set_state(self, state): 
    523537        self.state = state 
     538         
     539    def map_from_widget(self, point): 
     540        return QPointF(point) - QPointF(self.contentsRect().topLeft()) - self.graph_item.pos() 
  • source/orangegraph/curve.cpp

    r8310 r8313  
    7373    { 
    7474      p = QPointF(m_data[i].x, m_data[i].y); 
    75       if (dataRect.contains(p)) 
    76       { 
    77     m_pointItems[i]->show(); 
    78     m_pointItems[i]->setPos(m_graphTransform.map(p)); 
    79       } 
    80       else 
    81       { 
    82     m_pointItems[i]->hide(); 
    83       } 
     75      m_pointItems[i]->setPos(m_graphTransform.map(p)); 
    8476    } 
    8577  } 
     
    10597  QBrush brush(m_color); 
    10698  m_path = pathForSymbol(m_symbol, m_pointSize); 
    107   QRectF dataRect = m_graphTransform.inverted().mapRect(m_graphArea); 
    10899  QPointF p; 
    109100  for (int i = 0; i < n; ++i) 
     
    113104    item->setPath(m_path); 
    114105    p = QPointF(point.x, point.x); 
    115     if (dataRect.contains(p)) 
    116     { 
    117       item->setPos(p * m_graphTransform); 
    118       item->show(); 
    119     } 
    120     else 
    121     { 
    122       item->hide(); 
    123     } 
     106    item->setPos(p * m_graphTransform); 
    124107    item->setBrush(brush); 
    125108  } 
Note: See TracChangeset for help on using the changeset viewer.