Qwtplotitem (1)

Source: Internet
Author: User

The qwtplotitem class is the base class of all elements on the canvas. Qwtplotitem is an abstract base class. All instance elements must implement the yourplotitem: Draw () method (pure virtual function ). For details, refer to the qwt document:

Base class for items on the plot canvas.

A plot item is "something", that can be painted on the plot canvas, or only affects the scales of the plot widget. They can be categorized:

  • Representator
    A "representator" is an item that represents some sort of data on the plot canvas. The different representator classes are organized according to the characteristics of the data:

    • Qwtplotmarker represents a point or a horizontal/vertical coordinate
    • Qwtplotcurve represents a series of points
    • Qwtplotspectrogram (qwtplotrasteritem)
      Represents Raster Data
    • ...
  • Decorators
    A "decorator" is an item, that displays additional information, that is not related to any data:

    • Qwtplotgrid
    • Qwtplotscaleitem
    • Qwtplotsvgitem
    • ...

Depending on the qwtplotitem: itemattribute flags,
An item is wrongly ded into autoscaling or has an entry on the legnd.

Before misusing the existing item classes it might be better to implement a new type of plot item(Don't implement a watermark as Spectrogram
). Deriving a new type of qwtplotitemprimarily means to implement
The yourplotitem: Draw () method.

See also:
The cpuplot example shows the implementation of additional plot items.

Qwtplotitem inherits from the qwtlegenditemmanager class to bind qwtplotitem to qwtlegend. That is, the qwtlegenditemmanager class is mainly used as an interface.[Abstract API to bind plot items to the legend .]An example of the inheritance relationship is shown below:

Qwtlegenditemmanager class code analysis:

/*!  \brief Abstract API to bind plot items to the legend*/class QWT_EXPORT QwtLegendItemManager{public:    //! Constructor    QwtLegendItemManager()    {    }    //! Destructor    virtual ~QwtLegendItemManager()    {    }    /*!      Update the widget that represents the item on the legend      \param legend Legend      \sa legendItem()     */    virtual void updateLegend( QwtLegend *legend ) const = 0;    /*!      Allocate the widget that represents the item on the legend      \return Allocated widget      \sa updateLegend() QwtLegend()     */    virtual QWidget *legendItem() const = 0;    /*!      QwtLegendItem can display an icon-identifier followed      by a text. The icon helps to identify a plot item on      the plot canvas and depends on the type of information,      that is displayed.      The default implementation paints nothing.     */    virtual void drawLegendIdentifier( QPainter *, const QRectF & ) const    {    }};

Qwtplotitem code analysis:

Data:

class QwtPlotItem::PrivateData{public:    PrivateData():        plot( NULL ),        isVisible( true ),        attributes( 0 ),        renderHints( 0 ),        z( 0.0 ),        xAxis( QwtPlot::xBottom ),        yAxis( QwtPlot::yLeft )    {    }    mutable QwtPlot *plot;    bool isVisible;    QwtPlotItem::ItemAttributes attributes;    QwtPlotItem::RenderHints renderHints;    double z;    int xAxis;    int yAxis;    QwtText title;};

1. the mutable: mutable keyword can be used to modify the value of the member variable modified by mutable in a constant function. But from the code implementation point of view, have you ever seen the need for such a requirement?

2. qwtplotitem is still an abstract base class, so only a few required common attributes are defined.

3. This kind of commonality extraction needs to be considered and verified during the design of an inheritance system. It is also a constant concern for reconstruction during the coding process.

Implementation:

1. Return runtime type information:

Virtual int rtti () const; // runtime type information

2. Set the sequence of adding (drawing) elements:

/*! \ Brief set the Z value plot items are painted in increasing Z-order. \ Param z-value \ sa z (), qwtplotdict: itemlist () */void qwtplotitem: setz (Double Z) {If (d_data-> Z! = Z) {If (d_data-> plot) // update the Z order d_data-> plot-> attachitem (this, false); d_data-> Z = z; if (d_data-> plot) d_data-> plot-> attachitem (this, true); // rearrange the itemchanged ();}}

3. Several virtual functions that need to be re-implemented in the derived class:

Virtual void itemchanged (); // update legend and call the automatic update function of qwtplot /*! \ Brief draw the item \ Param painter \ Param xmap maps X-values into pixel coordinates. \ Param ymap maps y-values into pixel coordinates. \ Param canvasrect contents rect of the canvas in painter coordinates */virtual void draw (qpainter * painter, const Upper & xmap, const lower & ymap, const lower & canvasrect) const = 0; // The pure virtual function. If the item is drawn, virtual qrectf boundingrect () con is implemented in each derived class. St; // The peripheral border box of item. By default, an invalid rectangle is returned, and virtual void updatelegend (qwtlegend * legend) const is re-implemented in each derived class; // update the qwtlegenditem (created if it does not exist) and draw the corresponding icon (drawlegendidentifier () virtual void updatescalediv (const qwtscalediv &, const qwtscalediv &); // The default implementation of this interface is: do nothing. Only some specific Derived classes need to be re-implemented (like qwtplotgrid () virtual qwidget * legenditem () const; // allocate the widget that represents the item on the legend

4. Disable copy and assign values:

private:    // Disabled copy constructor and operator=    QwtPlotItem( const QwtPlotItem & );    QwtPlotItem &operator=( const QwtPlotItem & );

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.