Skip to content

Commit

Permalink
[needs-docs] Use a QgsFileWidget for template file selector
Browse files Browse the repository at this point in the history
Rename "Add" button to "Create"
  • Loading branch information
nyalldawson committed Dec 6, 2017
1 parent a30dd8a commit e5e37fc
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 46 deletions.
4 changes: 2 additions & 2 deletions python/gui/qgsfilewidget.sip
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -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 determines if the relative path is with respect to the project path or the default path
%End %End


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


signals: signals:
Expand Down
41 changes: 17 additions & 24 deletions src/app/layout/qgslayoutmanagerdialog.cpp
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -41,11 +41,25 @@ QgsLayoutManagerDialog::QgsLayoutManagerDialog( QWidget *parent, Qt::WindowFlags
setupUi( this ); setupUi( this );
connect( mAddButton, &QPushButton::clicked, this, &QgsLayoutManagerDialog::mAddButton_clicked ); connect( mAddButton, &QPushButton::clicked, this, &QgsLayoutManagerDialog::mAddButton_clicked );
connect( mTemplate, static_cast<void ( QComboBox::* )( int )>( &QComboBox::currentIndexChanged ), this, &QgsLayoutManagerDialog::mTemplate_currentIndexChanged ); 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( mTemplatesDefaultDirBtn, &QPushButton::pressed, this, &QgsLayoutManagerDialog::mTemplatesDefaultDirBtn_pressed );
connect( mTemplatesUserDirBtn, &QPushButton::pressed, this, &QgsLayoutManagerDialog::mTemplatesUserDirBtn_pressed ); connect( mTemplatesUserDirBtn, &QPushButton::pressed, this, &QgsLayoutManagerDialog::mTemplatesUserDirBtn_pressed );


QgsGui::instance()->enableAutoGeometryRestore( this ); 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(), mModel = new QgsLayoutManagerModel( QgsProject::instance()->layoutManager(),
this ); this );
Expand Down Expand Up @@ -85,9 +99,6 @@ QgsLayoutManagerDialog::QgsLayoutManagerDialog( QWidget *parent, Qt::WindowFlags
this->addTemplates( defaultTemplateMap ); this->addTemplates( defaultTemplateMap );
this->addTemplates( this->otherTemplates() ); this->addTemplates( this->otherTemplates() );


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

toggleButtons(); toggleButtons();
} }


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


void QgsLayoutManagerDialog::mTemplatesDefaultDirBtn_pressed() void QgsLayoutManagerDialog::mTemplatesDefaultDirBtn_pressed()
Expand Down
2 changes: 0 additions & 2 deletions src/app/layout/qgslayoutmanagerdialog.h
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -107,8 +107,6 @@ class QgsLayoutManagerDialog: public QDialog, private Ui::QgsLayoutManagerBase
void mAddButton_clicked(); void mAddButton_clicked();
//! Slot to track combobox to use specific template path //! Slot to track combobox to use specific template path
void mTemplate_currentIndexChanged( int indx ); void mTemplate_currentIndexChanged( int indx );
//! Slot to choose path to template
void mTemplatePathBtn_pressed();
//! Slot to open default templates dir with user's system //! Slot to open default templates dir with user's system
void mTemplatesDefaultDirBtn_pressed(); void mTemplatesDefaultDirBtn_pressed();
//! Slot to open user templates dir with user's system //! Slot to open user templates dir with user's system
Expand Down
2 changes: 1 addition & 1 deletion src/gui/qgsfilewidget.cpp
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ void QgsFileWidget::setRelativeStorage( QgsFileWidget::RelativeStorage relativeS
mRelativeStorage = relativeStorage; mRelativeStorage = relativeStorage;
} }


QLineEdit *QgsFileWidget::lineEdit() QgsFilterLineEdit *QgsFileWidget::lineEdit()
{ {
return mLineEdit; return mLineEdit;
} }
Expand Down
2 changes: 1 addition & 1 deletion src/gui/qgsfilewidget.h
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ class GUI_EXPORT QgsFileWidget : public QWidget
* the appearance and behavior of the line edit portion of the widget. * the appearance and behavior of the line edit portion of the widget.
* \since QGIS 3.0 * \since QGIS 3.0
*/ */
QLineEdit *lineEdit(); QgsFilterLineEdit *lineEdit();


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

0 comments on commit e5e37fc

Please sign in to comment.