|
| 1 | +/* |
| 2 | + * $Id$ |
| 3 | + */ |
| 4 | +/*************************************************************************** |
| 5 | + globe_plugin_dialog.cpp - settings dialog for the globe plugin |
| 6 | + -------------------------------------- |
| 7 | + Date : 11-Nov-2010 |
| 8 | + Copyright : (C) 2010 by Marco Bernasocchi |
| 9 | + Email : marco at bernawebdesign.ch |
| 10 | +/*************************************************************************** |
| 11 | + * * |
| 12 | + * This program is free software; you can redistribute it and/or modify * |
| 13 | + * it under the terms of the GNU General Public License as published by * |
| 14 | + * the Free Software Foundation; either version 2 of the License, or * |
| 15 | + * (at your option) any later version. * |
| 16 | + * * |
| 17 | + ***************************************************************************/ |
| 18 | + |
| 19 | +#include "globe_plugin_dialog.h" |
| 20 | + |
| 21 | +#include <qgsapplication.h> |
| 22 | +#include <qgslogger.h> |
| 23 | +#include <qgscontexthelp.h> |
| 24 | + |
| 25 | +#include <QtAlgorithms> |
| 26 | +#include <QtDebug> |
| 27 | +#include <QFileDialog> |
| 28 | +#include <QMessageBox> |
| 29 | +#include <QSettings> |
| 30 | +#include <QString> |
| 31 | +#include <QStringList> |
| 32 | +#include <QVariant> |
| 33 | + |
| 34 | +//constructor |
| 35 | +QgsGlobePluginDialog::QgsGlobePluginDialog( QWidget* parent, Qt::WFlags fl ) |
| 36 | + : QDialog( parent, fl ) |
| 37 | +{ |
| 38 | + setupUi( this ); |
| 39 | +} |
| 40 | + |
| 41 | +//destructor |
| 42 | +QgsGlobePluginDialog::~QgsGlobePluginDialog() |
| 43 | +{ |
| 44 | +} |
| 45 | + |
| 46 | +QString QgsGlobePluginDialog::openFile() |
| 47 | +{ |
| 48 | + QSettings sets; |
| 49 | + QString path = QFileDialog::getOpenFileName( this, |
| 50 | + tr( "Open Earthfile" ), |
| 51 | + "/home", |
| 52 | + tr( "Earthfiles (*.earth)" ) ); |
| 53 | + |
| 54 | + return path; |
| 55 | +} |
| 56 | + |
| 57 | +void QgsGlobePluginDialog::on_buttonBox_accepted() |
| 58 | +{ |
| 59 | + /* |
| 60 | + // Validate input settings |
| 61 | + QString srcUrl( inputSrcDataset->text() ); |
| 62 | + QString srcLayer( comboSrcLayer->currentText() ); |
| 63 | +
|
| 64 | + if ( srcUrl.isEmpty() ) |
| 65 | + { |
| 66 | + QMessageBox::warning( this, |
| 67 | + tr( "OGR Layer Converter" ), |
| 68 | + tr( "Input OGR dataset is missing!" ) ); |
| 69 | + return; |
| 70 | + } |
| 71 | +
|
| 72 | + if ( srcLayer.isEmpty() ) |
| 73 | + { |
| 74 | + QMessageBox::warning( this, |
| 75 | + tr( "OGR Layer Converter" ), |
| 76 | + tr( "Input OGR layer name is missing!" ) ); |
| 77 | + return; |
| 78 | + } |
| 79 | +
|
| 80 | + // Validate output settings |
| 81 | + QString dstFormat( comboDstFormats->currentText() ); |
| 82 | + QString dstUrl( inputDstDataset->text() ); |
| 83 | + QString dstLayer( inputDstLayer->text() ); |
| 84 | + if ( dstLayer.isEmpty() ) |
| 85 | + dstLayer = srcLayer; |
| 86 | +
|
| 87 | + if ( dstFormat.isEmpty() ) |
| 88 | + { |
| 89 | + QMessageBox::warning( this, |
| 90 | + tr( "OGR Layer Converter" ), |
| 91 | + tr( "Target OGR format not selected!" ) ); |
| 92 | + return; |
| 93 | + } |
| 94 | +
|
| 95 | + if ( dstUrl.isEmpty() ) |
| 96 | + { |
| 97 | + QMessageBox::warning( this, |
| 98 | + tr( "OGR Layer Converter" ), |
| 99 | + tr( "Output OGR dataset is missing!" ) ); |
| 100 | + return; |
| 101 | + } |
| 102 | +
|
| 103 | + if ( dstLayer.isEmpty() ) |
| 104 | + { |
| 105 | + QMessageBox::warning( this, |
| 106 | + tr( "OGR Layer Converter" ), |
| 107 | + tr( "Output OGR layer name is missing!" ) ); |
| 108 | + return; |
| 109 | + } |
| 110 | +
|
| 111 | + // TODO: SRS transformation support |
| 112 | + //QString srcSrs("EPSG:"); |
| 113 | + //QString dstSrs("EPSG:"); |
| 114 | + //srcSrs += inputSrcSrs->text(); |
| 115 | + //dstSrs += inputDstSrs->text(); |
| 116 | +
|
| 117 | + // Execute layer translation |
| 118 | + bool success = false; |
| 119 | +
|
| 120 | + // TODO: Use try-catch to display more meaningful error messages from Translator |
| 121 | + Translator worker( srcUrl, dstUrl, dstFormat ); |
| 122 | + worker.setSourceLayer( srcLayer ); |
| 123 | + worker.setTargetLayer( dstLayer ); |
| 124 | + success = worker.translate(); |
| 125 | +
|
| 126 | + if ( success ) |
| 127 | + { |
| 128 | + QMessageBox::information( this, |
| 129 | + tr( "OGR Layer Converter" ), |
| 130 | + tr( "Successfully translated layer '%1'" ).arg( srcLayer ) ); |
| 131 | + } |
| 132 | + else |
| 133 | + { |
| 134 | + QMessageBox::information( this, |
| 135 | + tr( "OGR Layer Converter" ), |
| 136 | + tr( "Failed to translate layer '%1'" ).arg( srcLayer ) ); |
| 137 | + } |
| 138 | +
|
| 139 | + // Close dialog box |
| 140 | + */ |
| 141 | + accept(); |
| 142 | +} |
| 143 | + |
| 144 | +void QgsGlobePluginDialog::on_buttonBox_rejected() |
| 145 | +{ |
| 146 | + reject(); |
| 147 | +} |
| 148 | + |
| 149 | +void QgsGlobePluginDialog::on_comboStereo_currentIndexChanged( int stereoMode ) |
| 150 | +{ |
| 151 | + QMessageBox msgBox; |
| 152 | + msgBox.setText("stereo mode changed"); |
| 153 | + msgBox.exec(); |
| 154 | + //showText("stereo mode changed"); |
| 155 | + /* |
| 156 | + // Select destination data format |
| 157 | + QString frmtCode = comboDstFormats->currentText(); |
| 158 | + mDstFormat = mFrmts.find( frmtCode ); |
| 159 | +
|
| 160 | + resetDstUi(); |
| 161 | + */ |
| 162 | +} |
| 163 | + |
| 164 | +void QgsGlobePluginDialog::on_buttonSelectEarthfile_clicked() |
| 165 | +{ |
| 166 | + QMessageBox msgBox; |
| 167 | + msgBox.setText("select file"); |
| 168 | + msgBox.exec(); |
| 169 | + /* |
| 170 | + QSettings settings; |
| 171 | + QString src; |
| 172 | +
|
| 173 | + src = openFile(); |
| 174 | +
|
| 175 | + inputSrcDataset->setText( src ); |
| 176 | +
|
| 177 | + if ( !src.isEmpty() ) |
| 178 | + { |
| 179 | + QMessageBox msgBox; |
| 180 | + msgBox.setText(src); |
| 181 | + msgBox.exec(); |
| 182 | + //showText( src.toString() ); |
| 183 | + } |
| 184 | + */ |
| 185 | +} |
| 186 | + |
| 187 | +/*void QgsGlobePluginDialog::showText(QString text) |
| 188 | +{ |
| 189 | + QMessageBox msgBox; |
| 190 | + msgBox.setText(text); |
| 191 | + msgBox.exec(); |
| 192 | +} |
| 193 | +*/ |
0 commit comments