Skip to content

Commit

Permalink
Slight improvement in UI for saving to database table - add an
Browse files Browse the repository at this point in the history
explicit "OK" button next to new table name when shown inline in
processing panel, to make it clear to users how to "lock in"
the new table name
  • Loading branch information
nyalldawson committed Mar 26, 2020
1 parent 51a4a7d commit f131355
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 14 deletions.
11 changes: 11 additions & 0 deletions python/gui/auto_generated/qgsnewdatabasetablenamewidget.sip.in
Expand Up @@ -44,6 +44,13 @@ Constructs a new QgsNewDatabaseTableNameWidget
shown in the widget, if not specified all providers data items with database
capabilities will be shown
:param parent: optional parent for this widget
%End

void setAcceptButtonVisible( bool visible );
%Docstring
Sets whether the optional "Ok"/accept button should be visible.

By default this is hidden, to better allow the widget to be embedded inside other widgets and dialogs.
%End

QString schema() const;
Expand Down Expand Up @@ -121,6 +128,10 @@ This signal is emitted when the URI of the new table changes, whether or not it
:param uri: URI string representation
%End

void accepted();
%Docstring
Emitted when the OK/accept button is clicked.
%End

};

Expand Down
6 changes: 6 additions & 0 deletions src/gui/processing/qgsprocessingoutputdestinationwidget.cpp
Expand Up @@ -408,6 +408,7 @@ void QgsProcessingLayerOutputDestinationWidget::saveToDatabase()
<< QStringLiteral( "ogr" )
<< QStringLiteral( "spatialite" ), this );
widget->setPanelTitle( tr( "Save “%1” to Database Table" ).arg( mParameter->description() ) );
widget->setAcceptButtonVisible( true );

panel->openPanel( widget );

Expand Down Expand Up @@ -445,6 +446,11 @@ void QgsProcessingLayerOutputDestinationWidget::saveToDatabase()
connect( widget, &QgsNewDatabaseTableNameWidget::schemaNameChanged, this, [ = ] { changed(); } );
connect( widget, &QgsNewDatabaseTableNameWidget::validationChanged, this, [ = ] { changed(); } );
connect( widget, &QgsNewDatabaseTableNameWidget::providerKeyChanged, this, [ = ] { changed(); } );
connect( widget, &QgsNewDatabaseTableNameWidget::accepted, this, [ = ]
{
changed();
widget->acceptPanel();
} );
}
}

Expand Down
11 changes: 11 additions & 0 deletions src/gui/qgsnewdatabasetablenamewidget.cpp
Expand Up @@ -52,6 +52,9 @@ QgsNewDatabaseTableNameWidget::QgsNewDatabaseTableNameWidget(

setupUi( this );

mOkButton->hide();
mOkButton->setEnabled( false );

QStringList shownDataItemProvidersFilter;

const auto providerList { QgsApplication::dataItemProviderRegistry()->providers() };
Expand Down Expand Up @@ -150,9 +153,17 @@ QgsNewDatabaseTableNameWidget::QgsNewDatabaseTableNameWidget(
}
} );

connect( this, &QgsNewDatabaseTableNameWidget::validationChanged, mOkButton, &QWidget::setEnabled );
connect( mOkButton, &QPushButton::clicked, this, &QgsNewDatabaseTableNameWidget::accepted );

validate();
}

void QgsNewDatabaseTableNameWidget::setAcceptButtonVisible( bool visible )
{
mOkButton->setVisible( visible );
}

void QgsNewDatabaseTableNameWidget::refreshModel( const QModelIndex &index )
{

Expand Down
11 changes: 11 additions & 0 deletions src/gui/qgsnewdatabasetablenamewidget.h
Expand Up @@ -60,6 +60,13 @@ class GUI_EXPORT QgsNewDatabaseTableNameWidget : public QgsPanelWidget, private
const QStringList &providersFilter = QStringList(),
QWidget *parent = nullptr );

/**
* Sets whether the optional "Ok"/accept button should be visible.
*
* By default this is hidden, to better allow the widget to be embedded inside other widgets and dialogs.
*/
void setAcceptButtonVisible( bool visible );

/**
* Returns the currently selected schema or file path (in case of filesystem-based DBs like spatialite or GPKG) for the new table
*/
Expand Down Expand Up @@ -132,6 +139,10 @@ class GUI_EXPORT QgsNewDatabaseTableNameWidget : public QgsPanelWidget, private
*/
void uriChanged( const QString &uri );

/**
* Emitted when the OK/accept button is clicked.
*/
void accepted();

private:

Expand Down
35 changes: 21 additions & 14 deletions src/ui/qgsnewdatabasetablenamewidget.ui
Expand Up @@ -10,7 +10,7 @@
<height>629</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<layout class="QGridLayout" name="gridLayout">
<property name="leftMargin">
<number>0</number>
</property>
Expand All @@ -23,7 +23,24 @@
<property name="bottomMargin">
<number>4</number>
</property>
<item>
<item row="2" column="0">
<widget class="QLineEdit" name="mNewTableName">
<property name="text">
<string/>
</property>
<property name="placeholderText">
<string>name of the new table</string>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QPushButton" name="mOkButton">
<property name="text">
<string>Ok</string>
</property>
</widget>
</item>
<item row="0" column="0" colspan="2">
<layout class="QVBoxLayout" name="verticalLayout_2">
<property name="spacing">
<number>0</number>
Expand All @@ -50,24 +67,14 @@
</item>
</layout>
</item>
<item>
<item row="1" column="0" colspan="2">
<widget class="QLabel" name="label">
<property name="text">
<string>New table name</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="mNewTableName">
<property name="text">
<string/>
</property>
<property name="placeholderText">
<string>name of the new table</string>
</property>
</widget>
</item>
<item>
<item row="3" column="0" colspan="2">
<widget class="QLabel" name="mValidationResults">
<property name="enabled">
<bool>true</bool>
Expand Down

0 comments on commit f131355

Please sign in to comment.