Skip to content

Commit

Permalink
Cleanup code
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Aug 31, 2018
1 parent 95e8960 commit bf649e7
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 39 deletions.
97 changes: 59 additions & 38 deletions src/gui/symbology/qgsstyleexportimportdialog.cpp
Expand Up @@ -71,10 +71,11 @@ QgsStyleExportImportDialog::QgsStyleExportImportDialog( QgsStyle *style, QWidget
{
setWindowTitle( tr( "Import Item(s)" ) );
// populate the import types
importTypeCombo->addItem( tr( "file specified below" ), QVariant( "file" ) );
// importTypeCombo->addItem( "official QGIS repo online", QVariant( "official" ) );
importTypeCombo->addItem( tr( "URL specified below" ), QVariant( "url" ) );
importTypeCombo->addItem( tr( "File" ), ImportSource::File );
// importTypeCombo->addItem( "official QGIS repo online", ImportSource::Official );
importTypeCombo->addItem( tr( "URL" ), ImportSource::Url );
connect( importTypeCombo, static_cast<void ( QComboBox::* )( int )>( &QComboBox::currentIndexChanged ), this, &QgsStyleExportImportDialog::importTypeChanged );
importTypeChanged( 0 );

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

Expand All @@ -91,7 +92,7 @@ QgsStyleExportImportDialog::QgsStyleExportImportDialog( QgsStyle *style, QWidget
btnBrowse->setHidden( true );
fromLabel->setHidden( true );
importTypeCombo->setHidden( true );
locationLabel->setHidden( true );
mLocationLabel->setHidden( true );
locationLineEdit->setHidden( true );

mFavorite->setHidden( true );
Expand Down Expand Up @@ -479,53 +480,73 @@ void QgsStyleExportImportDialog::selectByGroup()

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

locationLineEdit->clear();

if ( type == QLatin1String( "file" ) )
switch ( source )
{
locationLineEdit->setEnabled( true );
btnBrowse->setText( QStringLiteral( "Browse" ) );
}
else if ( type == QLatin1String( "official" ) )
{
btnBrowse->setText( QStringLiteral( "Fetch Items" ) );
locationLineEdit->setEnabled( false );
}
else
{
btnBrowse->setText( QStringLiteral( "Fetch Items" ) );
locationLineEdit->setEnabled( true );
case ImportSource::File:
{
mLocationLabel->setText( tr( "File" ) );
locationLineEdit->setEnabled( true );
btnBrowse->setText( QStringLiteral( "Browse" ) );
break;
}
#if 0
case ImportSource::Official:
{
btnBrowse->setText( QStringLiteral( "Fetch Items" ) );
locationLineEdit->setEnabled( false );
break;
}
#endif
case ImportSource::Url:
{
mLocationLabel->setText( tr( "URL" ) );
btnBrowse->setText( QStringLiteral( "Fetch Items" ) );
locationLineEdit->setEnabled( true );
break;
}
}
}

void QgsStyleExportImportDialog::browse()
{
QString type = importTypeCombo->currentData().toString();
ImportSource source = static_cast< ImportSource >( importTypeCombo->currentData().toInt() );

if ( type == QLatin1String( "file" ) )
switch ( source )
{
mFileName = QFileDialog::getOpenFileName( this, tr( "Load Styles" ), QDir::homePath(),
tr( "XML files (*.xml *.XML)" ) );
if ( mFileName.isEmpty() )
case ImportSource::File:
{
return;
mFileName = QFileDialog::getOpenFileName( this, tr( "Load Styles" ), QDir::homePath(),
tr( "XML files (*.xml *.XML)" ) );
if ( mFileName.isEmpty() )
{
return;
}
QFileInfo pathInfo( mFileName );
QString tag = pathInfo.fileName().remove( QStringLiteral( ".xml" ) );
mSymbolTags->setText( tag );
locationLineEdit->setText( mFileName );
populateStyles( mTempStyle );
break;
}

#if 0
case ImportSource::Official:
{
// TODO set URL
// downloadStyleXML( QUrl( "http://...." ) );
break;
}
#endif

case ImportSource::Url:
{
downloadStyleXml( QUrl( locationLineEdit->text() ) );
break;
}
QFileInfo pathInfo( mFileName );
QString tag = pathInfo.fileName().remove( QStringLiteral( ".xml" ) );
mSymbolTags->setText( tag );
locationLineEdit->setText( mFileName );
populateStyles( mTempStyle );
}
else if ( type == QLatin1String( "official" ) )
{
// TODO set URL
// downloadStyleXML( QUrl( "http://...." ) );
}
else
{
downloadStyleXml( QUrl( locationLineEdit->text() ) );
}
}

Expand Down
8 changes: 8 additions & 0 deletions src/gui/symbology/qgsstyleexportimportdialog.h
Expand Up @@ -119,6 +119,14 @@ class GUI_EXPORT QgsStyleExportImportDialog : public QDialog, private Ui::QgsSty
void showHelp();

private:

enum ImportSource
{
File,
//Official,
Url,
};

void downloadStyleXml( const QUrl &url );
bool populateStyles( QgsStyle *style );
void moveStyles( QModelIndexList *selection, QgsStyle *src, QgsStyle *dst );
Expand Down
2 changes: 1 addition & 1 deletion src/ui/qgsstyleexportimportdialogbase.ui
Expand Up @@ -27,7 +27,7 @@
<widget class="QComboBox" name="importTypeCombo"/>
</item>
<item row="1" column="0">
<widget class="QLabel" name="locationLabel">
<widget class="QLabel" name="mLocationLabel">
<property name="text">
<string>Location</string>
</property>
Expand Down

0 comments on commit bf649e7

Please sign in to comment.