mirror of
https://github.com/qgis/QGIS.git
synced 2025-02-25 00:58:06 -05:00
[GRASS] optional modules config path
This commit is contained in:
parent
266aa7bc95
commit
32d7cc5e00
@ -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
|
||||
|
@ -6,8 +6,8 @@
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>590</width>
|
||||
<height>400</height>
|
||||
<width>616</width>
|
||||
<height>411</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
@ -74,6 +74,15 @@
|
||||
<property name="wordWrap">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>Modules</string>
|
||||
</property>
|
||||
<property name="icon">
|
||||
<iconset resource="../../../images/images.qrc">
|
||||
<normaloff>:/images/themes/default/grass_mapset.png</normaloff>:/images/themes/default/grass_mapset.png</iconset>
|
||||
</property>
|
||||
</item>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>Browser</string>
|
||||
@ -81,6 +90,10 @@
|
||||
<property name="toolTip">
|
||||
<string>Browser</string>
|
||||
</property>
|
||||
<property name="icon">
|
||||
<iconset resource="../../../images/images.qrc">
|
||||
<normaloff>:/images/icons/qbrowser-icon-60x60.png</normaloff>:/images/icons/qbrowser-icon-60x60.png</iconset>
|
||||
</property>
|
||||
</item>
|
||||
</widget>
|
||||
</item>
|
||||
@ -97,37 +110,125 @@
|
||||
<enum>QFrame::NoFrame</enum>
|
||||
</property>
|
||||
<property name="frameShadow">
|
||||
<enum>QFrame::Raised</enum>
|
||||
<enum>QFrame::Plain</enum>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<property name="margin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_6">
|
||||
<item>
|
||||
<widget class="QStackedWidget" name="mOptionsStackedWidget">
|
||||
<property name="lineWidth">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="currentIndex">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<widget class="QWidget" name="mBrowserOptionsPage">
|
||||
<widget class="QWidget" name="mModulesPage">
|
||||
<layout class="QVBoxLayout" name="verticalLayout_7">
|
||||
<item>
|
||||
<widget class="QScrollArea" name="mModulesScrollArea">
|
||||
<property name="frameShape">
|
||||
<enum>QFrame::NoFrame</enum>
|
||||
</property>
|
||||
<property name="frameShadow">
|
||||
<enum>QFrame::Plain</enum>
|
||||
</property>
|
||||
<property name="lineWidth">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="widgetResizable">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<widget class="QWidget" name="mModulesContents">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>439</width>
|
||||
<height>350</height>
|
||||
</rect>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<item>
|
||||
<widget class="QgsCollapsibleGroupBox" name="mModulesConfigGroupBox">
|
||||
<property name="title">
|
||||
<string>Modules interface configuration</string>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_4">
|
||||
<item>
|
||||
<widget class="QRadioButton" name="mModulesConfigDefaultRadioButton">
|
||||
<property name="text">
|
||||
<string>Default</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_3">
|
||||
<item>
|
||||
<widget class="QRadioButton" name="mModulesConfigCustomRadioButton">
|
||||
<property name="text">
|
||||
<string>Custom</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLineEdit" name="mModulesConfigDirLineEdit"/>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="mModulesConfigBrowseButton">
|
||||
<property name="text">
|
||||
<string>Browse</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="verticalSpacer_2">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Vertical</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>20</width>
|
||||
<height>246</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<widget class="QWidget" name="mBrowserPage">
|
||||
<layout class="QVBoxLayout" name="verticalLayout_3">
|
||||
<property name="margin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<item>
|
||||
<widget class="QScrollArea" name="mBrowserOptionsScrollArea">
|
||||
<widget class="QScrollArea" name="mBrowserScrollArea">
|
||||
<property name="frameShape">
|
||||
<enum>QFrame::NoFrame</enum>
|
||||
</property>
|
||||
<property name="frameShadow">
|
||||
<enum>QFrame::Plain</enum>
|
||||
</property>
|
||||
<property name="lineWidth">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="widgetResizable">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<widget class="QWidget" name="mBrowserOptionsScrollAreaContents">
|
||||
<widget class="QWidget" name="mBrowserContents">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>429</width>
|
||||
<height>363</height>
|
||||
<width>447</width>
|
||||
<height>358</height>
|
||||
</rect>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_28">
|
||||
@ -207,13 +308,31 @@
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QDialogButtonBox" name="mButtonBox">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
<widget class="QFrame" name="mButtonBoxFrame">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Preferred" vsizetype="Maximum">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="standardButtons">
|
||||
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
|
||||
<property name="frameShape">
|
||||
<enum>QFrame::NoFrame</enum>
|
||||
</property>
|
||||
<property name="frameShadow">
|
||||
<enum>QFrame::Raised</enum>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout">
|
||||
<item row="0" column="0">
|
||||
<widget class="QDialogButtonBox" name="buttonBox">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="standardButtons">
|
||||
<set>QDialogButtonBox::Apply|QDialogButtonBox::Cancel|QDialogButtonBox::Help|QDialogButtonBox::Ok</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
@ -231,34 +350,18 @@
|
||||
</resources>
|
||||
<connections>
|
||||
<connection>
|
||||
<sender>mButtonBox</sender>
|
||||
<signal>accepted()</signal>
|
||||
<receiver>QgsGrassOptionsBase</receiver>
|
||||
<slot>accept()</slot>
|
||||
<sender>mOptionsListWidget</sender>
|
||||
<signal>currentRowChanged(int)</signal>
|
||||
<receiver>mOptionsStackedWidget</receiver>
|
||||
<slot>setCurrentIndex(int)</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>248</x>
|
||||
<y>254</y>
|
||||
<x>78</x>
|
||||
<y>186</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>157</x>
|
||||
<y>274</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
<connection>
|
||||
<sender>mButtonBox</sender>
|
||||
<signal>rejected()</signal>
|
||||
<receiver>QgsGrassOptionsBase</receiver>
|
||||
<slot>reject()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>316</x>
|
||||
<y>260</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>286</x>
|
||||
<y>274</y>
|
||||
<x>384</x>
|
||||
<y>186</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
|
Loading…
x
Reference in New Issue
Block a user