Skip to content
Permalink
Browse files

added initial support for layer loading through the gui

  • Loading branch information
mbernasocchi authored and pka committed Dec 8, 2010
1 parent 7bf8489 commit 85080d5c71d1cff79640ecf424c012eaece8876a
@@ -22,21 +22,23 @@
#include <qgsapplication.h>
#include <qgslogger.h>
#include <qgscontexthelp.h>

#include <QtAlgorithms>
#include <QtDebug>
#include <QFileDialog>
#include <QMessageBox>
#include <QSettings>
#include <QString>
#include <QStringList>

#include <QVariant>
#include <QNetworkAccessManager>
#include <QNetworkRequest>
#include <QNetworkReply>

#include <osg/DisplaySettings>

QList<DataSource> elevationsDataSources;

//constructor
QgsGlobePluginDialog::QgsGlobePluginDialog( QWidget* parent, Qt::WFlags fl )
: QDialog( parent, fl )
@@ -45,6 +47,8 @@ QgsGlobePluginDialog::QgsGlobePluginDialog( QWidget* parent, Qt::WFlags fl )
loadStereoConfig(); //values from settings, default values from OSG
setStereoConfig(); //overwrite with values from QSettings
updateStereoDialog(); //update the dialog gui

readElevationDataSourcesFromSettings();
}

//destructor
@@ -55,7 +59,9 @@ QgsGlobePluginDialog::~QgsGlobePluginDialog()
QString QgsGlobePluginDialog::openFile()
{
//see http://www.gdal.org/formats_list.html
const char* filter = "GDAL files (*.dem *.tif *.tiff *.jpg *.jpeg *.asc);;DEM files (*.dem);;All files (*.*)";
const char* filter = "GDAL files (*.dem *.tif *.tiff *.jpg *.jpeg *.asc) \
;;DEM files (*.dem) \
;;All files (*.*)";
QString path = QFileDialog::getOpenFileName( this,
tr( "Open raster file" ),
QDir::homePath (),
@@ -64,31 +70,48 @@ QString QgsGlobePluginDialog::openFile()
return path;
}

bool QgsGlobePluginDialog::validateNetworkResource(QString uri)
bool QgsGlobePluginDialog::validateResource( QString type, QString uri, QString &error )
{
QNetworkAccessManager *manager = new QNetworkAccessManager(this);
QNetworkRequest request;
request.setUrl(QUrl(uri));
QNetworkReply *reply = manager->get(request);

//wait for response syncronously
QEventLoop eLoop;
connect( manager, SIGNAL( finished( QNetworkReply * ) ),
&eLoop, SLOT( quit() ) );
eLoop.exec(QEventLoop::ExcludeUserInputEvents);

if (QNetworkReply::HostNotFoundError != reply->error())
//FIXME:should be the following line but reply->error() always give "unknown error"
//if (QNetworkReply::NoError == reply->error())
if ( "Raster" == type )
{
QByteArray data = reply->readAll();
QString req(data);
return true;
QFile file;
file.setFileName( uri );
if ( file.exists() )
{
return true;
}
else
{
error = tr("Invalid Path: ") + file.errorString();
return false;
}
}
else
{
showMessageBox( tr("Invalid URL: ") + reply->errorString() );
return false;
QNetworkAccessManager *manager = new QNetworkAccessManager(this);
QNetworkRequest request;
request.setUrl(QUrl(uri));
QNetworkReply *reply = manager->get(request);

//wait for response syncronously
QEventLoop eLoop;
connect( manager, SIGNAL( finished( QNetworkReply * ) ),
&eLoop, SLOT( quit() ) );
eLoop.exec(QEventLoop::ExcludeUserInputEvents);

if (QNetworkReply::HostNotFoundError != reply->error())
//FIXME:should be the following line but reply->error() always give "unknown error"
//if (QNetworkReply::NoError == reply->error())
{
QByteArray data = reply->readAll();
QString req(data);
return true;
}
else
{
error = tr("Invalid URL: ") + reply->errorString();
return false;
}
}
}

@@ -119,13 +142,35 @@ void QgsGlobePluginDialog::on_buttonBox_accepted()
{
restartGlobe();
}

settings.beginGroup("Plugin-Globe");
settings.beginWriteArray("ElevationsDataSources");
for (int i = 0; i < elevationsDataSources.size(); ++i)
{
settings.setArrayIndex(i);
settings.setValue("type", elevationsDataSources.at(i).type);
settings.setValue("uri", elevationsDataSources.at(i).uri);
}
settings.endArray();
settings.endGroup();

accept();
}

void QgsGlobePluginDialog::on_showDataSources_clicked(){
QString txt;
foreach (DataSource source, elevationsDataSources)
{
txt += source.type + ":\t" + source.uri + "\n";
}
showMessageBox( txt );
}

void QgsGlobePluginDialog::on_buttonBox_rejected()
{
loadStereoConfig();
setStereoConfig();
readElevationDataSourcesFromSettings();
reject();
}

@@ -144,12 +189,54 @@ void QgsGlobePluginDialog::on_elevationCombo_currentIndexChanged(QString type)

void QgsGlobePluginDialog::on_elevationBrowse_clicked()
{
elevationPath->setText( openFile() );
QString newPath = openFile();
if ( ! newPath.isEmpty() )
{
elevationPath->setText( newPath );
}
}


