check qwt-5.2, r588 into repository

This commit is contained in:
Sean Rhea
2009-09-20 10:09:15 -07:00
parent e906b76fa5
commit 13bd8a1f52
279 changed files with 57199 additions and 0 deletions

409
qwt/CHANGES Normal file
View File

@@ -0,0 +1,409 @@
Release 5.2.1
===================
Bug Fixes
---------
1) QwtScaleDraw
Wrong border dist hints for unregular scale divisions fixed
Release 5.2.0
===================
Changes
-------
1) Ported to Qt 4.5.x
2) Scaling of non cosmetic pens (for printing to devices in high resolution)
3) Clipping of polygons for SVG rendering
4) QwtRect removed
use QwtClipper instead
5) QwtPlotRescaler
Introduced
6) QwtDoubleInterval
BorderMode introduced
7) QwtPlotCurve
Performance of incremental curve painting ( = draw(from, to) ) improved.
8) QwtLegendItem
setIdentfierMode renamed to setIdentifierMode
9) QwtPlotCanvas::replot() introduced
code from QwtPlot::replot shifted
10)QwtPlot
drawCanvas(), updateAxes() changed from protected to public
11)QwtScaleEngine
loMargin/hiMargin renamed to lowerMargin/upperMargin
12)QwtScaleDiv
lBound/hBound renamed to lowerBound/upperBound
13)QwtSpline
cofficientA/B/C introduced
14)QwtDial
counter clockwise scales introduced
15)QwtPlotMarker
Vertical text labels
16)doc/qwt-5.2.0.qch added foe browsing the Qwt docs in the Qt assistant
Bug Fixes
---------
1) QwtLinearScaleEngine
Rounding problems fixed
2) Again some print layout problems fixed
3) QwtPlotScaleItem: 1 pixel offset fixed
4) QwtPlotSpectrogram, clipping of contour lines
against the bounding rect
5) QwtPlotZoomer::setZoomStack for stacks with unlimited depth
6) Printing of rotated tick labels
Release 5.1.1
===================
Bug Fixes
---------
1) Several compiler incompatibilities fixed
2) DBL_EPSILON removed
Using DBL_EPSILON in the calculations of the dials/sliders and the
scale engines leads to problems with the inaccuracy of floating points.
The behaviour has been reverted to 5.0.x.
3) QwtSlider/QwtKnob
setScaleDraw() fixed.
4) QwtRect
Pointless private declaration removed
Release 5.1.0
===================
Changes
-------
1) QwtSymbol::copy introduced
Now it is possible to use derived symbol classes for curves
2) QwtPlotScaleItem introduced
A new type of plot item for displaying axes on the canvas
3) QwtClipper added
A collection of clipping algos
4) Using DBL_EPSILON
This change allows smaller intervals for sliders/dials
5) QwtPanner
setOrientation() added.
6) QwtPlot
axisStepSize() added
clear is virtual now
7) QwtPlotPrintFilter
PrintCanvasBackground splitted into PrintBackground, PrintFrameWithScales
8) QwtPlotZoomer
setZoomStack() added
9) Changes for the QwtPolar package
QwtLegendItemManager introduced
QwtMagnifier introduced
10)Suffix rules added in qwtconfig.pri for different targets for
debug/release builds.
Bug Fixes
---------
1. QwtAbstractScaleDraw::setAbstractScaleDraw
Reinitialization problem fixed
2. QwtLegendItem
key event handlers fixed
3. QwtPicker
solaris-cc compiler problem fixed
4. Inaccurate mapping of scale to widget coordinates fixed
5. QwtPlotCurve::draw
Updates for Qt 4.3 added
6. QwtPlotLayout
AlignToCanvas layout calculation fixed
7. QwtPlot::print
Workaround for a QPen initialization problem,
when printing to Pdf, added
8. QwtText
Layout of rich text documents fixed
9. Designer
Handling of QwtScaleWidget fixed
10. realtime example
Qt::WA_PaintOutsidePaintEvent added, ScrollZoomer fixed
11. Several others I have forgotten
Release 5.0.2
===================
Bug Fixes
---------
1. QwtPlotCurve::Xfy curve type fixed
2. Memory leak in QwtLegend fixed
3. Vertical alignment of rich texts fixed
4. Workaround for a Qt4 bug added, that produces horrible performance
when painting curves with a pen width > 1.
5. Background for the tracker text of QwtPickers fixed.
Improved (faster + better rendered texts) implementation of
painting tracker texts, using capabilities of Qt >= 4.3.
6. QwtArrowButton/QwtCounter: workaround for layout bug ( Qt < 4.3 )
of the Cleanlook style added.
7. A couple of minor fixes
Changes
-------
1. QSvgGenerator added to the bode example
Release 5.0.1
===================
Changes
-------
1. A couple of problems, when building Qwt fixed.
2. Displaying Rich Text with Qt 4.x fixed
Release 5.0.0
===================
Platforms
---------
Support of Qt3 and Qt4. Qt2 is not supported any longer.
Key features
------------
1. Redesign of plot items. Makes it much easier to develop
individual items.
2. Redesign of the scale classes. All calculations are
collected in scale engines, where the application can
implement it´s own (f.e log2, or date scales). Now it´s
also possible to have individual and completely irregular scales
3. Redesign of the QwtText classes. The MathML renderer of
the Qt4 solutions package is embedded.
work for all expressions/situations.
4. New classes for navigating: QwtPanner, QwtMaginfier
5. Spectrogram/Contour plots and other classes for displaying
raster data added.
Changes
-------
5.0.0 is by far the release with the most changes in the history of Qwt
- too many to make list.
Release 4.2.0/0.4.2
===================
License
--------
A couple of exceptions to the LGPL with the intention to allow static
linking with commercial applications. See COPYING.
Key features:
-------------
1. Designer plugin
2. Rich Text support ( f.e. E = m * c<sup>2</sup> ) added.
3. QwtDial class family added (QwtDial, QwtCompass, QwtAnalogClock, ...)
4. QwtPicker class family added. Includes QwtPlotZoomer, a complete
implementation of recursive zooming.
5. Device metrics independent printing of QwtPlot. (QPrinter::HighResolution)
6. QwtPlot::setCurveBrush(), QwtCurve::setBrush() added. The area
between curve and baseline will be filled with this brush.
7. Rotation of axis tick labels added. Very useful for axis with long
labels like time scales ...
8. Added a new abstract QwtData class to plot data from almost any type of
container class.
9. QwtDoublePoint, QwtDoubleSize, QwtDoubleRect double counterparts
for QPoint, QSize, QRect.
10. First steps to support Qtopia. All examples can be compiled and started
in the qvfb emulator.
Changes:
---------
1. Rewrite of QwtLegend/QwtLegendItem (no QTable anymore)
2. Each plot item will be painted, even if one of the axis it is
attached to is disabled. (like in all other releases beside 0.4.1)
3. Code for double buffering moved to a new class QwtPaintBuffer.
Double buffering can be enabled/disabled now.
4. QwtPainter, QwtMetricsMap, QwtLayoutMetrics added
Hide paint device metrics dependencies.
5. Layout code rewritten and moved to a new class QwtPlotLayout
New layout options canvasMargin(), alignCanvasToScales()
6. QwtPlot: sizeHint() != minimumSizeHint()
9. Internal plot data are private again. A couple of get methods
added instead.
10. canvas repaints triggered by paint events. Enables event filtering
11. QwtPlot::drawCanvasItems added. In opposite to QwtPlot::drawCanvas
it is used by the printing code too.
12. qwtMax, qwtMin, qwtInt mapped to QMAX, QMIN, qRound from qglobal.h
13. operator= for plot item classes changed.
14. readOnly property added for sliders.
15. valid flag added for QwtDblRange
16. QwtCounter wrap around policy: a counter under- or overflow sets
focus to the smallest up/down button and disables counting.
A space bar keypress release event re-enables counting.
17. QwtPushButton added. A class that adds rich text and alignments
features to QPushButton, like they are used in QLabel
18. Clipped painting code moved from QwtCurve to QwtPainter/QwtRect
19. Canvas cache added to optimize trivial repaints.
20. QwtPlot::drawCurve added for incremental curve data
21. QwtSliderBase, readOnly, isValid added
22. Added filtering of the colors of the title and scales to QwtPrintFilter.
23. Support of QT_NO_CAST_ASII and QT_NO_COMPAT added
24. Batch file added for generating Visual Studio project files
25. QwtPlotCurve, QwtPlotMarker, QwtPlotGrid: more methods public
26. QwtPlot::setLegendPosition added
27. A lot of changes I don't remember, ... sorry.
Bugfixes:
---------
1. Autodetection of painter redirection. QPixmap::grabWidget() works
with Qwt Widgets again.
2. QwtSlider: Rounding double->int conversions instead of simple casts.
3. Bad additional line, connected to the first curve point, when zooming
deep, fixed.
4. QwtMarker: Painting of symbols with width != height fixed
5. QwtPlot::plotMouseXXX/canvasMap pixel coordinates synced.
Now both include the canvas frame.
6. Layout fixed for QwtScaleDraws without tick labels
8. Tab focus chains fixed, focus indications added.
9. Support QwtAutoScale::Inverted when autoScale is off also.
10. Keyboard control, focus indications added.
11. Improved QStyle awareness.
12. Printing of plots with disabled axes
Examples
--------
1. New example linux/cpustat added. Runs also on non linux boxes
with dummy values. Beside showing a couple of features that
are new with 0.4.1 and 0.4.2, it shows how to extend and customize
a QwtPlots.
2. Added new example event_filter to demonstrate event filtering.
This example shows how to add additional controls to the scales,
how to translate mouse clicks on the scales into signals and
how to move points on the canvas.
3. realtime example shows how to use scrollbars when zooming
Release 0.4.1
============
Changes:
---------
1. Platform independent project files. makefiles directory removed.
2. RPM spec file template added.
3. __declspec formalism added for Win32 DLLs. Requires
'DEFINES += QWT_DLL' in the .pro file.
4. QString used for visible texts.
5. Code for error curves removed. These type of features should be
implemented in derived curve classes.
6. A lot of Qt 1.2 related code removed/replaced.
7. QwtColorFilter, QwtPixFrame removed. QwtPlotPixFrame renamed
to QwtPlotCanvas.
8. qmodules.h aware. Skips QwtLegend in case of !QT_MODULE_TABLE
9. All Widgets including QwtPlot optimized to reduce flicker
during resize/repaint.
10. QwtPlot curves/markers can be disabled/enabled to hide/show individual
curves without removing the curves from the plot.
11. Internal maps removed from QwtCurve. QwtCurve::setMap, QwtCurve::setRect,
QwtCurve::setRange removed.
Feature additions:
------------------
1. Printing
QwtPlot::print prints to any type of QPaintDevice now.
Hardcoded printer attributes margin, creator and document title have
been removed and must/can be set by the applications now.
Printing of background and legends added. QwtColorFilter replaced
by QwtPlotPrintFilter.
2. Layout
Many layout fixes and additions. Now all Widgets behave well in
QLayouts and provide sensible sizeHints. QwtPlot::setMargin(int) added.
Fieldwidth added for QwtPlot::setAxisFormat for application that need
range independent width. Title and axis title are Qt:Alignment aware.
Qt::WordBreak or multiline titles are possible.
3. Legend
En/Disabling of single curves in the legend added.
QwtPlot::setAutoLegend added.
4. Extensibility
QwtPlot::insertCurve + QwtPlot::insertMarker added. Now derived
classes of QwtPlotCurve and QwtPlotMarker can be added. Virtual
methods provided by QwtPlotCurve for sub-classing.
QwtScale::setScaleDraw + QwtPlot::setAxisScaleDraw + some virtual
methods for QwtScaleDraw added. Application can implement individual
axis labels now.
5. Sliders
QWheelEvent added. The MouseWheel stepsize is controlled by the
Scroll Page Size. QwtWheel::setWheelWidth added. QwtKnob::setSymbol,
QwtKnob::symbol added.
Bugfixes:
---------
1. Workaround for spontanous curves resulting from overruns
when zooming too deep.
2. Wrong QColorGroup::ColorRole for background colors fixed.
Necessary for several non default QStyles.
3. QwtWheel fixed for vertical wheels. Better color support.
4. QwtSlider fixed.
5. Many forgotten others
Release 0.4.0
============
Bugfixes:
---------
1. A few occurences of the boolean literal \c false were changed into macro
\c FALSE for cross compiler compatibility.
2. A few local variables in member functions were renamed to suppress
warnings issued by really picky compilers about global/class variables
being hidden.
3. In qwt_legend.h, a fully qualified name was used in a class declaration.
The HPUX compiler chokes on this (and it's ugly), so it was fixed.
4. Macro M_2PI is now only defined is this hasn't already been done by the
system's clib.
Feature additions:
------------------
1. Qwt now works with Qt3.0. In order to achieve this, QwtLegend now no
longer derives from QTableView, but from QTable. This seems to have had
quite a few consequences. Kudo's to Uwe Rathmann for uploading this nice
fix to the CVS tree.
2. Getters for a plot's title and title font have been added.
Release 0.3.0
============
License:
--------
1. The license has changed from GPL to LGPL.
Bugfixes:
---------
1. The makefiles for win32 caused object files to have extension .o instead of
.obj. The 'propagate' file was changed to fix this, using tmake's target
platform flag.
2. There were problems with rint() on win32 platforms. rint() is a BSD call,
not even available on all unices. All calls to rint(x) have been replaced
by floor(x+.5).
3. Some static class data members were initialized with the value of other
static class data members (from Qt). This caused programs depend on the
initialization order of class members. This is now fixed by replacing the
static properties by static signleton factories.
4. When a plot was zoomed and then printed, curves and markers laying outside
the plot's scale were still printed. The print() function now uses clipping.
Feature additions:
------------------
1. Multi-line plot titles are now supported: the PostScript document name is
not the plot title, with "\n" characters replaced by "--". Geometry
management has been changed to support multi-line titles.
2. In the mailinglist, there were often feature requests for features that
were in fact implemented, but not available through QwtPlot's API. Many
private members have been made protected or even public, to give users
more control. This is poor design, but Qwt will be refactored anyway.
3. Qwt always displayed floats with 5 digits. This was insufficient for many
applications. QwtPlot, QwtScale, QwtAutoScale got some methods to set the
label format. This is a printf like format for the numbers at the scales,
consisting of 'f' and a precision, or 'g' and the significance.
Build system:
-------------
1. The 'makefiles' directory was removed from the cvs tree, and is now only
generated for releases. CVS users should have tmake installed, to generate
the makefiles themselves.
2. The 'examples' directory now uses tmake's 'subdirs' template, to iterate
over all subdirectories and build all examples with one command. There was
allready a makefile for this, but now the process is automated by tmake.
3. Under unix, the library now gets a proper version number. Current version
is 0.3.0.
Documentation:
--------------
1. All documentation is converted to the Doxygen documentation system. The
release contains two settings files, 'Doxygen' and 'Doxygen.users',
generating a developer's and user's manual, respectively.

543
qwt/COPYING Normal file
View File

@@ -0,0 +1,543 @@
Qwt License
Version 1.0, January 1, 2003
The Qwt library and included programs are provided under the terms
of the GNU LESSER GENERAL PUBLIC LICENSE (LGPL) with the following
exceptions:
1. Widgets that are subclassed from Qwt widgets do not
constitute a derivative work.
2. Static linking of applications and widgets to the
Qwt library does not constitute a derivative work
and does not require the author to provide source
code for the application or widget, use the shared
Qwt libraries, or link their applications or
widgets against a user-supplied version of Qwt.
If you link the application or widget to a modified
version of Qwt, then the changes to Qwt must be
provided under the terms of the LGPL in sections
1, 2, and 4.
3. You do not have to provide a copy of the Qwt license
with programs that are linked to the Qwt library, nor
do you have to identify the Qwt license in your
program or documentation as required by section 6
of the LGPL.
However, programs must still identify their use of Qwt.
The following example statement can be included in user
documentation to satisfy this requirement:
[program/widget] is based in part on the work of
the Qwt project (http://qwt.sf.net).
----------------------------------------------------------------------
GNU LESSER GENERAL PUBLIC LICENSE
Version 2.1, February 1999
Copyright (C) 1991, 1999 Free Software Foundation, Inc.
59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
[This is the first released version of the Lesser GPL. It also counts
as the successor of the GNU Library Public License, version 2, hence
the version number 2.1.]
Preamble
The licenses for most software are designed to take away your
freedom to share and change it. By contrast, the GNU General Public
Licenses are intended to guarantee your freedom to share and change
free software--to make sure the software is free for all its users.
This license, the Lesser General Public License, applies to some
specially designated software packages--typically libraries--of the
Free Software Foundation and other authors who decide to use it. You
can use it too, but we suggest you first think carefully about whether
this license or the ordinary General Public License is the better
strategy to use in any particular case, based on the explanations below.
When we speak of free software, we are referring to freedom of use,
not price. Our General Public Licenses are designed to make sure that
you have the freedom to distribute copies of free software (and charge
for this service if you wish); that you receive source code or can get
it if you want it; that you can change the software and use pieces of
it in new free programs; and that you are informed that you can do
these things.
To protect your rights, we need to make restrictions that forbid
distributors to deny you these rights or to ask you to surrender these
rights. These restrictions translate to certain responsibilities for
you if you distribute copies of the library or if you modify it.
For example, if you distribute copies of the library, whether gratis
or for a fee, you must give the recipients all the rights that we gave
you. You must make sure that they, too, receive or can get the source
code. If you link other code with the library, you must provide
complete object files to the recipients, so that they can relink them
with the library after making changes to the library and recompiling
it. And you must show them these terms so they know their rights.
We protect your rights with a two-step method: (1) we copyright the
library, and (2) we offer you this license, which gives you legal
permission to copy, distribute and/or modify the library.
To protect each distributor, we want to make it very clear that
there is no warranty for the free library. Also, if the library is
modified by someone else and passed on, the recipients should know
that what they have is not the original version, so that the original
author's reputation will not be affected by problems that might be
introduced by others.
Finally, software patents pose a constant threat to the existence of
any free program. We wish to make sure that a company cannot
effectively restrict the users of a free program by obtaining a
restrictive license from a patent holder. Therefore, we insist that
any patent license obtained for a version of the library must be
consistent with the full freedom of use specified in this license.
Most GNU software, including some libraries, is covered by the
ordinary GNU General Public License. This license, the GNU Lesser
General Public License, applies to certain designated libraries, and
is quite different from the ordinary General Public License. We use
this license for certain libraries in order to permit linking those
libraries into non-free programs.
When a program is linked with a library, whether statically or using
a shared library, the combination of the two is legally speaking a
combined work, a derivative of the original library. The ordinary
General Public License therefore permits such linking only if the
entire combination fits its criteria of freedom. The Lesser General
Public License permits more lax criteria for linking other code with
the library.
We call this license the "Lesser" General Public License because it
does Less to protect the user's freedom than the ordinary General
Public License. It also provides other free software developers Less
of an advantage over competing non-free programs. These disadvantages
are the reason we use the ordinary General Public License for many
libraries. However, the Lesser license provides advantages in certain
special circumstances.
For example, on rare occasions, there may be a special need to
encourage the widest possible use of a certain library, so that it becomes
a de-facto standard. To achieve this, non-free programs must be
allowed to use the library. A more frequent case is that a free
library does the same job as widely used non-free libraries. In this
case, there is little to gain by limiting the free library to free
software only, so we use the Lesser General Public License.
In other cases, permission to use a particular library in non-free
programs enables a greater number of people to use a large body of
free software. For example, permission to use the GNU C Library in
non-free programs enables many more people to use the whole GNU
operating system, as well as its variant, the GNU/Linux operating
system.
Although the Lesser General Public License is Less protective of the
users' freedom, it does ensure that the user of a program that is
linked with the Library has the freedom and the wherewithal to run
that program using a modified version of the Library.
The precise terms and conditions for copying, distribution and
modification follow. Pay close attention to the difference between a
"work based on the library" and a "work that uses the library". The
former contains code derived from the library, whereas the latter must
be combined with the library in order to run.
GNU LESSER GENERAL PUBLIC LICENSE
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
0. This License Agreement applies to any software library or other
program which contains a notice placed by the copyright holder or
other authorized party saying it may be distributed under the terms of
this Lesser General Public License (also called "this License").
Each licensee is addressed as "you".
A "library" means a collection of software functions and/or data
prepared so as to be conveniently linked with application programs
(which use some of those functions and data) to form executables.
The "Library", below, refers to any such software library or work
which has been distributed under these terms. A "work based on the
Library" means either the Library or any derivative work under
copyright law: that is to say, a work containing the Library or a
portion of it, either verbatim or with modifications and/or translated
straightforwardly into another language. (Hereinafter, translation is
included without limitation in the term "modification".)
"Source code" for a work means the preferred form of the work for
making modifications to it. For a library, complete source code means
all the source code for all modules it contains, plus any associated
interface definition files, plus the scripts used to control compilation
and installation of the library.
Activities other than copying, distribution and modification are not
covered by this License; they are outside its scope. The act of
running a program using the Library is not restricted, and output from
such a program is covered only if its contents constitute a work based
on the Library (independent of the use of the Library in a tool for
writing it). Whether that is true depends on what the Library does
and what the program that uses the Library does.
1. You may copy and distribute verbatim copies of the Library's
complete source code as you receive it, in any medium, provided that
you conspicuously and appropriately publish on each copy an
appropriate copyright notice and disclaimer of warranty; keep intact
all the notices that refer to this License and to the absence of any
warranty; and distribute a copy of this License along with the
Library.
You may charge a fee for the physical act of transferring a copy,
and you may at your option offer warranty protection in exchange for a
fee.
2. You may modify your copy or copies of the Library or any portion
of it, thus forming a work based on the Library, and copy and
distribute such modifications or work under the terms of Section 1
above, provided that you also meet all of these conditions:
a) The modified work must itself be a software library.
b) You must cause the files modified to carry prominent notices
stating that you changed the files and the date of any change.
c) You must cause the whole of the work to be licensed at no
charge to all third parties under the terms of this License.
d) If a facility in the modified Library refers to a function or a
table of data to be supplied by an application program that uses
the facility, other than as an argument passed when the facility
is invoked, then you must make a good faith effort to ensure that,
in the event an application does not supply such function or
table, the facility still operates, and performs whatever part of
its purpose remains meaningful.
(For example, a function in a library to compute square roots has
a purpose that is entirely well-defined independent of the
application. Therefore, Subsection 2d requires that any
application-supplied function or table used by this function must
be optional: if the application does not supply it, the square
root function must still compute square roots.)
These requirements apply to the modified work as a whole. If
identifiable sections of that work are not derived from the Library,
and can be reasonably considered independent and separate works in
themselves, then this License, and its terms, do not apply to those
sections when you distribute them as separate works. But when you
distribute the same sections as part of a whole which is a work based
on the Library, the distribution of the whole must be on the terms of
this License, whose permissions for other licensees extend to the
entire whole, and thus to each and every part regardless of who wrote
it.
Thus, it is not the intent of this section to claim rights or contest
your rights to work written entirely by you; rather, the intent is to
exercise the right to control the distribution of derivative or
collective works based on the Library.
In addition, mere aggregation of another work not based on the Library
with the Library (or with a work based on the Library) on a volume of
a storage or distribution medium does not bring the other work under
the scope of this License.
3. You may opt to apply the terms of the ordinary GNU General Public
License instead of this License to a given copy of the Library. To do
this, you must alter all the notices that refer to this License, so
that they refer to the ordinary GNU General Public License, version 2,
instead of to this License. (If a newer version than version 2 of the
ordinary GNU General Public License has appeared, then you can specify
that version instead if you wish.) Do not make any other change in
these notices.
Once this change is made in a given copy, it is irreversible for
that copy, so the ordinary GNU General Public License applies to all
subsequent copies and derivative works made from that copy.
This option is useful when you wish to copy part of the code of
the Library into a program that is not a library.
4. You may copy and distribute the Library (or a portion or
derivative of it, under Section 2) in object code or executable form
under the terms of Sections 1 and 2 above provided that you accompany
it with the complete corresponding machine-readable source code, which
must be distributed under the terms of Sections 1 and 2 above on a
medium customarily used for software interchange.
If distribution of object code is made by offering access to copy
from a designated place, then offering equivalent access to copy the
source code from the same place satisfies the requirement to
distribute the source code, even though third parties are not
compelled to copy the source along with the object code.
5. A program that contains no derivative of any portion of the
Library, but is designed to work with the Library by being compiled or
linked with it, is called a "work that uses the Library". Such a
work, in isolation, is not a derivative work of the Library, and
therefore falls outside the scope of this License.
However, linking a "work that uses the Library" with the Library
creates an executable that is a derivative of the Library (because it
contains portions of the Library), rather than a "work that uses the
library". The executable is therefore covered by this License.
Section 6 states terms for distribution of such executables.
When a "work that uses the Library" uses material from a header file
that is part of the Library, the object code for the work may be a
derivative work of the Library even though the source code is not.
Whether this is true is especially significant if the work can be
linked without the Library, or if the work is itself a library. The
threshold for this to be true is not precisely defined by law.
If such an object file uses only numerical parameters, data
structure layouts and accessors, and small macros and small inline
functions (ten lines or less in length), then the use of the object
file is unrestricted, regardless of whether it is legally a derivative
work. (Executables containing this object code plus portions of the
Library will still fall under Section 6.)
Otherwise, if the work is a derivative of the Library, you may
distribute the object code for the work under the terms of Section 6.
Any executables containing that work also fall under Section 6,
whether or not they are linked directly with the Library itself.
6. As an exception to the Sections above, you may also combine or
link a "work that uses the Library" with the Library to produce a
work containing portions of the Library, and distribute that work
under terms of your choice, provided that the terms permit
modification of the work for the customer's own use and reverse
engineering for debugging such modifications.
You must give prominent notice with each copy of the work that the
Library is used in it and that the Library and its use are covered by
this License. You must supply a copy of this License. If the work
during execution displays copyright notices, you must include the
copyright notice for the Library among them, as well as a reference
directing the user to the copy of this License. Also, you must do one
of these things:
a) Accompany the work with the complete corresponding
machine-readable source code for the Library including whatever
changes were used in the work (which must be distributed under
Sections 1 and 2 above); and, if the work is an executable linked
with the Library, with the complete machine-readable "work that
uses the Library", as object code and/or source code, so that the
user can modify the Library and then relink to produce a modified
executable containing the modified Library. (It is understood
that the user who changes the contents of definitions files in the
Library will not necessarily be able to recompile the application
to use the modified definitions.)
b) Use a suitable shared library mechanism for linking with the
Library. A suitable mechanism is one that (1) uses at run time a
copy of the library already present on the user's computer system,
rather than copying library functions into the executable, and (2)
will operate properly with a modified version of the library, if
the user installs one, as long as the modified version is
interface-compatible with the version that the work was made with.
c) Accompany the work with a written offer, valid for at
least three years, to give the same user the materials
specified in Subsection 6a, above, for a charge no more
than the cost of performing this distribution.
d) If distribution of the work is made by offering access to copy
from a designated place, offer equivalent access to copy the above
specified materials from the same place.
e) Verify that the user has already received a copy of these
materials or that you have already sent this user a copy.
For an executable, the required form of the "work that uses the
Library" must include any data and utility programs needed for
reproducing the executable from it. However, as a special exception,
the materials to be distributed need not include anything that is
normally distributed (in either source or binary form) with the major
components (compiler, kernel, and so on) of the operating system on
which the executable runs, unless that component itself accompanies
the executable.
It may happen that this requirement contradicts the license
restrictions of other proprietary libraries that do not normally
accompany the operating system. Such a contradiction means you cannot
use both them and the Library together in an executable that you
distribute.
7. You may place library facilities that are a work based on the
Library side-by-side in a single library together with other library
facilities not covered by this License, and distribute such a combined
library, provided that the separate distribution of the work based on
the Library and of the other library facilities is otherwise
permitted, and provided that you do these two things:
a) Accompany the combined library with a copy of the same work
based on the Library, uncombined with any other library
facilities. This must be distributed under the terms of the
Sections above.
b) Give prominent notice with the combined library of the fact
that part of it is a work based on the Library, and explaining
where to find the accompanying uncombined form of the same work.
8. You may not copy, modify, sublicense, link with, or distribute
the Library except as expressly provided under this License. Any
attempt otherwise to copy, modify, sublicense, link with, or
distribute the Library is void, and will automatically terminate your
rights under this License. However, parties who have received copies,
or rights, from you under this License will not have their licenses
terminated so long as such parties remain in full compliance.
9. You are not required to accept this License, since you have not
signed it. However, nothing else grants you permission to modify or
distribute the Library or its derivative works. These actions are
prohibited by law if you do not accept this License. Therefore, by
modifying or distributing the Library (or any work based on the
Library), you indicate your acceptance of this License to do so, and
all its terms and conditions for copying, distributing or modifying
the Library or works based on it.
10. Each time you redistribute the Library (or any work based on the
Library), the recipient automatically receives a license from the
original licensor to copy, distribute, link with or modify the Library
subject to these terms and conditions. You may not impose any further
restrictions on the recipients' exercise of the rights granted herein.
You are not responsible for enforcing compliance by third parties with
this License.
11. If, as a consequence of a court judgment or allegation of patent
infringement or for any other reason (not limited to patent issues),
conditions are imposed on you (whether by court order, agreement or
otherwise) that contradict the conditions of this License, they do not
excuse you from the conditions of this License. If you cannot
distribute so as to satisfy simultaneously your obligations under this
License and any other pertinent obligations, then as a consequence you
may not distribute the Library at all. For example, if a patent
license would not permit royalty-free redistribution of the Library by
all those who receive copies directly or indirectly through you, then
the only way you could satisfy both it and this License would be to
refrain entirely from distribution of the Library.
If any portion of this section is held invalid or unenforceable under any
particular circumstance, the balance of the section is intended to apply,
and the section as a whole is intended to apply in other circumstances.
It is not the purpose of this section to induce you to infringe any
patents or other property right claims or to contest validity of any
such claims; this section has the sole purpose of protecting the
integrity of the free software distribution system which is
implemented by public license practices. Many people have made
generous contributions to the wide range of software distributed
through that system in reliance on consistent application of that
system; it is up to the author/donor to decide if he or she is willing
to distribute software through any other system and a licensee cannot
impose that choice.
This section is intended to make thoroughly clear what is believed to
be a consequence of the rest of this License.
12. If the distribution and/or use of the Library is restricted in
certain countries either by patents or by copyrighted interfaces, the
original copyright holder who places the Library under this License may add
an explicit geographical distribution limitation excluding those countries,
so that distribution is permitted only in or among countries not thus
excluded. In such case, this License incorporates the limitation as if
written in the body of this License.
13. The Free Software Foundation may publish revised and/or new
versions of the Lesser General Public License from time to time.
Such new versions will be similar in spirit to the present version,
but may differ in detail to address new problems or concerns.
Each version is given a distinguishing version number. If the Library
specifies a version number of this License which applies to it and
"any later version", you have the option of following the terms and
conditions either of that version or of any later version published by
the Free Software Foundation. If the Library does not specify a
license version number, you may choose any version ever published by
the Free Software Foundation.
14. If you wish to incorporate parts of the Library into other free
programs whose distribution conditions are incompatible with these,
write to the author to ask for permission. For software which is
copyrighted by the Free Software Foundation, write to the Free
Software Foundation; we sometimes make exceptions for this. Our
decision will be guided by the two goals of preserving the free status
of all derivatives of our free software and of promoting the sharing
and reuse of software generally.
NO WARRANTY
15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO
WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW.
EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR
OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY
KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE
LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME
THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN
WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY
AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU
FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR
CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE
LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING
RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A
FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF
SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
DAMAGES.
END OF TERMS AND CONDITIONS
How to Apply These Terms to Your New Libraries
If you develop a new library, and you want it to be of the greatest
possible use to the public, we recommend making it free software that
everyone can redistribute and change. You can do so by permitting
redistribution under these terms (or, alternatively, under the terms of the
ordinary General Public License).
To apply these terms, attach the following notices to the library. It is
safest to attach them to the start of each source file to most effectively
convey the exclusion of warranty; and each file should have at least the
"copyright" line and a pointer to where the full notice is found.
<one line to give the library's name and a brief idea of what it does.>
Copyright (C) <year> <name of author>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Also add information on how to contact you by electronic and paper mail.
You should also get your employer (if you work as a programmer) or your
school, if any, to sign a "copyright disclaimer" for the library, if
necessary. Here is a sample; alter the names:
Yoyodyne, Inc., hereby disclaims all copyright interest in the
library `Frob' (a library for tweaking knobs) written by James Random Hacker.
<signature of Ty Coon>, 1 April 1990
Ty Coon, President of Vice
That's all there is to it!

176
qwt/INSTALL Normal file
View File

@@ -0,0 +1,176 @@
Introduction
============
Qwt uses qmake to build all its components and examples.
qmake is part of a Qt distribution.
qmake reads project files, that contain the options and rules how to
build a certain project. A project file ends with the suffix "*.pro".
Files that end with the suffix "*.pri" are included by the project
files and contain definitions, that are common for several project files.
qwtconfig.pri is read by all project files of the Qwt package.
So the first step is to edit qwtconfig.pri to adjust it to your
needs.
MathML Extension
================
Qwt/Qt4 supports the MathML render engine from the Qt solutions package,
that is only available with a commercial Qt license.
You need a release of qtmmlwidget >= 2.1.
Copy the files qtmmlwidget.[cpp|h] to textengines/mathml.
Documentation
==========================
Qwt includes a class documentation, that is available in various formats:
- Html files
- PDF document
- Qt Compressed Help (*.qch ) for the Qt assistant.
- Man pages ( UNIX only )
A) Unix Qt3/Qt4
==========================
qmake
make
make install
If you have installed a shared library it's path has to be known to
the run-time linker of your operating system. On Linux systems read
"man ldconfig" ( or google for it ). Another option is to use
the LD_LIBRARY_PATH (on some systems LIBPATH is used instead, on MacOSX
it is called DYLD_LIBRARY_PATH) environment variable.
If you only want to check the Qwt examples without installing something,
you can set the LD_LIBRARY_PATH to the lib directory
of your local build.
If you didn't enable autobuilding of the examples in qwtconfig.pri
you have to build the examples this way:
cd examples
qmake
make
B) Win32/MSVC Qt3/Qt4
=====================
Please read the qmake documentation how to convert
your *.pro files into your development environment.
F.e MSVC with nmake:
qmake qwt.pro
nmake
If you didn't enable autobuilding of the examples in qwtconfig.pri
you have to build the examples this way:
cd examples
qmake examples.pro
nmake
admin/msvc-qmake.bat helps users of Visual Studio users to
generate makefiles or project files (.dsp for MSVC-6.0 or vcproj for
MSVC.NET) for Qwt.
To generate makefiles, type: "admin\msvc-qmake"
To generate project files, type: "admin\msvc-qmake vc"
When you have built a Qwt DLL you need to add the following
define to your compiler flags: QWT_DLL.
Windows doesn't like mixing of debug and release binaries. Most
of the problems with using the Qwt designer plugin are because
of trying to load a Qwt debug library into a designer release
executable.
C) Win32/MinGW Qt4
==================
C1) Windows Shell
Start a Windows Shell, where Qt4 is initialized. ( F.e. with
"Programs->Qt by Trolltech ...->Qt 4.x.x Command Prompt" ).
qmake qwt.pro
make
If you didn't enable autobuilding of the examples in qwtconfig.pri
you have to build the examples this way:
cd examples
qmake examples.pro
make
make install
C2) MSYS Shell Qt >= 4.3.0
Support for the MSYS Shell has been improved in Qt 4.3.0.
Now building Qwt from the MSYS Shell works exactly like in UNIX or in the
Windows Shell - or at least it should:
because of a bug in Qt 4.3.0 you always have to do a "qmake -r".
C3) MSYS Shell Qt < 4.3.0
For Qt < 4.3.0 you have to set the MINGW_IN_SHELL variable.
make will run into errors with the subdirs target, that can be
ignored (make -i).
export MINGW_IN_SHELL=1;
qmake
make -i
make -i install
If you didn't enable autobuilding of the examples in qwtconfig.pri
you have to build the examples this way:
cd examples
qmake examples.pro
make -i
make -i install
C1-C3)
When you have built a Qwt DLL you need to add QWT_DLL to your compiler
flags. If you are using qmake for your own builds this done by adding
the following line to your profile: "DEFINES += QWT_DLL".
Windows doesn't like mixing of debug and release binaries. Most
of the problems with using the Qwt designer plugin are because
of trying to load a Qwt debug library into a designer release
executable.
D) MacOSX
Well, the Mac is only another Unix system. So read the instructions in A).
In the recent Qt4 releases the default target of qmake is to generate
XCode project files instead of makefiles. So you might need to do the
following:
qmake -spec macx-g++
...
D) Qtopia Core
I only tested Qwt with Qtopia Core in qvfb (Virtual Framebuffer Devivce)
Emulator on my Linux box. To build Qwt for the emulator was as simple as
for a regular Unix build.
qmake
make
E) Qtopia (!= Qtopia Core)
I once compiled the Qwt library against Qtopia 4.2.0 successfully - but
not more. It should be possible to build and install Qwt, but it's
not done yet.
Good luck !

33
qwt/README Normal file
View File

@@ -0,0 +1,33 @@
The Qwt Widget Library
----------------------
Qwt is an extension to the Qt GUI library from Troll Tech AS.
The Qwt library contains widgets and components which are
primarily useful for technical and scientifical purposes.
It includes a 2-D plotting widget, different kinds of sliders,
and much more.
Qwt is hosted at http://qwt.sf.net
Installation
------------
Read INSTALL how to build and install Qwt.
Copyright
---------
Qwt Widget Library
Copyright (C) 1997 Josef Wilgen
Copyright (C) 2002 Uwe Rathmann
Qwt is published under the Qwt License, Version 1.0.
You should have received a copy of this licence in the file
COPYING.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

58
qwt/admin/msvc-qmake.bat Normal file
View File

@@ -0,0 +1,58 @@
REM Batch file to make all Makefiles or all Visual Studio project files
REM (*.dsp for MSVC-6.0 or *.vcproj for MSVC-7.0) for Qwt with qmake.
REM
REM BUG: the designer plugin *.dsp file may not work; the Makefile does.
REM
REM To make Makefiles, type: msvc-qmake
REM To make project files type: msvc-qmake vc
REM For the Qwt library:
cd src
qmake -t %1lib% src.pro
cd ..
REM For the designer plugin:
cd textengines\mathml
qmake -t %1lib mathml.pro
cd ..\..
REM For the designer plugin:
cd designer
qmake -t %1lib designer.pro
cd ..
REM For the examples:
cd examples
cd bode
qmake -t %1app bode.pro
cd ..\cpuplot
qmake -t %1app cpuplot.pro
cd ..\curvdemo1
qmake -t %1app curvdemo1.pro
cd ..\curvdemo2
qmake -t %1app curvdemo2.pro
cd ..\data_plot
qmake -t %1app data_plot.pro
cd ..\dials
qmake -t %1app dials.pro
cd ..\event_filter
qmake -t %1app event_filter.pro
cd ..\histogram
qmake -t %1app histogram.pro
cd ..\radio
qmake -t %1app radio.pro
cd ..\realtime_plot
qmake -t %1app realtime_plot.pro
cd ..\simple_plot
qmake -t %1app simple_plot.pro
cd ..\sliders
qmake -t %1app sliders.pro
cd ..\spectrogram
qmake -t %1app spectrogram.pro
cd ..\svgmap
qmake -t %1app svgmap.pro
cd ..\sysinfo
qmake -t %1app sysinfo.pro
cd ..\..
REM EOF

9
qwt/admin/no-qt-keywords.sh Executable file
View File

@@ -0,0 +1,9 @@
#! /bin/sh
find src -name "qwt_*.h" | xargs grep -l 'signals:' | xargs sed -i "s/signals:/Q_SIGNALS:/"
find src -name "qwt_*.h" | xargs grep -l 'slots:' | xargs sed -i "s/signals:/Q_SLOTS:/"
find src -name "qwt_*.cpp" | xargs grep -l 'emit ' | xargs sed -i "s/emit /Q_EMIT /"
echo "CONFIG += no_keywords" >> src/src.pro

299
qwt/admin/svn2package.sh Executable file
View File

@@ -0,0 +1,299 @@
#! /bin/sh
#
# Generates a Qwt package from sourceforge svn
#
# Usage: svn2package.sh [-b|--branch <svn-branch>] [packagename]
#
##########################
# usage
##########################
function usage() {
echo "Usage: $0 [-b|--branch <svn-branch>] [-pdf] [-qch] [packagename]"
exit 1
}
################################
# checkout
################################
function checkoutQwt() {
if [ -x $2 ]
then
rm -r $2
if [ $? -ne 0 ]
then
exit $?
fi
fi
svn -q co https://qwt.svn.sourceforge.net/svnroot/qwt/$1/$2
if [ $? -ne 0 ]
then
echo "Can't access sourceforge SVN"
exit $?
fi
if [ "$3" != "$2" ]
then
rm -rf $3
mv $2 $3
fi
}
##########################
# cleanQwt dirname
##########################
function cleanQwt {
cd $1
if [ $? -ne 0 ]
then
exit $?
fi
find . -name .svn -print | xargs rm -r
rm TODO
rm admin/svn2package.sh
PROFILES="qwtconfig.pri"
for PROFILE in $PROFILES
do
sed -i -e 's/= debug /= release /' $PROFILE
done
HEADERS=`find . -type f -name '*.h' -print`
SOURCES=`find . -type f -name '*.cpp' -print`
PROFILES=`find . -type f -name '*.pro' -print`
PRIFILES=`find . -type f -name '*.pri' -print`
for EXPANDFILE in $HEADERS $SOURCES $PROFILES $PRIFILES
do
expand -4 $EXPANDFILE > $EXPANDFILE.expand
mv $EXPANDFILE.expand $EXPANDFILE
done
for SRCFILE in $SOURCES $PROFILES $PRIFILES
do
sed -i -e '/#warning/d' $SRCFILE
done
sed -i -e "s/\$\$VERSION-svn/$VERSION/" qwtconfig.pri
sed -i -e "s/\$\${QwtVersion}-svn/\$\${QwtVersion}/" qwt.prf
cd - > /dev/null
}
##########################
# createDocs dirname
##########################
function createDocs {
ODIR=`pwd`
cd $1
if [ $? -ne 0 ]
then
exit $?
fi
cp Doxyfile Doxyfile.doc
sed -i '/PROJECT_NUMBER/d' Doxyfile.doc
echo "PROJECT_NUMBER = $VERSION" >> Doxyfile.doc
if [ $GENERATE_MAN -ne 0 ]
then
sed -i -e '/GENERATE_MAN/d' -e '/PROJECT_NUMBER/d' Doxyfile.doc
echo 'GENERATE_MAN = YES' >> Doxyfile.doc
fi
if [ $GENERATE_PDF -ne 0 ]
then
# We need LateX for the qwtdoc.pdf
sed -i -e '/GENERATE_LATEX/d' -e '/GENERATE_MAN/d' -e '/PROJECT_NUMBER/d' Doxyfile.doc
echo 'GENERATE_LATEX = YES' >> Doxyfile.doc
echo 'GENERATE_MAN = YES' >> Doxyfile.doc
echo "PROJECT_NUMBER = $VERSION" >> Doxyfile.doc
fi
if [ $GENERATE_QCH -ne 0 ]
then
sed -i -e '/GENERATE_HTMLHELP/d' Doxyfile.doc
echo "GENERATE_HTMLHELP = YES" >> Doxyfile.doc
fi
cp ../INSTALL ../COPYING ./
doxygen Doxyfile.doc > /dev/null
if [ $? -ne 0 ]
then
exit $?
fi
if [ $GENERATE_QCH -ne 0 ]
then
doxygen2qthelp --namespace=net.sourceforge.qwt-$VERSION --folder=qwt-$VERSION html/index.hhp qwt-$VERSION.qch
rm html/index.hh*
fi
rm Doxyfile.doc Doxygen.log INSTALL COPYING
rm -r images
if [ $GENERATE_PDF -ne 0 ]
then
cd latex
make > /dev/null 2>&1
if [ $? -ne 0 ]
then
exit $?
fi
cd ..
mkdir pdf
mv latex/refman.pdf pdf/qwtdoc.pdf
rm -r latex
fi
cd $ODIR
}
##########################
# posix2dos filename
##########################
function posix2dos {
# At least one unix2dos writes to stdout instead of overwriting the input.
# The -q option is always enabled in stdin->stdout mode.
unix2dos <$1 >$1.dos
mv $1.dos $1
}
##########################
# prepare4Win dirname
##########################
function prepare4Win {
cd $1
if [ $? -ne 0 ]
then
exit $?
fi
rm -r doc/man
# win files, but not uptodate
BATCHES=`find . -type f -name '*.bat' -print`
HEADERS=`find . -type f -name '*.h' -print`
SOURCES=`find . -type f -name '*.cpp' -print`
PROFILES=`find . -type f -name '*.pro' -print`
PRIFILES=`find . -type f -name '*.pri' -print`
for FILE in $BATCHES $HEADERS $SOURCES $PROFILES $PRIFILES
do
posix2dos $FILE
done
cd - > /dev/null
}
##########################
# prepare4Unix dirname
##########################
function prepare4Unix {
cd $1
if [ $? -ne 0 ]
then
exit $?
fi
rm -rf admin
cd - > /dev/null
}
##########################
# main
##########################
QWTDIR=
SVNDIR=trunk
BRANCH=qwt
VERSION=
GENERATE_PDF=0
GENERATE_QCH=0
GENERATE_MAN=1
while [ $# -gt 0 ] ; do
case "$1" in
-h|--help)
usage; exit 1 ;;
-b|--branch)
shift; SVNDIR=branches; BRANCH=$1; shift;;
-pdf)
GENERATE_PDF=1; shift;;
-qch)
GENERATE_QCH=1; shift;;
*)
QWTDIR=qwt-$1 ; VERSION=$1; shift;;
esac
done
if [ "$QWTDIR" == "" ]
then
usage
exit 2
fi
TMPDIR=/tmp/$QWTDIR-tmp
echo -n "checkout to $TMPDIR ... "
checkoutQwt $SVNDIR $BRANCH $TMPDIR
cleanQwt $TMPDIR
echo done
echo -n "generate documentation ... "
createDocs $TMPDIR/doc
if [ $GENERATE_PDF -ne 0 ]
then
mv $TMPDIR/doc/pdf/qwtdoc.pdf $QWTDIR.pdf
rmdir $TMPDIR/doc/pdf
fi
echo done
DIR=`pwd`
echo -n "create packages in $DIR ... "
cd /tmp
rm -rf $QWTDIR
cp -a $TMPDIR $QWTDIR
prepare4Unix $QWTDIR
tar cfz $QWTDIR.tgz $QWTDIR
tar cfj $QWTDIR.tar.bz2 $QWTDIR
rm -rf $QWTDIR
cp -a $TMPDIR $QWTDIR
prepare4Win $QWTDIR
zip -r $QWTDIR.zip $QWTDIR > /dev/null
rm -rf $TMPDIR $QWTDIR
mv $QWTDIR.tgz $QWTDIR.tar.bz2 $QWTDIR.zip $DIR/
echo done
exit 0

135
qwt/designer/designer.pro Normal file
View File

@@ -0,0 +1,135 @@
# -*- mode: sh -*- ###########################
# Qwt Widget Library
# Copyright (C) 1997 Josef Wilgen
# Copyright (C) 2002 Uwe Rathmann
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the Qwt License, Version 1.0
##############################################
QWT_ROOT = ..
include ( $${QWT_ROOT}/qwtconfig.pri )
contains(CONFIG, QwtDesigner) {
CONFIG += warn_on
SUFFIX_STR =
VVERSION = $$[QT_VERSION]
isEmpty(VVERSION) {
# Qt 3
debug {
SUFFIX_STR = $${DEBUG_SUFFIX}
}
else {
SUFFIX_STR = $${RELEASE_SUFFIX}
}
}
else {
CONFIG(debug, debug|release) {
SUFFIX_STR = $${DEBUG_SUFFIX}
}
else {
SUFFIX_STR = $${RELEASE_SUFFIX}
}
}
TEMPLATE = lib
MOC_DIR = moc
OBJECTS_DIR = obj$${SUFFIX_STR}
DESTDIR = plugins/designer
INCLUDEPATH += $${QWT_ROOT}/src
DEPENDPATH += $${QWT_ROOT}/src
LIBNAME = qwt$${SUFFIX_STR}
contains(CONFIG, QwtDll) {
win32 {
DEFINES += QT_DLL QWT_DLL
LIBNAME = $${LIBNAME}$${VER_MAJ}
}
}
!contains(CONFIG, QwtPlot) {
DEFINES += NO_QWT_PLOT
}
!contains(CONFIG, QwtWidgets) {
DEFINES += NO_QWT_WIDGETS
}
unix:LIBS += -L$${QWT_ROOT}/lib -l$${LIBNAME}
win32-msvc:LIBS += $${QWT_ROOT}/lib/$${LIBNAME}.lib
win32-msvc.net:LIBS += $${QWT_ROOT}/lib/$${LIBNAME}.lib
win32-msvc2002:LIBS += $${QWT_ROOT}/lib/$${LIBNAME}.lib
win32-msvc2003:LIBS += $${QWT_ROOT}/lib/$${LIBNAME}.lib
win32-msvc2005:LIBS += $${QWT_ROOT}/lib/$${LIBNAME}.lib
win32-msvc2008:LIBS += $${QWT_ROOT}/lib/$${LIBNAME}.lib
win32-g++:LIBS += -L$${QWT_ROOT}/lib -l$${LIBNAME}
# isEmpty(QT_VERSION) does not work with Qt-4.1.0/MinGW
VVERSION = $$[QT_VERSION]
isEmpty(VVERSION) {
# Qt 3
TARGET = qwtplugin$${SUFFIX_STR}
CONFIG += qt plugin
UI_DIR = ui
HEADERS += qwtplugin.h
SOURCES += qwtplugin.cpp
target.path = $(QTDIR)/plugins/designer
INSTALLS += target
IMAGES += \
pixmaps/qwtplot.png \
pixmaps/qwtanalogclock.png \
pixmaps/qwtcounter.png \
pixmaps/qwtcompass.png \
pixmaps/qwtdial.png \
pixmaps/qwtknob.png \
pixmaps/qwtscale.png \
pixmaps/qwtslider.png \
pixmaps/qwtthermo.png \
pixmaps/qwtwheel.png \
pixmaps/qwtwidget.png
} else {
# Qt 4
TARGET = qwt_designer_plugin$${SUFFIX_STR}
CONFIG += qt designer plugin
RCC_DIR = resources
HEADERS += \
qwt_designer_plugin.h
SOURCES += \
qwt_designer_plugin.cpp
contains(CONFIG, QwtPlot) {
HEADERS += \
qwt_designer_plotdialog.h
SOURCES += \
qwt_designer_plotdialog.cpp
}
RESOURCES += \
qwt_designer_plugin.qrc
target.path = $$[QT_INSTALL_PLUGINS]/designer
INSTALLS += target
}
}
else {
TEMPLATE = subdirs # do nothing
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 422 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 992 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 433 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 807 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 543 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 373 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 452 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 580 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 298 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

View File

@@ -0,0 +1,42 @@
/* -*- mode: C++ ; c-file-style: "stroustrup" -*- *****************************
* Qwt Widget Library
* Copyright (C) 1997 Josef Wilgen
* Copyright (C) 2002 Uwe Rathmann
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the Qwt License, Version 1.0
*****************************************************************************/
#include <QLineEdit>
#include <QTabWidget>
#include <QHBoxLayout>
#include <QPushButton>
#include "qwt_designer_plotdialog.h"
using namespace QwtDesignerPlugin;
PlotDialog::PlotDialog(const QString &properties, QWidget *parent):
QDialog(parent)
{
setWindowTitle("Plot Properties");
QLineEdit *lineEdit = new QLineEdit(properties);
connect(lineEdit, SIGNAL(textChanged(const QString &)),
SIGNAL(edited(const QString &)));
QTabWidget *tabWidget = new QTabWidget(this);
tabWidget->addTab(lineEdit, "General");
QPushButton *closeButton = new QPushButton("Close");
connect(closeButton, SIGNAL(clicked()), this, SLOT(accept()));
QHBoxLayout *buttonLayout = new QHBoxLayout;
buttonLayout->addStretch(1);
buttonLayout->addWidget(closeButton);
QVBoxLayout *mainLayout = new QVBoxLayout;
mainLayout->addWidget(tabWidget);
mainLayout->addLayout(buttonLayout);
setLayout(mainLayout);
}

View File

@@ -0,0 +1,39 @@
/* -*- mode: C++ ; c-file-style: "stroustrup" -*- *****************************
* Qwt Widget Library
* Copyright (C) 1997 Josef Wilgen
* Copyright (C) 2002 Uwe Rathmann
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the Qwt License, Version 1.0
*****************************************************************************/
#ifndef QWT_DESIGNER_PLOTDIALOG_H
#define QWT_DESIGNER_PLOTDIALOG_H
#include <qglobal.h>
#if QT_VERSION < 0x040000
#ifdef __GNUC__
#error This code is Qt4 only
#endif
#endif
#include <QDialog>
namespace QwtDesignerPlugin
{
class PlotDialog: public QDialog
{
Q_OBJECT
public:
PlotDialog(const QString &properties, QWidget *parent = NULL);
signals:
void edited(const QString&);
};
}
#endif

View File

@@ -0,0 +1,516 @@
/* -*- mode: C++ ; c-file-style: "stroustrup" -*- *****************************
* Qwt Widget Library
* Copyright (C) 1997 Josef Wilgen
* Copyright (C) 2002 Uwe Rathmann
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the Qwt License, Version 1.0
*****************************************************************************/
#if defined(_MSC_VER) /* MSVC Compiler */
#pragma warning ( disable : 4786 )
#endif
#include <qglobal.h>
#include <qaction.h>
#include <QtPlugin>
#include <QDesignerFormEditorInterface>
#include <QDesignerFormWindowInterface>
#include <QDesignerFormWindowCursorInterface>
#include <QExtensionManager>
#include <QErrorMessage>
#include "qwt_designer_plugin.h"
#ifndef NO_QWT_PLOT
#include "qwt_designer_plotdialog.h"
#include "qwt_plot.h"
#include "qwt_scale_widget.h"
#endif
#ifndef NO_QWT_WIDGETS
#include "qwt_counter.h"
#include "qwt_wheel.h"
#include "qwt_thermo.h"
#include "qwt_knob.h"
#include "qwt_slider.h"
#include "qwt_analog_clock.h"
#include "qwt_compass.h"
#endif
#include "qwt_text_label.h"
using namespace QwtDesignerPlugin;
CustomWidgetInterface::CustomWidgetInterface(QObject *parent):
QObject(parent),
d_isInitialized(false)
{
}
bool CustomWidgetInterface::isContainer() const
{
return false;
}
bool CustomWidgetInterface::isInitialized() const
{
return d_isInitialized;
}
QIcon CustomWidgetInterface::icon() const
{
return d_icon;
}
QString CustomWidgetInterface::codeTemplate() const
{
return d_codeTemplate;
}
QString CustomWidgetInterface::domXml() const
{
return d_domXml;
}
QString CustomWidgetInterface::group() const
{
return "Qwt Widgets";
}
QString CustomWidgetInterface::includeFile() const
{
return d_include;
}
QString CustomWidgetInterface::name() const
{
return d_name;
}
QString CustomWidgetInterface::toolTip() const
{
return d_toolTip;
}
QString CustomWidgetInterface::whatsThis() const
{
return d_whatsThis;
}
void CustomWidgetInterface::initialize(
QDesignerFormEditorInterface *formEditor)
{
if ( d_isInitialized )
return;
QExtensionManager *manager = formEditor->extensionManager();
if ( manager )
{
manager->registerExtensions(new TaskMenuFactory(manager),
Q_TYPEID(QDesignerTaskMenuExtension));
}
d_isInitialized = true;
}
#ifndef NO_QWT_PLOT
PlotInterface::PlotInterface(QObject *parent):
CustomWidgetInterface(parent)
{
d_name = "QwtPlot";
d_include = "qwt_plot.h";
d_icon = QPixmap(":/pixmaps/qwtplot.png");
d_domXml =
"<widget class=\"QwtPlot\" name=\"qwtPlot\">\n"
" <property name=\"geometry\">\n"
" <rect>\n"
" <x>0</x>\n"
" <y>0</y>\n"
" <width>400</width>\n"
" <height>200</height>\n"
" </rect>\n"
" </property>\n"
"</widget>\n";
}
QWidget *PlotInterface::createWidget(QWidget *parent)
{
return new QwtPlot(parent);
}
#endif
#ifndef NO_QWT_WIDGETS
AnalogClockInterface::AnalogClockInterface(QObject *parent):
CustomWidgetInterface(parent)
{
d_name = "QwtAnalogClock";
d_include = "qwt_analog_clock.h";
d_icon = QPixmap(":/pixmaps/qwtanalogclock.png");
d_domXml =
"<widget class=\"QwtAnalogClock\" name=\"AnalogClock\">\n"
" <property name=\"geometry\">\n"
" <rect>\n"
" <x>0</x>\n"
" <y>0</y>\n"
" <width>200</width>\n"
" <height>200</height>\n"
" </rect>\n"
" </property>\n"
" <property name=\"lineWidth\">\n"
" <number>4</number>\n"
" </property>\n"
"</widget>\n";
}
QWidget *AnalogClockInterface::createWidget(QWidget *parent)
{
return new QwtAnalogClock(parent);
}
#endif
#ifndef NO_QWT_WIDGETS
CompassInterface::CompassInterface(QObject *parent):
CustomWidgetInterface(parent)
{
d_name = "QwtCompass";
d_include = "qwt_compass.h";
d_icon = QPixmap(":/pixmaps/qwtcompass.png");
d_domXml =
"<widget class=\"QwtCompass\" name=\"Compass\">\n"
" <property name=\"geometry\">\n"
" <rect>\n"
" <x>0</x>\n"
" <y>0</y>\n"
" <width>200</width>\n"
" <height>200</height>\n"
" </rect>\n"
" </property>\n"
" <property name=\"lineWidth\">\n"
" <number>4</number>\n"
" </property>\n"
"</widget>\n";
}
QWidget *CompassInterface::createWidget(QWidget *parent)
{
return new QwtCompass(parent);
}
#endif
#ifndef NO_QWT_WIDGETS
CounterInterface::CounterInterface(QObject *parent):
CustomWidgetInterface(parent)
{
d_name = "QwtCounter";
d_include = "qwt_counter.h";
d_icon = QPixmap(":/pixmaps/qwtcounter.png");
d_domXml =
"<widget class=\"QwtCounter\" name=\"Counter\">\n"
"</widget>\n";
}
QWidget *CounterInterface::createWidget(QWidget *parent)
{
return new QwtCounter(parent);
}
#endif
#ifndef NO_QWT_WIDGETS
DialInterface::DialInterface(QObject *parent):
CustomWidgetInterface(parent)
{
d_name = "QwtDial";
d_include = "qwt_dial.h";
d_icon = QPixmap(":/pixmaps/qwtdial.png");
d_domXml =
"<widget class=\"QwtDial\" name=\"Dial\">\n"
" <property name=\"geometry\">\n"
" <rect>\n"
" <x>0</x>\n"
" <y>0</y>\n"
" <width>200</width>\n"
" <height>200</height>\n"
" </rect>\n"
" </property>\n"
" <property name=\"lineWidth\">\n"
" <number>4</number>\n"
" </property>\n"
"</widget>\n";
}
QWidget *DialInterface::createWidget(QWidget *parent)
{
return new QwtDial(parent);
}
#endif
#ifndef NO_QWT_WIDGETS
KnobInterface::KnobInterface(QObject *parent):
CustomWidgetInterface(parent)
{
d_name = "QwtKnob";
d_include = "qwt_knob.h";
d_icon = QPixmap(":/pixmaps/qwtknob.png");
d_domXml =
"<widget class=\"QwtKnob\" name=\"Knob\">\n"
" <property name=\"geometry\">\n"
" <rect>\n"
" <x>0</x>\n"
" <y>0</y>\n"
" <width>100</width>\n"
" <height>100</height>\n"
" </rect>\n"
" </property>\n"
"</widget>\n";
}
QWidget *KnobInterface::createWidget(QWidget *parent)
{
return new QwtKnob(parent);
}
#endif
#ifndef NO_QWT_PLOT
ScaleWidgetInterface::ScaleWidgetInterface(QObject *parent):
CustomWidgetInterface(parent)
{
d_name = "QwtScaleWidget";
d_include = "qwt_scale_widget.h";
d_icon = QPixmap(":/pixmaps/qwtscale.png");
d_domXml =
"<widget class=\"QwtScaleWidget\" name=\"ScaleWidget\">\n"
"</widget>\n";
}
QWidget *ScaleWidgetInterface::createWidget(QWidget *parent)
{
return new QwtScaleWidget(QwtScaleDraw::LeftScale, parent);
}
#endif
#ifndef NO_QWT_WIDGETS
SliderInterface::SliderInterface(QObject *parent):
CustomWidgetInterface(parent)
{
d_name = "QwtSlider";
d_include = "qwt_slider.h";
d_icon = QPixmap(":/pixmaps/qwtslider.png");
d_domXml =
"<widget class=\"QwtSlider\" name=\"Slider\">\n"
" <property name=\"geometry\">\n"
" <rect>\n"
" <x>0</x>\n"
" <y>0</y>\n"
" <width>200</width>\n"
" <height>60</height>\n"
" </rect>\n"
" </property>\n"
"</widget>\n";
}
QWidget *SliderInterface::createWidget(QWidget *parent)
{
QwtSlider *slider = new QwtSlider(parent);
#if 0
slider->setScalePosition(QwtSlider::Bottom);
slider->setRange(0.0, 10.0, 1.0, 0);
slider->setValue(3.0);
#endif
return slider;
}
#endif
TextLabelInterface::TextLabelInterface(QObject *parent):
CustomWidgetInterface(parent)
{
d_name = "QwtTextLabel";
d_include = "qwt_text_label.h";
#ifdef __GNUC__
#warning QwtTextLabel icon is missing
#endif
d_icon = QPixmap(":/pixmaps/qwtwidget.png");
d_domXml =
"<widget class=\"QwtTextLabel\" name=\"TextLabel\">\n"
" <property name=\"geometry\">\n"
" <rect>\n"
" <x>0</x>\n"
" <y>0</y>\n"
" <width>100</width>\n"
" <height>20</height>\n"
" </rect>\n"
" </property>\n"
"</widget>\n";
}
QWidget *TextLabelInterface::createWidget(QWidget *parent)
{
return new QwtTextLabel(parent);
}
#ifndef NO_QWT_WIDGETS
ThermoInterface::ThermoInterface(QObject *parent):
CustomWidgetInterface(parent)
{
d_name = "QwtThermo";
d_include = "qwt_thermo.h";
d_icon = QPixmap(":/pixmaps/qwtthermo.png");
d_domXml =
"<widget class=\"QwtThermo\" name=\"Thermo\">\n"
"</widget>\n";
}
QWidget *ThermoInterface::createWidget(QWidget *parent)
{
return new QwtThermo(parent);
}
#endif
#ifndef NO_QWT_WIDGETS
WheelInterface::WheelInterface(QObject *parent):
CustomWidgetInterface(parent)
{
d_name = "QwtWheel";
d_include = "qwt_wheel.h";
d_icon = QPixmap(":/pixmaps/qwtwheel.png");
d_domXml =
"<widget class=\"QwtWheel\" name=\"Wheel\">\n"
"</widget>\n";
}
QWidget *WheelInterface::createWidget(QWidget *parent)
{
return new QwtWheel(parent);
}
#endif
CustomWidgetCollectionInterface::CustomWidgetCollectionInterface(
QObject *parent):
QObject(parent)
{
#ifndef NO_QWT_PLOT
d_plugins.append(new PlotInterface(this));
d_plugins.append(new ScaleWidgetInterface(this));
#endif
#ifndef NO_QWT_WIDGETS
d_plugins.append(new AnalogClockInterface(this));
d_plugins.append(new CompassInterface(this));
d_plugins.append(new CounterInterface(this));
d_plugins.append(new DialInterface(this));
d_plugins.append(new KnobInterface(this));
d_plugins.append(new SliderInterface(this));
d_plugins.append(new ThermoInterface(this));
d_plugins.append(new WheelInterface(this));
#endif
d_plugins.append(new TextLabelInterface(this));
}
QList<QDesignerCustomWidgetInterface*>
CustomWidgetCollectionInterface::customWidgets(void) const
{
return d_plugins;
}
TaskMenuFactory::TaskMenuFactory(QExtensionManager *parent):
QExtensionFactory(parent)
{
}
QObject *TaskMenuFactory::createExtension(
QObject *object, const QString &iid, QObject *parent) const
{
if (iid == Q_TYPEID(QDesignerTaskMenuExtension))
{
#ifndef NO_QWT_PLOT
if (QwtPlot *plot = qobject_cast<QwtPlot*>(object))
return new TaskMenuExtension(plot, parent);
#endif
#ifndef NO_QWT_WIDGETS
if (QwtDial *dial = qobject_cast<QwtDial*>(object))
return new TaskMenuExtension(dial, parent);
#endif
}
return QExtensionFactory::createExtension(object, iid, parent);
}
TaskMenuExtension::TaskMenuExtension(QWidget *widget, QObject *parent):
QObject(parent),
d_widget(widget)
{
d_editAction = new QAction(tr("Edit Qwt Attributes ..."), this);
connect(d_editAction, SIGNAL(triggered()),
this, SLOT(editProperties()));
}
QList<QAction *> TaskMenuExtension::taskActions() const
{
QList<QAction *> list;
list.append(d_editAction);
return list;
}
QAction *TaskMenuExtension::preferredEditAction() const
{
return d_editAction;
}
void TaskMenuExtension::editProperties()
{
const QVariant v = d_widget->property("propertiesDocument");
if ( v.type() != QVariant::String )
return;
#ifndef NO_QWT_PLOT
QString properties = v.toString();
if ( qobject_cast<QwtPlot*>(d_widget) )
{
PlotDialog dialog(properties);
connect(&dialog, SIGNAL(edited(const QString&)),
SLOT(applyProperties(const QString &)));
(void)dialog.exec();
return;
}
#endif
static QErrorMessage *errorMessage = NULL;
if ( errorMessage == NULL )
errorMessage = new QErrorMessage();
errorMessage->showMessage("Not implemented yet.");
}
void TaskMenuExtension::applyProperties(const QString &properties)
{
QDesignerFormWindowInterface *formWindow
= QDesignerFormWindowInterface::findFormWindow(d_widget);
if ( formWindow && formWindow->cursor() )
formWindow->cursor()->setProperty("propertiesDocument", properties);
}
Q_EXPORT_PLUGIN2(QwtDesignerPlugin, CustomWidgetCollectionInterface)

View File

@@ -0,0 +1,244 @@
/* -*- mode: C++ ; c-file-style: "stroustrup" -*- *****************************
* Qwt Widget Library
* Copyright (C) 1997 Josef Wilgen
* Copyright (C) 2002 Uwe Rathmann
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the Qwt License, Version 1.0
*****************************************************************************/
#ifndef QWT_DESIGNER_PLUGIN_H
#define QWT_DESIGNER_PLUGIN_H
#include <qglobal.h>
#if QT_VERSION < 0x040000
#ifdef __GNUC__
#error This code is Qt4 only
#endif
#endif
#include <QDesignerCustomWidgetInterface>
#include <QDesignerTaskMenuExtension>
#include <QExtensionFactory>
namespace QwtDesignerPlugin
{
class CustomWidgetInterface: public QObject,
public QDesignerCustomWidgetInterface
{
Q_OBJECT
Q_INTERFACES(QDesignerCustomWidgetInterface)
public:
CustomWidgetInterface(QObject *parent);
virtual bool isContainer() const;
virtual bool isInitialized() const;
virtual QIcon icon() const;
virtual QString codeTemplate() const;
virtual QString domXml() const;
virtual QString group() const;
virtual QString includeFile() const;
virtual QString name() const;
virtual QString toolTip() const;
virtual QString whatsThis() const;
virtual void initialize(QDesignerFormEditorInterface *);
protected:
QString d_name;
QString d_include;
QString d_toolTip;
QString d_whatsThis;
QString d_domXml;
QString d_codeTemplate;
QIcon d_icon;
private:
bool d_isInitialized;
};
class CustomWidgetCollectionInterface: public QObject,
public QDesignerCustomWidgetCollectionInterface
{
Q_OBJECT
Q_INTERFACES(QDesignerCustomWidgetCollectionInterface)
public:
CustomWidgetCollectionInterface(QObject *parent = NULL);
virtual QList<QDesignerCustomWidgetInterface*> customWidgets() const;
private:
QList<QDesignerCustomWidgetInterface*> d_plugins;
};
#ifndef NO_QWT_PLOT
class PlotInterface: public CustomWidgetInterface
{
Q_OBJECT
Q_INTERFACES(QDesignerCustomWidgetInterface)
public:
PlotInterface(QObject *parent);
virtual QWidget *createWidget(QWidget *parent);
};
#endif
#ifndef NO_QWT_WIDGETS
class AnalogClockInterface: public CustomWidgetInterface
{
Q_OBJECT
Q_INTERFACES(QDesignerCustomWidgetInterface)
public:
AnalogClockInterface(QObject *parent);
virtual QWidget *createWidget(QWidget *parent);
};
#endif
#ifndef NO_QWT_WIDGETS
class CompassInterface: public CustomWidgetInterface
{
Q_OBJECT
Q_INTERFACES(QDesignerCustomWidgetInterface)
public:
CompassInterface(QObject *parent);
virtual QWidget *createWidget(QWidget *parent);
};
#endif
#ifndef NO_QWT_WIDGETS
class CounterInterface: public CustomWidgetInterface
{
Q_OBJECT
Q_INTERFACES(QDesignerCustomWidgetInterface)
public:
CounterInterface(QObject *parent);
virtual QWidget *createWidget(QWidget *parent);
};
#endif
#ifndef NO_QWT_WIDGETS
class DialInterface: public CustomWidgetInterface
{
Q_OBJECT
Q_INTERFACES(QDesignerCustomWidgetInterface)
public:
DialInterface(QObject *parent);
virtual QWidget *createWidget(QWidget *parent);
};
#endif
#ifndef NO_QWT_WIDGETS
class KnobInterface: public CustomWidgetInterface
{
Q_OBJECT
Q_INTERFACES(QDesignerCustomWidgetInterface)
public:
KnobInterface(QObject *parent);
virtual QWidget *createWidget(QWidget *parent);
};
#endif
#ifndef NO_QWT_PLOT
class ScaleWidgetInterface: public CustomWidgetInterface
{
Q_OBJECT
Q_INTERFACES(QDesignerCustomWidgetInterface)
public:
ScaleWidgetInterface(QObject *parent);
virtual QWidget *createWidget(QWidget *parent);
};
#endif
#ifndef NO_QWT_WIDGETS
class SliderInterface: public CustomWidgetInterface
{
Q_OBJECT
Q_INTERFACES(QDesignerCustomWidgetInterface)
public:
SliderInterface(QObject *parent);
virtual QWidget *createWidget(QWidget *parent);
};
#endif
class TextLabelInterface: public CustomWidgetInterface
{
Q_OBJECT
Q_INTERFACES(QDesignerCustomWidgetInterface)
public:
TextLabelInterface(QObject *parent);
virtual QWidget *createWidget(QWidget *parent);
};
#ifndef NO_QWT_WIDGETS
class ThermoInterface: public CustomWidgetInterface
{
Q_OBJECT
Q_INTERFACES(QDesignerCustomWidgetInterface)
public:
ThermoInterface(QObject *parent);
virtual QWidget *createWidget(QWidget *parent);
};
#endif
#ifndef NO_QWT_WIDGETS
class WheelInterface: public CustomWidgetInterface
{
Q_OBJECT
Q_INTERFACES(QDesignerCustomWidgetInterface)
public:
WheelInterface(QObject *parent);
virtual QWidget *createWidget(QWidget *parent);
};
#endif
class TaskMenuFactory: public QExtensionFactory
{
Q_OBJECT
public:
TaskMenuFactory(QExtensionManager *parent = 0);
protected:
QObject *createExtension(QObject *object,
const QString &iid, QObject *parent) const;
};
class TaskMenuExtension: public QObject,
public QDesignerTaskMenuExtension
{
Q_OBJECT
Q_INTERFACES(QDesignerTaskMenuExtension)
public:
TaskMenuExtension(QWidget *widget, QObject *parent);
QAction *preferredEditAction() const;
QList<QAction *> taskActions() const;
private slots:
void editProperties();
void applyProperties(const QString &);
private:
QAction *d_editAction;
QWidget *d_widget;
};
};
#endif

View File

@@ -0,0 +1,15 @@
<!DOCTYPE RCC><RCC version="1.0">
<qresource>
<file>pixmaps/qwtplot.png</file>
<file>pixmaps/qwtanalogclock.png</file>
<file>pixmaps/qwtcounter.png</file>
<file>pixmaps/qwtcompass.png</file>
<file>pixmaps/qwtdial.png</file>
<file>pixmaps/qwtknob.png</file>
<file>pixmaps/qwtscale.png</file>
<file>pixmaps/qwtslider.png</file>
<file>pixmaps/qwtthermo.png</file>
<file>pixmaps/qwtwheel.png</file>
<file>pixmaps/qwtwidget.png</file>
</qresource>
</RCC>

202
qwt/designer/qwtplugin.cpp Normal file
View File

@@ -0,0 +1,202 @@
/* -*- mode: C++ ; c-file-style: "stroustrup" -*- *****************************
* Qwt Widget Library
* Copyright (C) 1997 Josef Wilgen
* Copyright (C) 2002 Uwe Rathmann
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the Qwt License, Version 1.0
*****************************************************************************/
#if defined(_MSC_VER) /* MSVC Compiler */
#pragma warning ( disable : 4786 )
#endif
#include <qglobal.h>
#include <qvaluelist.h>
#include <qmime.h>
#include <qdragobject.h>
#include "qwtplugin.h"
#include "qwt_text_label.h"
#ifndef NO_QWT_PLOT
#include "qwt_plot.h"
#include "qwt_scale_widget.h"
#endif
#ifndef NO_QWT_WIDGETS
#include "qwt_counter.h"
#include "qwt_wheel.h"
#include "qwt_thermo.h"
#include "qwt_knob.h"
#include "qwt_slider.h"
#include "qwt_analog_clock.h"
#include "qwt_compass.h"
#endif
namespace
{
struct Entry
{
Entry() {}
Entry( QString _classname, QString _header, QString _pixmap,
QString _tooltip, QString _whatshis):
classname(_classname),
header(_header),
pixmap(_pixmap),
tooltip(_tooltip),
whatshis(_whatshis)
{}
QString classname;
QString header;
QString pixmap;
QString tooltip;
QString whatshis;
};
QValueList<Entry> vec;
const Entry *entry(const QString& str)
{
for ( uint i = 0; i < vec.count(); i++ )
{
if (str == vec[i].classname)
return &vec[i];
}
return NULL;
}
}
QwtPlugin::QwtPlugin()
{
#ifndef NO_QWT_PLOT
vec.append(Entry("QwtPlot", "qwt_plot.h",
"qwtplot.png", "QwtPlot", "whatsthis"));
vec.append(Entry("QwtScaleWidget", "qwt_scale_widget.h",
"qwtscale.png", "QwtScaleWidget", "whatsthis"));
#endif
#ifndef NO_QWT_WIDGETS
vec.append(Entry("QwtAnalogClock", "qwt_analog_clock.h",
"qwtanalogclock.png", "QwtAnalogClock", "whatsthis"));
vec.append(Entry("QwtCompass", "qwt_compass.h",
"qwtcompass.png", "QwtCompass", "whatsthis"));
vec.append(Entry("QwtCounter", "qwt_counter.h",
"qwtcounter.png", "QwtCounter", "whatsthis"));
vec.append(Entry("QwtDial", "qwt_dial.h",
"qwtdial.png", "QwtDial", "whatsthis"));
vec.append(Entry("QwtKnob", "qwt_knob.h",
"qwtknob.png", "QwtKnob", "whatsthis"));
vec.append(Entry("QwtSlider", "qwt_slider.h",
"qwtslider.png", "QwtSlider", "whatsthis"));
vec.append(Entry("QwtThermo", "qwt_thermo.h",
"qwtthermo.png", "QwtThermo", "whatsthis"));
vec.append(Entry("QwtWheel", "qwt_wheel.h",
"qwtwheel.png", "QwtWheel", "whatsthis"));
#endif
vec.append(Entry("QwtTextLabel", "qwt_text_label.h",
"qwtwidget.png", "QwtTextLabel", "whatsthis"));
}
QWidget* QwtPlugin::create(const QString &key,
QWidget* parent, const char* name)
{
QWidget *w = NULL;
#ifndef NO_QWT_PLOT
if ( key == "QwtPlot" )
w = new QwtPlot( parent );
else if ( key == "QwtScaleWidget" )
w = new QwtScaleWidget( QwtScaleDraw::LeftScale, parent);
#endif
#ifndef NO_QWT_WIDGETS
if ( key == "QwtAnalogClock" )
w = new QwtAnalogClock( parent);
else if ( key == "QwtCounter" )
w = new QwtCounter( parent);
else if ( key == "QwtCompass" )
w = new QwtCompass( parent);
else if ( key == "QwtDial" )
w = new QwtDial( parent);
else if ( key == "QwtWheel" )
w = new QwtWheel( parent);
else if ( key == "QwtThermo" )
w = new QwtThermo( parent);
else if ( key == "QwtKnob" )
w = new QwtKnob( parent);
else if ( key == "QwtSlider" )
w = new QwtSlider( parent);
#endif
if ( key == "QwtTextLabel" )
w = new QwtTextLabel( parent);
if ( w )
w->setName(name);
return w;
}
QStringList QwtPlugin::keys() const
{
QStringList list;
for (unsigned i = 0; i < vec.count(); i++)
list += vec[i].classname;
return list;
}
QString QwtPlugin::group( const QString& feature ) const
{
if (entry(feature) != NULL )
return QString("Qwt");
return QString::null;
}
QIconSet QwtPlugin::iconSet( const QString& pmap) const
{
QString pixmapKey("qwtwidget.png");
if (entry(pmap) != NULL )
pixmapKey = entry(pmap)->pixmap;
const QMimeSource *ms =
QMimeSourceFactory::defaultFactory()->data(pixmapKey);
QPixmap pixmap;
QImageDrag::decode(ms, pixmap);
return QIconSet(pixmap);
}
QString QwtPlugin::includeFile( const QString& feature ) const
{
if (entry(feature) != NULL)
return entry(feature)->header;
return QString::null;
}
QString QwtPlugin::toolTip( const QString& feature ) const
{
if (entry(feature) != NULL )
return entry(feature)->tooltip;
return QString::null;
}
QString QwtPlugin::whatsThis( const QString& feature ) const
{
if (entry(feature) != NULL)
return entry(feature)->whatshis;
return QString::null;
}
bool QwtPlugin::isContainer( const QString& ) const
{
return false;
}
Q_EXPORT_PLUGIN( QwtPlugin )

42
qwt/designer/qwtplugin.h Normal file
View File

@@ -0,0 +1,42 @@
/* -*- mode: C++ ; c-file-style: "stroustrup" -*- *****************************
* Qwt Widget Library
* Copyright (C) 1997 Josef Wilgen
* Copyright (C) 2002 Uwe Rathmann
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the Qwt License, Version 1.0
*****************************************************************************/
#ifndef QWT_PLUGIN_H
#define QWT_PLUGIN_H
#include <qglobal.h>
#if QT_VERSION >= 0x040000
#ifdef __GNUC__
#error This code is Qt3 only
#endif
This code is Qt3 only
#endif
#include <qwidgetplugin.h>
class QT_WIDGET_PLUGIN_EXPORT QwtPlugin: public QWidgetPlugin
{
public:
QwtPlugin();
QStringList keys() const;
QWidget* create( const QString &classname, QWidget* parent = 0, const char* name = 0 );
QString group( const QString& ) const;
QIconSet iconSet( const QString& ) const;
QString includeFile( const QString& ) const;
QString toolTip( const QString& ) const;
QString whatsThis( const QString& ) const;
bool isContainer( const QString& ) const;
};
#endif

1521
qwt/doc/Doxyfile Normal file

File diff suppressed because it is too large Load Diff

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

BIN
qwt/doc/images/cpuplot.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 36 KiB

BIN
qwt/doc/images/curves.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 20 KiB

BIN
qwt/doc/images/dials1.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 71 KiB

BIN
qwt/doc/images/dials2.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 28 KiB

BIN
qwt/doc/images/graph.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 13 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

BIN
qwt/doc/images/knob.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.3 KiB

BIN
qwt/doc/images/plot.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 30 KiB

BIN
qwt/doc/images/radio.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 19 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 23 KiB

BIN
qwt/doc/images/sinus.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 29 KiB

BIN
qwt/doc/images/sliders.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 46 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 16 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 55 KiB

BIN
qwt/doc/images/sysinfo.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 16 KiB

161
qwt/doc/qwt.dox Normal file
View File

@@ -0,0 +1,161 @@
/* -*- mode: C++ ; c-file-style: "stroustrup" -*- *****************************
* Qwt Widget Library
* Copyright (C) 1997 Josef Wilgen
* Copyright (C) 2002 Uwe Rathmann
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the Qwt License, Version 1.0
*****************************************************************************/
/*
This file contains NO source code, just some documentation for doxygen to
parse.
*/
/*!
\mainpage Qwt - Qt Widgets for Technical Applications
The Qwt library contains GUI Components and utility classes which are primarily
useful for programs with a technical background. Beside a 2D plot widget
it provides scales, sliders, dials, compasses, thermometers, wheels and knobs
to control or display values, arrays, or ranges of type double.
\image html plot.png
\if homepage
\section homepage Project page
The official project page is hosted at
<a href="http://qwt.sourceforge.net">sourceforge</a>
\endif
\section license License
Qwt is distributed under the terms of the \ref qwtlicense.
\section platforms Platforms
Qwt 5.x might be usable in all environments where you find
<a href="http://www.trolltech.com/products/qt">Qt</a>.
It is compatible with Qt 3.3.x and Qt 4.x, but the documentation
is generated for Qt 4.x.\n
\section screenshotsonmainpage Screenshots
- \ref curvescreenshots\n
- \ref scatterscreenshots\n
- \ref spectrogramscreenshots\n
- \ref histogramscreenshots\n
- \ref controlscreenshots\n
\latexonly Screenshots are only available in the HTML docs.\endlatexonly
\section downloads Downloads
Stable releases, prereleases and snapshots are available at the Qwt <a href="http://sourceforge.net/projects/qwt">project page</a>.
For getting a snapshot with all bugfixes for the latest 5.2 release:
\code svn co https://qwt.svn.sourceforge.net/svnroot/qwt/branches/qwt-5.2 \endcode
For getting a development snapshot from the SVN repository:
\code svn co https://qwt.svn.sourceforge.net/svnroot/qwt/trunk/qwt \endcode
Qwt doesn't distribute binary packages, but today all major Linux distributors
offer one. Note, that these packages often don't include the examples.
\section installonmainpage Installation
Have a look at the qwt.pro project file. It is prepared for building
dynamic libraries in Win32 and Unix/X11 environments.
If you don't know what to do with it, read the file \ref qwtinstall and/or
Trolltechs
<a href="http://www.trolltech.com/developer/documentation/index.html">qmake</a> documentation. Once you have build the library you have to install
all files from the lib, include and doc directories.
\section support Support
- Mailing list\n
For all kind of Qwt related questions use the Qwt <a href="http://sourceforge.net/mail/?group_id=13693">mailing list</a>.\n
If you prefer newsgroups use the mail to news gateway of <a href="http://dir.gmane.org/gmane.comp.graphics.qwt.general">Gmane</a>.
- Forum\n
<a href="http://www.qtcentre.org">Qt Centre</a> is a great resource for Qt
related questions. It has a sub forum, that is dedicated to
Qwt related questions.
- Individual support\n
If you are looking for individual support, or need someone who implements
your Qwt component/application contact qwt-support@tigertal.de.
\section relatedprojects Related Projects
<a href="http://qwtpolar.sourceforge.net">QwtPolar</a>, a polar plot widget.\n
<a href="http://qwtplot3d.sourceforge.net">QwtPlot3D</a>, an OpenGL 3D plot widget.\n
<a href="http://soft.proindependent.com/qtiplot.html">QtiPlot</a>,
data analysis and scientific plotting tool, using QwtPlot.
\section languagebindings Language Bindings
<a href="http://pyqwt.sourceforge.net">PyQwt</a>, a set of Qwt Python bindings.\n
<a href="http://rubyforge.org/projects/korundum/">Korundum/QtRuby</a>, including a set of Qwt Ruby bindings.\n
\section donations Donations
Sourceforge offers a <a href="http://sourceforge.net/docman/display_doc.php?docid=20244&group_id=1"> Donation System</a> via PayPal. You can use it, if you like to <a href="http://sourceforge.net/project/project_donations.php?group_id=13693">support</a> the development of Qwt.
\section credits Credits:
\par Authors:
Uwe Rathmann, Josef Wilgen ( <= Qwt 0.2 )
\par Project admin:
Uwe Rathmann \<rathmann@users.sourceforge.net\>
*/
/*!
\page qwtlicense Qwt License, Version 1.0
\include "COPYING"
*/
/*!
\page qwtinstall INSTALL
\include "INSTALL"
*/
/*!
\page curvescreenshots Curve Plots
\image html plot.png
\image html sinus.png
\image html cpuplot.png
\image html graph.png
\image html curves.png
*/
/*!
\page scatterscreenshots Scatter Plot
\image html scatterplot.png
*/
/*!
\page spectrogramscreenshots Spectrogram, Contour Plot
\image html spectrogram1.png
\image html spectrogram2.png
\image html spectrogram3.png
/*!
\page histogramscreenshots Histogram
\image html histogram.png
*/
/*!
\page controlscreenshots Dials, Compasses, Knobs, Wheels, Sliders, Thermos
\image html radio.png
\image html sliders.png
\image html dials1.png
\image html dials2.png
\image html sysinfo.png
*/

350
qwt/examples/bode/bode.cpp Normal file
View File

@@ -0,0 +1,350 @@
#include <qregexp.h>
#include <qapplication.h>
#include <qtoolbar.h>
#include <qtoolbutton.h>
#include <qlabel.h>
#include <qlayout.h>
#include <qstatusbar.h>
#include <qprinter.h>
#include <qpicture.h>
#include <qpainter.h>
#include <qfiledialog.h>
#if QT_VERSION >= 0x040300
#ifdef QT_SVG_LIB
#include <qsvggenerator.h>
#endif
#endif
#if QT_VERSION >= 0x040000
#include <qprintdialog.h>
#include <qfileinfo.h>
#else
#include <qwt_painter.h>
#endif
#include <qwt_counter.h>
#include <qwt_plot_zoomer.h>
#include <qwt_plot_panner.h>
#include <qwt_text.h>
#include <qwt_math.h>
#include "pixmaps.h"
#include "bode_plot.h"
#include "bode.h"
class Zoomer: public QwtPlotZoomer
{
public:
Zoomer(int xAxis, int yAxis, QwtPlotCanvas *canvas):
QwtPlotZoomer(xAxis, yAxis, canvas)
{
setSelectionFlags(QwtPicker::DragSelection | QwtPicker::CornerToCorner);
setTrackerMode(QwtPicker::AlwaysOff);
setRubberBand(QwtPicker::NoRubberBand);
// RightButton: zoom out by 1
// Ctrl+RightButton: zoom out to full size
#if QT_VERSION < 0x040000
setMousePattern(QwtEventPattern::MouseSelect2,
Qt::RightButton, Qt::ControlButton);
#else
setMousePattern(QwtEventPattern::MouseSelect2,
Qt::RightButton, Qt::ControlModifier);
#endif
setMousePattern(QwtEventPattern::MouseSelect3,
Qt::RightButton);
}
};
//-----------------------------------------------------------------
//
// bode.cpp -- A demo program featuring QwtPlot and QwtCounter
//
// This example demonstrates the mapping of different curves
// to different axes in a QwtPlot widget. It also shows how to
// display the cursor position and how to implement zooming.
//
//-----------------------------------------------------------------
MainWin::MainWin(QWidget *parent):
QMainWindow(parent)
{
d_plot = new BodePlot(this);
d_plot->setMargin(5);
#if QT_VERSION >= 0x040000
setContextMenuPolicy(Qt::NoContextMenu);
#endif
d_zoomer[0] = new Zoomer( QwtPlot::xBottom, QwtPlot::yLeft,
d_plot->canvas());
d_zoomer[0]->setRubberBand(QwtPicker::RectRubberBand);
d_zoomer[0]->setRubberBandPen(QColor(Qt::green));
d_zoomer[0]->setTrackerMode(QwtPicker::ActiveOnly);
d_zoomer[0]->setTrackerPen(QColor(Qt::white));
d_zoomer[1] = new Zoomer(QwtPlot::xTop, QwtPlot::yRight,
d_plot->canvas());
d_panner = new QwtPlotPanner(d_plot->canvas());
d_panner->setMouseButton(Qt::MidButton);
d_picker = new QwtPlotPicker(QwtPlot::xBottom, QwtPlot::yLeft,
QwtPicker::PointSelection | QwtPicker::DragSelection,
QwtPlotPicker::CrossRubberBand, QwtPicker::AlwaysOn,
d_plot->canvas());
d_picker->setRubberBandPen(QColor(Qt::green));
d_picker->setRubberBand(QwtPicker::CrossRubberBand);
d_picker->setTrackerPen(QColor(Qt::white));
setCentralWidget(d_plot);
QToolBar *toolBar = new QToolBar(this);
QToolButton *btnZoom = new QToolButton(toolBar);
#if QT_VERSION >= 0x040000
btnZoom->setText("Zoom");
btnZoom->setIcon(QIcon(zoom_xpm));
btnZoom->setCheckable(true);
btnZoom->setToolButtonStyle(Qt::ToolButtonTextUnderIcon);
#else
btnZoom->setTextLabel("Zoom");
btnZoom->setPixmap(zoom_xpm);
btnZoom->setToggleButton(true);
btnZoom->setUsesTextLabel(true);
#endif
QToolButton *btnPrint = new QToolButton(toolBar);
#if QT_VERSION >= 0x040000
btnPrint->setText("Print");
btnPrint->setIcon(QIcon(print_xpm));
btnPrint->setToolButtonStyle(Qt::ToolButtonTextUnderIcon);
#else
btnPrint->setTextLabel("Print");
btnPrint->setPixmap(print_xpm);
btnPrint->setUsesTextLabel(true);
#endif
#if QT_VERSION < 0x040000
QToolButton *btnSVG = new QToolButton(toolBar);
btnSVG->setTextLabel("SVG");
btnSVG->setPixmap(print_xpm);
btnSVG->setUsesTextLabel(true);
#elif QT_VERSION >= 0x040300
#ifdef QT_SVG_LIB
QToolButton *btnSVG = new QToolButton(toolBar);
btnSVG->setText("SVG");
btnSVG->setIcon(QIcon(print_xpm));
btnSVG->setToolButtonStyle(Qt::ToolButtonTextUnderIcon);
#endif
#endif
#if QT_VERSION >= 0x040000
toolBar->addWidget(btnZoom);
toolBar->addWidget(btnPrint);
#if QT_VERSION >= 0x040300
#ifdef QT_SVG_LIB
toolBar->addWidget(btnSVG);
#endif
#endif
#endif
toolBar->addSeparator();
QWidget *hBox = new QWidget(toolBar);
QHBoxLayout *layout = new QHBoxLayout(hBox);
layout->setSpacing(0);
layout->addWidget(new QWidget(hBox), 10); // spacer
layout->addWidget(new QLabel("Damping Factor", hBox), 0);
layout->addSpacing(10);
QwtCounter *cntDamp = new QwtCounter(hBox);
cntDamp->setRange(0.0, 5.0, 0.01);
cntDamp->setValue(0.0);
layout->addWidget(cntDamp, 0);
#if QT_VERSION >= 0x040000
(void)toolBar->addWidget(hBox);
#else
toolBar->setStretchableWidget(hBox);
#endif
addToolBar(toolBar);
#ifndef QT_NO_STATUSBAR
(void)statusBar();
#endif
enableZoomMode(false);
showInfo();
connect(cntDamp, SIGNAL(valueChanged(double)),
d_plot, SLOT(setDamp(double)));
connect(btnPrint, SIGNAL(clicked()), SLOT(print()));
#if QT_VERSION < 0x040000
connect(btnSVG, SIGNAL(clicked()), SLOT(exportSVG()));
#elif QT_VERSION >= 0x040300
#ifdef QT_SVG_LIB
connect(btnSVG, SIGNAL(clicked()), SLOT(exportSVG()));
#endif
#endif
connect(btnZoom, SIGNAL(toggled(bool)), SLOT(enableZoomMode(bool)));
connect(d_picker, SIGNAL(moved(const QPoint &)),
SLOT(moved(const QPoint &)));
connect(d_picker, SIGNAL(selected(const QwtPolygon &)),
SLOT(selected(const QwtPolygon &)));
}
void MainWin::print()
{
#if 1
QPrinter printer;
#else
QPrinter printer(QPrinter::HighResolution);
#if QT_VERSION < 0x040000
printer.setOutputToFile(true);
printer.setOutputFileName("/tmp/bode.ps");
printer.setColorMode(QPrinter::Color);
#else
printer.setOutputFileName("/tmp/bode.pdf");
#endif
#endif
QString docName = d_plot->title().text();
if ( !docName.isEmpty() )
{
docName.replace (QRegExp (QString::fromLatin1 ("\n")), tr (" -- "));
printer.setDocName (docName);
}
printer.setCreator("Bode example");
printer.setOrientation(QPrinter::Landscape);
#if QT_VERSION >= 0x040000
QPrintDialog dialog(&printer);
if ( dialog.exec() )
{
#else
if (printer.setup())
{
#endif
QwtPlotPrintFilter filter;
if ( printer.colorMode() == QPrinter::GrayScale )
{
int options = QwtPlotPrintFilter::PrintAll;
options &= ~QwtPlotPrintFilter::PrintBackground;
options |= QwtPlotPrintFilter::PrintFrameWithScales;
filter.setOptions(options);
}
d_plot->print(printer, filter);
}
}
void MainWin::exportSVG()
{
QString fileName = "bode.svg";
#if QT_VERSION < 0x040000
#ifndef QT_NO_FILEDIALOG
fileName = QFileDialog::getSaveFileName(
"bode.svg", "SVG Documents (*.svg)", this);
#endif
if ( !fileName.isEmpty() )
{
// enable workaround for Qt3 misalignments
QwtPainter::setSVGMode(true);
QPicture picture;
QPainter p(&picture);
d_plot->print(&p, QRect(0, 0, 800, 600));
p.end();
picture.save(fileName, "svg");
}
#elif QT_VERSION >= 0x040300
#ifdef QT_SVG_LIB
#ifndef QT_NO_FILEDIALOG
fileName = QFileDialog::getSaveFileName(
this, "Export File Name", QString(),
"SVG Documents (*.svg)");
#endif
if ( !fileName.isEmpty() )
{
QSvgGenerator generator;
generator.setFileName(fileName);
generator.setSize(QSize(800, 600));
d_plot->print(generator);
}
#endif
#endif
}
void MainWin::enableZoomMode(bool on)
{
d_panner->setEnabled(on);
d_zoomer[0]->setEnabled(on);
d_zoomer[0]->zoom(0);
d_zoomer[1]->setEnabled(on);
d_zoomer[1]->zoom(0);
d_picker->setEnabled(!on);
showInfo();
}
void MainWin::showInfo(QString text)
{
if ( text == QString::null )
{
if ( d_picker->rubberBand() )
text = "Cursor Pos: Press left mouse button in plot region";
else
text = "Zoom: Press mouse button and drag";
}
#ifndef QT_NO_STATUSBAR
#if QT_VERSION >= 0x040000
statusBar()->showMessage(text);
#else
statusBar()->message(text);
#endif
#endif
}
void MainWin::moved(const QPoint &pos)
{
QString info;
info.sprintf("Freq=%g, Ampl=%g, Phase=%g",
d_plot->invTransform(QwtPlot::xBottom, pos.x()),
d_plot->invTransform(QwtPlot::yLeft, pos.y()),
d_plot->invTransform(QwtPlot::yRight, pos.y())
);
showInfo(info);
}
void MainWin::selected(const QwtPolygon &)
{
showInfo();
}
int main (int argc, char **argv)
{
QApplication a(argc, argv);
MainWin w;
#if QT_VERSION < 0x040000
a.setMainWidget(&w);
#endif
w.resize(540,400);
w.show();
int rv = a.exec();
return rv;
}

32
qwt/examples/bode/bode.h Normal file
View File

@@ -0,0 +1,32 @@
#include <qmainwindow.h>
#include <qwt_polygon.h>
class QwtPlotZoomer;
class QwtPlotPicker;
class QwtPlotPanner;
class BodePlot;
class MainWin : public QMainWindow
{
Q_OBJECT
public:
MainWin(QWidget *parent = 0);
private slots:
void moved(const QPoint &);
void selected(const QwtPolygon &);
void print();
void exportSVG();
void enableZoomMode(bool);
private:
void showInfo(QString text = QString::null);
BodePlot *d_plot;
QwtPlotZoomer *d_zoomer[2];
QwtPlotPicker *d_picker;
QwtPlotPanner *d_panner;
};

View File

@@ -0,0 +1,23 @@
# -*- mode: sh -*- ################################################
# Qwt Widget Library
# Copyright (C) 1997 Josef Wilgen
# Copyright (C) 2002 Uwe Rathmann
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the Qwt License, Version 1.0
###################################################################
include( ../examples.pri )
TARGET = bode
QT += svg
HEADERS = \
bode.h \
bode_plot.h \
cplx.h \
pixmaps.h
SOURCES = \
bode.cpp \
bode_plot.cpp

View File

@@ -0,0 +1,181 @@
#include <qwt_math.h>
#include <qwt_scale_engine.h>
#include <qwt_symbol.h>
#include <qwt_plot_grid.h>
#include <qwt_plot_marker.h>
#include <qwt_plot_curve.h>
#include <qwt_legend.h>
#include <qwt_text.h>
#include "cplx.h"
#include "bode_plot.h"
static void logSpace(double *array, int size, double xmin, double xmax)
{
if ((xmin <= 0.0) || (xmax <= 0.0) || (size <= 0))
return;
const int imax = size -1;
array[0] = xmin;
array[imax] = xmax;
const double lxmin = log(xmin);
const double lxmax = log(xmax);
const double lstep = (lxmax - lxmin) / double(imax);
for (int i = 1; i < imax; i++)
array[i] = exp(lxmin + double(i) * lstep);
}
BodePlot::BodePlot(QWidget *parent):
QwtPlot(parent)
{
setAutoReplot(false);
setTitle("Frequency Response of a Second-Order System");
setCanvasBackground(QColor(Qt::darkBlue));
// legend
QwtLegend *legend = new QwtLegend;
legend->setFrameStyle(QFrame::Box|QFrame::Sunken);
insertLegend(legend, QwtPlot::BottomLegend);
// grid
QwtPlotGrid *grid = new QwtPlotGrid;
grid->enableXMin(true);
grid->setMajPen(QPen(Qt::white, 0, Qt::DotLine));
grid->setMinPen(QPen(Qt::gray, 0 , Qt::DotLine));
grid->attach(this);
// axes
enableAxis(QwtPlot::yRight);
setAxisTitle(QwtPlot::xBottom, "Normalized Frequency");
setAxisTitle(QwtPlot::yLeft, "Amplitude [dB]");
setAxisTitle(QwtPlot::yRight, "Phase [deg]");
setAxisMaxMajor(QwtPlot::xBottom, 6);
setAxisMaxMinor(QwtPlot::xBottom, 10);
setAxisScaleEngine(QwtPlot::xBottom, new QwtLog10ScaleEngine);
// curves
d_crv1 = new QwtPlotCurve("Amplitude");
#if QT_VERSION >= 0x040000
d_crv1->setRenderHint(QwtPlotItem::RenderAntialiased);
#endif
d_crv1->setPen(QPen(Qt::yellow));
d_crv1->setYAxis(QwtPlot::yLeft);
d_crv1->attach(this);
d_crv2 = new QwtPlotCurve("Phase");
#if QT_VERSION >= 0x040000
d_crv2->setRenderHint(QwtPlotItem::RenderAntialiased);
#endif
d_crv2->setPen(QPen(Qt::cyan));
d_crv2->setYAxis(QwtPlot::yRight);
d_crv2->attach(this);
// marker
d_mrk1 = new QwtPlotMarker();
d_mrk1->setValue(0.0, 0.0);
d_mrk1->setLineStyle(QwtPlotMarker::VLine);
d_mrk1->setLabelAlignment(Qt::AlignRight | Qt::AlignBottom);
d_mrk1->setLinePen(QPen(Qt::green, 0, Qt::DashDotLine));
d_mrk1->attach(this);
d_mrk2 = new QwtPlotMarker();
d_mrk2->setLineStyle(QwtPlotMarker::HLine);
d_mrk2->setLabelAlignment(Qt::AlignRight | Qt::AlignBottom);
d_mrk2->setLinePen(QPen(QColor(200,150,0), 0, Qt::DashDotLine));
d_mrk2->setSymbol( QwtSymbol(QwtSymbol::Diamond,
QColor(Qt::yellow), QColor(Qt::green), QSize(7,7)));
d_mrk2->attach(this);
setDamp(0.0);
setAutoReplot(true);
}
void BodePlot::showData(double *frequency, double *amplitude,
double *phase, int count)
{
d_crv1->setData(frequency, amplitude, count);
d_crv2->setData(frequency, phase, count);
}
void BodePlot::showPeak(double freq, double amplitude)
{
QString label;
label.sprintf("Peak: %.3g dB", amplitude);
QwtText text(label);
text.setFont(QFont("Helvetica", 10, QFont::Bold));
text.setColor(QColor(200,150,0));
d_mrk2->setValue(freq, amplitude);
d_mrk2->setLabel(text);
}
void BodePlot::show3dB(double freq)
{
QString label;
label.sprintf("-3 dB at f = %.3g", freq);
QwtText text(label);
text.setFont(QFont("Helvetica", 10, QFont::Bold));
text.setColor(Qt::green);
d_mrk1->setValue(freq, 0.0);
d_mrk1->setLabel(text);
}
//
// re-calculate frequency response
//
void BodePlot::setDamp(double damping)
{
const bool doReplot = autoReplot();
setAutoReplot(false);
const int ArraySize = 200;
double frequency[ArraySize];
double amplitude[ArraySize];
double phase[ArraySize];
// build frequency vector with logarithmic division
logSpace(frequency, ArraySize, 0.01, 100);
int i3 = 1;
double fmax = 1;
double amax = -1000.0;
for (int i = 0; i < ArraySize; i++)
{
double f = frequency[i];
cplx g = cplx(1.0) / cplx(1.0 - f * f, 2.0 * damping * f);
amplitude[i] = 20.0 * log10(sqrt( g.real()*g.real() + g.imag()*g.imag()));
phase[i] = atan2(g.imag(), g.real()) * (180.0 / M_PI);
if ((i3 <= 1) && (amplitude[i] < -3.0))
i3 = i;
if (amplitude[i] > amax)
{
amax = amplitude[i];
fmax = frequency[i];
}
}
double f3 = frequency[i3] -
(frequency[i3] - frequency[i3 - 1])
/ (amplitude[i3] - amplitude[i3 -1]) * (amplitude[i3] + 3);
showPeak(fmax, amax);
show3dB(f3);
showData(frequency, amplitude, phase, ArraySize);
setAutoReplot(doReplot);
replot();
}

View File

@@ -0,0 +1,25 @@
#include <qwt_plot.h>
class QwtPlotCurve;
class QwtPlotMarker;
class BodePlot: public QwtPlot
{
Q_OBJECT
public:
BodePlot(QWidget *parent);
public slots:
void setDamp(double damping);
private:
void showData(double *frequency, double *amplitude,
double *phase, int count);
void showPeak(double freq, double amplitude);
void show3dB(double freq);
QwtPlotCurve *d_crv1;
QwtPlotCurve *d_crv2;
QwtPlotMarker *d_mrk1;
QwtPlotMarker *d_mrk2;
};

62
qwt/examples/bode/cplx.h Normal file
View File

@@ -0,0 +1,62 @@
#ifndef BODE_CPLX_H
#define BODE_CPLX_H
#include <math.h>
class cplx {
private:
double re,im;
public:
double real() {return re;}
double imag() {return im;}
cplx() {
re = 0.0;
im = -0.0;
}
cplx& operator= (cplx a) {
re = a.re;
im = a.im;
return *this;
}
cplx(double r, double i = 0.0) {
re = r;
im = i;
}
friend cplx operator * (cplx x1, cplx x2);
friend cplx operator + (cplx x1, cplx x2);
friend cplx operator - (cplx x1, cplx x2);
friend cplx operator / (cplx x1, cplx x2);
};
inline cplx operator+(cplx x1, cplx x2)
{
return cplx(x1.re + x2.re, x1.im + x2.im);
}
inline cplx operator-(cplx x1, cplx x2)
{
return cplx(x1.re - x2.re, x1.im - x2.im);
}
inline cplx operator*(cplx x1, cplx x2)
{
return cplx(x1.re * x2.re - x1.im * x2.im,
x1.re * x2.im + x2.re * x1.im);
}
inline cplx operator/(cplx x1, cplx x2)
{
double denom = x2.re * x2.re + x2.im * x2.im;
return cplx( (x1.re * x2.re + x1.im * x2.im) /denom,
(x1.im * x2.re - x2.im * x1.re) / denom);
}
#endif

View File

@@ -0,0 +1,95 @@
#ifndef PIXMAPS_H
#define PIXMAPS_H
static const char *print_xpm[]={
"32 32 12 1",
"a c #ffffff",
"h c #ffff00",
"c c #ffffff",
"f c #dcdcdc",
"b c #c0c0c0",
"j c #a0a0a4",
"e c #808080",
"g c #808000",
"d c #585858",
"i c #00ff00",
"# c #000000",
". c None",
"................................",
"................................",
"...........###..................",
"..........#abb###...............",
".........#aabbbbb###............",
".........#ddaaabbbbb###.........",
"........#ddddddaaabbbbb###......",
".......#deffddddddaaabbbbb###...",
"......#deaaabbbddddddaaabbbbb###",
".....#deaaaaaaabbbddddddaaabbbb#",
"....#deaaabbbaaaa#ddedddfggaaad#",
"...#deaaaaaaaaaa#ddeeeeafgggfdd#",
"..#deaaabbbaaaa#ddeeeeabbbbgfdd#",
".#deeefaaaaaaa#ddeeeeabbhhbbadd#",
"#aabbbeeefaaa#ddeeeeabbbbbbaddd#",
"#bbaaabbbeee#ddeeeeabbiibbadddd#",
"#bbbbbaaabbbeeeeeeabbbbbbaddddd#",
"#bjbbbbbbaaabbbbeabbbbbbadddddd#",
"#bjjjjbbbbbbaaaeabbbbbbaddddddd#",
"#bjaaajjjbbbbbbaaabbbbadddddddd#",
"#bbbbbaaajjjbbbbbbaaaaddddddddd#",
"#bjbbbbbbaaajjjbbbbbbddddddddd#.",
"#bjjjjbbbbbbaaajjjbbbdddddddd#..",
"#bjaaajjjbbbbbbjaajjbddddddd#...",
"#bbbbbaaajjjbbbjbbaabdddddd#....",
"###bbbbbbaaajjjjbbbbbddddd#.....",
"...###bbbbbbaaajbbbbbdddd#......",
"......###bbbbbbjbbbbbddd#.......",
".........###bbbbbbbbbdd#........",
"............###bbbbbbd#.........",
"...............###bbb#..........",
"..................###..........."};
static const char *zoom_xpm[]={
"32 32 8 1",
"# c #000000",
"b c #c0c0c0",
"a c #ffffff",
"e c #585858",
"d c #a0a0a4",
"c c #0000ff",
"f c #00ffff",
". c None",
"..######################........",
".#a#baaaaaaaaaaaaaaaaaa#........",
"#aa#baaaaaaaaaaaaaccaca#........",
"####baaaaaaaaaaaaaaaaca####.....",
"#bbbbaaaaaaaaaaaacccaaa#da#.....",
"#aaaaaaaaaaaaaaaacccaca#da#.....",
"#aaaaaaaaaaaaaaaaaccaca#da#.....",
"#aaaaaaaaaabe###ebaaaaa#da#.....",
"#aaaaaaaaa#########aaaa#da#.....",
"#aaaaaaaa###dbbbb###aaa#da#.....",
"#aaaaaaa###aaaaffb###aa#da#.....",
"#aaaaaab##aaccaaafb##ba#da#.....",
"#aaaaaae#daaccaccaad#ea#da#.....",
"#aaaaaa##aaaaaaccaab##a#da#.....",
"#aaaaaa##aacccaaaaab##a#da#.....",
"#aaaaaa##aaccccaccab##a#da#.....",
"#aaaaaae#daccccaccad#ea#da#.....",
"#aaaaaab##aacccaaaa##da#da#.....",
"#aaccacd###aaaaaaa###da#da#.....",
"#aaaaacad###daaad#####a#da#.....",
"#acccaaaad##########da##da#.....",
"#acccacaaadde###edd#eda#da#.....",
"#aaccacaaaabdddddbdd#eda#a#.....",
"#aaaaaaaaaaaaaaaaaadd#eda##.....",
"#aaaaaaaaaaaaaaaaaaadd#eda#.....",
"#aaaaaaaccacaaaaaaaaadd#eda#....",
"#aaaaaaaaaacaaaaaaaaaad##eda#...",
"#aaaaaacccaaaaaaaaaaaaa#d#eda#..",
"########################dd#eda#.",
"...#dddddddddddddddddddddd##eda#",
"...#aaaaaaaaaaaaaaaaaaaaaa#.####",
"...########################..##."};
#endif

View File

@@ -0,0 +1,57 @@
#include <qpainter.h>
#include <qwt_scale_map.h>
#include <qwt_plot_curve.h>
#include "cpuplot.h"
#include "cpupiemarker.h"
CpuPieMarker::CpuPieMarker()
{
setZ(1000);
#if QT_VERSION >= 0x040000
setRenderHint(QwtPlotItem::RenderAntialiased, true);
#endif
}
int CpuPieMarker::rtti() const
{
return QwtPlotItem::Rtti_PlotUserItem;
}
void CpuPieMarker::draw(QPainter *p,
const QwtScaleMap &, const QwtScaleMap &,
const QRect &rect) const
{
const CpuPlot *cpuPlot = (CpuPlot *)plot();
const QwtScaleMap yMap = cpuPlot->canvasMap(QwtPlot::yLeft);
const int margin = 5;
QRect pieRect;
pieRect.setX(rect.x() + margin);
pieRect.setY(rect.y() + margin);
pieRect.setHeight(yMap.transform(80.0));
pieRect.setWidth(pieRect.height());
const int dataType[] = { CpuPlot::User, CpuPlot::System, CpuPlot::Idle };
int angle = (int)(5760 * 0.75);
for ( unsigned int i = 0;
i < sizeof(dataType) / sizeof(dataType[0]); i++ )
{
const QwtPlotCurve *curve = cpuPlot->cpuCurve(dataType[i]);
if ( curve->dataSize() > 0 )
{
const int value = (int)(5760 * curve->y(0) / 100.0);
p->save();
p->setBrush(QBrush(curve->pen().color(), Qt::SolidPattern));
if ( value != 0 )
p->drawPie(pieRect, -angle, -value);
p->restore();
angle += value;
}
}
}

View File

@@ -0,0 +1,18 @@
//-----------------------------------------------------------------
// This class shows how to extend QwtPlotItems. It displays a
// pie chart of user/total/idle cpu usage in percent.
//-----------------------------------------------------------------
#include <qwt_plot_item.h>
class CpuPieMarker: public QwtPlotItem
{
public:
CpuPieMarker();
virtual int rtti() const;
virtual void draw(QPainter *p,
const QwtScaleMap &, const QwtScaleMap &,
const QRect &rect) const;
};

View File

@@ -0,0 +1,244 @@
#include <qapplication.h>
#include <qlayout.h>
#include <qlabel.h>
#include <qpainter.h>
#include <qwt_plot_layout.h>
#include <qwt_plot_curve.h>
#include <qwt_scale_draw.h>
#include <qwt_scale_widget.h>
#include <qwt_legend.h>
#include <qwt_legend_item.h>
#include "cpupiemarker.h"
#include "cpuplot.h"
class TimeScaleDraw: public QwtScaleDraw
{
public:
TimeScaleDraw(const QTime &base):
baseTime(base)
{
}
virtual QwtText label(double v) const
{
QTime upTime = baseTime.addSecs((int)v);
return upTime.toString();
}
private:
QTime baseTime;
};
class Background: public QwtPlotItem
{
public:
Background()
{
setZ(0.0);
}
virtual int rtti() const
{
return QwtPlotItem::Rtti_PlotUserItem;
}
virtual void draw(QPainter *painter,
const QwtScaleMap &, const QwtScaleMap &yMap,
const QRect &rect) const
{
QColor c(Qt::white);
QRect r = rect;
for ( int i = 100; i > 0; i -= 10 )
{
r.setBottom(yMap.transform(i - 10));
r.setTop(yMap.transform(i));
painter->fillRect(r, c);
c = c.dark(110);
}
}
};
class CpuCurve: public QwtPlotCurve
{
public:
CpuCurve(const QString &title):
QwtPlotCurve(title)
{
#if QT_VERSION >= 0x040000
setRenderHint(QwtPlotItem::RenderAntialiased);
#endif
}
void setColor(const QColor &color)
{
#if QT_VERSION >= 0x040000
QColor c = color;
c.setAlpha(150);
setPen(c);
setBrush(c);
#else
setPen(color);
setBrush(QBrush(color, Qt::Dense4Pattern));
#endif
}
};
CpuPlot::CpuPlot(QWidget *parent):
QwtPlot(parent),
dataCount(0)
{
setAutoReplot(false);
plotLayout()->setAlignCanvasToScales(true);
QwtLegend *legend = new QwtLegend;
legend->setItemMode(QwtLegend::CheckableItem);
insertLegend(legend, QwtPlot::RightLegend);
setAxisTitle(QwtPlot::xBottom, " System Uptime [h:m:s]");
setAxisScaleDraw(QwtPlot::xBottom,
new TimeScaleDraw(cpuStat.upTime()));
setAxisScale(QwtPlot::xBottom, 0, HISTORY);
setAxisLabelRotation(QwtPlot::xBottom, -50.0);
setAxisLabelAlignment(QwtPlot::xBottom, Qt::AlignLeft | Qt::AlignBottom);
/*
In situations, when there is a label at the most right position of the
scale, additional space is needed to display the overlapping part
of the label would be taken by reducing the width of scale and canvas.
To avoid this "jumping canvas" effect, we add a permanent margin.
We don't need to do the same for the left border, because there
is enough space for the overlapping label below the left scale.
*/
QwtScaleWidget *scaleWidget = axisWidget(QwtPlot::xBottom);
const int fmh = QFontMetrics(scaleWidget->font()).height();
scaleWidget->setMinBorderDist(0, fmh / 2);
setAxisTitle(QwtPlot::yLeft, "Cpu Usage [%]");
setAxisScale(QwtPlot::yLeft, 0, 100);
Background *bg = new Background();
bg->attach(this);
CpuPieMarker *pie = new CpuPieMarker();
pie->attach(this);
CpuCurve *curve;
curve = new CpuCurve("System");
curve->setColor(Qt::red);
curve->attach(this);
data[System].curve = curve;
curve = new CpuCurve("User");
curve->setColor(Qt::blue);
curve->setZ(curve->z() - 1);
curve->attach(this);
data[User].curve = curve;
curve = new CpuCurve("Total");
curve->setColor(Qt::black);
curve->setZ(curve->z() - 2);
curve->attach(this);
data[Total].curve = curve;
curve = new CpuCurve("Idle");
curve->setColor(Qt::darkCyan);
curve->setZ(curve->z() - 3);
curve->attach(this);
data[Idle].curve = curve;
showCurve(data[System].curve, true);
showCurve(data[User].curve, true);
showCurve(data[Total].curve, false);
showCurve(data[Idle].curve, false);
for ( int i = 0; i < HISTORY; i++ )
timeData[HISTORY - 1 - i] = i;
(void)startTimer(1000); // 1 second
connect(this, SIGNAL(legendChecked(QwtPlotItem *, bool)),
SLOT(showCurve(QwtPlotItem *, bool)));
}
void CpuPlot::timerEvent(QTimerEvent *)
{
for ( int i = dataCount; i > 0; i-- )
{
for ( int c = 0; c < NCpuData; c++ )
{
if ( i < HISTORY )
data[c].data[i] = data[c].data[i-1];
}
}
cpuStat.statistic(data[User].data[0], data[System].data[0]);
data[Total].data[0] = data[User].data[0] +
data[System].data[0];
data[Idle].data[0] = 100.0 - data[Total].data[0];
if ( dataCount < HISTORY )
dataCount++;
for ( int j = 0; j < HISTORY; j++ )
timeData[j]++;
setAxisScale(QwtPlot::xBottom,
timeData[HISTORY - 1], timeData[0]);
for ( int c = 0; c < NCpuData; c++ )
{
data[c].curve->setRawData(
timeData, data[c].data, dataCount);
}
replot();
}
void CpuPlot::showCurve(QwtPlotItem *item, bool on)
{
item->setVisible(on);
QWidget *w = legend()->find(item);
if ( w && w->inherits("QwtLegendItem") )
((QwtLegendItem *)w)->setChecked(on);
replot();
}
int main(int argc, char **argv)
{
QApplication a(argc, argv);
QWidget vBox;
#if QT_VERSION >= 0x040000
vBox.setWindowTitle("Cpu Plot");
#else
vBox.setCaption("Cpu Plot");
#endif
CpuPlot *plot = new CpuPlot(&vBox);
plot->setTitle("History");
plot->setMargin(5);
QString info("Press the legend to en/disable a curve");
QLabel *label = new QLabel(info, &vBox);
QVBoxLayout *layout = new QVBoxLayout(&vBox);
layout->addWidget(plot);
layout->addWidget(label);
#if QT_VERSION < 0x040000
a.setMainWidget(&vBox);
#endif
vBox.resize(600,400);
vBox.show();
return a.exec();
}

View File

@@ -0,0 +1,42 @@
#include <qwt_plot.h>
#include "cpustat.h"
#define HISTORY 60 // seconds
class QwtPlotCurve;
class CpuPlot : public QwtPlot
{
Q_OBJECT
public:
enum CpuData
{
User,
System,
Total,
Idle,
NCpuData
};
CpuPlot(QWidget * = 0);
const QwtPlotCurve *cpuCurve(int id) const
{ return data[id].curve; }
protected:
void timerEvent(QTimerEvent *e);
private slots:
void showCurve(QwtPlotItem *, bool on);
private:
struct
{
QwtPlotCurve *curve;
double data[HISTORY];
} data[NCpuData];
double timeData[HISTORY];
int dataCount;
CpuStat cpuStat;
};

View File

@@ -0,0 +1,22 @@
# -*- mode: sh -*- ################################################
# Qwt Widget Library
# Copyright (C) 1997 Josef Wilgen
# Copyright (C) 2002 Uwe Rathmann
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the Qwt License, Version 1.0
###################################################################
include( ../examples.pri )
TARGET = cpuplot
HEADERS = \
cpuplot.h \
cpustat.h \
cpupiemarker.h
SOURCES = \
cpuplot.cpp \
cpustat.cpp \
cpupiemarker.cpp

View File

@@ -0,0 +1,235 @@
#include <qstringlist.h>
#include <qfile.h>
#include <qtextstream.h>
#include "cpustat.h"
CpuStat::CpuStat()
{
lookUp(procValues);
}
QTime CpuStat::upTime() const
{
QTime t;
for ( int i = 0; i < NValues; i++ )
t = t.addSecs(int(procValues[i] / 100));
return t;
}
void CpuStat::statistic(double &user, double &system)
{
double values[NValues];
lookUp(values);
double userDelta = values[User] + values[Nice]
- procValues[User] - procValues[Nice];
double systemDelta = values[System] - procValues[System];
double totalDelta = 0;
for ( int i = 0; i < NValues; i++ )
totalDelta += values[i] - procValues[i];
user = userDelta / totalDelta * 100.0;
system = systemDelta / totalDelta * 100.0;
for ( int j = 0; j < NValues; j++ )
procValues[j] = values[j];
}
void CpuStat::lookUp(double values[NValues]) const
{
QFile file("/proc/stat");
#if QT_VERSION >= 0x040000
if ( !file.open(QIODevice::ReadOnly) )
#else
if ( !file.open(IO_ReadOnly) )
#endif
{
static double dummyValues[][NValues] =
{
{ 103726, 0, 23484, 819556 },
{ 103783, 0, 23489, 819604 },
{ 103798, 0, 23490, 819688 },
{ 103820, 0, 23490, 819766 },
{ 103840, 0, 23493, 819843 },
{ 103875, 0, 23499, 819902 },
{ 103917, 0, 23504, 819955 },
{ 103950, 0, 23508, 820018 },
{ 103987, 0, 23510, 820079 },
{ 104020, 0, 23513, 820143 },
{ 104058, 0, 23514, 820204 },
{ 104099, 0, 23520, 820257 },
{ 104121, 0, 23525, 820330 },
{ 104159, 0, 23530, 820387 },
{ 104176, 0, 23534, 820466 },
{ 104215, 0, 23538, 820523 },
{ 104245, 0, 23541, 820590 },
{ 104267, 0, 23545, 820664 },
{ 104311, 0, 23555, 820710 },
{ 104355, 0, 23565, 820756 },
{ 104367, 0, 23567, 820842 },
{ 104383, 0, 23572, 820921 },
{ 104396, 0, 23577, 821003 },
{ 104413, 0, 23579, 821084 },
{ 104446, 0, 23588, 821142 },
{ 104521, 0, 23594, 821161 },
{ 104611, 0, 23604, 821161 },
{ 104708, 0, 23607, 821161 },
{ 104804, 0, 23611, 821161 },
{ 104895, 0, 23620, 821161 },
{ 104993, 0, 23622, 821161 },
{ 105089, 0, 23626, 821161 },
{ 105185, 0, 23630, 821161 },
{ 105281, 0, 23634, 821161 },
{ 105379, 0, 23636, 821161 },
{ 105472, 0, 23643, 821161 },
{ 105569, 0, 23646, 821161 },
{ 105666, 0, 23649, 821161 },
{ 105763, 0, 23652, 821161 },
{ 105828, 0, 23661, 821187 },
{ 105904, 0, 23666, 821206 },
{ 105999, 0, 23671, 821206 },
{ 106094, 0, 23676, 821206 },
{ 106184, 0, 23686, 821206 },
{ 106273, 0, 23692, 821211 },
{ 106306, 0, 23700, 821270 },
{ 106341, 0, 23703, 821332 },
{ 106392, 0, 23709, 821375 },
{ 106423, 0, 23715, 821438 },
{ 106472, 0, 23721, 821483 },
{ 106531, 0, 23727, 821517 },
{ 106562, 0, 23732, 821582 },
{ 106597, 0, 23736, 821643 },
{ 106633, 0, 23737, 821706 },
{ 106666, 0, 23742, 821768 },
{ 106697, 0, 23744, 821835 },
{ 106730, 0, 23748, 821898 },
{ 106765, 0, 23751, 821960 },
{ 106799, 0, 23754, 822023 },
{ 106831, 0, 23758, 822087 },
{ 106862, 0, 23761, 822153 },
{ 106899, 0, 23763, 822214 },
{ 106932, 0, 23766, 822278 },
{ 106965, 0, 23768, 822343 },
{ 107009, 0, 23771, 822396 },
{ 107040, 0, 23775, 822461 },
{ 107092, 0, 23780, 822504 },
{ 107143, 0, 23787, 822546 },
{ 107200, 0, 23795, 822581 },
{ 107250, 0, 23803, 822623 },
{ 107277, 0, 23810, 822689 },
{ 107286, 0, 23810, 822780 },
{ 107313, 0, 23817, 822846 },
{ 107325, 0, 23818, 822933 },
{ 107332, 0, 23818, 823026 },
{ 107344, 0, 23821, 823111 },
{ 107357, 0, 23821, 823198 },
{ 107368, 0, 23823, 823284 },
{ 107375, 0, 23824, 823377 },
{ 107386, 0, 23825, 823465 },
{ 107396, 0, 23826, 823554 },
{ 107422, 0, 23830, 823624 },
{ 107434, 0, 23831, 823711 },
{ 107456, 0, 23835, 823785 },
{ 107468, 0, 23838, 823870 },
{ 107487, 0, 23840, 823949 },
{ 107515, 0, 23843, 824018 },
{ 107528, 0, 23846, 824102 },
{ 107535, 0, 23851, 824190 },
{ 107548, 0, 23853, 824275 },
{ 107562, 0, 23857, 824357 },
{ 107656, 0, 23863, 824357 },
{ 107751, 0, 23868, 824357 },
{ 107849, 0, 23870, 824357 },
{ 107944, 0, 23875, 824357 },
{ 108043, 0, 23876, 824357 },
{ 108137, 0, 23882, 824357 },
{ 108230, 0, 23889, 824357 },
{ 108317, 0, 23902, 824357 },
{ 108412, 0, 23907, 824357 },
{ 108511, 0, 23908, 824357 },
{ 108608, 0, 23911, 824357 },
{ 108704, 0, 23915, 824357 },
{ 108801, 0, 23918, 824357 },
{ 108891, 0, 23928, 824357 },
{ 108987, 0, 23932, 824357 },
{ 109072, 0, 23943, 824361 },
{ 109079, 0, 23943, 824454 },
{ 109086, 0, 23944, 824546 },
{ 109098, 0, 23950, 824628 },
{ 109108, 0, 23955, 824713 },
{ 109115, 0, 23957, 824804 },
{ 109122, 0, 23958, 824896 },
{ 109132, 0, 23959, 824985 },
{ 109142, 0, 23961, 825073 },
{ 109146, 0, 23962, 825168 },
{ 109153, 0, 23964, 825259 },
{ 109162, 0, 23966, 825348 },
{ 109168, 0, 23969, 825439 },
{ 109176, 0, 23971, 825529 },
{ 109185, 0, 23974, 825617 },
{ 109193, 0, 23977, 825706 },
{ 109198, 0, 23978, 825800 },
{ 109206, 0, 23978, 825892 },
{ 109212, 0, 23981, 825983 },
{ 109219, 0, 23981, 826076 },
{ 109225, 0, 23981, 826170 },
{ 109232, 0, 23984, 826260 },
{ 109242, 0, 23984, 826350 },
{ 109255, 0, 23986, 826435 },
{ 109268, 0, 23987, 826521 },
{ 109283, 0, 23990, 826603 },
{ 109288, 0, 23991, 826697 },
{ 109295, 0, 23993, 826788 },
{ 109308, 0, 23994, 826874 },
{ 109322, 0, 24009, 826945 },
{ 109328, 0, 24011, 827037 },
{ 109338, 0, 24012, 827126 },
{ 109347, 0, 24012, 827217 },
{ 109354, 0, 24017, 827305 },
{ 109367, 0, 24017, 827392 },
{ 109371, 0, 24019, 827486 },
};
static int counter = 0;
for ( int i = 0; i < NValues; i++ )
values[i] = dummyValues[counter][i];
counter = (counter + 1)
% (sizeof(dummyValues) / sizeof(dummyValues[0]));
}
else
{
QTextStream textStream(&file);
do {
QString line = textStream.readLine();
#if QT_VERSION < 0x040000
line = line.stripWhiteSpace();
#else
line = line.trimmed();
#endif
if ( line.startsWith("cpu ") )
{
const QStringList valueList =
#if QT_VERSION < 0x040000
QStringList::split(" ", line);
#else
line.split(" ", QString::SkipEmptyParts);
#endif
if ( valueList.count() >= 5 )
{
for ( int i = 0; i < NValues; i++ )
values[i] = valueList[i+1].toDouble();
}
break;
}
}
#if QT_VERSION < 0x040000
while(!textStream.eof());
#else
while(!textStream.atEnd());
#endif
}
}

View File

@@ -0,0 +1,23 @@
#include <qdatetime.h>
class CpuStat
{
public:
CpuStat();
void statistic(double &user, double &system);
QTime upTime() const;
enum Value
{
User,
Nice,
System,
Idle,
NValues
};
private:
void lookUp(double[NValues]) const;
double procValues[NValues];
};

View File

@@ -0,0 +1,230 @@
#include <qapplication.h>
#include <qframe.h>
#include <qwt_scale_map.h>
#include <qwt_plot_curve.h>
#include <qwt_symbol.h>
#include <qcolor.h>
#include <qpainter.h>
#include <math.h>
//------------------------------------------------------------
// curvdemo1
//
// This example program features some of the different
// display styles of the QwtPlotCurve class
//------------------------------------------------------------
//
// Array Sizes
//
const int Size = 27;
#if QT_VERSION >= 0x040000
const int CurvCnt = 6;
#else
const int CurvCnt = 5;
#endif
//
// Arrays holding the values
//
double xval[Size];
double yval[Size];
QwtScaleMap xMap;
QwtScaleMap yMap;
class MainWin : public QFrame
{
public:
MainWin();
protected:
#if QT_VERSION >= 0x040000
virtual void paintEvent(QPaintEvent *);
#endif
void drawContents(QPainter *p);
private:
void shiftDown(QRect &rect, int offset) const;
QwtPlotCurve crv[CurvCnt];
};
MainWin::MainWin()
{
int i;
xMap.setScaleInterval(-0.5, 10.5);
yMap.setScaleInterval(-1.1, 1.1);
//
// Frame style
//
setFrameStyle(QFrame::Box|QFrame::Raised);
setLineWidth(2);
setMidLineWidth(3);
//
// Calculate values
//
for(i=0; i<Size;i++)
{ xval[i] = double(i) * 10.0 / double(Size - 1);
yval[i] = sin(xval[i]) * cos(2.0 * xval[i]);
}
//
// define curve styles
//
QwtSymbol sym;
i = 0;
sym.setStyle(QwtSymbol::Cross);
sym.setPen(QColor(Qt::black));
sym.setSize(5);
crv[i].setSymbol(sym);
crv[i].setPen(QColor(Qt::darkGreen));
crv[i].setStyle(QwtPlotCurve::Lines);
crv[i].setCurveAttribute(QwtPlotCurve::Fitted);
i++;
sym.setStyle(QwtSymbol::Ellipse);
sym.setPen(QColor(Qt::blue));
sym.setBrush(QColor(Qt::yellow));
sym.setSize(5);
crv[i].setSymbol(sym);
crv[i].setPen(QColor(Qt::red));
crv[i].setStyle(QwtPlotCurve::Sticks);
i++;
crv[i].setPen(QColor(Qt::darkBlue));
crv[i].setStyle(QwtPlotCurve::Lines);
i++;
#if QT_VERSION >= 0x040000
crv[i].setPen(QColor(Qt::darkBlue));
crv[i].setStyle(QwtPlotCurve::Lines);
crv[i].setRenderHint(QwtPlotItem::RenderAntialiased);
i++;
#endif
crv[i].setPen(QColor(Qt::darkCyan));
crv[i].setStyle(QwtPlotCurve::Steps);
i++;
sym.setStyle(QwtSymbol::XCross);
sym.setPen(QColor(Qt::darkMagenta));
crv[i].setSymbol(sym);
crv[i].setStyle(QwtPlotCurve::NoCurve);
i++;
//
// attach data
//
for(i=0;i<CurvCnt;i++)
crv[i].setRawData(xval,yval,Size);
}
void MainWin::shiftDown(QRect &rect, int offset) const
{
#if QT_VERSION < 0x040000
rect.moveBy(0, offset);
#else
rect.translate(0, offset);
#endif
}
#if QT_VERSION >= 0x040000
void MainWin::paintEvent(QPaintEvent *event)
{
QFrame::paintEvent(event);
QPainter painter(this);
painter.setClipRect(contentsRect());
drawContents(&painter);
}
#endif
//
// REDRAW CONTENTS
//
void MainWin::drawContents(QPainter *painter)
{
int deltay,i;
QRect r = contentsRect();
deltay = r.height() / CurvCnt - 1;
r.setHeight(deltay);
//
// draw curves
//
for (i=0;i<CurvCnt;i++)
{
xMap.setPaintInterval(r.left(), r.right());
yMap.setPaintInterval(r.top(), r.bottom());
#if QT_VERSION >= 0x040000
painter->setRenderHint(QPainter::Antialiasing,
crv[i].testRenderHint(QwtPlotItem::RenderAntialiased) );
#endif
crv[i].draw(painter, xMap, yMap, r);
shiftDown(r, deltay);
}
//
// draw titles
//
r = contentsRect(); // reset r
painter->setFont(QFont("Helvetica", 8));
const int alignment = Qt::AlignTop|Qt::AlignHCenter;
painter->setPen(Qt::black);
painter->drawText(0,r.top(),r.width(), painter->fontMetrics().height(),
alignment, "Style: Line/Fitted, Symbol: Cross");
shiftDown(r, deltay);
painter->drawText(0,r.top(),r.width(), painter->fontMetrics().height(),
alignment, "Style: Sticks, Symbol: Ellipse");
shiftDown(r, deltay);
painter->drawText(0 ,r.top(),r.width(), painter->fontMetrics().height(),
alignment, "Style: Lines, Symbol: None");
shiftDown(r, deltay);
#if QT_VERSION >= 0x040000
painter->drawText(0 ,r.top(),r.width(), painter->fontMetrics().height(),
alignment, "Style: Lines, Symbol: None, Antialiased");
shiftDown(r, deltay);
#endif
painter->drawText(0, r.top(),r.width(), painter->fontMetrics().height(),
alignment, "Style: Steps, Symbol: None");
shiftDown(r, deltay);
painter->drawText(0,r.top(),r.width(), painter->fontMetrics().height(),
alignment, "Style: NoCurve, Symbol: XCross");
}
int main (int argc, char **argv)
{
QApplication a(argc, argv);
MainWin w;
#if QT_VERSION < 0x040000
a.setMainWidget(&w);
#endif
w.resize(300,600);
w.show();
return a.exec();
}

View File

@@ -0,0 +1,15 @@
# -*- mode: sh -*- ################################################
# Qwt Widget Library
# Copyright (C) 1997 Josef Wilgen
# Copyright (C) 2002 Uwe Rathmann
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the Qwt License, Version 1.0
###################################################################
include( ../examples.pri )
TARGET = curvdemo1
SOURCES = \
curvdemo1.cpp

View File

@@ -0,0 +1,223 @@
#include <qapplication.h>
#include <qpainter.h>
#include <qwt_math.h>
#include <qwt_symbol.h>
#include <qwt_curve_fitter.h>
#include "curvdemo2.h"
//------------------------------------------------------------
// curvdemo2
//
// This example shows a simple animation featuring
// with several QwtPlotCurves
//
//------------------------------------------------------------
//
// Array Sizes
//
const int Size = 15;
const int USize = 13;
//
// Arrays holding the values
//
double xval[Size];
double yval[Size];
double zval[Size];
double uval[USize];
double vval[USize];
//
// CONSTRUCT MAIN WINDOW
//
MainWin::MainWin():
QFrame()
{
setFrameStyle(QFrame::Box|QFrame::Raised);
setLineWidth(2);
setMidLineWidth(3);
const QColor bgColor(30,30,50);
#if QT_VERSION < 0x040000
setPaletteBackgroundColor(bgColor);
#else
QPalette p = palette();
p.setColor(backgroundRole(), bgColor);
setPalette(p);
#endif
QwtSplineCurveFitter* curveFitter;
//
// curve 1
//
int i = 0;
xMap[i].setScaleInterval(-1.5, 1.5);
yMap[i].setScaleInterval(0.0, 6.28);
curve[i].setPen(QPen(QColor(150,150,200),2));
curve[i].setStyle(QwtPlotCurve::Lines);
curve[i].setCurveAttribute(QwtPlotCurve::Fitted, true);
curveFitter = new QwtSplineCurveFitter();
curveFitter->setSplineSize(150);
curve[i].setCurveFitter(curveFitter);
QwtSymbol sym;
sym.setStyle(QwtSymbol::XCross);
sym.setPen(QPen(Qt::yellow,2));
sym.setSize(7);
curve[i].setSymbol(sym);
curve[i].setRawData(yval,xval,Size);
//
// curve 2
//
i++;
xMap[i].setScaleInterval(0.0, 6.28);
yMap[i].setScaleInterval(-3.0, 1.1);
curve[i].setPen(QPen(QColor(200,150,50)));
curve[i].setStyle(QwtPlotCurve::Sticks);
curve[i].setSymbol(QwtSymbol(QwtSymbol::Ellipse,
QColor(Qt::blue), QColor(Qt::yellow), QSize(5,5)));
curve[i].setRawData(xval,zval,Size);
//
// curve 3
//
i++;
xMap[i].setScaleInterval(-1.1, 3.0);
yMap[i].setScaleInterval(-1.1, 3.0);
curve[i].setStyle(QwtPlotCurve::Lines);
curve[i].setCurveAttribute(QwtPlotCurve::Fitted, true);
curve[i].setPen(QColor(100,200,150));
curveFitter = new QwtSplineCurveFitter();
curveFitter->setFitMode(QwtSplineCurveFitter::ParametricSpline);
curveFitter->setSplineSize(200);
curve[i].setCurveFitter(curveFitter);
curve[i].setRawData(yval,zval,Size);
//
// curve 4
//
i++;
xMap[i].setScaleInterval(-5, 1.1);
yMap[i].setScaleInterval(-1.1, 5.0);
curve[i].setStyle(QwtPlotCurve::Lines);
curve[i].setCurveAttribute(QwtPlotCurve::Fitted, true);
curve[i].setPen(QColor(Qt::red));
curveFitter = new QwtSplineCurveFitter();
curveFitter->setSplineSize(200);
curve[i].setCurveFitter(curveFitter);
curve[i].setRawData(uval,vval,USize);
//
// initialize values
//
double base = 2.0 * M_PI / double(USize - 1);
double toggle = 1.0;
for (i = 0; i < USize; i++)
{
uval[i] = toggle * cos( double(i) * base);
vval[i] = toggle * sin( double(i) * base);
if (toggle == 1.0)
toggle = 0.5;
else
toggle = 1.0;
}
newValues();
//
// start timer
//
(void)startTimer(250);
}
#if QT_VERSION >= 0x040000
void MainWin::paintEvent(QPaintEvent *event)
{
QFrame::paintEvent(event);
QPainter painter(this);
painter.setClipRect(contentsRect());
drawContents(&painter);
}
#endif
void MainWin::drawContents(QPainter *painter)
{
const QRect &r = contentsRect();
for ( int i = 0; i < curveCount; i++ )
{
xMap[i].setPaintInterval(r.left(), r.right());
yMap[i].setPaintInterval(r.top(), r.bottom());
curve[i].draw(painter, xMap[i], yMap[i], r);
}
}
//
// TIMER EVENT
//
void MainWin::timerEvent(QTimerEvent *)
{
newValues();
repaint();
}
//
// RE-CALCULATE VALUES
//
void MainWin::newValues()
{
int i;
static double phs = 0.0;
double s,c,u;
for (i=0;i<Size;i++)
{
xval[i] = 6.28 * double(i) / double(Size -1);
yval[i] = sin(xval[i] - phs);
zval[i] = cos(3.0 * (xval[i] + phs));
}
s = 0.25 * sin(phs);
c = sqrt(1.0 - s*s);
for (i=0; i<USize;i++)
{
u = uval[i];
uval[i] = uval[i] * c - vval[i] * s;
vval[i] = vval[i] * c + u * s;
}
phs += 0.0628;
if (phs > 6.28)
phs = 0.0;
}
int main (int argc, char **argv)
{
QApplication a(argc, argv);
MainWin w;
#if QT_VERSION < 0x040000
a.setMainWidget(&w);
#endif
w.resize(300,300);
w.show();
return a.exec();
}

View File

@@ -0,0 +1,26 @@
#include <qframe.h>
#include <qwt_plot_curve.h>
#include <qwt_scale_map.h>
class MainWin : public QFrame
{
public:
enum { curveCount = 4 };
QwtScaleMap xMap[curveCount];
QwtScaleMap yMap[curveCount];
QwtPlotCurve curve[curveCount];
public:
MainWin();
protected:
virtual void timerEvent(QTimerEvent *t);
#if QT_VERSION >= 0x040000
virtual void paintEvent(QPaintEvent *);
#endif
virtual void drawContents(QPainter *);
private:
void newValues();
};

View File

@@ -0,0 +1,18 @@
# -*- mode: sh -*- ################################################
# Qwt Widget Library
# Copyright (C) 1997 Josef Wilgen
# Copyright (C) 2002 Uwe Rathmann
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the Qwt License, Version 1.0
###################################################################
include( ../examples.pri )
TARGET = curvdemo2
HEADERS = \
curvdemo2.h
SOURCES = \
curvdemo2.cpp

View File

@@ -0,0 +1,147 @@
#include <stdlib.h>
#include <qwt_painter.h>
#include <qwt_plot_canvas.h>
#include <qwt_plot_marker.h>
#include <qwt_plot_curve.h>
#include <qwt_scale_widget.h>
#include <qwt_legend.h>
#include <qwt_scale_draw.h>
#include <qwt_math.h>
#include "data_plot.h"
//
// Initialize main window
//
DataPlot::DataPlot(QWidget *parent):
QwtPlot(parent),
d_interval(0),
d_timerId(-1)
{
// Disable polygon clipping
QwtPainter::setDeviceClipping(false);
// We don't need the cache here
canvas()->setPaintAttribute(QwtPlotCanvas::PaintCached, false);
canvas()->setPaintAttribute(QwtPlotCanvas::PaintPacked, false);
#if QT_VERSION >= 0x040000
#ifdef Q_WS_X11
/*
Qt::WA_PaintOnScreen is only supported for X11, but leads
to substantial bugs with Qt 4.2.x/Windows
*/
canvas()->setAttribute(Qt::WA_PaintOnScreen, true);
#endif
#endif
alignScales();
// Initialize data
for (int i = 0; i< PLOT_SIZE; i++)
{
d_x[i] = 0.5 * i; // time axis
d_y[i] = 0;
d_z[i] = 0;
}
// Assign a title
setTitle("A Test for High Refresh Rates");
insertLegend(new QwtLegend(), QwtPlot::BottomLegend);
// Insert new curves
QwtPlotCurve *cRight = new QwtPlotCurve("Data Moving Right");
cRight->attach(this);
QwtPlotCurve *cLeft = new QwtPlotCurve("Data Moving Left");
cLeft->attach(this);
// Set curve styles
cRight->setPen(QPen(Qt::red));
cLeft->setPen(QPen(Qt::blue));
// Attach (don't copy) data. Both curves use the same x array.
cRight->setRawData(d_x, d_y, PLOT_SIZE);
cLeft->setRawData(d_x, d_z, PLOT_SIZE);
#if 0
// Insert zero line at y = 0
QwtPlotMarker *mY = new QwtPlotMarker();
mY->setLabelAlignment(Qt::AlignRight|Qt::AlignTop);
mY->setLineStyle(QwtPlotMarker::HLine);
mY->setYValue(0.0);
mY->attach(this);
#endif
// Axis
setAxisTitle(QwtPlot::xBottom, "Time/seconds");
setAxisScale(QwtPlot::xBottom, 0, 100);
setAxisTitle(QwtPlot::yLeft, "Values");
setAxisScale(QwtPlot::yLeft, -1.5, 1.5);
setTimerInterval(0.0);
}
//
// Set a plain canvas frame and align the scales to it
//
void DataPlot::alignScales()
{
// The code below shows how to align the scales to
// the canvas frame, but is also a good example demonstrating
// why the spreaded API needs polishing.
canvas()->setFrameStyle(QFrame::Box | QFrame::Plain );
canvas()->setLineWidth(1);
for ( int i = 0; i < QwtPlot::axisCnt; i++ )
{
QwtScaleWidget *scaleWidget = (QwtScaleWidget *)axisWidget(i);
if ( scaleWidget )
scaleWidget->setMargin(0);
QwtScaleDraw *scaleDraw = (QwtScaleDraw *)axisScaleDraw(i);
if ( scaleDraw )
scaleDraw->enableComponent(QwtAbstractScaleDraw::Backbone, false);
}
}
void DataPlot::setTimerInterval(double ms)
{
d_interval = qRound(ms);
if ( d_timerId >= 0 )
{
killTimer(d_timerId);
d_timerId = -1;
}
if (d_interval >= 0 )
d_timerId = startTimer(d_interval);
}
// Generate new values
void DataPlot::timerEvent(QTimerEvent *)
{
static double phase = 0.0;
if (phase > (M_PI - 0.0001))
phase = 0.0;
// y moves from left to right:
// Shift y array right and assign new value to y[0].
for ( int i = PLOT_SIZE - 1; i > 0; i-- )
d_y[i] = d_y[i-1];
d_y[0] = sin(phase) * (-1.0 + 2.0 * double(rand()) / double(RAND_MAX));
for ( int j = 0; j < PLOT_SIZE - 1; j++ )
d_z[j] = d_z[j+1];
d_z[PLOT_SIZE - 1] = 0.8 - (2.0 * phase/M_PI) + 0.4 *
double(rand()) / double(RAND_MAX);
// update the display
replot();
phase += M_PI * 0.02;
}

View File

@@ -0,0 +1,32 @@
#ifndef _DATA_PLOT_H
#define _DATA_PLOT_H 1
#include <qwt_plot.h>
const int PLOT_SIZE = 201; // 0 to 200
class DataPlot : public QwtPlot
{
Q_OBJECT
public:
DataPlot(QWidget* = NULL);
public slots:
void setTimerInterval(double interval);
protected:
virtual void timerEvent(QTimerEvent *e);
private:
void alignScales();
double d_x[PLOT_SIZE];
double d_y[PLOT_SIZE];
double d_z[PLOT_SIZE];
int d_interval; // timer in ms
int d_timerId;
};
#endif

View File

@@ -0,0 +1,20 @@
# -*- mode: sh -*- ################################################
# Qwt Widget Library
# Copyright (C) 1997 Josef Wilgen
# Copyright (C) 2002 Uwe Rathmann
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the Qwt License, Version 1.0
###################################################################
include( ../examples.pri )
TARGET = data_plot
HEADERS = \
data_plot.h
SOURCES = \
data_plot.cpp \
main.cpp

View File

@@ -0,0 +1,62 @@
#include <qapplication.h>
#include <qmainwindow.h>
#include <qwt_counter.h>
#include <qtoolbar.h>
#include <qlabel.h>
#include <qlayout.h>
#include "data_plot.h"
class MainWindow: public QMainWindow
{
public:
MainWindow()
{
QToolBar *toolBar = new QToolBar(this);
toolBar->setFixedHeight(80);
#if QT_VERSION < 0x040000
setDockEnabled(TornOff, true);
setRightJustification(true);
#else
toolBar->setAllowedAreas(Qt::TopToolBarArea | Qt::BottomToolBarArea);
#endif
QWidget *hBox = new QWidget(toolBar);
QLabel *label = new QLabel("Timer Interval", hBox);
QwtCounter *counter = new QwtCounter(hBox);
counter->setRange(-1.0, 100.0, 1.0);
QHBoxLayout *layout = new QHBoxLayout(hBox);
layout->addWidget(label);
layout->addWidget(counter);
layout->addWidget(new QWidget(hBox), 10); // spacer);
#if QT_VERSION >= 0x040000
toolBar->addWidget(hBox);
#endif
addToolBar(toolBar);
DataPlot *plot = new DataPlot(this);
setCentralWidget(plot);
connect(counter, SIGNAL(valueChanged(double)),
plot, SLOT(setTimerInterval(double)) );
counter->setValue(20.0);
}
};
int main(int argc, char **argv)
{
QApplication a(argc, argv);
MainWindow mainWindow;
#if QT_VERSION < 0x040000
a.setMainWidget(&mainWindow);
#endif
mainWindow.resize(600,400);
mainWindow.show();
return a.exec();
}

View File

@@ -0,0 +1,149 @@
#include <qevent.h>
#include <qpainter.h>
#include <qwt_math.h>
#include <qwt_polygon.h>
#include "attitude_indicator.h"
AttitudeIndicatorNeedle::AttitudeIndicatorNeedle(const QColor &c)
{
QPalette palette;
for ( int i = 0; i < QPalette::NColorGroups; i++ )
{
#if QT_VERSION < 0x040000
palette.setColor((QPalette::ColorGroup)i,
QColorGroup::Text, c);
#else
palette.setColor((QPalette::ColorGroup)i,
QPalette::Text, c);
#endif
}
setPalette(palette);
}
void AttitudeIndicatorNeedle::draw(QPainter *painter, const QPoint &center,
int length, double direction, QPalette::ColorGroup cg) const
{
direction *= M_PI / 180.0;
int triangleSize = qRound(length * 0.1);
painter->save();
const QPoint p0(QPoint(center.x() + 1, center.y() + 1));
const QPoint p1 = qwtPolar2Pos(p0,
length - 2 * triangleSize - 2, direction);
QwtPolygon pa(3);
pa.setPoint(0, qwtPolar2Pos(p1, 2 * triangleSize, direction));
pa.setPoint(1, qwtPolar2Pos(p1, triangleSize, direction + M_PI_2));
pa.setPoint(2, qwtPolar2Pos(p1, triangleSize, direction - M_PI_2));
const QColor color =
#if QT_VERSION < 0x040000
palette().color(cg, QColorGroup::Text);
#else
palette().color(cg, QPalette::Text);
#endif
painter->setBrush(color);
painter->drawPolygon(pa);
painter->setPen(QPen(color, 3));
painter->drawLine(qwtPolar2Pos(p0, length - 2, direction + M_PI_2),
qwtPolar2Pos(p0, length - 2, direction - M_PI_2));
painter->restore();
}
AttitudeIndicator::AttitudeIndicator(
QWidget *parent):
QwtDial(parent),
d_gradient(0.0)
{
setMode(RotateScale);
setWrapping(true);
setOrigin(270.0);
setScaleOptions(ScaleTicks);
setScale(0, 0, 30.0);
const QColor color =
#if QT_VERSION < 0x040000
colorGroup().text();
#else
palette().color(QPalette::Text);
#endif
setNeedle(new AttitudeIndicatorNeedle(color));
}
void AttitudeIndicator::setGradient(double gradient)
{
if ( gradient < -1.0 )
gradient = -1.0;
else if ( gradient > 1.0 )
gradient = 1.0;
if ( d_gradient != gradient )
{
d_gradient = gradient;
update();
}
}
void AttitudeIndicator::drawScale(QPainter *painter, const QPoint &center,
int radius, double origin, double minArc, double maxArc) const
{
double dir = (360.0 - origin) * M_PI / 180.0; // counter clockwise, radian
int offset = 4;
const QPoint p0 = qwtPolar2Pos(center, offset, dir + M_PI);
const int w = contentsRect().width();
QwtPolygon pa(4);
pa.setPoint(0, qwtPolar2Pos(p0, w, dir - M_PI_2));
pa.setPoint(1, qwtPolar2Pos(pa.point(0), 2 * w, dir + M_PI_2));
pa.setPoint(2, qwtPolar2Pos(pa.point(1), w, dir));
pa.setPoint(3, qwtPolar2Pos(pa.point(2), 2 * w, dir - M_PI_2));
painter->save();
painter->setClipRegion(pa); // swallow 180 - 360 degrees
QwtDial::drawScale(painter, center, radius, origin,
minArc, maxArc);
painter->restore();
}
void AttitudeIndicator::drawScaleContents(QPainter *painter,
const QPoint &, int) const
{
int dir = 360 - qRound(origin() - value()); // counter clockwise
int arc = 90 + qRound(gradient() * 90);
const QColor skyColor(38, 151, 221);
painter->save();
painter->setBrush(skyColor);
painter->drawChord(scaleContentsRect(),
(dir - arc) * 16, 2 * arc * 16 );
painter->restore();
}
void AttitudeIndicator::keyPressEvent(QKeyEvent *e)
{
switch(e->key())
{
case Qt::Key_Plus:
setGradient(gradient() + 0.05);
break;
case Qt::Key_Minus:
setGradient(gradient() - 0.05);
break;
default:
QwtDial::keyPressEvent(e);
}
}

View File

@@ -0,0 +1,38 @@
#include <qwt_dial.h>
#include <qwt_dial_needle.h>
class AttitudeIndicatorNeedle: public QwtDialNeedle
{
public:
AttitudeIndicatorNeedle(const QColor &);
virtual void draw(QPainter *, const QPoint &, int length,
double direction, QPalette::ColorGroup) const;
};
class AttitudeIndicator: public QwtDial
{
Q_OBJECT
public:
AttitudeIndicator(QWidget *parent = NULL);
double angle() const { return value(); }
double gradient() const { return d_gradient; }
public slots:
void setGradient(double);
void setAngle(double angle) { setValue(angle); }
protected:
virtual void keyPressEvent(QKeyEvent *);
virtual void drawScale(QPainter *, const QPoint &center,
int radius, double origin, double arcMin, double arcMax) const;
virtual void drawScaleContents(QPainter *painter,
const QPoint &center, int radius) const;
private:
double d_gradient;
};

View File

@@ -0,0 +1,206 @@
#include <qlayout.h>
#include <qtimer.h>
#include <qwt_analog_clock.h>
#include "attitude_indicator.h"
#include "speedo_meter.h"
#include "cockpit_grid.h"
#if QT_VERSION < 0x040000
typedef QColorGroup Palette;
#else
typedef QPalette Palette;
#endif
CockpitGrid::CockpitGrid(QWidget *parent):
QFrame(parent)
{
#if QT_VERSION >= 0x040100
setAutoFillBackground(true);
#endif
setPalette(colorTheme(QColor(Qt::darkGray).dark(150)));
QGridLayout *layout = new QGridLayout(this);
layout->setSpacing(5);
layout->setMargin(0);
int i;
for ( i = 0; i < 3; i++ )
{
QwtDial *dial = createDial(i);
layout->addWidget(dial, 0, i);
}
#if QT_VERSION < 0x040000
for ( i = 0; i < layout->numCols(); i++ )
layout->setColStretch(i, 1);
#else
for ( i = 0; i < layout->columnCount(); i++ )
layout->setColumnStretch(i, 1);
#endif
}
QwtDial *CockpitGrid::createDial(int pos)
{
QwtDial *dial = NULL;
switch(pos)
{
case 0:
{
d_clock = new QwtAnalogClock(this);
const QColor knobColor = QColor(Qt::gray).light(130);
for ( int i = 0; i < QwtAnalogClock::NHands; i++)
{
QColor handColor = QColor(Qt::gray).light(150);
int width = 8;
if ( i == QwtAnalogClock::SecondHand )
{
handColor = Qt::gray;
width = 5;
}
QwtDialSimpleNeedle *hand = new QwtDialSimpleNeedle(
QwtDialSimpleNeedle::Arrow, true, handColor, knobColor);
hand->setWidth(width);
d_clock->setHand((QwtAnalogClock::Hand)i, hand);
}
QTimer *timer = new QTimer(d_clock);
timer->connect(timer, SIGNAL(timeout()),
d_clock, SLOT(setCurrentTime()));
timer->start(1000);
dial = d_clock;
break;
}
case 1:
{
d_speedo = new SpeedoMeter(this);
d_speedo->setRange(0.0, 240.0);
d_speedo->setScale(-1, 2, 20);
QTimer *timer = new QTimer(d_speedo);
timer->connect(timer, SIGNAL(timeout()),
this, SLOT(changeSpeed()));
timer->start(50);
dial = d_speedo;
break;
}
case 2:
{
d_ai = new AttitudeIndicator(this);
QTimer *gradientTimer = new QTimer(d_ai);
gradientTimer->connect(gradientTimer, SIGNAL(timeout()),
this, SLOT(changeGradient()));
gradientTimer->start(100);
QTimer *angleTimer = new QTimer(d_ai);
angleTimer->connect(angleTimer, SIGNAL(timeout()),
this, SLOT(changeAngle()));
angleTimer->start(100);
dial = d_ai;
break;
}
}
if ( dial )
{
dial->setReadOnly(true);
dial->scaleDraw()->setPenWidth(3);
dial->setLineWidth(4);
dial->setFrameShadow(QwtDial::Sunken);
}
return dial;
}
QPalette CockpitGrid::colorTheme(const QColor &base) const
{
const QColor background = base.dark(150);
const QColor foreground = base.dark(200);
const QColor mid = base.dark(110);
const QColor dark = base.dark(170);
const QColor light = base.light(170);
const QColor text = foreground.light(800);
QPalette palette;
for ( int i = 0; i < QPalette::NColorGroups; i++ )
{
QPalette::ColorGroup cg = (QPalette::ColorGroup)i;
palette.setColor(cg, Palette::Base, base);
palette.setColor(cg, Palette::Background, background);
palette.setColor(cg, Palette::Mid, mid);
palette.setColor(cg, Palette::Light, light);
palette.setColor(cg, Palette::Dark, dark);
palette.setColor(cg, Palette::Text, text);
palette.setColor(cg, Palette::Foreground, foreground);
}
return palette;
}
void CockpitGrid::changeSpeed()
{
static double offset = 0.8;
double speed = d_speedo->value();
if ( (speed < 40.0 && offset < 0.0 ) ||
(speed > 160.0 && offset > 0.0) )
{
offset = -offset;
}
static int counter = 0;
switch(counter++ % 12 )
{
case 0:
case 2:
case 7:
case 8:
break;
default:
d_speedo->setValue(speed + offset);
}
}
void CockpitGrid::changeAngle()
{
static double offset = 0.05;
double angle = d_ai->angle();
if ( angle > 180.0 )
angle -= 360.0;
if ( (angle < -5.0 && offset < 0.0 ) ||
(angle > 5.0 && offset > 0.0) )
{
offset = -offset;
}
d_ai->setAngle(angle + offset);
}
void CockpitGrid::changeGradient()
{
static double offset = 0.005;
double gradient = d_ai->gradient();
if ( (gradient < -0.05 && offset < 0.0 ) ||
(gradient > 0.05 && offset > 0.0) )
{
offset = -offset;
}
d_ai->setGradient(gradient + offset);
}

View File

@@ -0,0 +1,28 @@
#include <qframe.h>
#include <qpalette.h>
class QwtDial;
class QwtAnalogClock;
class SpeedoMeter;
class AttitudeIndicator;
class CockpitGrid: public QFrame
{
Q_OBJECT
public:
CockpitGrid(QWidget *parent = NULL);
private slots:
void changeSpeed();
void changeGradient();
void changeAngle();
private:
QPalette colorTheme(const QColor &) const;
QwtDial *createDial(int pos);
QwtAnalogClock *d_clock;
SpeedoMeter *d_speedo;
AttitudeIndicator *d_ai;
};

View File

@@ -0,0 +1,225 @@
#include <qlayout.h>
#include <qwt_compass.h>
#include <qwt_compass_rose.h>
#include <qwt_dial_needle.h>
#include "compass_grid.h"
#if QT_VERSION < 0x040000
typedef QColorGroup Palette;
#else
typedef QPalette Palette;
#endif
CompassGrid::CompassGrid(QWidget *parent):
QFrame(parent)
{
#if QT_VERSION < 0x040000
setBackgroundColor(Qt::gray);
#else
QPalette p = palette();
p.setColor(backgroundRole(), Qt::gray);
setPalette(p);
#endif
#if QT_VERSION >= 0x040100
setAutoFillBackground(true);
#endif
QGridLayout *layout = new QGridLayout(this);
layout->setSpacing(5);
layout->setMargin(0);
int i;
for ( i = 0; i < 6; i++ )
{
QwtCompass *compass = createCompass(i);
layout->addWidget(compass, i / 3, i % 3);
}
#if QT_VERSION < 0x040000
for ( i = 0; i < layout->numCols(); i++ )
layout->setColStretch(i, 1);
#else
for ( i = 0; i < layout->columnCount(); i++ )
layout->setColumnStretch(i, 1);
#endif
}
QwtCompass *CompassGrid::createCompass(int pos)
{
int c;
Palette colorGroup;
for ( c = 0; c < Palette::NColorRoles; c++ )
colorGroup.setColor((Palette::ColorRole)c, QColor());
#if QT_VERSION < 0x040000
colorGroup.setColor(Palette::Base, backgroundColor().light(120));
#else
colorGroup.setColor(Palette::Base,
palette().color(backgroundRole()).light(120));
#endif
colorGroup.setColor(Palette::Foreground,
colorGroup.color(Palette::Base));
QwtCompass *compass = new QwtCompass(this);
compass->setLineWidth(4);
compass->setFrameShadow(
pos <= 2 ? QwtCompass::Sunken : QwtCompass::Raised);
switch(pos)
{
case 0:
{
/*
A compass with a rose and no needle. Scale and rose are
rotating.
*/
compass->setMode(QwtCompass::RotateScale);
QwtSimpleCompassRose *rose = new QwtSimpleCompassRose(16, 2);
rose->setWidth(0.15);
compass->setRose(rose);
break;
}
case 1:
{
/*
A windrose, with a scale indicating the main directions only
*/
QMap<double, QString> map;
map.insert(0.0, "N");
map.insert(90.0, "E");
map.insert(180.0, "S");
map.insert(270.0, "W");
compass->setLabelMap(map);
QwtSimpleCompassRose *rose = new QwtSimpleCompassRose(4, 1);
compass->setRose(rose);
compass->setNeedle(
new QwtCompassWindArrow(QwtCompassWindArrow::Style2));
compass->setValue(60.0);
break;
}
case 2:
{
/*
A compass with a rotating needle in darkBlue. Shows
a ticks for each degree.
*/
colorGroup.setColor(Palette::Base, Qt::darkBlue);
colorGroup.setColor(Palette::Foreground,
QColor(Qt::darkBlue).dark(120));
colorGroup.setColor(Palette::Text, Qt::white);
compass->setScaleOptions(QwtDial::ScaleTicks | QwtDial::ScaleLabel);
compass->setScaleTicks(1, 1, 3);
compass->setScale(36, 5, 0);
compass->setNeedle(
new QwtCompassMagnetNeedle(QwtCompassMagnetNeedle::ThinStyle));
compass->setValue(220.0);
break;
}
case 3:
{
/*
A compass without a frame, showing numbers as tick labels.
The origin is at 220.0
*/
#if QT_VERSION < 0x040000
colorGroup.setColor(Palette::Base, backgroundColor());
#else
colorGroup.setColor(Palette::Base,
palette().color(backgroundRole()));
#endif
colorGroup.setColor(Palette::Foreground, Qt::blue);
compass->setLineWidth(0);
compass->setScaleOptions(QwtDial::ScaleBackbone |
QwtDial::ScaleTicks | QwtDial::ScaleLabel);
compass->setScaleTicks(0, 0, 3);
QMap<double, QString> map;
for ( double d = 0.0; d < 360.0; d += 60.0 )
{
QString label;
label.sprintf("%.0f", d);
map.insert(d, label);
}
compass->setLabelMap(map);
compass->setScale(36, 5, 0);
compass->setNeedle(new QwtDialSimpleNeedle(QwtDialSimpleNeedle::Ray,
false, Qt::white));
compass->setOrigin(220.0);
compass->setValue(20.0);
break;
}
case 4:
{
/*
A compass showing another needle
*/
compass->setScaleOptions(QwtDial::ScaleTicks | QwtDial::ScaleLabel);
compass->setScaleTicks(0, 0, 3);
compass->setNeedle(new QwtCompassMagnetNeedle(
QwtCompassMagnetNeedle::TriangleStyle, Qt::white, Qt::red));
compass->setValue(220.0);
break;
}
case 5:
{
/*
A compass with a yellow on black ray
*/
colorGroup.setColor(Palette::Foreground, Qt::black);
compass->setNeedle(new QwtDialSimpleNeedle(QwtDialSimpleNeedle::Ray,
false, Qt::yellow));
compass->setValue(315.0);
break;
}
}
QPalette newPalette = compass->palette();
for ( c = 0; c < Palette::NColorRoles; c++ )
{
if ( colorGroup.color((Palette::ColorRole)c).isValid() )
{
for ( int cg = 0; cg < QPalette::NColorGroups; cg++ )
{
newPalette.setColor(
(QPalette::ColorGroup)cg,
(Palette::ColorRole)c,
colorGroup.color((Palette::ColorRole)c));
}
}
}
for ( int i = 0; i < QPalette::NColorGroups; i++ )
{
QPalette::ColorGroup cg = (QPalette::ColorGroup)i;
const QColor light =
newPalette.color(cg, Palette::Base).light(170);
const QColor dark = newPalette.color(cg, Palette::Base).dark(170);
const QColor mid = compass->frameShadow() == QwtDial::Raised
? newPalette.color(cg, Palette::Base).dark(110)
: newPalette.color(cg, Palette::Base).light(110);
newPalette.setColor(cg, Palette::Dark, dark);
newPalette.setColor(cg, Palette::Mid, mid);
newPalette.setColor(cg, Palette::Light, light);
}
compass->setPalette(newPalette);
return compass;
}

View File

@@ -0,0 +1,11 @@
#include <qframe.h>
class QwtCompass;
class CompassGrid: public QFrame
{
public:
CompassGrid(QWidget *parent = NULL);
private:
QwtCompass *createCompass(int pos);
};

View File

@@ -0,0 +1,30 @@
#include <qapplication.h>
#include <qtabwidget.h>
#include "compass_grid.h"
#include "cockpit_grid.h"
//-----------------------------------------------------------------
//
// dials.cpp -- A demo program featuring QwtDial and friends
//
//-----------------------------------------------------------------
int main (int argc, char **argv)
{
QApplication a(argc, argv);
QTabWidget tabWidget;
#if QT_VERSION < 0x040000
tabWidget.addTab(new CompassGrid(&tabWidget), "Compass");
tabWidget.addTab(new CockpitGrid(&tabWidget), "Cockpit");
a.setMainWidget(&tabWidget);
#else
tabWidget.addTab(new CompassGrid, "Compass");
tabWidget.addTab(new CockpitGrid, "Cockpit");
#endif
tabWidget.show();
return a.exec();
}

View File

@@ -0,0 +1,26 @@
# -*- mode: sh -*- ################################################
# Qwt Widget Library
# Copyright (C) 1997 Josef Wilgen
# Copyright (C) 2002 Uwe Rathmann
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the Qwt License, Version 1.0
###################################################################
include( ../examples.pri )
TARGET = dials
HEADERS = \
attitude_indicator.h \
speedo_meter.h \
cockpit_grid.h \
compass_grid.h
SOURCES = \
attitude_indicator.cpp \
speedo_meter.cpp \
cockpit_grid.cpp \
compass_grid.cpp \
dials.cpp

View File

@@ -0,0 +1,52 @@
#include <qpainter.h>
#include <qwt_dial_needle.h>
#include "speedo_meter.h"
SpeedoMeter::SpeedoMeter(QWidget *parent):
QwtDial(parent),
d_label("km/h")
{
setWrapping(false);
setReadOnly(true);
setOrigin(135.0);
setScaleArc(0.0, 270.0);
scaleDraw()->setSpacing(8);
QwtDialSimpleNeedle *needle = new QwtDialSimpleNeedle(
QwtDialSimpleNeedle::Arrow, true, Qt::red,
QColor(Qt::gray).light(130));
setNeedle(needle);
setScaleOptions(ScaleTicks | ScaleLabel);
setScaleTicks(0, 4, 8);
}
void SpeedoMeter::setLabel(const QString &label)
{
d_label = label;
update();
}
QString SpeedoMeter::label() const
{
return d_label;
}
void SpeedoMeter::drawScaleContents(QPainter *painter,
const QPoint &center, int radius) const
{
QRect rect(0, 0, 2 * radius, 2 * radius - 10);
rect.moveCenter(center);
const QColor color =
#if QT_VERSION < 0x040000
colorGroup().text();
#else
palette().color(QPalette::Text);
#endif
painter->setPen(color);
const int flags = Qt::AlignBottom | Qt::AlignHCenter;
painter->drawText(rect, flags, d_label);
}

View File

@@ -0,0 +1,18 @@
#include <qstring.h>
#include <qwt_dial.h>
class SpeedoMeter: public QwtDial
{
public:
SpeedoMeter(QWidget *parent = NULL);
void setLabel(const QString &);
QString label() const;
protected:
virtual void drawScaleContents(QPainter *painter,
const QPoint &center, int radius) const;
private:
QString d_label;
};

View File

@@ -0,0 +1,27 @@
QwtPlot is a composite widget consisting of a title label,
the canvas, the scales and a legend. Although all components
should be exchangable some day, the current design isn´t ready for it.
In this situation event filtering is the mechanism to extend the behaviour
of the plot components. event_filter shows 3 examples how to use it:
1) CanvasPicker
The CanvasPicker implements a solution, how to move points on the canvas
with mouse and keyboard.
2) ScalePicker
The ScalePicker translates the position of mouse clicks on the scales
and emits them as signals.
3) Plot: ColorBar, QSlider
The Plot class shows how to add widgets to the scales. In this example
there is no filter class. The derived plot widget filters its components.
Please note that CanvasPicker and ScalePicker are standalone classes
that could be connected with your QwtPlot as well.
Uwe

View File

@@ -0,0 +1,329 @@
#include <qapplication.h>
#include <qevent.h>
#include <qwhatsthis.h>
#include <qpainter.h>
#include <qwt_plot.h>
#include <qwt_symbol.h>
#include <qwt_scale_map.h>
#include <qwt_plot_canvas.h>
#include <qwt_plot_curve.h>
#include "canvaspicker.h"
CanvasPicker::CanvasPicker(QwtPlot *plot):
QObject(plot),
d_selectedCurve(NULL),
d_selectedPoint(-1)
{
QwtPlotCanvas *canvas = plot->canvas();
canvas->installEventFilter(this);
// We want the focus, but no focus rect. The
// selected point will be highlighted instead.
#if QT_VERSION >= 0x040000
canvas->setFocusPolicy(Qt::StrongFocus);
#ifndef QT_NO_CURSOR
canvas->setCursor(Qt::PointingHandCursor);
#endif
#else
canvas->setFocusPolicy(QWidget::StrongFocus);
#ifndef QT_NO_CURSOR
canvas->setCursor(Qt::pointingHandCursor);
#endif
#endif
canvas->setFocusIndicator(QwtPlotCanvas::ItemFocusIndicator);
canvas->setFocus();
const char *text =
"All points can be moved using the left mouse button "
"or with these keys:\n\n"
"- Up:\t\tSelect next curve\n"
"- Down:\t\tSelect previous curve\n"
"- Left, ´-´:\tSelect next point\n"
"- Right, ´+´:\tSelect previous point\n"
"- 7, 8, 9, 4, 6, 1, 2, 3:\tMove selected point";
#if QT_VERSION >= 0x040000
canvas->setWhatsThis(text);
#else
QWhatsThis::add(canvas, text);
#endif
shiftCurveCursor(true);
}
bool CanvasPicker::event(QEvent *e)
{
if ( e->type() == QEvent::User )
{
showCursor(true);
return true;
}
return QObject::event(e);
}
bool CanvasPicker::eventFilter(QObject *object, QEvent *e)
{
if ( object != (QObject *)plot()->canvas() )
return false;
switch(e->type())
{
case QEvent::FocusIn:
showCursor(true);
case QEvent::FocusOut:
showCursor(false);
case QEvent::Paint:
{
QApplication::postEvent(this, new QEvent(QEvent::User));
break;
}
case QEvent::MouseButtonPress:
{
select(((QMouseEvent *)e)->pos());
return true;
}
case QEvent::MouseMove:
{
move(((QMouseEvent *)e)->pos());
return true;
}
case QEvent::KeyPress:
{
const int delta = 5;
switch(((const QKeyEvent *)e)->key())
{
case Qt::Key_Up:
shiftCurveCursor(true);
return true;
case Qt::Key_Down:
shiftCurveCursor(false);
return true;
case Qt::Key_Right:
case Qt::Key_Plus:
if ( d_selectedCurve )
shiftPointCursor(true);
else
shiftCurveCursor(true);
return true;
case Qt::Key_Left:
case Qt::Key_Minus:
if ( d_selectedCurve )
shiftPointCursor(false);
else
shiftCurveCursor(true);
return true;
// The following keys represent a direction, they are
// organized on the keyboard.
case Qt::Key_1:
moveBy(-delta, delta);
break;
case Qt::Key_2:
moveBy(0, delta);
break;
case Qt::Key_3:
moveBy(delta, delta);
break;
case Qt::Key_4:
moveBy(-delta, 0);
break;
case Qt::Key_6:
moveBy(delta, 0);
break;
case Qt::Key_7:
moveBy(-delta, -delta);
break;
case Qt::Key_8:
moveBy(0, -delta);
break;
case Qt::Key_9:
moveBy(delta, -delta);
break;
default:
break;
}
}
default:
break;
}
return QObject::eventFilter(object, e);
}
// Select the point at a position. If there is no point
// deselect the selected point
void CanvasPicker::select(const QPoint &pos)
{
QwtPlotCurve *curve = NULL;
double dist = 10e10;
int index = -1;
const QwtPlotItemList& itmList = plot()->itemList();
for ( QwtPlotItemIterator it = itmList.begin();
it != itmList.end(); ++it )
{
if ( (*it)->rtti() == QwtPlotItem::Rtti_PlotCurve )
{
QwtPlotCurve *c = (QwtPlotCurve*)(*it);
double d;
int idx = c->closestPoint(pos, &d);
if ( d < dist )
{
curve = c;
index = idx;
dist = d;
}
}
}
showCursor(false);
d_selectedCurve = NULL;
d_selectedPoint = -1;
if ( curve && dist < 10 ) // 10 pixels tolerance
{
d_selectedCurve = curve;
d_selectedPoint = index;
showCursor(true);
}
}
// Move the selected point
void CanvasPicker::moveBy(int dx, int dy)
{
if ( dx == 0 && dy == 0 )
return;
if ( !d_selectedCurve )
return;
const int x = plot()->transform(d_selectedCurve->xAxis(),
d_selectedCurve->x(d_selectedPoint)) + dx;
const int y = plot()->transform(d_selectedCurve->yAxis(),
d_selectedCurve->y(d_selectedPoint)) + dy;
move(QPoint(x, y));
}
// Move the selected point
void CanvasPicker::move(const QPoint &pos)
{
if ( !d_selectedCurve )
return;
QwtArray<double> xData(d_selectedCurve->dataSize());
QwtArray<double> yData(d_selectedCurve->dataSize());
for ( int i = 0; i < d_selectedCurve->dataSize(); i++ )
{
if ( i == d_selectedPoint )
{
xData[i] = plot()->invTransform(d_selectedCurve->xAxis(), pos.x());;
yData[i] = plot()->invTransform(d_selectedCurve->yAxis(), pos.y());;
}
else
{
xData[i] = d_selectedCurve->x(i);
yData[i] = d_selectedCurve->y(i);
}
}
d_selectedCurve->setData(xData, yData);
plot()->replot();
showCursor(true);
}
// Hightlight the selected point
void CanvasPicker::showCursor(bool showIt)
{
if ( !d_selectedCurve )
return;
const QwtSymbol symbol = d_selectedCurve->symbol();
QwtSymbol newSymbol = symbol;
if ( showIt )
newSymbol.setBrush(symbol.brush().color().dark(150));
const bool doReplot = plot()->autoReplot();
plot()->setAutoReplot(false);
d_selectedCurve->setSymbol(newSymbol);
d_selectedCurve->draw(d_selectedPoint, d_selectedPoint);
d_selectedCurve->setSymbol(symbol);
plot()->setAutoReplot(doReplot);
}
// Select the next/previous curve
void CanvasPicker::shiftCurveCursor(bool up)
{
QwtPlotItemIterator it;
const QwtPlotItemList &itemList = plot()->itemList();
QwtPlotItemList curveList;
for ( it = itemList.begin(); it != itemList.end(); ++it )
{
if ( (*it)->rtti() == QwtPlotItem::Rtti_PlotCurve )
curveList += *it;
}
if ( curveList.isEmpty() )
return;
it = curveList.begin();
if ( d_selectedCurve )
{
for ( it = curveList.begin(); it != curveList.end(); ++it )
{
if ( d_selectedCurve == *it )
break;
}
if ( it == curveList.end() ) // not found
it = curveList.begin();
if ( up )
{
++it;
if ( it == curveList.end() )
it = curveList.begin();
}
else
{
if ( it == curveList.begin() )
it = curveList.end();
--it;
}
}
showCursor(false);
d_selectedPoint = 0;
d_selectedCurve = (QwtPlotCurve *)*it;
showCursor(true);
}
// Select the next/previous neighbour of the selected point
void CanvasPicker::shiftPointCursor(bool up)
{
if ( !d_selectedCurve )
return;
int index = d_selectedPoint + (up ? 1 : -1);
index = (index + d_selectedCurve->dataSize()) % d_selectedCurve->dataSize();
if ( index != d_selectedPoint )
{
showCursor(false);
d_selectedPoint = index;
showCursor(true);
}
}

View File

@@ -0,0 +1,33 @@
#include <qobject.h>
class QPoint;
class QCustomEvent;
class QwtPlot;
class QwtPlotCurve;
class CanvasPicker: public QObject
{
Q_OBJECT
public:
CanvasPicker(QwtPlot *plot);
virtual bool eventFilter(QObject *, QEvent *);
virtual bool event(QEvent *);
private:
void select(const QPoint &);
void move(const QPoint &);
void moveBy(int dx, int dy);
void release();
void showCursor(bool enable);
void shiftPointCursor(bool up);
void shiftCurveCursor(bool up);
QwtPlot *plot() { return (QwtPlot *)parent(); }
const QwtPlot *plot() const { return (QwtPlot *)parent(); }
QwtPlotCurve *d_selectedCurve;
int d_selectedPoint;
};

View File

@@ -0,0 +1,125 @@
#include <qevent.h>
#include <qpixmap.h>
#include <qimage.h>
#include <qpainter.h>
#include "colorbar.h"
ColorBar::ColorBar(Qt::Orientation o, QWidget *parent):
QWidget(parent),
d_orientation(o),
d_light(Qt::white),
d_dark(Qt::black)
{
#ifndef QT_NO_CURSOR
#if QT_VERSION < 0x040000
setCursor(Qt::pointingHandCursor);
#else
setCursor(Qt::PointingHandCursor);
#endif
#endif
}
void ColorBar::setOrientation(Qt::Orientation o)
{
d_orientation = o;
update();
}
void ColorBar::setLight(const QColor &light)
{
d_light = light;
update();
}
void ColorBar::setDark(const QColor &dark)
{
d_dark = dark;
update();
}
void ColorBar::setRange(const QColor &light, const QColor &dark)
{
d_light = light;
d_dark = dark;
update();
}
void ColorBar::mousePressEvent(QMouseEvent *e)
{
if( e->button() == Qt::LeftButton )
{
// emit the color of the position where the mouse click
// happened
const QPixmap pm = QPixmap::grabWidget(this);
#if QT_VERSION < 0x040000
const QRgb rgb = pm.convertToImage().pixel(e->x(), e->y());
#else
const QRgb rgb = pm.toImage().pixel(e->x(), e->y());
#endif
emit selected(QColor(rgb));
e->accept();
}
}
void ColorBar::paintEvent(QPaintEvent *)
{
QPainter painter(this);
drawColorBar(&painter, rect());
}
void ColorBar::drawColorBar(QPainter *painter, const QRect &rect) const
{
int h1, s1, v1;
int h2, s2, v2;
#if QT_VERSION < 0x040000
d_light.hsv(&h1, &s1, &v1);
d_dark.hsv(&h2, &s2, &v2);
#else
d_light.getHsv(&h1, &s1, &v1);
d_dark.getHsv(&h2, &s2, &v2);
#endif
painter->save();
painter->setClipRect(rect);
painter->setClipping(true);
painter->fillRect(rect, d_dark);
const int sectionSize = 2;
int numIntervalls;
if ( d_orientation == Qt::Horizontal )
numIntervalls = rect.width() / sectionSize;
else
numIntervalls = rect.height() / sectionSize;
for ( int i = 0; i < numIntervalls; i++ )
{
QRect section;
if ( d_orientation == Qt::Horizontal )
{
section.setRect(rect.x() + i * sectionSize, rect.y(),
sectionSize, rect.height());
}
else
{
section.setRect(rect.x(), rect.y() + i * sectionSize,
rect.width(), sectionSize);
}
const double ratio = i / (double)numIntervalls;
QColor c;
c.setHsv( h1 + qRound(ratio * (h2 - h1)),
s1 + qRound(ratio * (s2 - s1)),
v1 + qRound(ratio * (v2 - v1)) );
painter->fillRect(section, c);
}
painter->restore();
}

View File

@@ -0,0 +1,34 @@
#include <qwidget.h>
class ColorBar: public QWidget
{
Q_OBJECT
public:
ColorBar(Qt::Orientation = Qt::Horizontal,
QWidget * = NULL);
virtual void setOrientation(Qt::Orientation o);
Qt::Orientation orientation() const { return d_orientation; }
void setRange(const QColor &light, const QColor &dark);
void setLight(const QColor &light);
void setDark(const QColor &dark);
QColor light() const { return d_light; }
QColor dark() const { return d_dark; }
signals:
void selected(const QColor &);
protected:
virtual void mousePressEvent(QMouseEvent *);
virtual void paintEvent(QPaintEvent *);
void drawColorBar(QPainter *, const QRect &) const;
private:
Qt::Orientation d_orientation;
QColor d_light;
QColor d_dark;
};

View File

@@ -0,0 +1,62 @@
//-----------------------------------------------------------------
// A demo program showing how to use event filtering
//-----------------------------------------------------------------
#include <qapplication.h>
#include <qmainwindow.h>
#include <qwhatsthis.h>
#include <qtoolbar.h>
#include <qtoolbutton.h>
#include "plot.h"
#include "canvaspicker.h"
#include "scalepicker.h"
int main (int argc, char **argv)
{
QApplication a(argc, argv);
QMainWindow mainWindow;
QToolBar *toolBar = new QToolBar(&mainWindow);
#if QT_VERSION >= 0x040000
QAction *action = QWhatsThis::createAction(toolBar);
toolBar->addAction(action);
mainWindow.addToolBar(toolBar);
#else
(void)QWhatsThis::whatsThisButton(toolBar);
#endif
Plot *plot = new Plot(&mainWindow);
// The canvas picker handles all mouse and key
// events on the plot canvas
(void) new CanvasPicker(plot);
// The scale picker translates mouse clicks
// int o clicked() signals
ScalePicker *scalePicker = new ScalePicker(plot);
a.connect(scalePicker, SIGNAL(clicked(int, double)),
plot, SLOT(insertCurve(int, double)));
mainWindow.setCentralWidget(plot);
#if QT_VERSION < 0x040000
a.setMainWidget(&mainWindow);
#endif
mainWindow.resize(540, 400);
mainWindow.show();
const char *text =
"An useless plot to demonstrate how to use event filtering.\n\n"
"You can click on the color bar, the scales or move the wheel.\n"
"All points can be moved using the mouse or the keyboard.";
#if QT_VERSION < 0x040000
QWhatsThis::add(plot, text);
#else
plot->setWhatsThis(text);
#endif
int rv = a.exec();
return rv;
}

View File

@@ -0,0 +1,25 @@
# -*- mode: sh -*- ################################################
# Qwt Widget Library
# Copyright (C) 1997 Josef Wilgen
# Copyright (C) 2002 Uwe Rathmann
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the Qwt License, Version 1.0
###################################################################
include( ../examples.pri )
TARGET = event_filter
HEADERS = \
colorbar.h \
scalepicker.h \
canvaspicker.h \
plot.h
SOURCES = \
colorbar.cpp \
scalepicker.cpp \
canvaspicker.cpp \
plot.cpp \
event_filter.cpp

View File

@@ -0,0 +1,196 @@
#include "plot.h"
#include "colorbar.h"
#include <qevent.h>
#if QT_VERSION < 0x040000
#include <qwhatsthis.h>
#endif
#include <qwt_plot_layout.h>
#include <qwt_plot_canvas.h>
#include <qwt_plot_grid.h>
#include <qwt_plot_curve.h>
#include <qwt_symbol.h>
#include <qwt_scale_widget.h>
#include <qwt_wheel.h>
#include <stdlib.h>
Plot::Plot(QWidget *parent):
QwtPlot(parent)
{
setTitle("Interactive Plot");
setCanvasColor(Qt::darkCyan);
QwtPlotGrid *grid = new QwtPlotGrid;
grid->setMajPen(QPen(Qt::white, 0, Qt::DotLine));
grid->attach(this);
// axes
setAxisScale(QwtPlot::xBottom, 0.0, 100.0);
setAxisScale(QwtPlot::yLeft, 0.0, 100.0);
// Avoid jumping when label with 3 digits
// appear/disappear when scrolling vertically
QwtScaleDraw *sd = axisScaleDraw(QwtPlot::yLeft);
sd->setMinimumExtent( sd->extent(QPen(),
axisWidget(QwtPlot::yLeft)->font()));
plotLayout()->setAlignCanvasToScales(true);
insertCurve(Qt::Vertical, Qt::blue, 30.0);
insertCurve(Qt::Vertical, Qt::magenta, 70.0);
insertCurve(Qt::Horizontal, Qt::yellow, 30.0);
insertCurve(Qt::Horizontal, Qt::white, 70.0);
replot();
// ------------------------------------
// We add a color bar to the left axis
// ------------------------------------
QwtScaleWidget *scaleWidget = (QwtScaleWidget *)axisWidget(yLeft);
scaleWidget->setMargin(10); // area for the color bar
d_colorBar = new ColorBar(Qt::Vertical, scaleWidget);
d_colorBar->setRange(Qt::red, Qt::darkBlue);
#if QT_VERSION >= 0x040000
d_colorBar->setFocusPolicy( Qt::TabFocus );
#else
d_colorBar->setFocusPolicy( QWidget::TabFocus );
#endif
connect(d_colorBar, SIGNAL(selected(const QColor &)),
SLOT(setCanvasColor(const QColor &)));
// we need the resize events, to lay out the color bar
scaleWidget->installEventFilter(this);
// ------------------------------------
// We add a wheel to the canvas
// ------------------------------------
d_wheel = new QwtWheel(canvas());
d_wheel->setOrientation(Qt::Vertical);
d_wheel->setRange(-100, 100);
d_wheel->setValue(0.0);
d_wheel->setMass(0.2);
d_wheel->setTotalAngle(4 * 360.0);
connect(d_wheel, SIGNAL(valueChanged(double)),
SLOT(scrollLeftAxis(double)));
// we need the resize events, to lay out the wheel
canvas()->installEventFilter(this);
#if QT_VERSION < 0x040000
QWhatsThis::add(d_colorBar,
"Selecting a color will change the background of the plot.");
QWhatsThis::add(scaleWidget,
"Selecting a value at the scale will insert a new curve.");
QWhatsThis::add(d_wheel,
"With the wheel you can move the visible area.");
QWhatsThis::add(axisWidget(xBottom),
"Selecting a value at the scale will insert a new curve.");
#else
d_colorBar->setWhatsThis(
"Selecting a color will change the background of the plot.");
scaleWidget->setWhatsThis(
"Selecting a value at the scale will insert a new curve.");
d_wheel->setWhatsThis(
"With the wheel you can move the visible area.");
axisWidget(xBottom)->setWhatsThis(
"Selecting a value at the scale will insert a new curve.");
#endif
}
void Plot::setCanvasColor(const QColor &c)
{
setCanvasBackground(c);
replot();
}
void Plot::scrollLeftAxis(double value)
{
setAxisScale(yLeft, value, value + 100.0);
replot();
}
bool Plot::eventFilter(QObject *object, QEvent *e)
{
if ( e->type() == QEvent::Resize )
{
const QSize &size = ((QResizeEvent *)e)->size();
if ( object == (QObject *)axisWidget(yLeft) )
{
const QwtScaleWidget *scaleWidget = axisWidget(yLeft);
const int margin = 2;
// adjust the color bar to the scale backbone
const int x = size.width() - scaleWidget->margin() + margin;
const int w = scaleWidget->margin() - 2 * margin;
const int y = scaleWidget->startBorderDist();
const int h = size.height() -
scaleWidget->startBorderDist() - scaleWidget->endBorderDist();
d_colorBar->setGeometry(x, y, w, h);
}
if ( object == canvas() )
{
const int w = 16;
const int h = 50;
const int margin = 2;
const QRect cr = canvas()->contentsRect();
d_wheel->setGeometry(
cr.right() - margin - w, cr.center().y() - h / 2, w, h);
}
}
return QwtPlot::eventFilter(object, e);
}
void Plot::insertCurve(int axis, double base)
{
Qt::Orientation o;
if ( axis == yLeft || axis == yRight )
o = Qt::Horizontal;
else
o = Qt::Vertical;
QRgb rgb = (uint)rand();
insertCurve(o, QColor(rgb), base);
replot();
}
void Plot::insertCurve(Qt::Orientation o,
const QColor &c, double base)
{
QwtPlotCurve *curve = new QwtPlotCurve();
curve->setPen(c);
curve->setSymbol(QwtSymbol(QwtSymbol::Ellipse,
Qt::gray, c, QSize(8, 8)));
double x[10];
double y[sizeof(x) / sizeof(x[0])];
for ( uint i = 0; i < sizeof(x) / sizeof(x[0]); i++ )
{
double v = 5.0 + i * 10.0;
if ( o == Qt::Horizontal )
{
x[i] = v;
y[i] = base;
}
else
{
x[i] = base;
y[i] = v;
}
}
curve->setData(x, y, sizeof(x) / sizeof(x[0]));
curve->attach(this);
}

View File

@@ -0,0 +1,25 @@
#include <qwt_plot.h>
class ColorBar;
class QwtWheel;
class Plot: public QwtPlot
{
Q_OBJECT
public:
Plot(QWidget *parent = NULL);
virtual bool eventFilter(QObject *, QEvent *);
public slots:
void setCanvasColor(const QColor &);
void insertCurve(int axis, double base);
private slots:
void scrollLeftAxis(double);
private:
void insertCurve(Qt::Orientation, const QColor &, double base);
ColorBar *d_colorBar;
QwtWheel *d_wheel;
};

View File

@@ -0,0 +1,114 @@
#include <qevent.h>
#include <qwt_plot.h>
#include <qwt_scale_widget.h>
#include "scalepicker.h"
ScalePicker::ScalePicker(QwtPlot *plot):
QObject(plot)
{
for ( uint i = 0; i < QwtPlot::axisCnt; i++ )
{
QwtScaleWidget *scaleWidget = (QwtScaleWidget *)plot->axisWidget(i);
if ( scaleWidget )
scaleWidget->installEventFilter(this);
}
}
bool ScalePicker::eventFilter(QObject *object, QEvent *e)
{
if ( object->inherits("QwtScaleWidget") &&
e->type() == QEvent::MouseButtonPress )
{
mouseClicked((const QwtScaleWidget *)object,
((QMouseEvent *)e)->pos());
return true;
}
return QObject::eventFilter(object, e);
}
void ScalePicker::mouseClicked(const QwtScaleWidget *scale, const QPoint &pos)
{
QRect rect = scaleRect(scale);
int margin = 10; // 10 pixels tolerance
rect.setRect(rect.x() - margin, rect.y() - margin,
rect.width() + 2 * margin, rect.height() + 2 * margin);
if ( rect.contains(pos) ) // No click on the title
{
// translate the position in a value on the scale
double value = 0.0;
int axis = -1;
const QwtScaleDraw *sd = scale->scaleDraw();
switch(scale->alignment())
{
case QwtScaleDraw::LeftScale:
{
value = sd->map().invTransform(pos.y());
axis = QwtPlot::yLeft;
break;
}
case QwtScaleDraw::RightScale:
{
value = sd->map().invTransform(pos.y());
axis = QwtPlot::yRight;
break;
}
case QwtScaleDraw::BottomScale:
{
value = sd->map().invTransform(pos.x());
axis = QwtPlot::xBottom;
break;
}
case QwtScaleDraw::TopScale:
{
value = sd->map().invTransform(pos.x());
axis = QwtPlot::xTop;
break;
}
}
emit clicked(axis, value);
}
}
// The rect of a scale without the title
QRect ScalePicker::scaleRect(const QwtScaleWidget *scale) const
{
const int bld = scale->margin();
const int mjt = scale->scaleDraw()->majTickLength();
const int sbd = scale->startBorderDist();
const int ebd = scale->endBorderDist();
QRect rect;
switch(scale->alignment())
{
case QwtScaleDraw::LeftScale:
{
rect.setRect(scale->width() - bld - mjt, sbd,
mjt, scale->height() - sbd - ebd);
break;
}
case QwtScaleDraw::RightScale:
{
rect.setRect(bld, sbd,
mjt, scale->height() - sbd - ebd);
break;
}
case QwtScaleDraw::BottomScale:
{
rect.setRect(sbd, bld,
scale->width() - sbd - ebd, mjt);
break;
}
case QwtScaleDraw::TopScale:
{
rect.setRect(sbd, scale->height() - bld - mjt,
scale->width() - sbd - ebd, mjt);
break;
}
}
return rect;
}

View File

@@ -0,0 +1,20 @@
#include <qobject.h>
#include <qrect.h>
class QwtPlot;
class QwtScaleWidget;
class ScalePicker: public QObject
{
Q_OBJECT
public:
ScalePicker(QwtPlot *plot);
virtual bool eventFilter(QObject *, QEvent *);
signals:
void clicked(int axis, double value);
private:
void mouseClicked(const QwtScaleWidget *, const QPoint &);
QRect scaleRect(const QwtScaleWidget *) const;
};

61
qwt/examples/examples.pri Normal file
View File

@@ -0,0 +1,61 @@
# -*- mode: sh -*- ################################################
# Qwt Widget Library
# Copyright (C) 1997 Josef Wilgen
# Copyright (C) 2002 Uwe Rathmann
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the Qwt License, Version 1.0
###################################################################
QWT_ROOT = ../..
include( $${QWT_ROOT}/qwtconfig.pri )
SUFFIX_STR =
VVERSION = $$[QT_VERSION]
isEmpty(VVERSION) {
# Qt 3
debug {
SUFFIX_STR = $${DEBUG_SUFFIX}
}
else {
SUFFIX_STR = $${RELEASE_SUFFIX}
}
}
else {
CONFIG(debug, debug|release) {
SUFFIX_STR = $${DEBUG_SUFFIX}
}
else {
SUFFIX_STR = $${RELEASE_SUFFIX}
}
}
TEMPLATE = app
MOC_DIR = moc
INCLUDEPATH += $${QWT_ROOT}/src
DEPENDPATH += $${QWT_ROOT}/src
OBJECTS_DIR = obj$${SUFFIX_STR}
DESTDIR = $${QWT_ROOT}/examples/bin$${SUFFIX_STR}
QWTLIB = qwt$${SUFFIX_STR}
win32 {
contains(CONFIG, QwtDll) {
DEFINES += QT_DLL QWT_DLL
QWTLIB = $${QWTLIB}$${VER_MAJ}
}
win32-msvc:LIBS += $${QWT_ROOT}/lib/$${QWTLIB}.lib
win32-msvc.net:LIBS += $${QWT_ROOT}/lib/$${QWTLIB}.lib
win32-msvc2002:LIBS += $${QWT_ROOT}/lib/$${QWTLIB}.lib
win32-msvc2003:LIBS += $${QWT_ROOT}/lib/$${QWTLIB}.lib
win32-msvc2005:LIBS += $${QWT_ROOT}/lib/$${QWTLIB}.lib
win32-msvc2008:LIBS += $${QWT_ROOT}/lib/$${QWTLIB}.lib
win32-g++:LIBS += -L$${QWT_ROOT}/lib -l$${QWTLIB}
}
else {
LIBS += -L$${QWT_ROOT}/lib -l$${QWTLIB}
}

49
qwt/examples/examples.pro Normal file
View File

@@ -0,0 +1,49 @@
# -*- mode: sh -*- ################################################
# Qwt Widget Library
# Copyright (C) 1997 Josef Wilgen
# Copyright (C) 2002 Uwe Rathmann
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the Qwt License, Version 1.0
###################################################################
include( ../qwtconfig.pri )
TEMPLATE = subdirs
contains(CONFIG, QwtPlot) {
SUBDIRS += \
cpuplot \
curvdemo1 \
curvdemo2 \
simple_plot \
realtime_plot \
spectrogram \
histogram
contains(CONFIG, QwtWidgets) {
SUBDIRS += \
bode \
data_plot \
event_filter
}
contains(CONFIG, QwtSVGItem) {
SUBDIRS += \
svgmap
}
}
contains(CONFIG, QwtWidgets) {
SUBDIRS += \
sysinfo \
radio \
dials \
sliders
}

View File

@@ -0,0 +1,19 @@
# -*- mode: sh -*- ################################################
# Qwt Widget Library
# Copyright (C) 1997 Josef Wilgen
# Copyright (C) 2002 Uwe Rathmann
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the Qwt License, Version 1.0
###################################################################
include( ../examples.pri )
TARGET = histogram
SOURCES = \
main.cpp \
histogram_item.cpp
INCLUDES = \
histogram_item.h

View File

@@ -0,0 +1,283 @@
#include <qstring.h>
#include <qpainter.h>
#include <qwt_plot.h>
#include <qwt_interval_data.h>
#include <qwt_painter.h>
#include <qwt_scale_map.h>
#include "histogram_item.h"
class HistogramItem::PrivateData
{
public:
int attributes;
QwtIntervalData data;
QColor color;
double reference;
};
HistogramItem::HistogramItem(const QwtText &title):
QwtPlotItem(title)
{
init();
}
HistogramItem::HistogramItem(const QString &title):
QwtPlotItem(QwtText(title))
{
init();
}
HistogramItem::~HistogramItem()
{
delete d_data;
}
void HistogramItem::init()
{
d_data = new PrivateData();
d_data->reference = 0.0;
d_data->attributes = HistogramItem::Auto;
setItemAttribute(QwtPlotItem::AutoScale, true);
setItemAttribute(QwtPlotItem::Legend, true);
setZ(20.0);
}
void HistogramItem::setBaseline(double reference)
{
if ( d_data->reference != reference )
{
d_data->reference = reference;
itemChanged();
}
}
double HistogramItem::baseline() const
{
return d_data->reference;
}
void HistogramItem::setData(const QwtIntervalData &data)
{
d_data->data = data;
itemChanged();
}
const QwtIntervalData &HistogramItem::data() const
{
return d_data->data;
}
void HistogramItem::setColor(const QColor &color)
{
if ( d_data->color != color )
{
d_data->color = color;
itemChanged();
}
}
QColor HistogramItem::color() const
{
return d_data->color;
}
QwtDoubleRect HistogramItem::boundingRect() const
{
QwtDoubleRect rect = d_data->data.boundingRect();
if ( !rect.isValid() )
return rect;
if ( d_data->attributes & Xfy )
{
rect = QwtDoubleRect( rect.y(), rect.x(),
rect.height(), rect.width() );
if ( rect.left() > d_data->reference )
rect.setLeft( d_data->reference );
else if ( rect.right() < d_data->reference )
rect.setRight( d_data->reference );
}
else
{
if ( rect.bottom() < d_data->reference )
rect.setBottom( d_data->reference );
else if ( rect.top() > d_data->reference )
rect.setTop( d_data->reference );
}
return rect;
}
int HistogramItem::rtti() const
{
return QwtPlotItem::Rtti_PlotHistogram;
}
void HistogramItem::setHistogramAttribute(HistogramAttribute attribute, bool on)
{
if ( bool(d_data->attributes & attribute) == on )
return;
if ( on )
d_data->attributes |= attribute;
else
d_data->attributes &= ~attribute;
itemChanged();
}
bool HistogramItem::testHistogramAttribute(HistogramAttribute attribute) const
{
return d_data->attributes & attribute;
}
void HistogramItem::draw(QPainter *painter, const QwtScaleMap &xMap,
const QwtScaleMap &yMap, const QRect &) const
{
const QwtIntervalData &iData = d_data->data;
painter->setPen(QPen(d_data->color));
const int x0 = xMap.transform(baseline());
const int y0 = yMap.transform(baseline());
for ( int i = 0; i < (int)iData.size(); i++ )
{
if ( d_data->attributes & HistogramItem::Xfy )
{
const int x2 = xMap.transform(iData.value(i));
if ( x2 == x0 )
continue;
int y1 = yMap.transform( iData.interval(i).minValue());
int y2 = yMap.transform( iData.interval(i).maxValue());
if ( y1 > y2 )
qSwap(y1, y2);
if ( i < (int)iData.size() - 2 )
{
const int yy1 = yMap.transform(iData.interval(i+1).minValue());
const int yy2 = yMap.transform(iData.interval(i+1).maxValue());
if ( y2 == qwtMin(yy1, yy2) )
{
const int xx2 = xMap.transform(
iData.interval(i+1).minValue());
if ( xx2 != x0 && ( (xx2 < x0 && x2 < x0) ||
(xx2 > x0 && x2 > x0) ) )
{
// One pixel distance between neighboured bars
y2++;
}
}
}
drawBar(painter, Qt::Horizontal,
QRect(x0, y1, x2 - x0, y2 - y1));
}
else
{
const int y2 = yMap.transform(iData.value(i));
if ( y2 == y0 )
continue;
int x1 = xMap.transform(iData.interval(i).minValue());
int x2 = xMap.transform(iData.interval(i).maxValue());
if ( x1 > x2 )
qSwap(x1, x2);
if ( i < (int)iData.size() - 2 )
{
const int xx1 = xMap.transform(iData.interval(i+1).minValue());
const int xx2 = xMap.transform(iData.interval(i+1).maxValue());
if ( x2 == qwtMin(xx1, xx2) )
{
const int yy2 = yMap.transform(iData.value(i+1));
if ( yy2 != y0 && ( (yy2 < y0 && y2 < y0) ||
(yy2 > y0 && y2 > y0) ) )
{
// One pixel distance between neighboured bars
x2--;
}
}
}
drawBar(painter, Qt::Vertical,
QRect(x1, y0, x2 - x1, y2 - y0) );
}
}
}
void HistogramItem::drawBar(QPainter *painter,
Qt::Orientation, const QRect& rect) const
{
painter->save();
const QColor color(painter->pen().color());
#if QT_VERSION >= 0x040000
const QRect r = rect.normalized();
#else
const QRect r = rect.normalize();
#endif
const int factor = 125;
const QColor light(color.light(factor));
const QColor dark(color.dark(factor));
painter->setBrush(color);
painter->setPen(Qt::NoPen);
QwtPainter::drawRect(painter, r.x() + 1, r.y() + 1,
r.width() - 2, r.height() - 2);
painter->setBrush(Qt::NoBrush);
painter->setPen(QPen(light, 2));
#if QT_VERSION >= 0x040000
QwtPainter::drawLine(painter,
r.left() + 1, r.top() + 2, r.right() + 1, r.top() + 2);
#else
QwtPainter::drawLine(painter,
r.left(), r.top() + 2, r.right() + 1, r.top() + 2);
#endif
painter->setPen(QPen(dark, 2));
#if QT_VERSION >= 0x040000
QwtPainter::drawLine(painter,
r.left() + 1, r.bottom(), r.right() + 1, r.bottom());
#else
QwtPainter::drawLine(painter,
r.left(), r.bottom(), r.right() + 1, r.bottom());
#endif
painter->setPen(QPen(light, 1));
#if QT_VERSION >= 0x040000
QwtPainter::drawLine(painter,
r.left(), r.top() + 1, r.left(), r.bottom());
QwtPainter::drawLine(painter,
r.left() + 1, r.top() + 2, r.left() + 1, r.bottom() - 1);
#else
QwtPainter::drawLine(painter,
r.left(), r.top() + 1, r.left(), r.bottom() + 1);
QwtPainter::drawLine(painter,
r.left() + 1, r.top() + 2, r.left() + 1, r.bottom());
#endif
painter->setPen(QPen(dark, 1));
#if QT_VERSION >= 0x040000
QwtPainter::drawLine(painter,
r.right() + 1, r.top() + 1, r.right() + 1, r.bottom());
QwtPainter::drawLine(painter,
r.right(), r.top() + 2, r.right(), r.bottom() - 1);
#else
QwtPainter::drawLine(painter,
r.right() + 1, r.top() + 1, r.right() + 1, r.bottom() + 1);
QwtPainter::drawLine(painter,
r.right(), r.top() + 2, r.right(), r.bottom());
#endif
painter->restore();
}

View File

@@ -0,0 +1,64 @@
/* -*- mode: C++ ; c-file-style: "stroustrup" -*- *****************************
* Qwt Widget Library
* Copyright (C) 1997 Josef Wilgen
* Copyright (C) 2002 Uwe Rathmann
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the Qwt License, Version 1.0
*****************************************************************************/
#ifndef HISTOGRAM_ITEM_H
#define HISTOGRAM_ITEM_H
#include <qglobal.h>
#include <qcolor.h>
#include "qwt_plot_item.h"
class QwtIntervalData;
class QString;
class HistogramItem: public QwtPlotItem
{
public:
explicit HistogramItem(const QString &title = QString::null);
explicit HistogramItem(const QwtText &title);
virtual ~HistogramItem();
void setData(const QwtIntervalData &data);
const QwtIntervalData &data() const;
void setColor(const QColor &);
QColor color() const;
virtual QwtDoubleRect boundingRect() const;
virtual int rtti() const;
virtual void draw(QPainter *, const QwtScaleMap &xMap,
const QwtScaleMap &yMap, const QRect &) const;
void setBaseline(double reference);
double baseline() const;
enum HistogramAttribute
{
Auto = 0,
Xfy = 1
};
void setHistogramAttribute(HistogramAttribute, bool on = true);
bool testHistogramAttribute(HistogramAttribute) const;
protected:
virtual void drawBar(QPainter *,
Qt::Orientation o, const QRect &) const;
private:
void init();
class PrivateData;
PrivateData *d_data;
};
#endif

View File

@@ -0,0 +1,60 @@
#include <stdlib.h>
#include <qapplication.h>
#include <qpen.h>
#include <qwt_plot.h>
#include <qwt_plot_grid.h>
#include <qwt_plot_marker.h>
#include <qwt_interval_data.h>
#include "histogram_item.h"
int main(int argc, char **argv)
{
QApplication a(argc, argv);
QwtPlot plot;
plot.setCanvasBackground(QColor(Qt::white));
plot.setTitle("Histogram");
QwtPlotGrid *grid = new QwtPlotGrid;
grid->enableXMin(true);
grid->enableYMin(true);
grid->setMajPen(QPen(Qt::black, 0, Qt::DotLine));
grid->setMinPen(QPen(Qt::gray, 0 , Qt::DotLine));
grid->attach(&plot);
HistogramItem *histogram = new HistogramItem();
histogram->setColor(Qt::darkCyan);
const int numValues = 20;
QwtArray<QwtDoubleInterval> intervals(numValues);
QwtArray<double> values(numValues);
double pos = 0.0;
for ( int i = 0; i < (int)intervals.size(); i++ )
{
const int width = 5 + rand() % 15;
const int value = rand() % 100;
intervals[i] = QwtDoubleInterval(pos, pos + double(width));
values[i] = value;
pos += width;
}
histogram->setData(QwtIntervalData(intervals, values));
histogram->attach(&plot);
plot.setAxisScale(QwtPlot::yLeft, 0.0, 100.0);
plot.setAxisScale(QwtPlot::xBottom, 0.0, pos);
plot.replot();
#if QT_VERSION < 0x040000
a.setMainWidget(&plot);
#endif
plot.resize(600,400);
plot.show();
return a.exec();
}

View File

@@ -0,0 +1,182 @@
#include "ampfrm.h"
#include <qwt_knob.h>
#include <qlayout.h>
#include <qlabel.h>
#include <qfont.h>
#include <qpen.h>
#include <qevent.h>
#include <qwt_thermo.h>
#include <qwt_round_scale_draw.h>
#include <qwt_math.h>
class Knob: public QWidget
{
public:
Knob(const QString &title, double min, double max, QWidget *parent):
QWidget(parent)
{
d_knob = new QwtKnob(this);
d_knob->setRange(min, max, 0,1);
d_knob->setScaleMaxMajor(10);
d_knob->setKnobWidth(50);
d_label = new QLabel(title, this);
d_label->setAlignment(Qt::AlignTop | Qt::AlignHCenter);
setSizePolicy(QSizePolicy::MinimumExpanding,
QSizePolicy::MinimumExpanding);
}
virtual QSize sizeHint() const
{
QSize sz1 = d_knob->sizeHint();
QSize sz2 = d_label->sizeHint();
const int w = qwtMax(sz1.width(), sz2.width());
const int h = sz1.height() + sz2.height();
int off = d_knob->scaleDraw()->extent(QPen(), d_knob->font());
off -= 10; // spacing
return QSize(w, h - off);
}
double value() const
{
return d_knob->value();
}
protected:
virtual void resizeEvent(QResizeEvent *e)
{
const QSize sz = e->size();
int h = d_label->sizeHint().height();
d_label->setGeometry(0, sz.height() - h,
sz.width(), h);
h = d_knob->sizeHint().height();
int off = d_knob->scaleDraw()->extent(QPen(), d_knob->font());
off -= 10; // spacing
d_knob->setGeometry(0, d_label->pos().y() - h + off,
sz.width(), h);
}
private:
QwtKnob *d_knob;
QLabel *d_label;
};
class Thermo: public QWidget
{
public:
Thermo(const QString &title, QWidget *parent):
QWidget(parent)
{
d_thermo = new QwtThermo(this);
d_thermo->setPipeWidth(6);
d_thermo->setRange(-40,10);
d_thermo->setFillColor(Qt::green);
d_thermo->setAlarmColor(Qt::red);
d_thermo->setAlarmLevel(0.0);
d_thermo->setAlarmEnabled(true);
QLabel *label = new QLabel(title, this);
label->setAlignment(Qt::AlignTop | Qt::AlignLeft);
QVBoxLayout *layout = new QVBoxLayout(this);
layout->setMargin(0);
layout->setSpacing(0);
layout->addWidget(d_thermo, 10);
layout->addWidget(label);
}
void setValue(double value)
{
d_thermo->setValue(value);
}
private:
QwtThermo *d_thermo;
};
AmpFrame::AmpFrame(QWidget *p):
QFrame(p)
{
d_knbVolume = new Knob("Volume", 0.0, 10.0, this);
d_knbBalance = new Knob("Balance", -10.0, 10.0, this);
d_knbTreble = new Knob("Treble", -10.0, 10.0, this);
d_knbBass = new Knob("Bass", -10.0, 10.0, this);
d_thmLeft = new Thermo("Left [dB]", this);
d_thmRight = new Thermo("Right [dB]", this);
QHBoxLayout *layout = new QHBoxLayout(this);
layout->setSpacing(0);
layout->setMargin(10);
layout->addWidget(d_knbVolume);
layout->addWidget(d_knbBalance);
layout->addWidget(d_knbTreble);
layout->addWidget(d_knbBass);
layout->addSpacing(20);
layout->addStretch(10);
layout->addWidget(d_thmLeft);
layout->addSpacing(10);
layout->addWidget(d_thmRight);
(void)startTimer(50);
}
void AmpFrame::timerEvent(QTimerEvent *)
{
static double phs = 0;
//
// This amplifier generates its own input signal...
//
const double sig_bass = (1.0 + 0.1 * d_knbBass->value())
* sin(13.0 * phs);
const double sig_mid_l = sin(17.0 * phs);
const double sig_mid_r = cos(17.5 * phs);
const double sig_trbl_l = 0.5 * (1.0 + 0.1 * d_knbTreble->value())
* sin(35.0 * phs);
const double sig_trbl_r = 0.5 * (1.0 + 0.1 * d_knbTreble->value())
* sin(34.0 * phs);
double sig_l = 0.05 * d_master * d_knbVolume->value()
* qwtSqr(sig_bass + sig_mid_l + sig_trbl_l);
double sig_r = 0.05 * d_master * d_knbVolume->value()
* qwtSqr(sig_bass + sig_mid_r + sig_trbl_r);
double balance = 0.1 * d_knbBalance->value();
if (balance > 0)
sig_l *= (1.0 - balance);
else
sig_r *= (1.0 + balance);
if (sig_l > 0.01)
sig_l = 20.0 * log10(sig_l);
else
sig_l = -40.0;
if (sig_r > 0.01)
sig_r = 20.0 * log10(sig_r);
else
sig_r = - 40.0;
d_thmLeft->setValue(sig_l);
d_thmRight->setValue(sig_r);
phs += M_PI / 100;
if (phs > M_PI)
phs = 0;
}
void AmpFrame::setMaster(double v)
{
d_master = v;
}

View File

@@ -0,0 +1,29 @@
#include <qframe.h>
class Knob;
class Thermo;
class AmpFrame : public QFrame
{
Q_OBJECT
public:
AmpFrame(QWidget *);
public slots:
void setMaster(double v);
protected:
void timerEvent(QTimerEvent *);
private:
Knob *d_knbVolume;
Knob *d_knbBalance;
Knob *d_knbTreble;
Knob *d_knbBass;
Thermo *d_thmLeft;
Thermo *d_thmRight;
double d_master;
};

View File

@@ -0,0 +1,40 @@
#include <qapplication.h>
#include <qlayout.h>
#include "tunerfrm.h"
#include "ampfrm.h"
#include "radio.h"
MainWin::MainWin():
QWidget()
{
TunerFrame *frmTuner = new TunerFrame(this);
frmTuner->setFrameStyle(QFrame::Panel|QFrame::Raised);
AmpFrame *frmAmp = new AmpFrame(this);
frmAmp->setFrameStyle(QFrame::Panel|QFrame::Raised);
QVBoxLayout *layout = new QVBoxLayout(this);
layout->setMargin(0);
layout->setSpacing(0);
layout->addWidget(frmTuner);
layout->addWidget(frmAmp);
connect(frmTuner, SIGNAL(fieldChanged(double)),
frmAmp, SLOT(setMaster(double)));
frmTuner->setFreq(90.0);
}
int main (int argc, char **argv)
{
QApplication a(argc, argv);
MainWin w;
#if QT_VERSION < 0x040000
a.setMainWidget(&w);
#endif
w.show();
return a.exec();
}

View File

@@ -0,0 +1,9 @@
#include <qwidget.h>
class MainWin : public QWidget
{
public:
MainWin();
};

View File

@@ -0,0 +1,22 @@
# -*- mode: sh -*- ################################################
# Qwt Widget Library
# Copyright (C) 1997 Josef Wilgen
# Copyright (C) 2002 Uwe Rathmann
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the Qwt License, Version 1.0
###################################################################
include( ../examples.pri )
TARGET = radio
HEADERS = \
radio.h \
ampfrm.h \
tunerfrm.h
SOURCES = \
radio.cpp \
ampfrm.cpp \
tunerfrm.cpp

Some files were not shown because too many files have changed in this diff Show More