@@ -71,10 +71,11 @@ QgsStyleExportImportDialog::QgsStyleExportImportDialog( QgsStyle *style, QWidget
71
71
{
72
72
setWindowTitle ( tr ( " Import Item(s)" ) );
73
73
// populate the import types
74
- importTypeCombo->addItem ( tr ( " file specified below " ), QVariant ( " file " ) );
75
- // importTypeCombo->addItem( "official QGIS repo online", QVariant( "official" ) );
76
- importTypeCombo->addItem ( tr ( " URL specified below " ), QVariant ( " url " ) );
74
+ importTypeCombo->addItem ( tr ( " File " ), ImportSource::File );
75
+ // importTypeCombo->addItem( "official QGIS repo online", ImportSource::Official );
76
+ importTypeCombo->addItem ( tr ( " URL" ), ImportSource::Url );
77
77
connect ( importTypeCombo, static_cast <void ( QComboBox::* )( int )>( &QComboBox::currentIndexChanged ), this , &QgsStyleExportImportDialog::importTypeChanged );
78
+ importTypeChanged ( 0 );
78
79
79
80
mSymbolTags ->setText ( QStringLiteral ( " imported" ) );
80
81
@@ -91,7 +92,7 @@ QgsStyleExportImportDialog::QgsStyleExportImportDialog( QgsStyle *style, QWidget
91
92
btnBrowse->setHidden ( true );
92
93
fromLabel->setHidden ( true );
93
94
importTypeCombo->setHidden ( true );
94
- locationLabel ->setHidden ( true );
95
+ mLocationLabel ->setHidden ( true );
95
96
locationLineEdit->setHidden ( true );
96
97
97
98
mFavorite ->setHidden ( true );
@@ -479,53 +480,73 @@ void QgsStyleExportImportDialog::selectByGroup()
479
480
480
481
void QgsStyleExportImportDialog::importTypeChanged ( int index )
481
482
{
482
- QString type = importTypeCombo->itemData ( index ).toString ( );
483
+ ImportSource source = static_cast < ImportSource >( importTypeCombo->itemData ( index ).toInt () );
483
484
484
485
locationLineEdit->clear ();
485
486
486
- if ( type == QLatin1String ( " file " ) )
487
+ switch ( source )
487
488
{
488
- locationLineEdit->setEnabled ( true );
489
- btnBrowse->setText ( QStringLiteral ( " Browse" ) );
490
- }
491
- else if ( type == QLatin1String ( " official" ) )
492
- {
493
- btnBrowse->setText ( QStringLiteral ( " Fetch Items" ) );
494
- locationLineEdit->setEnabled ( false );
495
- }
496
- else
497
- {
498
- btnBrowse->setText ( QStringLiteral ( " Fetch Items" ) );
499
- locationLineEdit->setEnabled ( true );
489
+ case ImportSource::File:
490
+ {
491
+ mLocationLabel ->setText ( tr ( " File" ) );
492
+ locationLineEdit->setEnabled ( true );
493
+ btnBrowse->setText ( QStringLiteral ( " Browse" ) );
494
+ break ;
495
+ }
496
+ #if 0
497
+ case ImportSource::Official:
498
+ {
499
+ btnBrowse->setText( QStringLiteral( "Fetch Items" ) );
500
+ locationLineEdit->setEnabled( false );
501
+ break;
502
+ }
503
+ #endif
504
+ case ImportSource::Url:
505
+ {
506
+ mLocationLabel ->setText ( tr ( " URL" ) );
507
+ btnBrowse->setText ( QStringLiteral ( " Fetch Items" ) );
508
+ locationLineEdit->setEnabled ( true );
509
+ break ;
510
+ }
500
511
}
501
512
}
502
513
503
514
void QgsStyleExportImportDialog::browse ()
504
515
{
505
- QString type = importTypeCombo->currentData ().toString ( );
516
+ ImportSource source = static_cast < ImportSource >( importTypeCombo->currentData ().toInt () );
506
517
507
- if ( type == QLatin1String ( " file " ) )
518
+ switch ( source )
508
519
{
509
- mFileName = QFileDialog::getOpenFileName ( this , tr ( " Load Styles" ), QDir::homePath (),
510
- tr ( " XML files (*.xml *.XML)" ) );
511
- if ( mFileName .isEmpty () )
520
+ case ImportSource::File:
512
521
{
513
- return ;
522
+ mFileName = QFileDialog::getOpenFileName ( this , tr ( " Load Styles" ), QDir::homePath (),
523
+ tr ( " XML files (*.xml *.XML)" ) );
524
+ if ( mFileName .isEmpty () )
525
+ {
526
+ return ;
527
+ }
528
+ QFileInfo pathInfo ( mFileName );
529
+ QString tag = pathInfo.fileName ().remove ( QStringLiteral ( " .xml" ) );
530
+ mSymbolTags ->setText ( tag );
531
+ locationLineEdit->setText ( mFileName );
532
+ populateStyles ( mTempStyle );
533
+ break ;
534
+ }
535
+
536
+ #if 0
537
+ case ImportSource::Official:
538
+ {
539
+ // TODO set URL
540
+ // downloadStyleXML( QUrl( "http://...." ) );
541
+ break;
542
+ }
543
+ #endif
544
+
545
+ case ImportSource::Url:
546
+ {
547
+ downloadStyleXml ( QUrl ( locationLineEdit->text () ) );
548
+ break ;
514
549
}
515
- QFileInfo pathInfo ( mFileName );
516
- QString tag = pathInfo.fileName ().remove ( QStringLiteral ( " .xml" ) );
517
- mSymbolTags ->setText ( tag );
518
- locationLineEdit->setText ( mFileName );
519
- populateStyles ( mTempStyle );
520
- }
521
- else if ( type == QLatin1String ( " official" ) )
522
- {
523
- // TODO set URL
524
- // downloadStyleXML( QUrl( "http://...." ) );
525
- }
526
- else
527
- {
528
- downloadStyleXml ( QUrl ( locationLineEdit->text () ) );
529
550
}
530
551
}
531
552
0 commit comments