Skip to content

Commit

Permalink
[layouts] improve right-click popup menu
Browse files Browse the repository at this point in the history
- as with the main window, show bold titles
- sort toolbars and panels alphabetically
  • Loading branch information
nirvn committed Feb 19, 2018
1 parent 6da78b9 commit 007009f
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 13 deletions.
75 changes: 68 additions & 7 deletions src/app/layout/qgslayoutdesignerdialog.cpp
Expand Up @@ -79,6 +79,7 @@
#include <QPrinter>
#include <QPrintDialog>
#include <QPageSetupDialog>
#include <QWidgetAction>
#ifdef Q_OS_MACX
#include <ApplicationServices/ApplicationServices.h>
#endif
Expand Down Expand Up @@ -630,7 +631,7 @@ QgsLayoutDesignerDialog::QgsLayoutDesignerDialog( QWidget *parent, Qt::WindowFla
int minDockWidth( fontMetrics().width( QStringLiteral( "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" ) ) );

setTabPosition( Qt::AllDockWidgetAreas, QTabWidget::North );
mGeneralDock = new QgsDockWidget( tr( "Layout" ), this );
mGeneralDock = new QgsDockWidget( tr( "Layout Panel" ), this );
mGeneralDock->setObjectName( QStringLiteral( "LayoutDock" ) );
mGeneralDock->setMinimumWidth( minDockWidth );
mGeneralPropertiesStack = new QgsPanelWidgetStack();
Expand All @@ -641,14 +642,14 @@ QgsLayoutDesignerDialog::QgsLayoutDesignerDialog( QWidget *parent, Qt::WindowFla
mGeneralDock->setUserVisible( true );
} );

mItemDock = new QgsDockWidget( tr( "Item Properties" ), this );
mItemDock = new QgsDockWidget( tr( "Item Properties Panel" ), this );
mItemDock->setObjectName( QStringLiteral( "ItemDock" ) );
mItemDock->setMinimumWidth( minDockWidth );
mItemPropertiesStack = new QgsPanelWidgetStack();
mItemDock->setWidget( mItemPropertiesStack );
mPanelsMenu->addAction( mItemDock->toggleViewAction() );

mGuideDock = new QgsDockWidget( tr( "Guides" ), this );
mGuideDock = new QgsDockWidget( tr( "Guides Panel" ), this );
mGuideDock->setObjectName( QStringLiteral( "GuideDock" ) );
mGuideDock->setMinimumWidth( minDockWidth );
mGuideStack = new QgsPanelWidgetStack();
Expand All @@ -659,25 +660,25 @@ QgsLayoutDesignerDialog::QgsLayoutDesignerDialog( QWidget *parent, Qt::WindowFla
mGuideDock->setUserVisible( true );
} );

mUndoDock = new QgsDockWidget( tr( "Undo History" ), this );
mUndoDock = new QgsDockWidget( tr( "Undo History Panel" ), this );
mUndoDock->setObjectName( QStringLiteral( "UndoDock" ) );
mPanelsMenu->addAction( mUndoDock->toggleViewAction() );
mUndoView = new QUndoView( this );
mUndoDock->setWidget( mUndoView );

mItemsDock = new QgsDockWidget( tr( "Items" ), this );
mItemsDock = new QgsDockWidget( tr( "Items Panel" ), this );
mItemsDock->setObjectName( QStringLiteral( "ItemsDock" ) );
mPanelsMenu->addAction( mItemsDock->toggleViewAction() );

//items tree widget
mItemsTreeView = new QgsLayoutItemsListView( mItemsDock, this );
mItemsDock->setWidget( mItemsTreeView );

mAtlasDock = new QgsDockWidget( tr( "Atlas" ), this );
mAtlasDock = new QgsDockWidget( tr( "Atlas Panel" ), this );
mAtlasDock->setObjectName( QStringLiteral( "AtlasDock" ) );
connect( mAtlasDock, &QDockWidget::visibilityChanged, mActionAtlasSettings, &QAction::setChecked );

mReportDock = new QgsDockWidget( tr( "Report Organizer" ), this );
mReportDock = new QgsDockWidget( tr( "Report Organizer Panel" ), this );
mReportDock->setObjectName( QStringLiteral( "ReportDock" ) );
connect( mReportDock, &QDockWidget::visibilityChanged, mActionReportSettings, &QAction::setChecked );

Expand Down Expand Up @@ -739,6 +740,66 @@ QgsAppLayoutDesignerInterface *QgsLayoutDesignerDialog::iface()
return mInterface;
}

