@@ -139,7 +139,6 void MainWidget::showLegendSpinbox() | |||||
139 | { |
|
139 | { | |
140 | m_legendSettings->setVisible(true); |
|
140 | m_legendSettings->setVisible(true); | |
141 | QRectF chartViewRect = m_chartView->rect(); |
|
141 | QRectF chartViewRect = m_chartView->rect(); | |
142 | QRectF legendRect = m_chart->legend()->boundingRect(); |
|
|||
143 |
|
142 | |||
144 | m_legendPosX->setMinimum(0); |
|
143 | m_legendPosX->setMinimum(0); | |
145 | m_legendPosX->setMaximum(chartViewRect.width()); |
|
144 | m_legendPosX->setMaximum(chartViewRect.width()); |
@@ -107,6 +107,30 QTCOMMERCIALCHART_BEGIN_NAMESPACE | |||||
107 | */ |
|
107 | */ | |
108 |
|
108 | |||
109 | /*! |
|
109 | /*! | |
|
110 | \qmlproperty real ChartView::topMargin | |||
|
111 | The space between the top of chart view and the top of the plot area. The title (if non-empty) is drawn on top margin | |||
|
112 | area of the chart view. Top margin area is also used by legend, if aligned to top. | |||
|
113 | */ | |||
|
114 | ||||
|
115 | /*! | |||
|
116 | \qmlproperty real ChartView::bottomMargin | |||
|
117 | The space between the bottom of chart view and the bottom of the plot area. The bottom margin area may be used by | |||
|
118 | legend (if aligned to bottom), x-axis, x-axis labels and x-axis tick marks. | |||
|
119 | */ | |||
|
120 | ||||
|
121 | /*! | |||
|
122 | \qmlproperty real ChartView::leftMargin | |||
|
123 | The space between the left side of chart view and the left side of the plot area. The left margin area may be used by | |||
|
124 | legend (if aligned to left), y-axis, y-axis labels and y-axis tick marks. | |||
|
125 | */ | |||
|
126 | ||||
|
127 | /*! | |||
|
128 | \qmlproperty real ChartView::rightMargin | |||
|
129 | The space between the right side of chart view and the right side of the plot area. The right margin area may be used | |||
|
130 | by legend (if aligned to right). | |||
|
131 | */ | |||
|
132 | ||||
|
133 | /*! | |||
110 | \qmlmethod AbstractSeries ChartView::series(int index) |
|
134 | \qmlmethod AbstractSeries ChartView::series(int index) | |
111 | Returns the series with \a index on the chart. This allows you to loop through the series of a chart together with |
|
135 | Returns the series with \a index on the chart. This allows you to loop through the series of a chart together with | |
112 | the count property of the chart. |
|
136 | the count property of the chart. | |
@@ -167,6 +191,22 DeclarativeChart::DeclarativeChart(QDeclarativeItem *parent) | |||||
167 | { |
|
191 | { | |
168 | setFlag(QGraphicsItem::ItemHasNoContents, false); |
|
192 | setFlag(QGraphicsItem::ItemHasNoContents, false); | |
169 | // m_chart->axisX()->setNiceNumbersEnabled(false); |
|
193 | // m_chart->axisX()->setNiceNumbersEnabled(false); | |
|
194 | m_chartMargins = m_chart->margins(); | |||
|
195 | connect(m_chart, SIGNAL(marginsChanged(QRectF)), this, SLOT(handleMarginsChanged(QRectF))); | |||
|
196 | } | |||
|
197 | ||||
|
198 | void DeclarativeChart::handleMarginsChanged(QRectF newMargins) | |||
|
199 | { | |||
|
200 | if (m_chartMargins.top() != newMargins.top()) | |||
|
201 | topMarginChanged(m_chart->margins().top()); | |||
|
202 | if (m_chartMargins.bottom() != newMargins.bottom()) | |||
|
203 | bottomMarginChanged(m_chart->margins().bottom()); | |||
|
204 | if (m_chartMargins.left() != newMargins.left()) | |||
|
205 | leftMarginChanged(m_chart->margins().left()); | |||
|
206 | if (m_chartMargins.right() != newMargins.right()) | |||
|
207 | rightMarginChanged(m_chart->margins().right()); | |||
|
208 | ||||
|
209 | m_chartMargins = m_chart->margins(); | |||
170 | } |
|
210 | } | |
171 |
|
211 | |||
172 | DeclarativeChart::~DeclarativeChart() |
|
212 | DeclarativeChart::~DeclarativeChart() | |
@@ -302,7 +342,7 void DeclarativeChart::setTitleColor(QColor color) | |||||
302 | if (color != b.color()) { |
|
342 | if (color != b.color()) { | |
303 | b.setColor(color); |
|
343 | b.setColor(color); | |
304 | m_chart->setTitleBrush(b); |
|
344 | m_chart->setTitleBrush(b); | |
305 | emit titleColorChanged(); |
|
345 | emit titleColorChanged(color); | |
306 | } |
|
346 | } | |
307 | } |
|
347 | } | |
308 |
|
348 | |||
@@ -355,6 +395,26 bool DeclarativeChart::dropShadowEnabled() | |||||
355 | return m_chart->isDropShadowEnabled(); |
|
395 | return m_chart->isDropShadowEnabled(); | |
356 | } |
|
396 | } | |
357 |
|
397 | |||
|
398 | qreal DeclarativeChart::topMargin() | |||
|
399 | { | |||
|
400 | return m_chart->margins().top(); | |||
|
401 | } | |||
|
402 | ||||
|
403 | qreal DeclarativeChart::bottomMargin() | |||
|
404 | { | |||
|
405 | return m_chart->margins().bottom(); | |||
|
406 | } | |||
|
407 | ||||
|
408 | qreal DeclarativeChart::leftMargin() | |||
|
409 | { | |||
|
410 | return m_chart->margins().left(); | |||
|
411 | } | |||
|
412 | ||||
|
413 | qreal DeclarativeChart::rightMargin() | |||
|
414 | { | |||
|
415 | return m_chart->margins().right(); | |||
|
416 | } | |||
|
417 | ||||
358 | void DeclarativeChart::zoom(qreal factor) |
|
418 | void DeclarativeChart::zoom(qreal factor) | |
359 | { |
|
419 | { | |
360 | m_chart->zoom(factor); |
|
420 | m_chart->zoom(factor); |
@@ -47,6 +47,10 class DeclarativeChart : public QDeclarativeItem | |||||
47 | Q_PROPERTY(int count READ count) |
|
47 | Q_PROPERTY(int count READ count) | |
48 | Q_PROPERTY(QColor backgroundColor READ backgroundColor WRITE setBackgroundColor NOTIFY backgroundColorChanged) |
|
48 | Q_PROPERTY(QColor backgroundColor READ backgroundColor WRITE setBackgroundColor NOTIFY backgroundColorChanged) | |
49 | Q_PROPERTY(bool dropShadowEnabled READ dropShadowEnabled WRITE setDropShadowEnabled NOTIFY dropShadowEnabledChanged) |
|
49 | Q_PROPERTY(bool dropShadowEnabled READ dropShadowEnabled WRITE setDropShadowEnabled NOTIFY dropShadowEnabledChanged) | |
|
50 | Q_PROPERTY(qreal topMargin READ topMargin NOTIFY topMarginChanged) | |||
|
51 | Q_PROPERTY(qreal bottomMargin READ bottomMargin NOTIFY bottomMarginChanged) | |||
|
52 | Q_PROPERTY(qreal leftMargin READ leftMargin NOTIFY leftMarginChanged) | |||
|
53 | Q_PROPERTY(qreal rightMargin READ rightMargin NOTIFY rightMarginChanged) | |||
50 | Q_ENUMS(Animation) |
|
54 | Q_ENUMS(Animation) | |
51 | Q_ENUMS(Theme) |
|
55 | Q_ENUMS(Theme) | |
52 | Q_ENUMS(SeriesType) |
|
56 | Q_ENUMS(SeriesType) | |
@@ -112,6 +116,10 public: | |||||
112 | int count(); |
|
116 | int count(); | |
113 | void setDropShadowEnabled(bool enabled); |
|
117 | void setDropShadowEnabled(bool enabled); | |
114 | bool dropShadowEnabled(); |
|
118 | bool dropShadowEnabled(); | |
|
119 | qreal topMargin(); | |||
|
120 | qreal bottomMargin(); | |||
|
121 | qreal leftMargin(); | |||
|
122 | qreal rightMargin(); | |||
115 |
|
123 | |||
116 | public: |
|
124 | public: | |
117 | Q_INVOKABLE QAbstractSeries *series(int index); |
|
125 | Q_INVOKABLE QAbstractSeries *series(int index); | |
@@ -126,14 +134,22 public: | |||||
126 |
|
134 | |||
127 | Q_SIGNALS: |
|
135 | Q_SIGNALS: | |
128 | void axisLabelsChanged(); |
|
136 | void axisLabelsChanged(); | |
129 | void titleColorChanged(); |
|
137 | void titleColorChanged(QColor color); | |
130 | void backgroundColorChanged(); |
|
138 | void backgroundColorChanged(); | |
131 | void dropShadowEnabledChanged(bool enabled); |
|
139 | void dropShadowEnabledChanged(bool enabled); | |
|
140 | void topMarginChanged(qreal margin); | |||
|
141 | void bottomMarginChanged(qreal margin); | |||
|
142 | void leftMarginChanged(qreal margin); | |||
|
143 | void rightMarginChanged(qreal margin); | |||
132 |
|
144 | |||
133 | public: |
|
145 | public Q_SLOTS: | |
|
146 | void handleMarginsChanged(QRectF newMargins); | |||
|
147 | ||||
|
148 | private: | |||
134 | // Extending QChart with DeclarativeChart is not possible because QObject does not support |
|
149 | // Extending QChart with DeclarativeChart is not possible because QObject does not support | |
135 | // multi inheritance, so we now have a QChart as a member instead |
|
150 | // multi inheritance, so we now have a QChart as a member instead | |
136 | QChart *m_chart; |
|
151 | QChart *m_chart; | |
|
152 | QRectF m_chartMargins; | |||
137 | }; |
|
153 | }; | |
138 |
|
154 | |||
139 | QTCOMMERCIALCHART_END_NAMESPACE |
|
155 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -300,6 +300,8 void ChartPresenter::updateLayout() | |||||
300 | { |
|
300 | { | |
301 | if (!m_rect.isValid()) return; |
|
301 | if (!m_rect.isValid()) return; | |
302 |
|
302 | |||
|
303 | QRectF oldChargMargins = m_chartMargins; | |||
|
304 | ||||
303 | // recalculate title size |
|
305 | // recalculate title size | |
304 |
|
306 | |||
305 | QSize titleSize; |
|
307 | QSize titleSize; | |
@@ -389,6 +391,8 void ChartPresenter::updateLayout() | |||||
389 | emit geometryChanged(m_chartRect); |
|
391 | emit geometryChanged(m_chartRect); | |
390 | } |
|
392 | } | |
391 |
|
393 | |||
|
394 | if (oldChargMargins != m_chartMargins) | |||
|
395 | emit marginsChanged(m_chartMargins); | |||
392 | } |
|
396 | } | |
393 |
|
397 | |||
394 | void ChartPresenter::createChartBackgroundItem() |
|
398 | void ChartPresenter::createChartBackgroundItem() |
@@ -122,6 +122,7 private Q_SLOTS: | |||||
122 | Q_SIGNALS: |
|
122 | Q_SIGNALS: | |
123 | void geometryChanged(const QRectF& rect); |
|
123 | void geometryChanged(const QRectF& rect); | |
124 | void animationsFinished(); |
|
124 | void animationsFinished(); | |
|
125 | void marginsChanged(QRectF margins); | |||
125 |
|
126 | |||
126 | private: |
|
127 | private: | |
127 | QChart* m_chart; |
|
128 | QChart* m_chart; |
@@ -76,6 +76,7 QChart::QChart(QGraphicsItem *parent, Qt::WindowFlags wFlags) : QGraphicsWidget( | |||||
76 | d_ptr->createConnections(); |
|
76 | d_ptr->createConnections(); | |
77 | d_ptr->m_legend = new LegendScroller(this); |
|
77 | d_ptr->m_legend = new LegendScroller(this); | |
78 | d_ptr->m_presenter->setTheme(QChart::ChartThemeLight, false); |
|
78 | d_ptr->m_presenter->setTheme(QChart::ChartThemeLight, false); | |
|
79 | connect(d_ptr->m_presenter, SIGNAL(marginsChanged(QRectF)), this, SIGNAL(marginsChanged(QRectF))); | |||
79 | } |
|
80 | } | |
80 |
|
81 | |||
81 | /*! |
|
82 | /*! |
@@ -37,6 +37,12 struct QChartPrivate; | |||||
37 | class QTCOMMERCIALCHART_EXPORT QChart : public QGraphicsWidget |
|
37 | class QTCOMMERCIALCHART_EXPORT QChart : public QGraphicsWidget | |
38 | { |
|
38 | { | |
39 | Q_OBJECT |
|
39 | Q_OBJECT | |
|
40 | Q_PROPERTY(QChart::ChartTheme theme READ theme WRITE setTheme) | |||
|
41 | Q_PROPERTY(QString title READ title WRITE setTitle) | |||
|
42 | Q_PROPERTY(bool backgroundVisible READ isBackgroundVisible WRITE setBackgroundVisible) | |||
|
43 | Q_PROPERTY(bool dropShadowEnabled READ isDropShadowEnabled WRITE setDropShadowEnabled) | |||
|
44 | Q_PROPERTY(QChart::AnimationOptions animationOptions READ animationOptions WRITE setAnimationOptions) | |||
|
45 | Q_PROPERTY(QRectF margins READ margins NOTIFY marginsChanged) | |||
40 | Q_ENUMS(ChartTheme) |
|
46 | Q_ENUMS(ChartTheme) | |
41 | Q_ENUMS(AnimationOption) |
|
47 | Q_ENUMS(AnimationOption) | |
42 |
|
48 | |||
@@ -107,6 +113,9 public: | |||||
107 | QLegend* legend() const; |
|
113 | QLegend* legend() const; | |
108 | QRectF margins() const; |
|
114 | QRectF margins() const; | |
109 |
|
115 | |||
|
116 | Q_SIGNALS: | |||
|
117 | void marginsChanged(QRectF newMargins); | |||
|
118 | ||||
110 | protected: |
|
119 | protected: | |
111 | void resizeEvent(QGraphicsSceneResizeEvent *event); |
|
120 | void resizeEvent(QGraphicsSceneResizeEvent *event); | |
112 |
|
121 |
@@ -38,10 +38,26 ChartView { | |||||
38 | XyPoint { x: 4.1; y: 3.3 } |
|
38 | XyPoint { x: 4.1; y: 3.3 } | |
39 | } |
|
39 | } | |
40 |
|
40 | |||
41 |
onVisibleChanged: console.log("chart.onVisibleChanged: " + |
|
41 | onVisibleChanged: console.log("chart.onVisibleChanged: " + visible); | |
42 |
onTitleColorChanged: console.log("chart.onTitleColorChanged: " + |
|
42 | onTitleColorChanged: console.log("chart.onTitleColorChanged: " + color); | |
43 | onBackgroundColorChanged: console.log("chart.onBackgroundColorChanged: " + series.backgroundColor); |
|
43 | onBackgroundColorChanged: console.log("chart.onBackgroundColorChanged: " + series.backgroundColor); | |
44 | onDropShadowEnabledChanged: console.log("chart.onDropShadowEnabledChanged: " + enabled); |
|
44 | onDropShadowEnabledChanged: console.log("chart.onDropShadowEnabledChanged: " + enabled); | |
|
45 | onTopMarginChanged: { | |||
|
46 | console.log("chart.onTopMarginChanged: " + margin); | |||
|
47 | marginVisualizer.opacity = 1.0; | |||
|
48 | } | |||
|
49 | onBottomMarginChanged: { | |||
|
50 | console.log("chart.onBottomMarginChanged: " + margin); | |||
|
51 | marginVisualizer.opacity = 1.0; | |||
|
52 | } | |||
|
53 | onLeftMarginChanged: { | |||
|
54 | console.log("chart.onLeftMarginChanged: " + margin); | |||
|
55 | marginVisualizer.opacity = 1.0; | |||
|
56 | } | |||
|
57 | onRightMarginChanged: { | |||
|
58 | console.log("chart.onRightMarginChanged: " + margin); | |||
|
59 | marginVisualizer.opacity = 1.0; | |||
|
60 | } | |||
45 |
|
61 | |||
46 | legend.onVisibleChanged: console.log("legend.onVisibleChanged: " + series.legend.visible); |
|
62 | legend.onVisibleChanged: console.log("legend.onVisibleChanged: " + series.legend.visible); | |
47 | legend.onBackgroundVisibleChanged: console.log("legend.onBackgroundVisibleChanged: " + visible); |
|
63 | legend.onBackgroundVisibleChanged: console.log("legend.onBackgroundVisibleChanged: " + visible); | |
@@ -69,4 +85,21 ChartView { | |||||
69 | axisY.onShadesBorderColorChanged: console.log("axisY.onShadesBorderColorChanged: " + color); |
|
85 | axisY.onShadesBorderColorChanged: console.log("axisY.onShadesBorderColorChanged: " + color); | |
70 | axisY.onMinChanged: console.log("axisY.onMinChanged: " + min); |
|
86 | axisY.onMinChanged: console.log("axisY.onMinChanged: " + min); | |
71 | axisY.onMaxChanged: console.log("axisY.onMaxChanged: " + max); |
|
87 | axisY.onMaxChanged: console.log("axisY.onMaxChanged: " + max); | |
|
88 | ||||
|
89 | ||||
|
90 | Rectangle { | |||
|
91 | id: marginVisualizer | |||
|
92 | color: "transparent" | |||
|
93 | border.color: "red" | |||
|
94 | anchors.fill: parent | |||
|
95 | anchors.topMargin: parent.topMargin | |||
|
96 | anchors.bottomMargin: parent.bottomMargin | |||
|
97 | anchors.leftMargin: parent.leftMargin | |||
|
98 | anchors.rightMargin: parent.rightMargin | |||
|
99 | opacity: 0.0 | |||
|
100 | onOpacityChanged: if (opacity == 1.0) opacity = 0.0; | |||
|
101 | Behavior on opacity { | |||
|
102 | NumberAnimation { duration: 800 } | |||
|
103 | } | |||
|
104 | } | |||
72 | } |
|
105 | } |
General Comments 0
You need to be logged in to leave comments.
Login now