Skip to content

Commit

Permalink
add menu option to reset to ui defaults (implements #9746)
Browse files Browse the repository at this point in the history
  • Loading branch information
jef-n committed Mar 8, 2014
1 parent 245422a commit 637359a
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 8 deletions.
28 changes: 21 additions & 7 deletions src/app/composer/qgscomposer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -214,22 +214,24 @@ QgsComposer::QgsComposer( QgisApp *qgis, const QString& title )
composerMenu->addAction( mActionPrint );
composerMenu->addSeparator();
composerMenu->addAction( mActionQuit );
QObject::connect( mActionQuit, SIGNAL( triggered() ), this, SLOT( close() ) );
connect( mActionQuit, SIGNAL( triggered() ), this, SLOT( close() ) );

//cut/copy/paste actions. Note these are not included in the ui file
//as ui files have no support for QKeySequence shortcuts
mActionCut = new QAction( tr( "Cu&t" ), this );
mActionCut->setShortcuts( QKeySequence::Cut );
mActionCut->setStatusTip( tr( "Cut" ) );
QObject::connect( mActionCut, SIGNAL( triggered() ), this, SLOT( actionCutTriggered() ) );
connect( mActionCut, SIGNAL( triggered() ), this, SLOT( actionCutTriggered() ) );

mActionCopy = new QAction( tr( "&Copy" ), this );
mActionCopy->setShortcuts( QKeySequence::Copy );
mActionCopy->setStatusTip( tr( "Copy" ) );
QObject::connect( mActionCopy, SIGNAL( triggered() ), this, SLOT( actionCopyTriggered() ) );
connect( mActionCopy, SIGNAL( triggered() ), this, SLOT( actionCopyTriggered() ) );

mActionPaste = new QAction( tr( "&Paste" ), this );
mActionPaste->setShortcuts( QKeySequence::Paste );
mActionPaste->setStatusTip( tr( "Paste" ) );
QObject::connect( mActionPaste, SIGNAL( triggered() ), this, SLOT( actionPasteTriggered() ) );
connect( mActionPaste, SIGNAL( triggered() ), this, SLOT( actionPasteTriggered() ) );

QMenu *editMenu = menuBar()->addMenu( tr( "Edit" ) );
editMenu->addAction( mActionUndo );
Expand Down Expand Up @@ -337,6 +339,7 @@ QgsComposer::QgsComposer( QgisApp *qgis, const QString& title )

QMenu *settingsMenu = menuBar()->addMenu( tr( "Settings" ) );
settingsMenu->addAction( mActionOptions );
settingsMenu->addAction( mActionResetUIdefaults );

#ifdef Q_WS_MAC
// this doesn't work on Mac anymore: menuBar()->addMenu( mQgis->windowMenu() );
Expand Down Expand Up @@ -2496,6 +2499,17 @@ void QgsComposer::restoreWindowState()
}
}

void QgsComposer::on_mActionResetUIdefaults_triggered()
{
if ( QMessageBox::warning( this, tr( "Restore UI defaults" ), tr( "Are you sure to reset the UI to default?" ), QMessageBox::Ok | QMessageBox::Cancel ) == QMessageBox::Cancel )
return;

saveWindowState();
QSettings settings;
settings.remove( "/ComposerUI/state" );
restoreWindowState();
}

