Changeset 8540:f6f3deb14fe8 in orange


Ignore:
Timestamp:
07/30/11 17:37:12 (3 years ago)
Author:
Noughmad <Noughmad@…>
Branch:
default
Convert:
b19ecd4f011734c1b8f9c1a7b2fde92f2ea6a6ba
Message:

Add support for unselecting and unmarking all points, and use it to implement exclusive selection in the GUI

Files:
7 edited

Legend:

Unmodified
Added
Removed
  • orange/OrangeWidgets/plot/owconstants.py

    r8537 r8540  
    3434SELECTION_REMOVE = 1 
    3535SELECTION_TOGGLE = 2 
    36 SELECTION_ONE = 3 
     36SELECTION_REPLACE = 3 
  • orange/OrangeWidgets/plot/owplot.py

    r8538 r8540  
    849849            d = 10 * max(dr.width(), dr.height()) / max(gr.width(), gr.height()) 
    850850            point_item = self.nearest_point(self.map_from_graph(point), d) 
    851             qDebug(repr(self.map_from_graph(point)) + ' ' + repr(point_item)) 
     851            b = self.selection_behavior 
     852            if b == self.ReplaceSelection: 
     853                self.unselect_all_points() 
     854                b = self.AddSelection 
    852855            if point_item: 
    853                 point_item.set_selected(True) 
     856                point_item.set_selected(b == self.AddSelection or (b == self.ToggleSelection and not point_item.is_selected())) 
    854857        else: 
    855858            return False 
  • orange/OrangeWidgets/plot/owplotgui.py

    r8538 r8540  
    100100        SelectionRemove : ('Remove from selection', 'selection_behavior', SELECTION_REMOVE, ''), 
    101101        SelectionToggle : ('Toggle selection', 'selection_behavior', SELECTION_TOGGLE, ''), 
    102         SelectionOne : ('Replace selection', 'selection_behavior', SELECTION_ONE, '') 
     102        SelectionOne : ('Replace selection', 'selection_behavior', SELECTION_REPLACE, '') 
    103103    } 
    104104     
  • source/orangeplot/plot.cpp

    r8523 r8540  
    162162void Plot::mark_points(const QRectF& rect, Plot::SelectionBehavior behavior) 
    163163{ 
     164    if (behavior == ReplaceSelection) 
     165    { 
     166        unmark_all_points(); 
     167        behavior = AddSelection; 
     168    } 
    164169    set_points_state(rect, scene(), Point::Marked, behavior); 
    165170} 
     
    167172void Plot::mark_points(const QPolygonF& area, Plot::SelectionBehavior behavior) 
    168173{ 
     174    if (behavior == ReplaceSelection) 
     175    { 
     176        unmark_all_points(); 
     177        behavior = AddSelection; 
     178    } 
    169179    set_points_state(area, scene(), Point::Marked, behavior); 
    170180} 
     
    172182void Plot::select_points(const QRectF& rect, Plot::SelectionBehavior behavior) 
    173183{ 
     184    if (behavior == ReplaceSelection) 
     185    { 
     186        unselect_all_points(); 
     187        behavior = AddSelection; 
     188    } 
    174189    set_points_state(rect, scene(), Point::Selected, behavior); 
    175190} 
     
    177192void Plot::select_points(const QPolygonF& area, Plot::SelectionBehavior behavior) 
    178193{ 
     194    if (behavior == ReplaceSelection) 
     195    { 
     196        unselect_all_points(); 
     197        behavior = AddSelection; 
     198    } 
    179199    set_points_state(area, scene(), Point::Selected, behavior); 
    180200} 
     
    281301} 
    282302 
     303void Plot::unmark_all_points() 
     304{ 
     305    foreach (const PointHash& hash, m_point_hash) 
     306    { 
     307        foreach (Point* point, hash) 
     308        { 
     309            point->set_marked(false); 
     310        } 
     311    } 
     312} 
     313 
     314void Plot::unselect_all_points() 
     315{ 
     316    int i = 0; 
     317    foreach (const PointHash& hash, m_point_hash) 
     318    { 
     319        foreach (Point* point, hash) 
     320        { 
     321            ++i; 
     322            point->set_selected(false); 
     323        } 
     324    } 
     325    qDebug() << "Unselected" << i << "points"; 
     326} 
     327 
     328 
    283329#include "plot.moc" 
  • source/orangeplot/plot.h

    r8511 r8540  
    1919        AddSelection, 
    2020        RemoveSelection, 
    21         ToggleSelection 
     21        ToggleSelection, 
     22        ReplaceSelection 
    2223    }; 
    2324     
     
    7475    void remove_point(const DataPoint& pos, PlotItem* parent); 
    7576    void remove_all_points(PlotItem* parent); 
     77     
     78    void unselect_all_points(); 
     79    void unmark_all_points(); 
    7680        
    7781protected: 
     
    7983    bool is_dirty(); 
    8084     
    81 private: 
     85private:     
    8286    QList<PlotItem*> m_items; 
    8387    bool m_dirty; 
  • source/orangeplot/plot.sip

    r8511 r8540  
    3636        AddSelection, 
    3737        RemoveSelection, 
    38         ToggleSelection 
     38        ToggleSelection, 
     39        ReplaceSelection 
    3940    }; 
    4041     
     
    5960    void select_points(const QRectF& rect, SelectionBehavior behavior = AddSelection); 
    6061    void select_points(const QPolygonF& area, SelectionBehavior behavior = AddSelection); 
     62    void unselect_all_points(); 
     63     
    6164    void mark_points(const QRectF& rect, SelectionBehavior behavior = AddSelection); 
    6265    void mark_points(const QPolygonF& area, SelectionBehavior behavior = AddSelection); 
     66    void unmark_all_points(); 
    6367     
    6468    QList< int > selected_points(const QList< double > x_data, const QList< double > y_data, const QTransform& transform); 
  • source/orangeplot/point.cpp

    r8502 r8540  
    284284    else 
    285285    { 
    286         m_size &= ~flag; 
     286        m_state &= ~flag; 
    287287    } 
    288288    update(); 
Note: See TracChangeset for help on using the changeset viewer.