Skip to content

Commit 5caa403

Browse files
committed
Delay loading of composer picture preview icons until widget is shown
1 parent c0cf1ab commit 5caa403

5 files changed

+40
-22
lines changed

src/app/composer/qgscomposer.cpp

+16
Original file line numberDiff line numberDiff line change
@@ -1134,6 +1134,14 @@ void QgsComposer::showEvent( QShowEvent* event )
11341134
mapIt.key()->update();
11351135
}
11361136
mMapsToRestore.clear();
1137+
1138+
//create composer picture widget previews
1139+
QList< QgsComposerPictureWidget* >::iterator picIt = mPicturePreviews.begin();
1140+
for ( ; picIt != mPicturePreviews.end(); ++picIt )
1141+
{
1142+
( *picIt )->addStandardDirectoriesToPreview();
1143+
}
1144+
mPicturePreviews.clear();
11371145
}
11381146

11391147
#ifdef Q_WS_MAC
@@ -1382,6 +1390,14 @@ void QgsComposer::addComposerPicture( QgsComposerPicture* picture )
13821390
}
13831391

13841392
QgsComposerPictureWidget* pWidget = new QgsComposerPictureWidget( picture );
1393+
if ( isVisible() )
1394+
{
1395+
pWidget->addStandardDirectoriesToPreview();
1396+
}
1397+
else
1398+
{
1399+
mPicturePreviews.append( pWidget );
1400+
}
13851401
mItemWidgetMap.insert( picture, pWidget );
13861402
}
13871403

src/app/composer/qgscomposer.h

+2
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ class QgsComposerArrow;
2727
class QgsComposerLabel;
2828
class QgsComposerLegend;
2929
class QgsComposerPicture;
30+
class QgsComposerPictureWidget;
3031
class QgsComposerScaleBar;
3132
class QgsComposerShape;
3233
class QgsComposerAttributeTable;
@@ -322,6 +323,7 @@ class QgsComposer: public QMainWindow, private Ui::QgsComposerBase
322323

323324
//! We load composer map content from project xml only on demand. Therefore we need to store the real preview mode type
324325
QMap< QgsComposerMap*, int > mMapsToRestore;
326+
QList< QgsComposerPictureWidget* > mPicturePreviews;
325327

326328
QDockWidget* mItemDock;
327329
QDockWidget* mUndoDock;

src/app/composer/qgscomposerpicturewidget.cpp

+10-14
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
#include <QSettings>
3131
#include <QSvgRenderer>
3232

33-
QgsComposerPictureWidget::QgsComposerPictureWidget( QgsComposerPicture* picture ): QWidget(), mPicture( picture ), mPreviewInitialized( false )
33+
QgsComposerPictureWidget::QgsComposerPictureWidget( QgsComposerPicture* picture ): QWidget(), mPicture( picture )
3434
{
3535
setupUi( this );
3636

@@ -44,8 +44,6 @@ QgsComposerPictureWidget::QgsComposerPictureWidget( QgsComposerPicture* picture
4444

4545
mPreviewListWidget->setIconSize( QSize( 30, 30 ) );
4646

47-
//add preview icons on demand in showEvent()
48-
4947
connect( mPicture, SIGNAL( itemChanged() ), this, SLOT( setGuiElementValues() ) );
5048
connect( mPicture, SIGNAL( rotationChanged( double ) ), this, SLOT( setGuiElementValues() ) );
5149
}
@@ -261,17 +259,6 @@ void QgsComposerPictureWidget::on_mRotationFromComposerMapCheckBox_stateChanged(
261259
mPicture->endCommand();
262260
}
263261

264-
void QgsComposerPictureWidget::showEvent( QShowEvent * event )
265-
{
266-
refreshMapComboBox();
267-
if ( !mPreviewInitialized )
268-
{
269-
addStandardDirectoriesToPreview();
270-
mPreviewInitialized = true;
271-
}
272-
QWidget::showEvent( event );
273-
}
274-
275262
void QgsComposerPictureWidget::on_mComposerMapComboBox_activated( const QString & text )
276263
{
277264
if ( !mPicture || text.isEmpty() || !mPicture->useRotationMap() )
@@ -481,6 +468,8 @@ int QgsComposerPictureWidget::addDirectoryToPreview( const QString& path )
481468

482469
void QgsComposerPictureWidget::addStandardDirectoriesToPreview()
483470
{
471+
mPreviewListWidget->clear();
472+
484473
//list all directories in $prefix/share/qgis/svg
485474
QStringList svgPaths = QgsApplication::svgPaths();
486475
for ( int i = 0; i < svgPaths.size(); i++ )
@@ -536,3 +525,10 @@ bool QgsComposerPictureWidget::testImageFile( const QString& filename ) const
536525
QString formatName = QString( QImageReader::imageFormat( filename ) );
537526
return !formatName.isEmpty(); //file is in a supported pixel format
538527
}
528+
529+
void QgsComposerPictureWidget::showEvent( QShowEvent * event )
530+
{
531+
Q_UNUSED( event );
532+
refreshMapComboBox();
533+
}
534+

src/app/composer/qgscomposerpicturewidget.h

+7-6
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@ class QgsComposerPictureWidget: public QWidget, private Ui::QgsComposerPictureWi
3333
QgsComposerPictureWidget( QgsComposerPicture* picture );
3434
~QgsComposerPictureWidget();
3535

36+
/**Add the icons of the standard directories to the preview*/
37+
void addStandardDirectoriesToPreview();
38+
3639
public slots:
3740
void on_mPictureBrowseButton_clicked();
3841
void on_mPictureLineEdit_editingFinished();
@@ -45,21 +48,19 @@ class QgsComposerPictureWidget: public QWidget, private Ui::QgsComposerPictureWi
4548
void on_mRotationFromComposerMapCheckBox_stateChanged( int state );
4649
void on_mComposerMapComboBox_activated( const QString & text );
4750

51+
protected:
52+
void showEvent( QShowEvent * event );
53+
4854
private slots:
4955
/**Sets the GUI elements to the values of mPicture*/
5056
void setGuiElementValues();
5157

52-
protected:
53-
void showEvent( QShowEvent * event );
54-
5558
private:
5659
QgsComposerPicture* mPicture;
57-
bool mPreviewInitialized;
5860

5961
/**Add the icons of a directory to the preview. Returns 0 in case of success*/
6062
int addDirectoryToPreview( const QString& path );
61-
/**Add the icons of the standard directories to the preview*/
62-
void addStandardDirectoriesToPreview();
63+
6364
/**Tests if a file is valid svg*/
6465
bool testSvgFile( const QString& filename ) const;
6566
/**Tests if a file is a valid pixel format*/

src/ui/qgscomposerpicturewidgetbase.ui

+5-2
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@
3333
<rect>
3434
<x>0</x>
3535
<y>0</y>
36-
<width>327</width>
37-
<height>585</height>
36+
<width>317</width>
37+
<height>577</height>
3838
</rect>
3939
</property>
4040
<attribute name="label">
@@ -79,6 +79,9 @@
7979
<property name="isWrapping" stdset="0">
8080
<bool>true</bool>
8181
</property>
82+
<property name="resizeMode">
83+
<enum>QListView::Adjust</enum>
84+
</property>
8285
<property name="gridSize">
8386
<size>
8487
<width>30</width>

0 commit comments

Comments
 (0)