Skip to content

Commit 32d7cc5

Browse files
committed
[GRASS] optional modules config path
1 parent 266aa7b commit 32d7cc5

File tree

8 files changed

+254
-50
lines changed

8 files changed

+254
-50
lines changed

src/plugins/grass/modules/CMakeLists.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@ INSTALL (FILES ${MODULE_FILES}
55

66
FILE (GLOB CONFIG *.qgc)
77
INSTALL (FILES ${CONFIG}
8-
DESTINATION ${QGIS_DATA_DIR}/grass/config)
8+
DESTINATION ${QGIS_DATA_DIR}/grass/modules)

src/plugins/grass/qgsgrasstools.cpp

+10-3
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,8 @@ QgsGrassTools::QgsGrassTools( QgisInterface *iface, QWidget * parent, const char
9999
connect( mDirectListView, SIGNAL( clicked( const QModelIndex ) ),
100100
this, SLOT( directListItemClicked( const QModelIndex ) ) );
101101

102+
connect( QgsGrass::instance(), SIGNAL( modulesConfigChanged() ), SLOT( loadConfig() ) );
103+
102104
// Show before loadConfig() so that user can see loading
103105
restorePosition();
104106
showTabs();
@@ -143,8 +145,7 @@ void QgsGrassTools::showTabs()
143145
{
144146
// Load the modules lists
145147
QApplication::setOverrideCursor( Qt::WaitCursor );
146-
QString conf = QgsApplication::pkgDataPath() + "/grass/config/default.qgc";
147-
loadConfig( conf, mModulesTree, mModulesListModel, false );
148+
loadConfig();
148149
QApplication::restoreOverrideCursor();
149150
QgsDebugMsg( QString( "topLevelItemCount = %1" ).arg( mModulesTree->topLevelItemCount() ) );
150151
}
@@ -277,6 +278,12 @@ void QgsGrassTools::runModule( QString name, bool direct )
277278
#endif
278279
}
279280

