Skip to content

Commit b6ff401

Browse files
committedFeb 8, 2018
[raster calc] make use of qgsfilewidget and fix some labels
1 parent a29d6d2 commit b6ff401

File tree

3 files changed

+18
-51
lines changed

3 files changed

+18
-51
lines changed
 

‎src/app/qgsrastercalcdialog.cpp

Lines changed: 8 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,10 @@ QgsRasterCalcDialog::QgsRasterCalcDialog( QgsRasterLayer *rasterLayer, QWidget *
3434
setupUi( this );
3535
QgsGui::instance()->enableAutoGeometryRestore( this );
3636

37-
connect( mOutputLayerPushButton, &QPushButton::clicked, this, &QgsRasterCalcDialog::mOutputLayerPushButton_clicked );
3837
connect( mRasterBandsListWidget, &QListWidget::itemDoubleClicked, this, &QgsRasterCalcDialog::mRasterBandsListWidget_itemDoubleClicked );
3938
connect( mButtonBox, &QDialogButtonBox::accepted, this, &QgsRasterCalcDialog::mButtonBox_accepted );
4039
connect( mCurrentLayerExtentButton, &QPushButton::clicked, this, &QgsRasterCalcDialog::mCurrentLayerExtentButton_clicked );
4140
connect( mExpressionTextEdit, &QTextEdit::textChanged, this, &QgsRasterCalcDialog::mExpressionTextEdit_textChanged );
42-
connect( mOutputLayerLineEdit, &QLineEdit::textChanged, this, &QgsRasterCalcDialog::mOutputLayerLineEdit_textChanged );
4341
connect( mPlusPushButton, &QPushButton::clicked, this, &QgsRasterCalcDialog::mPlusPushButton_clicked );
4442
connect( mMinusPushButton, &QPushButton::clicked, this, &QgsRasterCalcDialog::mMinusPushButton_clicked );
4543
connect( mMultiplyPushButton, &QPushButton::clicked, this, &QgsRasterCalcDialog::mMultiplyPushButton_clicked );
@@ -77,6 +75,11 @@ QgsRasterCalcDialog::QgsRasterCalcDialog( QgsRasterLayer *rasterLayer, QWidget *
7775
insertAvailableRasterBands();
7876

7977
mExpressionTextEdit->setCurrentFont( QFontDatabase::systemFont( QFontDatabase::FixedFont ) );
78+
79+
QgsSettings settings;
80+
mOutputLayer->setDialogTitle( tr( "Enter result file" ) );
81+
mOutputLayer->setDefaultRoot( settings.value( QStringLiteral( "/RasterCalculator/lastOutputDir" ), QDir::homePath() ).toString() );
82+
connect( mOutputLayer, &QgsFileWidget::fileChanged, this, [ = ]() { setAcceptButtonState(); } );
8083
}
8184

8285
QString QgsRasterCalcDialog::formulaString() const
@@ -86,7 +89,7 @@ QString QgsRasterCalcDialog::formulaString() const
8689

8790
QString QgsRasterCalcDialog::outputFile() const
8891
{
89-
QString outputFileName = mOutputLayerLineEdit->text();
92+
QString outputFileName = mOutputLayer->filePath();
9093
QFileInfo fileInfo( outputFileName );
9194
QString suffix = fileInfo.suffix();
9295
if ( !suffix.isEmpty() )
@@ -253,24 +256,14 @@ void QgsRasterCalcDialog::mButtonBox_accepted()
253256
//save last output format
254257
QgsSettings s;
255258
s.setValue( QStringLiteral( "/RasterCalculator/lastOutputFormat" ), QVariant( mOutputFormatComboBox->currentText() ) );
256-
s.setValue( QStringLiteral( "/RasterCalculator/lastOutputDir" ), QVariant( QFileInfo( mOutputLayerLineEdit->text() ).absolutePath() ) );
259+
s.setValue( QStringLiteral( "/RasterCalculator/lastOutputDir" ), QVariant( QFileInfo( mOutputLayer->filePath() ).absolutePath() ) );
257260
}
258261

259262
void QgsRasterCalcDialog::showHelp()
260263
{
261264
QgsHelp::openHelp( QStringLiteral( "working_with_raster/raster_analysis.html#raster-calculator" ) );
262265
}
263266

264-
void QgsRasterCalcDialog::mOutputLayerPushButton_clicked()
265-
{
266-
QgsSettings s;
267-
QString saveFileName = QFileDialog::getSaveFileName( nullptr, tr( "Enter result file" ), s.value( QStringLiteral( "/RasterCalculator/lastOutputDir" ), QDir::homePath() ).toString() );
268-
if ( !saveFileName.isNull() )
269-
{
270-
mOutputLayerLineEdit->setText( saveFileName );
271-
}
272-
}
273-
274267
void QgsRasterCalcDialog::mCurrentLayerExtentButton_clicked()
275268
{
276269
QListWidgetItem *currentLayerItem = mRasterBandsListWidget->currentItem();
@@ -320,12 +313,6 @@ void QgsRasterCalcDialog::mExpressionTextEdit_textChanged()
320313
mButtonBox->button( QDialogButtonBox::Ok )->setEnabled( false );
321314
}
322315

323-
void QgsRasterCalcDialog::mOutputLayerLineEdit_textChanged( const QString &text )
324-
{
325-
Q_UNUSED( text );
326-
setAcceptButtonState();
327-
}
328-
329316
void QgsRasterCalcDialog::setAcceptButtonState()
330317
{
331318
if ( expressionValid() && filePathValid() )
@@ -352,7 +339,7 @@ bool QgsRasterCalcDialog::expressionValid() const
352339

353340
bool QgsRasterCalcDialog::filePathValid() const
354341
{
355-
QString outputPath = mOutputLayerLineEdit->text();
342+
QString outputPath = mOutputLayer->filePath();
356343
if ( outputPath.isEmpty() )
357344
return false;
358345

‎src/app/qgsrastercalcdialog.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,10 @@ class APP_EXPORT QgsRasterCalcDialog: public QDialog, private Ui::QgsRasterCalcD
4646
QVector<QgsRasterCalculatorEntry> rasterEntries() const;
4747

4848
private slots:
49-
void mOutputLayerPushButton_clicked();
5049
void mRasterBandsListWidget_itemDoubleClicked( QListWidgetItem *item );
5150
void mButtonBox_accepted();
5251
void mCurrentLayerExtentButton_clicked();
5352
void mExpressionTextEdit_textChanged();
54-
void mOutputLayerLineEdit_textChanged( const QString &text );
5553
//! Enables OK button if calculator expression is valid and output file path exists
5654
void setAcceptButtonState();
5755
void showHelp();

‎src/ui/qgsrastercalcdialogbase.ui

Lines changed: 10 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@
8484
<item row="1" column="3">
8585
<widget class="QLabel" name="mXMaxLabel">
8686
<property name="text">
87-
<string>XMax</string>
87+
<string>X Max</string>
8888
</property>
8989
</widget>
9090
</item>
@@ -163,8 +163,8 @@
163163
</item>
164164
</layout>
165165
</item>
166-
<item row="0" column="1" colspan="2">
167-
<widget class="QLineEdit" name="mOutputLayerLineEdit"/>
166+
<item row="0" column="1" colspan="3">
167+
<widget class="QgsFileWidget" name="mOutputLayer"/>
168168
</item>
169169
<item row="1" column="0">
170170
<widget class="QLabel" name="mOutputFormatLabel">
@@ -176,7 +176,7 @@
176176
<item row="2" column="0">
177177
<widget class="QPushButton" name="mCurrentLayerExtentButton">
178178
<property name="text">
179-
<string>Current layer extent</string>
179+
<string>Selected layer extent</string>
180180
</property>
181181
</widget>
182182
</item>
@@ -185,28 +185,6 @@
185185
<property name="text">
186186
<string>Output layer</string>
187187
</property>
188-
<property name="buddy">
189-
<cstring>mOutputLayerPushButton</cstring>
190-
</property>
191-
</widget>
192-
</item>
193-
<item row="0" column="3">
194-
<widget class="QPushButton" name="mOutputLayerPushButton">
195-
<property name="sizePolicy">
196-
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
197-
<horstretch>0</horstretch>
198-
<verstretch>0</verstretch>
199-
</sizepolicy>
200-
</property>
201-
<property name="minimumSize">
202-
<size>
203-
<width>20</width>
204-
<height>0</height>
205-
</size>
206-
</property>
207-
<property name="text">
208-
<string>…</string>
209-
</property>
210188
</widget>
211189
</item>
212190
<item row="6" column="0" colspan="4">
@@ -526,11 +504,15 @@
526504
<header>qgsprojectionselectionwidget.h</header>
527505
<container>1</container>
528506
</customwidget>
507+
<customwidget>
508+
<class>QgsFileWidget</class>
509+
<extends>QWidget</extends>
510+
<header>qgsfilewidget.h</header>
511+
</customwidget>
529512
</customwidgets>
530513
<tabstops>
531514
<tabstop>mRasterBandsListWidget</tabstop>
532-
<tabstop>mOutputLayerLineEdit</tabstop>
533-
<tabstop>mOutputLayerPushButton</tabstop>
515+
<tabstop>mOutputLayer</tabstop>
534516
<tabstop>mOutputFormatComboBox</tabstop>
535517
<tabstop>mCurrentLayerExtentButton</tabstop>
536518
<tabstop>mXMinSpinBox</tabstop>

0 commit comments

Comments
 (0)
Please sign in to comment.