Navigation Menu

Skip to content

Commit

Permalink
Fix for #7458, project crashes when loaded from command line
Browse files Browse the repository at this point in the history
- 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 e2bd04f
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 36 deletions.
21 changes: 0 additions & 21 deletions src/app/composer/qgscomposer.cpp
Expand Up @@ -1725,7 +1725,6 @@ void QgsComposer::showEvent( QShowEvent* event )
if ( event->spontaneous() ) //event from the window system
{
restoreComposerMapStates();
initialiseComposerPicturePreviews();
}

#ifdef Q_WS_MAC
Expand Down Expand Up @@ -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 );
}

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

restoreComposerMapStates();
initialiseComposerPicturePreviews();
}

void QgsComposer::on_mActionPageSetup_triggered()
Expand All @@ -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();
Expand Down
5 changes: 0 additions & 5 deletions src/app/composer/qgscomposer.h
Expand Up @@ -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();

Expand Down Expand Up @@ -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;
Expand Down
25 changes: 20 additions & 5 deletions src/app/composer/qgscomposerpicturewidget.cpp
Expand Up @@ -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 );

Expand All @@ -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() ) );
}
Expand Down Expand Up @@ -464,6 +469,8 @@ void QgsComposerPictureWidget::addStandardDirectoriesToPreview()
addDirectoryToPreview( *userDirIt );
mSearchDirectoriesComboBox->addItem( *userDirIt );
}

mPreviewsLoaded = true;
}

bool QgsComposerPictureWidget::testSvgFile( const QString& filename ) const
Expand All @@ -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();
Expand All @@ -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 );
Expand Down
9 changes: 9 additions & 0 deletions src/app/composer/qgscomposerpicturewidget.h
Expand Up @@ -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 );
Expand Down
7 changes: 2 additions & 5 deletions src/ui/qgscomposerpicturewidgetbase.ui
Expand Up @@ -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>
Expand All @@ -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>
Expand Down

0 comments on commit e2bd04f

Please sign in to comment.