281+
bool QgsGrassTools::loadConfig()
282+
{
283+
QString conf = QgsGrass::modulesConfigDirPath() + "/default.qgc";
284+
return loadConfig( conf, mModulesTree, mModulesListModel, false );
285+
}
286+
280287
bool QgsGrassTools::loadConfig( QString filePath, QTreeWidget *modulesTreeWidget, QStandardItemModel * modulesListModel, bool direct )
281288
{
282289
QgsDebugMsg( filePath );
@@ -385,7 +392,7 @@ void QgsGrassTools::addModules( QTreeWidgetItem *parent, QDomElement &element, Q
385392
else if ( e.tagName() == "grass" )
386393
{ // GRASS module
387394
QString name = e.attribute( "name" );
388-
QgsDebugMsg( QString( "name = %1" ).arg( name ) );
395+
QgsDebugMsgLevel( QString( "name = %1" ).arg( name ), 1 );
389396

390397
QString path = QgsApplication::pkgDataPath() + "/grass/modules/" + name;
391398
QgsGrassModule::Description description = QgsGrassModule::description( path );

src/plugins/grass/qgsgrasstools.h

+3-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ class QDomElement;
3131
class QSortFilterProxyModel;
3232
class QStandardItemModel;
3333

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

5757
public slots:
58+
bool loadConfig();
59+
5860
//! Load configuration from file
5961
bool loadConfig( QString filePath, QTreeWidget *modulesTreeWidget, QStandardItemModel * modulesListModel, bool direct );
6062

src/providers/grass/qgsgrass.cpp

+42
Original file line numberDiff line numberDiff line change
@@ -2294,6 +2294,48 @@ void GRASS_LIB_EXPORT QgsGrass::putEnv( QString name, QString value )
22942294
putenv( envChar );
22952295
}
22962296

2297+
QString GRASS_LIB_EXPORT QgsGrass::modulesConfigDefaultDirPath()
2298+
{
2299+
#ifdef _MSC_VER
2300+
if ( QgsApplication::isRunningFromBuildDir() )
2301+
{
2302+
return QgsApplication::buildSourcePath() + "/src/plugins/grass/modules";
2303+
}
2304+
#endif
2305+
return QgsApplication::pkgDataPath() + "/grass/modules";
2306+
}
2307+
2308+
QString GRASS_LIB_EXPORT QgsGrass::modulesConfigDirPath()
2309+
{
2310+
QSettings settings;
2311+
bool customModules = settings.value( "/GRASS/modules/config/custom", false ).toBool();
2312+
QString customModulesDir = settings.value( "/GRASS/modules/config/customDir" ).toString();
2313+
2314+
if ( customModules && !customModulesDir.isEmpty() )
2315+
{
2316+
return customModulesDir;
2317+
}
2318+
else
2319+
{
2320+
return modulesConfigDefaultDirPath();
2321+
}
2322+
}
2323+
2324+
void GRASS_LIB_EXPORT QgsGrass::setModulesConfig( bool custom, const QString &customDir )
2325+
{
2326+
QSettings settings;
2327+
2328+
bool previousCustom = settings.value( "/GRASS/modules/config/custom", false ).toBool();
2329+
QString previousCustomDir = settings.value( "/GRASS/modules/config/customDir" ).toString();
2330+
settings.setValue( "/GRASS/modules/config/custom", custom );
2331+
settings.setValue( "/GRASS/modules/config/customDir", customDir );
2332+
2333+
if ( custom != previousCustom || ( custom && customDir != previousCustomDir ) )
2334+
{
2335+
emit modulesConfigChanged();
2336+
}
2337+
}
2338+
22972339
void GRASS_LIB_EXPORT QgsGrass::warning( const QString &message )
22982340
{
22992341
QMessageBox::warning( 0, QObject::tr( "Warning" ), message );

src/providers/grass/qgsgrass.h

+11
Original file line numberDiff line numberDiff line change
@@ -453,6 +453,14 @@ class GRASS_LIB_EXPORT QgsGrass : public QObject
453453
return QgsApplication::libexecPath() + "grass/modules";
454454
}
455455

456+
// path to default modules interface config dir
457+
static GRASS_LIB_EXPORT QString modulesConfigDefaultDirPath();
458+
459+
// path to modules interface config dir (default or custom)
460+
static GRASS_LIB_EXPORT QString modulesConfigDirPath();
461+
462+
void GRASS_LIB_EXPORT setModulesConfig( bool custom, const QString &customDir );
463+
456464
/** Show warning dialog with message */
457465
static GRASS_LIB_EXPORT void warning( const QString &message );
458466

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

482+
/** Emited when path to modules config dir changed */
483+
void modulesConfigChanged();
484+
474485
private:
475486
static int initialized; // Set to 1 after initialization
476487
static bool active; // is active mode

src/providers/grass/qgsgrassoptions.cpp

+38-2
Original file line numberDiff line numberDiff line change
@@ -13,38 +13,74 @@
1313
* (at your option) any later version. *
1414
* *
1515
***************************************************************************/
16+
17+
#include <QFileDialog>
18+
1619
#include "qgsrasterprojector.h"
1720

21+
#include "qgsgrass.h"
1822
#include "qgsgrassoptions.h"
1923
#include "ui_qgsgrassoptionsbase.h"
2024

2125
QgsGrassOptions::QgsGrassOptions( QWidget *parent )
22-
: QDialog( parent )
26+
: QgsOptionsDialogBase( "GrassOptions", parent )
2327
, QgsGrassOptionsBase()
2428
, mImportSettingsPath( "/GRASS/browser/import" )
29+
, mModulesSettingsPath( "/GRASS/modules/config" )
2530
{
2631
setupUi( this );
32+
initOptionsBase( false );
2733

28-
connect( this, SIGNAL( accepted() ), this, SLOT( saveOptions() ) );
34+
connect( this, SIGNAL( accepted() ), SLOT( saveOptions() ) );
35+
connect( buttonBox->button( QDialogButtonBox::Apply ), SIGNAL( clicked() ), SLOT( saveOptions() ) );
2936

3037
QSettings settings;
3138

39+
// Modules
40+
bool customModules = settings.value( mModulesSettingsPath + "/custom", false ).toBool();
41+
QString customModulesDir = settings.value( mModulesSettingsPath + "/customDir" ).toString();
42+
mModulesConfigDefaultRadioButton->setText( tr( "Default" ) + " (" + QgsGrass::modulesConfigDefaultDirPath() + ")" );
43+
mModulesConfigDefaultRadioButton->setChecked( !customModules );
44+
mModulesConfigCustomRadioButton->setChecked( customModules );
45+
mModulesConfigDirLineEdit->setText( customModulesDir );
46+
47+
// Browser
3248
QgsRasterProjector::Precision crsTransform = ( QgsRasterProjector::Precision ) settings.value( mImportSettingsPath + "/crsTransform", QgsRasterProjector::Approximate ).toInt();
3349
mCrsTransformationComboBox->addItem( QgsRasterProjector::precisionLabel( QgsRasterProjector::Approximate ), QgsRasterProjector::Approximate );
3450
mCrsTransformationComboBox->addItem( QgsRasterProjector::precisionLabel( QgsRasterProjector::Exact ), QgsRasterProjector::Exact );
3551
mCrsTransformationComboBox->setCurrentIndex( mCrsTransformationComboBox->findData( crsTransform ) );
3652

3753
mImportExternalCheckBox->setChecked( settings.value( mImportSettingsPath + "/external", true ).toBool() );
54+
55+
restoreOptionsBaseUi();
3856
}
3957

4058
QgsGrassOptions::~QgsGrassOptions()
4159
{
4260
}
4361

62+
void QgsGrassOptions::on_mModulesConfigBrowseButton_clicked()
63+
{
64+
QString dir = QFileDialog::getExistingDirectory( this,
65+
tr( "Choose a directory with configuration files (default.qgc, *.qgm)" ),
66+
mModulesConfigDirLineEdit->text() );
67+
68+
if ( !dir.isEmpty() )
69+
{
70+
mModulesConfigDirLineEdit->setText( dir );
71+
}
72+
}
73+
4474
void QgsGrassOptions::saveOptions()
4575
{
4676
QSettings settings;
4777

78+
// Modules
79+
bool customModules = mModulesConfigCustomRadioButton->isChecked();
80+
QString customModulesDir = mModulesConfigDirLineEdit->text();
81+
QgsGrass::instance()->setModulesConfig( customModules, customModulesDir );
82+
83+
// Browser
4884
settings.setValue( mImportSettingsPath + "/crsTransform",
4985
mCrsTransformationComboBox->itemData( mCrsTransformationComboBox->currentIndex() ).toInt() );
5086

src/providers/grass/qgsgrassoptions.h

+5-2
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,11 @@
1818

1919
#include <QDialog>
2020

21+
#include "qgsoptionsdialogbase.h"
22+
2123
#include "ui_qgsgrassoptionsbase.h"
2224

23-
class GRASS_LIB_EXPORT QgsGrassOptions : public QDialog, private Ui::QgsGrassOptionsBase
25+
class GRASS_LIB_EXPORT QgsGrassOptions : public QgsOptionsDialogBase, private Ui::QgsGrassOptionsBase
2426
{
2527
Q_OBJECT
2628

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

3133
private slots:
34+
void on_mModulesConfigBrowseButton_clicked();
3235
void saveOptions();
3336

3437
private:
3538
QString mImportSettingsPath;
36-
39+
QString mModulesSettingsPath;
3740
};
3841

3942
#endif // QGSGRASSOPTIONS_H

0 commit comments

Comments
 (0)