Skip to content

Commit

Permalink
Add methods to get, add and remove plugins to mesh menu
Browse files Browse the repository at this point in the history
  • Loading branch information
DelazJ committed Jan 20, 2022
1 parent 0ef51fe commit 37ca339
Showing 1 changed file with 118 additions and 1 deletion.
119 changes: 118 additions & 1 deletion src/app/qgisapp.cpp
Expand Up @@ -14652,6 +14652,50 @@ QMenu *QgisApp::getWebMenu( const QString &menuName )
return menu;
}

QMenu *QgisApp::getMeshMenu( const QString &menuName )
{
if ( menuName.isEmpty() )
return mMeshMenu;

QString cleanedMenuName = menuName;
#ifdef Q_OS_MAC
// Mac doesn't have '&' keyboard shortcuts.
cleanedMenuName.remove( QChar( '&' ) );
#endif
QString dst = cleanedMenuName;
dst.remove( QChar( '&' ) );

QAction *before = nullptr;
QList<QAction *> actions = mMeshMenu->actions();
for ( int i = 0; i < actions.count(); i++ )
{
QString src = actions.at( i )->text();
src.remove( QChar( '&' ) );

int comp = dst.localeAwareCompare( src );
if ( comp < 0 )
{
// Add item before this one
before = actions.at( i );
break;
}
else if ( comp == 0 )
{
// Plugin menu item already exists
return actions.at( i )->menu();
}
}
// It doesn't exist, so create
QMenu *menu = new QMenu( cleanedMenuName, this );
menu->setObjectName( normalizedMenuName( cleanedMenuName ) );
if ( before )
mMeshMenu->insertMenu( before, menu );
else
mMeshMenu->addMenu( menu );

return menu;
}

void QgisApp::insertAddLayerAction( QAction *action )
{
mAddLayerMenu->insertAction( mActionAddLayerSeparator, action );
Expand Down Expand Up @@ -14721,7 +14765,7 @@ void QgisApp::addPluginToWebMenu( const QString &name, QAction *action )
QMenu *menu = getWebMenu( name );
menu->addAction( action );

// add the Vector menu to the menuBar if not added yet
// add the Web menu to the menuBar if not added yet
if ( mWebMenu->actions().count() != 1 )
return;

Expand Down Expand Up @@ -14759,6 +14803,55 @@ void QgisApp::addPluginToWebMenu( const QString &name, QAction *action )
menuBar()->insertMenu( firstRightStandardMenu()->menuAction(), mWebMenu );
}

void QgisApp::addPluginToMeshMenu( const QString &name, QAction *action )
{
QMenu *menu = getMeshMenu( name );
menu->addAction( action );

// add the Mesh menu to the menuBar if not added yet
if ( mMeshMenu->actions().count() != 1 )
return;

QAction *before = nullptr;
QList<QAction *> actions = menuBar()->actions();
for ( int i = 0; i < actions.count(); i++ )
{
// goes after Database menu, if present
if ( actions.at( i )->menu() == mDatabaseMenu )
{
before = actions.at( i += 1 );
// don't break here
}
// goes after Web menu, if present
if ( actions.at( i )->menu() == mWebMenu )
{
before = actions.at( i += 1 );
// don't break here
}

if ( actions.at( i )->menu() == mMeshMenu )
return;
}
for ( int i = 0; i < actions.count(); i++ )
{
// defaults to after Raster menu, which is already in qgisapp.ui
if ( actions.at( i )->menu() == mRasterMenu )
{
if ( !before )
{
before = actions.at( i += 1 );
break;
}
}
}

if ( before )
menuBar()->insertMenu( before, mMeshMenu );
else
// fallback insert
menuBar()->insertMenu( firstRightStandardMenu()->menuAction(), mMeshMenu );
}

void QgisApp::removePluginDatabaseMenu( const QString &name, QAction *action )
{
QMenu *menu = getDatabaseMenu( name );
Expand Down Expand Up @@ -14849,6 +14942,30 @@ void QgisApp::removePluginWebMenu( const QString &name, QAction *action )
}
}

void QgisApp::removePluginMeshMenu( const QString &name, QAction *action )
{
QMenu *menu = getMeshMenu( name );
menu->removeAction( action );
if ( menu->actions().isEmpty() )
{
mMeshMenu->removeAction( menu->menuAction() );
}

// remove the Mesh menu from the menuBar if there are no more actions
if ( !mMeshMenu->actions().isEmpty() )
return;

QList<QAction *> actions = menuBar()->actions();
for ( int i = 0; i < actions.count(); i++ )
{
if ( actions.at( i )->menu() == mMeshMenu )
{
menuBar()->removeAction( actions.at( i ) );
return;
}
}
}

int QgisApp::addPluginToolBarIcon( QAction *qAction )
{
mPluginToolBar->addAction( qAction );
Expand Down

0 comments on commit 37ca339

Please sign in to comment.