void QgsComposer::writeXML( QDomDocument& doc )
{

Expand Down Expand Up @@ -2593,9 +2607,9 @@ void QgsComposer::readXML( const QDomElement& composerElem, const QDomDocument&

//create compositionwidget
QgsCompositionWidget* compositionWidget = new QgsCompositionWidget( mGeneralDock, mComposition );
QObject::connect( mComposition, SIGNAL( paperSizeChanged() ), compositionWidget, SLOT( displayCompositionWidthHeight() ) );
QObject::connect( this, SIGNAL( printAsRasterChanged( bool ) ), compositionWidget, SLOT( setPrintAsRasterCheckBox( bool ) ) );
QObject::connect( compositionWidget, SIGNAL( pageOrientationChanged( QString ) ), this, SLOT( setPrinterPageOrientation( QString ) ) );
connect( mComposition, SIGNAL( paperSizeChanged() ), compositionWidget, SLOT( displayCompositionWidthHeight() ) );
connect( this, SIGNAL( printAsRasterChanged( bool ) ), compositionWidget, SLOT( setPrintAsRasterCheckBox( bool ) ) );
connect( compositionWidget, SIGNAL( pageOrientationChanged( QString ) ), this, SLOT( setPrinterPageOrientation( QString ) ) );
mGeneralDock->setWidget( compositionWidget );

//read and restore all the items
Expand Down
3 changes: 3 additions & 0 deletions src/app/composer/qgscomposer.h
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,9 @@ class QgsComposer: public QMainWindow, private Ui::QgsComposerBase
//!Show options dialog
void on_mActionOptions_triggered();

//! Restore the default window and toolbar state
void on_mActionResetUIdefaults_triggered();

//!Toggle atlas preview
void on_mActionAtlasPreview_triggered( bool checked );

Expand Down
17 changes: 16 additions & 1 deletion src/app/qgisapp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1097,6 +1097,7 @@ void QgisApp::createActions()
connect( mActionConfigureShortcuts, SIGNAL( triggered() ), this, SLOT( configureShortcuts() ) );
connect( mActionStyleManagerV2, SIGNAL( triggered() ), this, SLOT( showStyleManagerV2() ) );
connect( mActionCustomization, SIGNAL( triggered() ), this, SLOT( customize() ) );
connect( mActionResetUIdefaults, SIGNAL( triggered() ), this, SLOT( restoreDefaultWindowState() ) );

#ifdef Q_WS_MAC
// Window Menu Items
Expand Down Expand Up @@ -2351,7 +2352,7 @@ void QgisApp::saveWindowState()

void QgisApp::restoreWindowState()
{
// restore the toolbar and dock widgets postions using Qt4 settings API
// restore the toolbar and dock widgets positions using Qt4 settings API
QSettings settings;

if ( !restoreState( settings.value( "/UI/state", QByteArray::fromRawData(( char * )defaultUIstate, sizeof defaultUIstate ) ).toByteArray() ) )
Expand All @@ -2366,6 +2367,20 @@ void QgisApp::restoreWindowState()
}

}

void QgisApp::restoreDefaultWindowState()
{
if ( QMessageBox::warning( this, tr( "Restore UI defaults" ), tr( "Are you sure to reset the UI to default?" ), QMessageBox::Ok | QMessageBox::Cancel ) == QMessageBox::Cancel )
return;

saveWindowState();

QSettings settings;
settings.remove( "/UI/state" );

restoreWindowState();
}

///////////// END OF GUI SETUP ROUTINES ///////////////
void QgisApp::sponsors()
{
Expand Down
2 changes: 2 additions & 0 deletions src/app/qgisapp.h
Original file line number Diff line number Diff line change
Expand Up @@ -837,6 +837,8 @@ class APP_EXPORT QgisApp : public QMainWindow, private Ui::MainWindow
void saveWindowState();
//! Restore the window and toolbar state
void restoreWindowState();
//! Restore the default window and toolbar state
void restoreDefaultWindowState();
//! Save project. Returns true if the user selected a file to save to, false if not.
bool fileSave();
//! Save project as
Expand Down
6 changes: 6 additions & 0 deletions src/ui/qgisapp.ui
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@
<addaction name="mActionCustomization"/>
<addaction name="mActionOptions"/>
<addaction name="mActionSnappingOptions"/>
<addaction name="mActionResetUIdefaults"/>
</widget>
<widget class="QMenu" name="mRasterMenu">
<property name="title">
Expand Down Expand Up @@ -2156,6 +2157,11 @@ Acts on currently active editable layer</string>
<string>Fill Ring</string>
</property>
</action>
<action name="mActionResetUIdefaults">
<property name="text">
<string>Reset UI defaults</string>
</property>
</action>
</widget>
<resources>
<include location="../../images/images.qrc"/>
Expand Down
12 changes: 12 additions & 0 deletions src/ui/qgscomposerbase.ui
Original file line number Diff line number Diff line change
Expand Up @@ -836,6 +836,18 @@
<enum>QAction::PreferencesRole</enum>
</property>
</action>
<action name="mActionResetUIdefaults">
<property name="icon">
<iconset resource="../../images/images.qrc">
<normaloff>:/images/themes/default/mActionOptions.svg</normaloff>:/images/themes/default/mActionOptions.svg</iconset>
</property>
<property name="text">
<string>Reset UI defaults...</string>
</property>
<property name="menuRole">
<enum>QAction::PreferencesRole</enum>
</property>
</action>
<action name="mActionShowRulers">
<property name="text">
<string>Show Rulers</string>
Expand Down

0 comments on commit 637359a

Please sign in to comment.