Skip to content
Permalink
Browse files

basic raster format option widget

  • Loading branch information
etiennesky committed Jul 21, 2012
1 parent 4e49c42 commit 7c760b22f5b7e77e557c02f4a4f346767630bae9
@@ -26,6 +26,8 @@
#include "qgsnetworkaccessmanager.h"
#include "qgsproject.h"

#include "qgsrasterformatoptionswidget.h"

#include <QInputDialog>
#include <QFileDialog>
#include <QSettings>
@@ -579,7 +581,11 @@ QgsOptions::QgsOptions( QWidget *parent, Qt::WFlags fl ) :
// load gdal driver list only when gdal tab is first opened
mLoadedGdalDriverList = false;

tabWidget->setCurrentIndex( settings.value( "/Windows/Options/row" ).toInt() );
// tabWidget->setCurrentIndex( settings.value( "/Windows/Options/row" ).toInt() );
int currentTab = settings.value( "/Windows/Options/row" ).toInt();
QgsDebugMsg(QString("current=%1").arg(currentTab));
tabWidget->setCurrentIndex( currentTab );
on_tabWidget_currentChanged( currentTab );
}

//! Destructor
@@ -1085,25 +1091,24 @@ void QgsOptions::on_lstGdalDrivers_itemDoubleClicked( QTreeWidgetItem * item, in

void QgsOptions::editGdalDriver( const QString& driverName )
{
QSettings mySettings;

// this will go to a standalone widget class
QDialog dlg( this );
QVBoxLayout *layout = new QVBoxLayout();
QgsRasterFormatOptionsWidget* optionsWidget = new QgsRasterFormatOptionsWidget( 0, driverName, "gdal" );
layout->addWidget( optionsWidget );
optionsWidget->showProfileButtons( true );
QDialogButtonBox *buttonBox = new QDialogButtonBox( QDialogButtonBox::Ok | QDialogButtonBox::Cancel );
connect(buttonBox, SIGNAL(accepted()), &dlg, SLOT(accept()));
connect(buttonBox, SIGNAL(rejected()), &dlg, SLOT(reject()));
QVBoxLayout *layout = new QVBoxLayout();
QLineEdit *lineEdit = new QLineEdit();
layout->addWidget( lineEdit );
layout->addWidget( buttonBox );
dlg.setLayout( layout );

lineEdit->setText( mySettings.value( "gdal/driverOptions/" + driverName.toLower() + "/create", "" ).toString() );
if ( dlg.exec() == QDialog::Accepted )
{
// perhaps setting should not be applied already, but this is easier
mySettings.setValue( "gdal/driverOptions/" + driverName.toLower() + "/create", lineEdit->text().trimmed().toUpper() );
optionsWidget->apply();
}
delete optionsWidget;
}

// Return state of the visibility flag for newly added layers. If
@@ -1326,6 +1331,7 @@ void QgsOptions::on_mClearCache_clicked()

void QgsOptions::on_tabWidget_currentChanged( int theTab )
{
QgsDebugMsg(QString("current=%1").arg(theTab));
// load gdal driver list when gdal tab is first opened
if ( theTab == 1 && ! mLoadedGdalDriverList )
{
@@ -7,6 +7,7 @@ raster/qgspalettedrendererwidget.cpp
raster/qgssinglebandgrayrendererwidget.cpp
raster/qgssinglebandpseudocolorrendererwidget.cpp
raster/qgsrasterhistogramwidget.cpp
raster/qgsrasterformatoptionswidget.cpp

symbology-ng/qgsbrushstylecombobox.cpp
symbology-ng/qgscolorrampcombobox.cpp
@@ -103,6 +104,7 @@ raster/qgsmultibandcolorrendererwidget.h
raster/qgssinglebandgrayrendererwidget.h
raster/qgssinglebandpseudocolorrendererwidget.h
raster/qgsrasterhistogramwidget.h
raster/qgsrasterformatoptionswidget.h

symbology-ng/qgsdashspacedialog.h
symbology-ng/qgssymbollayerv2widget.h
@@ -1,11 +1,13 @@
#include "qgsrasterlayersaveasdialog.h"
#include "qgsrasterdataprovider.h"
#include "raster/qgsrasterformatoptionswidget.h"

#include <QFileDialog>
#include <QSettings>

QgsRasterLayerSaveAsDialog::QgsRasterLayerSaveAsDialog( QgsRasterDataProvider* sourceProvider, const QgsRectangle& currentExtent,
QWidget* parent, Qt::WindowFlags f ): QDialog( parent, f ),
mDataProvider( sourceProvider ), mCurrentExtent( currentExtent )
mDataProvider( sourceProvider ), mCurrentExtent( currentExtent )

{
setupUi( this );
@@ -42,6 +44,14 @@ QgsRasterLayerSaveAsDialog::QgsRasterLayerSaveAsDialog( QgsRasterDataProvider* s

//extent
setOutputExtent( mCurrentExtent );

mOptionsWidget->setProvider( mDataProvider->name() );
if ( mDataProvider->name() == "gdal" )
{
mOptionsWidget->setFormat( myFormats[0] );
}
mOptionsWidget->update();

}

QPushButton* okButton = mButtonBox->button( QDialogButtonBox::Ok );
@@ -114,8 +124,8 @@ void QgsRasterLayerSaveAsDialog::on_mFormatComboBox_currentIndexChanged( const Q
//gdal-specific
if ( mDataProvider && mDataProvider->name() == "gdal" )
{
QSettings mySettings;
mCreateOptionsLineEdit->setText( mySettings.value( "gdal/driverOptions/" + text.toLower() + "/create", "" ).toString() );
mOptionsWidget->setFormat( text );
mOptionsWidget->update();
}
}

@@ -156,7 +166,8 @@ QString QgsRasterLayerSaveAsDialog::outputFormat() const

QStringList QgsRasterLayerSaveAsDialog::createOptions() const
{
return mCreateOptionsLineEdit->text().trimmed().toUpper().split( " " );
// return mCreateOptionsLineEdit->text().trimmed().toUpper().split( " " );
return mOptionsWidget ? mOptionsWidget->createOptions() : QStringList();
}

QgsRectangle QgsRasterLayerSaveAsDialog::outputRectangle() const
@@ -5,6 +5,7 @@
#include "qgsrectangle.h"

class QgsRasterDataProvider;
class QgsRasterFormatOptionsWidget;

class GUI_EXPORT QgsRasterLayerSaveAsDialog: public QDialog, private Ui::QgsRasterLayerSaveAsDialogBase
{
@@ -0,0 +1,125 @@
#include "qgsrasterformatoptionswidget.h"
#include "qgslogger.h"

#include <QSettings>
#include <QInputDialog>

QgsRasterFormatOptionsWidget::QgsRasterFormatOptionsWidget( QWidget* parent, QString format, QString provider ): QWidget( parent ), mFormat( format ), mProvider( provider )

{
setupUi( this );
showProfileButtons( false );
connect( mProfileComboBox, SIGNAL( currentIndexChanged ( const QString & ) ),
this, SLOT( profileChanged() ) );
connect( mProfileApplyButton, SIGNAL( clicked() ), this, SLOT( apply() ) );
update();
}

QgsRasterFormatOptionsWidget::~QgsRasterFormatOptionsWidget()
{
}


void QgsRasterFormatOptionsWidget::showProfileButtons( bool show )
{
mProfileButtons->setVisible( show );
}

void QgsRasterFormatOptionsWidget::update()
{
// mCreateOptionsLineEdit->setText( createOption( mProfileComboBox->currentText() ) );
mProfileComboBox->blockSignals( true );
mProfileComboBox->clear();
foreach ( QString profileName, profiles() )
{
mProfileComboBox->addItem( profileName );
}
mProfileComboBox->blockSignals( false );
mProfileComboBox->setCurrentIndex( 0 );
profileChanged();
}

void QgsRasterFormatOptionsWidget::apply()
{
setProfiles();
setCreateOptions( mProfileComboBox->currentText(), mCreateOptionsLineEdit->text() );
profileChanged();
}

// void QgsRasterFormatOptionsWidget::on_mProfileComboBox_currentIndexChanged( const QString & text )
void QgsRasterFormatOptionsWidget::profileChanged()
{
QgsDebugMsg("Entered");
mCreateOptionsLineEdit->setText( createOptions( mProfileComboBox->currentText() ) );
}

void QgsRasterFormatOptionsWidget::on_mProfileNewButton_clicked()
{
QString profileName = QInputDialog::getText( this, "", tr("Profile name:") );
if ( ! profileName.isEmpty() )
{
profileName = profileName.trimmed();
profileName.replace( " ", "_" );
profileName.replace( "=", "_" );
mProfileComboBox->addItem( profileName );
mProfileComboBox->setCurrentIndex( mProfileComboBox->count()-1 );
}
}

void QgsRasterFormatOptionsWidget::on_mProfileDeleteButton_clicked()
{
int index = mProfileComboBox->currentIndex();
QString profileName = mProfileComboBox->currentText();
if ( index != -1 )
{
mProfileComboBox->removeItem( index );
setCreateOptions( profileName, "" );
}
}

QString QgsRasterFormatOptionsWidget::settingsKey( QString profileName ) const
{
if ( profileName != "" )
profileName = "/profile_" + profileName;
else
profileName = "/profile_default" + profileName;
return mProvider + "/driverOptions/" + mFormat.toLower() + profileName + "/create";
}

QStringList QgsRasterFormatOptionsWidget::createOptions() const
{
return mCreateOptionsLineEdit->text().trimmed().split( " " ) ;
}

QString QgsRasterFormatOptionsWidget::createOptions( QString profileName ) const
{
QSettings mySettings;
return mySettings.value( settingsKey( profileName ), "" ).toString();
}

void QgsRasterFormatOptionsWidget::deleteCreateOptions( QString profileName )
{
QSettings mySettings;
mySettings.remove( settingsKey( profileName ) );
}

void QgsRasterFormatOptionsWidget::setCreateOptions( QString profileName, QString value )
{
QSettings mySettings;
mySettings.setValue( settingsKey( profileName ), value.trimmed() );
}

QStringList QgsRasterFormatOptionsWidget::profiles() const
{
QSettings mySettings;
return mySettings.value( mProvider + "/driverOptions/" + mFormat.toLower() + "/profiles", "" ).toString().split( " " );
}

void QgsRasterFormatOptionsWidget::setProfiles() const
{
QSettings mySettings;
QString myProfiles;
for ( int i = 0 ; i < mProfileComboBox->count() ; i++ )
myProfiles += mProfileComboBox->itemText( i ) + QString( " " );
return mySettings.setValue( mProvider + "/driverOptions/" + mFormat.toLower() + "/profiles", myProfiles.trimmed() );
}
@@ -0,0 +1,44 @@
#ifndef QGSRASTERFORMATOPTIONSWIDGET_H
#define QGSRASTERFORMATOPTIONSWIDGET_H

#include "ui_qgsrasterformatoptionswidgetbase.h"

//class QgsRasterDataProvider;

class GUI_EXPORT QgsRasterFormatOptionsWidget: public QWidget, private Ui::QgsRasterFormatOptionsWidgetBase
{
Q_OBJECT
public:
QgsRasterFormatOptionsWidget( QWidget* parent = 0, QString format = "GTiff", QString provider = "gdal" );
~QgsRasterFormatOptionsWidget();

void setFormat( QString format ) { mFormat = format; }
void setProvider( QString provider ) { mProvider = provider; }

public slots:
QStringList createOptions() const;
void showProfileButtons( bool show = true );
void update();
void apply();

private slots:
/* void on_mProfileComboBox_currentIndexChanged( const QString & text ); */
void profileChanged();
void on_mProfileNewButton_clicked();
void on_mProfileDeleteButton_clicked();

private:

QString mFormat;
QString mProvider;

QString settingsKey( QString profile ) const;
QString createOptions( QString profile ) const;
void deleteCreateOptions( QString profile );
void setCreateOptions( QString profile, QString value );
QStringList profiles() const;
void setProfiles() const;

};

#endif // QGSRASTERLAYERSAVEASDIALOG_H

0 comments on commit 7c760b2

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