From 32d7cc5e008ba489290cddf41901724af368689e Mon Sep 17 00:00:00 2001 From: Radim Blazek Date: Thu, 23 Jul 2015 20:58:06 +0200 Subject: [PATCH] [GRASS] optional modules config path --- src/plugins/grass/modules/CMakeLists.txt | 2 +- src/plugins/grass/qgsgrasstools.cpp | 13 +- src/plugins/grass/qgsgrasstools.h | 4 +- src/providers/grass/qgsgrass.cpp | 42 +++++ src/providers/grass/qgsgrass.h | 11 ++ src/providers/grass/qgsgrassoptions.cpp | 40 ++++- src/providers/grass/qgsgrassoptions.h | 7 +- src/providers/grass/qgsgrassoptionsbase.ui | 185 ++++++++++++++++----- 8 files changed, 254 insertions(+), 50 deletions(-) diff --git a/src/plugins/grass/modules/CMakeLists.txt b/src/plugins/grass/modules/CMakeLists.txt index 7f30242143e..ecec7678cba 100644 --- a/src/plugins/grass/modules/CMakeLists.txt +++ b/src/plugins/grass/modules/CMakeLists.txt @@ -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) diff --git a/src/plugins/grass/qgsgrasstools.cpp b/src/plugins/grass/qgsgrasstools.cpp index 3696282e30f..74e05e99286 100644 --- a/src/plugins/grass/qgsgrasstools.cpp +++ b/src/plugins/grass/qgsgrasstools.cpp @@ -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 ); diff --git a/src/plugins/grass/qgsgrasstools.h b/src/plugins/grass/qgsgrasstools.h index be78df48f83..fe095e543cf 100644 --- a/src/plugins/grass/qgsgrasstools.h +++ b/src/plugins/grass/qgsgrasstools.h @@ -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 ); diff --git a/src/providers/grass/qgsgrass.cpp b/src/providers/grass/qgsgrass.cpp index 278ca315fa7..77b55e8b3e5 100644 --- a/src/providers/grass/qgsgrass.cpp +++ b/src/providers/grass/qgsgrass.cpp @@ -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 ); diff --git a/src/providers/grass/qgsgrass.h b/src/providers/grass/qgsgrass.h index 4ad5133d82d..2168c9252f5 100644 --- a/src/providers/grass/qgsgrass.h +++ b/src/providers/grass/qgsgrass.h @@ -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 diff --git a/src/providers/grass/qgsgrassoptions.cpp b/src/providers/grass/qgsgrassoptions.cpp index 3d15c8e3c6b..13c8f467fcd 100644 --- a/src/providers/grass/qgsgrassoptions.cpp +++ b/src/providers/grass/qgsgrassoptions.cpp @@ -13,38 +13,74 @@ * (at your option) any later version. * * * ***************************************************************************/ + +#include + #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() ); diff --git a/src/providers/grass/qgsgrassoptions.h b/src/providers/grass/qgsgrassoptions.h index 2345b5416f4..917d2400f33 100644 --- a/src/providers/grass/qgsgrassoptions.h +++ b/src/providers/grass/qgsgrassoptions.h @@ -18,9 +18,11 @@ #include +#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 diff --git a/src/providers/grass/qgsgrassoptionsbase.ui b/src/providers/grass/qgsgrassoptionsbase.ui index b2cf4af5aac..5d126230ade 100644 --- a/src/providers/grass/qgsgrassoptionsbase.ui +++ b/src/providers/grass/qgsgrassoptionsbase.ui @@ -6,8 +6,8 @@ 0 0 - 590 - 400 + 616 + 411 @@ -74,6 +74,15 @@ true + + + Modules + + + + :/images/themes/default/grass_mapset.png:/images/themes/default/grass_mapset.png + + Browser @@ -81,6 +90,10 @@ Browser + + + :/images/icons/qbrowser-icon-60x60.png:/images/icons/qbrowser-icon-60x60.png + @@ -97,37 +110,125 @@ QFrame::NoFrame - QFrame::Raised + QFrame::Plain - - - 0 - + + + 0 + 0 - + + + + + + QFrame::NoFrame + + + QFrame::Plain + + + 0 + + + true + + + + + 0 + 0 + 439 + 350 + + + + + + + Modules interface configuration + + + + + + Default + + + + + + + + + Custom + + + + + + + + + + Browse + + + + + + + + + + + + Qt::Vertical + + + + 20 + 246 + + + + + + + + + + + 0 - + QFrame::NoFrame + + QFrame::Plain + + + 0 + true - + 0 0 - 429 - 363 + 447 + 358 @@ -207,13 +308,31 @@ - - - Qt::Horizontal + + + + 0 + 0 + - - QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + QFrame::NoFrame + + QFrame::Raised + + + + + + Qt::Horizontal + + + QDialogButtonBox::Apply|QDialogButtonBox::Cancel|QDialogButtonBox::Help|QDialogButtonBox::Ok + + + + @@ -231,34 +350,18 @@ - mButtonBox - accepted() - QgsGrassOptionsBase - accept() + mOptionsListWidget + currentRowChanged(int) + mOptionsStackedWidget + setCurrentIndex(int) - 248 - 254 + 78 + 186 - 157 - 274 - - - - - mButtonBox - rejected() - QgsGrassOptionsBase - reject() - - - 316 - 260 - - - 286 - 274 + 384 + 186