Skip to content

Commit

Permalink
check/uncheck all MSSQL schemas (backport #42678)
Browse files Browse the repository at this point in the history
  • Loading branch information
vcloarec authored and nyalldawson committed Apr 26, 2021
1 parent 8f0e606 commit 44d7dfa
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 23 deletions.
32 changes: 32 additions & 0 deletions src/providers/mssql/qgsmssqlnewconnection.cpp
Expand Up @@ -20,6 +20,7 @@
#include <QSqlDatabase>
#include <QSqlError>
#include <QRegExpValidator>
#include <QMenu>

#include "qgsmssqlnewconnection.h"
#include "qgsmssqlprovider.h"
Expand Down Expand Up @@ -95,6 +96,24 @@ QgsMssqlNewConnection::QgsMssqlNewConnection( QWidget *parent, const QString &co
cb_trustedConnection_clicked();

schemaView->setModel( &mSchemaModel );
schemaView->setContextMenuPolicy( Qt::CustomContextMenu );

connect( schemaView, &QWidget::customContextMenuRequested, this, [this]( const QPoint & p )
{
QMenu menu;
menu.addAction( tr( "Check All" ), this, [this]
{
mSchemaModel.checkAll();
} );

menu.addAction( tr( "Uncheck All" ), this, [this]
{
mSchemaModel.unCheckAll();
} );

menu.exec( this->schemaView->viewport()->mapToGlobal( p ) );
}
);
onCurrentDataBaseChange();

groupBoxSchemasFilter->setCollapsed( !groupBoxSchemasFilter->isChecked() );
Expand Down Expand Up @@ -353,6 +372,7 @@ void QgsMssqlNewConnection::onPrimaryKeyFromGeometryToggled( bool checked )
bar->pushInfo( tr( "Use primary key(s) from geometry_columns table" ), tr( "Primary key column found." ) );
}


bool QgsMssqlNewConnection::testExtentInGeometryColumns() const
{
QSqlDatabase db = getDatabase();
Expand Down Expand Up @@ -468,3 +488,15 @@ void QgsMssqlNewConnection::SchemaModel::setSettings( const QString &database, c
mExcludedSchemas = excludedSchemas;
endResetModel();
}

void QgsMssqlNewConnection::SchemaModel::checkAll()
{
mExcludedSchemas.clear();
emit dataChanged( index( 0, 0, QModelIndex() ), index( mSchemas.count() - 1, 0, QModelIndex() ) );
}

void QgsMssqlNewConnection::SchemaModel::unCheckAll()
{
mExcludedSchemas = mSchemas;
emit dataChanged( index( 0, 0, QModelIndex() ), index( mSchemas.count() - 1, 0, QModelIndex() ) );
}
6 changes: 6 additions & 0 deletions src/providers/mssql/qgsmssqlnewconnection.h
Expand Up @@ -80,6 +80,12 @@ class QgsMssqlNewConnection : public QDialog, private Ui::QgsMssqlNewConnectionB
//! Sets the settings for \a database
void setSettings( const QString &database, const QStringList &schemas, const QStringList &excludedSchemas );

//! Checks all schemas
void checkAll();

//! Unchecks all schemas
void unCheckAll();

private:
QString mDataBaseName;
QStringList mSchemas;
Expand Down
33 changes: 10 additions & 23 deletions src/ui/qgsmssqlnewconnectionbase.ui
Expand Up @@ -6,8 +6,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>810</width>
<height>765</height>
<width>800</width>
<height>755</height>
</rect>
</property>
<property name="sizePolicy">
Expand Down Expand Up @@ -265,6 +265,13 @@ Untick save if you don't wish to be the case.</string>
</layout>
</widget>
</item>
<item row="3" column="0" colspan="2">
<widget class="QCheckBox" name="checkBoxPKFromGeometryColumns">
<property name="text">
<string>Use primary key from geometry_columns table</string>
</property>
</widget>
</item>
<item row="4" column="0" colspan="2">
<widget class="QCheckBox" name="cb_allowGeometrylessTables">
<property name="toolTip">
Expand Down Expand Up @@ -302,19 +309,6 @@ Untick save if you don't wish to be the case.</string>
</widget>
</item>
<item row="8" column="0" colspan="2">
<widget class="Line" name="line">
<property name="minimumSize">
<size>
<width>0</width>
<height>0</height>
</size>
</property>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
<item row="9" column="0" colspan="2">
<widget class="QgsCollapsibleGroupBoxBasic" name="groupBoxSchemasFilter">
<property name="title">
<string>Use Only a Subset of Schemas</string>
Expand Down Expand Up @@ -347,20 +341,13 @@ Untick save if you don't wish to be the case.</string>
</layout>
</widget>
</item>
<item row="10" column="0" colspan="2">
<item row="9" column="0" colspan="2">
<widget class="QPushButton" name="btnConnect">
<property name="text">
<string>Test Connection</string>
</property>
</widget>
</item>
<item row="3" column="0" colspan="2">
<widget class="QCheckBox" name="checkBoxPKFromGeometryColumns">
<property name="text">
<string>Use primary key from geometry_columns table</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
Expand Down

0 comments on commit 44d7dfa

Please sign in to comment.