Drawing scientific charts based on QT -- qwt trial

Source: Internet
Author: User
Tags ranges
Drawing scientific charts based on QT -- qwt trial

 

Qwt is an open-source project based on the lgpl copyright Protocol. Its goal is to provide a set of 2D form libraries to display data in the technical field. The data source is provided in floating point groups or ranges, the output can be curves, Slider, dials, and compasses. The tool library is developed based on QT, so it also inherits the cross-platform features of QT, according to the original document, the project in the QT-Win/Qt-x11/Qt-embedded (qvfb environment) have been tested and run normally. The home page of the project is:Http://qwt.sourceforge.net/

I searched the internet and found that there are very few Chinese documents about qwt. Basically, there are only articles about compilation and installation. In fact, through the practice of the author, the compilation and running of qwt is really not good, qmake; make can be done, there is nothing to do with Memo, so this article will focus on literacy and introduce the feature of qwt.

Of course, in the normal order, we will start from compilation and installation. Download the latest code from the svn server: SVN Co https://qwt.svn.sourceforge.net/svnroot/qwt/trunk/qwt
Go to the qwt directory, run qmake corresponding to qt4 on your computer, and then run make compilation. For example, in my environment
$ CD qwt
$ Export Path =/usr/local/trolltech/Qt-4.5.1/bin/: $ path
$ Qmake
$ Make

Compilation takes several minutes. After successful execution, the libqwt. So * file is generated in lib and examples is also used for compilation. The generated binary file is in examples/bin. We can run these examples to check the qwt function.

$ Export LD_LIBRARY_PATH = $ PWD/lib
$ CD examples/bin
$./Simple

Simple is the simplest example of qwt. It only contains one hundred lines of code and implements the sine function (sin () and cosine function (COS () curves in mathematics. For example:

There are four core classes used in this example (the following content is the author's understanding, and there may be something wrong, please read as appropriate ):
Qwtplot
Similar to a 2D drawing container, other qwtplotitem derived class objects can be placed, such as qwtplotmarker used in this example. (Similar to graphicsview in QT .) This class controls the generation and transmission of drawing data and draws an axis.
Qwtplotmarker
Scale class, used to draw a dial line.
Qwtplotcurve
Curve class, used to draw various curves.
Qwtsyntheticpointdata
It is strange that this is an unreceivented class. It is estimated that this class is accidentally omitted by the author. The description of this class is not provided in the document, and the answer can only be found from the source code. This is depressing. By looking at the comments in the Code and the example code, the author understands that this class is responsible for generating data. Its function is to provide a fixed number of floating point points, and the number of points is passed in when constructing the class. When obtaining data, the qwtplotcurve class calls the Y () method of the class to obtain the ordinate.

The basic process of the program is:
1. initialize the drawing container and set the axis Parameters
// Set Axes
Setaxistitle (xbottom, "X-> ");
Setaxisscale (xbottom, 0.0, 10.0); // the x-axis ranges from 0 to 10. The X-axis indicates that the X-axis ranges from bottom to top.

Setaxistitle (yleft, "Y-> ");
Setaxisscale (yleft,-1.0, 1.0); // y coordinate-1 to 1, yleft indicates the direction of Y coordinate from left to right

2. Add a sine cosine curve
// Insert new curves
Qwtplotcurve * Csin = new qwtplotcurve ("Y = sin (x )");
# If qt_version> = 0 ×040000
Csin-> setrenderhint (qwtplotitem: renderantialiased );
# Endif
Csin-> setpen (qpen (QT: Red); // red curve
Csin-> attach (this );

Qwtplotcurve * ccos = new qwtplotcurve ("y = cos (x )");
# If qt_version> = 0 ×040000
Ccos-> setrenderhint (qwtplotitem: renderantialiased );
# Endif
Ccos-> setpen (qpen (QT: Blue); // blue curve
Ccos-> attach (this );

3. Set the data content of the curve
// Create sin and cos data
Csin-> setdata (functiondata (: sin ));
Ccos-> setdata (functiondata (: COS ));

4. Add the horizontal and vertical ruler lines as the reference coordinates.
// Insert markers
//... A horizontal line at y = 0...
Qwtplotmarker * My = new qwtplotmarker ();
My-> setlabel (qstring: fromlatin1 ("Y = 0 ″));
My-> setlabelalignment (QT: alignright | QT: aligntop );
My-> setlinestyle (qwtplotmarker: hline); // line direction
My-> setyvalue (0.0); // The ruler line is drawn at the position Y = 0.
My-> attach (this );

//... A vertical line at x = 2 * pi
Qwtplotmarker * MX = new qwtplotmarker ();
Mx-> setlabel (qstring: fromlatin1 ("x = 2 pi "));
Mx-> setlabelalignment (QT: alignleft | QT: alignbottom );
Mx-> setlabelorientation (QT: vertical );
Mx-> setlinestyle (qwtplotmarker: vline );
Mx-> setlinepen (qpen (QT: Black, 0, QT: dashdotline ));
Mx-> setxvalue (2.0 * m_pi); // draw the line at the position X = 2PI.
Mx-> attach (this );

If you use QT to write the same function, you need to write a large amount of drawing code, which is troublesome. However, the qwt encapsulated library code is more Oo and easier to understand and maintain. In this example, the advantages of using qwt may not be obvious, and more complex charts can reflect the superiority of qwt. Here are several examples:

How about these examples? In general, this database is more practical and worth a try. If you are interested, you may wish to download and play it yourself.

Link to the original article: Drawing scientific charts based on QT-qwt trial

3 Responses to "Drawing scientific charts based on QT -- qwt trial"

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.