Tuesday, June 15, 2010

Get certified with classes today

Train to be in Med Imaging
To stop further mailing, visit here or write:
PinpointMediaServices, 4255 E. Charleston Blvd. Suite D-345, Las Vegas, NV 89104
I probably should've posted this a while ago, but I didn't get around to it. There is a bug in the CommonTokenStream.getTokens() function in the Python target version 3.1.2 (it looks like there is a 3.2 version in the bug database, but 3.1.2 is the released python runtime and it shouldn't affect the bug anyways). The array reference that selects which tokens to return uses this: self.tokens[start:stop] which drops the last token. My guess is that in normal cases, this is overlooked because the last token is EOF, and if you're calling getTokens() after the fact, EOF has already served its primary purpose and terminated the lexer. A cursory look at the java code makes me think that it won't have this problem, but I have not test it. A port of the included reproducer could answer that. The workaround is to use the tokens list inside the CommonTokenStream class directly instead of getTokens(). On a side note, there is also a bug (sort of) in the code given on the wiki page for emitting multiple tokens ( ). The method proposed builds up an array of tokens and then emits them one by one as it continues to go through the file. This is fine for non- island grammars, but if you use multiple-emit inside an island grammar, the lexer will happily continue munching input as it cleans out its emit buffer even after the EOF token is "emitted". This either leads to the island lexer throwing away input (since it terminates on EOF and tosses the remaining multi-emit buffer) or throwing an error (if it runs across input that it cannot understand). I've included a reproducer (in python) which can demonstrate and gives a workaround for both. Thanks, -Bob List: Unsubscribe: Thanks for the reviews of the initial patch. Since reviewboard is very slow at the moment, I'm sending the second version now directly to the mailing list. Changes since version 1: ================ - Review fix: make label "Number of tiles:" more verbose ("Number of tiles to download:"). - DownloadRegionDialog: Review fix: use QDialogButtonBox, looks much better now. - DownloadRegionDialog: Review fix: Change "current region " to "visible region " which is more concrete. Also adjust corresponding qualifiers. - MarblePart: use kDebug() instead of mDebug(). - Download region : fix 32bit overflow when calculating number of tiles to download. - LatLonBoxWidget: instead of using 1.0 as single step value, use 10% of angle. - DownloadRegionDialog:: region : switch from tile coords to pixel coords. When calculating tile coords, it is better to do it in pixel coords as long as possible to not loose accuracy for no reason. With the current approach of using the top level (of the pyramid) coords as reference this might not give benefit, but once we switch to bottom level coords, there will be much better accuracy. - TileCoordsPyramid: fix potential crash. TileCoordsPyramid has got dynamically allocated data members and so needs to define a copy constructor and an assignment operator especially since TileCoordsPyramid objects are copied in existing code. - TileCoordsPyramid: improve accuracy of tile coordinates and tiles count calculations. Use bottom level coordinates for calculations instead of top level coordinates, so we don't loose information. - TileLevelRangeWidget: Assure that maximum top level is not higher than then current bottom level. Likewise for minimum bottom level: should not be smaller than current top level. - TileLevelRangeWidget: improve API consistency. As this is a TileLevelRangeWidget it is not necessary to prefix level with tile. The levels this widget deals with are inherently tile levels. The methods topLevel and bottomLevel already reflect this. So following methods were renamed: setAllowedTileLevelRange -> setAllowedLevelRange setDefaultTileLevel -> setDefaultLevel - TileLevelRangeWidget: rename spin boxes: minSpinBox -> topSpinBox maxSpinBox -> bottomSpinBox - TileLevelRangeWidget: remove obsolete comment, break long line. - Disable copy operations on DownloadRegionDialog, LatLonBoxWidget and TileLevelRangeWidget as these classes are indirectly derived from QObject. - DownloadRegionDialog: set window title. - DownloadRegionDialog: Review fix: show message box every time when the limit of (currently) 100000 tiles to download is exceeded. - After dropping the "Tile" infix the identifiers are shorter now and this line break is not needed anymore. Best regards, Jens-Michael Hoffmann Index: marble/src/lib/LatLonBoxWidget.ui =================================================================== --- marble/src/lib/LatLonBoxWidget.ui (Revision 0) +++ marble/src/lib/LatLonBoxWidget.ui (Revision 0) @@ -0,0 +1,242 @@ + + + LatLonBoxWidget + + + true + + + + 0 + 0 + 313 + 100 + + + + Select a geographic region + + + + + + Qt::Horizontal + + + + 13 + 13 + + + + + + + + + + true + + + Northern Latitude + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + 3 + + + -90.000000000000000 + + + 90.000000000000000 + + + 90.000000000000000 + + + + + + + &N + + + northSpinBox + + + + + + + + + Qt::Horizontal + + + + 13 + 13 + + + + + + + + + + Western Longitude + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + 3 + + + -180.000000000000000 + + + 180.000000000000000 + + + -180.000000000000000 + + + + + + + &W + + + westSpinBox + + + + + + + + + Qt::Horizontal + + + + 13 + 13 + + + + + + + + + + Eastern Longitude + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + 3 + + + -180.000000000000000 + + + 180.000000000000000 + + + 180.000000000000000 + + + + + + + &E + + + eastSpinBox + + + + + + + + + Qt::Horizontal + + + + 13 + 13 + + + + + + + + + + Southern Latitude + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + 3 + + + -90.000000000000000 + + + 90.000000000000000 + + + -90.000000000000000 + + + + + + + &S + + + southSpinBox + + + + + + + + + Qt::Horizontal + + + + 13 + 13 + + + + + + + + northSpinBox + westSpinBox + eastSpinBox + southSpinBox + + + + Index: marble/src/lib/TileLevelRangeWidget.ui =================================================================== --- marble/src/lib/TileLevelRangeWidget.ui (Revision 0) +++ marble/src/lib/TileLevelRangeWidget.ui (Revision 0) @@ -0,0 +1,100 @@ + + + TileLevelRangeWidget + + + + 0 + 0 + 400 + 300 + + + + Form + + + + + 10 + 0 + 450 + 68 + + + + Zoom + + + + + + + + &Tile Level Range: + + + topSpinBox + + + + + + + Minimum Tile Level + + + 0 + + + 20 + + + 0 + + + + + + + to + + + + + + + Maximum Tile Level + + + 0 + + + 20 + + + 4 + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + + + Index: marble/src/lib/AbstractScanlineTextureMapper.h =================================================================== --- marble/src/lib/AbstractScanlineTextureMapper.h (Revision 1118774) +++ marble/src/lib/AbstractScanlineTextureMapper.h (Arbeitskopie) @@ -48,6 +48,8 @@ bool interlaced() const; void setInterlaced( bool enabled ); int tileZoomLevel() const; + QSize tileSize() const; + GeoSceneTexture const * textureLayer() const; Q_SIGNALS: void mapChanged(); @@ -169,6 +171,16 @@ m_interlaced = enabled; } +inline QSize AbstractScanlineTextureMapper::tileSize() const +{ + return m_tileSize; +} + +inline GeoSceneTexture const * AbstractScanlineTextureMapper::textureLayer() const +{ + return m_textureLayer; +} + inline int AbstractScanlineTextureMapper::globalWidth() const { return m_globalWidth; Index: marble/src/lib/LatLonBoxWidget.cpp =================================================================== --- marble/src/lib/LatLonBoxWidget.cpp (Revision 0) +++ marble/src/lib/LatLonBoxWidget.cpp (Revision 0) @@ -0,0 +1,84 @@ +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library. If not, see < >. + +#include "LatLonBoxWidget.h" + +#include "GeoDataLatLonBox.h" +#include "ui_LatLonBoxWidget.h" + +namespace Marble +{ + +class LatLonBoxWidget::Private +{ +public: + explicit Private( QWidget * const parent ); + Ui::LatLonBoxWidget m_ui; +}; + +LatLonBoxWidget::Private::Private( QWidget * const parent ) +{ + m_ui.setupUi( parent ); +} + + +LatLonBoxWidget::LatLonBoxWidget( QWidget * const parent, Qt::WindowFlags const f ) + : QWidget( parent, f ), + d( new Private( this )) +{ + // used for updating tiles count in DownloadRegionDialog + connect( d->m_ui.northSpinBox, SIGNAL( valueChanged( double )), SIGNAL( valueChanged() )); + connect( d->m_ui.southSpinBox, SIGNAL( valueChanged( double )), SIGNAL( valueChanged() )); + connect( d->m_ui.eastSpinBox, SIGNAL( valueChanged( double )), SIGNAL( valueChanged() )); + connect( d->m_ui.westSpinBox, SIGNAL( valueChanged( double )), SIGNAL( valueChanged() )); + // used for adjusting single step values + connect( d->m_ui.northSpinBox, SIGNAL( valueChanged( double )), SLOT( updateLatSingleStep() )); + connect( d->m_ui.southSpinBox, SIGNAL( valueChanged( double )), SLOT( updateLatSingleStep() )); + connect( d->m_ui.eastSpinBox, SIGNAL( valueChanged( double )), SLOT( updateLonSingleStep() )); + connect( d->m_ui.westSpinBox, SIGNAL( valueChanged( double )), SLOT( updateLonSingleStep() )); +} + +GeoDataLatLonBox LatLonBoxWidget::latLonBox() const +{ + return GeoDataLatLonBox( d->m_ui.northSpinBox->value(), d->m_ui.southSpinBox->value(), + d->m_ui.eastSpinBox->value(), d->m_ui.westSpinBox->value(), + GeoDataCoordinates::Degree ); +} + +void LatLonBoxWidget::setLatLonBox( GeoDataLatLonBox const & latLonBox ) +{ + d->m_ui.northSpinBox->setValue( latLonBox.north( GeoDataCoordinates::Degree )); + d->m_ui.southSpinBox->setValue( latLonBox.south( GeoDataCoordinates::Degree )); + d->m_ui.eastSpinBox->setValue( latLonBox.east( GeoDataCoordinates::Degree )); + d->m_ui.westSpinBox->setValue( latLonBox.west( GeoDataCoordinates::Degree )); +} + +void LatLonBoxWidget::updateLatSingleStep() +{ + double const singleStep = + qAbs( d->m_ui.northSpinBox->value() - d->m_ui.southSpinBox->value() ) / 10.0; + d->m_ui.northSpinBox->setSingleStep( singleStep ); + d->m_ui.southSpinBox->setSingleStep( singleStep ); +} + +void LatLonBoxWidget::updateLonSingleStep() +{ + double const singleStep = + qAbs( d->m_ui.eastSpinBox->value() - d->m_ui.westSpinBox->value() ) / 10.0; + d->m_ui.eastSpinBox->setSingleStep( singleStep ); + d->m_ui.westSpinBox->setSingleStep( singleStep ); +} + +} + +#include "LatLonBoxWidget.moc" Index: marble/src/lib/TileLevelRangeWidget.cpp =================================================================== --- marble/src/lib/TileLevelRangeWidget.cpp (Revision 0) +++ marble/src/lib/TileLevelRangeWidget.cpp (Revision 0) @@ -0,0 +1,86 @@ +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library. If not, see < >. + +#include "TileLevelRangeWidget.h" + +#include "ui_TileLevelRangeWidget.h" + +namespace Marble +{ + +class TileLevelRangeWidget::Private +{ +public: + explicit Private( QWidget * const parent ); + Ui::TileLevelRangeWidget m_ui; +}; + +TileLevelRangeWidget::Private::Private( QWidget * const parent ) +{ + m_ui.setupUi( parent ); +} + +TileLevelRangeWidget::TileLevelRangeWidget( QWidget * const parent, Qt::WindowFlags const f ) + : QWidget( parent, f ), + d( new Private( this )) +{ + connect( d->m_ui.topSpinBox, SIGNAL( valueChanged( int )), SIGNAL( topLevelChanged( int ))); + connect( d->m_ui.bottomSpinBox, SIGNAL( valueChanged( int )), + SIGNAL( bottomLevelChanged( int ))); + + connect( d->m_ui.topSpinBox, SIGNAL( valueChanged( int )), SLOT( setMinimumBottomLevel( int ))); + connect( d->m_ui.bottomSpinBox, SIGNAL( valueChanged( int )), SLOT( setMaximumTopLevel( int ))); +} + +TileLevelRangeWidget::~TileLevelRangeWidget() +{ + delete d; +} + +void TileLevelRangeWidget::setAllowedLevelRange( int const minimumLevel, int const maximumLevel ) +{ + d->m_ui.topSpinBox->setRange( minimumLevel, qMin( d->m_ui.bottomSpinBox->value(), + maximumLevel )); + d->m_ui.bottomSpinBox->setRange( qMax( d->m_ui.topSpinBox->value(), minimumLevel ), + maximumLevel ); +} + +void TileLevelRangeWidget::setDefaultLevel( int const level ) +{ + d->m_ui.topSpinBox->setValue( level ); + d->m_ui.bottomSpinBox->setValue( level ); +} + +int TileLevelRangeWidget::bottomLevel() const +{ + return d->m_ui.bottomSpinBox->value(); +} + +int TileLevelRangeWidget::topLevel() const +{ + return d->m_ui.topSpinBox->value(); +} + +void TileLevelRangeWidget::setMaximumTopLevel( int const level ) +{ + d->m_ui.topSpinBox->setMaximum( level ); +} + +void TileLevelRangeWidget::setMinimumBottomLevel( int const level ) +{ + d->m_ui.bottomSpinBox->setMinimum( level ); +} + +} + +#include "TileLevelRangeWidget.moc" Index: marble/src/lib/TileCoordsPyramid.cpp =================================================================== --- marble/src/lib/TileCoordsPyramid.cpp (Revision 0) +++ marble/src/lib/TileCoordsPyramid.cpp (Revision 0) @@ -0,0 +1,106 @@ +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library. If not, see < >. + +#include "TileCoordsPyramid.h" + +#include + +namespace Marble +{ + +class TileCoordsPyramid::Private +{ +public: + Private( int const topLevel, int const bottomLevel ); + + int m_topLevel; + int m_bottomLevel; + QRect m_bottomLevelCoords; +}; + +TileCoordsPyramid::Private::Private( int const topLevel, int const bottomLevel ) + : m_topLevel( topLevel ), + m_bottomLevel( bottomLevel ) +{ + Q_ASSERT( m_topLevel <= m_bottomLevel ); +} + + +TileCoordsPyramid::TileCoordsPyramid( int const topLevel, int const bottomLevel ) + : d( new Private( topLevel, bottomLevel )) +{ +} + +TileCoordsPyramid::TileCoordsPyramid( TileCoordsPyramid const & other ) + : d( new Private( *other.d )) +{ +} + +TileCoordsPyramid & TileCoordsPyramid::operator=( TileCoordsPyramid const & rhs ) +{ + TileCoordsPyramid temp( rhs ); + swap( temp ); + return *this; +} + +TileCoordsPyramid::~TileCoordsPyramid() +{ + delete d; +} + +int TileCoordsPyramid::topLevel() const +{ + return d->m_topLevel; +} + +int TileCoordsPyramid::bottomLevel() const +{ + return d->m_bottomLevel; +} + +void TileCoordsPyramid::setBottomLevelCoords( QRect const & coords ) +{ + d->m_bottomLevelCoords = coords; +} + +QRect TileCoordsPyramid::coords( int const level ) const +{ + Q_ASSERT( d->m_topLevel <= level && level <= d->m_bottomLevel ); + int bottomX1, bottomY1, bottomX2, bottomY2; + d->m_bottomLevelCoords.getCoords( &bottomX1, &bottomY1, &bottomX2, &bottomY2 ); + int const deltaLevel = d->m_bottomLevel - level; + int const x1 = bottomX1 >> deltaLevel; + int const y1 = bottomY1 >> deltaLevel; + int const x2 = bottomX2 >> deltaLevel; + int const y2 = bottomY2 >> deltaLevel; + QRect result; + result.setCoords( x1, y1, x2, y2 ); + return result; +} + +qint64 TileCoordsPyramid::tilesCount() const +{ + qint64 result = 0; + for ( int level = d->m_topLevel; level <= d->m_bottomLevel; ++level ) { + QRect const levelCoords = coords( level ); + result += levelCoords.width() * levelCoords.height(); + } + return result; +} + +void TileCoordsPyramid::swap( TileCoordsPyramid & other ) +{ + std::swap( d, other.d ); +} + +} Index: marble/src/lib/TileLevelRangeWidget.h =================================================================== --- marble/src/lib/TileLevelRangeWidget.h (Revision 0) +++ marble/src/lib/TileLevelRangeWidget.h (Revision 0) @@ -0,0 +1,54 @@ +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library. If not, see < >. + +#ifndef MARBLE_TILELEVELRANGEWIDGET_H +#define MARBLE_TILELEVELRANGEWIDGET_H + +#include + +#include "marble_export.h" + +namespace Marble +{ + +class MARBLE_EXPORT TileLevelRangeWidget: public QWidget +{ + Q_OBJECT + + public: + explicit TileLevelRangeWidget( QWidget * const parent = 0, Qt::WindowFlags const f = 0 ); + ~TileLevelRangeWidget(); + + void setAllowedLevelRange( int const minimumLevel, int const maximumLevel ); + void setDefaultLevel( int const ); + + int topLevel() const; + int bottomLevel() const; + + private Q_SLOTS: + void setMaximumTopLevel( int const ); + void setMinimumBottomLevel( int const ); + + Q_SIGNALS: + void topLevelChanged( int ); + void bottomLevelChanged( int ); + + private: + Q_DISABLE_COPY( TileLevelRangeWidget ) + class Private; + Private * const d; +}; + +} + +