Skip to content
Permalink
Browse files

Use configpath for customization. Fix #6068

  • Loading branch information
NathanW2 committed Sep 8, 2012
1 parent f143507 commit 4a9a9f7dbb97d12f2b29237ec97fb7f93a9f2535
Showing with 53 additions and 46 deletions.
  1. +9 −1 src/app/main.cpp
  2. +36 −39 src/app/qgscustomization.cpp
  3. +8 −6 src/app/qgscustomization.h
@@ -504,14 +504,22 @@ int main( int argc, char *argv[] )
QCoreApplication::setApplicationName( "QGIS" );
QCoreApplication::setAttribute( Qt::AA_DontShowIconsInMenus, false );

QSettings* customizationsettings;
if ( !optionpath.isEmpty() || !configpath.isEmpty() )
{
// tell QSettings to use INI format and save the file in custom config path
QSettings::setDefaultFormat( QSettings::IniFormat );
QSettings::setPath( QSettings::IniFormat, QSettings::UserScope, optionpath.isEmpty() ? configpath : optionpath );
QString path = optionpath.isEmpty() ? configpath : optionpath;
QSettings::setPath( QSettings::IniFormat, QSettings::UserScope, path );
customizationsettings = new QSettings(QSettings::IniFormat, QSettings::UserScope, "QuantumGIS", "QGISCUSTOMIZATION");
}
else
{
customizationsettings = new QSettings( "QuantumGIS", "QGISCUSTOMIZATION" );
}

// Load and set possible default customization, must be done afterQgsApplication init and QSettings ( QCoreApplication ) init
QgsCustomization::instance()->setSettings( customizationsettings );
QgsCustomization::instance()->loadDefault();

#ifdef Q_OS_MACX
@@ -37,15 +37,14 @@
#include <QMetaObject>

