Skip to content
Permalink
Browse files

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
  • Loading branch information
dakcarto committed Jun 1, 2013
1 parent e87623d commit e2bd04f39a9a05865dfc8d650269b454464031c5
@@ -1725,7 +1725,6 @@ void QgsComposer::showEvent( QShowEvent* event )
if ( event->spontaneous() ) //event from the window system
{
restoreComposerMapStates();
initialiseComposerPicturePreviews();
}

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

QgsComposerPictureWidget* pWidget = new QgsComposerPictureWidget( picture );
if ( isVisible() )
{
pWidget->addStandardDirectoriesToPreview();
}
else
{
mPicturePreviews.append( pWidget );
}
mItemWidgetMap.insert( picture, pWidget );
}

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

restoreComposerMapStates();
initialiseComposerPicturePreviews();
}

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

void QgsComposer::initialiseComposerPicturePreviews()
{
//create composer picture widget previews
QList< QgsComposerPictureWidget* >::iterator picIt = mPicturePreviews.begin();
for ( ; picIt != mPicturePreviews.end(); ++picIt )
{
( *picIt )->addStandardDirectoriesToPreview();
}
mPicturePreviews.clear();
}

void QgsComposer::populatePrintComposersMenu()
{
mPrintComposersMenu->clear();
@@ -331,10 +331,6 @@ class QgsComposer: public QMainWindow, private Ui::QgsComposerBase
//! Initially after reading from xml, states are set to rectangle to achieve faster project loading.
void restoreComposerMapStates();

//! Fills icons into composer picture widgets
//! To make loading from project faster, the previews are generated when the composer becomes visible.
void initialiseComposerPicturePreviews();

//! Create composer view and rulers
void createComposerView();

@@ -375,7 +371,6 @@ 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
QMap< QgsComposerMap*, int > mMapsToRestore;
QList< QgsComposerPictureWidget* > mPicturePreviews;

QDockWidget* mItemDock;
QDockWidget* mUndoDock;
@@ -31,7 +31,7 @@
#include <QSettings>
#include <QSvgRenderer>

QgsComposerPictureWidget::QgsComposerPictureWidget( QgsComposerPicture* picture ): QWidget(), mPicture( picture )
QgsComposerPictureWidget::QgsComposerPictureWidget( QgsComposerPicture* picture ): QWidget(), mPicture( picture ), mPreviewsLoaded( false )
{
setupUi( this );

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

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

// mSearchDirectoriesGroupBox is a QgsCollapsibleGroupBoxBasic, so its collapsed state should not be saved/restored
mSearchDirectoriesGroupBox->setCollapsed( true );
// setup connection for loading previews on first expansion of group box
connect( mSearchDirectoriesGroupBox, SIGNAL( collapsedStateChanged( bool ) ), this, SLOT( loadPicturePreviews( bool ) ) );

connect( mPicture, SIGNAL( itemChanged() ), this, SLOT( setGuiElementValues() ) );
connect( mPicture, SIGNAL( rotationChanged( double ) ), this, SLOT( setGuiElementValues() ) );
}
@@ -464,6 +469,8 @@ void QgsComposerPictureWidget::addStandardDirectoriesToPreview()
addDirectoryToPreview( *userDirIt );
mSearchDirectoriesComboBox->addItem( *userDirIt );
}

mPreviewsLoaded = true;
}

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

void QgsComposerPictureWidget::showEvent( QShowEvent * event )
void QgsComposerPictureWidget::loadPicturePreviews( bool collapsed )
{
Q_UNUSED( event );
refreshMapComboBox();
if ( mPreviewsLoaded )
{
return;
}

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

void QgsComposerPictureWidget::showEvent( QShowEvent * event )
{
Q_UNUSED( event );
refreshMapComboBox();
}

void QgsComposerPictureWidget::resizeEvent( QResizeEvent * event )
{
Q_UNUSED( event );
@@ -53,9 +53,18 @@ class QgsComposerPictureWidget: public QWidget, private Ui::QgsComposerPictureWi
private slots:
/**Sets the GUI elements to the values of mPicture*/
void setGuiElementValues();
/** Load SVG and pixel-based image previews
* @param collapsed Whether the parent group box is collapsed
* @note added in 1.9
*/
void loadPicturePreviews( bool collapsed );

private:
QgsComposerPicture* mPicture;
/** Whether the picture selection previews have been loaded
* @note added in 1.9
*/
bool mPreviewsLoaded;

/**Add the icons of a directory to the preview. Returns 0 in case of success*/
int addDirectoryToPreview( const QString& path );
@@ -123,7 +123,7 @@
<string notr="true">composeritem</string>
</property>
<property name="collapsed" stdset="0">
<bool>false</bool>
<bool>true</bool>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
@@ -133,11 +133,8 @@
<italic>true</italic>
</font>
</property>
<property name="styleSheet">
<string notr="true">color: rgb(19, 133, 54);</string>
</property>
<property name="text">
<string>Loading SVG previews...</string>
<string>Loading previews...</string>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>

0 comments on commit e2bd04f

Please sign in to comment.
You can’t perform that action at this time.