[QGIS Commit] r13228 - trunk/qgis/src/app/composer
svn_qgis at osgeo.org
svn_qgis at osgeo.org
Sat Apr 3 11:49:50 EDT 2010
Author: mhugent
Date: 2010-04-03 11:49:48 -0400 (Sat, 03 Apr 2010)
New Revision: 13228
Modified:
trunk/qgis/src/app/composer/qgscomposer.cpp
trunk/qgis/src/app/composer/qgscomposermanager.cpp
trunk/qgis/src/app/composer/qgscomposermanager.h
Log:
[FEATURE]: implement possibility to place a set of default composer templates in pkgDataPath/composer_templates
Modified: trunk/qgis/src/app/composer/qgscomposer.cpp
===================================================================
--- trunk/qgis/src/app/composer/qgscomposer.cpp 2010-04-03 10:39:59 UTC (rev 13227)
+++ trunk/qgis/src/app/composer/qgscomposer.cpp 2010-04-03 15:49:48 UTC (rev 13228)
@@ -903,9 +903,6 @@
deleteItems();
readXML( templateDocument );
-
- //clean up after template read (e.g. legend and map extent)
- cleanupAfterTemplateRead();
}
void QgsComposer::on_mActionMoveItemContent_triggered()
@@ -1103,6 +1100,7 @@
return;
}
readXML( composerNodeList.at( 0 ).toElement(), doc, true );
+ cleanupAfterTemplateRead();
}
void QgsComposer::readXML( const QDomElement& composerElem, const QDomDocument& doc, bool fromTemplate )
Modified: trunk/qgis/src/app/composer/qgscomposermanager.cpp
===================================================================
--- trunk/qgis/src/app/composer/qgscomposermanager.cpp 2010-04-03 10:39:59 UTC (rev 13227)
+++ trunk/qgis/src/app/composer/qgscomposermanager.cpp 2010-04-03 15:49:48 UTC (rev 13228)
@@ -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 @@
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 @@
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 @@
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 );
+ }
+}
Modified: trunk/qgis/src/app/composer/qgscomposermanager.h
===================================================================
--- trunk/qgis/src/app/composer/qgscomposermanager.h 2010-04-03 10:39:59 UTC (rev 13227)
+++ trunk/qgis/src/app/composer/qgscomposermanager.h 2010-04-03 15:49:48 UTC (rev 13228)
@@ -35,8 +35,12 @@
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 @@
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
More information about the QGIS-commit
mailing list