Skip to content
Permalink
Browse files

Use a QgsFileWidget in style import dialog

  • Loading branch information
nyalldawson committed Aug 31, 2018
1 parent bf649e7 commit fc8d90fc7d541c3cc0856498f32fbb778ee5c888
@@ -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" ) );
@@ -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 );
@@ -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
@@ -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 )
@@ -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();
@@ -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
@@ -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>
@@ -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>
@@ -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>

0 comments on commit fc8d90f

Please sign in to comment.
You can’t perform that action at this time.