Skip to content

Commit e2bd04f

Browse files
committed
Fix for #7458, project crashes when loaded from command line
- Image selection previews now load only on first expansion of parent group box - Note: this is an OK fix for 2.0 release. One better solution noted here: http://hub.qgis.org/issues/7458#note-12
1 parent e87623d commit e2bd04f

5 files changed

+31
-36
lines changed

src/app/composer/qgscomposer.cpp

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1725,7 +1725,6 @@ void QgsComposer::showEvent( QShowEvent* event )
17251725
if ( event->spontaneous() ) //event from the window system
17261726
{
17271727
restoreComposerMapStates();
1728-
initialiseComposerPicturePreviews();
17291728
}
17301729

17311730
#ifdef Q_WS_MAC
@@ -1967,14 +1966,6 @@ void QgsComposer::addComposerPicture( QgsComposerPicture* picture )
19671966
}
19681967

19691968
QgsComposerPictureWidget* pWidget = new QgsComposerPictureWidget( picture );
1970-
if ( isVisible() )
1971-
{
1972-
pWidget->addStandardDirectoriesToPreview();
1973-
}
1974-
else
1975-
{
1976-
mPicturePreviews.append( pWidget );
1977-
}
19781969
mItemWidgetMap.insert( picture, pWidget );
19791970
}
19801971

@@ -2198,7 +2189,6 @@ void QgsComposer::cleanupAfterTemplateRead()
21982189
}
21992190

22002191
restoreComposerMapStates();
2201-
initialiseComposerPicturePreviews();
22022192
}
22032193

22042194
void QgsComposer::on_mActionPageSetup_triggered()
@@ -2225,17 +2215,6 @@ void QgsComposer::restoreComposerMapStates()
22252215
mMapsToRestore.clear();
22262216
}
22272217

2228-
void QgsComposer::initialiseComposerPicturePreviews()
2229-
{
2230-
//create composer picture widget previews
2231-
QList< QgsComposerPictureWidget* >::iterator picIt = mPicturePreviews.begin();
2232-
for ( ; picIt != mPicturePreviews.end(); ++picIt )
2233-
{
2234-
( *picIt )->addStandardDirectoriesToPreview();
2235-
}
2236-
mPicturePreviews.clear();
2237-
}
2238-
22392218
void QgsComposer::populatePrintComposersMenu()
22402219
{
22412220
mPrintComposersMenu->clear();

src/app/composer/qgscomposer.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -331,10 +331,6 @@ class QgsComposer: public QMainWindow, private Ui::QgsComposerBase
331331
//! Initially after reading from xml, states are set to rectangle to achieve faster project loading.
332332
void restoreComposerMapStates();
333333

334-
//! Fills icons into composer picture widgets
335-
//! To make loading from project faster, the previews are generated when the composer becomes visible.
336-
void initialiseComposerPicturePreviews();
337-
338334
//! Create composer view and rulers
339335
void createComposerView();
340336

@@ -375,7 +371,6 @@ class QgsComposer: public QMainWindow, private Ui::QgsComposerBase
375371

376372
//! We load composer map content from project xml only on demand. Therefore we need to store the real preview mode type
377373
QMap< QgsComposerMap*, int > mMapsToRestore;
378-
QList< QgsComposerPictureWidget* > mPicturePreviews;
379374

380375
QDockWidget* mItemDock;
381376
QDockWidget* mUndoDock;

src/app/composer/qgscomposerpicturewidget.cpp

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
#include <QSettings>
3232
#include <QSvgRenderer>
3333

34-
QgsComposerPictureWidget::QgsComposerPictureWidget( QgsComposerPicture* picture ): QWidget(), mPicture( picture )
34+
QgsComposerPictureWidget::QgsComposerPictureWidget( QgsComposerPicture* picture ): QWidget(), mPicture( picture ), mPreviewsLoaded( false )
3535
{
3636
setupUi( this );
3737

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

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

47+
// mSearchDirectoriesGroupBox is a QgsCollapsibleGroupBoxBasic, so its collapsed state should not be saved/restored
48+
mSearchDirectoriesGroupBox->setCollapsed( true );
49+
// setup connection for loading previews on first expansion of group box
50+
connect( mSearchDirectoriesGroupBox, SIGNAL( collapsedStateChanged( bool ) ), this, SLOT( loadPicturePreviews( bool ) ) );
51+
4752
connect( mPicture, SIGNAL( itemChanged() ), this, SLOT( setGuiElementValues() ) );
4853
connect( mPicture, SIGNAL( rotationChanged( double ) ), this, SLOT( setGuiElementValues() ) );
4954
}
@@ -464,6 +469,8 @@ void QgsComposerPictureWidget::addStandardDirectoriesToPreview()
464469
addDirectoryToPreview( *userDirIt );
465470
mSearchDirectoriesComboBox->addItem( *userDirIt );
466471
}
472+
473+
mPreviewsLoaded = true;
467474
}
468475

