@@ -139,7 +139,6 void MainWidget::showLegendSpinbox() | |||
|
139 | 139 | { |
|
140 | 140 | m_legendSettings->setVisible(true); |
|
141 | 141 | QRectF chartViewRect = m_chartView->rect(); |
|
142 | QRectF legendRect = m_chart->legend()->boundingRect(); | |
|
143 | 142 | |
|
144 | 143 | m_legendPosX->setMinimum(0); |
|
145 | 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 | 134 | \qmlmethod AbstractSeries ChartView::series(int index) |
|
111 | 135 | Returns the series with \a index on the chart. This allows you to loop through the series of a chart together with |
|
112 | 136 | the count property of the chart. |
@@ -167,6 +191,22 DeclarativeChart::DeclarativeChart(QDeclarativeItem *parent) | |||
|
167 | 191 | { |
|
168 | 192 | setFlag(QGraphicsItem::ItemHasNoContents, false); |
|
169 | 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 | 212 | DeclarativeChart::~DeclarativeChart() |
@@ -302,7 +342,7 void DeclarativeChart::setTitleColor(QColor color) | |||
|
302 | 342 | if (color != b.color()) { |
|
303 | 343 | b.setColor(color); |
|
304 | 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 | 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 | 418 | void DeclarativeChart::zoom(qreal factor) |
|
359 | 419 | { |
|
360 | 420 | m_chart->zoom(factor); |
@@ -47,6 +47,10 class DeclarativeChart : public QDeclarativeItem | |||
|
47 | 47 | Q_PROPERTY(int count READ count) |
|
48 | 48 | Q_PROPERTY(QColor backgroundColor READ backgroundColor WRITE setBackgroundColor NOTIFY backgroundColorChanged) |
|
49 | 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 | 54 | Q_ENUMS(Animation) |
|
51 | 55 | Q_ENUMS(Theme) |
|
52 | 56 | Q_ENUMS(SeriesType) |
@@ -112,6 +116,10 public: | |||
|
112 | 116 | int count(); |
|
113 | 117 | void setDropShadowEnabled(bool enabled); |
|
114 | 118 | bool dropShadowEnabled(); |
|
119 | qreal topMargin(); | |
|
120 | qreal bottomMargin(); | |
|
121 | qreal leftMargin(); | |
|
122 | qreal rightMargin(); | |
|
115 | 123 | |
|
116 | 124 | public: |
|
117 | 125 | Q_INVOKABLE QAbstractSeries *series(int index); |
@@ -126,14 +134,22 public: | |||
|
126 | 134 | |
|
127 | 135 | Q_SIGNALS: |
|
128 | 136 | void axisLabelsChanged(); |
|
129 | void titleColorChanged(); | |
|
137 | void titleColorChanged(QColor color); | |
|
130 | 138 | void backgroundColorChanged(); |
|
131 | 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 | 149 | // Extending QChart with DeclarativeChart is not possible because QObject does not support |
|
135 | 150 | // multi inheritance, so we now have a QChart as a member instead |
|
136 | 151 | QChart *m_chart; |
|
152 | QRectF m_chartMargins; | |
|
137 | 153 | }; |
|
138 | 154 | |
|
139 | 155 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -300,6 +300,8 void ChartPresenter::updateLayout() | |||
|
300 | 300 | { |
|
301 | 301 | if (!m_rect.isValid()) return; |
|
302 | 302 | |
|
303 | QRectF oldChargMargins = m_chartMargins; | |
|
304 | ||
|
303 | 305 | // recalculate title size |
|
304 | 306 | |
|
305 | 307 | QSize titleSize; |
@@ -389,6 +391,8 void ChartPresenter::updateLayout() | |||
|
389 | 391 | emit geometryChanged(m_chartRect); |
|
390 | 392 | } |
|
391 | 393 | |
|
394 | if (oldChargMargins != m_chartMargins) | |
|
395 | emit marginsChanged(m_chartMargins); | |
|
392 | 396 | } |
|
393 | 397 | |
|
394 | 398 | void ChartPresenter::createChartBackgroundItem() |
@@ -122,6 +122,7 private Q_SLOTS: | |||
|
122 | 122 | Q_SIGNALS: |
|
123 | 123 | void geometryChanged(const QRectF& rect); |
|
124 | 124 | void animationsFinished(); |
|
125 | void marginsChanged(QRectF margins); | |
|
125 | 126 | |
|
126 | 127 | private: |
|
127 | 128 | QChart* m_chart; |
@@ -76,6 +76,7 QChart::QChart(QGraphicsItem *parent, Qt::WindowFlags wFlags) : QGraphicsWidget( | |||
|
76 | 76 | d_ptr->createConnections(); |
|
77 | 77 | d_ptr->m_legend = new LegendScroller(this); |
|
78 | 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 | 37 | class QTCOMMERCIALCHART_EXPORT QChart : public QGraphicsWidget |
|
38 | 38 | { |
|
39 | 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 | 46 | Q_ENUMS(ChartTheme) |
|
41 | 47 | Q_ENUMS(AnimationOption) |
|
42 | 48 | |
@@ -107,6 +113,9 public: | |||
|
107 | 113 | QLegend* legend() const; |
|
108 | 114 | QRectF margins() const; |
|
109 | 115 | |
|
116 | Q_SIGNALS: | |
|
117 | void marginsChanged(QRectF newMargins); | |
|
118 | ||
|
110 | 119 | protected: |
|
111 | 120 | void resizeEvent(QGraphicsSceneResizeEvent *event); |
|
112 | 121 |
@@ -38,10 +38,26 ChartView { | |||
|
38 | 38 | XyPoint { x: 4.1; y: 3.3 } |
|
39 | 39 | } |
|
40 | 40 | |
|
41 |
onVisibleChanged: console.log("chart.onVisibleChanged: " + |
|
|
42 |
onTitleColorChanged: console.log("chart.onTitleColorChanged: " + |
|
|
41 | onVisibleChanged: console.log("chart.onVisibleChanged: " + visible); | |
|
42 | onTitleColorChanged: console.log("chart.onTitleColorChanged: " + color); | |
|
43 | 43 | onBackgroundColorChanged: console.log("chart.onBackgroundColorChanged: " + series.backgroundColor); |
|
44 | 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 | 62 | legend.onVisibleChanged: console.log("legend.onVisibleChanged: " + series.legend.visible); |
|
47 | 63 | legend.onBackgroundVisibleChanged: console.log("legend.onBackgroundVisibleChanged: " + visible); |
@@ -69,4 +85,21 ChartView { | |||
|
69 | 85 | axisY.onShadesBorderColorChanged: console.log("axisY.onShadesBorderColorChanged: " + color); |
|
70 | 86 | axisY.onMinChanged: console.log("axisY.onMinChanged: " + min); |
|
71 | 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