Skip to content

Commit

Permalink
[GRASS] fixed animated import icon on windows
Browse files Browse the repository at this point in the history
  • Loading branch information
blazek committed Jun 23, 2015
1 parent 7536690 commit 7b26838
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 31 deletions.
28 changes: 23 additions & 5 deletions src/providers/grass/qgsgrassimport.cpp
Expand Up @@ -35,12 +35,29 @@ extern "C"
#include <grass/imagery.h>
}

//------------------------------ QgsGrassImport ------------------------------------
QgsGrassImportIcon *QgsGrassImportIcon::instance()
{
static QgsGrassImportIcon* sInstance = new QgsGrassImportIcon();
return sInstance;
}

QgsGrassImportIcon::QgsGrassImportIcon()
: QgsAnimatedIcon( QgsApplication::iconPath( "/mIconImport.gif" ) )
{
}

//------------------------------ QgsGrassImport ------------------------------------
QgsGrassImport::QgsGrassImport( QgsGrassObject grassObject )
: QObject()
, mGrassObject( grassObject )
, mCanceled( false )
, mFutureWatcher( 0 )
{
// QMovie used by QgsAnimatedIcon is using QTimer which cannot be start from another thread
// (it works on Linux however) so we cannot start it connecting from QgsGrassImportItem and
// connect it also here (QgsGrassImport is constructed on the main thread) to a slot doing nothing.
QgsGrassImportIcon::instance()->connectFrameChanged( this, SLOT( frameChanged() ) );
}

QgsGrassImport::~QgsGrassImport()
Expand All @@ -50,6 +67,7 @@ QgsGrassImport::~QgsGrassImport()
QgsDebugMsg( "mFutureWatcher not finished -> waitForFinished()" );
mFutureWatcher->waitForFinished();
}
QgsGrassImportIcon::instance()->disconnectFrameChanged( this, SLOT( frameChanged() ) );
}

void QgsGrassImport::setError( QString error )
Expand Down Expand Up @@ -264,8 +282,8 @@ bool QgsGrassRasterImport::import()
outStream << false; // not canceled
outStream << byteArray;

// Without waitForBytesWritten() it does not finish ok on Windows (process timeout)
process->waitForBytesWritten(-1);
// Without waitForBytesWritten() it does not finish ok on Windows (process timeout)
process->waitForBytesWritten( -1 );

#ifndef Q_OS_WIN
// wait until the row is written to allow quick cancel (don't send data to buffer)
Expand Down Expand Up @@ -479,8 +497,8 @@ bool QgsGrassVectorImport::import()
outStream << false; // not canceled
outStream << feature;

// Without waitForBytesWritten() it does not finish ok on Windows (data lost)
process->waitForBytesWritten(-1);
// Without waitForBytesWritten() it does not finish ok on Windows (data lost)
process->waitForBytesWritten( -1 );

#ifndef Q_OS_WIN
// wait until the feature is written to allow quick cancel (don't send data to buffer)
Expand All @@ -493,7 +511,7 @@ bool QgsGrassVectorImport::import()
outStream << false; // not canceled
outStream << feature;

process->waitForBytesWritten(-1);
process->waitForBytesWritten( -1 );
QgsDebugMsg( "features sent" );
#ifndef Q_OS_WIN
process->waitForReadyRead();
Expand Down
11 changes: 11 additions & 0 deletions src/providers/grass/qgsgrassimport.h
Expand Up @@ -19,12 +19,22 @@
#include <QFutureWatcher>
#include <QObject>

#include "qgsdataitem.h"
#include "qgslogger.h"
#include "qgsrasterpipe.h"
#include "qgsvectordataprovider.h"

#include "qgsgrass.h"

class GRASS_LIB_EXPORT QgsGrassImportIcon : public QgsAnimatedIcon
{
Q_OBJECT
public:
static QgsGrassImportIcon *instance();
QgsGrassImportIcon();
virtual ~QgsGrassImportIcon() {};
};

class GRASS_LIB_EXPORT QgsGrassImport : public QObject
{
Q_OBJECT
Expand All @@ -48,6 +58,7 @@ class GRASS_LIB_EXPORT QgsGrassImport : public QObject
// and thus recieves the signal.
// Most probably however, it will work correctly, even if read/write the bool wasn't atomic
void cancel();
void frameChanged() {};

signals:
// sent when process finished
Expand Down
27 changes: 3 additions & 24 deletions src/providers/grass/qgsgrassprovidermodule.cpp
Expand Up @@ -254,9 +254,6 @@ bool QgsGrassMapsetItem::handleDrop( const QMimeData * data, Qt::DropAction )
if ( !QgsMimeDataUtils::isUriList( data ) )
return false;

// Init animated icon on main thread
QgsGrassImportItem::initIcon();

QSettings settings;

QgsGrassObject mapsetObject( mGisdbase, mLocation, mName );
Expand Down Expand Up @@ -763,18 +760,12 @@ QgsGrassImportItem::QgsGrassImportItem( QgsDataItem* parent, const QString& name
setCapabilities( QgsDataItem::NoCapabilities ); // disable fertility
setState( Populating );

if ( mImportIcon )
{
mImportIcon->connectFrameChanged( this, SLOT( emitDataChanged() ) );
}
QgsGrassImportIcon::instance()->connectFrameChanged( this, SLOT( emitDataChanged() ) );
}

QgsGrassImportItem::~QgsGrassImportItem()
{
if ( mImportIcon )
{
mImportIcon->disconnectFrameChanged( this, SLOT( emitDataChanged() ) );
}
QgsGrassImportIcon::instance()->disconnectFrameChanged( this, SLOT( emitDataChanged() ) );
}

QList<QAction*> QgsGrassImportItem::actions()
Expand All @@ -801,19 +792,7 @@ void QgsGrassImportItem::cancel()

QIcon QgsGrassImportItem::icon()
{
if ( mImportIcon )
{
return mImportIcon->icon();
}
return QIcon();
}

void QgsGrassImportItem::initIcon()
{
if ( !mImportIcon )
{
mImportIcon = new QgsAnimatedIcon( QgsApplication::iconPath( "/mIconImport.gif" ) );
}
return QgsGrassImportIcon::instance()->icon();
}

//-------------------------------------------------------------------------
Expand Down
2 changes: 0 additions & 2 deletions src/providers/grass/qgsgrassprovidermodule.h
Expand Up @@ -180,8 +180,6 @@ class QgsGrassImportItem : public QgsDataItem, public QgsGrassObjectItemBase
//} // do nothing to keep Populating
virtual QList<QAction*> actions() override;
virtual QIcon icon() override;
// Init animated icon, to be called from main UI thread
static void initIcon();

public slots:
virtual void refresh() override {}
Expand Down

0 comments on commit 7b26838

Please sign in to comment.