469476
bool QgsComposerPictureWidget::testSvgFile( const QString& filename ) const
@@ -485,12 +492,14 @@ bool QgsComposerPictureWidget::testImageFile( const QString& filename ) const
485492
return !formatName.isEmpty(); //file is in a supported pixel format
486493
}
487494

488-
void QgsComposerPictureWidget::showEvent( QShowEvent * event )
495+
void QgsComposerPictureWidget::loadPicturePreviews( bool collapsed )
489496
{
490-
Q_UNUSED( event );
491-
refreshMapComboBox();
497+
if ( mPreviewsLoaded )
498+
{
499+
return;
500+
}
492501

493-
if ( mPreviewListWidget->count() == 0 )
502+
if ( !collapsed ) // load the previews only on first parent group box expansion
494503
{
495504
mPreviewListWidget->hide();
496505
mPreviewsLoadingLabel->show();
@@ -500,6 +509,12 @@ void QgsComposerPictureWidget::showEvent( QShowEvent * event )
500509
}
501510
}
502511

512+
void QgsComposerPictureWidget::showEvent( QShowEvent * event )
513+
{
514+
Q_UNUSED( event );
515+
refreshMapComboBox();
516+
}
517+
503518
void QgsComposerPictureWidget::resizeEvent( QResizeEvent * event )
504519
{
505520
Q_UNUSED( event );

src/app/composer/qgscomposerpicturewidget.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,18 @@ class QgsComposerPictureWidget: public QWidget, private Ui::QgsComposerPictureWi
5353
private slots:
5454
/**Sets the GUI elements to the values of mPicture*/
5555
void setGuiElementValues();
56+
/** Load SVG and pixel-based image previews
57+
* @param collapsed Whether the parent group box is collapsed
58+
* @note added in 1.9
59+
*/
60+
void loadPicturePreviews( bool collapsed );
5661

5762
private:
5863
QgsComposerPicture* mPicture;
64+
/** Whether the picture selection previews have been loaded
65+
* @note added in 1.9
66+
*/
67+
bool mPreviewsLoaded;
5968

6069
/**Add the icons of a directory to the preview. Returns 0 in case of success*/
6170
int addDirectoryToPreview( const QString& path );

src/ui/qgscomposerpicturewidgetbase.ui

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@
123123
<string notr="true">composeritem</string>
124124
</property>
125125
<property name="collapsed" stdset="0">
126-
<bool>false</bool>
126+
<bool>true</bool>
127127
</property>
128128
<layout class="QVBoxLayout" name="verticalLayout">
129129
<item>
@@ -133,11 +133,8 @@
133133
<italic>true</italic>
134134
</font>
135135
</property>
136-
<property name="styleSheet">
137-
<string notr="true">color: rgb(19, 133, 54);</string>
138-
</property>
139136
<property name="text">
140-
<string>Loading SVG previews...</string>
137+
<string>Loading previews...</string>
141138
</property>
142139
<property name="alignment">
143140
<set>Qt::AlignCenter</set>

0 commit comments

Comments
 (0)