Skip to content
Permalink
Browse files
[FEATURE]: implement possibility to place a set of default composer t…
…emplates in pkgDataPath/composer_templates

git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@13228 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
mhugent committed Apr 3, 2010
1 parent dc0e381 commit bca3f68a0e7307f2ca0887febf2c319c877e82d9
Showing with 85 additions and 8 deletions.
  1. +1 −3 src/app/composer/qgscomposer.cpp
  2. +78 −4 src/app/composer/qgscomposermanager.cpp
  3. +6 −1 src/app/composer/qgscomposermanager.h
@@ -903,9 +903,6 @@ void QgsComposer::on_mActionLoadFromTemplate_triggered()

deleteItems();
readXML( templateDocument );

//clean up after template read (e.g. legend and map extent)
cleanupAfterTemplateRead();
}

void QgsComposer::on_mActionMoveItemContent_triggered()
@@ -1103,6 +1100,7 @@ void QgsComposer::readXML( const QDomDocument& doc )
return;
}
readXML( composerNodeList.at( 0 ).toElement(), doc, true );
cleanupAfterTemplateRead();
}

void QgsComposer::readXML( const QDomElement& composerElem, const QDomDocument& doc, bool fromTemplate )
@@ -16,7 +16,10 @@

#include "qgscomposermanager.h"
#include "qgisapp.h"
#include "qgsapplication.h"
#include "qgscomposer.h"
#include "qgslogger.h"
#include <QDir>
#include <QInputDialog>
#include <QListWidgetItem>
#include <QMessageBox>
@@ -48,6 +51,26 @@ void QgsComposerManager::initialize()
item->setFlags( Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsEditable );
mItemComposerMap.insert( item, *it );
}

//search for default templates in $pkgDataPath/composer_templates
QDir defaultTemplateDir( QgsApplication::pkgDataPath() + "/composer_templates" );
if ( !defaultTemplateDir.exists() )
{
return;
}

QFileInfoList defaultTemplateFiles = defaultTemplateDir.entryInfoList( QDir::Files );
QFileInfoList::const_iterator fileIt = defaultTemplateFiles.constBegin();

for ( ; fileIt != defaultTemplateFiles.constEnd(); ++fileIt )
{
mDefaultTemplateMap.insert( fileIt->baseName(), fileIt->absoluteFilePath() );
if ( mComposerListWidget->findItems( fileIt->baseName(), Qt::MatchExactly ).size() < 1 )
{
QListWidgetItem* item = new QListWidgetItem( fileIt->baseName(), mComposerListWidget );
mItemComposerMap.insert( item, 0 );
}
}
}

void QgsComposerManager::on_mAddButton_clicked()
@@ -110,13 +133,48 @@ void QgsComposerManager::on_mShowPushButton_clicked()
return;
}

//delete composer
QMap<QListWidgetItem*, QgsComposer*>::iterator it = mItemComposerMap.find( item );
if ( it != mItemComposerMap.end() )
{
it.value()->show();
it.value()->activate();
it.value()->stackUnder( this );
QgsComposer* c = 0;
if ( it.value() ) //a normal composer
{
c = it.value();
it.value()->show();
}
else //create composer from default template
{
QMap<QString, QString>::const_iterator templateIt = mDefaultTemplateMap.find( it.key()->text() );
if ( templateIt == mDefaultTemplateMap.constEnd() )
{
return;
}

QDomDocument templateDoc;
QFile templateFile( templateIt.value() );
if ( !templateFile.open( QIODevice::ReadOnly ) )
{
return;
}

if ( !templateDoc.setContent( &templateFile, false ) )
{
return;
}
c = mQgisApp->createNewComposer();
c->setTitle( it.key()->text() );
if ( c )
{
c->readXML( templateDoc );
}
}

if ( c )
{
c->show();
c->activate();
c->stackUnder( this );
}
}
}

@@ -157,3 +215,19 @@ void QgsComposerManager::on_mComposerListWidget_itemChanged( QListWidgetItem * i
it.value()->setTitle( item->text() );
}
}

void QgsComposerManager::on_mComposerListWidget_currentItemChanged( QListWidgetItem* current, QListWidgetItem* previous )
{
if ( !current )
{
return;
}
if ( mDefaultTemplateMap.contains( current->text() ) )
{
mRenamePushButton->setEnabled( false );
}
else
{
mRenamePushButton->setEnabled( true );
}
}
@@ -35,8 +35,12 @@ class QgsComposerManager: public QDialog, private Ui::QgsComposerManagerBase

private:
QgisApp* mQgisApp;
/**Stores the relation between items and composer pointers */
/**Stores the relation between items and composer pointers. A 0 pointer for the composer means that
this composer needs to be created from a default template*/
QMap<QListWidgetItem*, QgsComposer*> mItemComposerMap;
/**Key: name of the default template (=filename without suffix). Value: absolute path of the template*/
QMap<QString, QString > mDefaultTemplateMap;

/**Enters the composer instances and created the item-composer map*/
void initialize();

@@ -46,6 +50,7 @@ class QgsComposerManager: public QDialog, private Ui::QgsComposerManagerBase
void on_mShowPushButton_clicked();
void on_mRenamePushButton_clicked();
void on_mComposerListWidget_itemChanged( QListWidgetItem * item );
void on_mComposerListWidget_currentItemChanged( QListWidgetItem* current, QListWidgetItem* previous );
};

#endif // QGSCOMPOSERMANAGER_H

0 comments on commit bca3f68

Please sign in to comment.