|
QGIS API Documentation
master-6227475
|
00001 /*************************************************************************** 00002 qgsrasterpyramidsoptionswidget.cpp 00003 ------------------- 00004 begin : July 2012 00005 copyright : (C) 2012 by Etienne Tourigny 00006 email : etourigny dot dev at gmail dot com 00007 ***************************************************************************/ 00008 00009 /*************************************************************************** 00010 * * 00011 * This program is free software; you can redistribute it and/or modify * 00012 * it under the terms of the GNU General Public License as published by * 00013 * the Free Software Foundation; either version 2 of the License, or * 00014 * (at your option) any later version. * 00015 * * 00016 ***************************************************************************/ 00017 00018 #include "qgsrasterpyramidsoptionswidget.h" 00019 #include "qgslogger.h" 00020 #include "qgsdialog.h" 00021 00022 #include <QSettings> 00023 #include <QInputDialog> 00024 #include <QMessageBox> 00025 #include <QTextEdit> 00026 #include <QMouseEvent> 00027 #include <QMenu> 00028 #include <QCheckBox> 00029 00030 00031 QgsRasterPyramidsOptionsWidget::QgsRasterPyramidsOptionsWidget( QWidget* parent, QString provider ) 00032 : QWidget( parent ), mProvider( provider ) 00033 { 00034 setupUi( this ); 00035 00036 mSaveOptionsWidget->setProvider( provider ); 00037 mSaveOptionsWidget->setPyramidsFormat( QgsRaster::PyramidsGTiff ); 00038 mSaveOptionsWidget->setType( QgsRasterFormatSaveOptionsWidget::ProfileLineEdit ); 00039 00040 updateUi(); 00041 } 00042 00043 QgsRasterPyramidsOptionsWidget::~QgsRasterPyramidsOptionsWidget() 00044 { 00045 } 00046 00047 00048 void QgsRasterPyramidsOptionsWidget::updateUi() 00049 { 00050 QSettings mySettings; 00051 QString prefix = mProvider + "/driverOptions/_pyramids/"; 00052 QString tmpStr; 00053 00054 // cbxPyramidsInternal->setChecked( mySettings.value( prefix + "internal", false ).toBool() ); 00055 tmpStr = mySettings.value( prefix + "format", "gtiff" ).toString(); 00056 if ( tmpStr == "internal" ) 00057 cbxPyramidsFormat->setCurrentIndex( 1 ); 00058 else if ( tmpStr == "external_erdas" ) 00059 cbxPyramidsFormat->setCurrentIndex( 2 ); 00060 else 00061 cbxPyramidsFormat->setCurrentIndex( 0 ); 00062 00063 // initialize resampling methods 00064 cboResamplingMethod->clear(); 00065 QPair<QString, QString> method; 00066 foreach ( method, QgsRasterDataProvider::pyramidResamplingMethods( mProvider ) ) 00067 { 00068 cboResamplingMethod->addItem( method.second, method.first ); 00069 } 00070 cboResamplingMethod->setCurrentIndex( cboResamplingMethod->findData( 00071 mySettings.value( prefix + "resampling", "AVERAGE" ).toString() ) ); 00072 00073 // validate string, only space-separated positive integers are allowed 00074 lePyramidsLevels->setEnabled( cbxPyramidsLevelsCustom->isChecked() ); 00075 lePyramidsLevels->setValidator( new QRegExpValidator( QRegExp( "(\\d*)(\\s\\d*)*" ), lePyramidsLevels ) ); 00076 connect( lePyramidsLevels, SIGNAL( textEdited( const QString & ) ), 00077 this, SLOT( setOverviewList() ) ); 00078 00079 // overview list 00080 if ( mOverviewCheckBoxes.isEmpty() ) 00081 { 00082 QList<int> overviewList; 00083 overviewList << 2 << 4 << 8 << 16 << 32 << 64; 00084 mOverviewCheckBoxes.clear(); 00085 foreach ( int i, overviewList ) 00086 { 00087 mOverviewCheckBoxes[ i ] = new QCheckBox( QString::number( i ), this ); 00088 connect( mOverviewCheckBoxes[ i ], SIGNAL( toggled( bool ) ), 00089 this, SLOT( setOverviewList() ) ); 00090 layoutPyramidsLevels->addWidget( mOverviewCheckBoxes[ i ] ); 00091 } 00092 } 00093 else 00094 { 00095 foreach ( int i, mOverviewCheckBoxes.keys() ) 00096 mOverviewCheckBoxes[ i ]->setChecked( false ); 00097 } 00098 tmpStr = mySettings.value( prefix + "overviewList", "" ).toString(); 00099 foreach ( QString lev, tmpStr.split( " ", QString::SkipEmptyParts ) ) 00100 { 00101 if ( mOverviewCheckBoxes.contains( lev.toInt() ) ) 00102 mOverviewCheckBoxes[ lev.toInt()]->setChecked( true ); 00103 } 00104 setOverviewList(); 00105 00106 mSaveOptionsWidget->updateProfiles(); 00107 00108 connect( cbxPyramidsFormat, SIGNAL( currentIndexChanged( int ) ), 00109 this, SIGNAL( someValueChanged() ) ); 00110 connect( cboResamplingMethod, SIGNAL( currentIndexChanged( int ) ), 00111 this, SIGNAL( someValueChanged() ) ); 00112 connect( mSaveOptionsWidget, SIGNAL( optionsChanged() ), 00113 this, SIGNAL( someValueChanged() ) ); 00114 } 00115 00116 QString QgsRasterPyramidsOptionsWidget::resamplingMethod() const 00117 { 00118 return cboResamplingMethod->itemData( cboResamplingMethod->currentIndex() ).toString(); 00119 } 00120 00121 void QgsRasterPyramidsOptionsWidget::apply() 00122 { 00123 QSettings mySettings; 00124 QString prefix = mProvider + "/driverOptions/_pyramids/"; 00125 QString tmpStr; 00126 00127 // mySettings.setValue( prefix + "internal", cbxPyramidsInternal->isChecked() ); 00128 if ( cbxPyramidsFormat->currentIndex() == 1 ) 00129 tmpStr = "internal"; 00130 else if ( cbxPyramidsFormat->currentIndex() == 2 ) 00131 tmpStr = "external_erdas"; 00132 else 00133 tmpStr = "external"; 00134 mySettings.setValue( prefix + "format", tmpStr ); 00135 mySettings.setValue( prefix + "resampling", resamplingMethod() ); 00136 mySettings.setValue( prefix + "overviewStr", lePyramidsLevels->text().trimmed() ); 00137 00138 // overview list 00139 tmpStr = ""; 00140 foreach ( int i, mOverviewCheckBoxes.keys() ) 00141 { 00142 if ( mOverviewCheckBoxes[ i ]->isChecked() ) 00143 tmpStr += QString::number( i ) + " "; 00144 } 00145 mySettings.setValue( prefix + "overviewList", tmpStr.trimmed() ); 00146 00147 mSaveOptionsWidget->apply(); 00148 } 00149 00150 void QgsRasterPyramidsOptionsWidget::checkAllLevels( bool checked ) 00151 { 00152 foreach ( int i, mOverviewCheckBoxes.keys() ) 00153 mOverviewCheckBoxes[ i ]->setChecked( checked ); 00154 } 00155 00156 void QgsRasterPyramidsOptionsWidget::on_cbxPyramidsLevelsCustom_toggled( bool toggled ) 00157 { 00158 // if toggled, disable checkboxes and enable line edit 00159 lePyramidsLevels->setEnabled( toggled ); 00160 foreach ( int i, mOverviewCheckBoxes.keys() ) 00161 mOverviewCheckBoxes[ i ]->setEnabled( ! toggled ); 00162 setOverviewList(); 00163 } 00164 00165 void QgsRasterPyramidsOptionsWidget::on_cbxPyramidsFormat_currentIndexChanged( int index ) 00166 { 00167 mSaveOptionsWidget->setEnabled( index != 2 ); 00168 mSaveOptionsWidget->setPyramidsFormat(( QgsRaster::RasterPyramidsFormat ) index ); 00169 } 00170 00171 void QgsRasterPyramidsOptionsWidget::setOverviewList() 00172 { 00173 QgsDebugMsg( "Entered" ); 00174 00175 mOverviewList.clear(); 00176 00177 // if custom levels is toggled, get selection from line edit 00178 if ( cbxPyramidsLevelsCustom->isChecked() ) 00179 { 00180 // should we also validate that numbers are increasing? 00181 foreach ( QString lev, lePyramidsLevels->text().trimmed().split( " ", QString::SkipEmptyParts ) ) 00182 { 00183 QgsDebugMsg( "lev= " + lev ); 00184 int tmpInt = lev.toInt(); 00185 if ( tmpInt > 0 ) 00186 { 00187 QgsDebugMsg( "tmpInt= " + QString::number( tmpInt ) ); 00188 // if number is valid, add to overview list 00189 mOverviewList << tmpInt; 00190 } 00191 } 00192 } 00193 else 00194 { 00195 foreach ( int i, mOverviewCheckBoxes.keys() ) 00196 { 00197 if ( mOverviewCheckBoxes[ i ]->isChecked() ) 00198 mOverviewList << i; 00199 } 00200 } 00201 00202 emit overviewListChanged(); 00203 }