258 changes: 126 additions & 132 deletions src/app/qgisapp.cpp

Large diffs are not rendered by default.

7 changes: 7 additions & 0 deletions src/app/qgisapp.h
Original file line number Diff line number Diff line change
Expand Up @@ -1162,6 +1162,13 @@ class QgisApp : public QMainWindow, private Ui::MainWindow
*/
bool addRasterLayer( QgsRasterLayer * theRasterLayer );

/** Open a raster layer - this is the generic function which takes all parameters
* @note added in version 2.0
*/
QgsRasterLayer* addRasterLayerPrivate( const QString & uri, const QString & baseName,
const QString & providerKey, bool guiWarning,
bool guiUpdate );

/** add this file to the recently opened/saved projects list
* pass settings by reference since creating more than one
* instance simultaneously results in data loss.
Expand Down
4 changes: 4 additions & 0 deletions src/gui/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ qgsexpressionhighlighter.cpp
qgsquerybuilder.cpp
qgscollapsiblegroupbox.cpp
qgsfilterlineedit.cpp
qgssublayersdialog.cpp
)

IF (WITH_TOUCH)
Expand Down Expand Up @@ -221,6 +222,7 @@ qgsexpressionselectiondialog.h
qgsquerybuilder.h
qgscollapsiblegroupbox.h
qgsfilterlineedit.h
qgssublayersdialog.h
)

QT4_WRAP_CPP(QGIS_GUI_MOC_SRCS ${QGIS_GUI_MOC_HDRS})
Expand Down Expand Up @@ -270,6 +272,7 @@ qgsexpressionselectiondialog.h
qgsexpressionhighlighter.h
qgscollapsiblegroupbox.h
qgsfilterlineedit.h
qgssublayersdialog.h

attributetable/qgsattributetablemodel.h
attributetable/qgsattributetableview.h
Expand Down Expand Up @@ -302,6 +305,7 @@ ${CMAKE_CURRENT_BINARY_DIR}/../ui/ui_qgsquerybuilderbase.h
${CMAKE_CURRENT_BINARY_DIR}/../ui/ui_qgsexpressionbuilder.h
${CMAKE_CURRENT_BINARY_DIR}/../ui/ui_qgsexpressionbuilderdialogbase.h
${CMAKE_CURRENT_BINARY_DIR}/../ui/ui_qgsexpressionselectiondialogbase.h
${CMAKE_CURRENT_BINARY_DIR}/../ui/ui_qgssublayersdialogbase.h
)

# ModelTest
Expand Down
150 changes: 150 additions & 0 deletions src/gui/qgssublayersdialog.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
/***************************************************************************
qgssublayersdialog.cpp - dialog for selecting sublayers
---------------------
begin : January 2009
copyright : (C) 2009 by Florian El Ahdab
email : felahdab at gmail dot com
***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/

#include "qgssublayersdialog.h"

#include "qgslogger.h"

#include <QSettings>
#include <QTableWidgetItem>
#include <QPushButton>


QgsSublayersDialog::QgsSublayersDialog( ProviderType providerType, QString name,
QWidget* parent, Qt::WFlags fl )
: QDialog( parent, fl ), mName( name )
{
setupUi( this );

if ( providerType == QgsSublayersDialog::Ogr )
{
setWindowTitle( tr( "Select vector layers to add..." ) );
layersTable->setHeaderLabels( QStringList() << tr( "Layer ID" ) << tr( "Layer name" )
<< tr( "Nb of features" ) << tr( "Geometry type" ) );
}
else if ( providerType == QgsSublayersDialog::Gdal )
{
setWindowTitle( tr( "Select raster layers to add..." ) );
layersTable->setHeaderLabels( QStringList() << tr( "Layer ID" ) << tr( "Layer name" ) );
}
else
{
setWindowTitle( tr( "Select layers to add..." ) );
layersTable->setHeaderLabels( QStringList() << tr( "Layer ID" ) << tr( "Layer name" )
<< tr( "Type" ) );
}

// add a "Select All" button - would be nicer with an icon
QPushButton* button = new QPushButton( tr( "Select All" ) );
buttonBox->addButton( button, QDialogButtonBox::ActionRole );
connect( button, SIGNAL( pressed() ), layersTable, SLOT( selectAll() ) );
// connect( pbnSelectNone, SIGNAL( pressed() ), SLOT( layersTable->selectNone() ) );

QSettings settings;
restoreGeometry( settings.value( "/Windows/" + mName + "SubLayers/geometry" ).toByteArray() );
}

QgsSublayersDialog::~QgsSublayersDialog()
{
QSettings settings;
settings.setValue( "/Windows/" + mName + "SubLayers/geometry", saveGeometry() );
settings.setValue( "/Windows/" + mName + "SubLayers/headerState",
layersTable->header()->saveState() );
}

QStringList QgsSublayersDialog::selectionNames()
{
QStringList list;
for ( int i = 0; i < layersTable->selectedItems().size(); i++ )
{
list << layersTable->selectedItems().at( i )->text( 1 );
}
return list;
}

QList<int> QgsSublayersDialog::selectionIndexes()
{
QList<int> list;
for ( int i = 0; i < layersTable->selectedItems().size(); i++ )
{
list << layersTable->selectedItems().at( i )->text( 0 ).toInt();
}
return list;
}

void QgsSublayersDialog::populateLayerTable( QStringList theList, QString delim )
{
foreach ( QString item, theList )
{
layersTable->addTopLevelItem( new QTreeWidgetItem( item.split( delim ) ) );
}

// resize columns
QSettings settings;
QByteArray ba = settings.value( "/Windows/" + mName + "SubLayers/headerState" ).toByteArray();
if ( ! ba.isNull() )
{
layersTable->header()->restoreState( ba );
}
else
{
for ( int i = 0; i < layersTable->columnCount(); i++ )
layersTable->resizeColumnToContents( i );
layersTable->setColumnWidth( 1, layersTable->columnWidth( 1 ) + 10 );
}
}

// override exec() instead of using showEvent()
// because in some case we don't want the dialog to appear (depending on user settings)
// TODO alert the user when dialog is not opened
int QgsSublayersDialog::exec()
{
QSettings settings;
QString promptLayers = settings.value( "/qgis/promptForSublayers", 1 ).toString();

// make sure three are sublayers to choose
if ( layersTable->topLevelItemCount() == 0 )
return QDialog::Rejected;

// check promptForSublayers settings - perhaps this should be in QgsDataSource instead?
if ( promptLayers == "no" )
return QDialog::Rejected;
else if ( promptLayers == "all" )
{
layersTable->selectAll();
return QDialog::Accepted;
}

// if there is only 1 sublayer (probably the main layer), just select that one and return
if ( layersTable->topLevelItemCount() == 1 )
{
layersTable->selectAll();
return QDialog::Accepted;
}

// if we got here, disable override cursor, open dialog and return result
// TODO add override cursor where it is missing (e.g. when opening via "Add Raster")
QCursor cursor;
bool override = ( QApplication::overrideCursor() != 0 );
if ( override )
{
cursor = QCursor( * QApplication::overrideCursor() );
QApplication::restoreOverrideCursor();
}
int ret = QDialog::exec();
if ( override )
QApplication::setOverrideCursor( cursor );
return ret;
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/***************************************************************************
qgsogrsublayersdialog.h - dialog for selecting ogr sublayers
qgssublayersdialog.h - dialog for selecting sublayers
---------------------
begin : January 2009
copyright : (C) 2009 by Florian El Ahdab
Expand All @@ -13,25 +13,40 @@
* *
***************************************************************************/