void QgsGlobePluginDialog::on_elevationAdd_clicked()
{
QString errorText;
bool validationResult = validateResource( elevationCombo->currentText(), elevationPath->text(), errorText );

QMessageBox msgBox;
msgBox.setText( errorText );
msgBox.setInformativeText( tr( "Do you want to add the datasource anyway?" ) );
msgBox.setIcon( QMessageBox::Warning );
msgBox.setStandardButtons(QMessageBox::Ok | QMessageBox::Cancel);
msgBox.setDefaultButton(QMessageBox::Cancel);

if ( validationResult || msgBox.exec() == QMessageBox::Ok )
{
DataSource ds;
ds.uri = elevationPath->text();
ds.type = elevationCombo->currentText();
elevationsDataSources.append(ds);
}
}

void QgsGlobePluginDialog::on_elevationTest_clicked()
void QgsGlobePluginDialog::on_elevationRemove_clicked()
{
validateNetworkResource( elevationPath->text() );
elevationDatasets->clear();
}

void QgsGlobePluginDialog::readElevationDataSourcesFromSettings()
{
elevationsDataSources.clear();
settings.beginGroup("Plugin-Globe");
int size = settings.beginReadArray("ElevationsDataSources");
for (int i = 0; i < size; ++i) {
settings.setArrayIndex(i);
DataSource ds;
ds.type = settings.value("type").toString();
ds.uri = settings.value("uri").toString();
elevationsDataSources.append(ds);
}
settings.endArray();
settings.endGroup();
}

void QgsGlobePluginDialog::on_resetStereoDefaults_clicked()
@@ -37,7 +37,8 @@ class QgsGlobePluginDialog:public QDialog, private Ui::QgsGlobePluginDialogGuiBa
void updateStereoDialog();
void restartGlobe();
bool globeRunning();
bool validateNetworkResource( QString uri);
bool validateResource( QString type, QString uri, QString& error);
void readElevationDataSourcesFromSettings();
void showMessageBox( QString text);
//! Set osg/DisplaySettings
void setStereoConfig();
@@ -67,7 +68,14 @@ class QgsGlobePluginDialog:public QDialog, private Ui::QgsGlobePluginDialogGuiBa
//ELEVATION
void on_elevationCombo_currentIndexChanged(QString value);
void on_elevationBrowse_clicked();
void on_elevationTest_clicked();
void on_elevationAdd_clicked();
void on_elevationRemove_clicked();
void on_showDataSources_clicked();
};

struct DataSource {
QString type;
QString uri;
};

#endif // QGIS_GLOBE_PLUGIN_DIALOG_H
@@ -10,7 +10,7 @@
<x>0</x>
<y>0</y>
<width>593</width>
<height>470</height>
<height>496</height>
</rect>
</property>
<property name="sizePolicy">
@@ -83,20 +83,20 @@
</widget>
</item>
<item row="6" column="2">
<widget class="QPushButton" name="elevatonAdd">
<widget class="QPushButton" name="elevationAdd">
<property name="text">
<string>Add</string>
</property>
</widget>
</item>
<item row="7" column="2">
<item row="8" column="2">
<widget class="QPushButton" name="elevationRemove">
<property name="text">
<string>Remove</string>
</property>
</widget>
</item>
<item row="9" column="2">
<item row="10" column="2">
<widget class="QTableWidget" name="elevationDatasets">
<property name="rowCount">
<number>1</number>
@@ -126,7 +126,18 @@
</column>
<item row="0" column="0">
<property name="text">
<string>Worldwind</string>
<string/>
</property>
<property name="flags">
<set>ItemIsSelectable|ItemIsDragEnabled|ItemIsDropEnabled|ItemIsUserCheckable|ItemIsEnabled</set>
</property>
</item>
<item row="0" column="1">
<property name="text">
<string/>
</property>
<property name="flags">
<set>ItemIsSelectable|ItemIsDragEnabled|ItemIsDropEnabled|ItemIsUserCheckable|ItemIsEnabled</set>
</property>
</item>
</widget>
@@ -145,39 +156,15 @@
</property>
<widget class="QWidget" name="elevationIsLocal">
<layout class="QGridLayout" name="gridLayout_4">
<item row="0" column="0">
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item row="0" column="1">
<widget class="QPushButton" name="elevationBrowse">
<property name="text">
<string>Browse</string>
</property>
</widget>
</item>
</layout>
</widget>
<widget class="QWidget" name="elevationIsRemote">
<layout class="QGridLayout" name="gridLayout_3">
<item row="0" column="1">
<widget class="QPushButton" name="elevationTest">
<property name="text">
<string>Test</string>
</property>
</widget>
</item>
<item row="0" column="0">
<spacer name="horizontalSpacer_2">
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
@@ -191,6 +178,16 @@
</item>
</layout>
</widget>
<widget class="QWidget" name="elevationIsRemote">
<layout class="QGridLayout" name="gridLayout_3"/>
</widget>
</widget>
</item>
<item row="7" column="2">
<widget class="QPushButton" name="showDataSources">
<property name="text">
<string>Show</string>
</property>
</widget>
</item>
</layout>
@@ -433,7 +430,7 @@
<tabstop>elevationCombo</tabstop>
<tabstop>elevationPath</tabstop>
<tabstop>elevationBrowse</tabstop>
<tabstop>elevatonAdd</tabstop>
<tabstop>elevationAdd</tabstop>
<tabstop>elevationRemove</tabstop>
<tabstop>elevationDatasets</tabstop>
<tabstop>comboStereoMode</tabstop>
@@ -447,7 +444,6 @@
<tabstop>splitStereoVerticalEyeMapping</tabstop>
<tabstop>resetStereoDefaults</tabstop>
<tabstop>buttonBox</tabstop>
<tabstop>elevationTest</tabstop>
</tabstops>
<resources/>
<connections>

0 comments on commit 85080d5

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