@@ -0,0 +1,121 | |||||
|
1 | /**************************************************************************** | |||
|
2 | ** | |||
|
3 | ** Copyright (C) 2012 Digia Plc | |||
|
4 | ** All rights reserved. | |||
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |||
|
6 | ** | |||
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |||
|
8 | ** | |||
|
9 | ** $QT_BEGIN_LICENSE$ | |||
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |||
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |||
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |||
|
13 | ** a written agreement between you and Digia. | |||
|
14 | ** | |||
|
15 | ** If you have questions regarding the use of this file, please use | |||
|
16 | ** contact form at http://qt.digia.com | |||
|
17 | ** $QT_END_LICENSE$ | |||
|
18 | ** | |||
|
19 | ****************************************************************************/ | |||
|
20 | ||||
|
21 | // W A R N I N G | |||
|
22 | // ------------- | |||
|
23 | // | |||
|
24 | // This file is not part of the QtCommercial Chart API. It exists purely as an | |||
|
25 | // implementation detail. This header file may change from version to | |||
|
26 | // version without notice, or even be removed. | |||
|
27 | // | |||
|
28 | // We mean it. | |||
|
29 | ||||
|
30 | #ifndef QLEGENDMARKERPRIVATE_H | |||
|
31 | #define QLEGENDMARKERPRIVATE_H | |||
|
32 | ||||
|
33 | #include "qchartglobal.h" | |||
|
34 | #include <QGraphicsObject> | |||
|
35 | #include <QBrush> | |||
|
36 | #include <QPen> | |||
|
37 | #include <QGraphicsSimpleTextItem> | |||
|
38 | #include <QGraphicsLayoutItem> | |||
|
39 | ||||
|
40 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |||
|
41 | ||||
|
42 | // TODO: check these | |||
|
43 | class QAbstractSeries; | |||
|
44 | class QAreaSeries; | |||
|
45 | class QXYSeries; | |||
|
46 | class QBarSet; | |||
|
47 | class QAbstractBarSeries; | |||
|
48 | class QPieSlice; | |||
|
49 | class QLegend; | |||
|
50 | class QPieSeries; | |||
|
51 | ||||
|
52 | class QLegendMarker; | |||
|
53 | ||||
|
54 | class QLegendMarkerPrivate : public QGraphicsObject, public QGraphicsLayoutItem | |||
|
55 | { | |||
|
56 | Q_OBJECT | |||
|
57 | Q_INTERFACES(QGraphicsLayoutItem) | |||
|
58 | public: | |||
|
59 | explicit QLegendMarkerPrivate(QAbstractSeries *series, QLegendMarker *q); | |||
|
60 | /* | |||
|
61 | void setPen(const QPen &pen); | |||
|
62 | QPen pen() const; | |||
|
63 | ||||
|
64 | void setBrush(const QBrush &brush); | |||
|
65 | QBrush brush() const; | |||
|
66 | ||||
|
67 | void setFont(const QFont &font); | |||
|
68 | QFont font() const; | |||
|
69 | ||||
|
70 | void setLabel(const QString label); | |||
|
71 | QString label() const; | |||
|
72 | ||||
|
73 | void setLabelBrush(const QBrush &brush); | |||
|
74 | QBrush labelBrush() const; | |||
|
75 | */ | |||
|
76 | void setGeometry(const QRectF& rect); | |||
|
77 | ||||
|
78 | QRectF boundingRect() const; | |||
|
79 | ||||
|
80 | void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0); | |||
|
81 | ||||
|
82 | QSizeF sizeHint (Qt::SizeHint which, const QSizeF& constraint) const; | |||
|
83 | ||||
|
84 | protected: | |||
|
85 | // From QGraphicsObject | |||
|
86 | void mousePressEvent(QGraphicsSceneMouseEvent *event); | |||
|
87 | ||||
|
88 | public Q_SLOTS: | |||
|
89 | virtual void updated() {}; | |||
|
90 | ||||
|
91 | private: | |||
|
92 | QLegendMarker *q_ptr; | |||
|
93 | ||||
|
94 | /* | |||
|
95 | QLegend* m_legend; | |||
|
96 | */ | |||
|
97 | ||||
|
98 | // New legend marker properties | |||
|
99 | QAbstractSeries* m_series; | |||
|
100 | QString m_label; | |||
|
101 | QBrush m_labelBrush; | |||
|
102 | QFont m_font; | |||
|
103 | QPen m_pen; | |||
|
104 | QBrush m_brush; | |||
|
105 | bool m_visible; | |||
|
106 | ||||
|
107 | // Implementation details of new marker | |||
|
108 | QRectF m_markerRect; | |||
|
109 | QRectF m_boundingRect; | |||
|
110 | QGraphicsSimpleTextItem *m_textItem; | |||
|
111 | QGraphicsRectItem *m_rectItem; | |||
|
112 | qreal m_margin; | |||
|
113 | qreal m_space; | |||
|
114 | ||||
|
115 | friend class QLegendPrivate; // TODO: Is this needed? | |||
|
116 | Q_DECLARE_PUBLIC(QLegendMarker) | |||
|
117 | }; | |||
|
118 | ||||
|
119 | QTCOMMERCIALCHART_END_NAMESPACE | |||
|
120 | ||||
|
121 | #endif // QLEGENDMARKERPRIVATE_H |
@@ -28,6 +28,7 | |||||
28 | #include <QFormLayout> |
|
28 | #include <QFormLayout> | |
29 | #include <QPieSeries> |
|
29 | #include <QPieSeries> | |
30 | #include <QPieSlice> |
|
30 | #include <QPieSlice> | |
|
31 | #include <QLegendMarker> | |||
31 |
|
32 | |||
32 | QTCOMMERCIALCHART_USE_NAMESPACE |
|
33 | QTCOMMERCIALCHART_USE_NAMESPACE | |
33 |
|
34 | |||
@@ -53,11 +54,15 MainWidget::MainWidget(QWidget *parent) : | |||||
53 |
|
54 | |||
54 | QPushButton *boldButton = new QPushButton("Toggle bold"); |
|
55 | QPushButton *boldButton = new QPushButton("Toggle bold"); | |
55 | connect(boldButton, SIGNAL(clicked()), this, SLOT(toggleBold())); |
|
56 | connect(boldButton, SIGNAL(clicked()), this, SLOT(toggleBold())); | |
56 |
m_buttonLayout->addWidget(boldButton, |
|
57 | m_buttonLayout->addWidget(boldButton, 5, 0); | |
57 |
|
58 | |||
58 | QPushButton *italicButton = new QPushButton("Toggle italic"); |
|
59 | QPushButton *italicButton = new QPushButton("Toggle italic"); | |
59 | connect(italicButton, SIGNAL(clicked()), this, SLOT(toggleItalic())); |
|
60 | connect(italicButton, SIGNAL(clicked()), this, SLOT(toggleItalic())); | |
60 |
m_buttonLayout->addWidget(italicButton, |
|
61 | m_buttonLayout->addWidget(italicButton, 6, 0); | |
|
62 | ||||
|
63 | QPushButton *infoButton = new QPushButton("Debug info"); | |||
|
64 | connect(infoButton, SIGNAL(clicked()), this, SLOT(showDebugInfo())); | |||
|
65 | m_buttonLayout->addWidget(infoButton, 7, 0); | |||
61 |
|
66 | |||
62 | m_legendPosX = new QDoubleSpinBox(); |
|
67 | m_legendPosX = new QDoubleSpinBox(); | |
63 | m_legendPosY = new QDoubleSpinBox(); |
|
68 | m_legendPosY = new QDoubleSpinBox(); | |
@@ -227,6 +232,14 void MainWidget::toggleItalic() | |||||
227 | m_chart->legend()->setFont(font); |
|
232 | m_chart->legend()->setFont(font); | |
228 | } |
|
233 | } | |
229 |
|
234 | |||
|
235 | void MainWidget::showDebugInfo() | |||
|
236 | { | |||
|
237 | qDebug() << "marker count:" << m_chart->legend()->markers().count(); | |||
|
238 | foreach (QLegendMarker* marker, m_chart->legend()->markers()) { | |||
|
239 | qDebug() << "label:" << marker->label(); | |||
|
240 | } | |||
|
241 | } | |||
|
242 | ||||
230 | void MainWidget::fontSizeChanged() |
|
243 | void MainWidget::fontSizeChanged() | |
231 | { |
|
244 | { | |
232 | QFont font = m_chart->legend()->font(); |
|
245 | QFont font = m_chart->legend()->font(); |
@@ -55,6 +55,7 public slots: | |||||
55 |
|
55 | |||
56 | void toggleBold(); |
|
56 | void toggleBold(); | |
57 | void toggleItalic(); |
|
57 | void toggleItalic(); | |
|
58 | void showDebugInfo(); | |||
58 | void fontSizeChanged(); |
|
59 | void fontSizeChanged(); | |
59 |
|
60 | |||
60 | void updateLegendLayout(); |
|
61 | void updateLegendLayout(); |
@@ -382,6 +382,15 QList<LegendMarker *> QAreaSeriesPrivate::createLegendMarker(QLegend *legend) | |||||
382 | return list << new AreaLegendMarker(q, legend); |
|
382 | return list << new AreaLegendMarker(q, legend); | |
383 | } |
|
383 | } | |
384 |
|
384 | |||
|
385 | QList<QLegendMarker*> QAreaSeriesPrivate::createLegendMarkers(QLegend* legend) | |||
|
386 | { | |||
|
387 | Q_UNUSED(legend); | |||
|
388 | // Q_Q(QAreaSeries); | |||
|
389 | QList<QLegendMarker*> list; | |||
|
390 | // TODO: | |||
|
391 | // return list << new AreaLegendMarker(q,legend); | |||
|
392 | return list; | |||
|
393 | } | |||
385 |
|
394 | |||
386 | void QAreaSeriesPrivate::initializeAxis(QAbstractAxis *axis) |
|
395 | void QAreaSeriesPrivate::initializeAxis(QAbstractAxis *axis) | |
387 | { |
|
396 | { |
@@ -46,7 +46,9 public: | |||||
46 | void scaleDomain(Domain &domain); |
|
46 | void scaleDomain(Domain &domain); | |
47 | ChartElement *createGraphics(ChartPresenter *presenter); |
|
47 | ChartElement *createGraphics(ChartPresenter *presenter); | |
48 | QList<LegendMarker *> createLegendMarker(QLegend *legend); |
|
48 | QList<LegendMarker *> createLegendMarker(QLegend *legend); | |
|
49 | QList<QLegendMarker*> createLegendMarkers(QLegend* legend); | |||
49 | void initializeAxis(QAbstractAxis *axis); |
|
50 | void initializeAxis(QAbstractAxis *axis); | |
|
51 | ||||
50 | QAbstractAxis::AxisType defaultAxisType(Qt::Orientation orientation) const; |
|
52 | QAbstractAxis::AxisType defaultAxisType(Qt::Orientation orientation) const; | |
51 |
|
53 | |||
52 | Q_SIGNALS: |
|
54 | Q_SIGNALS: |
@@ -659,6 +659,22 QList<LegendMarker *> QAbstractBarSeriesPrivate::createLegendMarker(QLegend *leg | |||||
659 | return markers; |
|
659 | return markers; | |
660 | } |
|
660 | } | |
661 |
|
661 | |||
|
662 | QList<QLegendMarker*> QAbstractBarSeriesPrivate::createLegendMarkers(QLegend* legend) | |||
|
663 | { | |||
|
664 | Q_UNUSED(legend); | |||
|
665 | // Q_Q(QAbstractBarSeries); | |||
|
666 | QList<QLegendMarker*> markers; | |||
|
667 | // TODO: when QBarLegendMarker is implemented | |||
|
668 | /* | |||
|
669 | foreach(QBarSet* set, q->barSets()) { | |||
|
670 | BarLegendMarker* marker = new BarLegendMarker(q,set,legend); | |||
|
671 | markers << marker; | |||
|
672 | } | |||
|
673 | */ | |||
|
674 | return markers; | |||
|
675 | } | |||
|
676 | ||||
|
677 | ||||
662 | bool QAbstractBarSeriesPrivate::append(QBarSet *set) |
|
678 | bool QAbstractBarSeriesPrivate::append(QBarSet *set) | |
663 | { |
|
679 | { | |
664 | if ((m_barSets.contains(set)) || (set == 0)) |
|
680 | if ((m_barSets.contains(set)) || (set == 0)) |
@@ -39,6 +39,7 QTCOMMERCIALCHART_BEGIN_NAMESPACE | |||||
39 |
|
39 | |||
40 | class QBarModelMapper; |
|
40 | class QBarModelMapper; | |
41 | class QBarCategoryAxis; |
|
41 | class QBarCategoryAxis; | |
|
42 | class QLegendMarker; | |||
42 |
|
43 | |||
43 | class QAbstractBarSeriesPrivate : public QAbstractSeriesPrivate |
|
44 | class QAbstractBarSeriesPrivate : public QAbstractSeriesPrivate | |
44 | { |
|
45 | { | |
@@ -56,6 +57,7 public: | |||||
56 | void scaleDomain(Domain &domain); |
|
57 | void scaleDomain(Domain &domain); | |
57 | ChartElement *createGraphics(ChartPresenter *presenter); |
|
58 | ChartElement *createGraphics(ChartPresenter *presenter); | |
58 | QList<LegendMarker *> createLegendMarker(QLegend *legend); |
|
59 | QList<LegendMarker *> createLegendMarker(QLegend *legend); | |
|
60 | QList<QLegendMarker*> createLegendMarkers(QLegend* legend); | |||
59 |
|
61 | |||
60 | void initializeAxis(QAbstractAxis *axis); |
|
62 | void initializeAxis(QAbstractAxis *axis); | |
61 | virtual QAbstractAxis::AxisType defaultAxisType(Qt::Orientation orientation) const; |
|
63 | virtual QAbstractAxis::AxisType defaultAxisType(Qt::Orientation orientation) const; |
@@ -12,7 +12,8 PRIVATE_HEADERS += \ | |||||
12 | $$PWD/legendmarker_p.h \ |
|
12 | $$PWD/legendmarker_p.h \ | |
13 | $$PWD/legendscroller_p.h \ |
|
13 | $$PWD/legendscroller_p.h \ | |
14 | $$PWD/qlegend_p.h \ |
|
14 | $$PWD/qlegend_p.h \ | |
15 | $$PWD/legendlayout_p.h |
|
15 | $$PWD/legendlayout_p.h \ | |
|
16 | $$PWD/qlegendmarker_p.h | |||
16 |
|
17 | |||
17 |
|
18 | |||
18 | PUBLIC_HEADERS += \ |
|
19 | PUBLIC_HEADERS += \ |
@@ -44,6 +44,8 | |||||
44 | #include <QTimer> |
|
44 | #include <QTimer> | |
45 | #include <QGraphicsSceneEvent> |
|
45 | #include <QGraphicsSceneEvent> | |
46 |
|
46 | |||
|
47 | #include <QLegendMarker> | |||
|
48 | ||||
47 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
49 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
48 |
|
50 | |||
49 | /*! |
|
51 | /*! | |
@@ -465,7 +467,21 void QLegendPrivate::handleSeriesAdded(QAbstractSeries *series, Domain *domain) | |||||
465 | { |
|
467 | { | |
466 | Q_UNUSED(domain) |
|
468 | Q_UNUSED(domain) | |
467 |
|
469 | |||
468 | QList<LegendMarker *> markers = series->d_ptr->createLegendMarker(q_ptr); |
|
470 | // New markers ---> | |
|
471 | QList<QLegendMarker*> newMarkers = series->d_ptr->createLegendMarkers(q_ptr); | |||
|
472 | foreach (QLegendMarker* marker, newMarkers) { | |||
|
473 | marker->setFont(m_font); | |||
|
474 | marker->setLabelBrush(m_labelBrush); | |||
|
475 | marker->setVisible(series->isVisible()); | |||
|
476 | // TODO: QLegendMarker has QGraphicsItem vs QLegendMarker is QGraphicsItem | |||
|
477 | // m_items->addToGroup(marker); | |||
|
478 | m_legendMarkers << marker; | |||
|
479 | } | |||
|
480 | ||||
|
481 | QObject::connect(series, SIGNAL(visibleChanged()), this, SLOT(handleSeriesVisibleChanged())); | |||
|
482 | // <--- New markers | |||
|
483 | ||||
|
484 | QList<LegendMarker*> markers = series->d_ptr->createLegendMarker(q_ptr); | |||
469 |
|
485 | |||
470 | foreach (LegendMarker *marker, markers) { |
|
486 | foreach (LegendMarker *marker, markers) { | |
471 | marker->setFont(m_font); |
|
487 | marker->setFont(m_font); | |
@@ -484,6 +500,17 void QLegendPrivate::handleSeriesAdded(QAbstractSeries *series, Domain *domain) | |||||
484 |
|
500 | |||
485 | void QLegendPrivate::handleSeriesRemoved(QAbstractSeries *series) |
|
501 | void QLegendPrivate::handleSeriesRemoved(QAbstractSeries *series) | |
486 | { |
|
502 | { | |
|
503 | // New markers ---> | |||
|
504 | foreach (QLegendMarker *marker, m_legendMarkers) { | |||
|
505 | if (marker->series() == series) { | |||
|
506 | delete marker; | |||
|
507 | m_legendMarkers.removeAll(marker); | |||
|
508 | } | |||
|
509 | } | |||
|
510 | ||||
|
511 | QObject::disconnect(series, SIGNAL(visibleChanged()), this, SLOT(handleSeriesVisibleChanged())); | |||
|
512 | // <--- New markers | |||
|
513 | ||||
487 | foreach (LegendMarker *marker, m_markers) { |
|
514 | foreach (LegendMarker *marker, m_markers) { | |
488 | if (marker->series() == series) { |
|
515 | if (marker->series() == series) { | |
489 | delete marker; |
|
516 | delete marker; | |
@@ -501,8 +528,17 void QLegendPrivate::handleSeriesVisibleChanged() | |||||
501 | QAbstractSeries *series = qobject_cast<QAbstractSeries *> (sender()); |
|
528 | QAbstractSeries *series = qobject_cast<QAbstractSeries *> (sender()); | |
502 | Q_ASSERT(series); |
|
529 | Q_ASSERT(series); | |
503 |
|
530 | |||
504 | foreach (LegendMarker *marker, m_markers) { |
|
531 | // New markers ---> | |
505 | if (marker->series() == series) |
|
532 | foreach (QLegendMarker* marker, m_legendMarkers) { | |
|
533 | if (marker->series() == series) { | |||
|
534 | marker->setVisible(series->isVisible()); | |||
|
535 | } | |||
|
536 | } | |||
|
537 | ||||
|
538 | // <--- New markers | |||
|
539 | ||||
|
540 | foreach (LegendMarker* marker, m_markers) { | |||
|
541 | if (marker->series() == series) { | |||
506 | marker->setVisible(series->isVisible()); |
|
542 | marker->setVisible(series->isVisible()); | |
507 | } |
|
543 | } | |
508 | m_layout->invalidate(); |
|
544 | m_layout->invalidate(); | |
@@ -510,10 +546,13 void QLegendPrivate::handleSeriesVisibleChanged() | |||||
510 |
|
546 | |||
511 | void QLegendPrivate::handleCountChanged() |
|
547 | void QLegendPrivate::handleCountChanged() | |
512 | { |
|
548 | { | |
513 | QAbstractSeriesPrivate *series = qobject_cast<QAbstractSeriesPrivate *> (sender()); |
|
549 | // With new markers, the series shoud notify markers directly? | |
514 | Q_ASSERT(series); |
|
550 | ||
515 | handleSeriesRemoved(series->q_ptr); |
|
551 | // Handle new or removed markers | |
516 | handleSeriesAdded(series->q_ptr, 0); |
|
552 | // Handle changes of marker pen/brush/label. every property that legend is interested | |
|
553 | handleSeriesRemoved(series); | |||
|
554 | Domain domain; | |||
|
555 | handleSeriesAdded(series, &domain); | |||
517 | } |
|
556 | } | |
518 |
|
557 | |||
519 | #include "moc_qlegend.cpp" |
|
558 | #include "moc_qlegend.cpp" |
@@ -19,15 +19,15 | |||||
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 | #include "qlegendmarker.h" |
|
21 | #include "qlegendmarker.h" | |
22 |
|
|
22 | #include "qlegendmarker_p.h" | |
23 | #include <QDebug> |
|
23 | #include <QDebug> | |
|
24 | #include <QFontMetrics> | |||
24 |
|
25 | |||
25 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
26 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
26 |
|
27 | |||
27 | QLegendMarker::QLegendMarker(QAbstractSeries* series, QObject *parent) : |
|
28 | QLegendMarker::QLegendMarker(QAbstractSeries* series, QObject *parent) : | |
28 | QObject(parent), |
|
29 | QObject(parent), | |
29 | m_series(series) |
|
30 | d_ptr(new QLegendMarkerPrivate(series, this)) | |
30 | // d_ptr(new QLegendMarkerPrivate(this)) |
|
|||
31 | { |
|
31 | { | |
32 | } |
|
32 | } | |
33 |
|
33 | |||
@@ -37,50 +37,149 QLegendMarker::~QLegendMarker() | |||||
37 |
|
37 | |||
38 | QString QLegendMarker::label() const |
|
38 | QString QLegendMarker::label() const | |
39 | { |
|
39 | { | |
40 | return m_label; |
|
40 | return d_ptr->m_label; | |
41 | } |
|
41 | } | |
42 |
|
42 | |||
43 | void QLegendMarker::setLabel(const QString &label) |
|
43 | void QLegendMarker::setLabel(const QString &label) | |
44 | { |
|
44 | { | |
45 | m_label = label; |
|
45 | d_ptr->m_label = label; | |
|
46 | } | |||
|
47 | ||||
|
48 | QBrush QLegendMarker::labelBrush() const | |||
|
49 | { | |||
|
50 | return d_ptr->m_labelBrush; | |||
|
51 | } | |||
|
52 | ||||
|
53 | void QLegendMarker::setLabelBrush(const QBrush &brush) | |||
|
54 | { | |||
|
55 | d_ptr->m_labelBrush = brush; | |||
|
56 | } | |||
|
57 | ||||
|
58 | QFont QLegendMarker::font() const | |||
|
59 | { | |||
|
60 | return d_ptr->m_font; | |||
|
61 | } | |||
|
62 | ||||
|
63 | void QLegendMarker::setFont(const QFont &font) | |||
|
64 | { | |||
|
65 | d_ptr->m_font = font; | |||
46 | } |
|
66 | } | |
47 |
|
67 | |||
48 | QPen QLegendMarker::pen() const |
|
68 | QPen QLegendMarker::pen() const | |
49 | { |
|
69 | { | |
50 | return m_pen; |
|
70 | return d_ptr->m_pen; | |
51 | } |
|
71 | } | |
52 |
|
72 | |||
53 | void QLegendMarker::setPen(const QPen &pen) |
|
73 | void QLegendMarker::setPen(const QPen &pen) | |
54 | { |
|
74 | { | |
55 | m_pen = pen; |
|
75 | d_ptr->m_pen = pen; | |
56 | } |
|
76 | } | |
57 |
|
77 | |||
58 | QBrush QLegendMarker::brush() const |
|
78 | QBrush QLegendMarker::brush() const | |
59 | { |
|
79 | { | |
60 | return m_brush; |
|
80 | return d_ptr->m_brush; | |
61 | } |
|
81 | } | |
62 |
|
82 | |||
63 | void QLegendMarker::setBrush(const QBrush &brush) |
|
83 | void QLegendMarker::setBrush(const QBrush &brush) | |
64 | { |
|
84 | { | |
65 | m_brush = brush; |
|
85 | d_ptr->m_brush = brush; | |
66 | } |
|
86 | } | |
67 |
|
87 | |||
68 | bool QLegendMarker::isVisible() const |
|
88 | bool QLegendMarker::isVisible() const | |
69 | { |
|
89 | { | |
70 | return m_visible; |
|
90 | return d_ptr->m_visible; | |
71 | } |
|
91 | } | |
72 |
|
92 | |||
73 | void QLegendMarker::setVisible(bool visible) |
|
93 | void QLegendMarker::setVisible(bool visible) | |
74 | { |
|
94 | { | |
75 | m_visible = visible; |
|
95 | d_ptr->m_visible = visible; | |
76 | } |
|
96 | } | |
77 |
|
97 | |||
78 | void QLegendMarker::markersUpdated() |
|
98 | QAbstractSeries* QLegendMarker::series() | |
79 | { |
|
99 | { | |
80 | // TODO: |
|
100 | return d_ptr->m_series; | |
81 | } |
|
101 | } | |
82 |
|
102 | |||
|
103 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||
|
104 | ||||
|
105 | QLegendMarkerPrivate::QLegendMarkerPrivate(QAbstractSeries *series, QLegendMarker *q) : | |||
|
106 | q_ptr(q), | |||
|
107 | m_series(series) | |||
|
108 | { | |||
|
109 | ||||
|
110 | } | |||
|
111 | ||||
|
112 | void QLegendMarkerPrivate::setGeometry(const QRectF& rect) | |||
|
113 | { | |||
|
114 | QFontMetrics fn (m_font); | |||
|
115 | ||||
|
116 | ||||
|
117 | int width = rect.width(); | |||
|
118 | qreal x = m_margin + m_markerRect.width() + m_space + m_margin; | |||
|
119 | qreal y = qMax(m_markerRect.height()+2*m_margin,fn.height()+2*m_margin); | |||
|
120 | ||||
|
121 | if (fn.boundingRect(m_label).width() + x > width) | |||
|
122 | { | |||
|
123 | QString string = m_label + "..."; | |||
|
124 | while(fn.boundingRect(string).width() + x > width && string.length() > 3) | |||
|
125 | string.remove(string.length() - 4, 1); | |||
|
126 | m_textItem->setText(string); | |||
|
127 | } | |||
|
128 | else | |||
|
129 | m_textItem->setText(m_label); | |||
|
130 | ||||
|
131 | const QRectF& textRect = m_textItem->boundingRect(); | |||
|
132 | ||||
|
133 | ||||
|
134 | m_textItem->setPos(x-m_margin,y/2 - textRect.height()/2); | |||
|
135 | m_rectItem->setRect(m_markerRect); | |||
|
136 | m_rectItem->setPos(m_margin,y/2 - m_markerRect.height()/2); | |||
|
137 | ||||
|
138 | prepareGeometryChange(); | |||
|
139 | m_boundingRect = QRectF(0,0,x+textRect.width()+m_margin,y); | |||
|
140 | } | |||
|
141 | ||||
|
142 | QRectF QLegendMarkerPrivate::boundingRect() const | |||
|
143 | { | |||
|
144 | return m_boundingRect; | |||
|
145 | } | |||
|
146 | ||||
|
147 | void QLegendMarkerPrivate::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) | |||
|
148 | { | |||
|
149 | Q_UNUSED(option) | |||
|
150 | Q_UNUSED(widget) | |||
|
151 | Q_UNUSED(painter) | |||
|
152 | } | |||
|
153 | ||||
|
154 | QSizeF QLegendMarkerPrivate::sizeHint(Qt::SizeHint which, const QSizeF& constraint) const | |||
|
155 | { | |||
|
156 | Q_UNUSED(constraint) | |||
|
157 | ||||
|
158 | QFontMetrics fn(m_textItem->font()); | |||
|
159 | QSizeF sh; | |||
|
160 | ||||
|
161 | switch (which) { | |||
|
162 | case Qt::MinimumSize: | |||
|
163 | sh = QSizeF(fn.boundingRect("...").width() + 2*m_margin + m_space +m_markerRect.width(),qMax(m_markerRect.height()+2*m_margin,fn.height()+2*m_margin)); | |||
|
164 | break; | |||
|
165 | case Qt::PreferredSize: | |||
|
166 | sh = QSizeF(fn.boundingRect(m_label).width() + 2*m_margin + m_space +m_markerRect.width(),qMax(m_markerRect.height()+2*m_margin,fn.height()+2*m_margin)); | |||
|
167 | break; | |||
|
168 | default: | |||
|
169 | break; | |||
|
170 | } | |||
|
171 | ||||
|
172 | return sh; | |||
|
173 | } | |||
|
174 | ||||
|
175 | void QLegendMarkerPrivate::mousePressEvent(QGraphicsSceneMouseEvent *event) | |||
|
176 | { | |||
|
177 | QGraphicsObject::mousePressEvent(event); | |||
|
178 | //TODO: selected signal removed for now | |||
|
179 | } | |||
|
180 | ||||
|
181 | ||||
83 | #include "moc_qlegendmarker.cpp" |
|
182 | #include "moc_qlegendmarker.cpp" | |
84 |
|
|
183 | #include "moc_qlegendmarker_p.cpp" | |
85 |
|
184 | |||
86 | QTCOMMERCIALCHART_END_NAMESPACE |
|
185 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -25,14 +25,14 | |||||
25 | #include <QObject> |
|
25 | #include <QObject> | |
26 | #include <QPen> |
|
26 | #include <QPen> | |
27 | #include <QBrush> |
|
27 | #include <QBrush> | |
|
28 | #include <QFont> | |||
28 |
|
29 | |||
29 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
30 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
30 |
|
31 | |||
31 | // TODO: |
|
32 | class QLegendMarkerPrivate; | |
32 | //class QLegendMarkerPrivate; |
|
|||
33 | class QAbstractSeries; |
|
33 | class QAbstractSeries; | |
34 |
|
34 | |||
35 |
// TODO: should this be |
|
35 | // TODO: should this be QAbstractLegendMarker? | |
36 | class QTCOMMERCIALCHART_EXPORT QLegendMarker : public QObject |
|
36 | class QTCOMMERCIALCHART_EXPORT QLegendMarker : public QObject | |
37 | { |
|
37 | { | |
38 | Q_OBJECT |
|
38 | Q_OBJECT | |
@@ -49,6 +49,12 public: | |||||
49 | QString label() const; |
|
49 | QString label() const; | |
50 | void setLabel(const QString &label); |
|
50 | void setLabel(const QString &label); | |
51 |
|
51 | |||
|
52 | QBrush labelBrush() const; | |||
|
53 | void setLabelBrush(const QBrush &brush); | |||
|
54 | ||||
|
55 | QFont font() const; | |||
|
56 | void setFont(const QFont &font); | |||
|
57 | ||||
52 | QPen pen() const; |
|
58 | QPen pen() const; | |
53 | void setPen(const QPen &pen); |
|
59 | void setPen(const QPen &pen); | |
54 |
|
60 | |||
@@ -59,7 +65,7 public: | |||||
59 | void setVisible(bool visible); |
|
65 | void setVisible(bool visible); | |
60 |
|
66 | |||
61 | // virtual QAbstractSeries::SeriesType type() = 0; |
|
67 | // virtual QAbstractSeries::SeriesType type() = 0; | |
62 |
virtual QAbstractSeries* series() |
|
68 | virtual QAbstractSeries* series(); | |
63 | virtual QObject* peerObject() = 0; |
|
69 | virtual QObject* peerObject() = 0; | |
64 |
|
70 | |||
65 | Q_SIGNALS: |
|
71 | Q_SIGNALS: | |
@@ -67,19 +73,12 Q_SIGNALS: | |||||
67 | void hovered(bool status); |
|
73 | void hovered(bool status); | |
68 |
|
74 | |||
69 | public Q_SLOTS: |
|
75 | public Q_SLOTS: | |
70 |
void |
|
76 | virtual void updated() = 0; // TODO: private. Idea is that series signals, when some property has changed | |
71 |
|
77 | |||
72 | public: |
|
78 | public: | |
73 | // TODO: |
|
79 | QScopedPointer<QLegendMarkerPrivate> d_ptr; | |
74 | // QScopedPointer<QLegendMarkerPrivate> d_ptr; |
|
|||
75 | Q_DISABLE_COPY(QLegendMarker) |
|
80 | Q_DISABLE_COPY(QLegendMarker) | |
76 |
|
81 | |||
77 | // TODO: move to PIMPL |
|
|||
78 | QAbstractSeries* m_series; |
|
|||
79 | QString m_label; |
|
|||
80 | QPen m_pen; |
|
|||
81 | QBrush m_brush; |
|
|||
82 | bool m_visible; |
|
|||
83 | }; |
|
82 | }; | |
84 |
|
83 | |||
85 | QTCOMMERCIALCHART_END_NAMESPACE |
|
84 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -27,8 +27,17 QPieLegendMarker::QPieLegendMarker(QPieSeries* series, QPieSlice* slice, QObject | |||||
27 | QLegendMarker(series, parent), |
|
27 | QLegendMarker(series, parent), | |
28 | m_slice(slice) |
|
28 | m_slice(slice) | |
29 | { |
|
29 | { | |
|
30 | QObject::connect(slice, SIGNAL(labelChanged()), this, SLOT(updated())); | |||
|
31 | QObject::connect(slice, SIGNAL(brushChanged()), this, SLOT(updated())); | |||
|
32 | updated(); | |||
30 | } |
|
33 | } | |
31 |
|
34 | |||
|
35 | void QPieLegendMarker::updated() | |||
|
36 | { | |||
|
37 | // TODO: to PIMPL. | |||
|
38 | setBrush(m_slice->brush()); | |||
|
39 | setLabel(m_slice->label()); | |||
|
40 | } | |||
32 |
|
41 | |||
33 | #include "moc_qpielegendmarker.cpp" |
|
42 | #include "moc_qpielegendmarker.cpp" | |
34 | //#include "moc_qpielegendmarker_p.cpp" |
|
43 | //#include "moc_qpielegendmarker_p.cpp" |
@@ -36,6 +36,9 public: | |||||
36 |
|
36 | |||
37 | virtual QPieSlice* peerObject() { return m_slice; } |
|
37 | virtual QPieSlice* peerObject() { return m_slice; } | |
38 |
|
38 | |||
|
39 | // TODO: to pimp. | |||
|
40 | void updated(); | |||
|
41 | ||||
39 | //Q_SIGNALS: |
|
42 | //Q_SIGNALS: | |
40 |
|
43 | |||
41 | //public Q_SLOTS: |
|
44 | //public Q_SLOTS: |
@@ -29,6 +29,8 | |||||
29 | #include "qabstractaxis.h" |
|
29 | #include "qabstractaxis.h" | |
30 | #include "pieanimation_p.h" |
|
30 | #include "pieanimation_p.h" | |
31 |
|
31 | |||
|
32 | #include "qpielegendmarker.h" | |||
|
33 | ||||
32 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
34 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
33 |
|
35 | |||
34 | /*! |
|
36 | /*! | |
@@ -861,6 +863,17 QList<LegendMarker *> QPieSeriesPrivate::createLegendMarker(QLegend *legend) | |||||
861 | return markers; |
|
863 | return markers; | |
862 | } |
|
864 | } | |
863 |
|
865 | |||
|
866 | QList<QLegendMarker*> QPieSeriesPrivate::createLegendMarkers(QLegend* legend) | |||
|
867 | { | |||
|
868 | Q_Q(QPieSeries); | |||
|
869 | QList<QLegendMarker*> markers; | |||
|
870 | foreach(QPieSlice* slice, q->slices()) { | |||
|
871 | QPieLegendMarker* marker = new QPieLegendMarker(q,slice,legend); | |||
|
872 | markers << marker; | |||
|
873 | } | |||
|
874 | return markers; | |||
|
875 | } | |||
|
876 | ||||
864 | void QPieSeriesPrivate::initializeAxis(QAbstractAxis *axis) |
|
877 | void QPieSeriesPrivate::initializeAxis(QAbstractAxis *axis) | |
865 | { |
|
878 | { | |
866 | Q_UNUSED(axis); |
|
879 | Q_UNUSED(axis); |
@@ -47,6 +47,7 public: | |||||
47 | void scaleDomain(Domain &domain); |
|
47 | void scaleDomain(Domain &domain); | |
48 | ChartElement *createGraphics(ChartPresenter *presenter); |
|
48 | ChartElement *createGraphics(ChartPresenter *presenter); | |
49 | QList<LegendMarker *> createLegendMarker(QLegend *legend); |
|
49 | QList<LegendMarker *> createLegendMarker(QLegend *legend); | |
|
50 | QList<QLegendMarker *> createLegendMarkers(QLegend *legend); | |||
50 | void initializeAxis(QAbstractAxis *axis); |
|
51 | void initializeAxis(QAbstractAxis *axis); | |
51 | QAbstractAxis::AxisType defaultAxisType(Qt::Orientation orientation) const; |
|
52 | QAbstractAxis::AxisType defaultAxisType(Qt::Orientation orientation) const; | |
52 |
|
53 |
@@ -41,6 +41,7 class LegendMarker; | |||||
41 | class QLegend; |
|
41 | class QLegend; | |
42 | class ChartDataSet; |
|
42 | class ChartDataSet; | |
43 | class QAbstractAxis; |
|
43 | class QAbstractAxis; | |
|
44 | class QLegendMarker; | |||
44 |
|
45 | |||
45 | class QAbstractSeriesPrivate : public QObject |
|
46 | class QAbstractSeriesPrivate : public QObject | |
46 | { |
|
47 | { | |
@@ -52,6 +53,7 public: | |||||
52 | virtual void scaleDomain(Domain &domain) = 0; |
|
53 | virtual void scaleDomain(Domain &domain) = 0; | |
53 | virtual ChartElement *createGraphics(ChartPresenter *presenter) = 0; |
|
54 | virtual ChartElement *createGraphics(ChartPresenter *presenter) = 0; | |
54 | virtual QList<LegendMarker *> createLegendMarker(QLegend *legend) = 0; |
|
55 | virtual QList<LegendMarker *> createLegendMarker(QLegend *legend) = 0; | |
|
56 | virtual QList<QLegendMarker*> createLegendMarkers(QLegend* legend) = 0; | |||
55 | virtual void initializeAxis(QAbstractAxis *axis) = 0; |
|
57 | virtual void initializeAxis(QAbstractAxis *axis) = 0; | |
56 | virtual QAbstractAxis::AxisType defaultAxisType(Qt::Orientation) const = 0; |
|
58 | virtual QAbstractAxis::AxisType defaultAxisType(Qt::Orientation) const = 0; | |
57 |
|
59 |
@@ -454,6 +454,16 QList<LegendMarker *> QXYSeriesPrivate::createLegendMarker(QLegend *legend) | |||||
454 | return list << new XYLegendMarker(q, legend); |
|
454 | return list << new XYLegendMarker(q, legend); | |
455 | } |
|
455 | } | |
456 |
|
456 | |||
|
457 | QList<QLegendMarker*> QXYSeriesPrivate::createLegendMarkers(QLegend* legend) | |||
|
458 | { | |||
|
459 | Q_UNUSED(legend); | |||
|
460 | // Q_Q(QXYSeries); | |||
|
461 | QList<QLegendMarker*> list; | |||
|
462 | // TODO: | |||
|
463 | // return list << new QXYLegendMarker(q,legend); | |||
|
464 | return list; | |||
|
465 | } | |||
|
466 | ||||
457 | void QXYSeriesPrivate::initializeAxis(QAbstractAxis *axis) |
|
467 | void QXYSeriesPrivate::initializeAxis(QAbstractAxis *axis) | |
458 | { |
|
468 | { | |
459 | Q_UNUSED(axis); |
|
469 | Q_UNUSED(axis); |
@@ -46,6 +46,7 public: | |||||
46 |
|
46 | |||
47 | void scaleDomain(Domain &domain); |
|
47 | void scaleDomain(Domain &domain); | |
48 | QList<LegendMarker *> createLegendMarker(QLegend *legend); |
|
48 | QList<LegendMarker *> createLegendMarker(QLegend *legend); | |
|
49 | QList<QLegendMarker*> createLegendMarkers(QLegend* legend); | |||
49 |
|
50 | |||
50 | void initializeAxis(QAbstractAxis *axis); |
|
51 | void initializeAxis(QAbstractAxis *axis); | |
51 | QAbstractAxis::AxisType defaultAxisType(Qt::Orientation orientation) const; |
|
52 | QAbstractAxis::AxisType defaultAxisType(Qt::Orientation orientation) const; |
General Comments 0
You need to be logged in to leave comments.
Login now