Skip to content
Permalink
Browse files

[needs-docs] Use a QgsFileWidget for template file selector

Rename "Add" button to "Create"
  • Loading branch information
nyalldawson committed Dec 5, 2017
1 parent a30dd8a commit e5e37fcafa085ed7b08394a45d3e8e8424794bac
@@ -157,12 +157,12 @@ returns if the relative path is with respect to the project path or the default
determines if the relative path is with respect to the project path or the default path
%End

QLineEdit *lineEdit();
QgsFilterLineEdit *lineEdit();
%Docstring
Returns a pointer to the widget's line edit, which can be used to customize
the appearance and behavior of the line edit portion of the widget.
.. versionadded:: 3.0
:rtype: QLineEdit
:rtype: QgsFilterLineEdit
%End

signals:
@@ -41,11 +41,25 @@ QgsLayoutManagerDialog::QgsLayoutManagerDialog( QWidget *parent, Qt::WindowFlags
setupUi( this );
connect( mAddButton, &QPushButton::clicked, this, &QgsLayoutManagerDialog::mAddButton_clicked );
connect( mTemplate, static_cast<void ( QComboBox::* )( int )>( &QComboBox::currentIndexChanged ), this, &QgsLayoutManagerDialog::mTemplate_currentIndexChanged );
connect( mTemplatePathBtn, &QPushButton::pressed, this, &QgsLayoutManagerDialog::mTemplatePathBtn_pressed );
connect( mTemplatesDefaultDirBtn, &QPushButton::pressed, this, &QgsLayoutManagerDialog::mTemplatesDefaultDirBtn_pressed );
connect( mTemplatesUserDirBtn, &QPushButton::pressed, this, &QgsLayoutManagerDialog::mTemplatesUserDirBtn_pressed );

QgsGui::instance()->enableAutoGeometryRestore( this );
mTemplateFileWidget->setStorageMode( QgsFileWidget::GetFile );
mTemplateFileWidget->setFilter( tr( "Layout templates" ) + QStringLiteral( " (*.qpt *.QPT)" ) );
mTemplateFileWidget->setDialogTitle( tr( "Select a Template" ) );
mTemplateFileWidget->lineEdit()->setShowClearButton( false );
QgsSettings settings;
mTemplateFileWidget->setDefaultRoot( settings.value( QStringLiteral( "UI/lastComposerTemplateDir" ), QString() ).toString() );
mTemplateFileWidget->setFilePath( settings.value( QStringLiteral( "UI/ComposerManager/templatePath" ), QString() ).toString() );

connect( mTemplateFileWidget, &QgsFileWidget::fileChanged, this, [ = ]
{
QgsSettings settings;
settings.setValue( QStringLiteral( "UI/ComposerManager/templatePath" ), mTemplateFileWidget->filePath() );
QFileInfo tmplFileInfo( mTemplateFileWidget->filePath() );
settings.setValue( QStringLiteral( "UI/lastComposerTemplateDir" ), tmplFileInfo.absolutePath() );
} );

mModel = new QgsLayoutManagerModel( QgsProject::instance()->layoutManager(),
this );
@@ -85,9 +99,6 @@ QgsLayoutManagerDialog::QgsLayoutManagerDialog( QWidget *parent, Qt::WindowFlags
this->addTemplates( defaultTemplateMap );
this->addTemplates( this->otherTemplates() );

QgsSettings settings;
mTemplatePathLineEdit->setText( settings.value( QStringLiteral( "UI/ComposerManager/templatePath" ), QString() ).toString() );

toggleButtons();
}

@@ -193,7 +204,7 @@ void QgsLayoutManagerDialog::mAddButton_clicked()
{
if ( mTemplate->currentIndex() == 1 )
{
templateFile.setFileName( mTemplatePathLineEdit->text() );
templateFile.setFileName( mTemplateFileWidget->filePath() );
}
else
{
@@ -254,25 +265,7 @@ void QgsLayoutManagerDialog::mAddButton_clicked()
void QgsLayoutManagerDialog::mTemplate_currentIndexChanged( int indx )
{
bool specific = ( indx == 1 ); // comes just after empty template
mTemplatePathLineEdit->setEnabled( specific );
mTemplatePathBtn->setEnabled( specific );
}

void QgsLayoutManagerDialog::mTemplatePathBtn_pressed()
{
QgsSettings settings;
QString lastTmplDir = settings.value( QStringLiteral( "UI/lastComposerTemplateDir" ), QDir::homePath() ).toString();
QString tmplPath = QFileDialog::getOpenFileName( this,
tr( "Choose template" ),
lastTmplDir,
tr( "Layout templates" ) + QStringLiteral( " (*.qpt *.QPT)" ) );
if ( !tmplPath.isEmpty() )
{
mTemplatePathLineEdit->setText( tmplPath );
settings.setValue( QStringLiteral( "UI/ComposerManager/templatePath" ), tmplPath );
QFileInfo tmplFileInfo( tmplPath );
settings.setValue( QStringLiteral( "UI/lastComposerTemplateDir" ), tmplFileInfo.absolutePath() );
}
mTemplateFileWidget->setEnabled( specific );
}

void QgsLayoutManagerDialog::mTemplatesDefaultDirBtn_pressed()
@@ -107,8 +107,6 @@ class QgsLayoutManagerDialog: public QDialog, private Ui::QgsLayoutManagerBase
void mAddButton_clicked();
//! Slot to track combobox to use specific template path
void mTemplate_currentIndexChanged( int indx );
//! Slot to choose path to template
void mTemplatePathBtn_pressed();
//! Slot to open default templates dir with user's system
void mTemplatesDefaultDirBtn_pressed();
//! Slot to open user templates dir with user's system
@@ -210,7 +210,7 @@ void QgsFileWidget::setRelativeStorage( QgsFileWidget::RelativeStorage relativeS
mRelativeStorage = relativeStorage;
}

QLineEdit *QgsFileWidget::lineEdit()
QgsFilterLineEdit *QgsFileWidget::lineEdit()
{
return mLineEdit;
}
@@ -155,7 +155,7 @@ class GUI_EXPORT QgsFileWidget : public QWidget
* the appearance and behavior of the line edit portion of the widget.
* \since QGIS 3.0
*/
QLineEdit *lineEdit();
QgsFilterLineEdit *lineEdit();

signals:
//! emitted as soon as the current file or directory is changed
@@ -57,20 +57,14 @@
</sizepolicy>
</property>
<property name="text">
<string>Add</string>
<string>Create</string>
</property>
</widget>
</item>
<item row="0" column="0" colspan="2">
<widget class="QComboBox" name="mTemplate"/>
</item>
<item row="1" column="0">
<widget class="QLineEdit" name="mTemplatePathLineEdit"/>
</item>
<item row="1" column="1">
<widget class="QPushButton" name="mTemplatePathBtn">
<property name="text">
<string>…</string>
<item row="1" column="0" colspan="3">
<widget class="QgsFileWidget" name="mTemplateFileWidget" native="true">
<property name="focusPolicy">
<enum>Qt::StrongFocus</enum>
</property>
</widget>
</item>
@@ -98,7 +92,7 @@
</sizepolicy>
</property>
<property name="text">
<string>user</string>
<string>User</string>
</property>
</widget>
</item>
@@ -111,7 +105,7 @@
</sizepolicy>
</property>
<property name="text">
<string>default</string>
<string>Default</string>
</property>
</widget>
</item>
@@ -130,6 +124,9 @@
</item>
</layout>
</item>
<item row="0" column="0" colspan="2">
<widget class="QComboBox" name="mTemplate"/>
</item>
</layout>
</widget>
</item>
@@ -152,17 +149,21 @@
<header>qgscollapsiblegroupbox.h</header>
<container>1</container>
</customwidget>
<customwidget>
<class>QgsFileWidget</class>
<extends>QWidget</extends>
<header>qgsfilewidget.h</header>
<container>1</container>
</customwidget>
</customwidgets>
<tabstops>
<tabstop>mLayoutListView</tabstop>
<tabstop>mTemplateGrpBox</tabstop>
<tabstop>mTemplate</tabstop>
<tabstop>mAddButton</tabstop>
<tabstop>mTemplatePathLineEdit</tabstop>
<tabstop>mTemplatePathBtn</tabstop>
<tabstop>mTemplateFileWidget</tabstop>
<tabstop>mTemplatesUserDirBtn</tabstop>
<tabstop>mTemplatesDefaultDirBtn</tabstop>
<tabstop>mButtonBox</tabstop>
</tabstops>
<resources/>
<connections>

0 comments on commit e5e37fc

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