Skip to content

Commit

Permalink
Port a few file related actions to layouts
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Dec 6, 2017
1 parent a9896ea commit 9c4a98f
Show file tree
Hide file tree
Showing 5 changed files with 98 additions and 1 deletion.
26 changes: 26 additions & 0 deletions src/app/layout/qgslayoutdesignerdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,9 @@ QgsLayoutDesignerDialog::QgsLayoutDesignerDialog( QWidget *parent, Qt::WindowFla
mVerticalRuler->setContextMenu( rulerMenu );

connect( mActionRefreshView, &QAction::triggered, this, &QgsLayoutDesignerDialog::refreshLayout );
connect( mActionSaveProject, &QAction::triggered, this, &QgsLayoutDesignerDialog::saveProject );
connect( mActionNewLayout, &QAction::triggered, this, &QgsLayoutDesignerDialog::newLayout );
connect( mActionLayoutManager, &QAction::triggered, this, &QgsLayoutDesignerDialog::showManager );

connect( mActionShowGrid, &QAction::triggered, this, &QgsLayoutDesignerDialog::showGrid );
connect( mActionSnapGrid, &QAction::triggered, this, &QgsLayoutDesignerDialog::snapToGrid );
Expand Down Expand Up @@ -1348,6 +1351,29 @@ void QgsLayoutDesignerDialog::duplicate()
}
}

void QgsLayoutDesignerDialog::saveProject()
{
QgisApp::instance()->actionSaveProject()->trigger();
}

void QgsLayoutDesignerDialog::newLayout()
{
QString title;
if ( !QgisApp::instance()->uniqueLayoutTitle( this, title, true ) )
{
return;
}
QgisApp::instance()->createNewLayout( title );
}

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

void QgsLayoutDesignerDialog::paste()
{
QPointF pt = mView->mapFromGlobal( QCursor::pos() );
Expand Down
3 changes: 3 additions & 0 deletions src/app/layout/qgslayoutdesignerdialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,9 @@ class QgsLayoutDesignerDialog: public QMainWindow, private Ui::QgsLayoutDesigner
void saveAsTemplate();
void addItemsFromTemplate();
void duplicate();
void saveProject();
void newLayout();
void showManager();

private:

Expand Down
17 changes: 16 additions & 1 deletion src/app/qgisapp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7445,6 +7445,19 @@ QgsComposer *QgisApp::openComposer( QgsComposition *composition )
return newComposerObject;
}

QgsLayoutDesignerDialog *QgisApp::createNewLayout( QString title )
{
if ( title.isEmpty() )
{
title = QgsProject::instance()->layoutManager()->generateUniqueTitle();
}
//create new layout object
QgsLayout *layout = new QgsLayout( QgsProject::instance() );
layout->setName( title );
QgsProject::instance()->layoutManager()->addLayout( layout );
return openLayoutDesignerDialog( layout );
}

QgsLayoutDesignerDialog *QgisApp::openLayoutDesignerDialog( QgsLayout *layout )
{
// maybe a designer already open for this layout
Expand Down Expand Up @@ -7474,7 +7487,9 @@ QgsLayoutDesignerDialog *QgisApp::openLayoutDesignerDialog( QgsLayout *layout )

newDesigner->open();
emit layoutDesignerOpened( newDesigner->iface() );
//connect( newDesigner, &QgsLayoutDesignerDialog::atlasPreviewFeatureChanged, this, &QgisApp::refreshMapCanvas );
#if 0 //TODO
connect( newDesigner, &QgsLayoutDesignerDialog::atlasPreviewFeatureChanged, this, &QgisApp::refreshMapCanvas );
#endif

return newDesigner;
}
Expand Down
3 changes: 3 additions & 0 deletions src/app/qgisapp.h
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,9 @@ class APP_EXPORT QgisApp : public QMainWindow, private Ui::MainWindow
*/
QgsComposer *openComposer( QgsComposition *composition );

//! Creates a new layout and returns a pointer to it
QgsLayoutDesignerDialog *createNewLayout( QString title = QString() );

/**
* Opens a layout designer dialog for an existing \a layout.
* If a designer already exists for this layout then it will be activated.
Expand Down
50 changes: 50 additions & 0 deletions src/ui/layout/qgslayoutdesignerbase.ui
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,11 @@
<attribute name="toolBarBreak">
<bool>false</bool>
</attribute>
<addaction name="mActionSaveProject"/>
<addaction name="separator"/>
<addaction name="mActionNewLayout"/>
<addaction name="mActionDuplicateLayout"/>
<addaction name="mActionLayoutManager"/>
<addaction name="mActionLoadFromTemplate"/>
<addaction name="mActionSaveAsTemplate"/>
</widget>
Expand Down Expand Up @@ -95,7 +99,11 @@
<property name="title">
<string>&amp;Layout</string>
</property>
<addaction name="mActionSaveProject"/>
<addaction name="separator"/>
<addaction name="mActionNewLayout"/>
<addaction name="mActionDuplicateLayout"/>
<addaction name="mActionLayoutManager"/>
<addaction name="separator"/>
<addaction name="mActionLayoutProperties"/>
<addaction name="mActionAddPages"/>
Expand Down Expand Up @@ -1101,6 +1109,48 @@
<string>Duplicate layout</string>
</property>
</action>
<action name="mActionSaveProject">
<property name="icon">
<iconset resource="../../../images/images.qrc">
<normaloff>:/images/themes/default/mActionFileSave.svg</normaloff>:/images/themes/default/mActionFileSave.svg</iconset>
</property>
<property name="text">
<string>&amp;Save Project</string>
</property>
<property name="toolTip">
<string>Save project</string>
</property>
<property name="shortcut">
<string>Ctrl+S</string>
</property>
</action>
<action name="mActionNewLayout">
<property name="icon">
<iconset resource="../../../images/images.qrc">
<normaloff>:/images/themes/default/mActionNewComposer.svg</normaloff>:/images/themes/default/mActionNewComposer.svg</iconset>
</property>
<property name="text">
<string>&amp;New Layout…</string>
</property>
<property name="toolTip">
<string>New layout</string>
</property>
<property name="shortcut">
<string>Ctrl+N</string>
</property>
</action>
<action name="mActionLayoutManager">
<property name="icon">
<iconset resource="../../../images/images.qrc">
<normaloff>:/images/themes/default/mActionComposerManager.svg</normaloff>:/images/themes/default/mActionComposerManager.svg</iconset>
</property>
<property name="text">
<string>Layout &amp;Manager...</string>
</property>
<property name="toolTip">
<string>Layout manager</string>
</property>
</action>
</widget>
<resources>
<include location="../../../images/images.qrc"/>
Expand Down

0 comments on commit 9c4a98f

Please sign in to comment.