Skip to content

Commit bf649e7

Browse files
committedAug 31, 2018
Cleanup code
1 parent 95e8960 commit bf649e7

File tree

3 files changed

+68
-39
lines changed

3 files changed

+68
-39
lines changed
 

‎src/gui/symbology/qgsstyleexportimportdialog.cpp

Lines changed: 59 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -71,10 +71,11 @@ QgsStyleExportImportDialog::QgsStyleExportImportDialog( QgsStyle *style, QWidget
7171
{
7272
setWindowTitle( tr( "Import Item(s)" ) );
7373
// 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 );
7777
connect( importTypeCombo, static_cast<void ( QComboBox::* )( int )>( &QComboBox::currentIndexChanged ), this, &QgsStyleExportImportDialog::importTypeChanged );
78+
importTypeChanged( 0 );
7879

7980
mSymbolTags->setText( QStringLiteral( "imported" ) );
8081

@@ -91,7 +92,7 @@ QgsStyleExportImportDialog::QgsStyleExportImportDialog( QgsStyle *style, QWidget
9192
btnBrowse->setHidden( true );
9293
fromLabel->setHidden( true );
9394
importTypeCombo->setHidden( true );
94-
locationLabel->setHidden( true );
95+
mLocationLabel->setHidden( true );
9596
locationLineEdit->setHidden( true );
9697

9798
mFavorite->setHidden( true );
@@ -479,53 +480,73 @@ void QgsStyleExportImportDialog::selectByGroup()
479480

480481
void QgsStyleExportImportDialog::importTypeChanged( int index )
481482
{
482-
QString type = importTypeCombo->itemData( index ).toString();
483+
ImportSource source = static_cast< ImportSource >( importTypeCombo->itemData( index ).toInt() );
483484

484485
locationLineEdit->clear();
485486

486-
if ( type == QLatin1String( "file" ) )
487+
switch ( source )
487488
{
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+
}
500511
}
501512
}
502513

503514
void QgsStyleExportImportDialog::browse()
504515
{
505-
QString type = importTypeCombo->currentData().toString();
516+
ImportSource source = static_cast< ImportSource >( importTypeCombo->currentData().toInt() );
506517

507-
if ( type == QLatin1String( "file" ) )
518+
switch ( source )
508519
{
509-
mFileName = QFileDialog::getOpenFileName( this, tr( "Load Styles" ), QDir::homePath(),
510-
tr( "XML files (*.xml *.XML)" ) );
511-
if ( mFileName.isEmpty() )
520+
case ImportSource::File:
512521
{
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;
514549
}
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() ) );
529550
}
530551
}
531552

‎src/gui/symbology/qgsstyleexportimportdialog.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,14 @@ class GUI_EXPORT QgsStyleExportImportDialog : public QDialog, private Ui::QgsSty
119119
void showHelp();
120120

121121
private:
122+
123+
enum ImportSource
124+
{
125+
File,
126+
//Official,
127+
Url,
128+
};
129+
122130
void downloadStyleXml( const QUrl &url );
123131
bool populateStyles( QgsStyle *style );
124132
void moveStyles( QModelIndexList *selection, QgsStyle *src, QgsStyle *dst );

‎src/ui/qgsstyleexportimportdialogbase.ui

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
<widget class="QComboBox" name="importTypeCombo"/>
2828
</item>
2929
<item row="1" column="0">
30-
<widget class="QLabel" name="locationLabel">
30+
<widget class="QLabel" name="mLocationLabel">
3131
<property name="text">
3232
<string>Location</string>
3333
</property>

0 commit comments

Comments
 (0)
Please sign in to comment.