Skip to content
Permalink
Browse files

[GRASS] refresh module input when location changed

  • Loading branch information
blazek committed Sep 29, 2015
1 parent ac38d89 commit 0692f25674800d0b3ab4bec15256db8fd4db7938
Showing with 40 additions and 20 deletions.
  1. +36 −20 src/plugins/grass/qgsgrassmoduleinput.cpp
  2. +4 −0 src/plugins/grass/qgsgrassmoduleinput.h
@@ -59,29 +59,15 @@ QgsGrassModuleInputModel::QgsGrassModuleInputModel( QObject *parent )
: QStandardItemModel( parent )
, mWatcher( 0 )
{
QgsDebugMsg( "entered" );
setColumnCount( 1 );
reload();

QString locationPath = QgsGrass::getDefaultLocationPath();
mWatcher = new QFileSystemWatcher( this );
mWatcher->addPath( locationPath );
connect( mWatcher, SIGNAL( directoryChanged( const QString & ) ), SLOT( onDirectoryChanged( const QString & ) ) );

// Watching all dirs in loacation because a dir may become a mapset later, when WIND is created
connect( QgsGrass::instance(), SIGNAL( mapsetChanged() ), SLOT( onMapsetChanged() ) );

//QStringList mapsets = QgsGrass::mapsets( QgsGrass::getDefaultGisdbase(), QgsGrass::getDefaultLocation() );
QStringList dirNames = locationDirNames();
foreach ( QString dirName, dirNames )
{
QString dirPath = locationPath + "/" + dirName;
// Watch the dir in any case, WIND mabe created later
mWatcher->addPath( dirPath );

foreach ( QString watchedDir, watchedDirs() )
{
watch( dirPath + "/" + watchedDir );
}
}
connect( mWatcher, SIGNAL( directoryChanged( const QString & ) ), SLOT( onDirectoryChanged( const QString & ) ) );
reload();
}

void QgsGrassModuleInputModel::onDirectoryChanged( const QString & path )
@@ -242,12 +228,44 @@ void QgsGrassModuleInputModel::refreshMapset( QStandardItem *mapsetItem, const Q

void QgsGrassModuleInputModel::reload()
{
QgsDebugMsg( "entered" );
mWatcher->removePaths( mWatcher->files() );
mWatcher->removePaths( mWatcher->directories() );

clear();

mLocationPath = QgsGrass::getDefaultLocationPath();

QStringList mapsets = QgsGrass::mapsets( QgsGrass::getDefaultGisdbase(), QgsGrass::getDefaultLocation() );
foreach ( QString mapset, mapsets )
{
addMapset( mapset );
}

mWatcher->addPath( mLocationPath );

// Watching all dirs in location because a dir may become a mapset later, when WIND is created
QStringList dirNames = locationDirNames();
foreach ( QString dirName, dirNames )
{
QString dirPath = mLocationPath + "/" + dirName;
// Watch the dir in any case, WIND mabe created later
mWatcher->addPath( dirPath );

foreach ( QString watchedDir, watchedDirs() )
{
watch( dirPath + "/" + watchedDir );
}
}
}

void QgsGrassModuleInputModel::onMapsetChanged()
{
QgsDebugMsg( "entered" );
if ( mLocationPath != QgsGrass::getDefaultLocationPath() )
{
reload();
}
}

QgsGrassModuleInputModel::~QgsGrassModuleInputModel()
@@ -263,7 +281,6 @@ QgsGrassModuleInputModel *QgsGrassModuleInputModel::instance()

QVariant QgsGrassModuleInputModel::data( const QModelIndex & index, int role ) const
{
QgsDebugMsg( "entered" );
QVariant data = QStandardItemModel::data( index, role );
if ( role == Qt::DisplayRole || role == Qt::EditRole ) // EditRole for combo
{
@@ -306,7 +323,6 @@ bool QgsGrassModuleInputProxy::filterAcceptsRow( int sourceRow, const QModelInde

bool QgsGrassModuleInputProxy::lessThan( const QModelIndex & left, const QModelIndex & right ) const
{
Q_UNUSED( right )
if ( mSourceModel )
{
// keep current mapset on top
@@ -74,18 +74,22 @@ class QgsGrassModuleInputModel : public QStandardItemModel
/** Reload current mapset */
void reload();

void onMapsetChanged();

void onDirectoryChanged( const QString & path );

private:
void addMapset( const QString & mapset );
void refreshMapset( QStandardItem *mapsetItem, const QString & mapset );
// Add to watched paths if exists and if not yet watched
void watch( const QString & path );
QString mLocationPath;
// mapset watched dirs
QStringList watchedDirs() { QStringList l; l << "cellhd" << "vector"; return l; }
// names of
QStringList locationDirNames();
QFileSystemWatcher *mWatcher;

};

// Filter maps by type

0 comments on commit 0692f25

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