#ifdef Q_OS_MACX
QgsCustomizationDialog::QgsCustomizationDialog( QWidget *parent )
QgsCustomizationDialog::QgsCustomizationDialog( QWidget *parent, QSettings settings )
: QMainWindow( parent, Qt::WindowSystemMenuHint ) // Modeless dialog with close button only
, mSettings( "QuantumGIS", "QGISCUSTOMIZATION" )
#else
QgsCustomizationDialog::QgsCustomizationDialog( QWidget *parent )
QgsCustomizationDialog::QgsCustomizationDialog( QWidget *parent, QSettings* settings )
: QMainWindow( parent )
, mSettings( "QuantumGIS", "QGISCUSTOMIZATION" )
#endif
{
mSettings = settings;
setupUi( this );
init();
QStringList myHeaders;
@@ -180,8 +179,8 @@ void QgsCustomizationDialog::settingsToTree( QSettings *theSettings )

void QgsCustomizationDialog::reset()
{
mSettings.sync();
settingsToTree( &mSettings );
mSettings->sync();
settingsToTree( mSettings );
}

void QgsCustomizationDialog::ok()
@@ -192,9 +191,9 @@ void QgsCustomizationDialog::ok()
void QgsCustomizationDialog::apply()
{
QgsDebugMsg( QString( "columnCount = %1" ).arg( treeWidget->columnCount() ) );
treeToSettings( &mSettings );
mSettings.setValue( QgsCustomization::instance()->statusPath(), QgsCustomization::User );
mSettings.sync();
treeToSettings( mSettings );
mSettings->setValue( QgsCustomization::instance()->statusPath(), QgsCustomization::User );
mSettings->sync();
}

void QgsCustomizationDialog::cancel()
@@ -601,7 +600,6 @@ QgsCustomization::QgsCustomization()
: pDialog( 0 )
, mEnabled( true )
, mStatusPath( "/Customization/status" )
, mSettings( "QuantumGIS", "QGISCUSTOMIZATION" )
{
QgsDebugMsg( "Entered" );
}
@@ -624,7 +622,7 @@ void QgsCustomization::updateMainWindow( QMenu * theToolBarMenu )
QMainWindow* mw = QgisApp::instance();
QMenuBar* menubar = mw->menuBar();

mSettings.beginGroup( "Customization/Menus" );
mSettings->beginGroup( "Customization/Menus" );

// hide menus and menu actions

@@ -633,7 +631,7 @@ void QgsCustomization::updateMainWindow( QMenu * theToolBarMenu )
if ( obj->inherits( "QMenu" ) )
{
QMenu* menu = qobject_cast<QMenu*>( obj );
bool visible = mSettings.value( menu->objectName(), true ).toBool();
bool visible = mSettings->value( menu->objectName(), true ).toBool();
if ( !visible )
{
menubar->removeAction( menu->menuAction() );
@@ -645,17 +643,17 @@ void QgsCustomization::updateMainWindow( QMenu * theToolBarMenu )
}
}

mSettings.endGroup();
mSettings->endGroup();

// remove toolbars, toolbar actions

mSettings.beginGroup( "Customization/Toolbars" );
mSettings->beginGroup( "Customization/Toolbars" );
foreach ( QObject* obj, mw->children() )
{
if ( obj->inherits( "QToolBar" ) )
{
QToolBar* tb = qobject_cast<QToolBar*>( obj );
bool visible = mSettings.value( tb->objectName(), true ).toBool();
bool visible = mSettings->value( tb->objectName(), true ).toBool();
if ( !visible )
{
mw->removeToolBar( tb );
@@ -664,47 +662,47 @@ void QgsCustomization::updateMainWindow( QMenu * theToolBarMenu )
}
else
{
mSettings.beginGroup( tb->objectName() );
mSettings->beginGroup( tb->objectName() );
// hide individual toolbar actions
foreach ( QAction* action, tb->actions() )
{
if ( action->objectName().isEmpty() )
{
continue;
}
visible = mSettings.value( action->objectName(), true ).toBool();
visible = mSettings->value( action->objectName(), true ).toBool();
if ( !visible )
tb->removeAction( action );
}
mSettings.endGroup();
mSettings->endGroup();
}
}
}

mSettings.endGroup();
mSettings->endGroup();

// remove dock widgets

mSettings.beginGroup( "Customization/Docks" );
mSettings->beginGroup( "Customization/Docks" );
foreach ( QObject* obj, mw->children() )
{
if ( obj->inherits( "QDockWidget" ) )
{
bool visible = mSettings.value( obj->objectName(), true ).toBool();
bool visible = mSettings->value( obj->objectName(), true ).toBool();
if ( !visible )
{
mw->removeDockWidget( qobject_cast<QDockWidget*>( obj ) );
}
}
}

mSettings.endGroup();
mSettings->endGroup();

// remove status bar widgets

if ( mSettings.value( "Customization/StatusBar", true ).toBool() )
if ( mSettings->value( "Customization/StatusBar", true ).toBool() )
{
mSettings.beginGroup( "Customization/StatusBar" );
mSettings->beginGroup( "Customization/StatusBar" );

QStatusBar* sb = mw->statusBar();
foreach ( QObject* obj, sb->children() )
@@ -716,15 +714,15 @@ void QgsCustomization::updateMainWindow( QMenu * theToolBarMenu )
{
continue;
}
bool visible = mSettings.value( widget->objectName(), true ).toBool();
bool visible = mSettings->value( widget->objectName(), true ).toBool();
if ( !visible )
{
sb->removeWidget( widget );
}
}
}

mSettings.endGroup();
mSettings->endGroup();
}
else
{
@@ -733,9 +731,9 @@ void QgsCustomization::updateMainWindow( QMenu * theToolBarMenu )
}
}

void QgsCustomization::updateMenu( QMenu* menu, QSettings& settings )
void QgsCustomization::updateMenu( QMenu* menu, QSettings* settings )
{
settings.beginGroup( menu->objectName() );
settings->beginGroup( menu->objectName() );
// hide individual menu actions and call recursively on visible submenus
foreach ( QAction* action, menu->actions() )
{
@@ -744,7 +742,7 @@ void QgsCustomization::updateMenu( QMenu* menu, QSettings& settings )
{
continue;
}
bool visible = settings.value( objName, true ).toBool();
bool visible = settings->value( objName, true ).toBool();
if ( !visible )
menu->removeAction( action );
else if ( action->menu() )
@@ -753,22 +751,22 @@ void QgsCustomization::updateMenu( QMenu* menu, QSettings& settings )
updateMenu( action->menu(), settings );
}
}
settings.endGroup();
settings->endGroup();
}

void QgsCustomization::openDialog( QWidget *parent )
{
QgsDebugMsg( "Entered" );
if ( !pDialog )
{
pDialog = new QgsCustomizationDialog( parent );
pDialog = new QgsCustomizationDialog( parent, mSettings );
}

// I am trying too enable switching widget status by clicking in main app, so I need non modal
pDialog->show();
}

