Skip to content
Permalink
Browse files
Add New from Template to composer's Composer menu
- Show busy indicator dialog while template is loading into hidden composer (much faster loading)
- Clean up composer actions' text (title capitalize action text, sentence capitalize tool tips)
  • Loading branch information
dakcarto committed Mar 1, 2013
1 parent fe898a0 commit 7f83b12afddeb7f9efc005a943e45b64b2deb1a7
Show file tree
Hide file tree
Showing 3 changed files with 108 additions and 19 deletions.
@@ -179,6 +179,7 @@ QgsComposer::QgsComposer( QgisApp *qgis, const QString& title )
composerMenu->addMenu( mPrintComposersMenu );

composerMenu->addSeparator();
composerMenu->addAction( mActionNewFromTemplate );
composerMenu->addAction( mActionLoadFromTemplate );
composerMenu->addAction( mActionSaveAsTemplate );
composerMenu->addSeparator();
@@ -362,6 +363,7 @@ void QgsComposer::setupTheme()
mActionNewComposer->setIcon( QgsApplication::getThemeIcon( "/mActionNewComposer.png" ) );
mActionDuplicateComposer->setIcon( QgsApplication::getThemeIcon( "/mActionDuplicateComposer.png" ) );
mActionComposerManager->setIcon( QgsApplication::getThemeIcon( "/mActionComposerManager.png" ) );
mActionNewFromTemplate->setIcon( QgsApplication::getThemeIcon( "/mActionNewComposer.png" ) );
mActionLoadFromTemplate->setIcon( QgsApplication::getThemeIcon( "/mActionFileOpen.png" ) );
mActionSaveAsTemplate->setIcon( QgsApplication::getThemeIcon( "/mActionFileSaveAs.png" ) );
mActionExportAsImage->setIcon( QgsApplication::getThemeIcon( "/mActionSaveMapAsImage.png" ) );
@@ -1434,7 +1436,17 @@ void QgsComposer::on_mActionSaveAsTemplate_triggered()
}
}

void QgsComposer::on_mActionNewFromTemplate_triggered()
{
loadTemplate( true );
}

void QgsComposer::on_mActionLoadFromTemplate_triggered()
{
loadTemplate( false );
}

void QgsComposer::loadTemplate( bool newCompser )
{
QSettings settings;
QString openFileDir = settings.value( "UI/lastComposerTemplateDir", "" ).toString();
@@ -1451,16 +1463,49 @@ void QgsComposer::on_mActionLoadFromTemplate_triggered()
QFile templateFile( openFileString );
if ( !templateFile.open( QIODevice::ReadOnly ) )
{
QMessageBox::warning( 0, tr( "Read error" ), tr( "Error, could not read file" ) );
QMessageBox::warning( this, tr( "Read error" ), tr( "Error, could not read file" ) );
return;
}

if ( mComposition )
QgsComposer* c = 0;
QgsComposition* comp = 0;

if ( newCompser )
{
QString newTitle = mQgis->uniqueComposerTitle( this, true );
if ( newTitle.isNull() )
{
return;
}
c = mQgis->createNewComposer( newTitle );
if ( !c )
{
QMessageBox::warning( this, tr( "Composer error" ), tr( "Error, could not create new composer" ) );
return;
}
comp = c->composition();
}
else
{
c = this;
comp = mComposition;
}

if ( comp )
{
QDomDocument templateDoc;
if ( templateDoc.setContent( &templateFile ) )
{
mComposition->loadFromTemplate( templateDoc, 0, false );
// provide feedback, since composer will be hidden when loading template (much faster)
QDialog* dlg = busyIndicatorDialog( tr( "Loading template into composer..." ), 0 );
dlg->setStyleSheet( mQgis->styleSheet() );
dlg->show();

c->hide();
comp->loadFromTemplate( templateDoc, 0, false );
c->activate();

dlg->close();
}
}
}
@@ -84,6 +84,11 @@ class QgsComposer: public QMainWindow, private Ui::QgsComposerBase
const QString& title() const {return mTitle;}
void setTitle( const QString& title );

//! Load template into current or blank composer
//! @param newCompser whether to create a new composer first
//! @note added in 1.9
void loadTemplate( bool newCompser );

//! Modal busy indicator dialog with no buttons that deletes on close
//! @param message text to show above busy progress indicator
//! @note added in 1.9
@@ -192,6 +197,10 @@ class QgsComposer: public QMainWindow, private Ui::QgsComposerBase
//! Save composer as template
void on_mActionSaveAsTemplate_triggered();

//! Load template into blank composer
//! @note added in 1.9
void on_mActionNewFromTemplate_triggered();

void on_mActionLoadFromTemplate_triggered();

