Delay loading of composer picture preview icons until widget is shown

This commit is contained in:
Marco Hugentobler 2012-02-28 14:20:26 +01:00
parent c0cf1abee5
commit 5caa4037f3
5 changed files with 40 additions and 22 deletions

View File

@ -1134,6 +1134,14 @@ void QgsComposer::showEvent( QShowEvent* event )
mapIt.key()->update(); mapIt.key()->update();
} }
mMapsToRestore.clear(); mMapsToRestore.clear();
//create composer picture widget previews
QList< QgsComposerPictureWidget* >::iterator picIt = mPicturePreviews.begin();
for ( ; picIt != mPicturePreviews.end(); ++picIt )
{
( *picIt )->addStandardDirectoriesToPreview();
}
mPicturePreviews.clear();
} }
#ifdef Q_WS_MAC #ifdef Q_WS_MAC
@ -1382,6 +1390,14 @@ void QgsComposer::addComposerPicture( QgsComposerPicture* picture )
} }
QgsComposerPictureWidget* pWidget = new QgsComposerPictureWidget( picture ); QgsComposerPictureWidget* pWidget = new QgsComposerPictureWidget( picture );
if ( isVisible() )
{
pWidget->addStandardDirectoriesToPreview();
}
else
{
mPicturePreviews.append( pWidget );
}
mItemWidgetMap.insert( picture, pWidget ); mItemWidgetMap.insert( picture, pWidget );
} }

View File

@ -27,6 +27,7 @@ class QgsComposerArrow;
class QgsComposerLabel; class QgsComposerLabel;
class QgsComposerLegend; class QgsComposerLegend;
class QgsComposerPicture; class QgsComposerPicture;
class QgsComposerPictureWidget;
class QgsComposerScaleBar; class QgsComposerScaleBar;
class QgsComposerShape; class QgsComposerShape;
class QgsComposerAttributeTable; class QgsComposerAttributeTable;
@ -322,6 +323,7 @@ class QgsComposer: public QMainWindow, private Ui::QgsComposerBase
//! We load composer map content from project xml only on demand. Therefore we need to store the real preview mode type //! We load composer map content from project xml only on demand. Therefore we need to store the real preview mode type
QMap< QgsComposerMap*, int > mMapsToRestore; QMap< QgsComposerMap*, int > mMapsToRestore;
QList< QgsComposerPictureWidget* > mPicturePreviews;
QDockWidget* mItemDock; QDockWidget* mItemDock;
QDockWidget* mUndoDock; QDockWidget* mUndoDock;

View File

