@@ -360,7 +360,6 void ThemeWidget::updateUI() | |||
|
360 | 360 | |
|
361 | 361 | QLegend::Alignments alignment(m_legendComboBox->itemData(m_legendComboBox->currentIndex()).toInt()); |
|
362 | 362 | foreach (QChartView *chartView, m_charts) { |
|
363 | qDebug() << alignment; | |
|
364 | 363 | chartView->chart()->legend()->setAlignmnent(alignment); |
|
365 | 364 | } |
|
366 | 365 | } |
@@ -11,7 +11,7 SOURCES += \ | |||
|
11 | 11 | $$PWD/qpercentbarseries.cpp \ |
|
12 | 12 | $$PWD/qstackedbarseries.cpp \ |
|
13 | 13 | $$PWD/stackedbarchartitem.cpp \ |
|
14 |
$$PWD/bar |
|
|
14 | $$PWD/barlabel.cpp | |
|
15 | 15 | |
|
16 | 16 | PRIVATE_HEADERS += \ |
|
17 | 17 | $$PWD/bar_p.h \ |
@@ -19,7 +19,7 PRIVATE_HEADERS += \ | |||
|
19 | 19 | $$PWD/barchartitem_p.h \ |
|
20 | 20 | $$PWD/percentbarchartitem_p.h \ |
|
21 | 21 | $$PWD/stackedbarchartitem_p.h \ |
|
22 |
$$PWD/bar |
|
|
22 | $$PWD/barlabel_p.h | |
|
23 | 23 | |
|
24 | 24 | PUBLIC_HEADERS += \ |
|
25 | 25 | $$PWD/qbarseries.h \ |
@@ -20,7 +20,7 | |||
|
20 | 20 | |
|
21 | 21 | #include "barchartitem_p.h" |
|
22 | 22 | #include "bar_p.h" |
|
23 |
#include "bar |
|
|
23 | #include "barlabel_p.h" | |
|
24 | 24 | #include "qbarset.h" |
|
25 | 25 | #include "qbarseries.h" |
|
26 | 26 | #include "qchart.h" |
@@ -75,7 +75,7 void BarChartItem::dataChanged() | |||
|
75 | 75 | delete item; |
|
76 | 76 | |
|
77 | 77 | m_bars.clear(); |
|
78 |
m_ |
|
|
78 | m_labels.clear(); | |
|
79 | 79 | m_layout.clear(); |
|
80 | 80 | |
|
81 | 81 | // Create new graphic items for bars |
@@ -93,14 +93,14 void BarChartItem::dataChanged() | |||
|
93 | 93 | } |
|
94 | 94 | } |
|
95 | 95 | |
|
96 |
// Create |
|
|
96 | // Create labels | |
|
97 | 97 | for (int category = 0; category < m_series->categoryCount(); category++) { |
|
98 | 98 | for (int s = 0; s < m_series->barsetCount(); s++) { |
|
99 | 99 | QBarSet *set = m_series->barsetAt(s); |
|
100 |
Bar |
|
|
100 | BarLabel *value = new BarLabel(*set, this); | |
|
101 | 101 | childItems().append(value); |
|
102 |
m_ |
|
|
103 |
connect(set,SIGNAL( |
|
|
102 | m_labels.append(value); | |
|
103 | connect(set,SIGNAL(labelsVisibleChanged(bool)),value,SLOT(labelsVisibleChanged(bool))); | |
|
104 | 104 | } |
|
105 | 105 | } |
|
106 | 106 | } |
@@ -142,17 +142,17 QVector<QRectF> BarChartItem::calculateLayout() | |||
|
142 | 142 | bar->setPen(barSet->pen()); |
|
143 | 143 | bar->setBrush(barSet->brush()); |
|
144 | 144 | |
|
145 |
Bar |
|
|
145 | BarLabel* label = m_labels.at(itemIndex); | |
|
146 | 146 | |
|
147 | 147 | if (!qFuzzyIsNull(barSet->valueAt(category))) { |
|
148 |
|
|
|
148 | label->setText(QString::number(barSet->valueAt(category))); | |
|
149 | 149 | } else { |
|
150 |
|
|
|
150 | label->setText(QString("")); | |
|
151 | 151 | } |
|
152 | 152 | |
|
153 |
|
|
|
154 |
,yPos - barHeight/2 - |
|
|
155 |
value->set |
|
|
153 | label->setPos(xPos + (rect.width()/2 - label->boundingRect().width()/2) | |
|
154 | ,yPos - barHeight/2 - label->boundingRect().height()/2); | |
|
155 | // value->setFont(barSet->valueFont()); | |
|
156 | 156 | |
|
157 | 157 | itemIndex++; |
|
158 | 158 | xPos += barWidth; |
@@ -29,7 +29,7 | |||
|
29 | 29 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
30 | 30 | |
|
31 | 31 | class Bar; |
|
32 |
class Bar |
|
|
32 | class BarLabel; | |
|
33 | 33 | class QChartAxisCategories; |
|
34 | 34 | class QChart; |
|
35 | 35 | |
@@ -81,7 +81,7 protected: | |||
|
81 | 81 | // Not owned. |
|
82 | 82 | QBarSeries *m_series; |
|
83 | 83 | QList<Bar *> m_bars; |
|
84 |
QList<Bar |
|
|
84 | QList<BarLabel *> m_labels; | |
|
85 | 85 | }; |
|
86 | 86 | |
|
87 | 87 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -18,73 +18,87 | |||
|
18 | 18 | ** |
|
19 | 19 | ****************************************************************************/ |
|
20 | 20 | |
|
21 |
#include "bar |
|
|
21 | #include "barlabel_p.h" | |
|
22 | #include "chartpresenter_p.h" | |
|
23 | #include <QBarSet> | |
|
22 | 24 | #include <QPainter> |
|
23 | 25 | #include <QPen> |
|
24 | 26 | #include <QGraphicsSimpleTextItem> |
|
25 | 27 | |
|
26 | 28 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
27 | 29 | |
|
28 |
Bar |
|
|
29 |
m_barSet( |
|
|
30 | BarLabel::BarLabel(QBarSet &barSet, QGraphicsItem *parent) : QGraphicsObject(parent), | |
|
31 | m_barSet(barSet), | |
|
30 | 32 | m_textItem(new QGraphicsSimpleTextItem(this)) |
|
31 | 33 | { |
|
32 |
// connect(&set,SIGNAL( |
|
|
33 | setVisible(false); | |
|
34 | // connect(&set,SIGNAL(labelsVisibleChanged(bool)),value,SLOT(labelsVisibleChanged(bool))); | |
|
35 | setZValue(ChartPresenter::BarSeriesZValue + 1); | |
|
36 | setVisible(barSet.labelsVisible()); | |
|
37 | setPen(Qt::NoPen); | |
|
38 | setBrush(Qt::SolidPattern); | |
|
34 | 39 | } |
|
35 | 40 | |
|
36 |
void Bar |
|
|
41 | void BarLabel::setText(QString str) | |
|
37 | 42 | { |
|
38 | 43 | m_textItem->setText(str); |
|
39 | 44 | } |
|
40 | 45 | |
|
41 |
QString Bar |
|
|
46 | QString BarLabel::text() const | |
|
42 | 47 | { |
|
43 | 48 | return m_textItem->text(); |
|
44 | 49 | } |
|
45 | 50 | |
|
46 |
void Bar |
|
|
51 | void BarLabel::setPen(const QPen &pen) | |
|
47 | 52 | { |
|
48 | 53 | m_textItem->setPen(pen); |
|
49 | 54 | } |
|
50 | 55 | |
|
51 |
QPen Bar |
|
|
56 | QPen BarLabel::pen() const | |
|
52 | 57 | { |
|
53 | 58 | return m_textItem->pen(); |
|
54 | 59 | } |
|
55 | 60 | |
|
56 |
void Bar |
|
|
61 | void BarLabel::setBrush(const QBrush &brush) | |
|
62 | { | |
|
63 | m_textItem->setBrush(brush); | |
|
64 | } | |
|
65 | ||
|
66 | QBrush BarLabel::brush() const | |
|
67 | { | |
|
68 | return m_textItem->brush(); | |
|
69 | } | |
|
70 | ||
|
71 | void BarLabel::setFont(const QFont &font) | |
|
57 | 72 | { |
|
58 | 73 | m_textItem->setFont(font); |
|
59 | 74 | } |
|
60 | 75 | |
|
61 |
QFont Bar |
|
|
76 | QFont BarLabel::font() const | |
|
62 | 77 | { |
|
63 | 78 | return m_textItem->font(); |
|
64 | 79 | } |
|
65 | 80 | |
|
66 |
void Bar |
|
|
81 | void BarLabel::setPos(qreal x, qreal y) | |
|
67 | 82 | { |
|
68 | 83 | m_textItem->setPos(x,y); |
|
69 | 84 | } |
|
70 | 85 | |
|
71 |
void Bar |
|
|
86 | void BarLabel::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) | |
|
72 | 87 | { |
|
73 | 88 | Q_UNUSED(painter) |
|
74 | 89 | Q_UNUSED(option) |
|
75 | 90 | Q_UNUSED(widget) |
|
76 | 91 | } |
|
77 | 92 | |
|
78 |
QRectF Bar |
|
|
93 | QRectF BarLabel::boundingRect() const | |
|
79 | 94 | { |
|
80 | 95 | return m_textItem->boundingRect(); |
|
81 | 96 | } |
|
82 | 97 | |
|
83 |
void Bar |
|
|
98 | void BarLabel::labelsVisibleChanged(bool visible) | |
|
84 | 99 | { |
|
85 | qDebug() << "BarValue visiblle changed:" <<visible; | |
|
86 | 100 | setVisible(visible); |
|
87 | 101 | } |
|
88 | 102 | |
|
89 |
#include "moc_bar |
|
|
103 | #include "moc_barlabel_p.cpp" | |
|
90 | 104 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -18,8 +18,8 | |||
|
18 | 18 | ** |
|
19 | 19 | ****************************************************************************/ |
|
20 | 20 | |
|
21 |
#ifndef BAR |
|
|
22 |
#define BAR |
|
|
21 | #ifndef BARLABEL_P_H | |
|
22 | #define BARLABEL_P_H | |
|
23 | 23 | |
|
24 | 24 | #include "qchartglobal.h" |
|
25 | 25 | #include <QGraphicsObject> |
@@ -32,11 +32,11 class QBarSet; | |||
|
32 | 32 | |
|
33 | 33 | // Visual class for bar values |
|
34 | 34 | // By default these are not visible. |
|
35 |
class Bar |
|
|
35 | class BarLabel : public QGraphicsObject | |
|
36 | 36 | { |
|
37 | 37 | Q_OBJECT |
|
38 | 38 | public: |
|
39 |
Bar |
|
|
39 | BarLabel(QBarSet &barSet, QGraphicsItem *parent = 0); | |
|
40 | 40 | |
|
41 | 41 | void setText(QString str); |
|
42 | 42 | QString text() const; |
@@ -44,6 +44,9 public: | |||
|
44 | 44 | void setPen(const QPen &pen); |
|
45 | 45 | QPen pen() const; |
|
46 | 46 | |
|
47 | void setBrush(const QBrush &brush); | |
|
48 | QBrush brush() const; | |
|
49 | ||
|
47 | 50 | void setFont(const QFont &font); |
|
48 | 51 | QFont font() const; |
|
49 | 52 | |
@@ -54,7 +57,7 public: | |||
|
54 | 57 | QRectF boundingRect() const; |
|
55 | 58 | |
|
56 | 59 | public Q_SLOTS: |
|
57 |
void |
|
|
60 | void labelsVisibleChanged(bool visible); | |
|
58 | 61 | |
|
59 | 62 | private: |
|
60 | 63 | |
@@ -64,4 +67,4 private: | |||
|
64 | 67 | |
|
65 | 68 | QTCOMMERCIALCHART_END_NAMESPACE |
|
66 | 69 | |
|
67 |
#endif // BAR |
|
|
70 | #endif // BARLABEL_P_H |
@@ -20,7 +20,7 | |||
|
20 | 20 | |
|
21 | 21 | #include "percentbarchartitem_p.h" |
|
22 | 22 | #include "bar_p.h" |
|
23 |
#include "bar |
|
|
23 | #include "barlabel_p.h" | |
|
24 | 24 | #include "qbarset.h" |
|
25 | 25 | #include <QDebug> |
|
26 | 26 | |
@@ -58,21 +58,21 QVector<QRectF> PercentBarChartItem::calculateLayout() | |||
|
58 | 58 | QRectF rect(xPos, yPos-barHeight, barWidth, barHeight); |
|
59 | 59 | layout.append(rect); |
|
60 | 60 | |
|
61 |
Bar |
|
|
61 | BarLabel* label = m_labels.at(itemIndex); | |
|
62 | 62 | |
|
63 | 63 | if (!qFuzzyIsNull(m_series->valueAt(set,category))) { |
|
64 | 64 | int p = m_series->percentageAt(set,category) * 100; |
|
65 | 65 | QString vString(QString::number(p)); |
|
66 | 66 | vString.truncate(3); |
|
67 | 67 | vString.append("%"); |
|
68 |
|
|
|
68 | label->setText(vString); | |
|
69 | 69 | } else { |
|
70 |
|
|
|
70 | label->setText(QString("")); | |
|
71 | 71 | } |
|
72 | 72 | |
|
73 |
|
|
|
74 |
,yPos - barHeight/2 - |
|
|
75 |
value->set |
|
|
73 | label->setPos(xPos + (rect.width()/2 - label->boundingRect().width()/2) | |
|
74 | ,yPos - barHeight/2 - label->boundingRect().height()/2); | |
|
75 | // value->setFont(barSet->valueFont()); | |
|
76 | 76 | itemIndex++; |
|
77 | 77 | yPos -= barHeight; |
|
78 | 78 | } |
@@ -391,10 +391,10 QBarCategories QBarSeries::categories() const | |||
|
391 | 391 | return categories; |
|
392 | 392 | } |
|
393 | 393 | |
|
394 |
void QBarSeries::set |
|
|
394 | void QBarSeries::setLabelsVisible(bool visible) | |
|
395 | 395 | { |
|
396 | 396 | foreach (QBarSet* s, barSets()) { |
|
397 |
s->set |
|
|
397 | s->setLabelsVisible(visible); | |
|
398 | 398 | } |
|
399 | 399 | } |
|
400 | 400 |
@@ -51,7 +51,7 public: | |||
|
51 | 51 | QList<QBarSet*> barSets() const; |
|
52 | 52 | QBarCategories categories() const; |
|
53 | 53 | |
|
54 |
void set |
|
|
54 | void setLabelsVisible(bool visible = true); | |
|
55 | 55 | |
|
56 | 56 | bool setModel(QAbstractItemModel *model); |
|
57 | 57 | QAbstractItemModel *modelExt() { return m_model; } |
@@ -56,8 +56,8 QTCOMMERCIALCHART_BEGIN_NAMESPACE | |||
|
56 | 56 | */ |
|
57 | 57 | |
|
58 | 58 | /*! |
|
59 |
\fn void QBarSet::set |
|
|
60 |
\brief Sets visibility of bar |
|
|
59 | \fn void QBarSet::setLabelssVisible(bool visible = true) | |
|
60 | \brief Sets visibility of bar labels. If \a visible is true, labels are drawn on top of barsets. | |
|
61 | 61 | */ |
|
62 | 62 | |
|
63 | 63 | /*! |
@@ -72,6 +72,7 QTCOMMERCIALCHART_BEGIN_NAMESPACE | |||
|
72 | 72 | QBarSet::QBarSet(QString name, QObject *parent) |
|
73 | 73 | : QObject(parent) |
|
74 | 74 | ,m_name(name) |
|
75 | ,m_labelsVisible(false) | |
|
75 | 76 | { |
|
76 | 77 | } |
|
77 | 78 | |
@@ -183,27 +184,71 QBrush QBarSet::brush() const | |||
|
183 | 184 | } |
|
184 | 185 | |
|
185 | 186 | /*! |
|
186 |
Sets |
|
|
187 | Sets pen of the values that are drawn on top of this barset | |
|
187 | 188 | */ |
|
188 |
void QBarSet::set |
|
|
189 | void QBarSet::setLabelPen(const QPen &pen) | |
|
189 | 190 | { |
|
190 |
m_ |
|
|
191 | m_labelPen = pen; | |
|
192 | emit valueChanged(); | |
|
193 | } | |
|
194 | ||
|
195 | /*! | |
|
196 | Returns pen of the values that are drawn on top of this barset | |
|
197 | */ | |
|
198 | QPen QBarSet::labelPen() const | |
|
199 | { | |
|
200 | return m_labelPen; | |
|
201 | } | |
|
202 | ||
|
203 | /*! | |
|
204 | Sets brush of the values that are drawn on top of this barset | |
|
205 | */ | |
|
206 | void QBarSet::setLabelBrush(const QBrush &brush) | |
|
207 | { | |
|
208 | m_labelBrush = brush; | |
|
209 | emit valueChanged(); | |
|
210 | } | |
|
211 | ||
|
212 | /*! | |
|
213 | Returns brush of the values that are drawn on top of this barset | |
|
214 | */ | |
|
215 | QBrush QBarSet::labelBrush() const | |
|
216 | { | |
|
217 | return m_labelBrush; | |
|
218 | } | |
|
219 | ||
|
220 | /*! | |
|
221 | Sets the pen for values that are drawn on top of this barset | |
|
222 | */ | |
|
223 | void QBarSet::setLabelFont(const QFont &font) | |
|
224 | { | |
|
225 | m_labelFont = font; | |
|
226 | emit valueChanged(); | |
|
191 | 227 | } |
|
192 | 228 | |
|
193 | 229 | /*! |
|
194 | 230 | Returns the pen for values that are drawn on top of this set |
|
195 | 231 | */ |
|
196 |
Q |
|
|
232 | QFont QBarSet::labelFont() const | |
|
197 | 233 | { |
|
198 |
return m_ |
|
|
234 | return m_labelFont; | |
|
199 | 235 | } |
|
200 | 236 | |
|
201 | 237 | /*! |
|
202 | 238 | Sets the visibility of barset values to \a visible |
|
203 | 239 | */ |
|
204 |
void QBarSet::set |
|
|
240 | void QBarSet::setLabelsVisible(bool visible) | |
|
241 | { | |
|
242 | m_labelsVisible = visible; | |
|
243 | emit labelsVisibleChanged(visible); | |
|
244 | } | |
|
245 | ||
|
246 | /*! | |
|
247 | Returns the visibility of values | |
|
248 | */ | |
|
249 | bool QBarSet::labelsVisible() const | |
|
205 | 250 | { |
|
206 | emit valuesVisibleChanged(visible); | |
|
251 | return m_labelsVisible; | |
|
207 | 252 | } |
|
208 | 253 | |
|
209 | 254 | /*! |
@@ -24,6 +24,7 | |||
|
24 | 24 | #include <qchartglobal.h> |
|
25 | 25 | #include <QPen> |
|
26 | 26 | #include <QBrush> |
|
27 | #include <QFont> | |
|
27 | 28 | |
|
28 | 29 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
29 | 30 | |
@@ -55,10 +56,17 public: | |||
|
55 | 56 | void setBrush(const QBrush &brush); |
|
56 | 57 | QBrush brush() const; |
|
57 | 58 | |
|
58 |
void set |
|
|
59 |
QPen |
|
|
59 | void setLabelPen(const QPen &pen); | |
|
60 | QPen labelPen() const; | |
|
60 | 61 | |
|
61 | void setValuesVisible(bool visible = true); | |
|
62 | void setLabelBrush(const QBrush &brush); | |
|
63 | QBrush labelBrush() const; | |
|
64 | ||
|
65 | void setLabelFont(const QFont &font); | |
|
66 | QFont labelFont() const; | |
|
67 | ||
|
68 | void setLabelsVisible(bool visible = true); | |
|
69 | bool labelsVisible() const; | |
|
62 | 70 | |
|
63 | 71 | Q_SIGNALS: |
|
64 | 72 | void clicked(QString category, Qt::MouseButtons button); // Clicked and hover signals exposed to user |
@@ -69,7 +77,7 Q_SIGNALS: | |||
|
69 | 77 | void hoverEnter(QPoint pos); |
|
70 | 78 | void hoverLeave(); |
|
71 | 79 | void showToolTip(QPoint pos, QString tip); // Private signal |
|
72 |
void |
|
|
80 | void labelsVisibleChanged(bool visible); | |
|
73 | 81 | // <--- TO PIMPL |
|
74 | 82 | |
|
75 | 83 | public Q_SLOTS: |
@@ -86,7 +94,10 private: | |||
|
86 | 94 | QMap<QString, qreal> m_mappedValues; |
|
87 | 95 | QPen m_pen; |
|
88 | 96 | QBrush m_brush; |
|
89 |
QPen m_ |
|
|
97 | QPen m_labelPen; | |
|
98 | QBrush m_labelBrush; | |
|
99 | QFont m_labelFont; | |
|
100 | bool m_labelsVisible; | |
|
90 | 101 | }; |
|
91 | 102 | |
|
92 | 103 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -20,7 +20,7 | |||
|
20 | 20 | |
|
21 | 21 | #include "stackedbarchartitem_p.h" |
|
22 | 22 | #include "bar_p.h" |
|
23 |
#include "bar |
|
|
23 | #include "barlabel_p.h" | |
|
24 | 24 | #include "qbarset.h" |
|
25 | 25 | #include <QDebug> |
|
26 | 26 | |
@@ -60,25 +60,24 QVector<QRectF> StackedBarChartItem::calculateLayout() | |||
|
60 | 60 | for (int set=0; set < m_series->barsetCount(); set++) { |
|
61 | 61 | QBarSet* barSet = m_series->barsetAt(set); |
|
62 | 62 | |
|
63 |
qreal barHeight = barSet->valueAt(category) * scale; |
|
|
63 | qreal barHeight = barSet->valueAt(category) * scale; | |
|
64 | 64 | Bar* bar = m_bars.at(itemIndex); |
|
65 | 65 | bar->setPen(barSet->pen()); |
|
66 | 66 | bar->setBrush(barSet->brush()); |
|
67 | 67 | QRectF rect(xPos, yPos-barHeight, barWidth, barHeight); |
|
68 | 68 | layout.append(rect); |
|
69 | 69 | |
|
70 |
Bar |
|
|
70 | BarLabel* label = m_labels.at(itemIndex); | |
|
71 | 71 | |
|
72 | 72 | if (!qFuzzyIsNull(barSet->valueAt(category))) { |
|
73 |
|
|
|
73 | label->setText(QString::number(barSet->valueAt(category))); | |
|
74 | 74 | } else { |
|
75 |
|
|
|
75 | label->setText(QString("")); | |
|
76 | 76 | } |
|
77 | 77 | |
|
78 |
|
|
|
79 |
,yPos - barHeight/2 - |
|
|
80 |
value->set |
|
|
81 | ||
|
78 | label->setPos(xPos + (rect.width()/2 - label->boundingRect().width()/2) | |
|
79 | ,yPos - barHeight/2 - label->boundingRect().height()/2); | |
|
80 | // value->setFont(barSet->valueFont()); | |
|
82 | 81 | itemIndex++; |
|
83 | 82 | yPos -= barHeight; |
|
84 | 83 | } |
@@ -183,9 +183,9 void ChartTheme::decorate(QBarSeries* series, int index, bool force) | |||
|
183 | 183 | // Pick label color from the opposite end of the gradient. |
|
184 | 184 | // 0.3 as a boundary seems to work well. |
|
185 | 185 | if (takeAtPos < 0.3) |
|
186 |
sets.at(i)->set |
|
|
186 | sets.at(i)->setLabelBrush(colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 1)); | |
|
187 | 187 | else |
|
188 |
sets.at(i)->set |
|
|
188 | sets.at(i)->setLabelBrush(colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 0)); | |
|
189 | 189 | |
|
190 | 190 | if (pen == sets.at(i)->pen() || force) { |
|
191 | 191 | QColor c = colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 0.0); |
General Comments 0
You need to be logged in to leave comments.
Login now