##// END OF EJS Templates
Added ChartView.minimumMargins to QML properties
Tero Ahola -
r1928:6a089ea6fc66
parent child
Show More
@@ -0,0 +1,111
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 #include "declarativemargins.h"
22 #include <QDataStream>
23 #include <QDebug>
24
25 QTCOMMERCIALCHART_BEGIN_NAMESPACE
26
27 /*!
28 \qmlclass Margins
29 Uncreatable type that is used to define top, bottom, left and right margins.
30 */
31
32 /*!
33 \qmlproperty int Margins::top
34 The top margin.
35 */
36
37 /*!
38 \qmlproperty int Margins::bottom
39 The bottom margin.
40 */
41
42 /*!
43 \qmlproperty int Margins::left
44 The left margin.
45 */
46
47 /*!
48 \qmlproperty int Margins::right
49 The right margin.
50 */
51
52 DeclarativeMargins::DeclarativeMargins(QObject *parent) :
53 QObject(parent)
54 {
55 QMargins::setTop(0);
56 QMargins::setBottom(0);
57 QMargins::setLeft(0);
58 QMargins::setRight(0);
59 }
60
61 void DeclarativeMargins::setTop(int top)
62 {
63 if (top < 0) {
64 qWarning() << "Cannot set top margin to a negative value:" << top;
65 } else {
66 if (top != QMargins::top()) {
67 QMargins::setTop(top);
68 emit topChanged(QMargins::top(), QMargins::bottom(), QMargins::left(), QMargins::right());
69 }
70 }
71 }
72
73 void DeclarativeMargins::setBottom(int bottom)
74 {
75 if (bottom < 0) {
76 qWarning() << "Cannot set bottom margin to a negative value:" << bottom;
77 } else {
78 if (bottom != QMargins::bottom()) {
79 QMargins::setBottom(bottom);
80 emit bottomChanged(QMargins::top(), QMargins::bottom(), QMargins::left(), QMargins::right());
81 }
82 }
83 }
84
85 void DeclarativeMargins::setLeft(int left)
86 {
87 if (left < 0) {
88 qWarning() << "Cannot set left margin to a negative value:" << left;
89 } else {
90 if (left != QMargins::left()) {
91 QMargins::setLeft(left);
92 emit leftChanged(QMargins::top(), QMargins::bottom(), QMargins::left(), QMargins::right());
93 }
94 }
95 }
96
97 void DeclarativeMargins::setRight(int right)
98 {
99 if (right < 0) {
100 qWarning() << "Cannot set left margin to a negative value:" << right;
101 } else {
102 if (right != QMargins::right()) {
103 QMargins::setRight(right);
104 emit rightChanged(QMargins::top(), QMargins::bottom(), QMargins::left(), QMargins::right());
105 }
106 }
107 }
108
109 #include "moc_declarativemargins.cpp"
110
111 QTCOMMERCIALCHART_END_NAMESPACE
@@ -0,0 +1,54
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 #ifndef DECLARATIVE_MARGINS_H
22 #define DECLARATIVE_MARGINS_H
23
24 #include "qchartglobal.h"
25 #include <QObject>
26 #include <QMargins>
27
28 QTCOMMERCIALCHART_BEGIN_NAMESPACE
29
30 class DeclarativeMargins : public QObject, public QMargins
31 {
32 Q_OBJECT
33 Q_PROPERTY(int top READ top WRITE setTop NOTIFY topChanged)
34 Q_PROPERTY(int bottom READ bottom WRITE setBottom NOTIFY bottomChanged)
35 Q_PROPERTY(int left READ left WRITE setLeft NOTIFY leftChanged)
36 Q_PROPERTY(int right READ right WRITE setRight NOTIFY rightChanged)
37
38 public:
39 explicit DeclarativeMargins(QObject *parent = 0);
40 void setTop(int top);
41 void setBottom(int bottom);
42 void setLeft(int left);
43 void setRight(int right);
44
45 Q_SIGNALS:
46 void topChanged(int top, int bottom, int left, int right);
47 void bottomChanged(int top, int bottom, int left, int right);
48 void leftChanged(int top, int bottom, int left, int right);
49 void rightChanged(int top, int bottom, int left, int right);
50 };
51
52 QTCOMMERCIALCHART_END_NAMESPACE
53
54 #endif // DECLARATIVE_MARGINS_H
@@ -168,13 +168,14 Rectangle {
168 }
168 }
169 }
169 }
170
170
171 }
171 VPieModelMapper {
172 VPieModelMapper {
172 model: customModel
173 model: customModel
174 series: pieSeries
173 labelsColumn: 1
175 labelsColumn: 1
174 valuesColumn: 2
176 valuesColumn: 2
175 firstRow: 1
177 firstRow: 1
176 }
178 }
177 }
178 //![3]
179 //![3]
179 }
180 }
180 }
181 }
@@ -22,7 +22,8 SOURCES += \
22 declarativescatterseries.cpp \
22 declarativescatterseries.cpp \
23 declarativepieseries.cpp \
23 declarativepieseries.cpp \
24 declarativebarseries.cpp \
24 declarativebarseries.cpp \
25 declarativecategoryaxis.cpp
25 declarativecategoryaxis.cpp \
26 declarativemargins.cpp
26
27
27 HEADERS += \
28 HEADERS += \
28 declarativechart.h \
29 declarativechart.h \
@@ -34,7 +35,8 HEADERS += \
34 declarativescatterseries.h \
35 declarativescatterseries.h \
35 declarativepieseries.h \
36 declarativepieseries.h \
36 declarativebarseries.h \
37 declarativebarseries.h \
37 declarativecategoryaxis.h
38 declarativecategoryaxis.h \
39 declarativemargins.h
38
40
39 TARGETPATH = QtCommercial/Chart
41 TARGETPATH = QtCommercial/Chart
40 target.path = $$[QT_INSTALL_IMPORTS]/$$TARGETPATH
42 target.path = $$[QT_INSTALL_IMPORTS]/$$TARGETPATH
@@ -31,6 +31,7
31 #include "qvalueaxis.h"
31 #include "qvalueaxis.h"
32 #include "qcategoryaxis.h"
32 #include "qcategoryaxis.h"
33 #include "qabstractseries_p.h"
33 #include "qabstractseries_p.h"
34 #include "declarativemargins.h"
34
35
35 #ifndef QT_ON_ARM
36 #ifndef QT_ON_ARM
36 #include "qdatetimeaxis.h"
37 #include "qdatetimeaxis.h"
@@ -117,26 +118,27 QTCOMMERCIALCHART_BEGIN_NAMESPACE
117
118
118 /*!
119 /*!
119 \qmlproperty real ChartView::topMargin
120 \qmlproperty real ChartView::topMargin
120 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
121 Deprecated. Use minimumMargins and plotArea instead.
121 area of the chart view. Top margin area is also used by legend, if aligned to top.
122 */
122 */
123
123
124 /*!
124 /*!
125 \qmlproperty real ChartView::bottomMargin
125 \qmlproperty real ChartView::bottomMargin
126 The space between the bottom of chart view and the bottom of the plot area. The bottom margin area may be used by
126 Deprecated. Use minimumMargins and plotArea instead.
127 legend (if aligned to bottom), x-axis, x-axis labels and x-axis tick marks.
128 */
127 */
129
128
130 /*!
129 /*!
131 \qmlproperty real ChartView::leftMargin
130 \qmlproperty real ChartView::leftMargin
132 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
131 Deprecated. Use minimumMargins and plotArea instead.
133 legend (if aligned to left), y-axis, y-axis labels and y-axis tick marks.
134 */
132 */
135
133
136 /*!
134 /*!
137 \qmlproperty real ChartView::rightMargin
135 \qmlproperty real ChartView::rightMargin
138 The space between the right side of chart view and the right side of the plot area. The right margin area may be used
136 Deprecated. Use minimumMargins and plotArea instead.
139 by legend (if aligned to right).
137 */
138
139 /*!
140 \qmlproperty Margins ChartView::minimumMargins
141 The minimum margins allowed between the outer bounds and the plotArea of the ChartView.
140 */
142 */
141
143
142 /*!
144 /*!
@@ -223,24 +225,17 DeclarativeChart::DeclarativeChart(QDeclarativeItem *parent)
223 m_chart(new QChart(this))
225 m_chart(new QChart(this))
224 {
226 {
225 setFlag(QGraphicsItem::ItemHasNoContents, false);
227 setFlag(QGraphicsItem::ItemHasNoContents, false);
226 //TODO: check what should be really here margins or platArea ?!
228 m_minMargins = new DeclarativeMargins(this);
227 m_chartMargins = m_chart->minimumMargins();
229 connect(m_minMargins, SIGNAL(topChanged(int, int, int, int)), this, SLOT(changeMinimumMargins(int, int, int, int)));
228 connect(m_chart, SIGNAL(marginsChanged(QRectF)), this, SLOT(handleMarginsChanged(QRectF)));
230 connect(m_minMargins, SIGNAL(bottomChanged(int, int, int, int)), this, SLOT(changeMinimumMargins(int, int, int, int)));
231 connect(m_minMargins, SIGNAL(leftChanged(int, int, int, int)), this, SLOT(changeMinimumMargins(int, int, int, int)));
232 connect(m_minMargins, SIGNAL(rightChanged(int, int, int, int)), this, SLOT(changeMinimumMargins(int, int, int, int)));
233 // TODO: connect to plotAreaChanged signal from m_chart
229 }
234 }
230
235
231 void DeclarativeChart::handleMarginsChanged(QRectF newMargins)
236 void DeclarativeChart::changeMinimumMargins(int top, int bottom, int left, int right)
232 {
237 {
233 //TODO: check what should be really here margins or platArea ?!
238 m_chart->setMinimumMargins(QMargins(left, top, right, bottom));
234 if (m_chartMargins.top() != newMargins.top())
235 topMarginChanged(m_chart->minimumMargins().top());
236 if (m_chartMargins.bottom() != newMargins.bottom())
237 bottomMarginChanged(m_chart->minimumMargins().bottom());
238 if (m_chartMargins.left() != newMargins.left())
239 leftMarginChanged(m_chart->minimumMargins().left());
240 if (m_chartMargins.right() != newMargins.right())
241 rightMarginChanged(m_chart->minimumMargins().right());
242
243 m_chartMargins = m_chart->minimumMargins();
244 }
239 }
245
240
246 DeclarativeChart::~DeclarativeChart()
241 DeclarativeChart::~DeclarativeChart()
@@ -482,22 +477,26 bool DeclarativeChart::dropShadowEnabled()
482
477
483 qreal DeclarativeChart::topMargin()
478 qreal DeclarativeChart::topMargin()
484 {
479 {
485 return m_chart->minimumMargins().top();
480 qWarning() << "ChartView.topMargin is deprecated. Use minimumMargins and plotArea instead.";
481 return m_chart->plotArea().top();
486 }
482 }
487
483
488 qreal DeclarativeChart::bottomMargin()
484 qreal DeclarativeChart::bottomMargin()
489 {
485 {
490 return m_chart->minimumMargins().bottom();
486 qWarning() << "ChartView.bottomMargin is deprecated. Use minimumMargins and plotArea instead.";
487 return m_chart->plotArea().bottom();
491 }
488 }
492
489
493 qreal DeclarativeChart::leftMargin()
490 qreal DeclarativeChart::leftMargin()
494 {
491 {
495 return m_chart->minimumMargins().left();
492 qWarning() << "ChartView.leftMargin is deprecated. Use minimumMargins and plotArea instead.";
493 return m_chart->plotArea().left();
496 }
494 }
497
495
498 qreal DeclarativeChart::rightMargin()
496 qreal DeclarativeChart::rightMargin()
499 {
497 {
500 return m_chart->minimumMargins().right();
498 qWarning() << "ChartView.rightMargin is deprecated. Use minimumMargins and plotArea instead.";
499 return m_chart->plotArea().right();
501 }
500 }
502
501
503 void DeclarativeChart::zoom(qreal factor)
502 void DeclarativeChart::zoom(qreal factor)
@@ -27,6 +27,8
27
27
28 QTCOMMERCIALCHART_BEGIN_NAMESPACE
28 QTCOMMERCIALCHART_BEGIN_NAMESPACE
29
29
30 class DeclarativeMargins;
31
30 class DeclarativeChart : public QDeclarativeItem
32 class DeclarativeChart : public QDeclarativeItem
31 {
33 {
32 Q_OBJECT
34 Q_OBJECT
@@ -43,6 +45,7 class DeclarativeChart : public QDeclarativeItem
43 Q_PROPERTY(qreal bottomMargin READ bottomMargin NOTIFY bottomMarginChanged)
45 Q_PROPERTY(qreal bottomMargin READ bottomMargin NOTIFY bottomMarginChanged)
44 Q_PROPERTY(qreal leftMargin READ leftMargin NOTIFY leftMarginChanged)
46 Q_PROPERTY(qreal leftMargin READ leftMargin NOTIFY leftMarginChanged)
45 Q_PROPERTY(qreal rightMargin READ rightMargin NOTIFY rightMarginChanged)
47 Q_PROPERTY(qreal rightMargin READ rightMargin NOTIFY rightMarginChanged)
48 Q_PROPERTY(DeclarativeMargins *minimumMargins READ minimumMargins REVISION 1)
46 Q_ENUMS(Animation)
49 Q_ENUMS(Animation)
47 Q_ENUMS(Theme)
50 Q_ENUMS(Theme)
48 Q_ENUMS(SeriesType)
51 Q_ENUMS(SeriesType)
@@ -111,6 +114,7 public:
111 qreal leftMargin();
114 qreal leftMargin();
112 qreal rightMargin();
115 qreal rightMargin();
113 void createDefaultAxes(QAbstractSeries* series);
116 void createDefaultAxes(QAbstractSeries* series);
117 DeclarativeMargins *minimumMargins() { return m_minMargins; }
114
118
115 public:
119 public:
116 Q_INVOKABLE QAbstractSeries *series(int index);
120 Q_INVOKABLE QAbstractSeries *series(int index);
@@ -139,7 +143,8 Q_SIGNALS:
139 void rightMarginChanged(qreal margin);
143 void rightMarginChanged(qreal margin);
140
144
141 public Q_SLOTS:
145 public Q_SLOTS:
142 void handleMarginsChanged(QRectF newMargins);
146 // void handleMarginsChanged(QRectF newMargins);
147 void changeMinimumMargins(int top, int bottom, int left, int right);
143 void handleAxisXSet(QAbstractAxis *axis);
148 void handleAxisXSet(QAbstractAxis *axis);
144 void handleAxisYSet(QAbstractAxis *axis);
149 void handleAxisYSet(QAbstractAxis *axis);
145
150
@@ -147,7 +152,8 private:
147 // Extending QChart with DeclarativeChart is not possible because QObject does not support
152 // Extending QChart with DeclarativeChart is not possible because QObject does not support
148 // multi inheritance, so we now have a QChart as a member instead
153 // multi inheritance, so we now have a QChart as a member instead
149 QChart *m_chart;
154 QChart *m_chart;
150 QMargins m_chartMargins;
155 //QMargins m_chartMargins;
156 DeclarativeMargins *m_minMargins;
151 };
157 };
152
158
153 QTCOMMERCIALCHART_END_NAMESPACE
159 QTCOMMERCIALCHART_END_NAMESPACE
@@ -40,6 +40,7
40 #include "qvpiemodelmapper.h"
40 #include "qvpiemodelmapper.h"
41 #include "qhbarmodelmapper.h"
41 #include "qhbarmodelmapper.h"
42 #include "qvbarmodelmapper.h"
42 #include "qvbarmodelmapper.h"
43 #include "declarativemargins.h"
43 #include <QAbstractItemModel>
44 #include <QAbstractItemModel>
44
45
45 QTCOMMERCIALCHART_BEGIN_NAMESPACE
46 QTCOMMERCIALCHART_BEGIN_NAMESPACE
@@ -97,7 +98,7 public:
97 QLatin1String("Trying to create uncreatable: QPieSeries. Use PieSeries instead."));
98 QLatin1String("Trying to create uncreatable: QPieSeries. Use PieSeries instead."));
98
99
99 // QtCommercial.Chart 1.1
100 // QtCommercial.Chart 1.1
100 qmlRegisterType<DeclarativeChart>(uri, 1, 1, "ChartView");
101 qmlRegisterType<DeclarativeChart, 1>(uri, 1, 1, "ChartView");
101 qmlRegisterType<DeclarativeXYPoint>(uri, 1, 1, "XYPoint");
102 qmlRegisterType<DeclarativeXYPoint>(uri, 1, 1, "XYPoint");
102 qmlRegisterType<DeclarativeScatterSeries, 1>(uri, 1, 1, "ScatterSeries");
103 qmlRegisterType<DeclarativeScatterSeries, 1>(uri, 1, 1, "ScatterSeries");
103 qmlRegisterType<DeclarativeLineSeries, 1>(uri, 1, 1, "LineSeries");
104 qmlRegisterType<DeclarativeLineSeries, 1>(uri, 1, 1, "LineSeries");
@@ -145,6 +146,8 public:
145 QLatin1String("Trying to create uncreatable: BarsetBase."));
146 QLatin1String("Trying to create uncreatable: BarsetBase."));
146 qmlRegisterUncreatableType<QPieSeries>(uri, 1, 1, "QPieSeries",
147 qmlRegisterUncreatableType<QPieSeries>(uri, 1, 1, "QPieSeries",
147 QLatin1String("Trying to create uncreatable: QPieSeries. Use PieSeries instead."));
148 QLatin1String("Trying to create uncreatable: QPieSeries. Use PieSeries instead."));
149 qmlRegisterUncreatableType<DeclarativeMargins>(uri, 1, 1, "Margins",
150 QLatin1String("Trying to create uncreatable: Margins."));
148 }
151 }
149 };
152 };
150
153
@@ -64,7 +64,10 ChartView {
64 legend.onColorChanged: console.log("legend.onColorChanged: " + color);
64 legend.onColorChanged: console.log("legend.onColorChanged: " + color);
65 legend.onBorderColorChanged: console.log("legend.onBorderColorChanged: " + color);
65 legend.onBorderColorChanged: console.log("legend.onBorderColorChanged: " + color);
66 legend.onLabelColorChanged: console.log("legend.onLabelColorChanged: " + color);
66 legend.onLabelColorChanged: console.log("legend.onLabelColorChanged: " + color);
67
67 minimumMargins.onTopChanged: console.log("chart.minimumMargins.onTopChanged: " + top);
68 minimumMargins.onBottomChanged: console.log("chart.minimumMargins.onBottomChanged: " + bottom);
69 minimumMargins.onLeftChanged: console.log("chart.minimumMargins.onLeftChanged: " + left);
70 minimumMargins.onRightChanged: console.log("chart.minimumMargins.onRightChanged: " + right);
68
71
69 ValueAxis{
72 ValueAxis{
70 onColorChanged: console.log("axisX.onColorChanged: " + color);
73 onColorChanged: console.log("axisX.onColorChanged: " + color);
@@ -84,6 +84,42 Row {
84 text: "title color"
84 text: "title color"
85 onClicked: chart.titleColor = main.nextColor();
85 onClicked: chart.titleColor = main.nextColor();
86 }
86 }
87 Button {
88 text: "zoom -"
89 onClicked: chart.zoom(0.5);
90 }
91 Button {
92 text: "top min margin +"
93 onClicked: chart.minimumMargins.top += 5;
94 }
95 Button {
96 text: "top min margin -"
97 onClicked: chart.minimumMargins.top -= 5;
98 }
99 Button {
100 text: "bottom min margin +"
101 onClicked: chart.minimumMargins.bottom += 5;
102 }
103 Button {
104 text: "bottom min margin -"
105 onClicked: chart.minimumMargins.bottom -= 5;
106 }
107 Button {
108 text: "left min margin +"
109 onClicked: chart.minimumMargins.left += 5;
110 }
111 Button {
112 text: "left min margin -"
113 onClicked: chart.minimumMargins.left -= 5;
114 }
115 Button {
116 text: "right min margin +"
117 onClicked: chart.minimumMargins.right += 5;
118 }
119 Button {
120 text: "right min margin -"
121 onClicked: chart.minimumMargins.right -= 5;
122 }
87 }
123 }
88
124
89 FontEditor {
125 FontEditor {
General Comments 0
You need to be logged in to leave comments. Login now