Skip to content

Commit

Permalink
Fix #7287, keep composer listings sorted in menus and manager
Browse files Browse the repository at this point in the history
  • Loading branch information
dakcarto committed Mar 7, 2013
1 parent b6cbb7b commit 4a36cbd
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/app/composer/qgscomposer.cpp
Expand Up @@ -81,6 +81,12 @@
#include <QProgressDialog>


// sort function for QList<QAction*>, e.g. menu listings
static bool cmpByText_( QAction* a, QAction* b )
{
return QString::localeAwareCompare( a->text(), b->text() ) < 0;
}

QgsComposer::QgsComposer( QgisApp *qgis, const QString& title )
: QMainWindow()
, mTitle( title )
Expand Down Expand Up @@ -2120,7 +2126,13 @@ void QgsComposer::initialiseComposerPicturePreviews()
void QgsComposer::populatePrintComposersMenu()
{
mPrintComposersMenu->clear();
mPrintComposersMenu->addActions( mQgis->printComposersMenu()->actions() );
QList<QAction*> acts = mQgis->printComposersMenu()->actions();
if ( acts.size() > 1 )
{
// sort actions in case main app's aboutToShow slot has not yet
qSort( acts.begin(), acts.end(), cmpByText_ );
}
mPrintComposersMenu->addActions( acts );
}

void QgsComposer::populateWindowMenu()
Expand Down
6 changes: 6 additions & 0 deletions src/app/composer/qgscomposermanager.cpp
Expand Up @@ -77,6 +77,7 @@ void QgsComposerManager::initialize()
item->setFlags( Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsEditable );
mItemComposerMap.insert( item, *it );
}
mComposerListWidget->sortItems();

mTemplate->addItem( tr( "Empty composer" ) );
mTemplate->addItem( tr( "Specific" ) );
Expand Down Expand Up @@ -198,6 +199,8 @@ void QgsComposerManager::on_mAddButton_clicked()
QListWidgetItem* item = new QListWidgetItem( newComposer->title(), mComposerListWidget );
item->setFlags( Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsEditable );
mItemComposerMap.insert( item, newComposer );

mComposerListWidget->sortItems();
mComposerListWidget->setCurrentItem( item );
mComposerListWidget->setFocus();
}
Expand Down Expand Up @@ -429,6 +432,8 @@ void QgsComposerManager::rename_clicked()
}
currentComposer->setTitle( newTitle );
item->setText( newTitle );

mComposerListWidget->sortItems();
}

void QgsComposerManager::on_mComposerListWidget_itemChanged( QListWidgetItem * item )
Expand All @@ -438,4 +443,5 @@ void QgsComposerManager::on_mComposerListWidget_itemChanged( QListWidgetItem * i
{
it.value()->setTitle( item->text() );
}
mComposerListWidget->sortItems();
}
12 changes: 12 additions & 0 deletions src/app/qgisapp.cpp
Expand Up @@ -4800,6 +4800,18 @@ void QgisApp::deletePrintComposers()
markDirty();
}

void QgisApp::on_mPrintComposersMenu_aboutToShow()
{
QList<QAction*> acts = mPrintComposersMenu->actions();
mPrintComposersMenu->clear();
if ( acts.size() > 1 )
{
// sort actions by text
qSort( acts.begin(), acts.end(), cmpByText_ );
}
mPrintComposersMenu->addActions( acts );
}

bool QgisApp::loadAnnotationItemsFromProject( const QDomDocument& doc )
{
if ( !mMapCanvas )
Expand Down
5 changes: 5 additions & 0 deletions src/app/qgisapp.h
Expand Up @@ -993,6 +993,11 @@ class QgisApp : public QMainWindow, private Ui::MainWindow
/**Creates the composer instances in a project file and adds them to the menu*/
bool loadComposersFromProject( const QDomDocument& doc );

/** Slot to handle display of composers menu, e.g. sorting
* @note added in 1.9
*/
void on_mPrintComposersMenu_aboutToShow();

bool loadAnnotationItemsFromProject( const QDomDocument& doc );

//! Toggles whether to show pinned labels
Expand Down

0 comments on commit 4a36cbd

Please sign in to comment.