Skip to content

Commit

Permalink
Fix duplication of main app's Window and Help menu to composers for Mac
Browse files Browse the repository at this point in the history
  • Loading branch information
dakcarto committed Feb 21, 2013
1 parent 417e119 commit a71946c
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 6 deletions.
61 changes: 55 additions & 6 deletions src/app/composer/qgscomposer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ QgsComposer::QgsComposer( QgisApp *qgis, const QString& title )

mPrintComposersMenu = new QMenu( tr( "Print Composers" ), this );
mPrintComposersMenu->setObjectName( "mPrintComposersMenu" );
QObject::connect( mPrintComposersMenu, SIGNAL( aboutToShow() ), this, SLOT( populatePrintComposersMenu() ) );
connect( mPrintComposersMenu, SIGNAL( aboutToShow() ), this, SLOT( populatePrintComposersMenu() ) );
composerMenu->addMenu( mPrintComposersMenu );

composerMenu->addSeparator();
Expand Down Expand Up @@ -239,11 +239,17 @@ QgsComposer::QgsComposer( QgisApp *qgis, const QString& title )
layoutMenu->addAction( mActionMoveItemsToBottom );

#ifdef Q_WS_MAC
#ifndef Q_WS_MAC64 /* assertion failure in NSMenuItem setSubmenu (Qt 4.5.0-snapshot-20080830) */
menuBar()->addMenu( mQgis->windowMenu() );

menuBar()->addMenu( mQgis->helpMenu() );
#endif
// this doesn't work on Mac anymore: menuBar()->addMenu( mQgis->windowMenu() );
// QgsComposer::populateWithOtherMenu should work recursively with submenus and regardless of Qt version
mWindowMenu = new QMenu( tr( "Window" ), this );
mWindowMenu->setObjectName( "mWindowMenu" );
connect( mWindowMenu, SIGNAL( aboutToShow() ), this, SLOT( populateWindowMenu() ) );
menuBar()->addMenu( mWindowMenu );

mHelpMenu = new QMenu( tr( "Help" ) );
mHelpMenu->setObjectName( "mHelpMenu" );
connect( mHelpMenu, SIGNAL( aboutToShow() ), this, SLOT( populateHelpMenu() ) );
menuBar()->addMenu( mHelpMenu );
#endif

mFirstTime = true;
Expand Down Expand Up @@ -1998,3 +2004,46 @@ void QgsComposer::populatePrintComposersMenu()
mPrintComposersMenu->clear();
mPrintComposersMenu->addActions( mQgis->printComposersMenu()->actions() );
}

void QgsComposer::populateWindowMenu()
{
populateWithOtherMenu( mWindowMenu, mQgis->windowMenu() );
}

void QgsComposer::populateHelpMenu()
{
populateWithOtherMenu( mHelpMenu, mQgis->helpMenu() );
}

void QgsComposer::populateWithOtherMenu( QMenu* thisMenu, QMenu* otherMenu )
{
thisMenu->clear();
foreach ( QAction* act, otherMenu->actions() )
{
if ( act->menu() )
{
thisMenu->addMenu( mirrorOtherMenu( act->menu() ) );
}
else
{
thisMenu->addAction( act );
}
}
}

QMenu* QgsComposer::mirrorOtherMenu( QMenu* otherMenu )
{
QMenu* newMenu = new QMenu( otherMenu->title(), this );
foreach ( QAction* act, otherMenu->actions() )
{
if ( act->menu() )
{
newMenu->addMenu( mirrorOtherMenu( act->menu() ) );
}
else
{
newMenu->addAction( act );
}
}
return newMenu;
}
24 changes: 24 additions & 0 deletions src/app/composer/qgscomposer.h
Original file line number Diff line number Diff line change
Expand Up @@ -350,11 +350,35 @@ class QgsComposer: public QMainWindow, private Ui::QgsComposerBase
//! @note added in 1.9
QMenu* mPrintComposersMenu;

//! Window menu as mirror of main app's (on Mac)
//! @note added in 1.9
QMenu* mWindowMenu;

//! Help menu as mirror of main app's (on Mac)
//! @note added in 1.9
QMenu* mHelpMenu;

private slots:

//! Populate Print Composers menu from main app's
//! @note added in 1.9
void populatePrintComposersMenu();

//! Populate Window menu from main app's (on Mac)
//! @note added in 1.9
void populateWindowMenu();

//! Populate Help menu from main app's (on Mac)
//! @note added in 1.9
void populateHelpMenu();

//! Populate one menu from another menu (for Mac)
//! @note added in 1.9
void populateWithOtherMenu( QMenu* thisMenu, QMenu* otherMenu );

//! Create a duplicate of a menu (for Mac)
//! @note added in 1.9
QMenu* mirrorOtherMenu( QMenu* otherMenu );
};

#endif

0 comments on commit a71946c

Please sign in to comment.