Permalink
Browse files

Added examples for qwt library

  • Loading branch information...
1 parent 3185704 commit ad6f2a2c454d56f5e2e772eed73e3c791cf8f157 Luis Armendariz committed Apr 29, 2008
Showing with 236 additions and 0 deletions.
  1. +15 −0 qwt/common.pro
  2. +75 −0 qwt/simpleplot/simpleplot.cpp
  3. +4 −0 qwt/simpleplot/simpleplot.pro
  4. +37 −0 qwt/svgmap/main.cpp
  5. +68 −0 qwt/svgmap/plot.cpp
  6. +22 −0 qwt/svgmap/plot.h
  7. +15 −0 qwt/svgmap/svgmap.pro
View
@@ -0,0 +1,15 @@
+TEMPLATE = app
+CONFIG += qt warn_on thread debug
+UI_DIR = tmp
+MOC_DIR = tmp
+OBJECTS_DIR = tmp
+VVERSION = $$[QT_VERSION]
+INCLUDEPATH += /usr/include/qwtplot3d-qt4
+unix:LIBS += -lqwtplot3d-qt4
+DEPENDPATH = $$INCLUDEPATH
+DESTDIR = ../bin
+
+linux-g++:QMAKE_CXXFLAGS += -fno-exceptions
+
+MYVERSION = $$[QMAKE_VERSION]
+
@@ -0,0 +1,75 @@
+// ---------------------------------------
+// simpleplot.cpp
+//
+// A simple example which shows how to use SurfacePlot
+//----------------------------------------
+
+#include <cmath>
+#include <qapplication.h>
+#include <qwt3d_surfaceplot.h>
+#include <qwt3d_function.h>
+
+using namespace Qwt3D;
+
+class Rosenbrock : public Function
+{
+public:
+ Rosenbrock(SurfacePlot* pw) : Function(pw)
+ {
+ }
+
+ double operator()(double x, double y)
+ {
+ return log((1-x)*(1-x) + 100*(y-x*x)*(y-x*x)) / 8;
+ }
+};
+
+class Plot : public SurfacePlot
+{
+public:
+ Plot();
+};
+
+
+Plot::Plot()
+{
+ setTitle("A Simple SurfacePlot Demonstration");
+
+ Rosenbrock rosenbrock(this);
+
+ rosenbrock.setMesh(41, 31);
+ rosenbrock.setDomain(-1.73, 1.5, -1.5, 1.5);
+ rosenbrock.setMinZ(-10);
+
+ rosenbrock.create();
+
+ setRotation(30, 0, 15);
+ setScale(1, 1, 1);
+ setShift(0.15, 0, 0);
+ setZoom(0.9);
+
+ for (unsigned i = 0; i != coordinates()->axes.size(); ++i)
+ {
+ coordinates()->axes[i].setMajors(7);
+ coordinates()->axes[i].setMinors(4);
+ }
+
+ coordinates()->axes[X1].setLabelString("x-axis");
+ coordinates()->axes[Y1].setLabelString("y-axis");
+ coordinates()->axes[Z1].setLabelString(QChar(0x38f)); // // Omega - see http://www.unicode.org/charts/
+
+ setCoordinateStyle(BOX);
+
+ updateData();
+ updateGL();
+}
+
+
+int main(int argc, char *argv[])
+{
+ QApplication a(argc, argv);
+ Plot plot;
+ plot.resize(800, 600);
+ plot.show();
+ return a.exec();
+}
@@ -0,0 +1,4 @@
+include( ../common.pro )
+
+SOURCES = simpleplot.cpp
+
View
@@ -0,0 +1,37 @@
+#include <qapplication.h>
+#include <qmainwindow.h>
+#include <qtoolbar.h>
+#include <qtoolbutton.h>
+#include "plot.h"
+
+class MainWindow : public QMainWindow
+{
+public:
+ MainWindow(QWidget *parent = NULL) : QMainWindow(parent)
+ {
+ Plot *plot = new Plot(this);
+ setCentralWidget(plot);
+
+ QToolBar *toolBar = new QToolBar(this);
+ QToolButton *btnLoad = new QToolButton(toolBar);
+ btnLoad->setText("Load SVG");
+ btnLoad->setToolButtonStyle(Qt::ToolButtonTextUnderIcon);
+ toolBar->addWidget(btnLoad);
+ addToolBar(toolBar);
+
+ connect(btnLoad, SIGNAL(clicked()), plot, SLOT(loadSVG()));
+ }
+};
+
+
+int main(int argc, char *argv[])
+{
+ QApplication a(argc, argv);
+
+ MainWindow w;
+ w.resize(600, 400);
+ w.show();
+
+ int rv = a.exec();
+ return rv;
+}
View
@@ -0,0 +1,68 @@
+#include <qfiledialog.h>
+#include <qwt_plot_svgitem.h>
+#include <qwt_plot_grid.h>
+#include <qwt_plot_layout.h>
+#include <qwt_plot_canvas.h>
+#include <qwt_plot_panner.h>
+#include <qwt_plot_magnifier.h>
+#include "plot.h"
+
+Plot::Plot(QWidget *parent) :
+ QwtPlot(parent),
+ d_mapItem(NULL),
+ d_mapRect(0.0, 0.0, 100.0, 100.0)
+{
+ /* d_mapRect is only a reference for zooming, but th ranges
+ * are nothing useful for the user. So we hide the axes.
+ */
+ plotLayout()->setCanvasMargin(0);
+ for (int axis = 0; axis < QwtPlot::axisCnt; axis++)
+ {
+ enableAxis(axis, false);
+ }
+
+ /* Navigation:
+ * Left Mouse Button : Panning
+ * Mouse Wheel : Zooming In/Out
+ * Right Mouse Button : Reset to initial
+ */
+ (void)(new QwtPlotPanner(canvas()));
+ (void)(new QwtPlotMagnifier(canvas()));
+
+ using namespace Qt;
+ canvas()->setFocusPolicy(WheelFocus);
+ rescale();
+
+}
+
+
+void Plot::loadSVG()
+{
+ QString dir;
+
+ const QString fileName = QFileDialog::getOpenFileName(NULL,
+ "Load a Scaleable Vector Graphic (SVG) Map",
+ dir, "SVG Files (*.svg)");
+
+ if (!fileName.isEmpty())
+ {
+ if (d_mapItem == NULL)
+ {
+ d_mapItem = new QwtPlotSvgItem();
+ d_mapItem->attach(this);
+ }
+
+ d_mapItem->loadFile(d_mapRect, fileName);
+ rescale();
+
+ replot();
+ }
+}
+
+
+void Plot::rescale()
+{
+ setAxisScale(QwtPlot::xBottom, d_mapRect.left(), d_mapRect.right());
+ setAxisScale(QwtPlot::yLeft, d_mapRect.top(), d_mapRect.bottom());
+}
+
View
@@ -0,0 +1,22 @@
+#include <qwt_plot.h>
+#include <qwt_double_rect.h>
+
+class QwtPlotSvgItem;
+
+class Plot : public QwtPlot
+{
+ Q_OBJECT
+
+public:
+ Plot(QWidget * = NULL);
+
+public slots:
+ void loadSVG();
+
+private:
+ void rescale();
+
+private:
+ QwtPlotSvgItem *d_mapItem;
+ const QwtDoubleRect d_mapRect;
+};
View
@@ -0,0 +1,15 @@
+######################################################################
+# Automatically generated by qmake (2.01a) Mon Apr 28 17:07:33 2008
+######################################################################
+
+TEMPLATE = app
+TARGET =
+DEPENDPATH += .
+INCLUDEPATH += .
+INCLUDEPATH += /usr/include/qwt-qt4/
+unix:LIBS += -lqwt-qt4
+
+# Input
+HEADERS += plot.h
+SOURCES += main.cpp plot.cpp
+

0 comments on commit ad6f2a2

Please sign in to comment.