Skip to content

Commit

Permalink
Use a QgsFileWidget in style import dialog
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Aug 31, 2018
1 parent bf649e7 commit fc8d90f
Show file tree
Hide file tree
Showing 3 changed files with 109 additions and 81 deletions.
66 changes: 22 additions & 44 deletions src/gui/symbology/qgsstyleexportimportdialog.cpp
Expand Up @@ -79,8 +79,12 @@ QgsStyleExportImportDialog::QgsStyleExportImportDialog( QgsStyle *style, QWidget

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

btnBrowse->setText( QStringLiteral( "Browse" ) );
connect( btnBrowse, &QAbstractButton::clicked, this, &QgsStyleExportImportDialog::browse );
connect( mButtonFetch, &QAbstractButton::clicked, this, &QgsStyleExportImportDialog::fetch );

mImportFileWidget->setStorageMode( QgsFileWidget::GetFile );
mImportFileWidget->setDialogTitle( tr( "Load Styles" ) );
mImportFileWidget->setFilter( tr( "XML files (*.xml *.XML)" ) );
connect( mImportFileWidget, &QgsFileWidget::fileChanged, this, &QgsStyleExportImportDialog::importFileChanged );

label->setText( tr( "Select items to import" ) );
buttonBox->button( QDialogButtonBox::Ok )->setText( tr( "Import" ) );
Expand All @@ -89,11 +93,10 @@ QgsStyleExportImportDialog::QgsStyleExportImportDialog( QgsStyle *style, QWidget
{
setWindowTitle( tr( "Export Item(s)" ) );
// hide import specific controls when exporting
btnBrowse->setHidden( true );
mLocationStackedEdit->setHidden( true );
fromLabel->setHidden( true );
importTypeCombo->setHidden( true );
mLocationLabel->setHidden( true );
locationLineEdit->setHidden( true );

mFavorite->setHidden( true );
mIgnoreXMLTags->setHidden( true );
Expand Down Expand Up @@ -482,15 +485,12 @@ void QgsStyleExportImportDialog::importTypeChanged( int index )
{
ImportSource source = static_cast< ImportSource >( importTypeCombo->itemData( index ).toInt() );

locationLineEdit->clear();

switch ( source )
{
case ImportSource::File:
{
mLocationStackedEdit->setCurrentIndex( 0 );
mLocationLabel->setText( tr( "File" ) );
locationLineEdit->setEnabled( true );
btnBrowse->setText( QStringLiteral( "Browse" ) );
break;
}
#if 0
Expand All @@ -503,51 +503,29 @@ void QgsStyleExportImportDialog::importTypeChanged( int index )
#endif
case ImportSource::Url:
{
mLocationStackedEdit->setCurrentIndex( 1 );
mLocationLabel->setText( tr( "URL" ) );
btnBrowse->setText( QStringLiteral( "Fetch Items" ) );
locationLineEdit->setEnabled( true );
break;
}
}
}

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

switch ( source )
{
case ImportSource::File:
{
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;
}
downloadStyleXml( QUrl( mUrlLineEdit->text() ) );
}

#if 0
case ImportSource::Official:
{
// TODO set URL
// downloadStyleXML( QUrl( "http://...." ) );
break;
}
#endif
void QgsStyleExportImportDialog::importFileChanged( const QString &path )
{
if ( path.isEmpty() )
return;

case ImportSource::Url:
{
downloadStyleXml( QUrl( locationLineEdit->text() ) );
break;
}
}
mFileName = path;
QFileInfo pathInfo( mFileName );
QString tag = pathInfo.fileName().remove( QStringLiteral( ".xml" ) );
mSymbolTags->setText( tag );
if ( QFileInfo::exists( mFileName ) )
populateStyles( mTempStyle );
}

void QgsStyleExportImportDialog::downloadStyleXml( const QUrl &url )
Expand Down
4 changes: 3 additions & 1 deletion src/gui/symbology/qgsstyleexportimportdialog.h
Expand Up @@ -108,7 +108,6 @@ class GUI_EXPORT QgsStyleExportImportDialog : public QDialog, private Ui::QgsSty
void deselectSmartgroup( const QString &groupName );

void importTypeChanged( int );
void browse();

private slots:
void httpFinished();
Expand All @@ -118,6 +117,9 @@ class GUI_EXPORT QgsStyleExportImportDialog : public QDialog, private Ui::QgsSty
void selectionChanged( const QItemSelection &selected, const QItemSelection &deselected );
void showHelp();

void fetch();
void importFileChanged( const QString &path );

private:

enum ImportSource
Expand Down
120 changes: 84 additions & 36 deletions src/ui/qgsstyleexportimportdialogbase.ui
Expand Up @@ -16,37 +16,40 @@
<layout class="QGridLayout" name="gridLayout_2">
<item row="0" column="0">
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0">
<widget class="QLabel" name="fromLabel">
<item row="4" column="1" colspan="2">
<widget class="QLineEdit" name="mSymbolTags"/>
</item>
<item row="3" column="0" colspan="3">
<widget class="QCheckBox" name="mIgnoreXMLTags">
<property name="sizePolicy">
<sizepolicy hsizetype="Maximum" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Import from</string>
<string>Do not import embedded tags</string>
</property>
</widget>
</item>
<item row="0" column="1" colspan="2">
<widget class="QComboBox" name="importTypeCombo"/>
</item>
<item row="1" column="0">
<widget class="QLabel" name="mLocationLabel">
<item row="5" column="1" colspan="2">
<widget class="QLabel" name="tagHintLabel">
<property name="text">
<string>Location</string>
<string>Tip: separate multiple tags with commas</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QLineEdit" name="locationLineEdit"/>
</item>
<item row="1" column="2">
<widget class="QPushButton" name="btnBrowse">
<item row="0" column="0">
<widget class="QLabel" name="fromLabel">
<property name="text">
<string/>
<string>Import from</string>
</property>
</widget>
</item>
<item row="4" column="0">
<widget class="QLabel" name="tagLabel">
<item row="1" column="0">
<widget class="QLabel" name="mLocationLabel">
<property name="text">
<string>Additional tag(s)</string>
<string>Location</string>
</property>
</widget>
</item>
Expand All @@ -63,27 +66,66 @@
</property>
</widget>
</item>
<item row="3" column="0" colspan="3">
<widget class="QCheckBox" name="mIgnoreXMLTags">
<property name="sizePolicy">
<sizepolicy hsizetype="Maximum" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<item row="0" column="1" colspan="2">
<widget class="QComboBox" name="importTypeCombo"/>
</item>
<item row="4" column="0">
<widget class="QLabel" name="tagLabel">
<property name="text">
<string>Do not import embedded tags</string>
<string>Additional tag(s)</string>
</property>
</widget>
</item>
<item row="4" column="1" colspan="2">
<widget class="QLineEdit" name="mSymbolTags"/>
</item>
<item row="5" column="1" colspan="2">
<widget class="QLabel" name="tagHintLabel">
<property name="text">
<string>Tip: separate multiple tags with commas</string>
<item row="1" column="1" colspan="2">
<widget class="QStackedWidget" name="mLocationStackedEdit">
<property name="currentIndex">
<number>0</number>
</property>
<widget class="QWidget" name="widget">
<layout class="QHBoxLayout" name="horizontalLayout_2">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<widget class="QgsFileWidget" name="mImportFileWidget" native="true"/>
</item>
</layout>
</widget>
<widget class="QWidget" name="page">
<layout class="QHBoxLayout" name="horizontalLayout" stretch="1,0">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<widget class="QLineEdit" name="mUrlLineEdit"/>
</item>
<item>
<widget class="QPushButton" name="mButtonFetch">
<property name="text">
<string>Fetch Items</string>
</property>
</widget>
</item>
</layout>
</widget>
</widget>
</item>
</layout>
Expand Down Expand Up @@ -150,10 +192,16 @@
</item>
</layout>
</widget>
<customwidgets>
<customwidget>
<class>QgsFileWidget</class>
<extends>QWidget</extends>
<header>qgsfilewidget.h</header>
<container>1</container>
</customwidget>
</customwidgets>
<tabstops>
<tabstop>importTypeCombo</tabstop>
<tabstop>locationLineEdit</tabstop>
<tabstop>btnBrowse</tabstop>
<tabstop>mFavorite</tabstop>
<tabstop>mIgnoreXMLTags</tabstop>
<tabstop>mSymbolTags</tabstop>
Expand Down

0 comments on commit fc8d90f

Please sign in to comment.