Skip to content

Commit

Permalink
Wire in QgsRasterLayerSaveAsDialog in QgisApp
Browse files Browse the repository at this point in the history
  • Loading branch information
mhugent committed Jul 11, 2012
1 parent b5be666 commit 1e6c400
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 6 deletions.
13 changes: 12 additions & 1 deletion src/app/qgisapp.cpp
Expand Up @@ -158,6 +158,7 @@
#include "qgspythonrunner.h"
#include "qgsquerybuilder.h"
#include "qgsrastercalcdialog.h"
#include "qgsrasterfilewriter.h"
#include "qgsrasterlayer.h"
#include "qgsrasterlayerproperties.h"
#include "qgsrasterrenderer.h"
Expand Down Expand Up @@ -3771,7 +3772,17 @@ void QgisApp::saveAsRasterFile()
}

QgsRasterLayerSaveAsDialog d( rasterLayer->dataProvider() );
d.exec();
if ( d.exec() == QDialog::Accepted )
{
QgsRasterFileWriter fileWriter( d.outputFileName() );
if ( d.tileMode() )
{
fileWriter.setTiledMode( true );
fileWriter.setMaxTileWidth( d.maximumTileSizeX() );
fileWriter.setMaxTileHeight( d.maximumTileSizeY() );
}
fileWriter.writeRaster( rasterLayer->dataProvider(), d.nColumns() );
}
}

void QgisApp::saveAsFile()
Expand Down
1 change: 1 addition & 0 deletions src/gui/CMakeLists.txt
Expand Up @@ -153,6 +153,7 @@ qgscredentialdialog.h
qgsowssourceselect.h
qgsprojectionselector.h
qgsquickprint.h
qgsrasterlayersaveasdialog.h
qgsludialog.h
qgsprojectbadlayerguihandler.h
qgslonglongvalidator.h
Expand Down
36 changes: 36 additions & 0 deletions src/gui/qgsrasterlayersaveasdialog.cpp
@@ -1,5 +1,6 @@
#include "qgsrasterlayersaveasdialog.h"
#include "qgsrasterdataprovider.h"
#include <QFileDialog>

QgsRasterLayerSaveAsDialog::QgsRasterLayerSaveAsDialog( QgsRasterDataProvider* sourceProvider,
QWidget* parent, Qt::WindowFlags f ): QDialog( parent, f ),
Expand Down Expand Up @@ -30,6 +31,12 @@ QgsRasterLayerSaveAsDialog::QgsRasterLayerSaveAsDialog( QgsRasterDataProvider* s
mMaximumSizeYLineEdit->setText( QString::number( 2000 ) );
}
}

QPushButton* okButton = mButtonBox->button( QDialogButtonBox::Ok );
if ( okButton )
{
okButton->setEnabled( false );
}
}

void QgsRasterLayerSaveAsDialog::setValidators()
Expand All @@ -44,6 +51,35 @@ QgsRasterLayerSaveAsDialog::~QgsRasterLayerSaveAsDialog()
{
}

void QgsRasterLayerSaveAsDialog::on_mBrowseButton_clicked()
{
QString fileName;
if ( mTileModeCheckBox->isChecked() )
{
fileName = QFileDialog::getExistingDirectory( this, tr( "Select output directory" ) );
}
else
{
fileName = QFileDialog::getOpenFileName( this, tr( "Select output file" ) );
}

if ( !fileName.isEmpty() )
{
mSaveAsLineEdit->setText( fileName );
}
}

void QgsRasterLayerSaveAsDialog::on_mSaveAsLineEdit_textChanged( const QString& text )
{
QPushButton* okButton = mButtonBox->button( QDialogButtonBox::Ok );
if ( !okButton )
{
return;
}

okButton->setEnabled( QFile::exists( text ) );
}

int QgsRasterLayerSaveAsDialog::nColumns() const
{
return mColumnsLineEdit->text().toInt();
Expand Down
5 changes: 5 additions & 0 deletions src/gui/qgsrasterlayersaveasdialog.h
Expand Up @@ -7,6 +7,7 @@ class QgsRasterDataProvider;

class QgsRasterLayerSaveAsDialog: public QDialog, private Ui::QgsRasterLayerSaveAsDialogBase
{
Q_OBJECT
public:
QgsRasterLayerSaveAsDialog( QgsRasterDataProvider* sourceProvider, QWidget* parent = 0, Qt::WindowFlags f = 0 );
~QgsRasterLayerSaveAsDialog();
Expand All @@ -19,6 +20,10 @@ class QgsRasterLayerSaveAsDialog: public QDialog, private Ui::QgsRasterLayerSave
QString outputFileName() const;
QString outputFormat() const;

private slots:
void on_mBrowseButton_clicked();
void on_mSaveAsLineEdit_textChanged( const QString& text );

private:
QgsRasterDataProvider* mDataProvider;

Expand Down
10 changes: 5 additions & 5 deletions src/ui/qgsrasterlayersaveasdialogbase.ui
Expand Up @@ -40,14 +40,14 @@
<item row="1" column="1">
<widget class="QLineEdit" name="mSaveAsLineEdit">
<property name="enabled">
<bool>false</bool>
<bool>true</bool>
</property>
</widget>
</item>
<item row="1" column="2">
<widget class="QPushButton" name="mBrowseButton">
<property name="enabled">
<bool>false</bool>
<bool>true</bool>
</property>
<property name="text">
<string>Browse...</string>
Expand Down Expand Up @@ -115,7 +115,7 @@
</widget>
</item>
<item row="4" column="0" colspan="2">
<widget class="QDialogButtonBox" name="buttonBox">
<widget class="QDialogButtonBox" name="mButtonBox">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
Expand All @@ -129,7 +129,7 @@
<resources/>
<connections>
<connection>
<sender>buttonBox</sender>
<sender>mButtonBox</sender>
<signal>accepted()</signal>
<receiver>QgsRasterLayerSaveAsDialogBase</receiver>
<slot>accept()</slot>
Expand All @@ -145,7 +145,7 @@
</hints>
</connection>
<connection>
<sender>buttonBox</sender>
<sender>mButtonBox</sender>
<signal>rejected()</signal>
<receiver>QgsRasterLayerSaveAsDialogBase</receiver>
<slot>reject()</slot>
Expand Down

0 comments on commit 1e6c400

Please sign in to comment.