@@ -81,7 +81,7 private Q_SLOTS: | |||||
81 | void barsetChanged(); |
|
81 | void barsetChanged(); | |
82 |
|
82 | |||
83 | protected: |
|
83 | protected: | |
84 | BarChartModel *m_internalModel; |
|
84 | BarChartModel *m_internalModel; // TODO: this may change... current "2 models" situation doesn't look good. | |
85 |
|
85 | |||
86 | QAbstractItemModel* m_model; |
|
86 | QAbstractItemModel* m_model; | |
87 | int m_mapCategories; |
|
87 | int m_mapCategories; |
@@ -9,50 +9,47 | |||||
9 |
|
9 | |||
10 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
10 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
11 |
|
11 | |||
12 |
LegendMarker::LegendMarker(QSeries* |
|
12 | LegendMarker::LegendMarker(QSeries *series, QGraphicsItem *parent) : QGraphicsObject(parent), | |
13 | : QGraphicsObject(parent) |
|
13 | mPos(0,0), | |
14 |
|
|
14 | mSize(0,0), | |
15 | ,mSize(0,0) |
|
15 | mBoundingRect(0,0,0,0), | |
16 |
|
|
16 | mMarkerBoundingRect(0,0,0,0), | |
17 | ,mMarkerBoundingRect(0,0,0,0) |
|
17 | mSeries(series), | |
18 | ,mSeries(series) |
|
18 | mBarset(0), | |
19 |
|
|
19 | mPieslice(0), | |
20 | ,mPieslice(0) |
|
20 | mType(LegendMarkerTypeSeries), | |
21 | ,mType(LegendMarkerTypeSeries) |
|
21 | mTextItem(new QGraphicsSimpleTextItem(this)) | |
22 | ,mTextItem(new QGraphicsSimpleTextItem(this)) |
|
22 | { | |
23 | { |
|
23 | setAcceptedMouseButtons(Qt::LeftButton|Qt::RightButton); | |
24 | setAcceptedMouseButtons(Qt::LeftButton|Qt::RightButton); |
|
24 | } | |
25 | } |
|
|||
26 |
|
25 | |||
27 | LegendMarker::LegendMarker(QSeries *series, QBarSet *barset, QGraphicsItem *parent) |
|
26 | LegendMarker::LegendMarker(QSeries *series, QBarSet *barset, QGraphicsItem *parent) : QGraphicsObject(parent), | |
28 | : QGraphicsObject(parent) |
|
27 | mPos(0,0), | |
29 |
|
|
28 | mSize(0,0), | |
30 | ,mSize(0,0) |
|
29 | mBoundingRect(0,0,0,0), | |
31 |
|
|
30 | mMarkerBoundingRect(0,0,0,0), | |
32 | ,mMarkerBoundingRect(0,0,0,0) |
|
31 | mSeries(series), | |
33 | ,mSeries(series) |
|
32 | mBarset(barset), | |
34 | ,mBarset(barset) |
|
33 | mPieslice(0), | |
35 | ,mPieslice(0) |
|
34 | mType(LegendMarkerTypeBarset), | |
36 | ,mType(LegendMarkerTypeBarset) |
|
35 | mTextItem(new QGraphicsSimpleTextItem(this)) | |
37 | ,mTextItem(new QGraphicsSimpleTextItem(this)) |
|
36 | { | |
38 | { |
|
37 | setAcceptedMouseButtons(Qt::LeftButton|Qt::RightButton); | |
39 | setAcceptedMouseButtons(Qt::LeftButton|Qt::RightButton); |
|
38 | } | |
40 | } |
|
|||
41 |
|
39 | |||
42 | LegendMarker::LegendMarker(QSeries *series, QPieSlice *pieslice, QGraphicsItem *parent) |
|
40 | LegendMarker::LegendMarker(QSeries *series, QPieSlice *pieslice, QGraphicsItem *parent) : QGraphicsObject(parent), | |
43 | : QGraphicsObject(parent) |
|
41 | mPos(0,0), | |
44 |
|
|
42 | mSize(0,0), | |
45 | ,mSize(0,0) |
|
43 | mBoundingRect(0,0,0,0), | |
46 |
|
|
44 | mMarkerBoundingRect(0,0,0,0), | |
47 | ,mMarkerBoundingRect(0,0,0,0) |
|
45 | mSeries(series), | |
48 | ,mSeries(series) |
|
46 | mBarset(0), | |
49 | ,mBarset(0) |
|
47 | mPieslice(pieslice), | |
50 | ,mPieslice(pieslice) |
|
48 | mType(LegendMarkerTypePieslice), | |
51 | ,mType(LegendMarkerTypePieslice) |
|
49 | mTextItem(new QGraphicsSimpleTextItem(this)) | |
52 | ,mTextItem(new QGraphicsSimpleTextItem(this)) |
|
50 | { | |
53 | { |
|
51 | setAcceptedMouseButtons(Qt::LeftButton|Qt::RightButton); | |
54 | setAcceptedMouseButtons(Qt::LeftButton|Qt::RightButton); |
|
52 | } | |
55 | } |
|
|||
56 |
|
53 | |||
57 | void LegendMarker::setPos(qreal x, qreal y) |
|
54 | void LegendMarker::setPos(qreal x, qreal y) | |
58 | { |
|
55 | { | |
@@ -60,7 +57,7 void LegendMarker::setPos(qreal x, qreal y) | |||||
60 | layoutChanged(); |
|
57 | layoutChanged(); | |
61 | } |
|
58 | } | |
62 |
|
59 | |||
63 | void LegendMarker::setPen(const QPen pen) |
|
60 | void LegendMarker::setPen(const QPen &pen) | |
64 | { |
|
61 | { | |
65 | mPen = pen; |
|
62 | mPen = pen; | |
66 | } |
|
63 | } | |
@@ -70,7 +67,7 QPen LegendMarker::pen() const | |||||
70 | return mPen; |
|
67 | return mPen; | |
71 | } |
|
68 | } | |
72 |
|
69 | |||
73 | void LegendMarker::setBrush(const QBrush brush) |
|
70 | void LegendMarker::setBrush(const QBrush &brush) | |
74 | { |
|
71 | { | |
75 | mBrush = brush; |
|
72 | mBrush = brush; | |
76 | } |
|
73 | } |
@@ -25,16 +25,16 class LegendMarker : public QGraphicsObject | |||||
25 | }; |
|
25 | }; | |
26 |
|
26 | |||
27 | public: |
|
27 | public: | |
28 |
LegendMarker(QSeries* |
|
28 | LegendMarker(QSeries *series, QGraphicsItem *parent = 0); | |
29 |
LegendMarker(QSeries* |
|
29 | LegendMarker(QSeries *series, QBarSet *barset, QGraphicsItem *parent = 0); | |
30 |
LegendMarker(QSeries* |
|
30 | LegendMarker(QSeries *series, QPieSlice *pieslice, QGraphicsItem *parent = 0); | |
31 |
|
31 | |||
32 | void setPos(qreal x, qreal y); |
|
32 | void setPos(qreal x, qreal y); | |
33 |
|
33 | |||
34 | void setPen(const QPen pen); |
|
34 | void setPen(const QPen &pen); | |
35 | QPen pen() const; |
|
35 | QPen pen() const; | |
36 |
|
36 | |||
37 | void setBrush(const QBrush brush); |
|
37 | void setBrush(const QBrush &brush); | |
38 | QBrush brush() const; |
|
38 | QBrush brush() const; | |
39 |
|
39 | |||
40 | void setName(const QString name); |
|
40 | void setName(const QString name); | |
@@ -53,9 +53,9 public: | |||||
53 | void mousePressEvent(QGraphicsSceneMouseEvent *event); |
|
53 | void mousePressEvent(QGraphicsSceneMouseEvent *event); | |
54 |
|
54 | |||
55 | Q_SIGNALS: |
|
55 | Q_SIGNALS: | |
56 |
void clicked(QSeries* |
|
56 | void clicked(QSeries *series, Qt::MouseButton button); | |
57 |
void clicked(QBarSet* |
|
57 | void clicked(QBarSet *barset, Qt::MouseButton button); | |
58 |
void clicked(QPieSlice* |
|
58 | void clicked(QPieSlice *pieslice, Qt::MouseButton button); | |
59 |
|
59 | |||
60 | public Q_SLOTS: |
|
60 | public Q_SLOTS: | |
61 | void changed(); |
|
61 | void changed(); | |
@@ -68,9 +68,9 private: | |||||
68 | QBrush mBrush; |
|
68 | QBrush mBrush; | |
69 | QPen mPen; |
|
69 | QPen mPen; | |
70 |
|
70 | |||
71 |
QSeries* |
|
71 | QSeries *mSeries; | |
72 |
QBarSet* |
|
72 | QBarSet *mBarset; | |
73 |
QPieSlice* |
|
73 | QPieSlice *mPieslice; | |
74 |
|
74 | |||
75 | LegendMarkerType mType; |
|
75 | LegendMarkerType mType; | |
76 | QGraphicsSimpleTextItem mTextItem; |
|
76 | QGraphicsSimpleTextItem mTextItem; |
@@ -59,17 +59,6 QLineSeries::~QLineSeries() | |||||
59 | } |
|
59 | } | |
60 |
|
60 | |||
61 | /*! |
|
61 | /*! | |
62 | Sets \a pen used for drawing line connecting points. |
|
|||
63 | */ |
|
|||
64 | void QLineSeries::setLinePen(const QPen &pen) |
|
|||
65 | { |
|
|||
66 | if (pen != m_pen){ |
|
|||
67 | m_pen = pen; |
|
|||
68 | emit QXYSeries::updated(); |
|
|||
69 | } |
|
|||
70 | } |
|
|||
71 |
|
||||
72 | /*! |
|
|||
73 | Sets if data points are \a visible and should be drawn on line. |
|
62 | Sets if data points are \a visible and should be drawn on line. | |
74 | */ |
|
63 | */ | |
75 | void QLineSeries::setPointsVisible(bool visible) |
|
64 | void QLineSeries::setPointsVisible(bool visible) |
@@ -13,9 +13,6 public: | |||||
13 | QLineSeries(QObject *parent=0); |
|
13 | QLineSeries(QObject *parent=0); | |
14 | virtual ~QLineSeries(); |
|
14 | virtual ~QLineSeries(); | |
15 |
|
15 | |||
16 | void setLinePen(const QPen &pen); |
|
|||
17 | QPen linePen() const {return m_pen;} |
|
|||
18 |
|
||||
19 | void setPointsVisible(bool visible); |
|
16 | void setPointsVisible(bool visible); | |
20 | bool pointsVisible() const {return m_pointsVisible;} |
|
17 | bool pointsVisible() const {return m_pointsVisible;} | |
21 |
|
18 | |||
@@ -23,7 +20,6 public: // from QChartSeries | |||||
23 | virtual QSeriesType type() const {return QSeries::SeriesTypeLine;} |
|
20 | virtual QSeriesType type() const {return QSeries::SeriesTypeLine;} | |
24 | friend QDebug operator<< (QDebug d, const QLineSeries series); |
|
21 | friend QDebug operator<< (QDebug d, const QLineSeries series); | |
25 | private: |
|
22 | private: | |
26 | QPen m_pen; |
|
|||
27 | bool m_pointsVisible; |
|
23 | bool m_pointsVisible; | |
28 |
|
24 | |||
29 | }; |
|
25 | }; |
@@ -397,22 +397,22 void QChartPrivate::updateLegendLayout() | |||||
397 | QRectF plotRect = m_rect.adjusted(padding,padding,-padding,-padding); |
|
397 | QRectF plotRect = m_rect.adjusted(padding,padding,-padding,-padding); | |
398 | QRectF legendRect; |
|
398 | QRectF legendRect; | |
399 |
|
399 | |||
400 |
switch (m_legend-> |
|
400 | switch (m_legend->alignment()) | |
401 | { |
|
401 | { | |
402 |
case QLegend:: |
|
402 | case QLegend::LayoutTop: { | |
403 | // legendRect = plotRect.adjusted(m_padding,0,-m_padding,-m_padding - plotRect.height()); |
|
403 | // legendRect = plotRect.adjusted(m_padding,0,-m_padding,-m_padding - plotRect.height()); | |
404 | legendRect = plotRect.adjusted(0,0,0,-padding - plotRect.height()); |
|
404 | legendRect = plotRect.adjusted(0,0,0,-padding - plotRect.height()); | |
405 | break; |
|
405 | break; | |
406 | } |
|
406 | } | |
407 |
case QLegend:: |
|
407 | case QLegend::LayoutBottom: { | |
408 | legendRect = plotRect.adjusted(padding,padding + plotRect.height(),-padding,0); |
|
408 | legendRect = plotRect.adjusted(padding,padding + plotRect.height(),-padding,0); | |
409 | break; |
|
409 | break; | |
410 | } |
|
410 | } | |
411 |
case QLegend:: |
|
411 | case QLegend::LayoutLeft: { | |
412 | legendRect = plotRect.adjusted(0,padding,-padding - plotRect.width(),-padding); |
|
412 | legendRect = plotRect.adjusted(0,padding,-padding - plotRect.width(),-padding); | |
413 | break; |
|
413 | break; | |
414 | } |
|
414 | } | |
415 |
case QLegend:: |
|
415 | case QLegend::LayoutRight: { | |
416 | legendRect = plotRect.adjusted(padding + plotRect.width(),padding,0,-padding); |
|
416 | legendRect = plotRect.adjusted(padding + plotRect.width(),padding,0,-padding); | |
417 | break; |
|
417 | break; | |
418 | } |
|
418 | } |
@@ -37,14 +37,14 QTCOMMERCIALCHART_BEGIN_NAMESPACE | |||||
37 | */ |
|
37 | */ | |
38 |
|
38 | |||
39 | /*! |
|
39 | /*! | |
40 |
\enum QLegend:: |
|
40 | \enum QLegend::Layout | |
41 |
|
41 | |||
42 | This enum describes the possible position for legend inside chart. |
|
42 | This enum describes the possible position for legend inside chart. | |
43 |
|
43 | |||
44 |
\value |
|
44 | \value LayoutTop | |
45 |
\value |
|
45 | \value LayoutBottom | |
46 |
\value |
|
46 | \value LayoutLeft | |
47 |
\value |
|
47 | \value LayoutRight | |
48 | */ |
|
48 | */ | |
49 |
|
49 | |||
50 |
|
50 | |||
@@ -67,27 +67,27 QTCOMMERCIALCHART_BEGIN_NAMESPACE | |||||
67 | Constructs the legend object and sets the parent to \a parent |
|
67 | Constructs the legend object and sets the parent to \a parent | |
68 | */ |
|
68 | */ | |
69 | QLegend::QLegend(QGraphicsItem *parent) : QGraphicsObject(parent), |
|
69 | QLegend::QLegend(QGraphicsItem *parent) : QGraphicsObject(parent), | |
70 |
m_ |
|
70 | m_pos(0,0), | |
71 |
m_ |
|
71 | m_size(0,0), | |
72 |
m_ |
|
72 | m_minimumSize(50,20), // TODO: magic numbers | |
73 |
m_ |
|
73 | m_maximumSize(150,100), | |
74 | m_brush(Qt::darkGray), // TODO: from theme? |
|
74 | m_brush(Qt::darkGray), // TODO: from theme? | |
75 |
m_ |
|
75 | m_alignment(QLegend::LayoutTop), | |
76 | mFirstMarker(0), |
|
76 | mFirstMarker(0), | |
77 |
m_ |
|
77 | m_margin(5) | |
78 | { |
|
78 | { | |
79 |
m_ |
|
79 | m_scrollButtonLeft = new LegendScrollButton(LegendScrollButton::ScrollButtonIdLeft, this); | |
80 |
m_ |
|
80 | m_scrollButtonRight = new LegendScrollButton(LegendScrollButton::ScrollButtonIdRight, this); | |
81 |
m_ |
|
81 | m_scrollButtonUp = new LegendScrollButton(LegendScrollButton::ScrollButtonIdUp, this); | |
82 |
m_ |
|
82 | m_scrollButtonDown = new LegendScrollButton(LegendScrollButton::ScrollButtonIdDown, this); | |
83 |
|
83 | |||
84 |
connect(m_ |
|
84 | connect(m_scrollButtonLeft, SIGNAL(clicked(QGraphicsSceneMouseEvent*)), | |
85 | this, SLOT(handleScrollButtonClicked(QGraphicsSceneMouseEvent*))); |
|
85 | this, SLOT(handleScrollButtonClicked(QGraphicsSceneMouseEvent*))); | |
86 |
connect(m_ |
|
86 | connect(m_scrollButtonRight, SIGNAL(clicked(QGraphicsSceneMouseEvent*)), | |
87 | this, SLOT(handleScrollButtonClicked(QGraphicsSceneMouseEvent*))); |
|
87 | this, SLOT(handleScrollButtonClicked(QGraphicsSceneMouseEvent*))); | |
88 |
connect(m_ |
|
88 | connect(m_scrollButtonUp, SIGNAL(clicked(QGraphicsSceneMouseEvent*)), | |
89 | this, SLOT(handleScrollButtonClicked(QGraphicsSceneMouseEvent*))); |
|
89 | this, SLOT(handleScrollButtonClicked(QGraphicsSceneMouseEvent*))); | |
90 |
connect(m_ |
|
90 | connect(m_scrollButtonDown, SIGNAL(clicked(QGraphicsSceneMouseEvent*)), | |
91 | this, SLOT(handleScrollButtonClicked(QGraphicsSceneMouseEvent*))); |
|
91 | this, SLOT(handleScrollButtonClicked(QGraphicsSceneMouseEvent*))); | |
92 |
|
92 | |||
93 | setZValue(ChartPresenter::LegendZValue); |
|
93 | setZValue(ChartPresenter::LegendZValue); | |
@@ -112,7 +112,7 void QLegend::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, Q | |||||
112 | */ |
|
112 | */ | |
113 | QRectF QLegend::boundingRect() const |
|
113 | QRectF QLegend::boundingRect() const | |
114 | { |
|
114 | { | |
115 |
return QRectF(m_ |
|
115 | return QRectF(m_pos,m_size); | |
116 | } |
|
116 | } | |
117 |
|
117 | |||
118 | /*! |
|
118 | /*! | |
@@ -156,20 +156,20 QPen QLegend::pen() const | |||||
156 |
|
156 | |||
157 | /*! |
|
157 | /*! | |
158 | Sets the \a preferred layout for legend. Legend tries to paint itself on the defined position in chart. |
|
158 | Sets the \a preferred layout for legend. Legend tries to paint itself on the defined position in chart. | |
159 |
\sa QLegend:: |
|
159 | \sa QLegend::Layout | |
160 | */ |
|
160 | */ | |
161 |
void QLegend::set |
|
161 | void QLegend::setAlignmnent(QLegend::Layout alignment) | |
162 | { |
|
162 | { | |
163 | m_PreferredLayout = preferred; |
|
163 | m_alignment = alignment; | |
164 | updateLayout(); |
|
164 | updateLayout(); | |
165 | } |
|
165 | } | |
166 |
|
166 | |||
167 | /*! |
|
167 | /*! | |
168 | Returns the preferred layout for legend |
|
168 | Returns the preferred layout for legend | |
169 | */ |
|
169 | */ | |
170 |
QLegend:: |
|
170 | QLegend::Layout QLegend::alignment() const | |
171 | { |
|
171 | { | |
172 |
return m_ |
|
172 | return m_alignment; | |
173 | } |
|
173 | } | |
174 |
|
174 | |||
175 | /*! |
|
175 | /*! | |
@@ -177,7 +177,7 QLegend::PreferredLayout QLegend::preferredLayout() const | |||||
177 | */ |
|
177 | */ | |
178 | QSizeF QLegend::maximumSize() const |
|
178 | QSizeF QLegend::maximumSize() const | |
179 | { |
|
179 | { | |
180 |
return m_ |
|
180 | return m_maximumSize; | |
181 | } |
|
181 | } | |
182 |
|
182 | |||
183 | /*! |
|
183 | /*! | |
@@ -186,7 +186,7 QSizeF QLegend::maximumSize() const | |||||
186 | */ |
|
186 | */ | |
187 | void QLegend::setMaximumSize(const QSizeF size) |
|
187 | void QLegend::setMaximumSize(const QSizeF size) | |
188 | { |
|
188 | { | |
189 |
m_ |
|
189 | m_maximumSize = size; | |
190 | updateLayout(); |
|
190 | updateLayout(); | |
191 | } |
|
191 | } | |
192 |
|
192 | |||
@@ -195,7 +195,7 void QLegend::setMaximumSize(const QSizeF size) | |||||
195 | */ |
|
195 | */ | |
196 | QSizeF QLegend::size() const |
|
196 | QSizeF QLegend::size() const | |
197 | { |
|
197 | { | |
198 |
return m_ |
|
198 | return m_size; | |
199 | } |
|
199 | } | |
200 |
|
200 | |||
201 | /*! |
|
201 | /*! | |
@@ -204,12 +204,12 QSizeF QLegend::size() const | |||||
204 | */ |
|
204 | */ | |
205 | void QLegend::setSize(const QSizeF size) |
|
205 | void QLegend::setSize(const QSizeF size) | |
206 | { |
|
206 | { | |
207 |
m_ |
|
207 | m_size = size; | |
208 |
if (m_ |
|
208 | if (m_size.width() > m_maximumSize.width()) { | |
209 |
m_ |
|
209 | m_size.setWidth(m_maximumSize.width()); | |
210 | } |
|
210 | } | |
211 |
if (m_ |
|
211 | if (m_size.height() > m_maximumSize.height()) { | |
212 |
m_ |
|
212 | m_size.setHeight(m_maximumSize.height()); | |
213 | } |
|
213 | } | |
214 | } |
|
214 | } | |
215 |
|
215 | |||
@@ -218,7 +218,7 void QLegend::setSize(const QSizeF size) | |||||
218 | */ |
|
218 | */ | |
219 | void QLegend::setPos(const QPointF &pos) |
|
219 | void QLegend::setPos(const QPointF &pos) | |
220 | { |
|
220 | { | |
221 |
m_ |
|
221 | m_pos = pos; | |
222 | updateLayout(); |
|
222 | updateLayout(); | |
223 | } |
|
223 | } | |
224 |
|
224 | |||
@@ -241,8 +241,7 void QLegend::handleSeriesRemoved(QSeries *series) | |||||
241 | { |
|
241 | { | |
242 | disconnectSeries(series); |
|
242 | disconnectSeries(series); | |
243 |
|
243 | |||
244 | if (series->type() == QSeries::SeriesTypeArea) |
|
244 | if (series->type() == QSeries::SeriesTypeArea) { | |
245 | { |
|
|||
246 | // This is special case. Area series has upper and lower series, which each have markers |
|
245 | // This is special case. Area series has upper and lower series, which each have markers | |
247 | QAreaSeries* s = static_cast<QAreaSeries *> (series); |
|
246 | QAreaSeries* s = static_cast<QAreaSeries *> (series); | |
248 | deleteMarkers(s->upperSeries()); |
|
247 | deleteMarkers(s->upperSeries()); | |
@@ -269,7 +268,7 void QLegend::handleAdded(QList<QPieSlice *> slices) | |||||
269 | connect(s, SIGNAL(changed()), marker, SLOT(changed())); |
|
268 | connect(s, SIGNAL(changed()), marker, SLOT(changed())); | |
270 | connect(s, SIGNAL(destroyed()), marker, SLOT(deleteLater())); |
|
269 | connect(s, SIGNAL(destroyed()), marker, SLOT(deleteLater())); | |
271 | connect(marker, SIGNAL(destroyed()), this, SLOT(handleMarkerDestroyed())); |
|
270 | connect(marker, SIGNAL(destroyed()), this, SLOT(handleMarkerDestroyed())); | |
272 |
m_ |
|
271 | m_markers.append(marker); | |
273 | childItems().append(marker); |
|
272 | childItems().append(marker); | |
274 | } |
|
273 | } | |
275 | updateLayout(); |
|
274 | updateLayout(); | |
@@ -290,9 +289,8 void QLegend::handleRemoved(QList<QPieSlice *> slices) | |||||
290 | */ |
|
289 | */ | |
291 | void QLegend::handleMarkerDestroyed() |
|
290 | void QLegend::handleMarkerDestroyed() | |
292 | { |
|
291 | { | |
293 | // TODO: what if more than one markers are destroyed and we update layout after first one? |
|
|||
294 | LegendMarker* m = static_cast<LegendMarker *> (sender()); |
|
292 | LegendMarker* m = static_cast<LegendMarker *> (sender()); | |
295 |
m_ |
|
293 | m_markers.removeOne(m); | |
296 | updateLayout(); |
|
294 | updateLayout(); | |
297 | } |
|
295 | } | |
298 |
|
296 | |||
@@ -333,47 +331,11 void QLegend::handleScrollButtonClicked(QGraphicsSceneMouseEvent *event) | |||||
333 | */ |
|
331 | */ | |
334 | void QLegend::connectSeries(QSeries *series) |
|
332 | void QLegend::connectSeries(QSeries *series) | |
335 | { |
|
333 | { | |
336 | // Connect relevant signals from series |
|
334 | // Connect relevant signals from series. Currently only pie series has interesting signals | |
337 | switch (series->type()) |
|
335 | // TODO: bar chart may have | |
338 | { |
|
336 | if (series->type() == QSeries::SeriesTypePie) { | |
339 | case QSeries::SeriesTypeLine: { |
|
|||
340 | // QLineSeries* lineSeries = static_cast<QLineSeries*>(series); |
|
|||
341 | break; |
|
|||
342 | } |
|
|||
343 | case QSeries::SeriesTypeArea: { |
|
|||
344 | // QAreaSeries* areaSeries = static_cast<QAreaSeries*>(series); |
|
|||
345 | break; |
|
|||
346 | } |
|
|||
347 | case QSeries::SeriesTypeBar: { |
|
|||
348 | // QBarSeries* barSeries = static_cast<QBarSeries*>(series); |
|
|||
349 | break; |
|
|||
350 | } |
|
|||
351 | case QSeries::SeriesTypeStackedBar: { |
|
|||
352 | // QStackedBarSeries* stackedBarSeries = static_cast<QStackedBarSeries*>(series); |
|
|||
353 | break; |
|
|||
354 | } |
|
|||
355 | case QSeries::SeriesTypePercentBar: { |
|
|||
356 | // QPercentBarSeries* percentBarSeries = static_cast<QPercentBarSeries*>(series); |
|
|||
357 | break; |
|
|||
358 | } |
|
|||
359 | case QSeries::SeriesTypeScatter: { |
|
|||
360 | // QScatterSeries *scatterSeries = static_cast<QScatterSeries *>(series); |
|
|||
361 | break; |
|
|||
362 | } |
|
|||
363 | case QSeries::SeriesTypePie: { |
|
|||
364 | QPieSeries *pieSeries = static_cast<QPieSeries *>(series); |
|
337 | QPieSeries *pieSeries = static_cast<QPieSeries *>(series); | |
365 | connect(pieSeries,SIGNAL(added(QList<QPieSlice*>)),this,SLOT(handleAdded(QList<QPieSlice*>))); |
|
338 | connect(pieSeries,SIGNAL(added(QList<QPieSlice*>)),this,SLOT(handleAdded(QList<QPieSlice*>))); | |
366 | // connect(pieSeries,SIGNAL(removed(QList<QPieSlice*>)),this,SLOT(handleRemoved(QList<QPieSlice*>))); |
|
|||
367 | break; |
|
|||
368 | } |
|
|||
369 | case QSeries::SeriesTypeSpline: { |
|
|||
370 | // QSplineSeries* splineSeries = static_cast<QSplineSeries*>(series); |
|
|||
371 | break; |
|
|||
372 | } |
|
|||
373 | default: { |
|
|||
374 | qWarning() << "QLegend::connectSeries" << series->type() << "not implemented."; |
|
|||
375 | break; |
|
|||
376 | } |
|
|||
377 | } |
|
339 | } | |
378 | } |
|
340 | } | |
379 |
|
341 | |||
@@ -382,47 +344,9 void QLegend::connectSeries(QSeries *series) | |||||
382 | */ |
|
344 | */ | |
383 | void QLegend::disconnectSeries(QSeries *series) |
|
345 | void QLegend::disconnectSeries(QSeries *series) | |
384 | { |
|
346 | { | |
385 | // Connect relevant signals from series |
|
347 | if (series->type() == QSeries::SeriesTypePie) { | |
386 | switch (series->type()) |
|
|||
387 | { |
|
|||
388 | case QSeries::SeriesTypeLine: { |
|
|||
389 | // QLineSeries* lineSeries = static_cast<QLineSeries*>(series); |
|
|||
390 | break; |
|
|||
391 | } |
|
|||
392 | case QSeries::SeriesTypeArea: { |
|
|||
393 | // QAreaSeries* areaSeries = static_cast<QAreaSeries*>(series); |
|
|||
394 | break; |
|
|||
395 | } |
|
|||
396 | case QSeries::SeriesTypeBar: { |
|
|||
397 | // QBarSeries* barSeries = static_cast<QBarSeries*>(series); |
|
|||
398 | break; |
|
|||
399 | } |
|
|||
400 | case QSeries::SeriesTypeStackedBar: { |
|
|||
401 | // QStackedBarSeries* stackedBarSeries = static_cast<QStackedBarSeries*>(series); |
|
|||
402 | break; |
|
|||
403 | } |
|
|||
404 | case QSeries::SeriesTypePercentBar: { |
|
|||
405 | // QPercentBarSeries* percentBarSeries = static_cast<QPercentBarSeries*>(series); |
|
|||
406 | break; |
|
|||
407 | } |
|
|||
408 | case QSeries::SeriesTypeScatter: { |
|
|||
409 | // QScatterSeries *scatterSeries = static_cast<QScatterSeries *>(series); |
|
|||
410 | break; |
|
|||
411 | } |
|
|||
412 | case QSeries::SeriesTypePie: { |
|
|||
413 | QPieSeries *pieSeries = static_cast<QPieSeries *>(series); |
|
348 | QPieSeries *pieSeries = static_cast<QPieSeries *>(series); | |
414 | disconnect(pieSeries, SIGNAL(added(QList<QPieSlice *>)), this, SLOT(handleAdded(QList<QPieSlice *>))); |
|
349 | disconnect(pieSeries, SIGNAL(added(QList<QPieSlice *>)), this, SLOT(handleAdded(QList<QPieSlice *>))); | |
415 | // disconnect(pieSeries,SIGNAL(removed(QList<QPieSlice*>)),this,SLOT(handleRemoved(QList<QPieSlice*>))); |
|
|||
416 | break; |
|
|||
417 | } |
|
|||
418 | case QSeries::SeriesTypeSpline: { |
|
|||
419 | // QSplineSeries* splineSeries = static_cast<QSplineSeries*>(series); |
|
|||
420 | break; |
|
|||
421 | } |
|
|||
422 | default: { |
|
|||
423 | qWarning()<< "QLegend::disconnectSeries" << series->type() << "not implemented."; |
|
|||
424 | break; |
|
|||
425 | } |
|
|||
426 | } |
|
350 | } | |
427 | } |
|
351 | } | |
428 |
|
352 | |||
@@ -447,44 +371,38 void QLegend::createMarkers(QSeries *series) | |||||
447 | appendMarkers(areaSeries->lowerSeries()); |
|
371 | appendMarkers(areaSeries->lowerSeries()); | |
448 | break; |
|
372 | break; | |
449 | } |
|
373 | } | |
450 |
|
||||
451 | case QSeries::SeriesTypeBar: { |
|
374 | case QSeries::SeriesTypeBar: { | |
452 | QBarSeries *barSeries = static_cast<QBarSeries *>(series); |
|
375 | QBarSeries *barSeries = static_cast<QBarSeries *>(series); | |
453 | appendMarkers(barSeries); |
|
376 | appendMarkers(barSeries); | |
454 | break; |
|
377 | break; | |
455 | } |
|
378 | } | |
456 |
|
||||
457 | case QSeries::SeriesTypeStackedBar: { |
|
379 | case QSeries::SeriesTypeStackedBar: { | |
458 | QStackedBarSeries *stackedBarSeries = static_cast<QStackedBarSeries *>(series); |
|
380 | QStackedBarSeries *stackedBarSeries = static_cast<QStackedBarSeries *>(series); | |
459 | appendMarkers(stackedBarSeries); |
|
381 | appendMarkers(stackedBarSeries); | |
460 | break; |
|
382 | break; | |
461 | } |
|
383 | } | |
462 |
|
||||
463 | case QSeries::SeriesTypePercentBar: { |
|
384 | case QSeries::SeriesTypePercentBar: { | |
464 | QPercentBarSeries *percentBarSeries = static_cast<QPercentBarSeries *>(series); |
|
385 | QPercentBarSeries *percentBarSeries = static_cast<QPercentBarSeries *>(series); | |
465 | appendMarkers(percentBarSeries); |
|
386 | appendMarkers(percentBarSeries); | |
466 | break; |
|
387 | break; | |
467 | } |
|
388 | } | |
468 |
|
||||
469 | case QSeries::SeriesTypeScatter: { |
|
389 | case QSeries::SeriesTypeScatter: { | |
470 | QScatterSeries *scatterSeries = static_cast<QScatterSeries *>(series); |
|
390 | QScatterSeries *scatterSeries = static_cast<QScatterSeries *>(series); | |
471 | appendMarkers(scatterSeries); |
|
391 | appendMarkers(scatterSeries); | |
472 | break; |
|
392 | break; | |
473 | } |
|
393 | } | |
474 |
|
||||
475 | case QSeries::SeriesTypePie: { |
|
394 | case QSeries::SeriesTypePie: { | |
476 | QPieSeries *pieSeries = static_cast<QPieSeries *>(series); |
|
395 | QPieSeries *pieSeries = static_cast<QPieSeries *>(series); | |
477 | appendMarkers(pieSeries); |
|
396 | appendMarkers(pieSeries); | |
478 | break; |
|
397 | break; | |
479 | } |
|
398 | } | |
480 |
|
||||
481 | case QSeries::SeriesTypeSpline: { |
|
399 | case QSeries::SeriesTypeSpline: { | |
482 | QSplineSeries *splineSeries = static_cast<QSplineSeries *>(series); |
|
400 | QSplineSeries *splineSeries = static_cast<QSplineSeries *>(series); | |
483 | appendMarkers(splineSeries); |
|
401 | appendMarkers(splineSeries); | |
484 | break; |
|
402 | break; | |
485 | } |
|
403 | } | |
486 | default: { |
|
404 | default: { | |
487 |
qWarning()<< "QLegend::createMarkers" << series->type() << " |
|
405 | qWarning()<< "QLegend::createMarkers" << series->type() << "unknown series type."; | |
488 | break; |
|
406 | break; | |
489 | } |
|
407 | } | |
490 | } |
|
408 | } | |
@@ -501,7 +419,7 void QLegend::appendMarkers(QXYSeries* series) | |||||
501 | marker->setBrush(series->brush()); |
|
419 | marker->setBrush(series->brush()); | |
502 | connect(marker, SIGNAL(clicked(QSeries *, Qt::MouseButton)), this, SIGNAL(clicked(QSeries *, Qt::MouseButton))); |
|
420 | connect(marker, SIGNAL(clicked(QSeries *, Qt::MouseButton)), this, SIGNAL(clicked(QSeries *, Qt::MouseButton))); | |
503 | connect(marker, SIGNAL(destroyed()), this, SLOT(handleMarkerDestroyed())); |
|
421 | connect(marker, SIGNAL(destroyed()), this, SLOT(handleMarkerDestroyed())); | |
504 |
m_ |
|
422 | m_markers.append(marker); | |
505 | childItems().append(marker); |
|
423 | childItems().append(marker); | |
506 | } |
|
424 | } | |
507 |
|
425 | |||
@@ -519,7 +437,7 void QLegend::appendMarkers(QBarSeries *series) | |||||
519 | this, SIGNAL(clicked(QBarSet *, Qt::MouseButton))); |
|
437 | this, SIGNAL(clicked(QBarSet *, Qt::MouseButton))); | |
520 | connect(s, SIGNAL(valueChanged()), marker, SLOT(changed())); |
|
438 | connect(s, SIGNAL(valueChanged()), marker, SLOT(changed())); | |
521 | connect(marker, SIGNAL(destroyed()), this, SLOT(handleMarkerDestroyed())); |
|
439 | connect(marker, SIGNAL(destroyed()), this, SLOT(handleMarkerDestroyed())); | |
522 |
m_ |
|
440 | m_markers.append(marker); | |
523 | childItems().append(marker); |
|
441 | childItems().append(marker); | |
524 | } |
|
442 | } | |
525 | } |
|
443 | } | |
@@ -539,7 +457,7 void QLegend::appendMarkers(QPieSeries *series) | |||||
539 | connect(s, SIGNAL(changed()), marker, SLOT(changed())); |
|
457 | connect(s, SIGNAL(changed()), marker, SLOT(changed())); | |
540 | connect(s, SIGNAL(destroyed()), marker, SLOT(deleteLater())); |
|
458 | connect(s, SIGNAL(destroyed()), marker, SLOT(deleteLater())); | |
541 | connect(marker, SIGNAL(destroyed()), this, SLOT(handleMarkerDestroyed())); |
|
459 | connect(marker, SIGNAL(destroyed()), this, SLOT(handleMarkerDestroyed())); | |
542 |
m_ |
|
460 | m_markers.append(marker); | |
543 | childItems().append(marker); |
|
461 | childItems().append(marker); | |
544 | } |
|
462 | } | |
545 | } |
|
463 | } | |
@@ -550,9 +468,9 void QLegend::appendMarkers(QPieSeries *series) | |||||
550 | void QLegend::deleteMarkers(QSeries *series) |
|
468 | void QLegend::deleteMarkers(QSeries *series) | |
551 | { |
|
469 | { | |
552 | // Search all markers that belong to given series and delete them. |
|
470 | // Search all markers that belong to given series and delete them. | |
553 |
foreach (LegendMarker *m, m_ |
|
471 | foreach (LegendMarker *m, m_markers) { | |
554 | if (m->series() == series) { |
|
472 | if (m->series() == series) { | |
555 |
m_ |
|
473 | m_markers.removeOne(m); | |
556 | delete m; |
|
474 | delete m; | |
557 | } |
|
475 | } | |
558 | } |
|
476 | } | |
@@ -566,7 +484,7 void QLegend::deleteMarkers(QSeries *series) | |||||
566 | void QLegend::updateLayout() |
|
484 | void QLegend::updateLayout() | |
567 | { |
|
485 | { | |
568 | // Calculate layout for markers and text |
|
486 | // Calculate layout for markers and text | |
569 |
if (m_ |
|
487 | if (m_markers.count() <= 0) { | |
570 | // Nothing to do |
|
488 | // Nothing to do | |
571 | return; |
|
489 | return; | |
572 | } |
|
490 | } | |
@@ -580,42 +498,42 void QLegend::updateLayout() | |||||
580 |
|
498 | |||
581 | qreal totalWidth = 0; |
|
499 | qreal totalWidth = 0; | |
582 | qreal totalHeight = 0; |
|
500 | qreal totalHeight = 0; | |
583 |
switch (m_ |
|
501 | switch (m_alignment) | |
584 | { |
|
502 | { | |
585 | // Both cases organise items horizontally |
|
503 | // Both cases organise items horizontally | |
586 |
case QLegend:: |
|
504 | case QLegend::LayoutBottom: | |
587 |
case QLegend:: |
|
505 | case QLegend::LayoutTop: { | |
588 |
|
506 | |||
589 | qreal xStep = markerMaxSize.width(); |
|
507 | qreal xStep = markerMaxSize.width(); | |
590 |
qreal x = m_ |
|
508 | qreal x = m_pos.x() + m_margin; | |
591 |
qreal y = m_ |
|
509 | qreal y = m_pos.y() + m_margin; | |
592 | int column = 0; |
|
510 | int column = 0; | |
593 | int maxColumns = 1; |
|
511 | int maxColumns = 1; | |
594 | qreal scrollButtonWidth = 0; |
|
512 | qreal scrollButtonWidth = 0; | |
595 |
|
513 | |||
596 | // Set correct visibility for scroll scrollbuttons |
|
514 | // Set correct visibility for scroll scrollbuttons | |
597 | if (scrollButtonsVisible()) { |
|
515 | if (scrollButtonsVisible()) { | |
598 |
m_ |
|
516 | m_scrollButtonLeft->setVisible(true); | |
599 |
m_ |
|
517 | m_scrollButtonRight->setVisible(true); | |
600 | // scrollbuttons visible, so add their width to total width |
|
518 | // scrollbuttons visible, so add their width to total width | |
601 |
totalWidth += (m_ |
|
519 | totalWidth += (m_scrollButtonLeft->boundingRect().width() + m_margin) * 2; | |
602 |
scrollButtonWidth = m_ |
|
520 | scrollButtonWidth = m_scrollButtonLeft->boundingRect().width() + m_margin; | |
603 | // start position changes by scrollbutton width |
|
521 | // start position changes by scrollbutton width | |
604 | x += scrollButtonWidth; |
|
522 | x += scrollButtonWidth; | |
605 | } else { |
|
523 | } else { | |
606 |
m_ |
|
524 | m_scrollButtonLeft->setVisible(false); | |
607 |
m_ |
|
525 | m_scrollButtonRight->setVisible(false); | |
608 | } |
|
526 | } | |
609 |
m_ |
|
527 | m_scrollButtonUp->setVisible(false); | |
610 |
m_ |
|
528 | m_scrollButtonDown->setVisible(false); | |
611 |
|
529 | |||
612 |
for (int i=0; i < m_ |
|
530 | for (int i=0; i < m_markers.count(); i++) { | |
613 |
LegendMarker *m = m_ |
|
531 | LegendMarker *m = m_markers.at(i); | |
614 | if (i < mFirstMarker) { |
|
532 | if (i < mFirstMarker) { | |
615 | // Markers before first are not visible. |
|
533 | // Markers before first are not visible. | |
616 | m->setVisible(false); |
|
534 | m->setVisible(false); | |
617 | } else { |
|
535 | } else { | |
618 |
if ((x + xStep + scrollButtonWidth + m_ |
|
536 | if ((x + xStep + scrollButtonWidth + m_margin) > (m_pos.x() + m_maximumSize.width())) { | |
619 | // This marker would go outside legend rect. |
|
537 | // This marker would go outside legend rect. | |
620 | m->setVisible(false); |
|
538 | m->setVisible(false); | |
621 | } else { |
|
539 | } else { | |
@@ -629,45 +547,45 void QLegend::updateLayout() | |||||
629 | maxColumns = column; |
|
547 | maxColumns = column; | |
630 | } |
|
548 | } | |
631 |
|
549 | |||
632 |
m_ |
|
550 | m_scrollButtonLeft->setPos(m_pos.x() + m_margin, y); | |
633 |
m_ |
|
551 | m_scrollButtonRight->setPos(x + m_margin, y); | |
634 |
|
552 | |||
635 |
totalWidth += maxColumns * markerMaxSize.width() + m_ |
|
553 | totalWidth += maxColumns * markerMaxSize.width() + m_margin * 2; | |
636 |
totalHeight = markerMaxSize.height() + m_ |
|
554 | totalHeight = markerMaxSize.height() + m_margin * 2; | |
637 |
|
555 | |||
638 | break; |
|
556 | break; | |
639 | } |
|
557 | } | |
640 | // Both cases organize items vertically |
|
558 | // Both cases organize items vertically | |
641 |
case QLegend:: |
|
559 | case QLegend::LayoutLeft: | |
642 |
case QLegend:: |
|
560 | case QLegend::LayoutRight: { | |
643 | qreal yStep = markerMaxSize.height(); |
|
561 | qreal yStep = markerMaxSize.height(); | |
644 |
qreal x = m_ |
|
562 | qreal x = m_pos.x() + m_margin; | |
645 |
qreal y = m_ |
|
563 | qreal y = m_pos.y() + m_margin; | |
646 | int row = 1; |
|
564 | int row = 1; | |
647 | int maxRows = 1; |
|
565 | int maxRows = 1; | |
648 | qreal scrollButtonHeight = 0; |
|
566 | qreal scrollButtonHeight = 0; | |
649 |
|
567 | |||
650 | // Set correct visibility for scroll scrollbuttons |
|
568 | // Set correct visibility for scroll scrollbuttons | |
651 | if (scrollButtonsVisible()) { |
|
569 | if (scrollButtonsVisible()) { | |
652 |
m_ |
|
570 | m_scrollButtonUp->setVisible(true); | |
653 |
m_ |
|
571 | m_scrollButtonDown->setVisible(true); | |
654 |
totalHeight += (m_ |
|
572 | totalHeight += (m_scrollButtonUp->boundingRect().height() + m_margin) * 2; // scrollbuttons visible, so add their height to total height | |
655 |
scrollButtonHeight = m_ |
|
573 | scrollButtonHeight = m_scrollButtonUp->boundingRect().height(); | |
656 |
y += scrollButtonHeight + m_ |
|
574 | y += scrollButtonHeight + m_margin; // start position changes by scrollbutton height | |
657 | } else { |
|
575 | } else { | |
658 |
m_ |
|
576 | m_scrollButtonUp->setVisible(false); | |
659 |
m_ |
|
577 | m_scrollButtonDown->setVisible(false); | |
660 | } |
|
578 | } | |
661 |
m_ |
|
579 | m_scrollButtonLeft->setVisible(false); | |
662 |
m_ |
|
580 | m_scrollButtonRight->setVisible(false); | |
663 |
|
581 | |||
664 |
for (int i=0; i < m_ |
|
582 | for (int i=0; i < m_markers.count(); i++) { | |
665 |
LegendMarker* m = m_ |
|
583 | LegendMarker* m = m_markers.at(i); | |
666 | if (i < mFirstMarker) { |
|
584 | if (i < mFirstMarker) { | |
667 | // Markers before first are not visible. |
|
585 | // Markers before first are not visible. | |
668 | m->setVisible(false); |
|
586 | m->setVisible(false); | |
669 | } else { |
|
587 | } else { | |
670 |
if ((y + yStep + scrollButtonHeight) > (m_ |
|
588 | if ((y + yStep + scrollButtonHeight) > (m_pos.y() + m_maximumSize.height())) { | |
671 | // This marker would go outside legend rect. |
|
589 | // This marker would go outside legend rect. | |
672 | m->setVisible(false); |
|
590 | m->setVisible(false); | |
673 | } else { |
|
591 | } else { | |
@@ -681,11 +599,11 void QLegend::updateLayout() | |||||
681 | maxRows = row; |
|
599 | maxRows = row; | |
682 | } |
|
600 | } | |
683 |
|
601 | |||
684 |
m_ |
|
602 | m_scrollButtonUp->setPos(m_pos.x() + m_margin, m_pos.y() + m_margin); | |
685 |
m_ |
|
603 | m_scrollButtonDown->setPos(m_pos.x() + m_margin, y + m_margin); | |
686 |
|
604 | |||
687 |
totalWidth += markerMaxSize.width() + m_ |
|
605 | totalWidth += markerMaxSize.width() + m_margin * 2; | |
688 |
totalHeight = maxRows * markerMaxSize.height() + m_ |
|
606 | totalHeight = maxRows * markerMaxSize.height() + m_margin * 4 + scrollButtonHeight; // TODO: check this | |
689 | break; |
|
607 | break; | |
690 | } |
|
608 | } | |
691 | default: { |
|
609 | default: { | |
@@ -693,8 +611,8 void QLegend::updateLayout() | |||||
693 | } |
|
611 | } | |
694 | } |
|
612 | } | |
695 |
|
613 | |||
696 |
m_ |
|
614 | m_size.setWidth(totalWidth); | |
697 |
m_ |
|
615 | m_size.setHeight(totalHeight); | |
698 |
|
616 | |||
699 | update(); |
|
617 | update(); | |
700 | } |
|
618 | } | |
@@ -713,10 +631,10 void QLegend::rescaleScrollButtons(const QSize &size) | |||||
713 | QPolygonF down; |
|
631 | QPolygonF down; | |
714 | down << QPointF(0, 0) << QPointF(size.width() / 2, size.height()) << QPointF(size.width(), 0); |
|
632 | down << QPointF(0, 0) << QPointF(size.width() / 2, size.height()) << QPointF(size.width(), 0); | |
715 |
|
633 | |||
716 |
m_ |
|
634 | m_scrollButtonLeft->setPolygon(left); | |
717 |
m_ |
|
635 | m_scrollButtonRight->setPolygon(right); | |
718 |
m_ |
|
636 | m_scrollButtonUp->setPolygon(up); | |
719 |
m_ |
|
637 | m_scrollButtonDown->setPolygon(down); | |
720 | } |
|
638 | } | |
721 |
|
639 | |||
722 | /*! |
|
640 | /*! | |
@@ -725,7 +643,7 void QLegend::rescaleScrollButtons(const QSize &size) | |||||
725 | QSizeF QLegend::maximumMarkerSize() |
|
643 | QSizeF QLegend::maximumMarkerSize() | |
726 | { |
|
644 | { | |
727 | QSizeF max(0,0); |
|
645 | QSizeF max(0,0); | |
728 |
foreach (LegendMarker* m, m_ |
|
646 | foreach (LegendMarker* m, m_markers) { | |
729 | if (m->boundingRect().width() > max.width()) |
|
647 | if (m->boundingRect().width() > max.width()) | |
730 | max.setWidth(m->boundingRect().width()); |
|
648 | max.setWidth(m->boundingRect().width()); | |
731 | if (m->boundingRect().height() > max.height()) |
|
649 | if (m->boundingRect().height() > max.height()) | |
@@ -740,28 +658,28 QSizeF QLegend::maximumMarkerSize() | |||||
740 | */ |
|
658 | */ | |
741 | void QLegend::checkFirstMarkerBounds() |
|
659 | void QLegend::checkFirstMarkerBounds() | |
742 | { |
|
660 | { | |
743 |
if ((m_ |
|
661 | if ((m_alignment == QLegend::LayoutLeft) || (m_alignment == QLegend::LayoutRight)) { | |
744 | // Bounds limited by height. |
|
662 | // Bounds limited by height. | |
745 | int max; |
|
663 | int max; | |
746 | if (scrollButtonsVisible()) { |
|
664 | if (scrollButtonsVisible()) { | |
747 |
max = (m_ |
|
665 | max = (m_maximumSize.height() - m_scrollButtonLeft->boundingRect().height() * 2 - m_margin * 4) / maximumMarkerSize().height(); | |
748 | } else { |
|
666 | } else { | |
749 |
max = m_ |
|
667 | max = m_maximumSize.height() / maximumMarkerSize().height(); | |
750 | } |
|
668 | } | |
751 |
|
669 | |||
752 |
if (mFirstMarker > m_ |
|
670 | if (mFirstMarker > m_markers.count() - max) | |
753 |
mFirstMarker = m_ |
|
671 | mFirstMarker = m_markers.count() - max; | |
754 | } else { |
|
672 | } else { | |
755 | // Bounds limited by width |
|
673 | // Bounds limited by width | |
756 | int max; |
|
674 | int max; | |
757 | if (scrollButtonsVisible()) { |
|
675 | if (scrollButtonsVisible()) { | |
758 |
max = (m_ |
|
676 | max = (m_maximumSize.width() - m_scrollButtonLeft->boundingRect().width() * 2 - m_margin*4) / maximumMarkerSize().width(); | |
759 | } else { |
|
677 | } else { | |
760 |
max = m_ |
|
678 | max = m_maximumSize.width() / maximumMarkerSize().width(); | |
761 | } |
|
679 | } | |
762 |
|
680 | |||
763 |
if (mFirstMarker > m_ |
|
681 | if (mFirstMarker > m_markers.count() - max) | |
764 |
mFirstMarker = m_ |
|
682 | mFirstMarker = m_markers.count() - max; | |
765 | } |
|
683 | } | |
766 |
|
684 | |||
767 | if (mFirstMarker < 0) |
|
685 | if (mFirstMarker < 0) | |
@@ -774,13 +692,13 void QLegend::checkFirstMarkerBounds() | |||||
774 | bool QLegend::scrollButtonsVisible() |
|
692 | bool QLegend::scrollButtonsVisible() | |
775 | { |
|
693 | { | |
776 | // Just a helper to clarify, what the magic below means :) |
|
694 | // Just a helper to clarify, what the magic below means :) | |
777 |
if ((m_ |
|
695 | if ((m_alignment == QLegend::LayoutTop) || (m_alignment == QLegend::LayoutBottom)) { | |
778 |
return (maximumMarkerSize().width() * m_ |
|
696 | return (maximumMarkerSize().width() * m_markers.count() + m_margin * 2 > m_maximumSize.width()); | |
779 |
} else if ((m_ |
|
697 | } else if ((m_alignment == QLegend::LayoutLeft) || (m_alignment == QLegend::LayoutRight)) { | |
780 |
return (maximumMarkerSize().height() * m_ |
|
698 | return (maximumMarkerSize().height() * m_markers.count() + m_margin * 2 > m_maximumSize.height()); | |
781 | } |
|
699 | } | |
782 |
|
700 | |||
783 |
return (maximumMarkerSize().height() * m_ |
|
701 | return (maximumMarkerSize().height() * m_markers.count() + m_margin * 2 > m_maximumSize.height()); | |
784 | } |
|
702 | } | |
785 |
|
703 | |||
786 | #include "moc_qlegend.cpp" |
|
704 | #include "moc_qlegend.cpp" |
@@ -18,16 +18,18 class QPieSeries; | |||||
18 | class LegendScrollButton; |
|
18 | class LegendScrollButton; | |
19 | class QSeries; |
|
19 | class QSeries; | |
20 |
|
20 | |||
|
21 | // TODO: This as widget | |||
21 | class QTCOMMERCIALCHART_EXPORT QLegend : public QGraphicsObject |
|
22 | class QTCOMMERCIALCHART_EXPORT QLegend : public QGraphicsObject | |
22 | { |
|
23 | { | |
23 | Q_OBJECT |
|
24 | Q_OBJECT | |
24 | public: |
|
25 | public: | |
25 |
|
26 | |||
26 | enum PreferredLayout { |
|
27 | // We only support these alignments (for now) | |
27 | PreferredLayoutTop, |
|
28 | enum Layout { | |
28 | PreferredLayoutBottom, |
|
29 | LayoutTop = Qt::AlignTop, | |
29 | PreferredLayoutLeft, |
|
30 | LayoutBottom = Qt::AlignBottom, | |
30 | PreferredLayoutRight |
|
31 | LayoutLeft = Qt::AlignLeft, | |
|
32 | LayoutRight = Qt::AlignRight | |||
31 | }; |
|
33 | }; | |
32 |
|
34 | |||
33 | explicit QLegend(QGraphicsItem *parent = 0); |
|
35 | explicit QLegend(QGraphicsItem *parent = 0); | |
@@ -41,8 +43,8 public: | |||||
41 | void setPen(const QPen &pen); |
|
43 | void setPen(const QPen &pen); | |
42 | QPen pen() const; |
|
44 | QPen pen() const; | |
43 |
|
45 | |||
44 | void setPreferredLayout(QLegend::PreferredLayout preferred); |
|
46 | void setAlignmnent(QLegend::Layout alignment); | |
45 |
QLegend:: |
|
47 | QLegend::Layout alignment() const; | |
46 |
|
48 | |||
47 | QSizeF maximumSize() const; |
|
49 | QSizeF maximumSize() const; | |
48 | void setMaximumSize(const QSizeF size); |
|
50 | void setMaximumSize(const QSizeF size); | |
@@ -82,25 +84,25 private: | |||||
82 | void checkFirstMarkerBounds(); |
|
84 | void checkFirstMarkerBounds(); | |
83 | bool scrollButtonsVisible(); |
|
85 | bool scrollButtonsVisible(); | |
84 |
|
86 | |||
85 |
QPointF m_ |
|
87 | QPointF m_pos; | |
86 |
QSizeF m_ |
|
88 | QSizeF m_size; | |
87 |
QSizeF m_ |
|
89 | QSizeF m_minimumSize; | |
88 |
QSizeF m_ |
|
90 | QSizeF m_maximumSize; | |
89 |
|
91 | |||
90 |
QList<LegendMarker *> m_ |
|
92 | QList<LegendMarker *> m_markers; | |
91 |
|
93 | |||
92 | QBrush m_brush; |
|
94 | QBrush m_brush; | |
93 | QPen m_pen; |
|
95 | QPen m_pen; | |
94 |
QLegend:: |
|
96 | QLegend::Layout m_alignment; | |
95 |
|
97 | |||
96 | int mFirstMarker; |
|
98 | int mFirstMarker; | |
97 |
|
99 | |||
98 |
LegendScrollButton *m_ |
|
100 | LegendScrollButton *m_scrollButtonLeft; | |
99 |
LegendScrollButton *m_ |
|
101 | LegendScrollButton *m_scrollButtonRight; | |
100 |
LegendScrollButton *m_ |
|
102 | LegendScrollButton *m_scrollButtonUp; | |
101 |
LegendScrollButton *m_ |
|
103 | LegendScrollButton *m_scrollButtonDown; | |
102 |
|
104 | |||
103 |
qreal m_ |
|
105 | qreal m_margin; | |
104 | // <--- PIMPL |
|
106 | // <--- PIMPL | |
105 | }; |
|
107 | }; | |
106 |
|
108 |
General Comments 0
You need to be logged in to leave comments.
Login now