Skip to content
Permalink
Browse files

Sort layouts in layout manager

  • Loading branch information
nyalldawson committed Dec 30, 2017
1 parent 19b0581 commit 3e12ec9dcbefcb1e573dfaccc53487336251d0a8
Showing with 28 additions and 6 deletions.
  1. +16 −6 src/app/layout/qgslayoutmanagerdialog.cpp
  2. +12 −0 src/app/layout/qgslayoutmanagerdialog.h
@@ -65,7 +65,9 @@ QgsLayoutManagerDialog::QgsLayoutManagerDialog( QWidget *parent, Qt::WindowFlags

mModel = new QgsLayoutManagerModel( QgsProject::instance()->layoutManager(),
this );
mLayoutListView->setModel( mModel );
mProxyModel = new QgsLayoutManagerProxyModel( mLayoutListView );
mProxyModel->setSourceModel( mModel );
mLayoutListView->setModel( mProxyModel );

connect( mButtonBox, &QDialogButtonBox::rejected, this, &QWidget::close );
connect( mLayoutListView->selectionModel(), &QItemSelectionModel::selectionChanged,
@@ -386,7 +388,7 @@ void QgsLayoutManagerDialog::removeClicked()
// Find the layouts that need to be deleted
for ( const QModelIndex &index : layoutItems )
{
QgsMasterLayoutInterface *l = mModel->layoutFromIndex( index );
QgsMasterLayoutInterface *l = mModel->layoutFromIndex( mProxyModel->mapToSource( index ) );
if ( l )
{
layoutList << l;
@@ -405,7 +407,7 @@ void QgsLayoutManagerDialog::showClicked()
const QModelIndexList layoutItems = mLayoutListView->selectionModel()->selectedRows();
for ( const QModelIndex &index : layoutItems )
{
if ( QgsMasterLayoutInterface *l = mModel->layoutFromIndex( index ) )
if ( QgsMasterLayoutInterface *l = mModel->layoutFromIndex( mProxyModel->mapToSource( index ) ) )
{
QgisApp::instance()->openLayoutDesignerDialog( l );
}
@@ -419,7 +421,7 @@ void QgsLayoutManagerDialog::duplicateClicked()
return;
}

QgsMasterLayoutInterface *currentLayout = mModel->layoutFromIndex( mLayoutListView->selectionModel()->selectedRows().at( 0 ) );
QgsMasterLayoutInterface *currentLayout = mModel->layoutFromIndex( mProxyModel->mapToSource( mLayoutListView->selectionModel()->selectedRows().at( 0 ) ) );
if ( !currentLayout )
return;
QString currentTitle = currentLayout->name();
@@ -459,7 +461,7 @@ void QgsLayoutManagerDialog::renameClicked()
return;
}

QgsMasterLayoutInterface *currentLayout = mModel->layoutFromIndex( mLayoutListView->selectionModel()->selectedRows().at( 0 ) );
QgsMasterLayoutInterface *currentLayout = mModel->layoutFromIndex( mProxyModel->mapToSource( mLayoutListView->selectionModel()->selectedRows().at( 0 ) ) );
if ( !currentLayout )
return;

@@ -474,7 +476,7 @@ void QgsLayoutManagerDialog::renameClicked()

void QgsLayoutManagerDialog::itemDoubleClicked( const QModelIndex &index )
{
if ( QgsMasterLayoutInterface *l = mModel->layoutFromIndex( index ) )
if ( QgsMasterLayoutInterface *l = mModel->layoutFromIndex( mProxyModel->mapToSource( index ) ) )
{
QgisApp::instance()->openLayoutDesignerDialog( l );
}
@@ -630,3 +632,11 @@ void QgsLayoutManagerModel::layoutRenamed( QgsMasterLayoutInterface *layout, con
QModelIndex index = createIndex( row, 0 );
emit dataChanged( index, index, QVector<int>() << Qt::DisplayRole );
}

QgsLayoutManagerProxyModel::QgsLayoutManagerProxyModel( QObject *parent )
: QSortFilterProxyModel( parent )
{
setDynamicSortFilter( true );
sort( 0 );
setSortCaseSensitivity( Qt::CaseInsensitive );
}
@@ -18,6 +18,7 @@
#define QGSLAYOUTMANAGERDIALOG_H

#include <QItemDelegate>
#include <QSortFilterProxyModel>

#include "ui_qgslayoutmanagerbase.h"

@@ -55,6 +56,16 @@ class QgsLayoutManagerModel : public QAbstractListModel
QgsLayoutManager *mLayoutManager = nullptr;
};

class QgsLayoutManagerProxyModel : public QSortFilterProxyModel
{
Q_OBJECT

public:

explicit QgsLayoutManagerProxyModel( QObject *parent );

};

/**
* A dialog that allows management of layouts within a project.
*/
@@ -94,6 +105,7 @@ class QgsLayoutManagerDialog: public QDialog, private Ui::QgsLayoutManagerBase
QPushButton *mDuplicateButton = nullptr;
QPushButton *mCreateReportButton = nullptr;
QgsLayoutManagerModel *mModel = nullptr;
QgsLayoutManagerProxyModel *mProxyModel = nullptr;

#ifdef Q_OS_MAC
void showEvent( QShowEvent *event );

0 comments on commit 3e12ec9

Please sign in to comment.
You can’t perform that action at this time.