Skip to content
Permalink
Browse files

[GRASS] optional modules config path

  • Loading branch information
blazek committed Jul 23, 2015
1 parent 266aa7b commit 32d7cc5e008ba489290cddf41901724af368689e
@@ -5,4 +5,4 @@ INSTALL (FILES ${MODULE_FILES}

FILE (GLOB CONFIG *.qgc)
INSTALL (FILES ${CONFIG}
DESTINATION ${QGIS_DATA_DIR}/grass/config)
DESTINATION ${QGIS_DATA_DIR}/grass/modules)
@@ -99,6 +99,8 @@ QgsGrassTools::QgsGrassTools( QgisInterface *iface, QWidget * parent, const char
connect( mDirectListView, SIGNAL( clicked( const QModelIndex ) ),
this, SLOT( directListItemClicked( const QModelIndex ) ) );

connect( QgsGrass::instance(), SIGNAL( modulesConfigChanged() ), SLOT( loadConfig() ) );

// Show before loadConfig() so that user can see loading
restorePosition();
showTabs();
@@ -143,8 +145,7 @@ void QgsGrassTools::showTabs()
{
// Load the modules lists
QApplication::setOverrideCursor( Qt::WaitCursor );
QString conf = QgsApplication::pkgDataPath() + "/grass/config/default.qgc";
loadConfig( conf, mModulesTree, mModulesListModel, false );
loadConfig();
QApplication::restoreOverrideCursor();
QgsDebugMsg( QString( "topLevelItemCount = %1" ).arg( mModulesTree->topLevelItemCount() ) );
}
@@ -277,6 +278,12 @@ void QgsGrassTools::runModule( QString name, bool direct )
#endif
}

bool QgsGrassTools::loadConfig()
{
QString conf = QgsGrass::modulesConfigDirPath() + "/default.qgc";
return loadConfig( conf, mModulesTree, mModulesListModel, false );
}

