Skip to content

Commit

Permalink
Fix a crash in the puzzle when not properly initialized
Browse files Browse the repository at this point in the history
  • Loading branch information
wonder-sk committed Apr 6, 2018
1 parent 1a515c9 commit ce72536
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 6 deletions.
4 changes: 2 additions & 2 deletions src/app/qgisapp.cpp
Expand Up @@ -1341,8 +1341,8 @@ QgisApp::QgisApp( QSplashScreen *splash, bool restorePlugins, bool skipVersionCh
mCentralContainer->insertWidget( 2, puzzleWidget );
connect( mCoordsEdit, &QgsStatusBarCoordinatesWidget::weAreBored, this, [ this, puzzleWidget ]
{
puzzleWidget->letsGetThePartyStarted();
mCentralContainer->setCurrentIndex( 2 );
if ( puzzleWidget->letsGetThePartyStarted() )
mCentralContainer->setCurrentIndex( 2 );
} );
connect( puzzleWidget, &QgsPuzzleWidget::done, this, [ this ]
{
Expand Down
11 changes: 10 additions & 1 deletion src/app/qgspuzzlewidget.cpp
Expand Up @@ -80,6 +80,9 @@ QgsPuzzleWidget::QgsPuzzleWidget( QgsMapCanvas *canvas )

void QgsPuzzleWidget::mousePressEvent( QMouseEvent *event )
{
if ( mTileWidth == 0 || mTileHeight == 0 )
return; // not initialized

int idxEmpty = findEmpty( mPositions );
int rEmpty = idxEmpty / mSize;
int cEmpty = idxEmpty % mSize;
Expand Down Expand Up @@ -107,12 +110,17 @@ void QgsPuzzleWidget::mousePressEvent( QMouseEvent *event )
}
}

void QgsPuzzleWidget::letsGetThePartyStarted()
bool QgsPuzzleWidget::letsGetThePartyStarted()
{
mPositions.clear();
delete mScene;
mItems.clear();
mTextItems.clear();
mTileWidth = 0;
mTileHeight = 0;

if ( !mCanvas->layerCount() )
return false;

mScene = new QGraphicsScene;

Expand Down Expand Up @@ -168,6 +176,7 @@ void QgsPuzzleWidget::letsGetThePartyStarted()
updateTilePositions();

setScene( mScene );
return true;
}

void QgsPuzzleWidget::updateTilePositions()
Expand Down
5 changes: 2 additions & 3 deletions src/app/qgspuzzlewidget.h
Expand Up @@ -27,15 +27,14 @@ class QgsPuzzleWidget : public QGraphicsView
public:
explicit QgsPuzzleWidget( QgsMapCanvas *canvas = nullptr );

bool letsGetThePartyStarted();

protected:
void mousePressEvent( QMouseEvent *event ) override;

signals:
void done();

public slots:
void letsGetThePartyStarted();

private:
void updateTilePositions();

Expand Down

0 comments on commit ce72536

Please sign in to comment.