@@ -0,0 +1,81 | |||||
|
1 | #include "qchartview.h" | |||
|
2 | #include "qchart.h" | |||
|
3 | #include <QGraphicsView> | |||
|
4 | #include <QGraphicsScene> | |||
|
5 | #include <QRubberBand> | |||
|
6 | #include <QResizeEvent> | |||
|
7 | #include <QDebug> | |||
|
8 | ||||
|
9 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |||
|
10 | ||||
|
11 | QChartView::QChartView(QWidget *parent) : | |||
|
12 | QGraphicsView(parent), | |||
|
13 | m_scene(new QGraphicsScene()), | |||
|
14 | m_chart(new QChart()), | |||
|
15 | m_rubberBand(0), | |||
|
16 | m_showRubberBand(false) | |||
|
17 | { | |||
|
18 | setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); | |||
|
19 | setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); | |||
|
20 | setScene(m_scene); | |||
|
21 | m_chart->setMargin(50); | |||
|
22 | m_scene->addItem(m_chart); | |||
|
23 | setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); | |||
|
24 | } | |||
|
25 | ||||
|
26 | QChartView::~QChartView() | |||
|
27 | { | |||
|
28 | } | |||
|
29 | ||||
|
30 | void QChartView::resizeEvent(QResizeEvent *event) | |||
|
31 | { | |||
|
32 | m_scene->setSceneRect(0,0,size().width(),size().height()); | |||
|
33 | m_chart->setSize(size()); | |||
|
34 | QWidget::resizeEvent(event); | |||
|
35 | } | |||
|
36 | ||||
|
37 | ||||
|
38 | void QChartView::addSeries(QChartSeries* series) | |||
|
39 | { | |||
|
40 | m_chart->addSeries(series); | |||
|
41 | } | |||
|
42 | ||||
|
43 | QChartSeries* QChartView::createSeries(QList<qreal> x, QList<qreal> y, QChartSeries::QChartSeriesType type) | |||
|
44 | { | |||
|
45 | ||||
|
46 | return m_chart->createSeries(x, y, type); | |||
|
47 | } | |||
|
48 | ||||
|
49 | void QChartView::mousePressEvent(QMouseEvent *event) | |||
|
50 | { | |||
|
51 | int margin = m_chart->margin(); | |||
|
52 | ||||
|
53 | QRect rect(margin,margin,width()-2*margin,height()-2*margin); | |||
|
54 | ||||
|
55 | m_origin = event->pos(); | |||
|
56 | ||||
|
57 | if (!rect.contains(m_origin)) return; | |||
|
58 | ||||
|
59 | if (!m_rubberBand) | |||
|
60 | m_rubberBand = new QRubberBand(QRubberBand::Rectangle, this); | |||
|
61 | m_rubberBand->setGeometry(QRect(m_origin, QSize())); | |||
|
62 | m_showRubberBand=true; | |||
|
63 | m_rubberBand->show(); | |||
|
64 | ||||
|
65 | } | |||
|
66 | ||||
|
67 | void QChartView::mouseMoveEvent(QMouseEvent *event) | |||
|
68 | { | |||
|
69 | if(m_showRubberBand) | |||
|
70 | m_rubberBand->setGeometry(QRect(m_origin, event->pos()).normalized()); | |||
|
71 | } | |||
|
72 | ||||
|
73 | void QChartView::mouseReleaseEvent(QMouseEvent *event) | |||
|
74 | { | |||
|
75 | if(m_showRubberBand) { | |||
|
76 | m_rubberBand->hide(); | |||
|
77 | m_showRubberBand=false; | |||
|
78 | } | |||
|
79 | } | |||
|
80 | ||||
|
81 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -0,0 +1,46 | |||||
|
1 | #ifndef QCHARTWIDGET_H | |||
|
2 | #define QCHARTWIDGET_H | |||
|
3 | ||||
|
4 | #include "qchartglobal.h" | |||
|
5 | #include "qchartseries.h" | |||
|
6 | #include <QGraphicsView> | |||
|
7 | ||||
|
8 | class QGraphicsScene; | |||
|
9 | class QRubberBand; | |||
|
10 | ||||
|
11 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |||
|
12 | ||||
|
13 | class QChart; | |||
|
14 | ||||
|
15 | class QTCOMMERCIALCHART_EXPORT QChartView : public QGraphicsView | |||
|
16 | { | |||
|
17 | public: | |||
|
18 | explicit QChartView(QWidget *parent = 0); | |||
|
19 | ~QChartView(); | |||
|
20 | ||||
|
21 | //implement from QWidget | |||
|
22 | void resizeEvent(QResizeEvent *event); | |||
|
23 | ||||
|
24 | // TODO: addSeries and createSeries are optional solutions | |||
|
25 | void addSeries(QChartSeries* series); | |||
|
26 | QChartSeries* createSeries(QList<qreal> x, QList<qreal> y, QChartSeries::QChartSeriesType type); | |||
|
27 | ||||
|
28 | protected: | |||
|
29 | void mouseMoveEvent (QMouseEvent *event); | |||
|
30 | void mousePressEvent (QMouseEvent *event); | |||
|
31 | void mouseReleaseEvent (QMouseEvent *event); | |||
|
32 | ||||
|
33 | private: | |||
|
34 | QGraphicsScene *m_scene; | |||
|
35 | QChart* m_chart; | |||
|
36 | QRubberBand *m_rubberBand; | |||
|
37 | QPoint m_origin; | |||
|
38 | bool m_showRubberBand; | |||
|
39 | Q_DISABLE_COPY(QChartView) | |||
|
40 | ||||
|
41 | ||||
|
42 | }; | |||
|
43 | ||||
|
44 | QTCOMMERCIALCHART_END_NAMESPACE | |||
|
45 | ||||
|
46 | #endif // QCHARTWIDGET_H |
@@ -1,55 +1,55 | |||||
1 | #include <QApplication> |
|
1 | #include <QApplication> | |
2 | #include <QMainWindow> |
|
2 | #include <QMainWindow> | |
3 |
#include <qchart |
|
3 | #include <qchartview.h> | |
4 | #include <qxychartseries.h> |
|
4 | #include <qxychartseries.h> | |
5 | #include <qchart.h> |
|
5 | #include <qchart.h> | |
6 | #include <cmath> |
|
6 | #include <cmath> | |
7 |
|
7 | |||
8 | QTCOMMERCIALCHART_USE_NAMESPACE |
|
8 | QTCOMMERCIALCHART_USE_NAMESPACE | |
9 |
|
9 | |||
10 | #define PI 3.14159265358979 |
|
10 | #define PI 3.14159265358979 | |
11 |
|
11 | |||
12 | int main(int argc, char *argv[]) |
|
12 | int main(int argc, char *argv[]) | |
13 | { |
|
13 | { | |
14 | QApplication a(argc, argv); |
|
14 | QApplication a(argc, argv); | |
15 |
|
15 | |||
16 | QMainWindow window; |
|
16 | QMainWindow window; | |
17 |
|
17 | |||
18 | QXYChartSeries* series0 = QXYChartSeries::create(); |
|
18 | QXYChartSeries* series0 = QXYChartSeries::create(); | |
19 | series0->setColor(Qt::blue); |
|
19 | series0->setColor(Qt::blue); | |
20 | QXYChartSeries* series1 = QXYChartSeries::create(); |
|
20 | QXYChartSeries* series1 = QXYChartSeries::create(); | |
21 | series1->setColor(Qt::red); |
|
21 | series1->setColor(Qt::red); | |
22 | QXYChartSeries* series2 = QXYChartSeries::create(); |
|
22 | QXYChartSeries* series2 = QXYChartSeries::create(); | |
23 | series2->setColor(Qt::gray); |
|
23 | series2->setColor(Qt::gray); | |
24 | QXYChartSeries* series3 = QXYChartSeries::create(); |
|
24 | QXYChartSeries* series3 = QXYChartSeries::create(); | |
25 | series3->setColor(Qt::green); |
|
25 | series3->setColor(Qt::green); | |
26 |
|
26 | |||
27 | int numPoints = 100; |
|
27 | int numPoints = 100; | |
28 |
|
28 | |||
29 | for (int x = 0; x < numPoints; ++x) { |
|
29 | for (int x = 0; x < numPoints; ++x) { | |
30 | series0->add(x,0); |
|
30 | series0->add(x,0); | |
31 | series1->add(x, abs(sin(PI/50*x)*100)); |
|
31 | series1->add(x, abs(sin(PI/50*x)*100)); | |
32 | series2->add(x, abs(cos(PI/50*x)*100)); |
|
32 | series2->add(x, abs(cos(PI/50*x)*100)); | |
33 | series3->add(x,100); |
|
33 | series3->add(x,100); | |
34 | } |
|
34 | } | |
35 |
|
35 | |||
36 | QList<QXYChartSeries*> dataset; |
|
36 | QList<QXYChartSeries*> dataset; | |
37 |
|
37 | |||
38 | //qDebug()<<"Series 1:" << *series1; |
|
38 | //qDebug()<<"Series 1:" << *series1; | |
39 | //qDebug()<<"Series 2:" << *series2; |
|
39 | //qDebug()<<"Series 2:" << *series2; | |
40 |
|
40 | |||
41 | dataset << series0; |
|
41 | dataset << series0; | |
42 | dataset << series1; |
|
42 | dataset << series1; | |
43 | dataset << series2; |
|
43 | dataset << series2; | |
44 | dataset << series3; |
|
44 | dataset << series3; | |
45 |
|
45 | |||
46 |
QChart |
|
46 | QChartView* chartView = new QChartView(&window); | |
47 |
chart |
|
47 | chartView->addSeries(series1); | |
48 |
chart |
|
48 | chartView->addSeries(series2); | |
49 |
|
49 | |||
50 |
window.setCentralWidget(chart |
|
50 | window.setCentralWidget(chartView); | |
51 | window.resize(400, 300); |
|
51 | window.resize(400, 300); | |
52 | window.show(); |
|
52 | window.show(); | |
53 |
|
53 | |||
54 | return a.exec(); |
|
54 | return a.exec(); | |
55 | } |
|
55 | } |
@@ -1,52 +1,51 | |||||
1 | #include "qchartwidget.h" |
|
1 | #include "qchartwidget.h" | |
2 | #include "qchartseries.h" |
|
2 | #include "qchartseries.h" | |
3 | #include <QGraphicsView> |
|
3 | #include <QGraphicsView> | |
4 | #include <QGraphicsScene> |
|
4 | #include <QGraphicsScene> | |
5 | #include <QResizeEvent> |
|
5 | #include <QResizeEvent> | |
6 |
|
6 | |||
7 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
7 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
8 |
|
8 | |||
9 | QChartWidget::QChartWidget(QWidget *parent) : |
|
9 | QChartWidget::QChartWidget(QWidget *parent) : | |
10 | QGraphicsView(parent) |
|
10 | QGraphicsView(parent) | |
11 | { |
|
11 | { | |
12 | setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); |
|
12 | setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); | |
13 | m_scene = new QGraphicsScene(); |
|
13 | m_scene = new QGraphicsScene(); | |
14 | m_view = new QGraphicsView(parent); |
|
14 | setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); | |
15 |
|
|
15 | setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); | |
16 | m_view->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); |
|
16 | setScene(m_scene); | |
17 | m_view->setScene(m_scene); |
|
|||
18 |
|
17 | |||
19 | m_chart = new QChart(); |
|
18 | m_chart = new QChart(); | |
20 | m_scene->addItem(m_chart); |
|
19 | m_scene->addItem(m_chart); | |
21 | show(); |
|
20 | show(); | |
22 | } |
|
21 | } | |
23 |
|
22 | |||
24 | QChartWidget::~QChartWidget() |
|
23 | QChartWidget::~QChartWidget() | |
25 | { |
|
24 | { | |
26 | } |
|
25 | } | |
27 |
|
26 | |||
28 | void QChartWidget::resizeEvent(QResizeEvent *event) |
|
27 | void QChartWidget::resizeEvent(QResizeEvent *event) | |
29 | { |
|
28 | { | |
30 | m_scene->setSceneRect(0,0,size().width(),size().height()); |
|
29 | m_scene->setSceneRect(0,0,size().width(),size().height()); | |
31 | m_chart->setSize(size()); |
|
30 | m_chart->setSize(size()); | |
32 | QWidget::resizeEvent(event); |
|
31 | QWidget::resizeEvent(event); | |
33 | } |
|
32 | } | |
34 |
|
33 | |||
35 | QSize QChartWidget::sizeHint() const |
|
34 | QSize QChartWidget::sizeHint() const | |
36 | { |
|
35 | { | |
37 | // TODO: calculate size hint based on contents? |
|
36 | // TODO: calculate size hint based on contents? | |
38 | return QSize(100, 100); |
|
37 | return QSize(100, 100); | |
39 | } |
|
38 | } | |
40 |
|
39 | |||
41 | void QChartWidget::addSeries(QChartSeries* series) |
|
40 | void QChartWidget::addSeries(QChartSeries* series) | |
42 | { |
|
41 | { | |
43 | m_chart->addSeries(series); |
|
42 | m_chart->addSeries(series); | |
44 | } |
|
43 | } | |
45 |
|
44 | |||
46 | QChartSeries* QChartWidget::createSeries(QList<qreal> x, QList<qreal> y, QChartSeries::QChartSeriesType type) |
|
45 | QChartSeries* QChartWidget::createSeries(QList<qreal> x, QList<qreal> y, QChartSeries::QChartSeriesType type) | |
47 | { |
|
46 | { | |
48 | return m_chart->createSeries(x, y, type); |
|
47 | return m_chart->createSeries(x, y, type); | |
49 | } |
|
48 | } | |
50 | #include "moc_qchartwidget.cpp" |
|
49 | #include "moc_qchartwidget.cpp" | |
51 |
|
50 | |||
52 | QTCOMMERCIALCHART_END_NAMESPACE |
|
51 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,87 +1,89 | |||||
1 | !include( ../common.pri ) { |
|
1 | !include( ../common.pri ) { | |
2 | error( Couldn't find the common.pri file! ) |
|
2 | error( Couldn't find the common.pri file! ) | |
3 | } |
|
3 | } | |
4 |
|
4 | |||
5 | TARGET = QtCommercialChart |
|
5 | TARGET = QtCommercialChart | |
6 | DESTDIR = $$CHART_BUILD_LIB_DIR |
|
6 | DESTDIR = $$CHART_BUILD_LIB_DIR | |
7 | TEMPLATE = lib |
|
7 | TEMPLATE = lib | |
8 | QT += core \ |
|
8 | QT += core \ | |
9 | gui |
|
9 | gui | |
10 |
|
10 | |||
11 | CONFIG += debug_and_release |
|
11 | CONFIG += debug_and_release | |
12 | CONFIG(debug, debug|release):TARGET = QtCommercialChartd |
|
12 | CONFIG(debug, debug|release):TARGET = QtCommercialChartd | |
13 |
|
13 | |||
14 | SOURCES += \ |
|
14 | SOURCES += \ | |
15 | barchart/barchartseries.cpp \ |
|
15 | barchart/barchartseries.cpp \ | |
16 | barchart/bargroup.cpp \ |
|
16 | barchart/bargroup.cpp \ | |
17 | barchart/bar.cpp \ |
|
17 | barchart/bar.cpp \ | |
18 | xylinechart/qxychartseries.cpp \ |
|
18 | xylinechart/qxychartseries.cpp \ | |
19 | xylinechart/xylinechartitem.cpp \ |
|
19 | xylinechart/xylinechartitem.cpp \ | |
20 | xylinechart/xygrid.cpp \ |
|
20 | xylinechart/xygrid.cpp \ | |
21 | xylinechart/xyplotdomain.cpp \ |
|
21 | xylinechart/xyplotdomain.cpp \ | |
22 | qscatterseries.cpp \ |
|
22 | qscatterseries.cpp \ | |
23 | qpieseries.cpp \ |
|
23 | qpieseries.cpp \ | |
24 | qchart.cpp \ |
|
24 | qchart.cpp \ | |
25 | axis.cpp \ |
|
25 | axis.cpp \ | |
26 | qchartwidget.cpp \ |
|
26 | qchartwidget.cpp \ | |
27 | pieslice.cpp |
|
27 | pieslice.cpp \ | |
|
28 | qchartview.cpp | |||
28 |
|
29 | |||
29 | PRIVATE_HEADERS += \ |
|
30 | PRIVATE_HEADERS += \ | |
30 | xylinechart/xylinechartitem_p.h \ |
|
31 | xylinechart/xylinechartitem_p.h \ | |
31 | xylinechart/xyplotdomain_p.h \ |
|
32 | xylinechart/xyplotdomain_p.h \ | |
32 | xylinechart/xygrid_p.h \ |
|
33 | xylinechart/xygrid_p.h \ | |
33 | qscatterseries_p.h \ |
|
34 | qscatterseries_p.h \ | |
34 | pieslice.h \ |
|
35 | pieslice.h \ | |
35 | axis_p.h |
|
36 | axis_p.h | |
36 |
|
37 | |||
37 | PUBLIC_HEADERS += \ |
|
38 | PUBLIC_HEADERS += \ | |
38 | qchartseries.h \ |
|
39 | qchartseries.h \ | |
39 | qscatterseries.h \ |
|
40 | qscatterseries.h \ | |
40 | qpieseries.h \ |
|
41 | qpieseries.h \ | |
41 | qchart.h \ |
|
42 | qchart.h \ | |
42 | qchartwidget.h \ |
|
43 | qchartwidget.h \ | |
43 | qchartglobal.h \ |
|
44 | qchartglobal.h \ | |
44 | xylinechart/qxychartseries.h \ |
|
45 | xylinechart/qxychartseries.h \ | |
45 | barchart/barchartseries.h \ |
|
46 | barchart/barchartseries.h \ | |
46 | barchart/bargroup.h |
|
47 | barchart/bargroup.h \ | |
|
48 | qchartview.h | |||
47 |
|
49 | |||
48 | HEADERS += $$PUBLIC_HEADERS |
|
50 | HEADERS += $$PUBLIC_HEADERS | |
49 | HEADERS += $$PRIVATE_HEADERS |
|
51 | HEADERS += $$PRIVATE_HEADERS | |
50 |
|
52 | |||
51 | INCLUDEPATH += xylinechart \ |
|
53 | INCLUDEPATH += xylinechart \ | |
52 | barchart \ |
|
54 | barchart \ | |
53 | . |
|
55 | . | |
54 |
|
56 | |||
55 | OBJECTS_DIR = $$CHART_BUILD_DIR/lib |
|
57 | OBJECTS_DIR = $$CHART_BUILD_DIR/lib | |
56 | MOC_DIR = $$CHART_BUILD_DIR/lib |
|
58 | MOC_DIR = $$CHART_BUILD_DIR/lib | |
57 | UI_DIR = $$CHART_BUILD_DIR/lib |
|
59 | UI_DIR = $$CHART_BUILD_DIR/lib | |
58 | RCC_DIR = $$CHART_BUILD_DIR/lib |
|
60 | RCC_DIR = $$CHART_BUILD_DIR/lib | |
59 |
|
61 | |||
60 |
|
62 | |||
61 | DEFINES += QTCOMMERCIALCHART_LIBRARY |
|
63 | DEFINES += QTCOMMERCIALCHART_LIBRARY | |
62 |
|
64 | |||
63 | public_headers.path = $$[QT_INSTALL_HEADERS]/QtCommercialChart |
|
65 | public_headers.path = $$[QT_INSTALL_HEADERS]/QtCommercialChart | |
64 | public_headers.files = $$PUBLIC_HEADERS |
|
66 | public_headers.files = $$PUBLIC_HEADERS | |
65 | target.path = $$[QT_INSTALL_LIBS] |
|
67 | target.path = $$[QT_INSTALL_LIBS] | |
66 | INSTALLS += target \ |
|
68 | INSTALLS += target \ | |
67 | public_headers |
|
69 | public_headers | |
68 |
|
70 | |||
69 |
|
71 | |||
70 | install_build_headers.name = bild_headers |
|
72 | install_build_headers.name = bild_headers | |
71 | install_build_headers.output = $$CHART_BUILD_HEADER_DIR/${QMAKE_FILE_BASE}.h |
|
73 | install_build_headers.output = $$CHART_BUILD_HEADER_DIR/${QMAKE_FILE_BASE}.h | |
72 | install_build_headers.input = PUBLIC_HEADERS |
|
74 | install_build_headers.input = PUBLIC_HEADERS | |
73 | install_build_headers.commands = $$QMAKE_COPY ${QMAKE_FILE_NAME} $$CHART_BUILD_HEADER_DIR |
|
75 | install_build_headers.commands = $$QMAKE_COPY ${QMAKE_FILE_NAME} $$CHART_BUILD_HEADER_DIR | |
74 | install_build_headers.CONFIG += target_predeps no_link |
|
76 | install_build_headers.CONFIG += target_predeps no_link | |
75 | QMAKE_EXTRA_COMPILERS += install_build_headers |
|
77 | QMAKE_EXTRA_COMPILERS += install_build_headers | |
76 |
|
78 | |||
77 | chartversion.target = qchartversion_p.h |
|
79 | chartversion.target = qchartversion_p.h | |
78 | chartversion.commands = @echo "build_time" > $$chartversion.target; |
|
80 | chartversion.commands = @echo "build_time" > $$chartversion.target; | |
79 | chartversion.depends = $$HEADERS $$SOURCES |
|
81 | chartversion.depends = $$HEADERS $$SOURCES | |
80 | PRE_TARGETDEPS += qchartversion_p.h |
|
82 | PRE_TARGETDEPS += qchartversion_p.h | |
81 | QMAKE_CLEAN+= qchartversion_p.h |
|
83 | QMAKE_CLEAN+= qchartversion_p.h | |
82 | QMAKE_EXTRA_TARGETS += chartversion |
|
84 | QMAKE_EXTRA_TARGETS += chartversion | |
83 |
|
85 | |||
84 | unix:QMAKE_DISTCLEAN += -r $$CHART_BUILD_HEADER_DIR $$CHART_BUILD_LIB_DIR |
|
86 | unix:QMAKE_DISTCLEAN += -r $$CHART_BUILD_HEADER_DIR $$CHART_BUILD_LIB_DIR | |
85 | win32:QMAKE_DISTCLEAN += /Q $$CHART_BUILD_HEADER_DIR $$CHART_BUILD_LIB_DIR |
|
87 | win32:QMAKE_DISTCLEAN += /Q $$CHART_BUILD_HEADER_DIR $$CHART_BUILD_LIB_DIR | |
86 |
|
88 | |||
87 |
|
89 |
General Comments 0
You need to be logged in to leave comments.
Login now