From 8f79fcf18e906bc8b3bc5dba74fde3fbc3c4e878 2012-02-21 08:54:31 From: sauimone Date: 2012-02-21 08:54:31 Subject: [PATCH] making bar as qobject causes crash for some reason. rewinding back a bit... --- diff --git a/src/barchart/bar.cpp b/src/barchart/bar.cpp index 855b85f..da6ce29 100644 --- a/src/barchart/bar.cpp +++ b/src/barchart/bar.cpp @@ -5,10 +5,17 @@ QTCOMMERCIALCHART_BEGIN_NAMESPACE Bar::Bar(QGraphicsItem *parent) - : QGraphicsObject(parent) + : ChartItem(parent) { } +void Bar::setSize(const QSizeF& size) +{ + mWidth = size.width(); + mHeight = size.height(); +} + + void Bar::resize( qreal w, qreal h ) { // qDebug() << "bar::resize" << w << h; @@ -16,6 +23,11 @@ void Bar::resize( qreal w, qreal h ) mHeight = h; } +void Bar::setColor( QColor col ) +{ + mColor = col; +} + void Bar::setPos(qreal x, qreal y) { // qDebug() << "Bar::setpos" << x << y; @@ -38,8 +50,10 @@ void Bar::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidg if (0 == mHeight) { return; } - + // TODO: accept brush instead of color painter->setBrush(mBrush); +// QBrush brush(mColor); +// painter->setBrush(brush); // This compensates for rounding errors. drawRect takes ints and cumulative error of pos + size may be over 1. int x0 = mXpos; @@ -57,21 +71,6 @@ QRectF Bar::boundingRect() const return r; } -void Bar::hoverEnterEvent(QGraphicsSceneHoverEvent* /*event*/) -{ - emit hoverEnter(); -} - -void Bar::hoverLeaveEvent(QGraphicsSceneHoverEvent* /*event*/) -{ - emit hoverLeave(); -} - -void Bar::mousePressEvent(QGraphicsSceneMouseEvent* /*event*/) -{ - emit clicked(); -} - -#include "moc_bar_p.cpp" +//#include "moc_bar_p.cpp" QTCOMMERCIALCHART_END_NAMESPACE diff --git a/src/barchart/bar_p.h b/src/barchart/bar_p.h index b7f69cb..013c01d 100644 --- a/src/barchart/bar_p.h +++ b/src/barchart/bar_p.h @@ -1,43 +1,35 @@ #ifndef BAR_H #define BAR_H -//#include "chartitem_p.h" +#include "chartitem_p.h" #include "qchartglobal.h" -#include +#include #include #include QTCOMMERCIALCHART_BEGIN_NAMESPACE // Single bar item of chart -class Bar : public QGraphicsObject +class Bar : public ChartItem { - Q_OBJECT - public: Bar(QGraphicsItem *parent=0); -public: +public: // from ChartItem + void setSize(const QSizeF &size); // Layout Stuff void resize(qreal w, qreal h); // Size of bar. void setPos(qreal x, qreal y); void setPen(QPen pen); void setBrush(QBrush brush); + void setColor( QColor col); // deprecated public: - // From QGraphicsItem + void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0); QRectF boundingRect() const; - void hoverEnterEvent(QGraphicsSceneHoverEvent *event); - void hoverLeaveEvent(QGraphicsSceneHoverEvent *event); - void mousePressEvent(QGraphicsSceneMouseEvent *event); - -Q_SIGNALS: - void clicked(); - void hoverEnter(); - void hoverLeave(); private: @@ -45,6 +37,7 @@ private: qreal mWidth; qreal mXpos; qreal mYpos; + QColor mColor; QBrush mBrush; QPen mPen; diff --git a/src/barchart/barpresenterbase.cpp b/src/barchart/barpresenterbase.cpp index bd4d107..6d8c36f 100644 --- a/src/barchart/barpresenterbase.cpp +++ b/src/barchart/barpresenterbase.cpp @@ -63,7 +63,7 @@ void BarPresenterBase::dataChanged() for (int c=0; c