Skip to content
Permalink
Browse files

Port composer manager dialog to layouts

Not exposed via GUI yet, but can be shown by entering

iface.showLayoutManager()

in the Python console
  • Loading branch information
nyalldawson committed Dec 5, 2017
1 parent 66b4b45 commit a30dd8a153ef8eb536ce10a25dffbcc7b4fe7573
@@ -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;
@@ -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
@@ -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
@@ -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 );
@@ -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();
@@ -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 )
{
@@ -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 );

@@ -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 );
@@ -26,7 +26,7 @@ class QgsComposer;
class QgsComposition;
class QgsLayoutManager;

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

@@ -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;
@@ -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 );
@@ -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
@@ -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()

0 comments on commit a30dd8a

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