Changeset 8475:61c1ff43a2c5 in orange


Ignore:
Timestamp:
07/27/11 08:40:26 (3 years ago)
Author:
Noughmad <Noughmad@…>
Branch:
default
Convert:
4957c150a51f40d57a4f9d0801d7a053c8e1149a
Message:

Make points selectable, and add method to Plot to select point in a specified area

Location:
source/orangeplot
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • source/orangeplot/networkcurve.cpp

    r8472 r8475  
    3131    Q_UNUSED(widget) 
    3232 
    33     if (m_selected) { 
     33    if (is_selected()) { 
    3434        painter->setPen(QPen(Qt::yellow, 3)); 
    3535        painter->setBrush(color()); 
    3636        QRectF rect(-(size() + 4) / 2, -(size() + 4) / 2, size() + 4, size() + 4); 
    3737        painter->drawEllipse(rect); 
    38     } else if (m_marked) { 
     38    } else if (is_marked()) { 
    3939        painter->setPen(color()); 
    4040        painter->setBrush(color()); 
     
    105105{ 
    106106    return m_label; 
    107 } 
    108  
    109 void NodeItem::set_selected(bool selected) 
    110 { 
    111     m_selected = selected; 
    112 } 
    113  
    114 bool NodeItem::is_selected() const 
    115 { 
    116     return m_selected; 
    117 } 
    118  
    119 void NodeItem::set_marked(bool marked) 
    120 { 
    121     m_marked = marked; 
    122 } 
    123  
    124 bool NodeItem::is_marked() const 
    125 { 
    126     return m_marked; 
    127107} 
    128108 
  • source/orangeplot/networkcurve.h

    r8472 r8475  
    3333    QString label() const; 
    3434 
    35     void set_selected(bool selected); 
    36     bool is_selected() const; 
    37  
    38     void set_marked(bool marked); 
    39     bool is_marked() const; 
    40  
    4135    void set_tooltip(const QString& tooltip); 
    4236 
     
    6155     
    6256    int m_index; 
    63     bool m_marked; 
    64     bool m_selected; 
    6557    QString m_label; 
    6658    int m_uuid; 
  • source/orangeplot/plot.cpp

    r8444 r8475  
    33 
    44#include <QtCore/QDebug> 
     5 
     6template <class Area> 
     7void set_points_state(Area area, QGraphicsScene* scene, Point::StateFlag flag, Plot::SelectionBehavior behavior) 
     8{ 
     9    /* 
     10     * NOTE: I think it's faster to rely on Qt to get all items in the current rect 
     11     * than to iterate over all points on the graph and check which of them are  
     12     * inside the specified rect 
     13     */ 
     14    foreach (QGraphicsItem* item, scene->items(area, Qt::ContainsItemBoundingRect)) 
     15    { 
     16        Point* point = qgraphicsitem_cast<Point*>(item); 
     17        if (point) 
     18        { 
     19            point->set_state_flag(flag, behavior == Plot::AddSelection || (behavior == Plot::ToggleSelection && !point->state_flag(flag))); 
     20        } 
     21    } 
     22} 
    523 
    624Plot::Plot(QWidget* parent):  
     
    119137} 
    120138 
     139void Plot::mark_points(const QRectF& rect, Plot::SelectionBehavior behavior) 
     140{ 
     141    set_points_state(rect, scene(), Point::Marked, behavior); 
     142} 
     143 
     144void Plot::mark_points(const QPolygonF& area, Plot::SelectionBehavior behavior) 
     145{ 
     146    set_points_state(area, scene(), Point::Marked, behavior); 
     147} 
     148 
     149void Plot::select_points(const QRectF& rect, Plot::SelectionBehavior behavior) 
     150{ 
     151    set_points_state(rect, scene(), Point::Selected, behavior); 
     152} 
     153 
     154void Plot::select_points(const QPolygonF& area, Plot::SelectionBehavior behavior) 
     155{ 
     156    set_points_state(area, scene(), Point::Selected, behavior); 
     157} 
     158 
    121159#include "plot.moc" 
  • source/orangeplot/plot.h

    r8446 r8475  
    44#include <QtGui/QGraphicsView> 
    55 
     6class Point; 
    67class PlotItem; 
    78 
     
    1011    Q_OBJECT 
    1112public: 
     13    enum SelectionBehavior 
     14    { 
     15        AddSelection, 
     16        RemoveSelection, 
     17        ToggleSelection 
     18    }; 
     19     
    1220    Plot(QWidget* parent = 0); 
    1321    virtual ~Plot(); 
     
    2937    void set_dirty(); 
    3038     
     39    void select_points(const QRectF& rect, SelectionBehavior behavior = AddSelection); 
     40    void select_points(const QPolygonF& area, SelectionBehavior behavior = AddSelection); 
     41    void mark_points(const QRectF& rect, SelectionBehavior behavior = AddSelection); 
     42    void mark_points(const QPolygonF& area, SelectionBehavior behavior = AddSelection); 
     43     
    3144protected: 
    3245    void set_clean();; 
  • source/orangeplot/plotitem.sip

    r8446 r8475  
    3232    void set_x_axis(int x_axis); 
    3333    void set_y_axis(int y_axis); 
     34 
    3435}; 
  • source/orangeplot/point.cpp

    r8444 r8475  
    3232    { 
    3333        painter->setPen(m_color); 
     34        const QPainterPath path = path_for_symbol(m_symbol, m_size); 
    3435        painter->drawPath(path_for_symbol(m_symbol, m_size)); 
    3536    }  
     
    9192    m_symbol = symbol; 
    9293} 
    93  
    94  
    95  
    96  
    97  
    98  
    99  
    100  
    10194 
    10295QPainterPath Point::path_for_symbol(int symbol, int size) 
     
    171164       
    172165    default: 
    173       qWarning() << "Unsupported symbol" << symbol; 
     166     // qWarning() << "Unsupported symbol" << symbol; 
     167        break; 
    174168  } 
    175169  return path; 
     
    232226    return QRectF(-size/2, -size/2, size, size); 
    233227} 
    234  
    235  
     228void Point::set_state(Point::State state) { 
     229    m_state = state; 
     230} 
     231Point::State Point::state() const { 
     232    return m_state; 
     233} 
     234void Point::set_state_flag(Point::StateFlag flag, bool on) { 
     235    if (on) 
     236    { 
     237        m_state |= flag; 
     238    } 
     239    else 
     240    { 
     241        m_size &= ~flag; 
     242    } 
     243} 
     244bool Point::state_flag(Point::StateFlag flag) const { 
     245    return m_state & flag; 
     246} 
     247 
     248 
     249void Point::set_selected(bool selected) 
     250{ 
     251    set_state_flag(Selected, selected); 
     252} 
     253 
     254bool Point::is_selected() const 
     255{ 
     256    return state_flag(Selected); 
     257} 
     258 
     259void Point::set_marked(bool marked) 
     260{ 
     261    set_state_flag(Marked, marked); 
     262} 
     263 
     264bool Point::is_marked() const 
     265{ 
     266    return state_flag(Marked); 
     267} 
     268 
     269 
     270 
  • source/orangeplot/point.h

    r8444 r8475  
    33 
    44#include <QtGui/QGraphicsItem> 
    5  
    65 
    76class Point : public QGraphicsItem 
     
    4039  }; 
    4140   
     41    enum StateFlag 
     42    { 
     43        Normal = 0x00, 
     44        Marked = 0x01, 
     45        Selected = 0x02 
     46    }; 
     47     
     48    enum  
     49    { 
     50        Type = UserType + 1 
     51    }; 
     52     
     53    virtual int type() const 
     54    { 
     55        return Type; 
     56    } 
     57     
     58    Q_DECLARE_FLAGS(State, StateFlag) 
     59   
    4260    Point(QGraphicsItem* parent = 0, QGraphicsScene* scene = 0); 
    4361    Point(int symbol, QColor color, int size, QGraphicsItem* parent = 0); 
     
    5977    DisplayMode display_mode() const; 
    6078     
     79    void set_state(State state); 
     80    State state() const; 
     81    void set_state_flag(StateFlag flag, bool on); 
     82    bool state_flag(StateFlag flag) const; 
     83     
     84    void set_selected(bool selected); 
     85    bool is_selected() const; 
     86 
     87    void set_marked(bool marked); 
     88    bool is_marked() const; 
     89 
     90 
     91     
    6192    /** 
    6293    * Creates a path from a symbol and a size 
     
    70101    static QImage image_for_symbol(int symbol, QColor color, int size); 
    71102    static QRectF rect_for_size(double size); 
    72      
     103         
    73104private: 
    74105    static QPainterPath trianglePath(double d, double rot); 
     
    80111    int m_size; 
    81112    DisplayMode m_display_mode; 
     113    State m_state; 
    82114}; 
    83115 
Note: See TracChangeset for help on using the changeset viewer.