Skip to content
Permalink
Browse files

[raster calc] make use of qgsfilewidget and fix some labels

  • Loading branch information
nirvn committed Feb 8, 2018
1 parent a29d6d2 commit b6ff401452b8d358f747a2a99d52f358f552c7d2
Showing with 18 additions and 51 deletions.
  1. +8 −21 src/app/qgsrastercalcdialog.cpp
  2. +0 −2 src/app/qgsrastercalcdialog.h
  3. +10 −28 src/ui/qgsrastercalcdialogbase.ui
@@ -34,12 +34,10 @@ QgsRasterCalcDialog::QgsRasterCalcDialog( QgsRasterLayer *rasterLayer, QWidget *
setupUi( this );
QgsGui::instance()->enableAutoGeometryRestore( this );

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

mExpressionTextEdit->setCurrentFont( QFontDatabase::systemFont( QFontDatabase::FixedFont ) );

QgsSettings settings;
mOutputLayer->setDialogTitle( tr( "Enter result file" ) );
mOutputLayer->setDefaultRoot( settings.value( QStringLiteral( "/RasterCalculator/lastOutputDir" ), QDir::homePath() ).toString() );
connect( mOutputLayer, &QgsFileWidget::fileChanged, this, [ = ]() { setAcceptButtonState(); } );
}

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

QString QgsRasterCalcDialog::outputFile() const
{
QString outputFileName = mOutputLayerLineEdit->text();
QString outputFileName = mOutputLayer->filePath();
QFileInfo fileInfo( outputFileName );
QString suffix = fileInfo.suffix();
if ( !suffix.isEmpty() )
@@ -253,24 +256,14 @@ void QgsRasterCalcDialog::mButtonBox_accepted()
//save last output format
QgsSettings s;
s.setValue( QStringLiteral( "/RasterCalculator/lastOutputFormat" ), QVariant( mOutputFormatComboBox->currentText() ) );
s.setValue( QStringLiteral( "/RasterCalculator/lastOutputDir" ), QVariant( QFileInfo( mOutputLayerLineEdit->text() ).absolutePath() ) );
s.setValue( QStringLiteral( "/RasterCalculator/lastOutputDir" ), QVariant( QFileInfo( mOutputLayer->filePath() ).absolutePath() ) );
}

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

void QgsRasterCalcDialog::mOutputLayerPushButton_clicked()
{
QgsSettings s;
QString saveFileName = QFileDialog::getSaveFileName( nullptr, tr( "Enter result file" ), s.value( QStringLiteral( "/RasterCalculator/lastOutputDir" ), QDir::homePath() ).toString() );
if ( !saveFileName.isNull() )
{
mOutputLayerLineEdit->setText( saveFileName );
}
}

void QgsRasterCalcDialog::mCurrentLayerExtentButton_clicked()
{
QListWidgetItem *currentLayerItem = mRasterBandsListWidget->currentItem();
@@ -320,12 +313,6 @@ void QgsRasterCalcDialog::mExpressionTextEdit_textChanged()
mButtonBox->button( QDialogButtonBox::Ok )->setEnabled( false );
}

void QgsRasterCalcDialog::mOutputLayerLineEdit_textChanged( const QString &text )
{
Q_UNUSED( text );
setAcceptButtonState();
}

void QgsRasterCalcDialog::setAcceptButtonState()
{
if ( expressionValid() && filePathValid() )
@@ -352,7 +339,7 @@ bool QgsRasterCalcDialog::expressionValid() const

bool QgsRasterCalcDialog::filePathValid() const
{
QString outputPath = mOutputLayerLineEdit->text();
QString outputPath = mOutputLayer->filePath();
if ( outputPath.isEmpty() )
return false;

@@ -46,12 +46,10 @@ class APP_EXPORT QgsRasterCalcDialog: public QDialog, private Ui::QgsRasterCalcD
QVector<QgsRasterCalculatorEntry> rasterEntries() const;

private slots:
void mOutputLayerPushButton_clicked();
void mRasterBandsListWidget_itemDoubleClicked( QListWidgetItem *item );
void mButtonBox_accepted();
void mCurrentLayerExtentButton_clicked();
void mExpressionTextEdit_textChanged();
void mOutputLayerLineEdit_textChanged( const QString &text );
//! Enables OK button if calculator expression is valid and output file path exists
void setAcceptButtonState();
void showHelp();
@@ -84,7 +84,7 @@
<item row="1" column="3">
<widget class="QLabel" name="mXMaxLabel">
<property name="text">
<string>XMax</string>
<string>X Max</string>
</property>
</widget>
</item>
@@ -163,8 +163,8 @@
</item>
</layout>
</item>
<item row="0" column="1" colspan="2">
<widget class="QLineEdit" name="mOutputLayerLineEdit"/>
<item row="0" column="1" colspan="3">
<widget class="QgsFileWidget" name="mOutputLayer"/>
</item>
<item row="1" column="0">
<widget class="QLabel" name="mOutputFormatLabel">
@@ -176,7 +176,7 @@
<item row="2" column="0">
<widget class="QPushButton" name="mCurrentLayerExtentButton">
<property name="text">
<string>Current layer extent</string>
<string>Selected layer extent</string>
</property>
</widget>
</item>
@@ -185,28 +185,6 @@
<property name="text">
<string>Output layer</string>
</property>
<property name="buddy">
<cstring>mOutputLayerPushButton</cstring>
</property>
</widget>
</item>
<item row="0" column="3">
<widget class="QPushButton" name="mOutputLayerPushButton">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>20</width>
<height>0</height>
</size>
</property>
<property name="text">
<string>…</string>
</property>
</widget>
</item>
<item row="6" column="0" colspan="4">
@@ -526,11 +504,15 @@
<header>qgsprojectionselectionwidget.h</header>
<container>1</container>
</customwidget>
<customwidget>
<class>QgsFileWidget</class>
<extends>QWidget</extends>
<header>qgsfilewidget.h</header>
</customwidget>
</customwidgets>
<tabstops>
<tabstop>mRasterBandsListWidget</tabstop>
<tabstop>mOutputLayerLineEdit</tabstop>
<tabstop>mOutputLayerPushButton</tabstop>
<tabstop>mOutputLayer</tabstop>
<tabstop>mOutputFormatComboBox</tabstop>
<tabstop>mCurrentLayerExtentButton</tabstop>
<tabstop>mXMinSpinBox</tabstop>

0 comments on commit b6ff401

Please sign in to comment.
You can’t perform that action at this time.