@ -30,7 +30,7 @@
#include <QSettings> #include <QSettings>
#include <QSvgRenderer> #include <QSvgRenderer>
QgsComposerPictureWidget::QgsComposerPictureWidget( QgsComposerPicture* picture ): QWidget(), mPicture( picture ), mPreviewInitialized( false ) QgsComposerPictureWidget::QgsComposerPictureWidget( QgsComposerPicture* picture ): QWidget(), mPicture( picture )
{ {
setupUi( this ); setupUi( this );
@ -44,8 +44,6 @@ QgsComposerPictureWidget::QgsComposerPictureWidget( QgsComposerPicture* picture
mPreviewListWidget->setIconSize( QSize( 30, 30 ) ); mPreviewListWidget->setIconSize( QSize( 30, 30 ) );
//add preview icons on demand in showEvent()
connect( mPicture, SIGNAL( itemChanged() ), this, SLOT( setGuiElementValues() ) ); connect( mPicture, SIGNAL( itemChanged() ), this, SLOT( setGuiElementValues() ) );
connect( mPicture, SIGNAL( rotationChanged( double ) ), this, SLOT( setGuiElementValues() ) ); connect( mPicture, SIGNAL( rotationChanged( double ) ), this, SLOT( setGuiElementValues() ) );
} }
@ -261,17 +259,6 @@ void QgsComposerPictureWidget::on_mRotationFromComposerMapCheckBox_stateChanged(
mPicture->endCommand(); mPicture->endCommand();
} }
void QgsComposerPictureWidget::showEvent( QShowEvent * event )
{
refreshMapComboBox();
if ( !mPreviewInitialized )
{
addStandardDirectoriesToPreview();
mPreviewInitialized = true;
}
QWidget::showEvent( event );
}
void QgsComposerPictureWidget::on_mComposerMapComboBox_activated( const QString & text ) void QgsComposerPictureWidget::on_mComposerMapComboBox_activated( const QString & text )
{ {
if ( !mPicture || text.isEmpty() || !mPicture->useRotationMap() ) if ( !mPicture || text.isEmpty() || !mPicture->useRotationMap() )
@ -481,6 +468,8 @@ int QgsComposerPictureWidget::addDirectoryToPreview( const QString& path )
void QgsComposerPictureWidget::addStandardDirectoriesToPreview() void QgsComposerPictureWidget::addStandardDirectoriesToPreview()
{ {
mPreviewListWidget->clear();
//list all directories in $prefix/share/qgis/svg //list all directories in $prefix/share/qgis/svg
QStringList svgPaths = QgsApplication::svgPaths(); QStringList svgPaths = QgsApplication::svgPaths();
for ( int i = 0; i < svgPaths.size(); i++ ) for ( int i = 0; i < svgPaths.size(); i++ )
@ -536,3 +525,10 @@ bool QgsComposerPictureWidget::testImageFile( const QString& filename ) const
QString formatName = QString( QImageReader::imageFormat( filename ) ); QString formatName = QString( QImageReader::imageFormat( filename ) );
return !formatName.isEmpty(); //file is in a supported pixel format return !formatName.isEmpty(); //file is in a supported pixel format
} }
void QgsComposerPictureWidget::showEvent( QShowEvent * event )
{
Q_UNUSED( event );
refreshMapComboBox();
}

View File

@ -33,6 +33,9 @@ class QgsComposerPictureWidget: public QWidget, private Ui::QgsComposerPictureWi
QgsComposerPictureWidget( QgsComposerPicture* picture ); QgsComposerPictureWidget( QgsComposerPicture* picture );
~QgsComposerPictureWidget(); ~QgsComposerPictureWidget();
/**Add the icons of the standard directories to the preview*/
void addStandardDirectoriesToPreview();
public slots: public slots:
void on_mPictureBrowseButton_clicked(); void on_mPictureBrowseButton_clicked();
void on_mPictureLineEdit_editingFinished(); void on_mPictureLineEdit_editingFinished();
@ -45,21 +48,19 @@ class QgsComposerPictureWidget: public QWidget, private Ui::QgsComposerPictureWi
void on_mRotationFromComposerMapCheckBox_stateChanged( int state ); void on_mRotationFromComposerMapCheckBox_stateChanged( int state );
void on_mComposerMapComboBox_activated( const QString & text ); void on_mComposerMapComboBox_activated( const QString & text );
protected:
void showEvent( QShowEvent * event );
private slots: private slots:
/**Sets the GUI elements to the values of mPicture*/ /**Sets the GUI elements to the values of mPicture*/
void setGuiElementValues(); void setGuiElementValues();
protected:
void showEvent( QShowEvent * event );
private: private:
QgsComposerPicture* mPicture; QgsComposerPicture* mPicture;
bool mPreviewInitialized;
/**Add the icons of a directory to the preview. Returns 0 in case of success*/ /**Add the icons of a directory to the preview. Returns 0 in case of success*/
int addDirectoryToPreview( const QString& path ); int addDirectoryToPreview( const QString& path );
/**Add the icons of the standard directories to the preview*/
void addStandardDirectoriesToPreview();
/**Tests if a file is valid svg*/ /**Tests if a file is valid svg*/
bool testSvgFile( const QString& filename ) const; bool testSvgFile( const QString& filename ) const;
/**Tests if a file is a valid pixel format*/ /**Tests if a file is a valid pixel format*/

View File

@ -33,8 +33,8 @@
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>327</width> <width>317</width>
<height>585</height> <height>577</height>
</rect> </rect>
</property> </property>
<attribute name="label"> <attribute name="label">
@ -79,6 +79,9 @@
<property name="isWrapping" stdset="0"> <property name="isWrapping" stdset="0">
<bool>true</bool> <bool>true</bool>
</property> </property>
<property name="resizeMode">
<enum>QListView::Adjust</enum>
</property>
<property name="gridSize"> <property name="gridSize">
<size> <size>
<width>30</width> <width>30</width>