|
41 | 41 | #include "qgsnewauxiliarylayerdialog.h"
|
42 | 42 | #include "qgsnewauxiliaryfielddialog.h"
|
43 | 43 | #include "qgsauxiliarystorage.h"
|
| 44 | +#include "qgsimagecache.h" |
44 | 45 |
|
45 | 46 | #include <QAbstractButton>
|
46 | 47 | #include <QButtonGroup>
|
@@ -3081,8 +3082,9 @@ QgsRasterMarkerSymbolLayerWidget::QgsRasterMarkerSymbolLayerWidget( QgsVectorLay
|
3081 | 3082 |
|
3082 | 3083 | setupUi( this );
|
3083 | 3084 |
|
3084 |
| - connect( mBrowseToolButton, &QToolButton::clicked, this, &QgsRasterMarkerSymbolLayerWidget::mBrowseToolButton_clicked ); |
3085 |
| - connect( mImageLineEdit, &QLineEdit::editingFinished, this, &QgsRasterMarkerSymbolLayerWidget::mImageLineEdit_editingFinished ); |
| 3085 | + mImageSourceLineEdit->setLastPathSettingsKey( QStringLiteral( "/UI/lastRasterMarkerImageDir" ) ); |
| 3086 | + |
| 3087 | + connect( mImageSourceLineEdit, &QgsImageSourceLineEdit::sourceChanged, this, &QgsRasterMarkerSymbolLayerWidget::imageSourceChanged ); |
3086 | 3088 | connect( mOffsetUnitWidget, &QgsUnitSelectionWidget::changed, this, &QgsRasterMarkerSymbolLayerWidget::mOffsetUnitWidget_changed );
|
3087 | 3089 | connect( mRotationSpinBox, static_cast < void ( QDoubleSpinBox::* )( double ) > ( &QDoubleSpinBox::valueChanged ), this, &QgsRasterMarkerSymbolLayerWidget::setAngle );
|
3088 | 3090 | connect( mSizeUnitWidget, &QgsUnitSelectionWidget::changed, this, &QgsRasterMarkerSymbolLayerWidget::mSizeUnitWidget_changed );
|
@@ -3121,7 +3123,7 @@ void QgsRasterMarkerSymbolLayerWidget::setSymbolLayer( QgsSymbolLayer *layer )
|
3121 | 3123 | mLayer = static_cast<QgsRasterMarkerSymbolLayer *>( layer );
|
3122 | 3124 |
|
3123 | 3125 | // set values
|
3124 |
| - whileBlocking( mImageLineEdit )->setText( mLayer->path() ); |
| 3126 | + whileBlocking( mImageSourceLineEdit )->setSource( mLayer->path() ); |
3125 | 3127 |
|
3126 | 3128 | whileBlocking( mWidthSpinBox )->setValue( mLayer->size() );
|
3127 | 3129 | bool preservedAspectRatio = mLayer->preservedAspectRatio();
|
@@ -3174,74 +3176,23 @@ QgsSymbolLayer *QgsRasterMarkerSymbolLayerWidget::symbolLayer()
|
3174 | 3176 | return mLayer;
|
3175 | 3177 | }
|
3176 | 3178 |
|
3177 |
| -void QgsRasterMarkerSymbolLayerWidget::mBrowseToolButton_clicked() |
| 3179 | +void QgsRasterMarkerSymbolLayerWidget::imageSourceChanged( const QString &text ) |
3178 | 3180 | {
|
3179 |
| - QgsSettings s; |
3180 |
| - QString openDir; |
3181 |
| - QString lineEditText = mImageLineEdit->text(); |
3182 |
| - if ( !lineEditText.isEmpty() ) |
3183 |
| - { |
3184 |
| - QFileInfo openDirFileInfo( lineEditText ); |
3185 |
| - openDir = openDirFileInfo.path(); |
3186 |
| - } |
3187 |
| - |
3188 |
| - if ( openDir.isEmpty() ) |
3189 |
| - { |
3190 |
| - openDir = s.value( QStringLiteral( "/UI/lastRasterMarkerImageDir" ), QDir::homePath() ).toString(); |
3191 |
| - } |
3192 |
| - |
3193 |
| - //show file dialog |
3194 |
| - QString filePath = QFileDialog::getOpenFileName( nullptr, tr( "Select Image File" ), openDir ); |
3195 |
| - if ( !filePath.isNull() ) |
3196 |
| - { |
3197 |
| - //check if file exists |
3198 |
| - QFileInfo fileInfo( filePath ); |
3199 |
| - if ( !fileInfo.exists() || !fileInfo.isReadable() ) |
3200 |
| - { |
3201 |
| - QMessageBox::critical( nullptr, QStringLiteral( "Select Image File" ), QStringLiteral( "Error, file does not exist or is not readable." ) ); |
3202 |
| - return; |
3203 |
| - } |
3204 |
| - |
3205 |
| - s.setValue( QStringLiteral( "/UI/lastRasterMarkerImageDir" ), fileInfo.absolutePath() ); |
3206 |
| - mImageLineEdit->setText( filePath ); |
3207 |
| - mImageLineEdit_editingFinished(); |
3208 |
| - } |
3209 |
| -} |
3210 |
| - |
3211 |
| -void QgsRasterMarkerSymbolLayerWidget::mImageLineEdit_editingFinished() |
3212 |
| -{ |
3213 |
| - QFileInfo fi( mImageLineEdit->text() ); |
3214 |
| - if ( !fi.exists() ) |
3215 |
| - { |
3216 |
| - QUrl url( mImageLineEdit->text() ); |
3217 |
| - if ( !url.isValid() ) |
3218 |
| - { |
3219 |
| - return; |
3220 |
| - } |
3221 |
| - } |
3222 |
| - |
3223 |
| - QApplication::setOverrideCursor( QCursor( Qt::WaitCursor ) ); |
3224 |
| - mLayer->setPath( mImageLineEdit->text() ); |
| 3181 | + mLayer->setPath( text ); |
3225 | 3182 | updatePreviewImage();
|
3226 |
| - QApplication::restoreOverrideCursor(); |
3227 |
| - |
3228 | 3183 | emit changed();
|
3229 | 3184 | }
|
3230 | 3185 |
|
3231 | 3186 | void QgsRasterMarkerSymbolLayerWidget::updatePreviewImage()
|
3232 | 3187 | {
|
3233 |
| - QImage image( mLayer->path() ); |
| 3188 | + bool fitsInCache = false; |
| 3189 | + QImage image = QgsApplication::imageCache()->pathAsImage( mLayer->path(), QSize( 150, 150 ), true, 1.0, fitsInCache ); |
3234 | 3190 | if ( image.isNull() )
|
3235 | 3191 | {
|
3236 | 3192 | mLabelImagePreview->setPixmap( QPixmap() );
|
3237 | 3193 | return;
|
3238 | 3194 | }
|
3239 | 3195 |
|
3240 |
| - if ( image.height() > 150 || image.width() > 150 ) |
3241 |
| - { |
3242 |
| - image = image.scaled( 150, 150, Qt::KeepAspectRatio, Qt::SmoothTransformation ); |
3243 |
| - } |
3244 |
| - |
3245 | 3196 | QImage previewImage( 150, 150, QImage::Format_ARGB32 );
|
3246 | 3197 | previewImage.fill( Qt::transparent );
|
3247 | 3198 | QRect imageRect( ( 150 - image.width() ) / 2.0, ( 150 - image.height() ) / 2.0, image.width(), image.height() );
|
|
0 commit comments