Skip to content

Commit 637359a

Browse files
committed
add menu option to reset to ui defaults (implements #9746)
1 parent 245422a commit 637359a

File tree

6 files changed

+60
-8
lines changed

6 files changed

+60
-8
lines changed

src/app/composer/qgscomposer.cpp

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -214,22 +214,24 @@ QgsComposer::QgsComposer( QgisApp *qgis, const QString& title )
214214
composerMenu->addAction( mActionPrint );
215215
composerMenu->addSeparator();
216216
composerMenu->addAction( mActionQuit );
217-
QObject::connect( mActionQuit, SIGNAL( triggered() ), this, SLOT( close() ) );
217+
connect( mActionQuit, SIGNAL( triggered() ), this, SLOT( close() ) );
218218

219219
//cut/copy/paste actions. Note these are not included in the ui file
220220
//as ui files have no support for QKeySequence shortcuts
221221
mActionCut = new QAction( tr( "Cu&t" ), this );
222222
mActionCut->setShortcuts( QKeySequence::Cut );
223223
mActionCut->setStatusTip( tr( "Cut" ) );
224-
QObject::connect( mActionCut, SIGNAL( triggered() ), this, SLOT( actionCutTriggered() ) );
224+
connect( mActionCut, SIGNAL( triggered() ), this, SLOT( actionCutTriggered() ) );
225+
225226
mActionCopy = new QAction( tr( "&Copy" ), this );
226227
mActionCopy->setShortcuts( QKeySequence::Copy );
227228
mActionCopy->setStatusTip( tr( "Copy" ) );
228-
QObject::connect( mActionCopy, SIGNAL( triggered() ), this, SLOT( actionCopyTriggered() ) );
229+
connect( mActionCopy, SIGNAL( triggered() ), this, SLOT( actionCopyTriggered() ) );
230+
229231
mActionPaste = new QAction( tr( "&Paste" ), this );
230232
mActionPaste->setShortcuts( QKeySequence::Paste );
231233
mActionPaste->setStatusTip( tr( "Paste" ) );
232-
QObject::connect( mActionPaste, SIGNAL( triggered() ), this, SLOT( actionPasteTriggered() ) );
234+
connect( mActionPaste, SIGNAL( triggered() ), this, SLOT( actionPasteTriggered() ) );
233235

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

338340
QMenu *settingsMenu = menuBar()->addMenu( tr( "Settings" ) );
339341
settingsMenu->addAction( mActionOptions );
342+
settingsMenu->addAction( mActionResetUIdefaults );
340343

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

2502+
void QgsComposer::on_mActionResetUIdefaults_triggered()
2503+
{
2504+
if ( QMessageBox::warning( this, tr( "Restore UI defaults" ), tr( "Are you sure to reset the UI to default?" ), QMessageBox::Ok | QMessageBox::Cancel ) == QMessageBox::Cancel )
2505+
return;
2506+
2507+
saveWindowState();
2508+
QSettings settings;
2509+
settings.remove( "/ComposerUI/state" );
2510+
restoreWindowState();
2511+
}
2512+
24992513
void QgsComposer::writeXML( QDomDocument& doc )
25002514
{
25012515

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

25942608
//create compositionwidget
25952609
QgsCompositionWidget* compositionWidget = new QgsCompositionWidget( mGeneralDock, mComposition );
2596-
QObject::connect( mComposition, SIGNAL( paperSizeChanged() ), compositionWidget, SLOT( displayCompositionWidthHeight() ) );
2597-
QObject::connect( this, SIGNAL( printAsRasterChanged( bool ) ), compositionWidget, SLOT( setPrintAsRasterCheckBox( bool ) ) );
2598-
QObject::connect( compositionWidget, SIGNAL( pageOrientationChanged( QString ) ), this, SLOT( setPrinterPageOrientation( QString ) ) );
2610+
connect( mComposition, SIGNAL( paperSizeChanged() ), compositionWidget, SLOT( displayCompositionWidthHeight() ) );
2611+
connect( this, SIGNAL( printAsRasterChanged( bool ) ), compositionWidget, SLOT( setPrintAsRasterCheckBox( bool ) ) );
2612+
connect( compositionWidget, SIGNAL( pageOrientationChanged( QString ) ), this, SLOT( setPrinterPageOrientation( QString ) ) );
25992613
mGeneralDock->setWidget( compositionWidget );
26002614

26012615
//read and restore all the items

src/app/composer/qgscomposer.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -326,6 +326,9 @@ class QgsComposer: public QMainWindow, private Ui::QgsComposerBase
326326
//!Show options dialog
327327
void on_mActionOptions_triggered();
328328

329+
//! Restore the default window and toolbar state
330+
void on_mActionResetUIdefaults_triggered();
331+
329332
//!Toggle atlas preview
330333
void on_mActionAtlasPreview_triggered( bool checked );
331334

src/app/qgisapp.cpp

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1097,6 +1097,7 @@ void QgisApp::createActions()
10971097
connect( mActionConfigureShortcuts, SIGNAL( triggered() ), this, SLOT( configureShortcuts() ) );
10981098
connect( mActionStyleManagerV2, SIGNAL( triggered() ), this, SLOT( showStyleManagerV2() ) );
10991099
connect( mActionCustomization, SIGNAL( triggered() ), this, SLOT( customize() ) );
1100+
connect( mActionResetUIdefaults, SIGNAL( triggered() ), this, SLOT( restoreDefaultWindowState() ) );
11001101

11011102
#ifdef Q_WS_MAC
11021103
// Window Menu Items
@@ -2351,7 +2352,7 @@ void QgisApp::saveWindowState()
23512352

23522353
void QgisApp::restoreWindowState()
23532354
{
2354-
// restore the toolbar and dock widgets postions using Qt4 settings API
2355+
// restore the toolbar and dock widgets positions using Qt4 settings API
23552356
QSettings settings;
23562357

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

23682369
}
2370+
2371+
void QgisApp::restoreDefaultWindowState()
2372+
{
2373+
if ( QMessageBox::warning( this, tr( "Restore UI defaults" ), tr( "Are you sure to reset the UI to default?" ), QMessageBox::Ok | QMessageBox::Cancel ) == QMessageBox::Cancel )
2374+
return;
2375+
2376+
saveWindowState();
2377+
2378+
QSettings settings;
2379+
settings.remove( "/UI/state" );
2380+
2381+
restoreWindowState();
2382+
}
2383+
23692384
///////////// END OF GUI SETUP ROUTINES ///////////////
23702385
void QgisApp::sponsors()
23712386
{

src/app/qgisapp.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -837,6 +837,8 @@ class APP_EXPORT QgisApp : public QMainWindow, private Ui::MainWindow
837837
void saveWindowState();
838838
//! Restore the window and toolbar state
839839
void restoreWindowState();
840+
//! Restore the default window and toolbar state
841+
void restoreDefaultWindowState();
840842
//! Save project. Returns true if the user selected a file to save to, false if not.
841843
bool fileSave();
842844
//! Save project as

src/ui/qgisapp.ui

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,7 @@
192192
<addaction name="mActionCustomization"/>
193193
<addaction name="mActionOptions"/>
194194
<addaction name="mActionSnappingOptions"/>
195+
<addaction name="mActionResetUIdefaults"/>
195196
</widget>
196197
<widget class="QMenu" name="mRasterMenu">
197198
<property name="title">
@@ -2156,6 +2157,11 @@ Acts on currently active editable layer</string>
21562157
<string>Fill Ring</string>
21572158
</property>
21582159
</action>
2160+
<action name="mActionResetUIdefaults">
2161+
<property name="text">
2162+
<string>Reset UI defaults</string>
2163+
</property>
2164+
</action>
21592165
</widget>
21602166
<resources>
21612167
<include location="../../images/images.qrc"/>

src/ui/qgscomposerbase.ui

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -836,6 +836,18 @@
836836
<enum>QAction::PreferencesRole</enum>
837837
</property>
838838
</action>
839+
<action name="mActionResetUIdefaults">
840+
<property name="icon">
841+
<iconset resource="../../images/images.qrc">
842+
<normaloff>:/images/themes/default/mActionOptions.svg</normaloff>:/images/themes/default/mActionOptions.svg</iconset>
843+
</property>
844+
<property name="text">
845+
<string>Reset UI defaults...</string>
846+
</property>
847+
<property name="menuRole">
848+
<enum>QAction::PreferencesRole</enum>
849+
</property>
850+
</action>
839851
<action name="mActionShowRulers">
840852
<property name="text">
841853
<string>Show Rulers</string>

0 commit comments

Comments
 (0)