#include <ReverseMapper.h>
Definition at line 49 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) |
QRectF | boundingRect (int row, int column) const |
void | clear () |
QModelIndexList | indexesAt (const QPointF &point) const |
QModelIndexList | indexesIn (const QRect &rect) const |
QPolygonF | polygon (int row, int column) 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 144 of file ReverseMapper.cpp.
References addPolygon().
Referenced by addLine().
00145 { 00146 QPainterPath path; 00147 QPointF ossfet( -0.5*diameter.width(), -0.5*diameter.height() ); 00148 path.addEllipse( QRectF( location + ossfet, diameter ) ); 00149 addPolygon( row, column, QPolygonF( path.toFillPolygon() ) ); 00150 }
void ReverseMapper::addItem | ( | ChartGraphicsItem * | item | ) |
Definition at line 125 of file ReverseMapper.cpp.
References KDChart::ChartGraphicsItem::column(), and KDChart::ChartGraphicsItem::row().
Referenced by addPolygon().
00126 { 00127 Q_ASSERT( m_scene ); 00128 m_scene->addItem( item ); 00129 m_itemMap.insert( m_diagram->model()->index( item->row(), item->column(), m_diagram->rootIndex() ), item ); 00130 }
void ReverseMapper::addLine | ( | int | row, | |
int | column, | |||
const QPointF & | from, | |||
const QPointF & | to | |||
) |
Definition at line 152 of file ReverseMapper.cpp.
References addCircle(), and addPolygon().
00153 { 00154 // that's no line, dude... make a small circle around that point, instead 00155 if( from == to ) 00156 { 00157 addCircle( row, column, from, QSizeF( 1.5, 1.5 ) ); 00158 return; 00159 } 00160 // lines do not make good polygons to click on. we calculate a 2 00161 // pixel wide rectangle, where the original line is excatly 00162 // centered in. 00163 // make a 3 pixel wide polygon from the line: 00164 static const QPointF pixel( 1.0, 1.0 ); 00165 QPointF left, right; 00166 if ( from.x() < to.x() ) { 00167 left = from; 00168 right = to; 00169 } else { 00170 right = from; 00171 left = to; 00172 } 00173 const QPointF lineVector( right - left ); 00174 const qreal lineVectorLength = sqrt( lineVector.x() * lineVector.x() + lineVector.y() * lineVector.y() ); 00175 const QPointF lineVectorUnit( lineVector / lineVectorLength ); 00176 const QPointF normOfLineVectorUnit( -lineVectorUnit.y(), lineVectorUnit.x() ); 00177 // now the four polygon end points: 00178 const QPointF one( left - lineVectorUnit + normOfLineVectorUnit ); 00179 const QPointF two( left - lineVectorUnit - normOfLineVectorUnit ); 00180 const QPointF three( right + lineVectorUnit - normOfLineVectorUnit ); 00181 const QPointF four( right + lineVectorUnit + normOfLineVectorUnit ); 00182 addPolygon( row, column, QPolygonF() << one << two << three << four ); 00183 }
void ReverseMapper::addPolygon | ( | int | row, | |
int | column, | |||
const QPolygonF & | polygon | |||
) |
Definition at line 137 of file ReverseMapper.cpp.
References addItem().
Referenced by addCircle(), addLine(), and addRect().
00138 { 00139 ChartGraphicsItem* item = new ChartGraphicsItem( row, column ); 00140 item->setPolygon( polygon ); 00141 addItem( item ); 00142 }
void ReverseMapper::addRect | ( | int | row, | |
int | column, | |||
const QRectF & | rect | |||
) |
Definition at line 132 of file ReverseMapper.cpp.
References addPolygon().
00133 { 00134 addPolygon( row, column, QPolygonF( rect ) ); 00135 }
QRectF ReverseMapper::boundingRect | ( | int | row, | |
int | column | |||
) | const |
Definition at line 119 of file ReverseMapper.cpp.
00120 { 00121 const QModelIndex index = m_diagram->model()->index( row, column, m_diagram->rootIndex() ); 00122 return m_itemMap.contains( index ) ? m_itemMap[ index ]->polygon().boundingRect() : QRectF(); 00123 }
void ReverseMapper::clear | ( | ) |
Definition at line 68 of file ReverseMapper.cpp.
00069 { 00070 delete m_scene; 00071 m_scene = new QGraphicsScene(); 00072 }
QModelIndexList ReverseMapper::indexesAt | ( | const QPointF & | point | ) | const |
Definition at line 93 of file ReverseMapper.cpp.
References KDChart::ChartGraphicsItem::column(), and KDChart::ChartGraphicsItem::row().
00094 { 00095 Q_ASSERT( m_diagram ); 00096 if ( m_scene && m_scene->sceneRect().contains( point ) ) { 00097 QList<QGraphicsItem *> items = m_scene->items( point ); 00098 QModelIndexList indexes; 00099 Q_FOREACH( QGraphicsItem* item, items ) { 00100 ChartGraphicsItem* i = qgraphicsitem_cast<ChartGraphicsItem*>( item ); 00101 if ( i ) { 00102 QModelIndex index ( m_diagram->model()->index( i->row(), i->column(), m_diagram->rootIndex() ) ); 00103 if( !indexes.contains(index) ) 00104 indexes << index; 00105 } 00106 } 00107 return indexes; 00108 } else { 00109 return QModelIndexList(); 00110 } 00111 }
QModelIndexList ReverseMapper::indexesIn | ( | const QRect & | rect | ) | const |
Definition at line 74 of file ReverseMapper.cpp.
References KDChart::ChartGraphicsItem::column(), and KDChart::ChartGraphicsItem::row().
00075 { 00076 Q_ASSERT( m_diagram ); 00077 if ( m_scene && m_scene->sceneRect().intersects( rect ) ) { 00078 QList<QGraphicsItem *> items = m_scene->items( rect ); 00079 QModelIndexList indexes; 00080 Q_FOREACH( QGraphicsItem* item, items ) { 00081 ChartGraphicsItem* i = qgraphicsitem_cast<ChartGraphicsItem*>( item ); 00082 if ( i ) { 00083 QModelIndex index ( m_diagram->model()->index( i->row(), i->column(), m_diagram->rootIndex() ) ); 00084 indexes << index; 00085 } 00086 } 00087 return indexes; 00088 } else { 00089 return QModelIndexList(); 00090 } 00091 }
QPolygonF ReverseMapper::polygon | ( | int | row, | |
int | column | |||
) | const |
Definition at line 113 of file ReverseMapper.cpp.
00114 { 00115 const QModelIndex index = m_diagram->model()->index( row, column, m_diagram->rootIndex() ); 00116 return m_itemMap.contains( index ) ? m_itemMap[ index ]->polygon() : QPolygon(); 00117 }
void ReverseMapper::setDiagram | ( | AbstractDiagram * | diagram | ) |