Skip to content
Permalink
Browse files

Fix a crash in the puzzle when not properly initialized

  • Loading branch information
wonder-sk committed Apr 6, 2018
1 parent 1a515c9 commit ce72536bcc4d86a6bf2ffc1e7a16ba74c47a2093
Showing with 14 additions and 6 deletions.
  1. +2 −2 src/app/qgisapp.cpp
  2. +10 −1 src/app/qgspuzzlewidget.cpp
  3. +2 −3 src/app/qgspuzzlewidget.h
@@ -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 ]
{
@@ -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;
@@ -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;

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

setScene( mScene );
return true;
}

void QgsPuzzleWidget::updateTilePositions()
@@ -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();

0 comments on commit ce72536

Please sign in to comment.
You can’t perform that action at this time.