Skip to content
Permalink
Browse files
Fix duplication of main app's Window and Help menu to composers for Mac
  • Loading branch information
dakcarto committed Feb 21, 2013
1 parent 417e119 commit a71946c184cec163d1104d6992d58851748ee025
Showing with 79 additions and 6 deletions.
  1. +55 −6 src/app/composer/qgscomposer.cpp
  2. +24 −0 src/app/composer/qgscomposer.h
@@ -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();
@@ -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;
@@ -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;
}
@@ -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.