bool QgsGrassTools::loadConfig( QString filePath, QTreeWidget *modulesTreeWidget, QStandardItemModel * modulesListModel, bool direct )
{
QgsDebugMsg( filePath );
@@ -385,7 +392,7 @@ void QgsGrassTools::addModules( QTreeWidgetItem *parent, QDomElement &element, Q
else if ( e.tagName() == "grass" )
{ // GRASS module
QString name = e.attribute( "name" );
QgsDebugMsg( QString( "name = %1" ).arg( name ) );
QgsDebugMsgLevel( QString( "name = %1" ).arg( name ), 1 );

QString path = QgsApplication::pkgDataPath() + "/grass/modules/" + name;
QgsGrassModule::Description description = QgsGrassModule::description( path );
@@ -31,7 +31,7 @@ class QDomElement;
class QSortFilterProxyModel;
class QStandardItemModel;

/*! \class QgsGrassTools
/** \class QgsGrassTools
* \brief Interface to GRASS modules.
*
*/
@@ -55,6 +55,8 @@ class QgsGrassTools: public QDockWidget, private Ui::QgsGrassToolsBase
QString appDir();

public slots:
bool loadConfig();

//! Load configuration from file
bool loadConfig( QString filePath, QTreeWidget *modulesTreeWidget, QStandardItemModel * modulesListModel, bool direct );

@@ -2294,6 +2294,48 @@ void GRASS_LIB_EXPORT QgsGrass::putEnv( QString name, QString value )
putenv( envChar );
}

QString GRASS_LIB_EXPORT QgsGrass::modulesConfigDefaultDirPath()
{
#ifdef _MSC_VER
if ( QgsApplication::isRunningFromBuildDir() )
{
return QgsApplication::buildSourcePath() + "/src/plugins/grass/modules";
}
#endif
return QgsApplication::pkgDataPath() + "/grass/modules";
}

QString GRASS_LIB_EXPORT QgsGrass::modulesConfigDirPath()
{
QSettings settings;
bool customModules = settings.value( "/GRASS/modules/config/custom", false ).toBool();
QString customModulesDir = settings.value( "/GRASS/modules/config/customDir" ).toString();

if ( customModules && !customModulesDir.isEmpty() )
{
return customModulesDir;
}
else
{
return modulesConfigDefaultDirPath();
}
}

void GRASS_LIB_EXPORT QgsGrass::setModulesConfig( bool custom, const QString &customDir )
{
QSettings settings;

bool previousCustom = settings.value( "/GRASS/modules/config/custom", false ).toBool();
QString previousCustomDir = settings.value( "/GRASS/modules/config/customDir" ).toString();
settings.setValue( "/GRASS/modules/config/custom", custom );
settings.setValue( "/GRASS/modules/config/customDir", customDir );

if ( custom != previousCustom || ( custom && customDir != previousCustomDir ) )
{
emit modulesConfigChanged();
}
}

void GRASS_LIB_EXPORT QgsGrass::warning( const QString &message )
{
QMessageBox::warning( 0, QObject::tr( "Warning" ), message );
@@ -453,6 +453,14 @@ class GRASS_LIB_EXPORT QgsGrass : public QObject
return QgsApplication::libexecPath() + "grass/modules";
}

// path to default modules interface config dir
static GRASS_LIB_EXPORT QString modulesConfigDefaultDirPath();

// path to modules interface config dir (default or custom)
static GRASS_LIB_EXPORT QString modulesConfigDirPath();

void GRASS_LIB_EXPORT setModulesConfig( bool custom, const QString &customDir );

/** Show warning dialog with message */
static GRASS_LIB_EXPORT void warning( const QString &message );

@@ -471,6 +479,9 @@ class GRASS_LIB_EXPORT QgsGrass : public QObject
/** Signal emited after mapset was opened */
void mapsetChanged();

/** Emited when path to modules config dir changed */
void modulesConfigChanged();

private:
static int initialized; // Set to 1 after initialization
static bool active; // is active mode
@@ -13,38 +13,74 @@
* (at your option) any later version. *
* *
***************************************************************************/

#include <QFileDialog>

#include "qgsrasterprojector.h"

#include "qgsgrass.h"
#include "qgsgrassoptions.h"
#include "ui_qgsgrassoptionsbase.h"

QgsGrassOptions::QgsGrassOptions( QWidget *parent )
: QDialog( parent )
: QgsOptionsDialogBase( "GrassOptions", parent )
, QgsGrassOptionsBase()
, mImportSettingsPath( "/GRASS/browser/import" )
, mModulesSettingsPath( "/GRASS/modules/config" )
{
setupUi( this );
initOptionsBase( false );

connect( this, SIGNAL( accepted() ), this, SLOT( saveOptions() ) );
connect( this, SIGNAL( accepted() ), SLOT( saveOptions() ) );
connect( buttonBox->button( QDialogButtonBox::Apply ), SIGNAL( clicked() ), SLOT( saveOptions() ) );

QSettings settings;

// Modules
bool customModules = settings.value( mModulesSettingsPath + "/custom", false ).toBool();
QString customModulesDir = settings.value( mModulesSettingsPath + "/customDir" ).toString();
mModulesConfigDefaultRadioButton->setText( tr( "Default" ) + " (" + QgsGrass::modulesConfigDefaultDirPath() + ")" );
mModulesConfigDefaultRadioButton->setChecked( !customModules );
mModulesConfigCustomRadioButton->setChecked( customModules );
mModulesConfigDirLineEdit->setText( customModulesDir );

// Browser
QgsRasterProjector::Precision crsTransform = ( QgsRasterProjector::Precision ) settings.value( mImportSettingsPath + "/crsTransform", QgsRasterProjector::Approximate ).toInt();
mCrsTransformationComboBox->addItem( QgsRasterProjector::precisionLabel( QgsRasterProjector::Approximate ), QgsRasterProjector::Approximate );
mCrsTransformationComboBox->addItem( QgsRasterProjector::precisionLabel( QgsRasterProjector::Exact ), QgsRasterProjector::Exact );
mCrsTransformationComboBox->setCurrentIndex( mCrsTransformationComboBox->findData( crsTransform ) );

mImportExternalCheckBox->setChecked( settings.value( mImportSettingsPath + "/external", true ).toBool() );

restoreOptionsBaseUi();
}

QgsGrassOptions::~QgsGrassOptions()
{
}

void QgsGrassOptions::on_mModulesConfigBrowseButton_clicked()
{
QString dir = QFileDialog::getExistingDirectory( this,
tr( "Choose a directory with configuration files (default.qgc, *.qgm)" ),
mModulesConfigDirLineEdit->text() );

if ( !dir.isEmpty() )
{
mModulesConfigDirLineEdit->setText( dir );
}
}

void QgsGrassOptions::saveOptions()
{
QSettings settings;

// Modules
bool customModules = mModulesConfigCustomRadioButton->isChecked();
QString customModulesDir = mModulesConfigDirLineEdit->text();
QgsGrass::instance()->setModulesConfig( customModules, customModulesDir );

// Browser
settings.setValue( mImportSettingsPath + "/crsTransform",
mCrsTransformationComboBox->itemData( mCrsTransformationComboBox->currentIndex() ).toInt() );

@@ -18,9 +18,11 @@

#include <QDialog>

#include "qgsoptionsdialogbase.h"

#include "ui_qgsgrassoptionsbase.h"

class GRASS_LIB_EXPORT QgsGrassOptions : public QDialog, private Ui::QgsGrassOptionsBase
class GRASS_LIB_EXPORT QgsGrassOptions : public QgsOptionsDialogBase, private Ui::QgsGrassOptionsBase
{
Q_OBJECT

@@ -29,11 +31,12 @@ class GRASS_LIB_EXPORT QgsGrassOptions : public QDialog, private Ui::QgsGrassOpt
~QgsGrassOptions();

private slots:
void on_mModulesConfigBrowseButton_clicked();
void saveOptions();

private:
QString mImportSettingsPath;

QString mModulesSettingsPath;
};

#endif // QGSGRASSOPTIONS_H

0 comments on commit 32d7cc5

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