Changeset 8476:572b2e9e7e1f in orange


Ignore:
Timestamp:
07/27/11 10:55:34 (3 years ago)
Author:
Noughmad <Noughmad@…>
Branch:
default
Convert:
3e2752a4ffe3db95c67b101584d48a349dc93be6
Message:

Selection is now point-based, so individual points can be selected.

Note that point selection is not yet possible from the GUI

Files:
6 edited

Legend:

Unmodified
Added
Removed
  • orange/OrangeWidgets/Prototypes/OWScatterPlotGraphQt.py

    r8466 r8476  
    440440        #if not self.rawData: return (None, None, None) 
    441441        if not self.haveData: return (None, None) 
    442         if not self.selectionCurveList: return (None, self.rawData)       # if no selections exist 
    443442 
    444443        selIndices, unselIndices = self.getSelectionsAsIndices(attrList) 
  • orange/OrangeWidgets/plot/owplot.py

    r8471 r8476  
    187187 
    188188        self.activate_zooming() 
     189        self.selection_behavior = self.AddSelection 
    189190        self.replot() 
    190191         
     
    804805         
    805806    def get_selected_points(self, xData, yData, validData): 
    806         region = QRegion() 
    807807        selected = [] 
    808808        unselected = [] 
    809         for item, reg in self.selection_items: 
    810             region |= reg 
    811         for j in range(len(xData)): 
    812             (x, y) = self.map_to_graph( (xData[j], yData[j]) ) 
    813             p = (QPointF(xData[j], yData[j]) * self.map_transform).toPoint() 
    814             sel = region.contains(p) 
    815             selected.append(sel) 
    816             unselected.append(not sel) 
     809        qDebug('Getting selected points') 
     810        for i in self.selected_points(xData, yData, self.map_transform): 
     811            selected.append(i) 
     812            unselected.append(not i) 
    817813        return selected, unselected 
    818814         
    819815    def add_selection_item(self, item, reg): 
    820         if type(reg) == QRectF: 
    821             reg = reg.toRect() 
    822         elif type(reg) == QPolygonF: 
    823             reg = reg.toPolygon() 
    824         t = (item, QRegion(reg)) 
    825         self.selection_items.append(t) 
     816        self.select_points(reg, self.selection_behavior) 
    826817        if self.auto_send_selection_callback: 
    827818            self.auto_send_selection_callback() 
  • source/orangeplot/plot.cpp

    r8475 r8476  
    11#include "plot.h" 
    22#include "plotitem.h" 
     3#include "point.h" 
    34 
    45#include <QtCore/QDebug> 
     
    1213     * inside the specified rect 
    1314     */ 
    14     foreach (QGraphicsItem* item, scene->items(area, Qt::ContainsItemBoundingRect)) 
     15    foreach (QGraphicsItem* item, scene->items(area, Qt::IntersectsItemBoundingRect)) 
    1516    { 
    1617        Point* point = qgraphicsitem_cast<Point*>(item); 
     
    157158} 
    158159 
     160QList< int > Plot::selected_points(const QList< double > x_data, const QList< double > y_data, const QTransform& transform) 
     161{ 
     162    Q_ASSERT(x_data.size() == y_data.size()); 
     163    const int n = qMin(x_data.size(), y_data.size()); 
     164    QList<int> selected; 
     165    selected.reserve(n); 
     166    for (int i = 0; i < n; ++i) 
     167    { 
     168        const QPointF coords = QPointF(x_data[i], y_data[i]) * transform; 
     169        bool found_point = false; 
     170        foreach (QGraphicsItem* item, scene()->items(coords)) 
     171        { 
     172            if (item->pos() != coords) 
     173            { 
     174                continue; 
     175            } 
     176            const Point* point = qgraphicsitem_cast<Point*>(item); 
     177            found_point = (point && point->is_selected()); 
     178            if (found_point) 
     179            { 
     180                break; 
     181            } 
     182        } 
     183        selected << found_point; 
     184    } 
     185    qDebug() << "Found" << selected.count(1) << "selected points out of" << selected.size(); 
     186    return selected; 
     187} 
     188 
     189 
    159190#include "plot.moc" 
  • source/orangeplot/plot.h

    r8475 r8476  
    4242    void mark_points(const QPolygonF& area, SelectionBehavior behavior = AddSelection); 
    4343     
     44    QList< int > selected_points(const QList< double > x_data, const QList< double > y_data, const QTransform& transform); 
     45     
    4446protected: 
    4547    void set_clean();; 
  • source/orangeplot/plot.sip

    r8446 r8476  
    3232 
    3333public: 
     34    enum SelectionBehavior 
     35    { 
     36        AddSelection, 
     37        RemoveSelection, 
     38        ToggleSelection 
     39    }; 
     40     
    3441    Plot(QWidget* parent /TransferThis/ = 0); 
    3542    virtual ~Plot(); 
     
    5057    QGraphicsRectItem* graph_item; 
    5158     
     59    void select_points(const QRectF& rect, SelectionBehavior behavior = AddSelection); 
     60    void select_points(const QPolygonF& area, SelectionBehavior behavior = AddSelection); 
     61    void mark_points(const QRectF& rect, SelectionBehavior behavior = AddSelection); 
     62    void mark_points(const QPolygonF& area, SelectionBehavior behavior = AddSelection); 
     63     
     64    QList< int > selected_points(const QList< double > x_data, const QList< double > y_data, const QTransform& transform); 
     65     
    5266protected: 
    5367    void set_clean(); 
  • source/orangeplot/point.cpp

    r8475 r8476  
    3131    if (m_display_mode == DisplayPath) 
    3232    { 
    33         painter->setPen(m_color); 
     33        if (m_state & Selected) 
     34        { 
     35            painter->setBrush(m_color); 
     36            painter->setPen(Qt::yellow); 
     37        } 
     38        else if (m_state & Marked) 
     39        { 
     40            painter->setBrush(m_color); 
     41        } 
     42        else 
     43        { 
     44            painter->setPen(m_color); 
     45        } 
    3446        const QPainterPath path = path_for_symbol(m_symbol, m_size); 
    3547        painter->drawPath(path_for_symbol(m_symbol, m_size)); 
     
    241253        m_size &= ~flag; 
    242254    } 
     255    update(); 
    243256} 
    244257bool Point::state_flag(Point::StateFlag flag) const { 
Note: See TracChangeset for help on using the changeset viewer.