summaryrefslogtreecommitdiffstats
path: root/src/charts/barchart
diff options
context:
space:
mode:
Diffstat (limited to 'src/charts/barchart')
-rw-r--r--src/charts/barchart/abstractbarchartitem.cpp9
-rw-r--r--src/charts/barchart/bar.cpp34
-rw-r--r--src/charts/barchart/bar_p.h10
-rw-r--r--src/charts/barchart/qabstractbarseries.cpp33
-rw-r--r--src/charts/barchart/qabstractbarseries.h3
-rw-r--r--src/charts/barchart/qabstractbarseries_p.h3
-rw-r--r--src/charts/barchart/qbarset.cpp21
-rw-r--r--src/charts/barchart/qbarset.h3
8 files changed, 113 insertions, 3 deletions
diff --git a/src/charts/barchart/abstractbarchartitem.cpp b/src/charts/barchart/abstractbarchartitem.cpp
index 1d32d9fa..c2f4c275 100644
--- a/src/charts/barchart/abstractbarchartitem.cpp
+++ b/src/charts/barchart/abstractbarchartitem.cpp
@@ -42,6 +42,7 @@ AbstractBarChartItem::AbstractBarChartItem(QAbstractBarSeries *series, QGraphics
{
setFlag(ItemClipsChildrenToShape);
+ setFlag(QGraphicsItem::ItemIsSelectable);
connect(series->d_func(), SIGNAL(updatedLayout()), this, SLOT(handleLayoutChanged()));
connect(series->d_func(), SIGNAL(updatedBars()), this, SLOT(handleUpdatedBars()));
connect(series->d_func(), SIGNAL(labelsVisibleChanged(bool)), this, SLOT(handleLabelsVisibleChanged(bool)));
@@ -163,8 +164,16 @@ void AbstractBarChartItem::handleDataStructureChanged()
m_bars.append(bar);
connect(bar, SIGNAL(clicked(int,QBarSet*)), m_series, SIGNAL(clicked(int,QBarSet*)));
connect(bar, SIGNAL(hovered(bool, int, QBarSet*)), m_series, SIGNAL(hovered(bool, int, QBarSet*)));
+ connect(bar, SIGNAL(pressed(int, QBarSet*)), m_series, SIGNAL(pressed(int, QBarSet*)));
+ connect(bar, SIGNAL(released(int, QBarSet*)),
+ m_series, SIGNAL(released(int, QBarSet*)));
+ connect(bar, SIGNAL(doubleClicked(int, QBarSet*)),
+ m_series, SIGNAL(doubleClicked(int, QBarSet*)));
connect(bar, SIGNAL(clicked(int,QBarSet*)), set, SIGNAL(clicked(int)));
connect(bar, SIGNAL(hovered(bool, int, QBarSet*)), set, SIGNAL(hovered(bool, int)));
+ connect(bar, SIGNAL(pressed(int, QBarSet*)), set, SIGNAL(pressed(int)));
+ connect(bar, SIGNAL(released(int, QBarSet*)), set, SIGNAL(released(int)));
+ connect(bar, SIGNAL(doubleClicked(int, QBarSet*)), set, SIGNAL(doubleClicked(int)));
// m_layout.append(QRectF(0, 0, 1, 1));
// Labels
diff --git a/src/charts/barchart/bar.cpp b/src/charts/barchart/bar.cpp
index 400fd58b..6338dbea 100644
--- a/src/charts/barchart/bar.cpp
+++ b/src/charts/barchart/bar.cpp
@@ -21,16 +21,20 @@
#include <private/bar_p.h>
#include <QtGui/QPainter>
#include <QtWidgets/QGraphicsSceneEvent>
+#include <QtWidgets/QStyleOptionGraphicsItem>
+#include <QtWidgets/QStyle>
QT_CHARTS_BEGIN_NAMESPACE
Bar::Bar(QBarSet *barset, int index, QGraphicsItem *parent) : QGraphicsRectItem(parent),
m_index(index),
m_barset(barset),
- m_hovering(false)
+ m_hovering(false),
+ m_mousePressed(false)
{
setAcceptedMouseButtons(Qt::LeftButton | Qt::RightButton);
setAcceptHoverEvents(true);
+ setFlag(QGraphicsItem::ItemIsSelectable);
}
Bar::~Bar()
@@ -42,8 +46,9 @@ Bar::~Bar()
void Bar::mousePressEvent(QGraphicsSceneMouseEvent *event)
{
- Q_UNUSED(event)
- emit clicked(m_index, m_barset);
+ emit pressed(m_index, m_barset);
+ m_lastMousePos = event->pos();
+ m_mousePressed = true;
QGraphicsItem::mousePressEvent(event);
}
@@ -62,6 +67,29 @@ void Bar::hoverLeaveEvent(QGraphicsSceneHoverEvent *event)
emit hovered(false, m_index, m_barset);
}
+void Bar::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
+{
+ emit released(m_index, m_barset);
+ if (m_lastMousePos == event->pos() && m_mousePressed)
+ emit clicked(m_index, m_barset);
+ m_mousePressed = false;
+ QGraphicsItem::mouseReleaseEvent(event);
+}
+
+void Bar::mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event)
+{
+ emit doubleClicked(m_index, m_barset);
+ QGraphicsItem::mouseDoubleClickEvent(event);
+}
+
+void Bar::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
+{
+ // Remove selection border around bar
+ QStyleOptionGraphicsItem barOption(*option);
+ barOption.state &= ~QStyle::State_Selected;
+ QGraphicsRectItem::paint(painter, &barOption, widget);
+}
+
#include "moc_bar_p.cpp"
QT_CHARTS_END_NAMESPACE
diff --git a/src/charts/barchart/bar_p.h b/src/charts/barchart/bar_p.h
index 4f8b010d..5f355b00 100644
--- a/src/charts/barchart/bar_p.h
+++ b/src/charts/barchart/bar_p.h
@@ -49,15 +49,25 @@ public:
void mousePressEvent(QGraphicsSceneMouseEvent *event);
void hoverEnterEvent(QGraphicsSceneHoverEvent *event);
void hoverLeaveEvent(QGraphicsSceneHoverEvent *event);
+ void mouseReleaseEvent(QGraphicsSceneMouseEvent *event);
+ void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event);
+
+ void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0);
Q_SIGNALS:
void clicked(int index, QBarSet *barset);
void hovered(bool status, int index, QBarSet *barset);
+ void pressed(int index, QBarSet *barset);
+ void released(int index, QBarSet *barset);
+ void doubleClicked(int index, QBarSet *barset);
private:
int m_index;
QBarSet *m_barset;
bool m_hovering;
+
+ QPointF m_lastMousePos;
+ bool m_mousePressed;
};
QT_CHARTS_END_NAMESPACE
diff --git a/src/charts/barchart/qabstractbarseries.cpp b/src/charts/barchart/qabstractbarseries.cpp
index e049ee53..7f785d28 100644
--- a/src/charts/barchart/qabstractbarseries.cpp
+++ b/src/charts/barchart/qabstractbarseries.cpp
@@ -211,6 +211,39 @@ QT_CHARTS_BEGIN_NAMESPACE
*/
/*!
+ \fn void QAbstractBarSeries::pressed(int index, QBarSet *barset)
+ The signal is emitted if the user presses with a mouse on top of QBarSet \a barset.
+ Pressed bar inside set is indexed by \a index
+*/
+/*!
+ \qmlsignal AbstractBarSeries::onPressed(int index, BarSet barset)
+ The signal is emitted if the user presses with a mouse on top of BarSet.
+ Pressed bar inside set is indexed by \a index
+*/
+
+/*!
+ \fn void QAbstractBarSeries::released(int index, QBarSet *barset)
+ The signal is emitted if the user releases with a mouse on top of QBarSet \a barset.
+ Released bar inside set is indexed by \a index
+*/
+/*!
+ \qmlsignal AbstractBarSeries::onReleased(int index, BarSet barset)
+ The signal is emitted if the user releases with a mouse on top of BarSet.
+ Released bar inside set is indexed by \a index
+*/
+
+/*!
+ \fn void QAbstractBarSeries::doubleClicked(int index, QBarSet *barset)
+ The signal is emitted if the user doubleclicks with a mouse on top of QBarSet \a barset.
+ DoubleClicked bar inside set is indexed by \a index
+*/
+/*!
+ \qmlsignal AbstractBarSeries::onDoubleClicked(int index, BarSet barset)
+ The signal is emitted if the user doubleclicks with a mouse on top of BarSet.
+ Doubleclicked bar inside set is indexed by \a index
+*/
+
+/*!
\fn void QAbstractBarSeries::hovered(bool status, int index, QBarSet* barset)
The signal is emitted if mouse is hovered on top of series.
diff --git a/src/charts/barchart/qabstractbarseries.h b/src/charts/barchart/qabstractbarseries.h
index 47a04476..9a92ec8f 100644
--- a/src/charts/barchart/qabstractbarseries.h
+++ b/src/charts/barchart/qabstractbarseries.h
@@ -78,6 +78,9 @@ protected:
Q_SIGNALS:
void clicked(int index, QBarSet *barset);
void hovered(bool status, int index, QBarSet *barset);
+ void pressed(int index, QBarSet *barset);
+ void released(int index, QBarSet *barset);
+ void doubleClicked(int index, QBarSet *barset);
void countChanged();
void labelsVisibleChanged();
void labelsFormatChanged(const QString &format);
diff --git a/src/charts/barchart/qabstractbarseries_p.h b/src/charts/barchart/qabstractbarseries_p.h
index c4ef1693..e3fb7697 100644
--- a/src/charts/barchart/qabstractbarseries_p.h
+++ b/src/charts/barchart/qabstractbarseries_p.h
@@ -89,6 +89,9 @@ public:
Q_SIGNALS:
void clicked(int index, QBarSet *barset);
+ void pressed(int index, QBarSet *barset);
+ void released(int index, QBarSet *barset);
+ void doubleClicked(int index, QBarSet *barset);
void updatedBars();
void updatedLayout();
void restructuredBars();
diff --git a/src/charts/barchart/qbarset.cpp b/src/charts/barchart/qbarset.cpp
index 0555b625..ba1fbf15 100644
--- a/src/charts/barchart/qbarset.cpp
+++ b/src/charts/barchart/qbarset.cpp
@@ -134,6 +134,27 @@ QT_CHARTS_BEGIN_NAMESPACE
*/
/*!
+ \fn void QBarSet::pressed(int index)
+
+ The signal is emitted if the user presses with a mouse on top of bar set.
+ Pressed bar inside set is indexed by \a index
+*/
+
+/*!
+ \fn void QBarSet::released(int index)
+
+ The signal is emitted if the user releases with a mouse on top of bar set.
+ Released bar inside set is indexed by \a index
+*/
+
+/*!
+ \fn void QBarSet::doubleClicked(int index)
+
+ The signal is emitted if the user doubleclicks with a mouse on top of bar set.
+ Doubleclicked bar inside set is indexed by \a index
+*/
+
+/*!
\fn void QBarSet::hovered(bool status, int index)
The signal is emitted if mouse is hovered on top of bar set.
diff --git a/src/charts/barchart/qbarset.h b/src/charts/barchart/qbarset.h
index 2faafbeb..8e1f307d 100644
--- a/src/charts/barchart/qbarset.h
+++ b/src/charts/barchart/qbarset.h
@@ -85,6 +85,9 @@ public:
Q_SIGNALS:
void clicked(int index);
void hovered(bool status, int index);
+ void pressed(int index);
+ void released(int index);
+ void doubleClicked(int index);
void penChanged();
void brushChanged();
void labelChanged();