QML ChartView scrolling, zooming, drop shadow

This commit is contained in:
Tero Ahola 2012-06-14 14:56:11 +03:00
parent b1351cf29d
commit bf7c8a356b
3 changed files with 104 additions and 1 deletions

View File

@ -220,6 +220,71 @@ int DeclarativeChart::count()
return m_chart->series().count();
}
void DeclarativeChart::setDropShadowEnabled(bool enabled)
{
if (enabled != m_chart->isBackgroundDropShadowEnabled()) {
m_chart->setBackgroundDropShadowEnabled(enabled);
dropShadowEnabledChanged(enabled);
}
}
bool DeclarativeChart::dropShadowEnabled()
{
return m_chart->isBackgroundDropShadowEnabled();
}
void DeclarativeChart::zoom(qreal factor)
{
m_chart->zoom(factor);
}
void DeclarativeChart::scrollLeft(qreal pixels)
{
m_chart->scroll(QPointF(pixels, 0));
}
void DeclarativeChart::scrollRight(qreal pixels)
{
m_chart->scroll(QPointF(-pixels, 0));
}
void DeclarativeChart::scrollUp(qreal pixels)
{
m_chart->scroll(QPointF(0, pixels));
}
void DeclarativeChart::scrollDown(qreal pixels)
{
m_chart->scroll(QPointF(0, -pixels));
}
//void DeclarativeChart::scrollLeft(qreal ticks)
//{
// m_chart->scroll(QPointF(ticksToPixels(m_chart->axisX(), ticks), 0));
//}
//void DeclarativeChart::scrollRight(qreal ticks)
//{
// m_chart->scroll(QPointF(-ticksToPixels(m_chart->axisX(), ticks), 0));
//}
//void DeclarativeChart::scrollUp(qreal ticks)
//{
// m_chart->scroll(QPointF(0, ticksToPixels(m_chart->axisY(), ticks)));
//}
//void DeclarativeChart::scrollDown(qreal ticks)
//{
// m_chart->scroll(QPointF(0, -ticksToPixels(m_chart->axisY(), ticks)));
//}
//qreal DeclarativeChart::ticksToPixels(QAxis *axis, qreal ticks)
//{
// qreal tickCount = axis->max() - axis->min();
// qreal tickPixels = (m_chart->size().width() - m_chart->margins().width() * 2) / tickCount;
// return tickPixels * ticks;
//}
QAbstractSeries *DeclarativeChart::series(int index)
{
if (index < m_chart->series().count()) {

View File

@ -37,14 +37,15 @@ class DeclarativeChart : public QDeclarativeItem
Q_PROPERTY(Theme theme READ theme WRITE setTheme NOTIFY themeChanged)
Q_PROPERTY(Animation animationOptions READ animationOptions WRITE setAnimationOptions NOTIFY animationOptionsChanged)
Q_PROPERTY(QString title READ title WRITE setTitle NOTIFY titleChanged)
Q_PROPERTY(QColor titleColor READ titleColor WRITE setTitleColor NOTIFY titleColorChanged)
Q_PROPERTY(QAxis *axisX READ axisX)
Q_PROPERTY(QAxis *axisY READ axisY)
Q_PROPERTY(QLegend *legend READ legend)
// TODO: how to define axis labels? This is not very convenient
Q_PROPERTY(QVariantList axisXLabels READ axisXLabels WRITE setAxisXLabels NOTIFY axisLabelsChanged)
Q_PROPERTY(int count READ count)
Q_PROPERTY(QColor titleColor READ titleColor WRITE setTitleColor NOTIFY titleColorChanged)
Q_PROPERTY(QColor backgroundColor READ backgroundColor WRITE setBackgroundColor NOTIFY backgroundColorChanged)
Q_PROPERTY(bool dropShadowEnabled READ dropShadowEnabled WRITE setDropShadowEnabled NOTIFY dropShadowEnabledChanged)
Q_ENUMS(Animation)
Q_ENUMS(Theme)
Q_ENUMS(SeriesType)
@ -107,6 +108,13 @@ public:
void setBackgroundColor(QColor color);
QColor backgroundColor();
int count();
void setDropShadowEnabled(bool enabled);
bool dropShadowEnabled();
Q_INVOKABLE void zoom(qreal factor);
Q_INVOKABLE void scrollLeft(qreal pixels);
Q_INVOKABLE void scrollRight(qreal pixels);
Q_INVOKABLE void scrollUp(qreal pixels);
Q_INVOKABLE void scrollDown(qreal pixels);
Q_INVOKABLE QAbstractSeries *series(int index);
Q_INVOKABLE QAbstractSeries *series(QString seriesName);
Q_INVOKABLE QAbstractSeries *createSeries(DeclarativeChart::SeriesType type, QString name = "");
@ -118,6 +126,7 @@ Q_SIGNALS:
void axisLabelsChanged();
void titleColorChanged();
void backgroundColorChanged();
void dropShadowEnabledChanged(bool enabled);
public:
// Extending QChart with DeclarativeChart is not possible because QObject does not support

View File

@ -43,6 +43,7 @@ Flow {
onAnimationOptionsChanged: console.log("chart.onAnimationOptionsChanged: " + series.animationOptions);
onTitleColorChanged: console.log("chart.onTitleColorChanged: " + series.titleColor);
onBackgroundColorChanged: console.log("chart.onBackgroundColorChanged: " + series.backgroundColor);
onDropShadowEnabledChanged: console.log("chart.onDropShadowEnabledChanged: " + enabled);
}
Connections {
@ -115,6 +116,34 @@ Flow {
text: "background color"
onClicked: series.backgroundColor = main.nextColor();
}
Button {
text: "drop shadow enabled"
onClicked: series.dropShadowEnabled = !series.dropShadowEnabled;
}
Button {
text: "zoom +"
onClicked: series.zoom(2);
}
Button {
text: "zoom -"
onClicked: series.zoom(0.5);
}
Button {
text: "scroll left"
onClicked: series.scrollLeft(10);
}
Button {
text: "scroll right"
onClicked: series.scrollRight(10);
}
Button {
text: "scroll up"
onClicked: series.scrollUp(10);
}
Button {
text: "scroll down"
onClicked: series.scrollDown(10);
}
Button {
text: "legend visible"
onClicked: series.legend.visible = !series.legend.visible;