mirror of
https://github.com/qgis/QGIS.git
synced 2025-04-16 00:03:12 -04:00
Delay loading of composer picture preview icons until widget is shown
This commit is contained in:
parent
c0cf1abee5
commit
5caa4037f3
@ -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
|
||||
@ -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 );
|
||||
}
|
||||
|
||||
|
@ -27,6 +27,7 @@ class QgsComposerArrow;
|
||||
class QgsComposerLabel;
|
||||
class QgsComposerLegend;
|
||||
class QgsComposerPicture;
|
||||
class QgsComposerPictureWidget;
|
||||
class QgsComposerScaleBar;
|
||||
class QgsComposerShape;
|
||||
class QgsComposerAttributeTable;
|
||||
@ -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;
|
||||
|
@ -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 );
|
||||
|
||||
@ -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() ) );
|
||||
}
|
||||
@ -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() )
|
||||
@ -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++ )
|
||||
@ -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();
|
||||
}
|
||||
|
||||
|
@ -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();
|
||||
@ -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*/
|
||||
|
@ -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">
|
||||
@ -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>
|
||||
|
Loading…
x
Reference in New Issue
Block a user