#ifndef QGSOGRSUBLAYERSDIALOG_H
#define QGSOGRSUBLAYERSDIALOG_H
#ifndef QGSSUBLAYERSDIALOG_H
#define QGSSUBLAYERSDIALOG_H

#include <QDialog>
#include <ui_qgsogrsublayersdialogbase.h>
#include <ui_qgssublayersdialogbase.h>
#include "qgscontexthelp.h"

class QgsOGRSublayersDialog : public QDialog, private Ui::QgsOGRSublayersDialogBase

class QgsSublayersDialog : public QDialog, private Ui::QgsSublayersDialogBase
{
Q_OBJECT
public:
QgsOGRSublayersDialog( QWidget* parent = 0, Qt::WFlags fl = 0 );
~QgsOGRSublayersDialog();

enum ProviderType
{
Ogr,
Gdal,
Vsifile
};

QgsSublayersDialog( ProviderType providerType, QString name, QWidget* parent = 0, Qt::WFlags fl = 0 );
~QgsSublayersDialog();

void populateLayerTable( QStringList theList, QString delim = ":" );
QStringList getSelection();
QList<int> getSelectionIndexes();
QStringList selectionNames();
QList<int> selectionIndexes();

public slots:
void on_buttonBox_helpRequested() { QgsContextHelp::run( metaObject()->className() ); }
int exec();

protected:
QString mName;
QStringList mSelectedSubLayers;
};

#endif
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>QgsOGRSublayersDialogBase</class>
<widget class="QDialog" name="QgsOGRSublayersDialogBase">
<class>QgsSublayersDialogBase</class>
<widget class="QDialog" name="QgsSublayersDialogBase">
<property name="geometry">
<rect>
<x>0</x>
Expand All @@ -20,16 +20,6 @@
<property name="spacing">
<number>6</number>
</property>
<item row="6" column="0">
<widget class="QDialogButtonBox" name="buttonBox">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Help|QDialogButtonBox::Ok</set>
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QTreeWidget" name="layersTable">
<property name="selectionMode">
Expand All @@ -45,6 +35,16 @@
</column>
</widget>
</item>
<item row="2" column="0">
<widget class="QDialogButtonBox" name="buttonBox">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
</property>
</widget>
</item>
</layout>
</widget>
<layoutdefault spacing="6" margin="11"/>
Expand All @@ -53,7 +53,7 @@
<connection>
<sender>buttonBox</sender>
<signal>accepted()</signal>
<receiver>QgsOGRSublayersDialogBase</receiver>
<receiver>QgsSublayersDialogBase</receiver>
<slot>accept()</slot>
<hints>
<hint type="sourcelabel">
Expand All @@ -69,7 +69,7 @@
<connection>
<sender>buttonBox</sender>
<signal>rejected()</signal>
<receiver>QgsOGRSublayersDialogBase</receiver>
<receiver>QgsSublayersDialogBase</receiver>
<slot>reject()</slot>
<hints>
<hint type="sourcelabel">
Expand Down
Binary file added tests/testdata/landsat.nc
Binary file not shown.
1,292 changes: 1,292 additions & 0 deletions tests/testdata/layers.gpx

Large diffs are not rendered by default.