//! Set tool to move item content
@@ -143,6 +143,9 @@
<property name="text">
<string>Zoom Full</string>
</property>
<property name="toolTip">
<string>Zoom full</string>
</property>
</action>
<action name="mActionZoomIn">
<property name="icon">
@@ -152,6 +155,9 @@
<property name="text">
<string>Zoom In</string>
</property>
<property name="toolTip">
<string>Zoom in</string>
</property>
</action>
<action name="mActionZoomOut">
<property name="icon">
@@ -161,6 +167,9 @@
<property name="text">
<string>Zoom Out</string>
</property>
<property name="toolTip">
<string>Zoom out</string>
</property>
</action>
<action name="mActionAddNewMap">
<property name="icon">
@@ -218,6 +227,9 @@
<property name="text">
<string>Export as Image...</string>
</property>
<property name="toolTip">
<string>Export as image</string>
</property>
</action>
<action name="mActionExportAsPDF">
<property name="icon">
@@ -269,6 +281,9 @@
<property name="text">
<string>Add Image</string>
</property>
<property name="toolTip">
<string>Add image</string>
</property>
</action>
<action name="mActionMoveItemContent">
<property name="text">
@@ -328,57 +343,63 @@
</action>
<action name="mActionLoadFromTemplate">
<property name="text">
<string>Load From template</string>
<string>Load from Template</string>
</property>
<property name="toolTip">
<string>Load from template</string>
</property>
</action>
<action name="mActionSaveAsTemplate">
<property name="text">
<string>Save as Template</string>
</property>
<property name="toolTip">
<string>Save as template</string>
</property>
</action>
<action name="mActionAlignLeft">
<property name="text">
<string>Align left</string>
<string>Align Left</string>
</property>
<property name="toolTip">
<string>Align selected items left</string>
</property>
</action>
<action name="mActionAlignHCenter">
<property name="text">
<string>Align center</string>
<string>Align Center</string>
</property>
<property name="toolTip">
<string>Align center horizontal</string>
</property>
</action>
<action name="mActionAlignRight">
<property name="text">
<string>Align right</string>
<string>Align Right</string>
</property>
<property name="toolTip">
<string>Align selected items right</string>
</property>
</action>
<action name="mActionAlignTop">
<property name="text">
<string>Align top</string>
<string>Align Top</string>
</property>
<property name="toolTip">
<string>Align selected items to top</string>
</property>
</action>
<action name="mActionAlignVCenter">
<property name="text">
<string>Align center vertical</string>
<string>Align Center Vertical</string>
</property>
<property name="toolTip">
<string>Align center vertical</string>
</property>
</action>
<action name="mActionAlignBottom">
<property name="text">
<string>Align bottom</string>
<string>Align Bottom</string>
</property>
<property name="toolTip">
<string>Align selected items bottom</string>
@@ -400,6 +421,9 @@
<bool>true</bool>
</property>
<property name="text">
<string>Add Arrow</string>
</property>
<property name="toolTip">
<string>Add arrow</string>
</property>
</action>
@@ -408,16 +432,19 @@
<bool>true</bool>
</property>
<property name="text">
<string>Add table</string>
<string>Add Table</string>
</property>
<property name="toolTip">
<string>Adds attribute table</string>
<string>Add attribute table</string>
</property>
</action>
<action name="mActionPageSetup">
<property name="text">
<string>Page Setup</string>
</property>
<property name="toolTip">
<string>Page setup</string>
</property>
<property name="shortcut">
<string>Ctrl+Shift+P</string>
</property>
@@ -461,7 +488,7 @@
<string>Add Rectangle</string>
</property>
<property name="toolTip">
<string>Add Rectangle</string>
<string>Add rectangle</string>
</property>
</action>
<action name="mActionAddTriangle">
@@ -472,7 +499,7 @@
<string>Add Triangle</string>
</property>
<property name="toolTip">
<string>Add Triangle</string>
<string>Add triangle</string>
</property>
</action>
<action name="mActionAddEllipse">
@@ -483,7 +510,7 @@
<string>Add Ellipse</string>
</property>
<property name="toolTip">
<string>Add Ellipse</string>
<string>Add ellipse</string>
</property>
</action>
<action name="mActionAddHtml">
@@ -502,15 +529,15 @@
<string>Composer Manager</string>
</property>
<property name="toolTip">
<string>Composer Manager</string>
<string>Composer manager</string>
</property>
</action>
<action name="mActionNewComposer">
<property name="text">
<string>&amp;New Composer</string>
</property>
<property name="toolTip">
<string>New Composer</string>
<string>New composer</string>
</property>
<property name="shortcut">
<string>Ctrl+N</string>
@@ -521,7 +548,7 @@
<string>&amp;Save Project</string>
</property>
<property name="toolTip">
<string>Save Project</string>
<string>Save project</string>
</property>
<property name="shortcut">
<string>Ctrl+S</string>
@@ -532,7 +559,15 @@
<string>&amp;Duplicate Composer</string>
</property>
<property name="toolTip">
<string>Duplicate Composer</string>
<string>Duplicate composer</string>
</property>
</action>
<action name="mActionNewFromTemplate">
<property name="text">
<string>New from Template</string>
</property>
<property name="toolTip">
<string>New from template</string>
</property>
</action>
</widget>

0 comments on commit 7f83b12

Please sign in to comment.