##// END OF EJS Templates
Add pressed, released and doubleClicked signals...
Add pressed, released and doubleClicked signals Added pressed, released and doubleClicked signals for all series. The signals are also added to QPieSlice and QBoxPlotSet. Change-Id: If94948be439a3b53ed48c02d0092091e836222a4 Task-number: QTRD-2384 Reviewed-by: Miikka Heikkinen <miikka.heikkinen@theqtcompany.com>

File last commit:

r2739:f78be8da2422
r2739:f78be8da2422
Show More
scatterchartitem.cpp
254 lines | 8.1 KiB | text/x-c | CppLexer
Jani Honkonen
Add license headers
r794 /****************************************************************************
Michal Klocek
Refactor xychartitem -> xychart
r1218 **
Titta Heikkala
Update copyright year...
r2688 ** Copyright (C) 2014 Digia Plc
Michal Klocek
Refactor xychartitem -> xychart
r1218 ** All rights reserved.
** For any questions to Digia, please use contact form at http://qt.digia.com
**
Miikka Heikkinen
Qt Commercial -> Qt Enterprise...
r2574 ** This file is part of the Qt Enterprise Charts Add-on.
Michal Klocek
Refactor xychartitem -> xychart
r1218 **
** $QT_BEGIN_LICENSE$
Miikka Heikkinen
Qt Commercial -> Qt Enterprise...
r2574 ** Licensees holding valid Qt Enterprise licenses may use this file in
** accordance with the Qt Enterprise License Agreement provided with the
Michal Klocek
Refactor xychartitem -> xychart
r1218 ** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Digia.
**
** If you have questions regarding the use of this file, please use
** contact form at http://qt.digia.com
** $QT_END_LICENSE$
**
****************************************************************************/
Jani Honkonen
Add license headers
r794
Titta Heikkala
Fix include syntax...
r2714 #include <private/scatterchartitem_p.h>
#include <QtCharts/QScatterSeries>
#include <private/qscatterseries_p.h>
#include <private/chartpresenter_p.h>
#include <private/abstractdomain_p.h>
#include <QtCharts/QChart>
#include <QtGui/QPainter>
#include <QtWidgets/QGraphicsScene>
#include <QtCore/QDebug>
#include <QtWidgets/QGraphicsSceneMouseEvent>
Michal Klocek
Refactor scatter chart to fit the other classes...
r470
Titta Heikkala
Qt Charts project file structure change...
r2712 QT_CHARTS_BEGIN_NAMESPACE
Michal Klocek
Refactor scatter chart to fit the other classes...
r470
Miikka Heikkinen
Add Polar chart support...
r2483 ScatterChartItem::ScatterChartItem(QScatterSeries *series, QGraphicsItem *item)
Michal Klocek
Refactors internals...
r2273 : XYChart(series,item),
Jani Honkonen
astyle and manual coding style fixes for src-folder
r2097 m_series(series),
m_items(this),
m_visible(true),
m_shape(QScatterSeries::MarkerShapeRectangle),
Titta Heikkala
Added possibility to show series value...
r2689 m_size(15),
m_pointLabelsVisible(false),
Titta Heikkala
Fix order of initialization...
r2695 m_pointLabelsFormat(series->pointLabelsFormat()),
Titta Heikkala
Added possibility to show series value...
r2689 m_pointLabelsFont(series->pointLabelsFont()),
Titta Heikkala
Add pressed, released and doubleClicked signals...
r2739 m_pointLabelsColor(series->pointLabelsColor()),
m_mousePressed(false)
Michal Klocek
Refactor scatter chart to fit the other classes...
r470 {
Jani Honkonen
astyle and manual coding style fixes for src-folder
r2097 QObject::connect(m_series->d_func(), SIGNAL(updated()), this, SLOT(handleUpdated()));
Tero Ahola
Added notifiers for scatter properties
r1349 QObject::connect(m_series, SIGNAL(visibleChanged()), this, SLOT(handleUpdated()));
Tero Ahola
Added opacity property to QAbstractSeries
r2067 QObject::connect(m_series, SIGNAL(opacityChanged()), this, SLOT(handleUpdated()));
Titta Heikkala
Added possibility to show series value...
r2689 QObject::connect(series, SIGNAL(pointLabelsFormatChanged(QString)),
this, SLOT(handleUpdated()));
QObject::connect(series, SIGNAL(pointLabelsVisibilityChanged(bool)),
this, SLOT(handleUpdated()));
QObject::connect(series, SIGNAL(pointLabelsFontChanged(QFont)), this, SLOT(handleUpdated()));
QObject::connect(series, SIGNAL(pointLabelsColorChanged(QColor)), this, SLOT(handleUpdated()));
Michal Klocek
Refactor scatter chart to fit the other classes...
r470
setZValue(ChartPresenter::ScatterSeriesZValue);
setFlags(QGraphicsItem::ItemClipsChildrenToShape);
Titta Heikkala
Add pressed, released and doubleClicked signals...
r2739 setFlag(QGraphicsItem::ItemIsSelectable);
Michal Klocek
Refactor scatter chart to fit the other classes...
r470
handleUpdated();
Michal Klocek
Adds missing scatter intercation implementation...
r541 m_items.setHandlesChildEvents(false);
Michal Klocek
Refactor scatter chart to fit the other classes...
r470 }
QRectF ScatterChartItem::boundingRect() const
{
return m_rect;
}
void ScatterChartItem::createPoints(int count)
{
for (int i = 0; i < count; ++i) {
Michal Klocek
Release compilation fixes
r689 QGraphicsItem *item = 0;
Michal Klocek
Refactor scatter chart to fit the other classes...
r470
switch (m_shape) {
Jani Honkonen
astyle and manual coding style fixes for src-folder
r2097 case QScatterSeries::MarkerShapeCircle: {
item = new CircleMarker(0, 0, m_size, m_size, this);
Jani Honkonen
more coding style fixes for src-folder...
r2104 const QRectF &rect = item->boundingRect();
Jani Honkonen
astyle and manual coding style fixes for src-folder
r2097 item->setPos(-rect.width() / 2, -rect.height() / 2);
break;
Jani Honkonen
src folder: another massive victory for coding style police
r2131 }
Jani Honkonen
more coding style fixes for src-folder...
r2104 case QScatterSeries::MarkerShapeRectangle:
Jani Honkonen
astyle and manual coding style fixes for src-folder
r2097 item = new RectangleMarker(0, 0, m_size, m_size, this);
item->setPos(-m_size / 2, -m_size / 2);
break;
default:
qWarning() << "Unsupported marker type";
Michal Klocek
Refactor xychartitem -> xychart
r1218 break;
Michal Klocek
Refactor scatter chart to fit the other classes...
r470 }
m_items.addToGroup(item);
}
}
void ScatterChartItem::deletePoints(int count)
{
QList<QGraphicsItem *> items = m_items.childItems();
for (int i = 0; i < count; ++i) {
Jani Honkonen
more coding style fixes for src-folder...
r2104 QGraphicsItem *item = items.takeLast();
Michal Klocek
Bugfixes for scatter series...
r1763 m_markerMap.remove(item);
delete(item);
Michal Klocek
Refactor scatter chart to fit the other classes...
r470 }
}
Michal Klocek
Bugfixes for scatter series...
r1763 void ScatterChartItem::markerSelected(QGraphicsItem *marker)
Michal Klocek
Refactor scatter chart to fit the other classes...
r470 {
Miikka Heikkinen
Add Polar chart support...
r2483 emit XYChart::clicked(m_markerMap[marker]);
Michal Klocek
Refactor scatter chart to fit the other classes...
r470 }
Marek Rosa
Added hovered support to scatter series
r2261 void ScatterChartItem::markerHovered(QGraphicsItem *marker, bool state)
{
Miikka Heikkinen
Add Polar chart support...
r2483 emit XYChart::hovered(m_markerMap[marker], state);
Marek Rosa
Added hovered support to scatter series
r2261 }
Titta Heikkala
Add pressed, released and doubleClicked signals...
r2739 void ScatterChartItem::markerPressed(QGraphicsItem *marker)
{
emit XYChart::pressed(m_markerMap[marker]);
}
void ScatterChartItem::markerReleased(QGraphicsItem *marker)
{
emit XYChart::released(m_markerMap[marker]);
}
void ScatterChartItem::markerDoubleClicked(QGraphicsItem *marker)
{
emit XYChart::doubleClicked(m_markerMap[marker]);
}
Michal Klocek
Refactors animation handling for xyseries
r1217 void ScatterChartItem::updateGeometry()
Michal Klocek
Refactor scatter chart to fit the other classes...
r470 {
Michal Klocek
Refactors animation handling for xyseries
r1217
const QVector<QPointF>& points = geometryPoints();
Jani Honkonen
astyle and manual coding style fixes for src-folder
r2097 if (points.size() == 0) {
Marek Rosa
XYSeries model support refactored
r1085 deletePoints(m_items.childItems().count());
Marek Rosa
Added support for adding and removing data with model. Updated the example
r545 return;
}
Michal Klocek
Refactor scatter chart to fit the other classes...
r470
Michal Klocek
Bugfixes for unnesery geometry changes
r869 int diff = m_items.childItems().size() - points.size();
Michal Klocek
Refactor scatter chart to fit the other classes...
r470
Jani Honkonen
astyle and manual coding style fixes for src-folder
r2097 if (diff > 0)
Michal Klocek
Refactor scatter chart to fit the other classes...
r470 deletePoints(diff);
Jani Honkonen
astyle and manual coding style fixes for src-folder
r2097 else if (diff < 0)
Michal Klocek
Refactor scatter chart to fit the other classes...
r470 createPoints(-diff);
Jani Honkonen
astyle and manual coding style fixes for src-folder
r2097 if (diff != 0)
handleUpdated();
Michal Klocek
Refactor scatter chart to fit the other classes...
r470
Jani Honkonen
more coding style fixes for src-folder...
r2104 QList<QGraphicsItem *> items = m_items.childItems();
Michal Klocek
Refactor scatter chart to fit the other classes...
r470
Michal Klocek
Refactors internals...
r2273 QRectF clipRect(QPointF(0,0),domain()->size());
Titta Heikkala
Fix zooming in crash...
r2603 // Only zoom in if the clipRect fits inside int limits. QWidget::update() uses
// a region that has to be compatible with QRect.
if (clipRect.height() <= INT_MAX
&& clipRect.width() <= INT_MAX) {
QVector<bool> offGridStatus = offGridStatusVector();
const int seriesLastIndex = m_series->count() - 1;
for (int i = 0; i < points.size(); i++) {
QGraphicsItem *item = items.at(i);
const QPointF &point = points.at(i);
const QRectF &rect = item->boundingRect();
// During remove animation series may have different number of points,
// so ensure we don't go over the index. Animation handling itself ensures that
// if there is actually no points in the series, then it won't generate a fake point,
// so we can be assured there is always at least one point in m_series here.
// Note that marker map values can be technically incorrect during the animation,
// if it was caused by an insert, but this shouldn't be a problem as the points are
// fake anyway. After remove animation stops, geometry is updated to correct one.
m_markerMap[item] = m_series->at(qMin(seriesLastIndex, i));
item->setPos(point.x() - rect.width() / 2, point.y() - rect.height() / 2);
if (!m_visible || offGridStatus.at(i))
item->setVisible(false);
else
item->setVisible(true);
}
Michal Klocek
Refactor scatter chart to fit the other classes...
r470
Titta Heikkala
Fix zooming in crash...
r2603 prepareGeometryChange();
m_rect = clipRect;
}
Michal Klocek
Refactor scatter chart to fit the other classes...
r470 }
void ScatterChartItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
{
Tero Ahola
Squashed bunch of warnings
r611 Q_UNUSED(option)
Q_UNUSED(widget)
Titta Heikkala
Added possibility to show series value...
r2689
QRectF clipRect = QRectF(QPointF(0, 0), domain()->size());
painter->save();
painter->setClipRect(clipRect);
Titta Heikkala
Fix point label position for QXYSeries...
r2696 if (m_pointLabelsVisible) {
m_series->d_func()->drawSeriesPointLabels(painter, m_points,
m_series->markerSize() / 2
+ m_series->pen().width());
}
Titta Heikkala
Added possibility to show series value...
r2689
painter->restore();
Michal Klocek
Refactor scatter chart to fit the other classes...
r470 }
Jani Honkonen
more coding style fixes for src-folder...
r2104 void ScatterChartItem::setPen(const QPen &pen)
Michal Klocek
Refactor scatter chart to fit the other classes...
r470 {
Jani Honkonen
astyle and manual coding style fixes for src-folder
r2097 foreach (QGraphicsItem *item , m_items.childItems())
Michal Klocek
Bugfixes for scatter series...
r1763 static_cast<QAbstractGraphicsShapeItem*>(item)->setPen(pen);
Michal Klocek
Refactor scatter chart to fit the other classes...
r470 }
Jani Honkonen
more coding style fixes for src-folder...
r2104 void ScatterChartItem::setBrush(const QBrush &brush)
Michal Klocek
Refactor scatter chart to fit the other classes...
r470 {
Jani Honkonen
astyle and manual coding style fixes for src-folder
r2097 foreach (QGraphicsItem *item , m_items.childItems())
Michal Klocek
Bugfixes for scatter series...
r1763 static_cast<QAbstractGraphicsShapeItem*>(item)->setBrush(brush);
Michal Klocek
Refactor scatter chart to fit the other classes...
r470 }
void ScatterChartItem::handleUpdated()
{
int count = m_items.childItems().count();
Jani Honkonen
astyle and manual coding style fixes for src-folder
r2097 if (count == 0)
return;
Michal Klocek
Refactor scatter chart to fit the other classes...
r470
Tero Ahola
Fixed isVisible implementation in XY series
r1346 bool recreate = m_visible != m_series->isVisible()
Jani Honkonen
astyle and manual coding style fixes for src-folder
r2097 || m_size != m_series->markerSize()
|| m_shape != m_series->markerShape();
Michal Klocek
Refactor scatter chart to fit the other classes...
r470
Tero Ahola
Fixed isVisible implementation in XY series
r1346 m_visible = m_series->isVisible();
Tero Ahola
Scatter customization to QML api
r1276 m_size = m_series->markerSize();
m_shape = m_series->markerShape();
Tero Ahola
Added opacity property to QAbstractSeries
r2067 setOpacity(m_series->opacity());
Titta Heikkala
Added possibility to show series value...
r2689 m_pointLabelsFormat = m_series->pointLabelsFormat();
m_pointLabelsVisible = m_series->pointLabelsVisible();
m_pointLabelsFont = m_series->pointLabelsFont();
m_pointLabelsColor = m_series->pointLabelsColor();
Michal Klocek
Refactor scatter chart to fit the other classes...
r470
Michal Klocek
Revert "TODOs removed from code. Undo me after release"...
r2407 if (recreate) {
Michal Klocek
Refactor scatter chart to fit the other classes...
r470 deletePoints(count);
createPoints(count);
Tero Ahola
Scatter customization to QML api
r1276
// Updating geometry is now safe, because it won't call handleUpdated unless it creates/deletes points
updateGeometry();
Michal Klocek
Refactor scatter chart to fit the other classes...
r470 }
setPen(m_series->pen());
setBrush(m_series->brush());
Tero Ahola
Fixed scatter not updating on setBrush/setPen
r1305 update();
Michal Klocek
Refactor scatter chart to fit the other classes...
r470 }
#include "moc_scatterchartitem_p.cpp"
Titta Heikkala
Qt Charts project file structure change...
r2712 QT_CHARTS_END_NAMESPACE