#include <ReverseMapper.h>
Collaboration diagram for KDChart::ReverseMapper:
Definition at line 47 of file ReverseMapper.h.
Public Member Functions | |
void | addCircle (int row, int column, const QPointF &location, const QSizeF &diameter) |
void | addItem (ChartGraphicsItem *item) |
void | addLine (int row, int column, const QPointF &from, const QPointF &to) |
void | addPolygon (int row, int column, const QPolygonF &polygon) |
void | addRect (int row, int column, const QRectF &rect) |
void | clear () |
QModelIndexList | indexesAt (const QPointF &point) const |
QModelIndexList | indexesIn (const QRect &rect) const |
ReverseMapper (AbstractDiagram *diagram) | |
ReverseMapper () | |
void | setDiagram (AbstractDiagram *diagram) |
~ReverseMapper () |
ReverseMapper::ReverseMapper | ( | ) |
ReverseMapper::ReverseMapper | ( | AbstractDiagram * | diagram | ) | [explicit] |
ReverseMapper::~ReverseMapper | ( | ) |
void ReverseMapper::addCircle | ( | int | row, | |
int | column, | |||
const QPointF & | location, | |||
const QSizeF & | diameter | |||
) |
Definition at line 129 of file ReverseMapper.cpp.
References addPolygon().
00130 { 00131 QPainterPath path; 00132 QPointF ossfet( -0.5*diameter.width(), -0.5*diameter.height() ); 00133 path.addEllipse( QRectF( location + ossfet, diameter ) ); 00134 addPolygon( row, column, QPolygonF( path.toFillPolygon() ) ); 00135 }
void ReverseMapper::addItem | ( | ChartGraphicsItem * | item | ) |
void ReverseMapper::addLine | ( | int | row, | |
int | column, | |||
const QPointF & | from, | |||
const QPointF & | to | |||
) |
Definition at line 137 of file ReverseMapper.cpp.
References addPolygon().
00138 { 00139 // lines do not make good polygons to click on. we calculate a 2 00140 // pixel wide rectangle, where the original line is excatly 00141 // centered in. 00142 // make a 3 pixel wide polygon from the line: 00143 static const QPointF pixel( 1.0, 1.0 ); 00144 QPointF left, right; 00145 if ( from.x() < to.x() ) { 00146 left = from; 00147 right = to; 00148 } else { 00149 right = from; 00150 left = to; 00151 } 00152 const QPointF lineVector( right - left ); 00153 const qreal lineVectorLength = sqrt( lineVector.x() * lineVector.x() + lineVector.y() * lineVector.y() ); 00154 const QPointF lineVectorUnit( lineVector / lineVectorLength ); 00155 const QPointF normOfLineVectorUnit( -lineVectorUnit.y(), lineVectorUnit.x() ); 00156 // now the four polygon end points: 00157 const QPointF one( left - lineVectorUnit + normOfLineVectorUnit ); 00158 const QPointF two( left - lineVectorUnit - normOfLineVectorUnit ); 00159 const QPointF three( right + lineVectorUnit - normOfLineVectorUnit ); 00160 const QPointF four( right + lineVectorUnit + normOfLineVectorUnit ); 00161 addPolygon( row, column, QPolygonF() << one << two << three << four ); 00162 }
void ReverseMapper::addPolygon | ( | int | row, | |
int | column, | |||
const QPolygonF & | polygon | |||
) |
Definition at line 122 of file ReverseMapper.cpp.
References addItem().
Referenced by addCircle(), addLine(), and addRect().
00123 { 00124 ChartGraphicsItem* item = new ChartGraphicsItem( row, column ); 00125 item->setPolygon( polygon ); 00126 addItem( item ); 00127 }
void ReverseMapper::addRect | ( | int | row, | |
int | column, | |||
const QRectF & | rect | |||
) |
Definition at line 117 of file ReverseMapper.cpp.
References addPolygon().
00118 { 00119 addPolygon( row, column, QPolygonF( rect ) ); 00120 }
void ReverseMapper::clear | ( | ) |
QModelIndexList ReverseMapper::indexesAt | ( | const QPointF & | point | ) | const |
Definition at line 92 of file ReverseMapper.cpp.
References KDChart::ChartGraphicsItem::column(), and KDChart::ChartGraphicsItem::row().
00093 { 00094 Q_ASSERT( m_diagram ); 00095 if ( m_scene && m_scene->sceneRect().contains( point ) ) { 00096 QList<QGraphicsItem *> items = m_scene->items( point ); 00097 QModelIndexList indexes; 00098 Q_FOREACH( QGraphicsItem* item, items ) { 00099 ChartGraphicsItem* i = qgraphicsitem_cast<ChartGraphicsItem*>( item ); 00100 if ( i ) { 00101 QModelIndex index ( m_diagram->model()->index( i->row(), i->column() ) ); 00102 indexes << index; 00103 } 00104 } 00105 return indexes; 00106 } else { 00107 return QModelIndexList(); 00108 } 00109 }
QModelIndexList ReverseMapper::indexesIn | ( | const QRect & | rect | ) | const |
Definition at line 73 of file ReverseMapper.cpp.
References KDChart::ChartGraphicsItem::column(), and KDChart::ChartGraphicsItem::row().
00074 { 00075 Q_ASSERT( m_diagram ); 00076 if ( m_scene && m_scene->sceneRect().intersects( rect ) ) { 00077 QList<QGraphicsItem *> items = m_scene->items( rect ); 00078 QModelIndexList indexes; 00079 Q_FOREACH( QGraphicsItem* item, items ) { 00080 ChartGraphicsItem* i = qgraphicsitem_cast<ChartGraphicsItem*>( item ); 00081 if ( i ) { 00082 QModelIndex index ( m_diagram->model()->index( i->row(), i->column() ) ); 00083 indexes << index; 00084 } 00085 } 00086 return indexes; 00087 } else { 00088 return QModelIndexList(); 00089 } 00090 }
void ReverseMapper::setDiagram | ( | AbstractDiagram * | diagram | ) |