static bool cmpByText_( QAction *a, QAction *b )
{
return QString::localeAwareCompare( a->text(), b->text() ) < 0;
}

QMenu *QgsLayoutDesignerDialog::createPopupMenu()
{
QMenu *menu = QMainWindow::createPopupMenu();
QList< QAction * > al = menu->actions();
QList< QAction * > panels, toolbars;

if ( !al.isEmpty() )
{
bool found = false;
for ( int i = 0; i < al.size(); ++i )
{
if ( al[ i ]->isSeparator() )
{
found = true;
continue;
}

if ( !found )
{
panels.append( al[ i ] );
}
else
{
toolbars.append( al[ i ] );
}
}

std::sort( panels.begin(), panels.end(), cmpByText_ );
QWidgetAction *panelstitle = new QWidgetAction( menu );
QLabel *plabel = new QLabel( QStringLiteral( "<b>%1</b>" ).arg( tr( "Panels" ) ) );
plabel->setMargin( 3 );
plabel->setAlignment( Qt::AlignHCenter );
panelstitle->setDefaultWidget( plabel );
menu->addAction( panelstitle );
Q_FOREACH ( QAction *a, panels )
{
menu->addAction( a );
}
menu->addSeparator();
QWidgetAction *toolbarstitle = new QWidgetAction( menu );
QLabel *tlabel = new QLabel( QStringLiteral( "<b>%1</b>" ).arg( tr( "Toolbars" ) ) );
tlabel->setMargin( 3 );
tlabel->setAlignment( Qt::AlignHCenter );
toolbarstitle->setDefaultWidget( tlabel );
menu->addAction( toolbarstitle );
std::sort( toolbars.begin(), toolbars.end(), cmpByText_ );
Q_FOREACH ( QAction *a, toolbars )
{
menu->addAction( a );
}
}

return menu;
}

QgsLayout *QgsLayoutDesignerDialog::currentLayout()
{
return mLayout;
Expand Down
5 changes: 5 additions & 0 deletions src/app/layout/qgslayoutdesignerdialog.h
Expand Up @@ -150,6 +150,11 @@ class QgsLayoutDesignerDialog: public QMainWindow, private Ui::QgsLayoutDesigner
*/
void setSectionTitle( const QString &title );

/**
* Overloaded function used to sort menu entries alphabetically
*/
QMenu *createPopupMenu() override;

public slots:

/**
Expand Down
12 changes: 6 additions & 6 deletions src/ui/layout/qgslayoutdesignerbase.ui
Expand Up @@ -54,7 +54,7 @@
<widget class="QStatusBar" name="mStatusBar"/>
<widget class="QToolBar" name="mLayoutToolbar">
<property name="windowTitle">
<string>Layout</string>
<string>Layout Toolbar</string>
</property>
<attribute name="toolBarArea">
<enum>TopToolBarArea</enum>
Expand All @@ -79,7 +79,7 @@
</widget>
<widget class="QToolBar" name="mToolsToolbar">
<property name="windowTitle">
<string>Toolbox</string>
<string>Toolbox Toolbar</string>
</property>
<attribute name="toolBarArea">
<enum>TopToolBarArea</enum>
Expand Down Expand Up @@ -306,7 +306,7 @@
</widget>
<widget class="QToolBar" name="mNavigationToolbar">
<property name="windowTitle">
<string>Navigation</string>
<string>Navigation Toolbar</string>
</property>
<attribute name="toolBarArea">
<enum>TopToolBarArea</enum>
Expand All @@ -322,7 +322,7 @@
</widget>
<widget class="QToolBar" name="mActionsToolbar">
<property name="windowTitle">
<string>Actions</string>
<string>Actions Toolbar</string>
</property>
<attribute name="toolBarArea">
<enum>TopToolBarArea</enum>
Expand All @@ -337,7 +337,7 @@
</widget>
<widget class="QToolBar" name="mAtlasToolbar">
<property name="windowTitle">
<string>Atlas</string>
<string>Atlas Toolbar</string>
</property>
<attribute name="toolBarArea">
<enum>TopToolBarArea</enum>
Expand All @@ -355,7 +355,7 @@
</widget>
<widget class="QToolBar" name="mReportToolbar">
<property name="windowTitle">
<string>Report</string>
<string>Report Toolbar</string>
</property>
<attribute name="toolBarArea">
<enum>TopToolBarArea</enum>
Expand Down

0 comments on commit 007009f

Please sign in to comment.