Skip to content

Commit

Permalink
Port composer manager dialog to layouts
Browse files Browse the repository at this point in the history
Not exposed via GUI yet, but can be shown by entering

iface.showLayoutManager()

in the Python console
  • Loading branch information
nyalldawson committed Dec 6, 2017
1 parent 66b4b45 commit a30dd8a
Show file tree
Hide file tree
Showing 13 changed files with 970 additions and 24 deletions.
6 changes: 6 additions & 0 deletions python/gui/qgisinterface.sip
Original file line number Diff line number Diff line change
Expand Up @@ -927,6 +927,12 @@ Adds a widget to the user input tool bar.
The composition remains unaffected.
.. versionadded:: 3.0
.. seealso:: :py:func:`openComposer()`
%End

virtual void showLayoutManager() = 0;
%Docstring
Opens the layout manager dialog.
.. versionadded:: 3.0
%End

virtual QgsLayoutDesignerInterface *openLayoutDesigner( QgsLayout *layout ) = 0;
Expand Down
2 changes: 2 additions & 0 deletions src/app/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@ SET(QGIS_APP_SRCS
layout/qgslayoutlabelwidget.cpp
layout/qgslayoutlegendlayersdialog.cpp
layout/qgslayoutlegendwidget.cpp
layout/qgslayoutmanagerdialog.cpp
layout/qgslayoutmapwidget.cpp
layout/qgslayoutmapgridwidget.cpp
layout/qgslayoutpagepropertieswidget.cpp
Expand Down Expand Up @@ -402,6 +403,7 @@ SET (QGIS_APP_MOC_HDRS
layout/qgslayoutlabelwidget.h
layout/qgslayoutlegendwidget.h
layout/qgslayoutlegendlayersdialog.h
layout/qgslayoutmanagerdialog.h
layout/qgslayoutmapwidget.h
layout/qgslayoutmapgridwidget.h
layout/qgslayoutpagepropertieswidget.h
Expand Down
38 changes: 19 additions & 19 deletions src/app/composer/qgscomposermanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ QgsComposerManager::QgsComposerManager( QWidget *parent, Qt::WindowFlags f ): QD
QgsSettings settings;
restoreGeometry( settings.value( QStringLiteral( "Windows/ComposerManager/geometry" ) ).toByteArray() );

mModel = new QgsLayoutManagerModel( QgsProject::instance()->layoutManager(),
this );
mModel = new QgsComposerManagerModel( QgsProject::instance()->layoutManager(),
this );
mComposerListView->setModel( mModel );

connect( mButtonBox, &QDialogButtonBox::rejected, this, &QWidget::close );
Expand Down Expand Up @@ -440,27 +440,27 @@ void QgsComposerManager::renameClicked()
}

//
// QgsLayoutManagerModel
// QgsComposerManagerModel
//

QgsLayoutManagerModel::QgsLayoutManagerModel( QgsLayoutManager *manager, QObject *parent )
QgsComposerManagerModel::QgsComposerManagerModel( QgsLayoutManager *manager, QObject *parent )
: QAbstractListModel( parent )
, mLayoutManager( manager )
{
connect( mLayoutManager, &QgsLayoutManager::compositionAboutToBeAdded, this, &QgsLayoutManagerModel::compositionAboutToBeAdded );
connect( mLayoutManager, &QgsLayoutManager::compositionAdded, this, &QgsLayoutManagerModel::compositionAdded );
connect( mLayoutManager, &QgsLayoutManager::compositionAboutToBeRemoved, this, &QgsLayoutManagerModel::compositionAboutToBeRemoved );
connect( mLayoutManager, &QgsLayoutManager::compositionRemoved, this, &QgsLayoutManagerModel::compositionRemoved );
connect( mLayoutManager, &QgsLayoutManager::compositionRenamed, this, &QgsLayoutManagerModel::compositionRenamed );
connect( mLayoutManager, &QgsLayoutManager::compositionAboutToBeAdded, this, &QgsComposerManagerModel::compositionAboutToBeAdded );
connect( mLayoutManager, &QgsLayoutManager::compositionAdded, this, &QgsComposerManagerModel::compositionAdded );
connect( mLayoutManager, &QgsLayoutManager::compositionAboutToBeRemoved, this, &QgsComposerManagerModel::compositionAboutToBeRemoved );
connect( mLayoutManager, &QgsLayoutManager::compositionRemoved, this, &QgsComposerManagerModel::compositionRemoved );
connect( mLayoutManager, &QgsLayoutManager::compositionRenamed, this, &QgsComposerManagerModel::compositionRenamed );
}

int QgsLayoutManagerModel::rowCount( const QModelIndex &parent ) const
int QgsComposerManagerModel::rowCount( const QModelIndex &parent ) const
{
Q_UNUSED( parent );
return mLayoutManager->compositions().count();
}

QVariant QgsLayoutManagerModel::data( const QModelIndex &index, int role ) const
QVariant QgsComposerManagerModel::data( const QModelIndex &index, int role ) const
{
if ( index.row() < 0 || index.row() >= rowCount( QModelIndex() ) )
return QVariant();
Expand All @@ -480,7 +480,7 @@ QVariant QgsLayoutManagerModel::data( const QModelIndex &index, int role ) const
}
}

