Skip to content

Commit

Permalink
Delay loading of composer picture preview icons until widget is shown
Browse files Browse the repository at this point in the history
  • Loading branch information
mhugent committed Feb 28, 2012
1 parent c0cf1ab commit 5caa403
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 22 deletions.
16 changes: 16 additions & 0 deletions src/app/composer/qgscomposer.cpp
Expand Up @@ -1134,6 +1134,14 @@ void QgsComposer::showEvent( QShowEvent* event )
mapIt.key()->update();
}
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
Expand Down Expand Up @@ -1382,6 +1390,14 @@ void QgsComposer::addComposerPicture( QgsComposerPicture* picture )
}

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

Expand Down
2 changes: 2 additions & 0 deletions src/app/composer/qgscomposer.h
Expand Up @@ -27,6 +27,7 @@ class QgsComposerArrow;
class QgsComposerLabel;
class QgsComposerLegend;
class QgsComposerPicture;
class QgsComposerPictureWidget;
class QgsComposerScaleBar;
class QgsComposerShape;
class QgsComposerAttributeTable;
Expand Down Expand Up @@ -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
QMap< QgsComposerMap*, int > mMapsToRestore;
QList< QgsComposerPictureWidget* > mPicturePreviews;

QDockWidget* mItemDock;
QDockWidget* mUndoDock;
Expand Down
24 changes: 10 additions & 14 deletions src/app/composer/qgscomposerpicturewidget.cpp
Expand Up @@ -30,7 +30,7 @@
#include <QSettings>
#include <QSvgRenderer>

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

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

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

//add preview icons on demand in showEvent()

connect( mPicture, SIGNAL( itemChanged() ), this, SLOT( setGuiElementValues() ) );
connect( mPicture, SIGNAL( rotationChanged( double ) ), this, SLOT( setGuiElementValues() ) );
}
Expand Down Expand Up @@ -261,17 +259,6 @@ void QgsComposerPictureWidget::on_mRotationFromComposerMapCheckBox_stateChanged(
mPicture->endCommand();
}

void QgsComposerPictureWidget::showEvent( QShowEvent * event )
{
refreshMapComboBox();
if ( !mPreviewInitialized )
{
addStandardDirectoriesToPreview();
mPreviewInitialized = true;
}
QWidget::showEvent( event );
}

void QgsComposerPictureWidget::on_mComposerMapComboBox_activated( const QString & text )
{
if ( !mPicture || text.isEmpty() || !mPicture->useRotationMap() )
Expand Down Expand Up @@ -481,6 +468,8 @@ int QgsComposerPictureWidget::addDirectoryToPreview( const QString& path )

void QgsComposerPictureWidget::addStandardDirectoriesToPreview()
{
mPreviewListWidget->clear();

//list all directories in $prefix/share/qgis/svg
QStringList svgPaths = QgsApplication::svgPaths();
for ( int i = 0; i < svgPaths.size(); i++ )
Expand Down Expand Up @@ -536,3 +525,10 @@ bool QgsComposerPictureWidget::testImageFile( const QString& filename ) const
QString formatName = QString( QImageReader::imageFormat( filename ) );
return !formatName.isEmpty(); //file is in a supported pixel format
}

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

13 changes: 7 additions & 6 deletions src/app/composer/qgscomposerpicturewidget.h
Expand Up @@ -33,6 +33,9 @@ class QgsComposerPictureWidget: public QWidget, private Ui::QgsComposerPictureWi
QgsComposerPictureWidget( QgsComposerPicture* picture );
~QgsComposerPictureWidget();

/**Add the icons of the standard directories to the preview*/
void addStandardDirectoriesToPreview();

public slots:
void on_mPictureBrowseButton_clicked();
void on_mPictureLineEdit_editingFinished();
Expand All @@ -45,21 +48,19 @@ class QgsComposerPictureWidget: public QWidget, private Ui::QgsComposerPictureWi
void on_mRotationFromComposerMapCheckBox_stateChanged( int state );
void on_mComposerMapComboBox_activated( const QString & text );

protected:
void showEvent( QShowEvent * event );

private slots:
/**Sets the GUI elements to the values of mPicture*/
void setGuiElementValues();

protected:
void showEvent( QShowEvent * event );

private:
QgsComposerPicture* mPicture;
bool mPreviewInitialized;

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

/**Tests if a file is valid svg*/
bool testSvgFile( const QString& filename ) const;
/**Tests if a file is a valid pixel format*/
Expand Down
7 changes: 5 additions & 2 deletions src/ui/qgscomposerpicturewidgetbase.ui
Expand Up @@ -33,8 +33,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>327</width>
<height>585</height>
<width>317</width>
<height>577</height>
</rect>
</property>
<attribute name="label">
Expand Down Expand Up @@ -79,6 +79,9 @@
<property name="isWrapping" stdset="0">
<bool>true</bool>
</property>
<property name="resizeMode">
<enum>QListView::Adjust</enum>
</property>
<property name="gridSize">
<size>
<width>30</width>
Expand Down

0 comments on commit 5caa403

Please sign in to comment.