void QgsCustomization::customizeWidget( QWidget * widget, QEvent * event )
void QgsCustomization::customizeWidget( QWidget * widget, QEvent * event, QSettings* settings )
{
Q_UNUSED( event );
// Test if the widget is child of QDialog
@@ -780,12 +778,11 @@ void QgsCustomization::customizeWidget( QWidget * widget, QEvent * event )
QgsDebugMsg( QString( "%1 x %2" ).arg( widget->metaObject()->className() ).arg( QDialog::staticMetaObject.className() ) );
QString path = "/Customization/Widgets/";

QgsCustomization::customizeWidget( path, widget );
QgsCustomization::customizeWidget( path, widget, settings );
}

void QgsCustomization::customizeWidget( QString thePath, QWidget * theWidget )
void QgsCustomization::customizeWidget( QString thePath, QWidget * theWidget, QSettings* settings )
{
QSettings mySettings( "QuantumGIS", "QGISCUSTOMIZATION" );
QString name = theWidget->objectName();
QString myPath = thePath;

@@ -808,11 +805,11 @@ void QgsCustomization::customizeWidget( QString thePath, QWidget * theWidget )

QString p = myPath + "/" + w->objectName();

bool on = mySettings.value( p, true ).toBool();
bool on = settings->value( p, true ).toBool();
//QgsDebugMsg( QString( "p = %1 on = %2" ).arg( p ).arg( on ) );
if ( on )
{
QgsCustomization::customizeWidget( myPath, w );
QgsCustomization::customizeWidget( myPath, w, settings);
}
else
{
@@ -862,7 +859,7 @@ void QgsCustomization::preNotify( QObject * receiver, QEvent * event, bool * don

if ( mEnabled && widget && event->type() == QEvent::Show )
{
QgsCustomization::customizeWidget( widget, event );
QgsCustomization::customizeWidget( widget, event, mSettings );
}
else if ( widget && event->type() == QEvent::MouseButtonPress )
{
@@ -921,7 +918,7 @@ void QgsCustomization::loadDefault()

bool val = fileSettings.value( p ).toBool();

mSettings.setValue( p, val );
mSettings->setValue( p, val );
}
mySettings.setValue( mStatusPath, QgsCustomization::Default );
}
@@ -34,7 +34,7 @@ class QgsCustomizationDialog : public QMainWindow, private Ui::QgsCustomizationD
{
Q_OBJECT
public:
QgsCustomizationDialog( QWidget *parent );
QgsCustomizationDialog( QWidget *parent, QSettings *settings );
~QgsCustomizationDialog();

// get item by path
@@ -95,7 +95,7 @@ class QgsCustomizationDialog : public QMainWindow, private Ui::QgsCustomizationD
QTreeWidgetItem * readWidgetsXmlNode( QDomNode theNode );

QString mLastDirSettingsName;
QSettings mSettings;
QSettings* mSettings;
};

class QgsCustomization : public QObject
@@ -114,8 +114,8 @@ class QgsCustomization : public QObject
static QgsCustomization* instance();

void openDialog( QWidget *parent );
static void customizeWidget( QWidget * widget, QEvent * event );
static void customizeWidget( QString path, QWidget * widget );
static void customizeWidget( QWidget * widget, QEvent * event, QSettings* settings );
static void customizeWidget( QString path, QWidget * widget, QSettings* settings );
static void removeFromLayout( QLayout *theLayout, QWidget * widget );

void updateMainWindow( QMenu * theToolBarMenu );
@@ -124,6 +124,8 @@ class QgsCustomization : public QObject
void setEnabled( bool enabled ) { mEnabled = enabled; }
bool isEnabled() const { return mEnabled; }

void setSettings( QSettings* settings ) { mSettings = settings ;}

// Load and set default customization
void loadDefault();

@@ -141,9 +143,10 @@ class QgsCustomization : public QObject
QgsCustomizationDialog *pDialog;

bool mEnabled;
QSettings* mSettings;
QString mStatusPath;

void updateMenu( QMenu* menu, QSettings& settings );
void updateMenu( QMenu* menu, QSettings* settings );
void createTreeItemMenus( );
void createTreeItemToolbars( );
void createTreeItemDocks( );
@@ -157,7 +160,6 @@ class QgsCustomization : public QObject

private:
static QgsCustomization* pinstance;
QSettings mSettings;

};
#endif // QGSCUSTOMIZATION_H

0 comments on commit 4a9a9f7

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