Skip to content
Permalink
Browse files

[GRASS] fixed animated import icon on windows

  • Loading branch information
blazek committed Jun 23, 2015
1 parent 7536690 commit 7b2683849ea1011ae0c2974c3d0bbe0054322b81
@@ -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()
@@ -50,6 +67,7 @@ QgsGrassImport::~QgsGrassImport()
QgsDebugMsg( "mFutureWatcher not finished -> waitForFinished()" );
mFutureWatcher->waitForFinished();
}
QgsGrassImportIcon::instance()->disconnectFrameChanged( this, SLOT( frameChanged() ) );
}

void QgsGrassImport::setError( QString error )
@@ -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)
@@ -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)
@@ -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();
@@ -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
@@ -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
@@ -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 );
@@ -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()
@@ -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();
}

//-------------------------------------------------------------------------
@@ -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 {}

0 comments on commit 7b26838

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