bool QgsLayoutManagerModel::setData( const QModelIndex &index, const QVariant &value, int role )
bool QgsComposerManagerModel::setData( const QModelIndex &index, const QVariant &value, int role )
{
if ( !index.isValid() || role != Qt::EditRole )
{
Expand Down Expand Up @@ -520,7 +520,7 @@ bool QgsLayoutManagerModel::setData( const QModelIndex &index, const QVariant &v
return true;
}

Qt::ItemFlags QgsLayoutManagerModel::flags( const QModelIndex &index ) const
Qt::ItemFlags QgsComposerManagerModel::flags( const QModelIndex &index ) const
{
Qt::ItemFlags flags = QAbstractListModel::flags( index );

Expand All @@ -534,36 +534,36 @@ Qt::ItemFlags QgsLayoutManagerModel::flags( const QModelIndex &index ) const
}
}

QgsComposition *QgsLayoutManagerModel::compositionFromIndex( const QModelIndex &index ) const
QgsComposition *QgsComposerManagerModel::compositionFromIndex( const QModelIndex &index ) const
{
return qobject_cast< QgsComposition * >( qvariant_cast<QObject *>( data( index, CompositionRole ) ) );
}

void QgsLayoutManagerModel::compositionAboutToBeAdded( const QString & )
void QgsComposerManagerModel::compositionAboutToBeAdded( const QString & )
{
int row = mLayoutManager->compositions().count();
beginInsertRows( QModelIndex(), row, row );
}

void QgsLayoutManagerModel::compositionAboutToBeRemoved( const QString &name )
void QgsComposerManagerModel::compositionAboutToBeRemoved( const QString &name )
{
QgsComposition *c = mLayoutManager->compositionByName( name );
int row = mLayoutManager->compositions().indexOf( c );
if ( row >= 0 )
beginRemoveRows( QModelIndex(), row, row );
}

void QgsLayoutManagerModel::compositionAdded( const QString & )
void QgsComposerManagerModel::compositionAdded( const QString & )
{
endInsertRows();
}

void QgsLayoutManagerModel::compositionRemoved( const QString & )
void QgsComposerManagerModel::compositionRemoved( const QString & )
{
endRemoveRows();
}

void QgsLayoutManagerModel::compositionRenamed( QgsComposition *composition, const QString & )
void QgsComposerManagerModel::compositionRenamed( QgsComposition *composition, const QString & )
{
int row = mLayoutManager->compositions().indexOf( composition );
QModelIndex index = createIndex( row, 0 );
Expand Down
6 changes: 3 additions & 3 deletions src/app/composer/qgscomposermanager.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class QgsComposer;
class QgsComposition;
class QgsLayoutManager;

class QgsLayoutManagerModel : public QAbstractListModel
class QgsComposerManagerModel : public QAbstractListModel
{
Q_OBJECT

Expand All @@ -37,7 +37,7 @@ class QgsLayoutManagerModel : public QAbstractListModel
CompositionRole = Qt::UserRole + 1,
};

explicit QgsLayoutManagerModel( QgsLayoutManager *manager, QObject *parent = nullptr );
explicit QgsComposerManagerModel( QgsLayoutManager *manager, QObject *parent = nullptr );

int rowCount( const QModelIndex &parent ) const override;
QVariant data( const QModelIndex &index, int role ) const override;
Expand Down Expand Up @@ -93,7 +93,7 @@ class QgsComposerManager: public QDialog, private Ui::QgsComposerManagerBase
QPushButton *mRemoveButton = nullptr;
QPushButton *mRenameButton = nullptr;
QPushButton *mDuplicateButton = nullptr;
QgsLayoutManagerModel *mModel = nullptr;
QgsComposerManagerModel *mModel = nullptr;

#ifdef Q_OS_MAC
void showEvent( QShowEvent *event );
Expand Down
7 changes: 6 additions & 1 deletion src/app/layout/qgslayoutdesignerdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -615,6 +615,8 @@ QgsLayout *QgsLayoutDesignerDialog::currentLayout()
void QgsLayoutDesignerDialog::setCurrentLayout( QgsLayout *layout )
{
mLayout = layout;
connect( mLayout, &QgsLayout::destroyed, this, &QgsLayoutDesignerDialog::close );

mView->setCurrentLayout( layout );

// add undo/redo actions which apply to the correct layout undo stack
Expand Down Expand Up @@ -1372,7 +1374,10 @@ void QgsLayoutDesignerDialog::showManager()
// NOTE: Avoid crash where composer that spawned modal manager from toolbar ends up
// being deleted by user, but event loop tries to return to layout on manager close
// (does not seem to be an issue for menu action)
QTimer::singleShot( 0, QgisApp::instance()->actionShowComposerManager(), SLOT( trigger() ) );
QTimer::singleShot( 0, this, [ = ]
{
QgisApp::instance()->showLayoutManager();
} );
}

void QgsLayoutDesignerDialog::paste()
Expand Down

0 comments on commit a30dd8a

Please sign in to comment.