##// END OF EJS Templates
Marek Rosa -
r427:82b3917abcdf merge
parent child
Show More
@@ -0,0 +1,6
1 #include "chartwidget.h"
2
3 ChartWidget::ChartWidget(QWidget *parent) :
4 QChartView(parent)
5 {
6 }
@@ -0,0 +1,21
1 #ifndef CHARTWIDGET_H
2 #define CHARTWIDGET_H
3
4 #include <qchartview.h>
5
6 QTCOMMERCIALCHART_USE_NAMESPACE
7
8
9 class ChartWidget : public QChartView
10 {
11 Q_OBJECT
12 public:
13 explicit ChartWidget(QWidget *parent = 0);
14
15 signals:
16
17 public slots:
18
19 };
20
21 #endif // CHARTWIDGET_H
@@ -0,0 +1,83
1 #include <QApplication>
2 #include <QMainWindow>
3 #include <qchartview.h>
4 #include <qstackedbarseries.h>
5 #include <qbarset.h>
6 #include <qchartaxis.h>
7 #include <QStringList>
8
9 QTCOMMERCIALCHART_USE_NAMESPACE
10
11 int main(int argc, char *argv[])
12 {
13 QApplication a(argc, argv);
14 QMainWindow window;
15
16 // TODO:
17 /*
18 //! [1]
19 // Define categories
20 QStringList categories;
21 categories << "Jan" << "Feb" << "Mar" << "Apr" << "May" << "Jun";
22 //! [1]
23
24 //! [2]
25 // Create some test sets for chat
26 QBarSet *set0 = new QBarSet("Bub");
27 QBarSet *set1 = new QBarSet("Bob");
28 QBarSet *set2 = new QBarSet("Guybrush");
29 QBarSet *set3 = new QBarSet("Larry");
30 QBarSet *set4 = new QBarSet("Zak");
31
32 *set0 << 1 << 2 << 3 << 4 << 5 << 6;
33 *set1 << 5 << 0 << 0 << 4 << 0 << 7;
34 *set2 << 3 << 5 << 8 << 13 << 8 << 5;
35 *set3 << 5 << 6 << 7 << 3 << 4 << 5;
36 *set4 << 9 << 7 << 5 << 3 << 1 << 2;
37 //! [2]
38
39 //! [3]
40 // Create series and add sets to it
41 QStackedBarSeries* series = new QStackedBarSeries(categories);
42
43 series->addBarSet(set0);
44 series->addBarSet(set1);
45 series->addBarSet(set2);
46 series->addBarSet(set3);
47 series->addBarSet(set4);
48 //! [3]
49
50 //! [4]
51 // Enable tooltip
52 series->setToolTipEnabled();
53
54 // Connect clicked signal of set to toggle floating values of set.
55 // Note that we leave QBarset "Zak" unconnected here, so clicking on it doesn't toggle values.
56 QObject::connect(set0,SIGNAL(clicked(QBarSet*,QString)),set0,SIGNAL(toggleFloatingValues()));
57 QObject::connect(set1,SIGNAL(clicked(QBarSet*,QString)),set1,SIGNAL(toggleFloatingValues()));
58 QObject::connect(set2,SIGNAL(clicked(QBarSet*,QString)),set2,SIGNAL(toggleFloatingValues()));
59 QObject::connect(set3,SIGNAL(clicked(QBarSet*,QString)),set3,SIGNAL(toggleFloatingValues()));
60 //! [4]
61
62 //! [5]
63 // Create view for chart and add series to it. Apply theme.
64
65 QChartView* chartView = new QChartView(&window);
66 chartView->addSeries(series);
67 chartView->setChartTitle("simple stacked barchart");
68 chartView->setChartTheme(QChart::ChartThemeIcy);
69 //! [5]
70
71 //! [6]
72 chartView->axisX()->setAxisVisible(false);
73 chartView->axisX()->setGridVisible(false);
74 chartView->axisX()->setLabelsVisible(false);
75 //! [6]
76
77 window.setCentralWidget(chartView);
78 window.resize(400, 300);
79 window.show();
80 */
81 return a.exec();
82 }
83
@@ -0,0 +1,9
1 !include( ../example.pri ) {
2 error( "Couldn't find the example.pri file!" )
3 }
4 TARGET = stackedbarchartdrilldown
5 SOURCES += main.cpp \
6 chartwidget.cpp
7 HEADERS += \
8 chartwidget.h
9
@@ -47,9 +47,15 int main(int argc, char *argv[])
47 //! [3]
47 //! [3]
48
48
49 //! [4]
49 //! [4]
50 // Enable some features
50 // Enable tooltip
51 series->setToolTipEnabled();
51 series->setToolTipEnabled();
52 series->setFloatingValuesEnabled();
52
53 // Connect clicked signal of set to toggle floating values of set.
54 // Note that we leave QBarset "Zak" unconnected here, so clicking on it doesn't toggle values.
55 QObject::connect(set0,SIGNAL(clicked(QString)),set0,SIGNAL(toggleFloatingValues()));
56 QObject::connect(set1,SIGNAL(clicked(QString)),set1,SIGNAL(toggleFloatingValues()));
57 QObject::connect(set2,SIGNAL(clicked(QString)),set2,SIGNAL(toggleFloatingValues()));
58 QObject::connect(set3,SIGNAL(clicked(QString)),set3,SIGNAL(toggleFloatingValues()));
53 //! [4]
59 //! [4]
54
60
55 //! [5]
61 //! [5]
@@ -16,4 +16,5 SUBDIRS += linechart \
16 chartview \
16 chartview \
17 scatterinteractions \
17 scatterinteractions \
18 splinechart \
18 splinechart \
19 areachart
19 areachart \
20 stackedbarchartdrilldown
@@ -47,9 +47,15 int main(int argc, char *argv[])
47 //! [3]
47 //! [3]
48
48
49 //! [4]
49 //! [4]
50 // Enable features
50 // Enable tooltip
51 series->setToolTipEnabled();
51 series->setToolTipEnabled();
52 series->setFloatingValuesEnabled();
52
53 // Connect clicked signal of set to toggle floating values of set.
54 // Note that we leave QBarset "Zak" unconnected here, so clicking on it doesn't toggle values.
55 QObject::connect(set0,SIGNAL(clicked(QString)),set0,SIGNAL(toggleFloatingValues()));
56 QObject::connect(set1,SIGNAL(clicked(QString)),set1,SIGNAL(toggleFloatingValues()));
57 QObject::connect(set2,SIGNAL(clicked(QString)),set2,SIGNAL(toggleFloatingValues()));
58 QObject::connect(set3,SIGNAL(clicked(QString)),set3,SIGNAL(toggleFloatingValues()));
53 //! [4]
59 //! [4]
54
60
55 //! [5]
61 //! [5]
@@ -46,9 +46,15 int main(int argc, char *argv[])
46 //! [3]
46 //! [3]
47
47
48 //! [4]
48 //! [4]
49 // Enable features
49 // Enable tooltip
50 series->setToolTipEnabled();
50 series->setToolTipEnabled();
51 series->setFloatingValuesEnabled();
51
52 // Connect clicked signal of set to toggle floating values of set.
53 // Note that we leave QBarset "Zak" unconnected here, so clicking on it doesn't toggle values.
54 QObject::connect(set0,SIGNAL(clicked(QString)),set0,SIGNAL(toggleFloatingValues()));
55 QObject::connect(set1,SIGNAL(clicked(QString)),set1,SIGNAL(toggleFloatingValues()));
56 QObject::connect(set2,SIGNAL(clicked(QString)),set2,SIGNAL(toggleFloatingValues()));
57 QObject::connect(set3,SIGNAL(clicked(QString)),set3,SIGNAL(toggleFloatingValues()));
52 //! [4]
58 //! [4]
53
59
54 //! [5]
60 //! [5]
@@ -5,8 +5,9
5
5
6 QTCOMMERCIALCHART_BEGIN_NAMESPACE
6 QTCOMMERCIALCHART_BEGIN_NAMESPACE
7
7
8 Bar::Bar(QGraphicsItem *parent)
8 Bar::Bar(QString category, QGraphicsItem *parent)
9 : QGraphicsObject(parent)
9 : QGraphicsObject(parent)
10 ,mCategory(category)
10 {
11 {
11 setAcceptedMouseButtons(Qt::LeftButton|Qt::RightButton);
12 setAcceptedMouseButtons(Qt::LeftButton|Qt::RightButton);
12 setAcceptHoverEvents(true);
13 setAcceptHoverEvents(true);
@@ -67,9 +68,9 QRectF Bar::boundingRect() const
67 void Bar::mousePressEvent(QGraphicsSceneMouseEvent* event)
68 void Bar::mousePressEvent(QGraphicsSceneMouseEvent* event)
68 {
69 {
69 if (event->button() == Qt::LeftButton) {
70 if (event->button() == Qt::LeftButton) {
70 emit clicked();
71 emit clicked(mCategory);
71 } else if (event->button() == Qt::RightButton) {
72 } else if (event->button() == Qt::RightButton) {
72 emit rightClicked();
73 emit rightClicked(mCategory);
73 }
74 }
74 }
75 }
75
76
@@ -13,7 +13,7 class Bar : public QGraphicsObject
13 {
13 {
14 Q_OBJECT
14 Q_OBJECT
15 public:
15 public:
16 Bar(QGraphicsItem *parent=0);
16 Bar(QString category, QGraphicsItem *parent=0);
17
17
18 public: // from ChartItem
18 public: // from ChartItem
19 void setSize(const QSizeF &size);
19 void setSize(const QSizeF &size);
@@ -33,8 +33,8 public:
33 void hoverLeaveEvent(QGraphicsSceneHoverEvent *event);
33 void hoverLeaveEvent(QGraphicsSceneHoverEvent *event);
34
34
35 Q_SIGNALS:
35 Q_SIGNALS:
36 void clicked();
36 void clicked(QString category);
37 void rightClicked();
37 void rightClicked(QString category);
38 void hoverEntered(QPoint pos);
38 void hoverEntered(QPoint pos);
39 void hoverLeaved();
39 void hoverLeaved();
40
40
@@ -48,6 +48,7 private:
48 QBrush mBrush;
48 QBrush mBrush;
49 QPen mPen;
49 QPen mPen;
50
50
51 QString mCategory;
51 };
52 };
52
53
53 QTCOMMERCIALCHART_END_NAMESPACE
54 QTCOMMERCIALCHART_END_NAMESPACE
@@ -14,8 +14,7 SOURCES += \
14 $$PWD/qstackedbarseries.cpp \
14 $$PWD/qstackedbarseries.cpp \
15 $$PWD/separator.cpp \
15 $$PWD/separator.cpp \
16 $$PWD/stackedbarpresenter.cpp \
16 $$PWD/stackedbarpresenter.cpp \
17 $$PWD/barvalue.cpp \
17 $$PWD/barvalue.cpp
18 $$PWD/barcategory.cpp
19
18
20 PRIVATE_HEADERS += \
19 PRIVATE_HEADERS += \
21 $$PWD/bar_p.h \
20 $$PWD/bar_p.h \
@@ -26,8 +25,7 PRIVATE_HEADERS += \
26 $$PWD/percentbarpresenter_p.h \
25 $$PWD/percentbarpresenter_p.h \
27 $$PWD/separator_p.h \
26 $$PWD/separator_p.h \
28 $$PWD/stackedbarpresenter_p.h \
27 $$PWD/stackedbarpresenter_p.h \
29 $$PWD/barvalue_p.h \
28 $$PWD/barvalue_p.h
30 $$PWD/barcategory_p.h
31
29
32 PUBLIC_HEADERS += \
30 PUBLIC_HEADERS += \
33 $$PWD/qbarseries.h \
31 $$PWD/qbarseries.h \
@@ -2,7 +2,6
2 #include <QVector>
2 #include <QVector>
3 #include <QDebug>
3 #include <QDebug>
4 #include "barchartmodel_p.h"
4 #include "barchartmodel_p.h"
5 #include "barcategory_p.h"
6 #include "qbarset.h"
5 #include "qbarset.h"
7
6
8 QTCOMMERCIALCHART_BEGIN_NAMESPACE
7 QTCOMMERCIALCHART_BEGIN_NAMESPACE
@@ -11,10 +10,6 BarChartModel::BarChartModel(QStringList categories, QObject *parent) :
11 QObject(parent)
10 QObject(parent)
12 ,mCategory(categories)
11 ,mCategory(categories)
13 {
12 {
14 for (int i=0; i<mCategory.count(); i++) {
15 BarCategory* cat = new BarCategory(mCategory.at(i), this);
16 mCategoryObjects.append(cat);
17 }
18 }
13 }
19
14
20 QStringList BarChartModel::category()
15 QStringList BarChartModel::category()
@@ -172,11 +167,6 QString BarChartModel::categoryName(int category)
172 return mCategory.at(category);
167 return mCategory.at(category);
173 }
168 }
174
169
175 BarCategory* BarChartModel::categoryObject(int category)
176 {
177 return mCategoryObjects.at(category);
178 }
179
180 #include "moc_barchartmodel_p.cpp"
170 #include "moc_barchartmodel_p.cpp"
181
171
182 QTCOMMERCIALCHART_END_NAMESPACE
172 QTCOMMERCIALCHART_END_NAMESPACE
@@ -12,7 +12,6 QTCOMMERCIALCHART_BEGIN_NAMESPACE
12 // TODO: Implement as QAbstractItemModel?
12 // TODO: Implement as QAbstractItemModel?
13
13
14 class QBarSet;
14 class QBarSet;
15 class BarCategory;
16
15
17 class BarChartModel : public QObject //, public QAbstractItemModel
16 class BarChartModel : public QObject //, public QAbstractItemModel
18 {
17 {
@@ -40,7 +39,6 public:
40 qreal maxCategorySum(); // returns maximum sum of sets in all categories.
39 qreal maxCategorySum(); // returns maximum sum of sets in all categories.
41
40
42 QString categoryName(int category);
41 QString categoryName(int category);
43 BarCategory* categoryObject(int category);
44
42
45 signals:
43 signals:
46 void modelUpdated();
44 void modelUpdated();
@@ -51,7 +49,6 private:
51
49
52 QList<QBarSet*> mDataModel;
50 QList<QBarSet*> mDataModel;
53 QStringList mCategory;
51 QStringList mCategory;
54 QList<BarCategory*> mCategoryObjects;
55
52
56 int mCurrentSet;
53 int mCurrentSet;
57
54
@@ -3,7 +3,6
3 #include "barvalue_p.h"
3 #include "barvalue_p.h"
4 #include "barlabel_p.h"
4 #include "barlabel_p.h"
5 #include "separator_p.h"
5 #include "separator_p.h"
6 #include "barcategory_p.h"
7 #include "qbarset.h"
6 #include "qbarset.h"
8 #include "qbarseries.h"
7 #include "qbarseries.h"
9 #include <QDebug>
8 #include <QDebug>
@@ -20,7 +19,7 BarPresenterBase::BarPresenterBase(QBarSeries *series, QGraphicsItem *parent)
20 ,mSeries(series)
19 ,mSeries(series)
21 {
20 {
22 connect(series,SIGNAL(showToolTip(QPoint,QString)),this,SLOT(showToolTip(QPoint,QString)));
21 connect(series,SIGNAL(showToolTip(QPoint,QString)),this,SLOT(showToolTip(QPoint,QString)));
23 connect(series,SIGNAL(separatorsEnabled(bool)),this,SLOT(enableSeparators(bool)));
22 // connect(series,SIGNAL(separatorsEnabled(bool)),this,SLOT(enableSeparators(bool)));
24 dataChanged();
23 dataChanged();
25 }
24 }
26
25
@@ -70,14 +69,14 void BarPresenterBase::dataChanged()
70
69
71 // Create new graphic items for bars
70 // Create new graphic items for bars
72 for (int c=0; c<mSeries->categoryCount(); c++) {
71 for (int c=0; c<mSeries->categoryCount(); c++) {
73 BarCategory *category = mSeries->categoryObject(c);
72 QString category = mSeries->categoryName(c);
74 for (int s=0; s<mSeries->barsetCount(); s++) {
73 for (int s=0; s<mSeries->barsetCount(); s++) {
75 QBarSet *set = mSeries->barsetAt(s);
74 QBarSet *set = mSeries->barsetAt(s);
76 Bar *bar = new Bar(this);
75 Bar *bar = new Bar(category,this);
77 childItems().append(bar);
76 childItems().append(bar);
78 mBars.append(bar);
77 mBars.append(bar);
79 connect(bar,SIGNAL(clicked()),set,SLOT(barClickedEvent()));
78 connect(bar,SIGNAL(clicked(QString)),set,SIGNAL(clicked(QString)));
80 connect(bar,SIGNAL(rightClicked()),category,SLOT(barRightClickEvent()));
79 connect(bar,SIGNAL(rightClicked(QString)),set,SIGNAL(rightClicked(QString)));
81 connect(bar,SIGNAL(hoverEntered(QPoint)),set,SLOT(barHoverEnterEvent(QPoint)));
80 connect(bar,SIGNAL(hoverEntered(QPoint)),set,SLOT(barHoverEnterEvent(QPoint)));
82 connect(bar,SIGNAL(hoverLeaved()),set,SLOT(barHoverLeaveEvent()));
81 connect(bar,SIGNAL(hoverLeaved()),set,SLOT(barHoverLeaveEvent()));
83 }
82 }
@@ -43,13 +43,6 void BarValue::setPos(qreal x, qreal y)
43 mYpos = y;
43 mYpos = y;
44 }
44 }
45
45
46 /*
47 bool BarValue::belongsToSet(QBarSet *set)
48 {
49 return (&mBarSet == set);
50 }
51 */
52
53 void BarValue::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
46 void BarValue::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
54 {
47 {
55 if (isVisible()) {
48 if (isVisible()) {
@@ -10,7 +10,6 QTCOMMERCIALCHART_BEGIN_NAMESPACE
10 class QBarSet;
10 class QBarSet;
11
11
12 // Visual class for floating bar values
12 // Visual class for floating bar values
13 // TODO: fonts, colors etc.
14 // By default these are not visible.
13 // By default these are not visible.
15 class BarValue : public QGraphicsObject
14 class BarValue : public QGraphicsObject
16 {
15 {
@@ -27,9 +26,6 public:
27 void resize(qreal w, qreal h);
26 void resize(qreal w, qreal h);
28 void setPos(qreal x, qreal y);
27 void setPos(qreal x, qreal y);
29
28
30 // Propably not needed.
31 // bool belongsToSet(QBarSet *set);
32
33 // From QGraphicsItem
29 // From QGraphicsItem
34 void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
30 void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
35 QRectF boundingRect() const;
31 QRectF boundingRect() const;
@@ -2,7 +2,6
2 #include "qbarseries.h"
2 #include "qbarseries.h"
3 #include "qbarset.h"
3 #include "qbarset.h"
4 #include "barchartmodel_p.h"
4 #include "barchartmodel_p.h"
5 #include "barcategory_p.h"
6
5
7 QTCOMMERCIALCHART_BEGIN_NAMESPACE
6 QTCOMMERCIALCHART_BEGIN_NAMESPACE
8
7
@@ -24,22 +23,7 QTCOMMERCIALCHART_BEGIN_NAMESPACE
24 \brief Returns type of series.
23 \brief Returns type of series.
25 \sa QSeries, QSeriesType
24 \sa QSeries, QSeriesType
26 */
25 */
27 /*!
26
28 \fn void QBarSeries::changed(int index)
29 \brief \internal \a index
30 */
31 /*!
32 \fn void QBarSeries::floatingValuesEnabled(bool enabled)
33 \brief \internal \a enabled
34 */
35 /*!
36 \fn void QBarSeries::toolTipEnabled(bool enabled)
37 \brief \internal \a enabled
38 */
39 /*!
40 \fn void QBarSeries::separatorsEnabled(bool enabled)
41 \brief \internal \a enabled
42 */
43 /*!
27 /*!
44 \fn void QBarSeries::showToolTip(QPoint pos, QString tip)
28 \fn void QBarSeries::showToolTip(QPoint pos, QString tip)
45 \brief \internal \a pos \a tip
29 \brief \internal \a pos \a tip
@@ -53,25 +37,29 QBarSeries::QBarSeries(QStringList categories, QObject *parent)
53 : QSeries(parent)
37 : QSeries(parent)
54 ,mModel(new BarChartModel(categories, this))
38 ,mModel(new BarChartModel(categories, this))
55 {
39 {
56 for (int i=0; i<mModel->categoryCount(); i++) {
57 BarCategory *categoryObject = mModel->categoryObject(i);
58 connect(categoryObject, SIGNAL(rightClicked(QString)), this, SIGNAL(categoryRightClicked(QString)));
59 }
60 }
40 }
61
41
62 /*!
42 /*!
63 Adds a set of bars to series. Takes ownership of \a set
43 Adds a set of bars to series. Takes ownership of \a set.
44 Connects the clicked(QString) and rightClicked(QString) signals
45 of \a set to this series
64 */
46 */
65 void QBarSeries::addBarSet(QBarSet *set)
47 void QBarSeries::addBarSet(QBarSet *set)
66 {
48 {
67 mModel->addBarSet(set);
49 mModel->addBarSet(set);
50 connect(set,SIGNAL(clicked(QString)),this,SLOT(barsetClicked(QString)));
51 connect(set,SIGNAL(rightClicked(QString)),this,SLOT(barsetRightClicked(QString)));
68 }
52 }
69
53
70 /*!
54 /*!
71 Removes a set of bars from series. Releases ownership of \a set. Doesnt delete \a set.
55 Removes a set of bars from series. Releases ownership of \a set. Doesnt delete \a set.
56 Disconnects the clicked(QString) and rightClicked(QString) signals
57 of \a set from this series
72 */
58 */
73 void QBarSeries::removeBarSet(QBarSet *set)
59 void QBarSeries::removeBarSet(QBarSet *set)
74 {
60 {
61 disconnect(set,SIGNAL(clicked(QString)),this,SLOT(barsetClicked(QString)));
62 disconnect(set,SIGNAL(rightClicked(QString)),this,SLOT(barsetRightClicked(QString)));
75 mModel->removeBarSet(set);
63 mModel->removeBarSet(set);
76 }
64 }
77
65
@@ -124,26 +112,6 QString QBarSeries::categoryName(int category)
124 }
112 }
125
113
126 /*!
114 /*!
127 Enables or disables floating values depending on parameter \a enabled.
128 Floating values are bar values, that are displayed on top of each bar.
129 Calling without parameter \a enabled, enables the floating values
130 */
131 void QBarSeries::setFloatingValuesEnabled(bool enabled)
132 {
133 if (enabled) {
134 for (int i=0; i<mModel->barsetCount(); i++) {
135 QBarSet *set = mModel->setAt(i);
136 connect(set,SIGNAL(clicked()),set,SIGNAL(toggleFloatingValues()));
137 }
138 } else {
139 for (int i=0; i<mModel->barsetCount(); i++) {
140 QBarSet *set = mModel->setAt(i);
141 disconnect(set,SIGNAL(clicked()),set,SIGNAL(toggleFloatingValues()));
142 }
143 }
144 }
145
146 /*!
147 Enables or disables tooltip depending on parameter \a enabled.
115 Enables or disables tooltip depending on parameter \a enabled.
148 Tooltip shows the name of set, when mouse is hovering on top of bar.
116 Tooltip shows the name of set, when mouse is hovering on top of bar.
149 Calling without parameter \a enabled, enables the tooltip
117 Calling without parameter \a enabled, enables the tooltip
@@ -170,9 +138,28 void QBarSeries::setToolTipEnabled(bool enabled)
170 */
138 */
171 void QBarSeries::setSeparatorsEnabled(bool enabled)
139 void QBarSeries::setSeparatorsEnabled(bool enabled)
172 {
140 {
173 emit separatorsEnabled(enabled);
141 // TODO: toggle
142 // emit separatorsEnabled(enabled);
174 }
143 }
175
144
145
146 /*!
147 \internal \a category
148 */
149 void QBarSeries::barsetClicked(QString category)
150 {
151 emit clicked(qobject_cast<QBarSet*>(sender()), category);
152 }
153
154 /*!
155 \internal \a category
156 */
157 void QBarSeries::barsetRightClicked(QString category)
158 {
159 emit rightClicked(qobject_cast<QBarSet*>(sender()), category);
160 }
161
162
176 /*!
163 /*!
177 \internal
164 \internal
178 */
165 */
@@ -229,12 +216,6 BarChartModel& QBarSeries::model()
229 return *mModel;
216 return *mModel;
230 }
217 }
231
218
232 BarCategory* QBarSeries::categoryObject(int category)
233 {
234 return mModel->categoryObject(category);
235 }
236
237
238 #include "moc_qbarseries.cpp"
219 #include "moc_qbarseries.cpp"
239
220
240 QTCOMMERCIALCHART_END_NAMESPACE
221 QTCOMMERCIALCHART_END_NAMESPACE
@@ -39,26 +39,27 public:
39 qreal categorySum(int category);
39 qreal categorySum(int category);
40 qreal maxCategorySum();
40 qreal maxCategorySum();
41 BarChartModel& model();
41 BarChartModel& model();
42 BarCategory* categoryObject(int category);
43 // <--- TO PIMPL
42 // <--- TO PIMPL
44
43
45 signals:
44 signals:
46 void changed(int index);
45 //void changed(int index);
47 void categoryRightClicked(QString category);
46 void clicked(QBarSet* barset, QString category); // Up to user of api, what to do with these signals
47 void rightClicked(QBarSet* barset, QString category);
48
48
49 // TODO: internal signals, these to private implementation.
49 // TODO: internal signals, these to private implementation.
50 // TODO: TO PIMPL --->
50 // TODO: TO PIMPL --->
51 void floatingValuesEnabled(bool enabled);
52 void toolTipEnabled(bool enabled);
53 void separatorsEnabled(bool enabled);
54 void showToolTip(QPoint pos, QString tip);
51 void showToolTip(QPoint pos, QString tip);
55 // <--- TO PIMPL
52 // <--- TO PIMPL
56
53
57 public Q_SLOTS:
54 public Q_SLOTS:
58 void setFloatingValuesEnabled(bool enabled=true); // enables floating values on top of bars
59 void setToolTipEnabled(bool enabled=true); // enables tooltips
55 void setToolTipEnabled(bool enabled=true); // enables tooltips
60 void setSeparatorsEnabled(bool enabled=true); // enables separators between categories
56 void setSeparatorsEnabled(bool enabled=true); // enables separators between categories
61
57
58 // TODO: TO PIMPL --->
59 void barsetClicked(QString category);
60 void barsetRightClicked(QString category);
61 // <--- TO PIMPL
62
62 protected:
63 protected:
63 BarChartModel* mModel;
64 BarChartModel* mModel;
64 };
65 };
@@ -19,21 +19,32 QTCOMMERCIALCHART_BEGIN_NAMESPACE
19 */
19 */
20
20
21 /*!
21 /*!
22 \fn void QBarSet::clicked()
22 \fn void QBarSet::clicked(QString category)
23 \brief signals that set has been clicked
23 \brief signals that set has been clicked
24 Parameter \a category describes on which category was clicked
24 */
25 */
26
27 /*!
28 \fn void QBarSet::rightClicked(QString category)
29 \brief signals that set has been clicked with right mouse button
30 Parameter \a category describes on which category was clicked
31 */
32
25 /*!
33 /*!
26 \fn void QBarSet::hoverEnter(QPoint pos)
34 \fn void QBarSet::hoverEnter(QPoint pos)
27 \brief signals that mouse has entered over the set at position \a pos.
35 \brief signals that mouse has entered over the set at position \a pos.
28 */
36 */
37
29 /*!
38 /*!
30 \fn void QBarSet::hoverLeave()
39 \fn void QBarSet::hoverLeave()
31 \brief signals that mouse has left from the set.
40 \brief signals that mouse has left from the set.
32 */
41 */
42
33 /*!
43 /*!
34 \fn void QBarSet::toggleFloatingValues()
44 \fn void QBarSet::toggleFloatingValues()
35 \brief \internal
45 \brief \internal
36 */
46 */
47
37 /*!
48 /*!
38 \fn void QBarSet::showToolTip(QPoint pos, QString tip)
49 \fn void QBarSet::showToolTip(QPoint pos, QString tip)
39 \brief \internal \a pos \a tip
50 \brief \internal \a pos \a tip
@@ -130,16 +141,20 QBrush QBarSet::brush()
130 return mBrush;
141 return mBrush;
131 }
142 }
132
143
133 /*!
144 /*
134 \internal
145 void QBarSet::barClickedEvent(QString category)
135 */
136 void QBarSet::barClickedEvent()
137 {
146 {
138 // Some bar of this set has been clicked
147 // Some bar of this set has been clicked
139 // TODO: What happens then?
148 // TODO: What happens then?
140 emit clicked(); // Notify that set has been clicked
149 emit clicked(category); // Notify that set has been clicked
141 }
150 }
142
151
152 void QBarSet::barRightClickedEvent(QString category)
153 {
154 emit rightClicked(category);
155 }
156 */
157
143 /*!
158 /*!
144 \internal \a pos
159 \internal \a pos
145 */
160 */
@@ -28,20 +28,22 public:
28 QBrush brush();
28 QBrush brush();
29
29
30 Q_SIGNALS:
30 Q_SIGNALS:
31 void clicked(); // Clicked and hover signals exposed to user
31 void clicked(QString category); // Clicked and hover signals exposed to user
32 void hoverEnter(QPoint pos);
32 void rightClicked(QString category);
33 void hoverLeave();
33 void toggleFloatingValues();
34
34
35 // TODO: Expose this to user or not?
35 // TODO: Expose this to user or not?
36 // TODO: TO PIMPL --->
36 // TODO: TO PIMPL --->
37 void toggleFloatingValues();
37 void hoverEnter(QPoint pos);
38 void hoverLeave();
38 void showToolTip(QPoint pos, QString tip); // Private signal
39 void showToolTip(QPoint pos, QString tip); // Private signal
39 // <--- TO PIMPL
40 // <--- TO PIMPL
40
41
41 public Q_SLOTS:
42 public Q_SLOTS:
42 // These are for internal communication
43 // These are for internal communication
43 // TODO: TO PIMPL --->
44 // TODO: TO PIMPL --->
44 void barClickedEvent();
45 // void barClickedEvent(QString category);
46 // void barRightClickedEvent(QString category);
45 void barHoverEnterEvent(QPoint pos);
47 void barHoverEnterEvent(QPoint pos);
46 void barHoverLeaveEvent();
48 void barHoverLeaveEvent();
47 // <--- TO PIMPL
49 // <--- TO PIMPL
@@ -148,7 +148,7 void ChartPresenter::handleSeriesAdded(QSeries* series)
148 BarPresenter* item = new BarPresenter(barSeries,m_chart);
148 BarPresenter* item = new BarPresenter(barSeries,m_chart);
149 m_chartTheme->decorate(item,barSeries,m_chartItems.count());
149 m_chartTheme->decorate(item,barSeries,m_chartItems.count());
150 QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),item,SLOT(handleGeometryChanged(const QRectF&)));
150 QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),item,SLOT(handleGeometryChanged(const QRectF&)));
151 QObject::connect(barSeries,SIGNAL(changed(int)),item,SLOT(handleModelChanged(int)));
151 // QObject::connect(barSeries,SIGNAL(changed(int)),item,SLOT(handleModelChanged(int)));
152 m_chartItems.insert(series,item);
152 m_chartItems.insert(series,item);
153 // m_axisXItem->setVisible(false);
153 // m_axisXItem->setVisible(false);
154 if(m_rect.isValid()) item->handleGeometryChanged(m_rect);
154 if(m_rect.isValid()) item->handleGeometryChanged(m_rect);
@@ -161,7 +161,7 void ChartPresenter::handleSeriesAdded(QSeries* series)
161 StackedBarPresenter* item = new StackedBarPresenter(stackedBarSeries,m_chart);
161 StackedBarPresenter* item = new StackedBarPresenter(stackedBarSeries,m_chart);
162 m_chartTheme->decorate(item,stackedBarSeries,m_chartItems.count());
162 m_chartTheme->decorate(item,stackedBarSeries,m_chartItems.count());
163 QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),item,SLOT(handleGeometryChanged(const QRectF&)));
163 QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),item,SLOT(handleGeometryChanged(const QRectF&)));
164 QObject::connect(stackedBarSeries,SIGNAL(changed(int)),item,SLOT(handleModelChanged(int)));
164 // QObject::connect(stackedBarSeries,SIGNAL(changed(int)),item,SLOT(handleModelChanged(int)));
165 m_chartItems.insert(series,item);
165 m_chartItems.insert(series,item);
166 if(m_rect.isValid()) item->handleGeometryChanged(m_rect);
166 if(m_rect.isValid()) item->handleGeometryChanged(m_rect);
167 break;
167 break;
@@ -173,7 +173,7 void ChartPresenter::handleSeriesAdded(QSeries* series)
173 PercentBarPresenter* item = new PercentBarPresenter(percentBarSeries,m_chart);
173 PercentBarPresenter* item = new PercentBarPresenter(percentBarSeries,m_chart);
174 m_chartTheme->decorate(item,percentBarSeries ,m_chartItems.count());
174 m_chartTheme->decorate(item,percentBarSeries ,m_chartItems.count());
175 QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),item,SLOT(handleGeometryChanged(const QRectF&)));
175 QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),item,SLOT(handleGeometryChanged(const QRectF&)));
176 QObject::connect(percentBarSeries,SIGNAL(changed(int)),item,SLOT(handleModelChanged(int)));
176 // QObject::connect(percentBarSeries,SIGNAL(changed(int)),item,SLOT(handleModelChanged(int)));
177 m_chartItems.insert(series,item);
177 m_chartItems.insert(series,item);
178 if(m_rect.isValid()) item->handleGeometryChanged(m_rect);
178 if(m_rect.isValid()) item->handleGeometryChanged(m_rect);
179 break;
179 break;
@@ -214,6 +214,7 void ChartPresenter::handleSeriesAdded(QSeries* series)
214 pie->handleGeometryChanged(m_rect);
214 pie->handleGeometryChanged(m_rect);
215 break;
215 break;
216 }
216 }
217
217 case QSeries::SeriesTypeSpline: {
218 case QSeries::SeriesTypeSpline: {
218 QSplineSeries* splineSeries = qobject_cast<QSplineSeries*>(series);
219 QSplineSeries* splineSeries = qobject_cast<QSplineSeries*>(series);
219 SplinePresenter* splinePresenter = new SplinePresenter(splineSeries, m_chart);
220 SplinePresenter* splinePresenter = new SplinePresenter(splineSeries, m_chart);
@@ -226,7 +227,6 void ChartPresenter::handleSeriesAdded(QSeries* series)
226 qDebug()<< "Series type" << series->type() << "not implemented.";
227 qDebug()<< "Series type" << series->type() << "not implemented.";
227 break;
228 break;
228 }
229 }
229
230 }
230 }
231 }
231 }
232
232
@@ -290,7 +290,8 void MainWidget::addSeries(QString seriesName, int columnCount, int rowCount, QS
290 }
290 }
291 series->addBarSet(set);
291 series->addBarSet(set);
292 }
292 }
293 series->setFloatingValuesEnabled(true);
293 // TODO: new implementation of setFloatingValuesEnabled with signals
294 //series->setFloatingValuesEnabled(true);
294 series->setToolTipEnabled(true);
295 series->setToolTipEnabled(true);
295 series->setSeparatorsEnabled(false);
296 series->setSeparatorsEnabled(false);
296 m_chartView->addSeries(series);
297 m_chartView->addSeries(series);
1 NO CONTENT: file was removed
NO CONTENT: file was removed
1 NO CONTENT: file was removed
NO CONTENT: file was removed
General Comments 0
You need to be logged in to leave comments. Login now