##// END OF EJS Templates
moved tooltip to presenter
sauimone -
r288:5f68000bea7a
parent child
Show More
@@ -7,8 +7,8
7 7
8 8 QTCOMMERCIALCHART_BEGIN_NAMESPACE
9 9
10 BarPresenter::BarPresenter(BarChartModel& model, QGraphicsItem *parent) :
11 BarPresenterBase(model,parent)
10 BarPresenter::BarPresenter(QBarChartSeries *series, QGraphicsItem *parent) :
11 BarPresenterBase(series, parent)
12 12 {
13 13 mBarDefaultWidth = 15;
14 14 }
@@ -17,7 +17,7 void BarPresenter::layoutChanged()
17 17 {
18 18 // Scale bars to new layout
19 19 // Layout for bars:
20 if (mModel.countSets() <= 0) {
20 if (mSeries->countSets() <= 0) {
21 21 qDebug() << "No sets in model!";
22 22 return;
23 23 }
@@ -29,12 +29,12 void BarPresenter::layoutChanged()
29 29
30 30 // TODO: better way to auto-layout?
31 31 // Use reals for accurancy (we might get some compiler warnings... :)
32 int categoryCount = mModel.countCategories();
33 int setCount = mModel.countSets();
32 int categoryCount = mSeries->countCategories();
33 int setCount = mSeries->countSets();
34 34
35 35 qreal tW = mWidth;
36 36 qreal tH = mHeight;
37 qreal tM = mModel.max();
37 qreal tM = mSeries->max();
38 38 qreal scale = (tH/tM);
39 39 qreal tC = categoryCount+1;
40 40 qreal xStepPerSet = (tW/tC);
@@ -47,13 +47,13 void BarPresenter::layoutChanged()
47 47 qreal xPos = xStepPerSet * category + ((tW + mBarDefaultWidth*setCount)/(categoryCount*2));
48 48 qreal yPos = mHeight;
49 49 for (int set = 0; set < setCount; set++) {
50 qreal barHeight = mModel.valueAt(set, category) * scale;
50 qreal barHeight = mSeries->valueAt(set,category) * scale;
51 51 Bar* bar = mBars.at(itemIndex);
52 52
53 53 // TODO: width settable per bar?
54 54 bar->resize(mBarDefaultWidth, barHeight);
55 bar->setBrush(mModel.setAt(set)->brush());
56 bar->setPos(xPos, yPos-barHeight); // item*posStep+startPos + set * mBarDefaultWidth, mHeight);
55 bar->setBrush(mSeries->setAt(set)->brush());
56 bar->setPos(xPos, yPos-barHeight);
57 57 itemIndex++;
58 58 xPos += mBarDefaultWidth;
59 59 }
@@ -67,11 +67,11 void BarPresenter::layoutChanged()
67 67
68 68 // Position floating values
69 69 itemIndex = 0;
70 for (int category=0; category < mModel.countCategories(); category++) {
70 for (int category=0; category < mSeries->countCategories(); category++) {
71 71 qreal xPos = xStepPerSet * category + ((tW + mBarDefaultWidth*setCount)/(categoryCount*2));
72 72 qreal yPos = mHeight;
73 for (int set=0; set < mModel.countSets(); set++) {
74 qreal barHeight = mModel.valueAt(set,category) * scale;
73 for (int set=0; set < mSeries->countSets(); set++) {
74 qreal barHeight = mSeries->valueAt(set,category) * scale;
75 75 BarValue* value = mFloatingValues.at(itemIndex);
76 76
77 77 // TODO: remove hard coding, apply layout
@@ -79,8 +79,8 void BarPresenter::layoutChanged()
79 79 value->setPos(xPos, yPos-barHeight/2);
80 80 value->setPen(QPen(QColor(255,255,255,255)));
81 81
82 if (mModel.valueAt(set,category) != 0) {
83 value->setValueString(QString::number(mModel.valueAt(set,category)));
82 if (mSeries->valueAt(set,category) != 0) {
83 value->setValueString(QString::number(mSeries->valueAt(set,category)));
84 84 } else {
85 85 value->setValueString(QString(""));
86 86 }
@@ -92,4 +92,6 void BarPresenter::layoutChanged()
92 92 mLayoutDirty = true;
93 93 }
94 94
95 #include "moc_barpresenter.cpp"
96
95 97 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,17 +1,20
1 1 #ifndef BARPRESENTER_H
2 2 #define BARPRESENTER_H
3 3
4 #include "qchartglobal.h"
4 5 #include "barpresenterbase.h"
5 #include "qbarchartseries.h"
6 6 #include <QGraphicsItem>
7 7
8 8 QTCOMMERCIALCHART_BEGIN_NAMESPACE
9 9
10 class QBarChartSeries;
11
10 12 // Presenter for parallel bars. Grouping of bars is done on category basis.
11 13 class BarPresenter : public BarPresenterBase
12 14 {
15 Q_OBJECT
13 16 public:
14 explicit BarPresenter(BarChartModel& model, QGraphicsItem *parent = 0);
17 explicit BarPresenter(QBarChartSeries *series, QGraphicsItem *parent = 0);
15 18
16 19 private:
17 20
@@ -4,24 +4,33
4 4 #include "barlabel_p.h"
5 5 #include "separator_p.h"
6 6 #include "qbarset.h"
7 #include "qbarchartseries.h"
7 8 #include <QDebug>
9 #include <QToolTip>
8 10
9 11 QTCOMMERCIALCHART_BEGIN_NAMESPACE
10 12
11 BarPresenterBase::BarPresenterBase(BarChartModel& model, QGraphicsItem *parent)
13 BarPresenterBase::BarPresenterBase(QBarChartSeries *series, QGraphicsItem *parent)
12 14 : ChartItem(parent)
13 15 ,mBarDefaultWidth(20) // TODO: remove hard coding, when we have layout code ready
14 16 ,mLayoutSet(false)
15 17 ,mLayoutDirty(true)
16 ,mSeparatorsVisible(false)
17 ,mModel(model)
18 ,mSeries(series)
18 19 {
20 connect(series,SIGNAL(floatingValuesEnabled(bool)),this,SLOT(enableFloatingValues(bool)));
21 connect(series,SIGNAL(toolTipEnabled(bool)),this,SLOT(enableToolTip(bool)));
22 connect(series,SIGNAL(separatorsEnabled(bool)),this,SLOT(enableSeparators(bool)));
23 connect(series,SIGNAL(showToolTip(QPoint,QString)),this,SLOT(showToolTip(QPoint,QString)));
19 24 dataChanged();
20 25 }
21 26
22 void BarPresenterBase::setSeparatorsVisible(bool visible)
27 BarPresenterBase::~BarPresenterBase()
23 28 {
24 mSeparatorsVisible = visible;
29 disconnect(this,SLOT(enableFloatingValues(bool)));
30 disconnect(this,SLOT(enableToolTip(bool)));
31 disconnect(this,SLOT(enableSeparators(bool)));
32 disconnect(this,SLOT(showToolTip(QPoint,QString)));
33 delete mSeries;
25 34 }
26 35
27 36 void BarPresenterBase::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
@@ -63,9 +72,9 void BarPresenterBase::dataChanged()
63 72 mFloatingValues.clear();
64 73
65 74 // Create new graphic items for bars
66 for (int c=0; c<mModel.countCategories(); c++) {
67 for (int s=0; s<mModel.countSets(); s++) {
68 QBarSet *set = mModel.setAt(s);
75 for (int c=0; c<mSeries->countCategories(); c++) {
76 for (int s=0; s<mSeries->countSets(); s++) {
77 QBarSet *set = mSeries->setAt(s);
69 78 Bar *bar = new Bar(this);
70 79 childItems().append(bar);
71 80 mBars.append(bar);
@@ -77,16 +86,16 void BarPresenterBase::dataChanged()
77 86 }
78 87
79 88 // Create labels
80 int count = mModel.countCategories();
89 int count = mSeries->countCategories();
81 90 for (int i=0; i<count; i++) {
82 91 BarLabel* label = new BarLabel(this);
83 label->set(mModel.label(i));
92 label->set(mSeries->label(i));
84 93 childItems().append(label);
85 94 mLabels.append(label);
86 95 }
87 96
88 97 // Create separators
89 count = mModel.countCategories() - 1; // There is one less separator than columns
98 count = mSeries->countCategories() - 1; // There is one less separator than columns
90 99 for (int i=0; i<count; i++) {
91 100 Separator* sep = new Separator(this);
92 101 sep->setColor(QColor(255,0,0,255)); // TODO: color for separations from theme
@@ -95,9 +104,9 void BarPresenterBase::dataChanged()
95 104 }
96 105
97 106 // Create floating values
98 for (int category=0; category<mModel.countCategories(); category++) {
99 for (int s=0; s<mModel.countSets(); s++) {
100 QBarSet *set = mModel.setAt(s);
107 for (int category=0; category<mSeries->countCategories(); category++) {
108 for (int s=0; s<mSeries->countSets(); s++) {
109 QBarSet *set = mSeries->setAt(s);
101 110 BarValue *value = new BarValue(*set, this);
102 111 childItems().append(value);
103 112 mFloatingValues.append(value);
@@ -134,15 +143,27 void BarPresenterBase::handleGeometryChanged(const QRectF& rect)
134 143 setPos(rect.topLeft());
135 144 }
136 145
146 void BarPresenterBase::enableFloatingValues(bool enabled)
147 {
148 mFloatingValuesEnabled = enabled;
149 }
150
151 void BarPresenterBase::enableToolTip(bool enabled)
152 {
153 mToolTipEnabled = enabled;
154 }
137 155
138 void BarPresenterBase::barHoverEntered(QGraphicsSceneHoverEvent *event)
156 void BarPresenterBase::enableSeparators(bool enabled)
139 157 {
140 //TODO: show tooltip (name of series, where bar belongs...)
158 mSeparatorsEnabled = enabled;
141 159 }
142 160
143 void BarPresenterBase::barHoverLeaved(QGraphicsSceneHoverEvent *event)
161 void BarPresenterBase::showToolTip(QPoint pos, QString tip)
144 162 {
145 //TODO: hide tooltip (name of series, where bar belongs...)
163 if (mToolTipEnabled) {
164 // TODO: cool tooltip instead of default
165 QToolTip::showText(pos,tip);
166 }
146 167 }
147 168
148 169 #include "moc_barpresenterbase.cpp"
@@ -2,7 +2,7
2 2 #define BARPRESENTERBASE_H
3 3
4 4 #include "chartitem_p.h"
5 #include "barchartmodel_p.h"
5 #include "qbarchartseries.h"
6 6 #include <QPen>
7 7 #include <QBrush>
8 8 #include <QGraphicsItem>
@@ -20,11 +20,10 class BarPresenterBase : public QObject, public ChartItem
20 20 {
21 21 Q_OBJECT
22 22 public:
23 BarPresenterBase(BarChartModel& model, QGraphicsItem *parent = 0);
24 void setSeparatorsVisible(bool visible = true);
23 BarPresenterBase(QBarChartSeries *series, QGraphicsItem *parent = 0);
24 ~BarPresenterBase();
25 25
26 26 public:
27
28 27 // From QGraphicsItem
29 28 void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
30 29 QRectF boundingRect() const;
@@ -41,8 +40,11 protected slots:
41 40 void handleDomainChanged(const Domain& domain);
42 41 void handleGeometryChanged(const QRectF& size);
43 42
44 void barHoverEntered(QGraphicsSceneHoverEvent *event); // Internal.
45 void barHoverLeaved(QGraphicsSceneHoverEvent *event);
43 // Internal slots
44 void enableFloatingValues(bool enabled=true); // enables floating values on top of bars
45 void enableToolTip(bool enabled=true); // enables tooltips
46 void enableSeparators(bool enabled=true); // enables separators between categories
47 void showToolTip(QPoint pos, QString tip); // shows tooltip (if enabled)
46 48
47 49 protected:
48 50
@@ -54,14 +56,19 protected:
54 56 bool mLayoutSet; // True, if component has been laid out.
55 57 bool mLayoutDirty;
56 58
57 bool mSeparatorsVisible;
58 BarChartModel& mModel;
59 bool mFloatingValuesEnabled;
60 bool mToolTipEnabled;
61 bool mSeparatorsEnabled;
62
63 // Owned
64 QBarChartSeries* mSeries;
59 65
60 66 // Not owned.
61 67 QList<Bar*> mBars;
62 68 QList<BarLabel*> mLabels;
63 69 QList<Separator*> mSeparators;
64 70 QList<BarValue*> mFloatingValues;
71
65 72 };
66 73
67 74 QTCOMMERCIALCHART_END_NAMESPACE
@@ -9,8 +9,8
9 9 QTCOMMERCIALCHART_BEGIN_NAMESPACE
10 10
11 11
12 PercentBarPresenter::PercentBarPresenter(BarChartModel& model, QGraphicsItem *parent) :
13 BarPresenterBase(model, parent)
12 PercentBarPresenter::PercentBarPresenter(QBarChartSeries *series, QGraphicsItem *parent) :
13 BarPresenterBase(series, parent)
14 14 {
15 15 }
16 16
@@ -18,7 +18,7 void PercentBarPresenter::layoutChanged()
18 18 {
19 19 // Scale bars to new layout
20 20 // Layout for bars:
21 if (mModel.countSets() <= 0) {
21 if (mSeries->countSets() <= 0) {
22 22 qDebug() << "No sets in model!";
23 23 // Nothing to do.
24 24 return;
@@ -31,7 +31,7 void PercentBarPresenter::layoutChanged()
31 31
32 32 // TODO: better way to auto-layout
33 33 // Use reals for accurancy (we might get some compiler warnings... :)
34 int count = mModel.countCategories();
34 int count = mSeries->countCategories();
35 35 int itemIndex(0);
36 36 int labelIndex(0);
37 37 qreal tW = mWidth;
@@ -40,17 +40,17 void PercentBarPresenter::layoutChanged()
40 40 qreal xPos = ((tW/tC) - mBarDefaultWidth / 2);
41 41 qreal h = mHeight;
42 42
43 for (int category = 0; category < mModel.countCategories(); category++) {
44 qreal colSum = mModel.categorySum(category);
43 for (int category = 0; category < mSeries->countCategories(); category++) {
44 qreal colSum = mSeries->categorySum(category);
45 45 qreal scale = (h / colSum);
46 46 qreal yPos = h;
47 for (int set=0; set < mModel.countSets(); set++) {
48 qreal barHeight = mModel.valueAt(set, category) * scale;
47 for (int set=0; set < mSeries->countSets(); set++) {
48 qreal barHeight = mSeries->valueAt(set, category) * scale;
49 49 Bar* bar = mBars.at(itemIndex);
50 50
51 51 // TODO: width settable per bar?
52 52 bar->resize(mBarDefaultWidth, barHeight);
53 bar->setBrush(mModel.setAt(set)->brush());
53 bar->setBrush(mSeries->setAt(set)->brush());
54 54 bar->setPos(xPos, yPos-barHeight);
55 55 itemIndex++;
56 56 yPos -= barHeight;
@@ -65,7 +65,7 void PercentBarPresenter::layoutChanged()
65 65
66 66 // Position separators
67 67 xPos = xStep + xStep/2;
68 for (int s=0; s < mModel.countCategories() - 1; s++) {
68 for (int s=0; s < mSeries->countCategories() - 1; s++) {
69 69 Separator* sep = mSeparators.at(s);
70 70 sep->setPos(xPos,0);
71 71 sep->setSize(QSizeF(1,mHeight));
@@ -75,12 +75,12 void PercentBarPresenter::layoutChanged()
75 75 // Position floating values
76 76 itemIndex = 0;
77 77 xPos = ((tW/tC) - mBarDefaultWidth / 2);
78 for (int category=0; category < mModel.countCategories(); category++) {
78 for (int category=0; category < mSeries->countCategories(); category++) {
79 79 qreal yPos = h;
80 qreal colSum = mModel.categorySum(category);
80 qreal colSum = mSeries->categorySum(category);
81 81 qreal scale = (h / colSum);
82 for (int set=0; set < mModel.countSets(); set++) {
83 qreal barHeight = mModel.valueAt(set,category) * scale;
82 for (int set=0; set < mSeries->countSets(); set++) {
83 qreal barHeight = mSeries->valueAt(set,category) * scale;
84 84 BarValue* value = mFloatingValues.at(itemIndex);
85 85
86 86 // TODO: remove hard coding, apply layout
@@ -88,8 +88,8 void PercentBarPresenter::layoutChanged()
88 88 value->setPos(xPos, yPos-barHeight/2);
89 89 value->setPen(QPen(QColor(255,255,255,255)));
90 90
91 if (mModel.valueAt(set,category) != 0) {
92 int p = mModel.percentageAt(set,category) * 100;
91 if (mSeries->valueAt(set,category) != 0) {
92 int p = mSeries->percentageAt(set,category) * 100;
93 93 QString vString(QString::number(p));
94 94 vString.truncate(3);
95 95 vString.append("%");
@@ -107,4 +107,6 void PercentBarPresenter::layoutChanged()
107 107 mLayoutDirty = true;
108 108 }
109 109
110 #include "moc_percentbarpresenter.cpp"
111
110 112 QTCOMMERCIALCHART_END_NAMESPACE
@@ -11,8 +11,9 QTCOMMERCIALCHART_BEGIN_NAMESPACE
11 11
12 12 class PercentBarPresenter : public BarPresenterBase
13 13 {
14 Q_OBJECT
14 15 public:
15 PercentBarPresenter(BarChartModel& model, QGraphicsItem *parent = 0);
16 PercentBarPresenter(QBarChartSeries *series, QGraphicsItem *parent = 0);
16 17
17 18 private:
18 19
@@ -15,15 +15,18 QBarChartSeries::QBarChartSeries(QBarCategory *category, QObject *parent)
15 15
16 16 void QBarChartSeries::addBarSet(QBarSet *set)
17 17 {
18 // connect(this,SIGNAL(floatingValuesEnabled(bool)),set,SLOT(enableFloatingValues(bool)));
19 // connect(this,SIGNAL(hoverNamesEnabled(bool)),set,SLOT(enableHoverNames(bool)));
18 connect(this,SIGNAL(floatingValuesEnabled(bool)),set,SLOT(enableFloatingValues(bool)));
19 connect(this,SIGNAL(separatorsEnabled(bool)),set,SLOT(enableSeparators(bool)));
20 connect(this,SIGNAL(toolTipEnabled(bool)),set,SLOT(enableToolTip(bool)));
21 connect(set,SIGNAL(showToolTip(QPoint,QString)),this,SIGNAL(showToolTip(QPoint,QString)));
20 22 mModel->addBarSet(set);
21 23 }
22 24
23 25 void QBarChartSeries::removeBarSet(QBarSet *set)
24 26 {
25 // disconnect(set,SLOT(enableFloatingValues(bool)));
26 // disconnect(set,SLOT(enableHoverNames(bool)));
27 disconnect(set,SLOT(enableFloatingValues(bool)));
28 disconnect(set,SLOT(enableSeparators(bool)));
29 disconnect(set,SLOT(enableToolTip(bool)));
27 30 mModel->removeBarSet(set);
28 31 }
29 32
@@ -37,19 +40,34 QBarSet* QBarChartSeries::nextSet(bool getFirst)
37 40 return mModel->nextSet(getFirst);
38 41 }
39 42
43 QBarSet* QBarChartSeries::setAt(int index)
44 {
45 return mModel->setAt(index);
46 }
47
40 48 QList<QString> QBarChartSeries::legend()
41 49 {
42 50 return mModel->legend();
43 51 }
44 52
53 QString QBarChartSeries::label(int category)
54 {
55 return mModel->label(category);
56 }
57
45 58 void QBarChartSeries::enableFloatingValues(bool enabled)
46 59 {
47 60 emit floatingValuesEnabled(enabled);
48 61 }
49 62
50 void QBarChartSeries::enableHoverNames(bool enabled)
63 void QBarChartSeries::enableToolTip(bool enabled)
51 64 {
52 emit hoverNamesEnabled(enabled);
65 emit toolTipEnabled(enabled);
66 }
67
68 void QBarChartSeries::enableSeparators(bool enabled)
69 {
70 emit separatorsEnabled(enabled);
53 71 }
54 72
55 73 int QBarChartSeries::countCategories()
@@ -72,6 +90,16 qreal QBarChartSeries::valueAt(int set, int category)
72 90 return mModel->valueAt(set,category);
73 91 }
74 92
93 qreal QBarChartSeries::percentageAt(int set, int category)
94 {
95 return mModel->percentageAt(set,category);
96 }
97
98 qreal QBarChartSeries::categorySum(int category)
99 {
100 return mModel->categorySum(category);
101 }
102
75 103 qreal QBarChartSeries::maxCategorySum()
76 104 {
77 105 return mModel->maxCategorySum();
@@ -22,19 +22,27 public:
22 22 void removeBarSet(QBarSet *set); // Releases ownership, doesn't delete set
23 23 int countSets();
24 24 QBarSet* nextSet(bool getFirst=false); // Returns first set, if called with true
25 QBarSet *setAt(int index);
25 26
26 27 QList<QString> legend(); // Returns legend of series (ie. names of all sets in series)
28 QString label(int category);
27 29
30 public Q_SLOTS:
28 31 // Disabled by default. Call these to change behavior.
29 void enableFloatingValues(bool enabled=true);
30 void enableHoverNames(bool enabled=true);
32 void enableFloatingValues(bool enabled=true); // enables floating values on top of bars
33 void enableToolTip(bool enabled=true); // enables tooltips
34 void enableSeparators(bool enabled=true); // enables separators between categories
31 35
36 public:
32 37 // TODO: Functions below this are not part of api and will be moved
33 38 // to private implementation, when we start using it (not part of api)
34 39 int countCategories();
35 40 qreal min();
36 41 qreal max();
37 42 qreal valueAt(int set, int category);
43 qreal percentageAt(int set, int category);
44
45 qreal categorySum(int category);
38 46 qreal maxCategorySum();
39 47
40 48 BarChartModel& model();
@@ -42,12 +50,11 public:
42 50 signals:
43 51 void changed(int index);
44 52
45 // TODO: these to private implementation.
53 // TODO: internal signals, these to private implementation.
46 54 void floatingValuesEnabled(bool enabled);
47 void hoverNamesEnabled(bool enabled);
48
49
50 //public Q_SLOTS:
55 void toolTipEnabled(bool enabled);
56 void separatorsEnabled(bool enabled);
57 void showToolTip(QPoint pos, QString tip);
51 58
52 59 protected:
53 60 BarChartModel* mModel;
@@ -7,7 +7,7 QTCOMMERCIALCHART_BEGIN_NAMESPACE
7 7 QBarSet::QBarSet(QString name, QObject *parent)
8 8 : QObject(parent)
9 9 ,mName(name)
10 ,mHoverNamesEnabled(true) // TODO: these 2 as false by default, when implementation is ready
10 ,mToolTipEnabled(true) // TODO: these 2 as false by default, when implementation is ready
11 11 ,mFloatingValuesEnabled(true)
12 12 {
13 13 }
@@ -64,19 +64,25 const QBrush& QBarSet::brush() const
64 64
65 65 void QBarSet::enableFloatingValues(bool enabled)
66 66 {
67 qDebug() << "QBarSet::enableFloatingValues" << enabled;
67 qDebug() << "QBarSet::enableFloatingValues";
68 68 mFloatingValuesEnabled = enabled;
69 69 }
70 70
71 71 void QBarSet::enableToolTip(bool enabled)
72 72 {
73 qDebug() << "QBarSet::enableHoverNames" << enabled;
74 mHoverNamesEnabled = enabled;
73 qDebug() << "QBarSet::enableToolTip";
74 mToolTipEnabled = enabled;
75 }
76
77 void QBarSet::enableSeparators(bool enabled)
78 {
79 qDebug() << "QBarSet::enableSeparators";
80 mSeparatorsEnabled = enabled;
75 81 }
76 82
77 83 void QBarSet::barClicked()
78 84 {
79 qDebug() << "QBarset::barClicked" << this;
85 // qDebug() << "QBarset::barClicked" << this;
80 86 // Some bar of this set has been clicked
81 87 // TODO: What happens then?
82 88 emit clicked(); // Notify that set has been clicked
@@ -84,19 +90,21 void QBarSet::barClicked()
84 90
85 91 void QBarSet::barHoverEntered(QPoint pos)
86 92 {
87 qDebug() << "QBarset::barHoverEntered" << this << pos;
88 if (mHoverNamesEnabled) {
89 QToolTip::showText(pos, mName);
90 // emit hoverEnter();
93 if (mToolTipEnabled) {
94 emit showToolTip(pos, mName);
91 95 }
96 // Emit signal to user of charts
97 emit hoverEnter(pos);
92 98 }
93 99
94 100 void QBarSet::barHoverLeaved()
95 101 {
96 qDebug() << "QBarset::barHoverLeaved" << this;
97 if (mHoverNamesEnabled) {
98 // emit hoverLeave();
99 }
102 // qDebug() << "QBarset::barHoverLeaved" << this;
103 // if (mToolTipEnabled) {
104 // TODO: do what?
105 // }
106 // Emit signal to user of charts
107 emit hoverLeave();
100 108 }
101 109
102 110 #include "moc_qbarset.cpp"
@@ -29,14 +29,15 public:
29 29
30 30 Q_SIGNALS:
31 31 void clicked(); // Clicked and hover signals exposed to user
32 void hoverEnter();
32 void hoverEnter(QPoint pos);
33 33 void hoverLeave();
34 34 void toggleFloatingValues(); // Private signal, TODO: move to private impl
35 void showToolTip(QPoint pos, QString tip); // Private signal, TODO: move to private impl
35 36
36 37 public Q_SLOTS:
37 // TODO: should these be in series instead?
38 38 void enableFloatingValues(bool enabled); // enables floating values on top of bars
39 39 void enableToolTip(bool enabled); // enables tooltips
40 void enableSeparators(bool enabled); // enables separators between categories
40 41
41 42 // TODO: these slots belong to private implementation.
42 43 // These are for single bars to notify set about internal events
@@ -53,7 +54,8 private:
53 54
54 55 // TODO: to pimpl
55 56 bool mFloatingValuesEnabled;
56 bool mHoverNamesEnabled;
57 bool mToolTipEnabled;
58 bool mSeparatorsEnabled;
57 59 };
58 60
59 61 QTCOMMERCIALCHART_END_NAMESPACE
@@ -8,8 +8,8
8 8
9 9 QTCOMMERCIALCHART_BEGIN_NAMESPACE
10 10
11 StackedBarPresenter::StackedBarPresenter(BarChartModel& model, QGraphicsItem *parent) :
12 BarPresenterBase(model,parent)
11 StackedBarPresenter::StackedBarPresenter(QBarChartSeries *series, QGraphicsItem *parent) :
12 BarPresenterBase(series,parent)
13 13 {
14 14 }
15 15
@@ -17,13 +17,13 void StackedBarPresenter::layoutChanged()
17 17 {
18 18 // Scale bars to new layout
19 19 // Layout for bars:
20 if (mModel.countSets() <= 0) {
20 if (mSeries->countSets() <= 0) {
21 21 qDebug() << "No sets in model!";
22 22 // Nothing to do.
23 23 return;
24 24 }
25 25
26 if (mModel.countCategories() == 0) {
26 if (mSeries->countCategories() == 0) {
27 27 qDebug() << "No categories in model!";
28 28 // Nothing to do
29 29 return;
@@ -37,25 +37,25 void StackedBarPresenter::layoutChanged()
37 37 // TODO: better way to auto-layout
38 38 // Use reals for accurancy (we might get some compiler warnings... :)
39 39 // TODO: use temp variable for category count...
40 qreal maxSum = mModel.maxCategorySum();
40 qreal maxSum = mSeries->maxCategorySum();
41 41 qreal h = mHeight;
42 42 qreal scale = (h / maxSum);
43 43
44 44 int itemIndex(0);
45 45 int labelIndex(0);
46 46 qreal tW = mWidth;
47 qreal tC = mModel.countCategories() + 1;
47 qreal tC = mSeries->countCategories() + 1;
48 48 qreal xStep = (tW/tC);
49 49 qreal xPos = ((tW/tC) - mBarDefaultWidth / 2);
50 50
51 for (int category = 0; category < mModel.countCategories(); category++) {
51 for (int category = 0; category < mSeries->countCategories(); category++) {
52 52 qreal yPos = h;
53 for (int set=0; set < mModel.countSets(); set++) {
54 qreal barHeight = mModel.valueAt(set, category) * scale;
53 for (int set=0; set < mSeries->countSets(); set++) {
54 qreal barHeight = mSeries->valueAt(set, category) * scale;
55 55 Bar* bar = mBars.at(itemIndex);
56 56
57 57 bar->resize(mBarDefaultWidth, barHeight);
58 bar->setBrush(mModel.setAt(set)->brush());
58 bar->setBrush(mSeries->setAt(set)->brush());
59 59 bar->setPos(xPos, yPos-barHeight);
60 60 itemIndex++;
61 61 yPos -= barHeight;
@@ -70,7 +70,7 void StackedBarPresenter::layoutChanged()
70 70
71 71 // Position separators
72 72 xPos = xStep + xStep/2;
73 for (int s=0; s < mModel.countCategories() - 1; s++) {
73 for (int s=0; s < mSeries->countCategories() - 1; s++) {
74 74 Separator* sep = mSeparators.at(s);
75 75 sep->setPos(xPos,0);
76 76 sep->setSize(QSizeF(1,mHeight));
@@ -80,10 +80,10 void StackedBarPresenter::layoutChanged()
80 80 // Position floating values
81 81 itemIndex = 0;
82 82 xPos = ((tW/tC) - mBarDefaultWidth / 2);
83 for (int category=0; category < mModel.countCategories(); category++) {
83 for (int category=0; category < mSeries->countCategories(); category++) {
84 84 qreal yPos = h;
85 for (int set=0; set < mModel.countSets(); set++) {
86 qreal barHeight = mModel.valueAt(set,category) * scale;
85 for (int set=0; set < mSeries->countSets(); set++) {
86 qreal barHeight = mSeries->valueAt(set,category) * scale;
87 87 BarValue* value = mFloatingValues.at(itemIndex);
88 88
89 89 // TODO: remove hard coding, apply layout
@@ -91,8 +91,8 void StackedBarPresenter::layoutChanged()
91 91 value->setPos(xPos, yPos-barHeight/2);
92 92 value->setPen(QPen(QColor(255,255,255,255)));
93 93
94 if (mModel.valueAt(set,category) != 0) {
95 value->setValueString(QString::number(mModel.valueAt(set,category)));
94 if (mSeries->valueAt(set,category) != 0) {
95 value->setValueString(QString::number(mSeries->valueAt(set,category)));
96 96 } else {
97 97 value->setValueString(QString(""));
98 98 }
@@ -106,4 +106,6 void StackedBarPresenter::layoutChanged()
106 106 mLayoutDirty = true;
107 107 }
108 108
109 #include "moc_stackedbarpresenter.cpp"
110
109 111 QTCOMMERCIALCHART_END_NAMESPACE
@@ -9,8 +9,9 QTCOMMERCIALCHART_BEGIN_NAMESPACE
9 9
10 10 class StackedBarPresenter : public BarPresenterBase
11 11 {
12 Q_OBJECT
12 13 public:
13 StackedBarPresenter(BarChartModel& model, QGraphicsItem *parent = 0);
14 StackedBarPresenter(QBarChartSeries *series, QGraphicsItem *parent = 0);
14 15
15 16 private:
16 17 // From BarPresenterBase
@@ -115,7 +115,7 void ChartPresenter::handleSeriesAdded(QChartSeries* series)
115 115
116 116 case QChartSeries::SeriesTypeBar: {
117 117 QBarChartSeries* barSeries = static_cast<QBarChartSeries*>(series);
118 BarPresenter* item = new BarPresenter(barSeries->model(),m_chart);
118 BarPresenter* item = new BarPresenter(barSeries,m_chart);
119 119 m_chartTheme->decorate(item,barSeries,m_chartItems.count());
120 120 QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),item,SLOT(handleGeometryChanged(const QRectF&)));
121 121 QObject::connect(barSeries,SIGNAL(changed(int)),item,SLOT(handleModelChanged(int)));
@@ -127,7 +127,7 void ChartPresenter::handleSeriesAdded(QChartSeries* series)
127 127 case QChartSeries::SeriesTypeStackedBar: {
128 128
129 129 QStackedBarChartSeries* stackedBarSeries = static_cast<QStackedBarChartSeries*>(series);
130 StackedBarPresenter* item = new StackedBarPresenter(stackedBarSeries->model(),m_chart);
130 StackedBarPresenter* item = new StackedBarPresenter(stackedBarSeries,m_chart);
131 131 m_chartTheme->decorate(item,stackedBarSeries,m_chartItems.count());
132 132 QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),item,SLOT(handleGeometryChanged(const QRectF&)));
133 133 QObject::connect(stackedBarSeries,SIGNAL(changed(int)),item,SLOT(handleModelChanged(int)));
@@ -138,7 +138,7 void ChartPresenter::handleSeriesAdded(QChartSeries* series)
138 138 case QChartSeries::SeriesTypePercentBar: {
139 139
140 140 QPercentBarChartSeries* percentBarSeries = static_cast<QPercentBarChartSeries*>(series);
141 PercentBarPresenter* item = new PercentBarPresenter(percentBarSeries->model(),m_chart);
141 PercentBarPresenter* item = new PercentBarPresenter(percentBarSeries,m_chart);
142 142 m_chartTheme->decorate(item,percentBarSeries ,m_chartItems.count());
143 143 QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),item,SLOT(handleGeometryChanged(const QRectF&)));
144 144 QObject::connect(percentBarSeries,SIGNAL(changed(int)),item,SLOT(handleModelChanged(int)));
General Comments 0
You need to be logged in to leave comments. Login now