##// END OF EJS Templates
integrating bar charts to test app.. crashes for now
integrating bar charts to test app.. crashes for now

File last commit:

r145:251cad7c49ee
r164:8e580b305fe6
Show More
axisitem.cpp
176 lines | 4.2 KiB | text/x-c | CppLexer
Michal Klocek
Add zoom support...
r67 #include "axisitem_p.h"
Michal Klocek
Adds refactored axis to presenter
r140 #include "qchartaxis.h"
Michal Klocek
Add zoom support...
r67 #include <QPainter>
#include <QDebug>
Michal Klocek
Refactora axis and line chart to use graphics items insted of painter.
r85 #define LABEL_PADDING 5
Michal Klocek
Add zoom support...
r67 QTCOMMERCIALCHART_BEGIN_NAMESPACE
Michal Klocek
Adds refactored axis to presenter
r140 AxisItem::AxisItem(QChartAxis* axis,AxisType type,QGraphicsItem* parent) :
Tero Ahola
Refactoring continued: restored ChartItem class
r104 ChartItem(parent),
Michal Klocek
Adds refactored axis to presenter
r140 m_axis(axis),
Tero Ahola
Refactored themes; now enabled for line, scatter and pies...
r103 m_ticks(4),
m_type(type)
Michal Klocek
Add zoom support...
r67 {
Michal Klocek
Fix previous broken commit
r145 //initial initialization
handleAxisChanged();
Michal Klocek
Add zoom support...
r67 }
AxisItem::~AxisItem()
{
}
QRectF AxisItem::boundingRect() const
{
return m_rect;
}
Tero Ahola
Refactored themes; now enabled for line, scatter and pies...
r103
Michal Klocek
Refactora axis and line chart to use graphics items insted of painter.
r85 /*
Michal Klocek
Add zoom support...
r67 void AxisItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option,QWidget *widget)
{
if (!m_rect.isValid())
Michal Klocek
Refactora axis and line chart to use graphics items insted of painter.
r85 return;
Michal Klocek
Add zoom support...
r67
if(m_type==X_AXIS) {
Michal Klocek
Refactora axis and line chart to use graphics items insted of painter.
r85 const qreal deltaX = m_rect.width() / m_ticks;
for (int i = 0; i <= m_ticks; ++i) {
int x = i * deltaX + m_rect.left();
Michal Klocek
Add zoom support...
r67
Michal Klocek
Refactora axis and line chart to use graphics items insted of painter.
r85 if(i==0) x--;
if(i==m_ticks) x++;
Michal Klocek
Add zoom support...
r67
Michal Klocek
Refactora axis and line chart to use graphics items insted of painter.
r85 qreal label = m_plotDomain.m_minX + (i * m_plotDomain.spanX()
/ m_ticks);
painter->drawLine(x, m_rect.top()-1, x, m_rect.bottom()+1);
// painter->drawLine(x, m_rect.bottom()-1, x, m_rect.bottom()-1 + 5);
Michal Klocek
Add zoom support...
r67
Michal Klocek
Refactora axis and line chart to use graphics items insted of painter.
r85 painter->drawText(x - 50, m_rect.bottom() + 5, 100, 20,Qt::AlignHCenter | Qt::AlignTop, QString::number(label));
}
Michal Klocek
Add zoom support...
r67 }
if(m_type==Y_AXIS) {
Michal Klocek
Refactora axis and line chart to use graphics items insted of painter.
r85 const qreal deltaY = (m_rect.height()) / m_ticks;
Michal Klocek
Add zoom support...
r67
Michal Klocek
Refactora axis and line chart to use graphics items insted of painter.
r85 for (int j = 0; j <= m_ticks; ++j) {
Michal Klocek
Add zoom support...
r67
Michal Klocek
Refactora axis and line chart to use graphics items insted of painter.
r85 int y = j * -deltaY + m_rect.bottom();
Michal Klocek
Add zoom support...
r67
Michal Klocek
Refactora axis and line chart to use graphics items insted of painter.
r85 if(j==0) y++;
if(j==m_ticks) y--;
qreal label = m_plotDomain.m_minY + (j * m_plotDomain.spanY()
/ m_ticks);
painter->drawLine(m_rect.left()-1, y, m_rect.right()+1, y);
//painter->drawLine(m_rect.left() - 5, y, m_rect.left(), y);
//TODO : margin = 50 ;
painter->drawText(m_rect.left() - 50, y - 10, 50 - 5, 20,
Qt::AlignRight | Qt::AlignVCenter,
QString::number(label));
}
Michal Klocek
Add zoom support...
r67 }
//painter->drawRect(m_rect.adjusted(0, 0, -1, -1));
Michal Klocek
Refactora axis and line chart to use graphics items insted of painter.
r85 }
*/
void AxisItem::createItems()
{
Michal Klocek
Adds refactored axis to presenter
r140 if(!m_rect.isValid()) return;
Michal Klocek
Refactora axis and line chart to use graphics items insted of painter.
r85
Michal Klocek
Fix previous broken commit
r145 switch (m_type)
{
case X_AXIS:
{
const qreal deltaX = m_rect.width() / m_ticks;
Michal Klocek
Refactora axis and line chart to use graphics items insted of painter.
r85
Michal Klocek
Fix previous broken commit
r145 for (int i = 0; i <= m_ticks; ++i) {
Michal Klocek
Refactora axis and line chart to use graphics items insted of painter.
r85
Michal Klocek
Fix previous broken commit
r145 int x = i * deltaX + m_rect.left();
Michal Klocek
Refactora axis and line chart to use graphics items insted of painter.
r85
Michal Klocek
Fix previous broken commit
r145 qreal label = m_domain.m_minX + (i * m_domain.spanX()/ m_ticks);
Michal Klocek
Refactora axis and line chart to use graphics items insted of painter.
r85
Michal Klocek
Fix previous broken commit
r145 m_grid<<new QGraphicsLineItem(x, m_rect.top(), x, m_rect.bottom(),this);
Michal Klocek
Refactora axis and line chart to use graphics items insted of painter.
r85
Michal Klocek
Fix previous broken commit
r145 QGraphicsSimpleTextItem* text = new QGraphicsSimpleTextItem(QString::number(label),this);
QPointF center = text->boundingRect().center();
text->setPos(x - center.x(), m_rect.bottom() + LABEL_PADDING);
//text->rotate(-45);
m_labels<<text;
}
}
break;
Michal Klocek
Refactora axis and line chart to use graphics items insted of painter.
r85
Michal Klocek
Fix previous broken commit
r145 case Y_AXIS:
{
const qreal deltaY = m_rect.height()/ m_ticks;
Michal Klocek
Refactora axis and line chart to use graphics items insted of painter.
r85
Michal Klocek
Fix previous broken commit
r145 for (int j = 0; j <= m_ticks; ++j) {
Michal Klocek
Refactora axis and line chart to use graphics items insted of painter.
r85
Michal Klocek
Fix previous broken commit
r145 int y = j * -deltaY + m_rect.bottom();
Michal Klocek
Refactora axis and line chart to use graphics items insted of painter.
r85
Michal Klocek
Fix previous broken commit
r145 qreal label = m_domain.m_minY + (j * m_domain.spanY()
/ m_ticks);
Michal Klocek
Refactora axis and line chart to use graphics items insted of painter.
r85
Michal Klocek
Fix previous broken commit
r145 m_grid<<new QGraphicsLineItem(m_rect.left() , y, m_rect.right(), y,this);
QGraphicsSimpleTextItem* text = new QGraphicsSimpleTextItem(QString::number(label),this);
QPointF center = text->boundingRect().center();
text->setPos(m_rect.left() - text->boundingRect().width() - LABEL_PADDING , y-center.y());
Michal Klocek
Refactora axis and line chart to use graphics items insted of painter.
r85
Michal Klocek
Fix previous broken commit
r145 m_labels<<text;
Michal Klocek
Add zoom support...
r67
Michal Klocek
Fix previous broken commit
r145 }
}
break;
default:
qDebug()<<"Unknown axis type";
break;
}
Michal Klocek
Add zoom support...
r67 }
Michal Klocek
Adds refactored axis to presenter
r140 void AxisItem::clear()
{
qDeleteAll(m_shades);
m_shades.clear();
qDeleteAll(m_grid);
m_grid.clear();
qDeleteAll(m_labels);
m_labels.clear();
}
void AxisItem::updateDomain()
{
clear();
createItems();
}
void AxisItem::handleAxisChanged()
{
//m_axis->
}
void AxisItem::handleDomainChanged(const Domain& domain)
{
m_domain = domain;
clear();
createItems();
}
void AxisItem::handleGeometryChanged(const QRectF& rect)
{
Q_ASSERT(rect.isValid());
m_rect = rect;
clear();
createItems();
}
Michal Klocek
Add zoom support...
r67 //TODO "nice numbers algorithm"
Michal Klocek
Adds refactored axis to presenter
r140 #include "moc_axisitem_p.cpp"
Michal Klocek
Add zoom support...
r67
QTCOMMERCIALCHART_END_NAMESPACE