00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00030 #include "../inc/App.h"
00031
00032 App::App( QWidget *widget ) : QMainWindow( widget )
00033 {
00034 InitData();
00035
00036 InitInterface();
00037
00038 TranslateInterface();
00039
00040 InitProjections();
00041
00042 UpdateParameters();
00043 }
00044
00045 App::~App( void )
00046 {
00047 delete [] *formats;
00048 delete [] *databases;
00049 delete [] *projections;
00050 }
00051
00052 void App::InitData( void )
00053 {
00054 ogr = new Ogr();
00055
00056 formats = new QString * [ formatsCount ];
00057
00058 for( int i = 0; i < formatsCount; i ++ )
00059 {
00060 formats[ i ] = new QString[ 2 ];
00061 }
00062
00063 databases = new QString * [ databasesCount ];
00064
00065 for( int i = 0; i < databasesCount; i ++ )
00066 {
00067 databases[ i ] = new QString[ 2 ];
00068 }
00069
00070 projections = new QString*[ projectionsCount ];
00071
00072 for( int i = 0; i < projectionsCount; i ++ )
00073 {
00074 projections[ i ] = new QString[ 2 ];
00075 }
00076
00077 #include "../inc/Dta.h"
00078 }
00079
00080 void App::InitProjections( void )
00081 {
00082 QString prj;
00083
00084 cmbTargetProj->addItem( tr( "" ) );
00085
00086 for( int i = 1; i < projectionsCount; i ++ )
00087 {
00088 prj.clear();
00089 prj = projections[ i ][ 0 ];
00090 prj.append( tr( " : " ) );
00091 prj.append( projections[ i ][ 1 ] );
00092
00093 cmbTargetProj->addItem( prj );
00094 }
00095 }
00096
00097 void App::InitInterface( void )
00098 {
00099 thePanel = new QWidget();
00100
00101 inf = new Inf( this );
00102
00103
00104 InitMenu();
00105
00106 InitLayout();
00107
00108 InitSlots();
00109
00110
00111 radSourceFile->setChecked( true );
00112
00113 radTargetFile->setChecked( true );
00114
00115 radTargetOverwrite->setChecked( true );
00116
00117 btnExecute->setEnabled( false );
00118
00119
00120 this->setCentralWidget( thePanel );
00121
00122 this->show();
00123 }
00124
00125 void App::InitMenu( void )
00126 {
00127 theMenu = new QMenuBar( this );
00128 {
00129 fileMenu = new QMenu( theMenu );
00130 {
00131 mnuQuit = new QAction( this );
00132
00133 fileMenu->addAction( mnuQuit );
00134 }
00135
00136 helpMenu = new QMenu( theMenu );
00137 {
00138 mnuOgrHelp = new QAction( this );
00139 mnuGuiHelp = new QAction( this );
00140 mnuAbout = new QAction( this );
00141
00142 helpMenu->addAction( mnuOgrHelp );
00143 helpMenu->addAction( mnuGuiHelp );
00144 helpMenu->addSeparator();
00145 helpMenu->addAction( mnuAbout );
00146 }
00147
00148 theMenu->addAction( fileMenu->menuAction() );
00149 theMenu->addAction( helpMenu->menuAction() );
00150 }
00151
00152 this->setMenuBar( theMenu );
00153 }
00154
00155 void App::InitLayout( void )
00156 {
00157 theLayout = new QVBoxLayout( thePanel );
00158 {
00159 theLayout->setMargin( 7 );
00160 theLayout->setSpacing( 7 );
00161
00162 grpSource = new QGroupBox( thePanel );
00163 {
00164 grpSource->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed );
00165
00166 lytSource = new QGridLayout();
00167 {
00168 lytSource->setMargin( 7 );
00169 lytSource->setSpacing( 7 );
00170
00171 lytSourceInput = new QHBoxLayout();
00172 {
00173 radSourceFile = new QRadioButton();
00174 radSourceFolder = new QRadioButton();
00175 radSourceDatabase = new QRadioButton();
00176
00177 lytSourceInput->addWidget( radSourceFile );
00178 lytSourceInput->addWidget( radSourceFolder );
00179 lytSourceInput->addWidget( radSourceDatabase );
00180 }
00181
00182 lytSource->addLayout( lytSourceInput, 0, 1 );
00183
00184 lblSourceFormat = new QLabel();
00185 lblSourceFormat->setAlignment( Qt::AlignRight | Qt::AlignVCenter );
00186 lblSourceFormat->setMinimumWidth( 70 );
00187 lblSourceFormat->setMaximumWidth( 70 );
00188
00189 cmbSourceFormat = new QComboBox();
00190
00191 lytSource->addWidget( lblSourceFormat, 1, 0 );
00192 lytSource->addWidget( cmbSourceFormat, 1, 1 );
00193
00194 lblSourceName = new QLabel();
00195 lblSourceName->setAlignment( Qt::AlignRight | Qt::AlignVCenter );
00196 lblSourceName->setMinimumWidth( 70 );
00197 lblSourceName->setMaximumWidth( 70 );
00198
00199 lytSourceName = new QHBoxLayout();
00200 {
00201 txtSourceName = new QLineEdit();
00202 txtSourceName->setReadOnly( true );
00203
00204 btnSourceName = new QPushButton();
00205
00206 lytSourceName->addWidget( txtSourceName );
00207 lytSourceName->addWidget( btnSourceName );
00208 }
00209
00210 lytSource->addWidget( lblSourceName, 2, 0 );
00211 lytSource->addLayout( lytSourceName, 2, 1 );
00212
00213 lblSourceProj = new QLabel();
00214 lblSourceProj->setAlignment( Qt::AlignRight | Qt::AlignVCenter );
00215 lblSourceProj->setMinimumWidth( 70 );
00216 lblSourceProj->setMaximumWidth( 70 );
00217
00218 txtSourceProj = new QLineEdit();
00219 txtSourceProj->setReadOnly( true );
00220
00221 lytSource->addWidget( lblSourceProj, 3, 0 );
00222 lytSource->addWidget( txtSourceProj, 3, 1 );
00223
00224 lblSourceQuery = new QLabel();
00225 lblSourceQuery->setAlignment( Qt::AlignRight | Qt::AlignVCenter );
00226 lblSourceQuery->setMinimumWidth( 70 );
00227 lblSourceQuery->setMaximumWidth( 70 );
00228
00229 txtSourceQuery = new QLineEdit();
00230
00231 lytSource->addWidget( lblSourceQuery );
00232 lytSource->addWidget( txtSourceQuery );
00233 }
00234
00235 grpSource->setLayout( lytSource );
00236 }
00237
00238 theLayout->addWidget( grpSource );
00239
00240 grpTarget = new QGroupBox( thePanel );
00241 {
00242 grpTarget->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed );
00243
00244 lytTarget = new QGridLayout();
00245 {
00246 lytTargetOutput = new QHBoxLayout();
00247 {
00248 grpTargetOutput = new QButtonGroup();
00249 {
00250 radTargetFile = new QRadioButton();
00251 radTargetFolder = new QRadioButton();
00252 radTargetDatabase = new QRadioButton();
00253
00254 grpTargetOutput->addButton( radTargetFile );
00255 grpTargetOutput->addButton( radTargetFolder );
00256 grpTargetOutput->addButton( radTargetDatabase );
00257
00258 lytTargetOutput->addWidget( radTargetFile );
00259 lytTargetOutput->addWidget( radTargetFolder );
00260 lytTargetOutput->addWidget( radTargetDatabase );
00261 }
00262 }
00263
00264 lytTarget->addLayout( lytTargetOutput, 0, 1 );
00265
00266
00267 lblTargetFormat = new QLabel();
00268 lblTargetFormat->setAlignment( Qt::AlignRight | Qt::AlignVCenter );
00269 lblTargetFormat->setMinimumWidth( 70 );
00270 lblTargetFormat->setMaximumWidth( 70 );
00271
00272 cmbTargetFormat = new QComboBox();
00273
00274 lytTarget->addWidget( lblTargetFormat, 1, 0 );
00275 lytTarget->addWidget( cmbTargetFormat, 1, 1 );
00276
00277
00278 lblTargetName = new QLabel();
00279 lblTargetName->setAlignment( Qt::AlignRight | Qt::AlignVCenter );
00280 lblTargetName->setMinimumWidth( 70 );
00281 lblTargetName->setMaximumWidth( 70 );
00282
00283 lytTargetName = new QHBoxLayout();
00284 {
00285 txtTargetName = new QLineEdit();
00286 txtTargetName->setReadOnly( true );
00287
00288 btnTargetName = new QPushButton();
00289
00290 lytTargetName->addWidget( txtTargetName );
00291 lytTargetName->addWidget( btnTargetName );
00292 }
00293
00294 lytTarget->addWidget( lblTargetName, 2, 0 );
00295 lytTarget->addLayout( lytTargetName, 2, 1 );
00296
00297
00298 lblTargetProj = new QLabel();
00299 lblTargetProj->setAlignment( Qt::AlignRight | Qt::AlignVCenter );
00300 lblTargetProj->setMinimumWidth( 70 );
00301 lblTargetProj->setMaximumWidth( 70 );
00302
00303 lytTargetProj = new QHBoxLayout();
00304 {
00305 txtTargetProj = new QLineEdit();
00306 txtTargetProj->setMaxLength( 5 );
00307 txtTargetProj->setMinimumWidth( 50 );
00308 txtTargetProj->setMaximumWidth( 50 );
00309
00310 cmbTargetProj = new QComboBox();
00311 cmbTargetProj->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed );
00312
00313 lytTargetProj->addWidget( txtTargetProj );
00314 lytTargetProj->addWidget( cmbTargetProj );
00315 }
00316
00317 lytTarget->addWidget( lblTargetProj, 3, 0 );
00318 lytTarget->addLayout( lytTargetProj, 3, 1 );
00319
00320 lytTargetOptions = new QHBoxLayout();
00321 {
00322 grpTargetOptions = new QButtonGroup();
00323 {
00324 radTargetOverwrite = new QRadioButton();
00325 radTargetAppend = new QRadioButton();
00326 radTargetUpdate = new QRadioButton();
00327
00328 lytTargetOptions->addWidget( radTargetOverwrite );
00329 lytTargetOptions->addWidget( radTargetAppend );
00330 lytTargetOptions->addWidget( radTargetUpdate );
00331
00332 grpTargetOptions->addButton( radTargetOverwrite );
00333 grpTargetOptions->addButton( radTargetAppend );
00334 grpTargetOptions->addButton( radTargetUpdate );
00335 }
00336 }
00337
00338 lytTarget->addLayout( lytTargetOptions, 4, 1 );
00339 }
00340
00341 grpTarget->setLayout( lytTarget );
00342 }
00343
00344 theLayout->addWidget( grpTarget );
00345
00346 txtOutput = new QTextEdit();
00347 txtOutput->setReadOnly( true );
00348
00349 lytExecute = new QHBoxLayout();
00350 {
00351 btnExecute = new QPushButton();
00352 btnExecute->setMinimumWidth( 200 );
00353 btnExecute->setEnabled( false );
00354
00355 btnQuit = new QPushButton();
00356 btnQuit->setMinimumWidth( 200 );
00357
00358 lytExecute->addWidget( btnExecute );
00359 lytExecute->addWidget( btnQuit );
00360 }
00361
00362 theLayout->addWidget( txtOutput );
00363 theLayout->addLayout( lytExecute );
00364
00365 theProgress = new QProgressBar();
00366
00367 theLayout->addWidget( theProgress );
00368 }
00369
00370 thePanel->setLayout( theLayout );
00371 }
00372
00373 void App::InitSlots( void )
00374 {
00375 QObject::connect( mnuQuit, SIGNAL( activated() ), this, SLOT( close( void ) ) );
00376
00377 QObject::connect( mnuOgrHelp, SIGNAL( activated() ), this, SLOT( evtMnuOgrHelp( void ) ) );
00378
00379 QObject::connect( mnuGuiHelp, SIGNAL( activated() ), this, SLOT( evtMnuGuiHelp( void ) ) );
00380
00381 QObject::connect( mnuAbout, SIGNAL( activated() ), this, SLOT( evtMnuAbout( void ) ) );
00382
00383
00384 QObject::connect( radSourceFile, SIGNAL( toggled( bool ) ), this, SLOT( evtRadSourceFile( void ) ) );
00385
00386 QObject::connect( radSourceFolder, SIGNAL( toggled( bool ) ), this, SLOT( evtRadSourceFolder( void ) ) );
00387
00388 QObject::connect( radSourceDatabase, SIGNAL( toggled( bool ) ), this, SLOT( evtRadSourceDatabase( void ) ) );
00389
00390
00391 QObject::connect( cmbSourceFormat, SIGNAL( currentIndexChanged( int ) ), this, SLOT( evtCmbSourceFormat( int ) ) );
00392
00393 QObject::connect( txtSourceName, SIGNAL( textChanged( QString ) ), this, SLOT( evtTxtSourceName( void ) ) );
00394
00395 QObject::connect( btnSourceName, SIGNAL( clicked( void ) ), this, SLOT( evtBtnSourceName( void ) ) );
00396
00397 QObject::connect( txtSourceQuery, SIGNAL( textChanged( QString ) ), this, SLOT( evtTxtSourceQuery( void ) ) );
00398
00399
00400 QObject::connect( radTargetFile, SIGNAL( toggled( bool ) ), this, SLOT( evtRadTargetFile( void ) ) );
00401
00402 QObject::connect( radTargetFolder, SIGNAL( toggled( bool ) ), this, SLOT( evtRadTargetFolder( void ) ) );
00403
00404 QObject::connect( radTargetDatabase, SIGNAL( toggled( bool ) ), this, SLOT( evtRadTargetDatabase( void ) ) );
00405
00406
00407 QObject::connect( cmbTargetFormat, SIGNAL( currentIndexChanged( int ) ), this, SLOT( evtCmbTargetFormat( void ) ) );
00408
00409 QObject::connect( txtTargetName, SIGNAL( textChanged( QString ) ), this, SLOT( evtTxtTargetName( void ) ) );
00410
00411 QObject::connect( btnTargetName, SIGNAL( clicked() ), this, SLOT( evtBtnTargetName( void ) ) );
00412
00413 QObject::connect( txtTargetProj, SIGNAL( textChanged( QString ) ), this, SLOT( evtTxtTargetProj( void ) ) );
00414
00415 QObject::connect( cmbTargetProj, SIGNAL( currentIndexChanged( int ) ), this, SLOT( evtCmbTargetProj( void ) ) );
00416
00417
00418 QObject::connect( radTargetOverwrite, SIGNAL( toggled( bool ) ), this, SLOT( evtRadTargetOverwrite( void ) ) );
00419
00420 QObject::connect( radTargetAppend, SIGNAL( toggled( bool ) ), this, SLOT( evtRadTargetAppend( void ) ) );
00421
00422 QObject::connect( radTargetUpdate, SIGNAL( toggled( bool ) ), this, SLOT( evtRadTargetUpdate( void ) ) );
00423
00424
00425 QObject::connect( btnExecute, SIGNAL( clicked( void ) ), this, SLOT( evtBtnExecute( void ) ) );
00426
00427 QObject::connect( btnQuit, SIGNAL( clicked( void ) ), this, SLOT( evtBtnQuit( void ) ) );
00428
00429
00430 QMetaObject::connectSlotsByName( this );
00431 }
00432
00433
00434 void App::TranslateInterface( void )
00435 {
00436 this->setWindowTitle( tr( "ogr2gui - Inventis" ) );
00437
00438 fileMenu->setTitle( tr( "&File" ) );
00439 {
00440 mnuQuit->setText( tr( "&Quit" ) );
00441 }
00442
00443 helpMenu->setTitle( tr( "&Help" ) );
00444 {
00445 mnuOgrHelp->setText( tr( "&ogr2ogr" ) );
00446 mnuGuiHelp->setText( tr( "ogr&2gui" ) );
00447
00448 mnuAbout->setText( tr( "&About" ) );
00449 }
00450
00451 grpSource->setTitle( tr( "Source" ) );
00452 {
00453 radSourceFile->setText( tr( "File" ) );
00454 radSourceFolder->setText( tr( "Folder" ) );
00455 radSourceDatabase->setText( tr( "Database" ) );
00456
00457 lblSourceFormat->setText( tr( "Format" ) );
00458
00459 lblSourceName->setText( tr( "Name" ) );
00460 btnSourceName->setText( tr( "&Open" ) );
00461
00462 lblSourceProj->setText( tr( "Projection" ) );
00463
00464 lblSourceQuery->setText( tr( "Query" ) );
00465 }
00466
00467 grpTarget->setTitle( tr( "Target" ) );
00468 {
00469 radTargetFile->setText( tr( "File" ) );
00470 radTargetFolder->setText( tr( "Folder" ) );
00471 radTargetDatabase->setText( tr( "Database" ) );
00472
00473 lblTargetFormat->setText( tr( "Format" ) );
00474
00475 lblTargetName->setText( tr( "Name" ) );
00476 btnTargetName->setText( tr( "&Save" ) );
00477
00478 lblTargetProj->setText( tr( "Projection" ) );
00479
00480 radTargetOverwrite->setText( tr( "overwrite" ) );
00481 radTargetAppend->setText( tr( "append" ) );
00482 radTargetUpdate->setText( tr( "update" ) );
00483 }
00484
00485 btnExecute->setText( tr( "&Execute" ) );
00486 btnQuit->setText( tr( "&Quit" ) );
00487 }
00488
00489
00490 void App::UpdateParameters( void )
00491 {
00492 parameters = tr( "ogr2ogr" ) + tr( " -f \"" ) + cmbTargetFormat->currentText() + tr( "\" " );
00493
00494 if( radTargetOverwrite->isChecked() )
00495 {
00496 parameters += tr( "-overwrite" );
00497 }
00498
00499 if( radTargetAppend->isChecked() )
00500 {
00501 parameters += tr( "-append" );
00502 }
00503
00504 if( radTargetUpdate->isChecked() )
00505 {
00506 parameters += tr( "-update" );
00507 }
00508
00509 parameters += tr( " \"" ) + txtTargetName->text() + tr( "\" \"" ) + txtSourceName->text() + tr( "\" " );
00510
00511 if( ! cmbTargetProj->currentText().isEmpty() )
00512 {
00513 parameters += tr( "-T_SRS EPSG:" ) + projections[ cmbTargetProj->currentIndex() ][ 0 ] + tr( " " );
00514 }
00515
00516 if( ! txtSourceQuery->text().isEmpty() )
00517 {
00518 parameters += tr( "-sql \"" ) + txtSourceQuery->text() + tr( "\" " );
00519 }
00520
00521 for( int i = 0; i < ( int ) parameters.size(); i ++ )
00522 {
00523 if( parameters.at( i ) == '\\' )
00524 {
00525 parameters[ i ] = '/';
00526 }
00527 }
00528
00529 parameters += tr( "\n" );
00530
00531 txtOutput->setText( parameters );
00532 }
00533
00534
00535 void App::evtMnuOgrHelp( void )
00536 {
00537 QDesktopServices::openUrl( QUrl( tr( "http://gdal.org/ogr" ) ) );
00538 }
00539
00540 void App::evtMnuGuiHelp( void )
00541 {
00542 QDesktopServices::openUrl( QUrl( tr( "http://www.ogr2gui.ca/0.5/doc/index.html" ) ) );
00543 }
00544
00545 void App::evtMnuAbout( void )
00546 {
00547 QDesktopServices::openUrl( QUrl( tr( "http://www.ogr2gui.ca/" ) ) );
00548 }
00549
00550
00551 void App::evtRadSourceFile( void )
00552 {
00553 btnSourceName->setText( tr( "&Open" ) );
00554
00555 cmbSourceFormat->clear();
00556
00557 for( int i = 0; i < formatsCount; i ++ )
00558 {
00559 cmbSourceFormat->addItem( formats[ i ][ 0 ] );
00560 }
00561
00562 radTargetFile->setEnabled( true );
00563 radTargetFolder->setEnabled( false );
00564 radTargetDatabase->setEnabled( true );
00565
00566 radTargetFile->setChecked( true );
00567
00568 txtSourceName->clear();
00569 txtSourceProj->clear();
00570 txtSourceQuery->clear();
00571
00572 txtSourceProj->setEnabled( true );
00573 txtSourceQuery->setEnabled( true );
00574 }
00575
00576 void App::evtRadSourceFolder( void )
00577 {
00578 btnSourceName->setText( tr( "&Browse" ) );
00579
00580 cmbSourceFormat->clear();
00581
00582 for( int i = 0; i < formatsCount; i ++ )
00583 {
00584 cmbSourceFormat->addItem( formats[ i ][ 0 ] );
00585 }
00586
00587 radTargetFile->setEnabled( false );
00588 radTargetFolder->setEnabled( true );
00589 radTargetDatabase->setEnabled( true );
00590
00591 radTargetFolder->setChecked( true );
00592
00593 txtSourceName->clear();
00594 txtSourceProj->clear();
00595 txtSourceQuery->clear();
00596
00597 txtSourceProj->setEnabled( true );
00598 txtSourceQuery->setEnabled( true );
00599 }
00600
00601 void App::evtRadSourceDatabase( void )
00602 {
00603 btnSourceName->setText( tr( "&Connect" ) );
00604
00605 cmbSourceFormat->clear();
00606
00607 for( int i = 0; i < databasesCount; i ++ )
00608 {
00609 cmbSourceFormat->addItem( databases[ i ][ 0 ] );
00610 }
00611
00612 radTargetFile->setEnabled( true );
00613 radTargetFolder->setEnabled( true );
00614 radTargetDatabase->setEnabled( true );
00615
00616 radTargetFile->setChecked( true );
00617
00618 txtSourceName->clear();
00619 txtSourceProj->clear();
00620 txtSourceQuery->clear();
00621
00622 txtSourceProj->setEnabled( true );
00623 txtSourceQuery->setEnabled( true );
00624 }
00625
00626
00627 void App::evtCmbSourceFormat( int i )
00628 {
00629 txtSourceName->clear();
00630
00631 txtSourceProj->clear();
00632
00633 txtSourceQuery->clear();
00634
00635 UpdateParameters();
00636 }
00637
00638
00639 void App::evtTxtSourceName( void )
00640 {
00641 if( txtSourceName->text().startsWith( tr( "file://" ) ) )
00642 {
00643 txtSourceName->setText( QUrl( txtSourceName->text() ).authority().trimmed() );
00644 }
00645
00646 string name = txtSourceName->text().toStdString();
00647 string epsg;
00648 string query;
00649 string error;
00650
00651 if( ogr->OpenSource( name, epsg, query, error ) )
00652 {
00653 for( int i = 0; i < projectionsCount; i ++ )
00654 {
00655 if( strcmp( epsg.c_str(), projections[ i ][ 0 ].toStdString().c_str() ) == 0 )
00656 {
00657 if( i > 1 )
00658 {
00659 txtSourceProj->setText( projections[ i ][ 0 ] + tr( " : " ) + projections[ i ][ 1 ] );
00660 }
00661
00662 break;
00663 }
00664 }
00665
00666 ogr->CloseSource();
00667
00668 if( radSourceFile->isChecked() )
00669 {
00670 txtSourceQuery->setText( query.c_str() );
00671 }
00672 }
00673 else
00674 {
00675 txtSourceProj->clear();
00676 txtSourceQuery->clear();
00677 }
00678
00679 UpdateParameters();
00680 }
00681
00682 void App::evtBtnSourceName( void )
00683 {
00684 int idx = cmbSourceFormat->currentIndex();
00685
00686 QString type;
00687
00688 if( radSourceFile->isChecked() )
00689 {
00690 type = tr( "\"" ) + formats[ idx ][ 0 ] + tr( "\" | *." ) + formats[ idx ][ 1 ];
00691
00692 txtSourceName->setText( QFileDialog::getOpenFileName( this, tr( "Source File" ), tr( "" ), type ) );
00693
00694 fileList.clear();
00695
00696 fileList.append( txtSourceName->text() );
00697 }
00698 else if( radSourceFolder->isChecked() )
00699 {
00700 QStringList types;
00701
00702 type = tr( "*." ) + formats[ cmbSourceFormat->currentIndex() ][ 1 ];
00703
00704 txtSourceName->setText( QFileDialog::getExistingDirectory( this, tr( "Source Folder" ), tr( "" ), QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks ) );
00705
00706 QDir dir( txtSourceName->text() );
00707
00708 types.append( type );
00709
00710 QStringList list = dir.entryList( types );
00711
00712 fileList.clear();
00713
00714 for( int i = 0; i < list.size(); i ++ )
00715 {
00716 fileList.append( list.at( i ) );
00717 }
00718
00719 if( list.size() > 1 )
00720 {
00721 txtSourceProj->setEnabled( false );
00722 txtSourceQuery->setEnabled( false );
00723 }
00724 }
00725 else if( radSourceDatabase->isChecked() )
00726 {
00727 inf->setConnectionType( databases[ idx ][ 1 ] );
00728
00729 inf->setDialogStyle( 1 );
00730
00731 if( inf->exec() == QDialog::Accepted )
00732 {
00733 txtSourceName->setText( inf->getConnectionString() );
00734 }
00735
00736 fileList.clear();
00737
00738 QStringList tables = inf->getSelectedTables();
00739
00740 QString connectionString = txtSourceName->text();
00741
00742 connectionString.truncate( connectionString.lastIndexOf( tr( "tables=" ) ) );
00743
00744 for( int i = 0; i < tables.size(); i ++ )
00745 {
00746 fileList.append( connectionString + tr( "tables=" ) + tables.at( i ) );
00747 }
00748
00749 if( fileList.size() > 1 )
00750 {
00751 txtSourceProj->setEnabled( false );
00752 txtSourceQuery->setEnabled( false );
00753
00754 radTargetFile->setEnabled( false );
00755 radTargetFolder->setChecked( true );
00756 }
00757 else
00758 {
00759 radTargetFile->setEnabled( true );
00760 radTargetFile->setChecked( true );
00761 }
00762 }
00763 }
00764
00765 void App::evtTxtSourceQuery( void )
00766 {
00767 UpdateParameters();
00768 }
00769
00770
00771 void App::evtRadTargetFile( void )
00772 {
00773 btnTargetName->setText( tr( "&Save" ) );
00774
00775 cmbTargetFormat->clear();
00776
00777 for( int i = 0; i < formatsOutput; i ++ )
00778 {
00779 cmbTargetFormat->addItem( formats[ i ][ 0 ] );
00780 }
00781
00782 txtTargetName->clear();
00783 txtTargetProj->clear();
00784
00785 cmbTargetProj->setCurrentIndex( 0 );
00786 }
00787
00788 void App::evtRadTargetFolder( void )
00789 {
00790 btnTargetName->setText( tr( "&Browse" ) );
00791
00792 cmbTargetFormat->clear();
00793
00794 for( int i = 0; i < formatsOutput; i ++ )
00795 {
00796 cmbTargetFormat->addItem( formats[ i ][ 0 ] );
00797 }
00798 }
00799
00800 void App::evtRadTargetDatabase( void )
00801 {
00802 btnTargetName->setText( tr( "&Connect" ) );
00803
00804 cmbTargetFormat->clear();
00805
00806 for( int i = 0; i < databasesOutput; i ++ )
00807 {
00808 cmbTargetFormat->addItem( databases[ i ][ 0 ] );
00809 }
00810 }
00811
00812 void App::evtCmbTargetFormat( void )
00813 {
00814 txtTargetName->clear();
00815 }
00816
00817 void App::evtTxtTargetName( void )
00818 {
00819 btnExecute->setEnabled( true );
00820
00821 UpdateParameters();
00822 }
00823
00824 void App::evtBtnTargetName( void )
00825 {
00826 QString type;
00827
00828 int idx = cmbTargetFormat->currentIndex();
00829
00830 if( radTargetDatabase->isChecked() )
00831 {
00832 inf->setDialogStyle( 0 );
00833
00834 inf->setConnectionType( databases[ cmbTargetFormat->currentIndex() ][ 1 ] );
00835
00836 if( inf->exec() == QDialog::Accepted )
00837 {
00838 txtTargetName->setText( inf->getConnectionString() );
00839 }
00840 }
00841 else if( radTargetFolder->isChecked() )
00842 {
00843 if( radSourceFile->isChecked() )
00844 {
00845 type = tr( "\"" ) + formats[ idx ][ 0 ] + tr( " (*." ) + formats[ idx ][ 1 ] + tr( ") | *." ) + formats[ idx ][ 1 ];
00846
00847 txtTargetName->setText( QFileDialog::getSaveFileName( this, tr( "Save File" ), tr( "" ), type ) );
00848 }
00849 else if( radTargetFolder->isChecked() )
00850 {
00851 txtTargetName->setText( QFileDialog::getExistingDirectory( this, tr( "Target Folder" ), tr( "" ), QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks ) );
00852 }
00853 }
00854 else
00855 {
00856 type = tr( "\"" ) + formats[ idx ][ 0 ] + tr( "\" | *." ) + formats[ idx ][ 1 ];
00857
00858 txtTargetName->setText( QFileDialog::getSaveFileName( this, tr( "Target File" ), tr( "" ), type ) );
00859 }
00860
00861 btnExecute->setEnabled( true );
00862 }
00863
00864 void App::evtTxtTargetProj( void )
00865 {
00866 QString projection = txtTargetProj->text();
00867
00868 for( int i = 0; i < projectionsCount; i ++ )
00869 {
00870 if( ( projections[ i ][ 0 ] ).startsWith( projection ) )
00871 {
00872 cmbTargetProj->setCurrentIndex( i );
00873
00874 break;
00875 }
00876 }
00877
00878 UpdateParameters();
00879 }
00880
00881 void App::evtCmbTargetProj( void )
00882 {
00883 UpdateParameters();
00884 }
00885
00886 void App::evtRadTargetAppend( void )
00887 {
00888 UpdateParameters();
00889 }
00890
00891 void App::evtRadTargetOverwrite( void )
00892 {
00893 UpdateParameters();
00894 }
00895
00896 void App::evtRadTargetUpdate( void )
00897 {
00898 UpdateParameters();
00899 }
00900
00901 void App::evtBtnExecute( void )
00902 {
00903 QString name;
00904 QString sourcename;
00905 QString targetname;
00906
00907 string epsg;
00908 string query;
00909 string error;
00910
00911 int featuresCount = 0;
00912 int progress = 0;
00913
00914 txtOutput->clear();
00915
00916 for( int i = 0; i < fileList.size(); i ++ )
00917 {
00918 if( radSourceFile->isChecked() )
00919 {
00920 sourcename = txtSourceName->text();
00921 targetname = txtTargetName->text();
00922 }
00923 else if( radSourceFolder->isChecked() )
00924 {
00925 sourcename = txtSourceName->text() + tr( "/" ) + fileList.at( i );
00926 targetname = txtTargetName->text();
00927 }
00928 else if( radSourceDatabase->isChecked() )
00929 {
00930 sourcename = fileList.at( i );
00931 targetname = txtTargetName->text();
00932 }
00933
00934 txtOutput->append( QString( sourcename + tr( " > " ) + targetname + tr( " ... " ) ) );
00935
00936 if( ogr->OpenSource( sourcename.toStdString(), epsg, query, error ) )
00937 {
00938 if( ogr->OpenDriver( cmbTargetFormat->currentText().toStdString(), error ) )
00939 {
00940 if( ogr->OpenTarget( targetname.toStdString(), atoi( projections[ cmbTargetProj->currentIndex() ][ 0 ].toStdString().c_str() ) ) )
00941 {
00942 ogr->Prepare( featuresCount, "" );
00943
00944 theProgress->setMinimum( 0 );
00945 theProgress->setMaximum( featuresCount );
00946 theProgress->setValue( 0 );
00947
00948 while( ogr->Process() )
00949 {
00950 progress ++;
00951
00952 theProgress->setValue( progress );
00953 }
00954
00955 ogr->CloseTarget();
00956 ogr->CloseSource();
00957
00958 theProgress->setValue( 0 );
00959
00960 txtOutput->append( tr( "successful.\n" ) );
00961 }
00962 else
00963 {
00964 txtOutput->append( tr( "\n * unable to open target !\n" ) );
00965 }
00966 }
00967 else
00968 {
00969 txtOutput->append( tr( "\n * unable to open driver !\n" ) );
00970 }
00971 }
00972 else
00973 {
00974 txtOutput->append( tr( "\n * unable to open source !\n" ) );
00975 }
00976 }
00977 }
00978
00979 void App::evtBtnQuit( void )
00980 {
00981 this->close();
00982 }
00983
00984 int main( int argc, char **argv )
00985 {
00986 QApplication app( argc, argv );
00987
00988 new App();
00989
00990 return app.exec();
00991 }