100403_show_residuals.diff
| src/plugins/georeferencer/qgsgcpcanvasitem.cpp (working copy) | ||
|---|---|---|
| 15 | 15 |
/* $Id$ */ |
| 16 | 16 | |
| 17 | 17 |
#include "qgsgcpcanvasitem.h" |
| 18 |
#include "qgsgeorefdatapoint.h" |
|
| 19 |
#include "qgsmaplayerregistry.h" |
|
| 20 |
#include "qgsmaprenderer.h" |
|
| 21 |
#include "qgsrasterlayer.h" |
|
| 18 | 22 | |
| 19 |
QgsGCPCanvasItem::QgsGCPCanvasItem( QgsMapCanvas* mapCanvas, const QgsPoint& rasterCoords, |
|
| 20 |
const QgsPoint& worldCoords, bool isGCPSource ) |
|
| 21 |
: QgsMapCanvasItem( mapCanvas ) |
|
| 23 |
QgsGCPCanvasItem::QgsGCPCanvasItem( QgsMapCanvas* mapCanvas, const QgsGeorefDataPoint* dataPoint, bool isGCPSource ) |
|
| 24 |
: QgsMapCanvasItem( mapCanvas ), mDataPoint( dataPoint ) |
|
| 22 | 25 |
, mPointBrush( Qt::red ) |
| 23 | 26 |
, mLabelBrush( Qt::yellow ) |
| 24 |
, mRasterCoords( rasterCoords ) |
|
| 25 |
, mWorldCoords( worldCoords ) |
|
| 26 |
, mId( -1 ) |
|
| 27 | 27 |
, mIsGCPSource( isGCPSource ) |
| 28 |
, mEnabled( true ) |
|
| 29 | 28 |
{
|
| 30 | 29 |
setFlags( QGraphicsItem::ItemIsMovable ); |
| 30 |
mResidualPen.setColor( QColor( 255, 0, 0 ) ); |
|
| 31 |
mResidualPen.setWidthF( 2.0 ); |
|
| 31 | 32 | |
| 32 | 33 |
updatePosition(); |
| 33 | 34 |
} |
| ... | ... | |
| 35 | 36 |
void QgsGCPCanvasItem::paint( QPainter* p ) |
| 36 | 37 |
{
|
| 37 | 38 |
p->setRenderHint( QPainter::Antialiasing ); |
| 38 |
p->setOpacity( mEnabled ? 1.0 : 0.3 ); |
|
| 39 | 39 | |
| 40 |
bool enabled = true; |
|
| 41 |
QgsPoint worldCoords; |
|
| 42 |
int id = -1; |
|
| 43 | ||
| 44 |
if ( mDataPoint ) |
|
| 45 |
{
|
|
| 46 |
enabled = mDataPoint->isEnabled(); |
|
| 47 |
worldCoords = mDataPoint->mapCoords(); |
|
| 48 |
id = mDataPoint->id(); |
|
| 49 |
} |
|
| 50 | ||
| 51 |
p->setOpacity( enabled ? 1.0 : 0.3 ); |
|
| 52 | ||
| 40 | 53 |
// draw the point |
| 41 | 54 |
p->setPen( Qt::black ); |
| 42 | 55 |
p->setBrush( mPointBrush ); |
| ... | ... | |
| 46 | 59 |
bool showIDs = s.value( "/Plugin-GeoReferencer/Config/ShowId" ).toBool(); |
| 47 | 60 |
if ( !showIDs && mIsGCPSource ) |
| 48 | 61 |
{
|
| 49 |
QString msg = QString( "X %1\nY %2" ).arg( QString::number( mWorldCoords.x(), 'f' ) ).
|
|
| 50 |
arg( QString::number( mWorldCoords.y(), 'f' ) );
|
|
| 62 |
QString msg = QString( "X %1\nY %2" ).arg( QString::number( worldCoords.x(), 'f' ) ).
|
|
| 63 |
arg( QString::number( worldCoords.y(), 'f' ) );
|
|
| 51 | 64 |
p->setFont( QFont( "helvetica", 9 ) ); |
| 52 | 65 |
QRect textBounds = p->boundingRect( 6, 6, 10, 10, Qt::AlignLeft, msg ); |
| 53 | 66 |
p->setBrush( mLabelBrush ); |
| ... | ... | |
| 58 | 71 |
else if ( showIDs ) |
| 59 | 72 |
{
|
| 60 | 73 |
p->setFont( QFont( "helvetica", 12 ) ); |
| 61 |
QString msg = QString::number( mId );
|
|
| 74 |
QString msg = QString::number( id );
|
|
| 62 | 75 |
p->setBrush( mLabelBrush ); |
| 63 | 76 |
p->drawRect( 5, 4, p->fontMetrics().width( msg ) + 2, 14 ); |
| 64 | 77 |
p->drawText( 6, 16, msg ); |
| 65 | 78 |
QFontMetrics fm = p->fontMetrics(); |
| 66 | 79 |
mTextBounds = QSize( fm.width( msg ) + 4, fm.height() + 4 ); |
| 67 | 80 |
} |
| 68 |
// else |
|
| 69 |
// mTextBounds = QSizeF(0, 0);
|
|
| 81 | ||
| 82 |
drawResidualArrow( p );
|
|
| 70 | 83 |
} |
| 71 | 84 | |
| 72 | 85 |
QRectF QgsGCPCanvasItem::boundingRect() const |
| 73 | 86 |
{
|
| 74 |
return QRectF( -2, -2, mTextBounds.width() + 6, mTextBounds.height() + 6 ); |
|
| 87 |
double residualLeft, residualRight, residualTop, residualBottom; |
|
| 88 | ||
| 89 |
QPointF residual; |
|
| 90 |
if ( mDataPoint ) |
|
| 91 |
{
|
|
| 92 |
residual = mDataPoint->residual(); |
|
| 93 |
} |
|
| 94 |
double rf = residualToScreenFactor(); |
|
| 95 | ||
| 96 |
if ( residual.x() > 0 ) |
|
| 97 |
{
|
|
| 98 |
residualRight = residual.x() * rf + mResidualPen.widthF(); |
|
| 99 |
residualLeft = -mResidualPen.widthF(); |
|
| 100 |
} |
|
| 101 |
else |
|
| 102 |
{
|
|
| 103 |
residualLeft = residual.x() * rf - mResidualPen.widthF(); |
|
| 104 |
residualRight = mResidualPen.widthF(); |
|
| 105 |
} |
|
| 106 |
if ( residual.y() > 0 ) |
|
| 107 |
{
|
|
| 108 |
residualBottom = residual.y() * rf + mResidualPen.widthF(); |
|
| 109 |
residualTop = -mResidualPen.widthF(); |
|
| 110 |
} |
|
| 111 |
else |
|
| 112 |
{
|
|
| 113 |
residualBottom = mResidualPen.widthF(); |
|
| 114 |
residualTop = residual.y() * rf - mResidualPen.widthF(); |
|
| 115 |
} |
|
| 116 | ||
| 117 |
QRectF residualArrowRect( QPointF( residualLeft, residualTop ), QPointF( residualRight, residualBottom ) ); |
|
| 118 |
QRectF markerRect( -2, -2, mTextBounds.width() + 6, mTextBounds.height() + 6 ); |
|
| 119 |
return residualArrowRect.united( markerRect ); |
|
| 75 | 120 |
} |
| 76 | 121 | |
| 77 | 122 |
QPainterPath QgsGCPCanvasItem::shape() const |
| ... | ... | |
| 83 | 128 |
return p; |
| 84 | 129 |
} |
| 85 | 130 | |
| 86 |
void QgsGCPCanvasItem::setEnabled( bool enabled )
|
|
| 131 |
void QgsGCPCanvasItem::updatePosition()
|
|
| 87 | 132 |
{
|
| 88 |
mEnabled = enabled; |
|
| 89 |
mPointBrush = enabled ? QBrush( Qt::red ) : QBrush( Qt::gray ); |
|
| 90 |
mLabelBrush = enabled ? QBrush( Qt::yellow ) : QBrush( Qt::gray ); |
|
| 91 |
update(); |
|
| 133 |
if ( !mDataPoint ) |
|
| 134 |
{
|
|
| 135 |
return; |
|
| 136 |
} |
|
| 137 | ||
| 138 |
setPos( toCanvasCoordinates( mIsGCPSource ? mDataPoint->pixelCoords() : mDataPoint->mapCoords() ) ); |
|
| 92 | 139 |
} |
| 93 | 140 | |
| 94 |
void QgsGCPCanvasItem::setRasterCoords( QgsPoint p )
|
|
| 141 |
void QgsGCPCanvasItem::drawResidualArrow( QPainter* p )
|
|
| 95 | 142 |
{
|
| 96 |
mRasterCoords = p; |
|
| 143 |
if ( !mDataPoint || !mIsGCPSource ) |
|
| 144 |
{
|
|
| 145 |
return; |
|
| 146 |
} |
|
| 147 | ||
| 148 |
QPointF residual = mDataPoint->residual(); |
|
| 149 | ||
| 150 |
double rf = residualToScreenFactor(); |
|
| 151 |
p->setPen( mResidualPen ); |
|
| 152 |
p->drawLine( QPointF( 0, 0 ), QPointF( residual.rx() * rf, residual.ry() * rf ) ); |
|
| 153 | ||
| 97 | 154 |
} |
| 98 | 155 | |
| 99 |
void QgsGCPCanvasItem::setWorldCoords( QgsPoint p ) |
|
| 156 |
double QgsGCPCanvasItem::residualToScreenFactor() const |
|
| 100 | 157 |
{
|
| 101 |
mWorldCoords = p; |
|
| 102 |
} |
|
| 158 |
if ( !mMapCanvas ) |
|
| 159 |
{
|
|
| 160 |
return 1; |
|
| 161 |
} |
|
| 103 | 162 | |
| 104 |
void QgsGCPCanvasItem::setId( int id ) |
|
| 105 |
{
|
|
| 106 |
mId = id; |
|
| 107 |
update(); |
|
| 163 |
double mapUnitsPerScreenPixel = mMapCanvas->mapUnitsPerPixel(); |
|
| 164 |
double mapUnitsPerRasterPixel = 1.0; |
|
| 165 | ||
| 166 |
if ( mMapCanvas->mapRenderer() ) |
|
| 167 |
{
|
|
| 168 |
QStringList canvasLayers = mMapCanvas->mapRenderer()->layerSet(); |
|
| 169 |
if ( canvasLayers.size() > 0 ) |
|
| 170 |
{
|
|
| 171 |
QString layerId = canvasLayers.at( 0 ); |
|
| 172 |
QgsMapLayer* mapLayer = QgsMapLayerRegistry::instance()->mapLayer( layerId ); |
|
| 173 |
if ( mapLayer ) |
|
| 174 |
{
|
|
| 175 |
QgsRasterLayer* rasterLayer = dynamic_cast<QgsRasterLayer*>( mapLayer ); |
|
| 176 |
if ( rasterLayer ) |
|
| 177 |
{
|
|
| 178 |
mapUnitsPerRasterPixel = rasterLayer->rasterUnitsPerPixel(); |
|
| 179 |
} |
|
| 180 |
} |
|
| 181 |
} |
|
| 182 |
} |
|
| 183 | ||
| 184 |
return 1.0 / ( mapUnitsPerScreenPixel * mapUnitsPerRasterPixel ); |
|
| 108 | 185 |
} |
| 109 | 186 | |
| 110 |
void QgsGCPCanvasItem::updatePosition()
|
|
| 187 |
void QgsGCPCanvasItem::checkBoundingRectChange()
|
|
| 111 | 188 |
{
|
| 112 |
setPos( toCanvasCoordinates( mIsGCPSource ? mRasterCoords : mWorldCoords ) );
|
|
| 189 |
prepareGeometryChange();
|
|
| 113 | 190 |
} |
| src/plugins/georeferencer/qgsgcpcanvasitem.h (working copy) | ||
|---|---|---|
| 20 | 20 |
#include "qgsmapcanvas.h" |
| 21 | 21 |
#include "qgsmapcanvasitem.h" |
| 22 | 22 | |
| 23 |
class QgsGeorefDataPoint; |
|
| 24 | ||
| 23 | 25 |
class QgsGCPCanvasItem : public QgsMapCanvasItem |
| 24 | 26 |
{
|
| 25 | 27 |
public: |
| 26 |
QgsGCPCanvasItem( QgsMapCanvas* mapCanvas, const QgsPoint& rasterCoords, |
|
| 27 |
const QgsPoint& worldCoords, bool isGCPSource/* = true*/ ); |
|
| 28 |
QgsGCPCanvasItem( QgsMapCanvas* mapCanvas, const QgsGeorefDataPoint* dataPoint, bool isGCPSource/* = true*/ ); |
|
| 28 | 29 | |
| 29 | 30 |
//! draws point information |
| 30 | 31 |
void paint( QPainter* p ); |
| ... | ... | |
| 34 | 35 | |
| 35 | 36 |
QPainterPath shape() const; |
| 36 | 37 | |
| 37 |
void setEnabled( bool enabled ); |
|
| 38 | ||
| 39 |
void setRasterCoords( QgsPoint p ); |
|
| 40 |
void setWorldCoords( QgsPoint p ); |
|
| 41 | ||
| 42 |
int id() { return mId; }
|
|
| 43 |
void setId( int id ); |
|
| 44 | ||
| 45 | 38 |
void updatePosition(); |
| 46 | 39 | |
| 40 |
/**Calls prepareGeometryChange()*/ |
|
| 41 |
void checkBoundingRectChange(); |
|
| 42 | ||
| 47 | 43 |
private: |
| 44 | ||
| 45 |
const QgsGeorefDataPoint* mDataPoint; |
|
| 48 | 46 |
QSizeF mTextBounds; |
| 49 | 47 |
QBrush mPointBrush; |
| 50 | 48 |
QBrush mLabelBrush; |
| 51 |
QgsPoint mRasterCoords; |
|
| 52 |
QgsPoint mWorldCoords; |
|
| 53 | ||
| 54 |
int mId; |
|
| 55 | 49 |
bool mIsGCPSource; |
| 56 |
bool mEnabled; |
|
| 50 |
QPen mResidualPen; |
|
| 51 | ||
| 52 |
void drawResidualArrow( QPainter* p ); |
|
| 53 |
/**Calculates scale factor for residual display*/ |
|
| 54 |
double residualToScreenFactor() const; |
|
| 57 | 55 |
}; |
| 58 | 56 | |
| 59 | 57 |
#endif // QGSGCPCANVASITEM_H |
| src/plugins/georeferencer/qgsgeorefdatapoint.h (working copy) | ||
|---|---|---|
| 39 | 39 |
bool isEnabled() const { return mEnabled; };
|
| 40 | 40 |
void setEnabled( bool enabled ); |
| 41 | 41 | |
| 42 |
int id() { return mId; }
|
|
| 42 |
int id() const { return mId; }
|
|
| 43 | 43 |
void setId( int id ); |
| 44 | 44 | |
| 45 | 45 |
bool contains( const QPoint &p ); |
| ... | ... | |
| 47 | 47 |
QgsMapCanvas *srcCanvas() const { return mSrcCanvas; }
|
| 48 | 48 |
QgsMapCanvas *dstCanvas() const { return mDstCanvas; }
|
| 49 | 49 | |
| 50 |
QPointF residual() const { return mResidual; }
|
|
| 51 |
void setResidual( const QPointF& r ); |
|
| 52 | ||
| 50 | 53 |
public slots: |
| 51 | 54 |
void moveTo( const QPoint & ); |
| 52 | 55 |
void updateCoords(); |
| ... | ... | |
| 61 | 64 | |
| 62 | 65 |
int mId; |
| 63 | 66 |
bool mEnabled; |
| 67 |
QPointF mResidual; |
|
| 64 | 68 |
}; |
| src/plugins/georeferencer/qgsgeorefdatapoint.cpp (working copy) | ||
|---|---|---|
| 30 | 30 |
, mId( -1 ) |
| 31 | 31 |
, mEnabled( enable ) |
| 32 | 32 |
{
|
| 33 |
mGCPSourceItem = new QgsGCPCanvasItem( srcCanvas, pixelCoords, mapCoords, true );
|
|
| 34 |
mGCPDestinationItem = new QgsGCPCanvasItem( dstCanvas, pixelCoords, mapCoords, false );
|
|
| 33 |
mGCPSourceItem = new QgsGCPCanvasItem( srcCanvas, this, true );
|
|
| 34 |
mGCPDestinationItem = new QgsGCPCanvasItem( dstCanvas, this, false );
|
|
| 35 | 35 | |
| 36 | 36 |
mGCPSourceItem->setEnabled( enable ); |
| 37 | 37 |
mGCPDestinationItem->setEnabled( enable ); |
| ... | ... | |
| 58 | 58 |
void QgsGeorefDataPoint::setPixelCoords( const QgsPoint &p ) |
| 59 | 59 |
{
|
| 60 | 60 |
mPixelCoords = p; |
| 61 |
mGCPSourceItem->setRasterCoords( p );
|
|
| 62 |
mGCPDestinationItem->setRasterCoords( p );
|
|
| 61 |
mGCPSourceItem->update();
|
|
| 62 |
mGCPDestinationItem->update();
|
|
| 63 | 63 |
} |
| 64 | 64 | |
| 65 | 65 |
void QgsGeorefDataPoint::setMapCoords( const QgsPoint &p ) |
| 66 | 66 |
{
|
| 67 | 67 |
mMapCoords = p; |
| 68 |
mGCPSourceItem->setWorldCoords( p ); |
|
| 69 |
mGCPDestinationItem->setWorldCoords( p ); |
|
| 68 |
if ( mGCPSourceItem ) |
|
| 69 |
{
|
|
| 70 |
mGCPSourceItem->update(); |
|
| 71 |
} |
|
| 72 |
if ( mGCPDestinationItem ) |
|
| 73 |
{
|
|
| 74 |
mGCPDestinationItem->update(); |
|
| 75 |
} |
|
| 70 | 76 |
} |
| 71 | 77 | |
| 72 | 78 |
void QgsGeorefDataPoint::setEnabled( bool enabled ) |
| 73 | 79 |
{
|
| 74 |
mGCPSourceItem->setEnabled( enabled ); |
|
| 75 | 80 |
mEnabled = enabled; |
| 81 |
if ( mGCPSourceItem ) |
|
| 82 |
{
|
|
| 83 |
mGCPSourceItem->update(); |
|
| 84 |
} |
|
| 76 | 85 |
} |
| 77 | 86 | |
| 78 | 87 |
void QgsGeorefDataPoint::setId( int id ) |
| 79 | 88 |
{
|
| 80 | 89 |
mId = id; |
| 81 |
mGCPSourceItem->setId( id ); |
|
| 82 |
mGCPDestinationItem->setId( id ); |
|
| 90 |
if ( mGCPSourceItem ) |
|
| 91 |
{
|
|
| 92 |
mGCPSourceItem->update(); |
|
| 93 |
} |
|
| 94 |
if ( mGCPDestinationItem ) |
|
| 95 |
{
|
|
| 96 |
mGCPDestinationItem->update(); |
|
| 97 |
} |
|
| 83 | 98 |
} |
| 84 | 99 | |
| 100 |
void QgsGeorefDataPoint::setResidual( const QPointF& r ) |
|
| 101 |
{
|
|
| 102 |
mResidual = r; |
|
| 103 |
if ( mGCPSourceItem ) |
|
| 104 |
{
|
|
| 105 |
mGCPSourceItem->checkBoundingRectChange(); |
|
| 106 |
} |
|
| 107 |
} |
|
| 108 | ||
| 85 | 109 |
void QgsGeorefDataPoint::updateCoords() |
| 86 | 110 |
{
|
| 87 |
mGCPSourceItem->updatePosition(); |
|
| 88 |
mGCPDestinationItem->updatePosition(); |
|
| 89 |
mGCPSourceItem->update(); |
|
| 90 |
mGCPDestinationItem->update(); |
|
| 111 |
if ( mGCPSourceItem ) |
|
| 112 |
{
|
|
| 113 |
mGCPSourceItem->updatePosition(); |
|
| 114 |
mGCPSourceItem->update(); |
|
| 115 |
} |
|
| 116 |
if ( mGCPDestinationItem ) |
|
| 117 |
{
|
|
| 118 |
mGCPDestinationItem->updatePosition(); |
|
| 119 |
mGCPDestinationItem->update(); |
|
| 120 |
} |
|
| 91 | 121 |
} |
| 92 | 122 | |
| 93 | 123 |
bool QgsGeorefDataPoint::contains( const QPoint &p ) |
| src/plugins/georeferencer/qgsgcplistmodel.cpp (working copy) | ||
|---|---|---|
| 143 | 143 |
{
|
| 144 | 144 |
dX = dY = residual = 0; |
| 145 | 145 |
} |
| 146 | ||
| 147 |
if ( p ) |
|
| 148 |
{
|
|
| 149 |
p->setResidual( QPointF( dX, dY ) ); |
|
| 150 |
} |
|
| 151 | ||
| 146 | 152 |
if ( residual >= 0.f ) |
| 147 | 153 |
{
|
| 148 | 154 |
setItem( i, j++, QGSSTANDARDITEM( dX ) /*create_item<double>(dX)*/ ); |