Merge pull request #4592 from alexbruy/messagebars-for-db

Use QgsMessageBar instead of QMessageBoxes to show result of testing connection
This commit is contained in:
Alexander Bruy 2017-06-05 08:22:08 +03:00 committed by GitHub
commit 27850fb00e
8 changed files with 181 additions and 180 deletions

View File

@ -51,7 +51,6 @@ QgsDb2NewConnection::QgsDb2NewConnection( QWidget *parent, const QString &connNa
txtDriver->setText( settings.value( key + "/driver" ).toString() ); txtDriver->setText( settings.value( key + "/driver" ).toString() );
txtDatabase->setText( settings.value( key + "/database" ).toString() ); txtDatabase->setText( settings.value( key + "/database" ).toString() );
if ( settings.value( key + "/saveUsername" ).toString() == QLatin1String( "true" ) ) if ( settings.value( key + "/saveUsername" ).toString() == QLatin1String( "true" ) )
{ {
txtUsername->setText( settings.value( key + "/username" ).toString() ); txtUsername->setText( settings.value( key + "/username" ).toString() );
@ -131,7 +130,6 @@ void QgsDb2NewConnection::accept()
void QgsDb2NewConnection::on_btnConnect_clicked() void QgsDb2NewConnection::on_btnConnect_clicked()
{ {
QgsDebugMsg( "DB2: TestDatabase; button clicked" );
testConnection(); testConnection();
} }
@ -149,7 +147,6 @@ void QgsDb2NewConnection::on_cb_trustedConnection_clicked()
QgsDb2NewConnection::~QgsDb2NewConnection() QgsDb2NewConnection::~QgsDb2NewConnection()
{ {
} }
bool QgsDb2NewConnection::testConnection() bool QgsDb2NewConnection::testConnection()
@ -172,7 +169,8 @@ bool QgsDb2NewConnection::testConnection()
if ( !rc ) if ( !rc )
{ {
db2ConnectStatus -> setText( errMsg ); bar->pushMessage( tr( "Error: %1." ).arg( errMsg ),
QgsMessageBar::WARNING );
QgsDebugMsg( "errMsg: " + errMsg ); QgsDebugMsg( "errMsg: " + errMsg );
return false; return false;
} }
@ -181,18 +179,19 @@ bool QgsDb2NewConnection::testConnection()
if ( errMsg.isEmpty() ) if ( errMsg.isEmpty() )
{ {
QgsDebugMsg( "connection open succeeded " + connInfo ); QgsDebugMsg( "connection open succeeded " + connInfo );
db2ConnectStatus -> setText( QStringLiteral( "DB2 connection open succeeded" ) ); bar->pushMessage( tr( "Connection to %1 was successful" ).arg( txtDatabase->text() ),
QgsMessageBar::INFO );
return true; return true;
} }
else else
{ {
QgsDebugMsg( "connection open failed: " + errMsg ); QgsDebugMsg( "connection open failed: " + errMsg );
db2ConnectStatus -> setText( "DB2 connection failed : " + errMsg ); bar->pushMessage( tr( "Connection failed: %1." ).arg( errMsg ),
QgsMessageBar::WARNING );
return false; return false;
} }
} }
void QgsDb2NewConnection::listDatabases() void QgsDb2NewConnection::listDatabases()
{ {
QgsDebugMsg( "DB2 New Connection Dialogue : list database" );
} }

View File

@ -145,7 +145,6 @@ void QgsMssqlNewConnection::on_cb_trustedConnection_clicked()
QgsMssqlNewConnection::~QgsMssqlNewConnection() QgsMssqlNewConnection::~QgsMssqlNewConnection()
{ {
delete bar;
} }
bool QgsMssqlNewConnection::testConnection( const QString &testDatabase ) bool QgsMssqlNewConnection::testConnection( const QString &testDatabase )

View File

@ -152,18 +152,15 @@ void QgsOracleNewConnection::on_btnConnect_clicked()
if ( conn ) if ( conn )
{ {
// Database successfully opened; we can now issue SQL commands. // Database successfully opened; we can now issue SQL commands.
QMessageBox::information( this, bar->pushMessage( tr( "Connection to %1 was successful" ).arg( txtDatabase->text() ),
tr( "Test connection" ), QgsMessageBar::INFO );
tr( "Connection to %1 was successful" ).arg( txtDatabase->text() ) );
// free connection resources // free connection resources
QgsOracleConnPool::instance()->releaseConnection( conn ); QgsOracleConnPool::instance()->releaseConnection( conn );
} }
else else
{ {
QMessageBox::information( this, bar->pushMessage( tr( "Connection failed - consult message log for details." ),
tr( "Test connection" ), QgsMessageBar::WARNING );
tr( "Connection failed - consult message log for details.\n\n" ) );
} }
} }

View File

@ -105,6 +105,12 @@ QgsPgNewConnection::QgsPgNewConnection( QWidget *parent, const QString &connName
txtName->setValidator( new QRegExpValidator( QRegExp( "[^\\/]+" ), txtName ) ); txtName->setValidator( new QRegExpValidator( QRegExp( "[^\\/]+" ), txtName ) );
} }
} }
QgsPgNewConnection::~QgsPgNewConnection()
{
}
//! Autoconnected SLOTS * //! Autoconnected SLOTS *
void QgsPgNewConnection::accept() void QgsPgNewConnection::accept()
{ {
@ -202,17 +208,15 @@ void QgsPgNewConnection::testConnection()
if ( conn ) if ( conn )
{ {
// Database successfully opened; we can now issue SQL commands. // Database successfully opened; we can now issue SQL commands.
QMessageBox::information( this, bar->pushMessage( tr( "Connection to %1 was successful" ).arg( txtDatabase->text() ),
tr( "Test connection" ), QgsMessageBar::INFO );
tr( "Connection to %1 was successful" ).arg( txtDatabase->text() ) );
// free pg connection resources // free pg connection resources
conn->unref(); conn->unref();
} }
else else
{ {
QMessageBox::information( this, bar->pushMessage( tr( "Connection failed - consult message log for details." ),
tr( "Test connection" ), QgsMessageBar::WARNING );
tr( "Connection failed - consult message log for details.\n\n" ) );
} }
} }

View File

@ -32,6 +32,8 @@ class QgsPgNewConnection : public QDialog, private Ui::QgsPgNewConnectionBase
//! Constructor //! Constructor
QgsPgNewConnection( QWidget *parent = nullptr, const QString &connName = QString::null, Qt::WindowFlags fl = QgsGuiUtils::ModalDialogFlags ); QgsPgNewConnection( QWidget *parent = nullptr, const QString &connName = QString::null, Qt::WindowFlags fl = QgsGuiUtils::ModalDialogFlags );
~QgsPgNewConnection();
//! Tests the connection using the parameters supplied //! Tests the connection using the parameters supplied
void testConnection(); void testConnection();
public slots: public slots:

View File

@ -15,23 +15,6 @@
</property> </property>
<layout class="QGridLayout" name="gridLayout_3"> <layout class="QGridLayout" name="gridLayout_3">
<item row="1" column="0"> <item row="1" column="0">
<widget class="QLabel" name="db2ConnectStatus">
<property name="text">
<string>DB2 Connect Status: </string>
</property>
</widget>
</item>
<item row="3" column="0">
<widget class="QDialogButtonBox" name="buttonBox">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QGroupBox" name="groupBox"> <widget class="QGroupBox" name="groupBox">
<property name="title"> <property name="title">
<string>Connection Information</string> <string>Connection Information</string>
@ -196,6 +179,19 @@
</property> </property>
</spacer> </spacer>
</item> </item>
<item row="3" column="0">
<widget class="QDialogButtonBox" name="buttonBox">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QgsMessageBar" name="bar" native="true"/>
</item>
</layout> </layout>
</widget> </widget>
<customwidgets> <customwidgets>
@ -204,6 +200,12 @@
<extends>QLineEdit</extends> <extends>QLineEdit</extends>
<header>qgspasswordlineedit.h</header> <header>qgspasswordlineedit.h</header>
</customwidget> </customwidget>
<customwidget>
<class>QgsMessageBar</class>
<extends>QWidget</extends>
<header>qgsmessagebar.h</header>
<container>1</container>
</customwidget>
</customwidgets> </customwidgets>
<tabstops> <tabstops>
<tabstop>txtName</tabstop> <tabstop>txtName</tabstop>

View File

@ -7,7 +7,7 @@
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>400</width> <width>400</width>
<height>513</height> <height>529</height>
</rect> </rect>
</property> </property>
<property name="sizePolicy"> <property name="sizePolicy">
@ -41,14 +41,14 @@
<property name="spacing"> <property name="spacing">
<number>6</number> <number>6</number>
</property> </property>
<item row="1" column="0"> <item row="2" column="0">
<widget class="QDialogButtonBox" name="buttonBox"> <widget class="QDialogButtonBox" name="buttonBox">
<property name="standardButtons"> <property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Help|QDialogButtonBox::Ok</set> <set>QDialogButtonBox::Cancel|QDialogButtonBox::Help|QDialogButtonBox::Ok</set>
</property> </property>
</widget> </widget>
</item> </item>
<item row="0" column="0"> <item row="1" column="0">
<widget class="QGroupBox" name="GroupBox1"> <widget class="QGroupBox" name="GroupBox1">
<property name="title"> <property name="title">
<string>Connection Information</string> <string>Connection Information</string>
@ -277,6 +277,9 @@
</layout> </layout>
</widget> </widget>
</item> </item>
<item row="0" column="0">
<widget class="QgsMessageBar" name="bar" native="true"/>
</item>
</layout> </layout>
</widget> </widget>
<layoutdefault spacing="6" margin="11"/> <layoutdefault spacing="6" margin="11"/>
@ -286,6 +289,12 @@
<extends>QLineEdit</extends> <extends>QLineEdit</extends>
<header>qgspasswordlineedit.h</header> <header>qgspasswordlineedit.h</header>
</customwidget> </customwidget>
<customwidget>
<class>QgsMessageBar</class>
<extends>QWidget</extends>
<header>qgsmessagebar.h</header>
<container>1</container>
</customwidget>
</customwidgets> </customwidgets>
<tabstops> <tabstops>
<tabstop>txtName</tabstop> <tabstop>txtName</tabstop>

View File

@ -26,32 +26,110 @@
<bool>true</bool> <bool>true</bool>
</property> </property>
<layout class="QGridLayout" name="gridLayout3"> <layout class="QGridLayout" name="gridLayout3">
<item row="1" column="0"> <item row="2" column="0">
<widget class="QDialogButtonBox" name="buttonBox"> <widget class="QDialogButtonBox" name="buttonBox">
<property name="standardButtons"> <property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Help|QDialogButtonBox::Ok</set> <set>QDialogButtonBox::Cancel|QDialogButtonBox::Help|QDialogButtonBox::Ok</set>
</property> </property>
</widget> </widget>
</item> </item>
<item row="0" column="0"> <item row="1" column="0">
<widget class="QGroupBox" name="GroupBox1"> <widget class="QGroupBox" name="GroupBox1">
<property name="title"> <property name="title">
<string>Connection Information</string> <string>Connection Information</string>
</property> </property>
<layout class="QGridLayout" name="gridLayout2"> <layout class="QVBoxLayout" name="verticalLayout">
<property name="leftMargin"> <item>
<number>5</number> <layout class="QGridLayout" name="gridLayout_2">
<item row="0" column="0">
<widget class="QLabel" name="TextLabel1_2">
<property name="text">
<string>Name</string>
</property> </property>
<property name="rightMargin"> <property name="buddy">
<number>5</number> <cstring>txtName</cstring>
</property> </property>
<property name="bottomMargin"> </widget>
<number>0</number> </item>
</property> <item row="0" column="1">
<property name="horizontalSpacing"> <widget class="QLineEdit" name="txtName">
<number>5</number> <property name="toolTip">
<string>Name of the new connection</string>
</property> </property>
</widget>
</item>
<item row="1" column="0"> <item row="1" column="0">
<widget class="QLabel" name="label">
<property name="text">
<string>Service</string>
</property>
<property name="buddy">
<cstring>txtService</cstring>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QLineEdit" name="txtService"/>
</item>
<item row="2" column="0">
<widget class="QLabel" name="TextLabel1">
<property name="text">
<string>Host</string>
</property>
<property name="buddy">
<cstring>txtHost</cstring>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QLineEdit" name="txtHost"/>
</item>
<item row="3" column="0">
<widget class="QLabel" name="TextLabel2_2">
<property name="text">
<string>Port</string>
</property>
<property name="buddy">
<cstring>txtPort</cstring>
</property>
</widget>
</item>
<item row="3" column="1">
<widget class="QLineEdit" name="txtPort">
<property name="text">
<string>5432</string>
</property>
</widget>
</item>
<item row="4" column="0">
<widget class="QLabel" name="TextLabel2">
<property name="text">
<string>Database</string>
</property>
<property name="buddy">
<cstring>txtDatabase</cstring>
</property>
</widget>
</item>
<item row="4" column="1">
<widget class="QLineEdit" name="txtDatabase"/>
</item>
<item row="5" column="0">
<widget class="QLabel" name="TextLabel3_3">
<property name="text">
<string>SSL mode</string>
</property>
<property name="buddy">
<cstring>cbxSSLmode</cstring>
</property>
</widget>
</item>
<item row="5" column="1">
<widget class="QComboBox" name="cbxSSLmode"/>
</item>
</layout>
</item>
<item>
<widget class="QTabWidget" name="tabAuthentication"> <widget class="QTabWidget" name="tabAuthentication">
<property name="sizePolicy"> <property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Maximum"> <sizepolicy hsizetype="Expanding" vsizetype="Maximum">
@ -127,7 +205,14 @@
</widget> </widget>
</widget> </widget>
</item> </item>
<item row="3" column="0"> <item>
<widget class="QPushButton" name="btnConnect">
<property name="text">
<string>&amp;Test Connection</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="cb_geometryColumnsOnly"> <widget class="QCheckBox" name="cb_geometryColumnsOnly">
<property name="toolTip"> <property name="toolTip">
<string>Restrict the displayed tables to those that are in the layer registries.</string> <string>Restrict the displayed tables to those that are in the layer registries.</string>
@ -140,112 +225,27 @@
</property> </property>
</widget> </widget>
</item> </item>
<item row="0" column="0">
<layout class="QHBoxLayout">
<item> <item>
<layout class="QVBoxLayout">
<item>
<widget class="QLabel" name="TextLabel1_2">
<property name="text">
<string>Name</string>
</property>
<property name="buddy">
<cstring>txtName</cstring>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="label">
<property name="text">
<string>Service</string>
</property>
<property name="buddy">
<cstring>txtService</cstring>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="TextLabel1">
<property name="text">
<string>Host</string>
</property>
<property name="buddy">
<cstring>txtHost</cstring>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="TextLabel2_2">
<property name="text">
<string>Port</string>
</property>
<property name="buddy">
<cstring>txtPort</cstring>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="TextLabel2">
<property name="text">
<string>Database</string>
</property>
<property name="buddy">
<cstring>txtDatabase</cstring>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="TextLabel3_3">
<property name="text">
<string>SSL mode</string>
</property>
<property name="buddy">
<cstring>cbxSSLmode</cstring>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QVBoxLayout">
<item>
<widget class="QLineEdit" name="txtName">
<property name="toolTip">
<string>Name of the new connection</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="txtService"/>
</item>
<item>
<widget class="QLineEdit" name="txtHost"/>
</item>
<item>
<widget class="QLineEdit" name="txtPort">
<property name="text">
<string>5432</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="txtDatabase"/>
</item>
<item>
<widget class="QComboBox" name="cbxSSLmode"/>
</item>
</layout>
</item>
</layout>
</item>
<item row="4" column="0">
<widget class="QCheckBox" name="cb_dontResolveType"> <widget class="QCheckBox" name="cb_dontResolveType">
<property name="text"> <property name="text">
<string>Don't resolve type of unrestricted columns (GEOMETRY)</string> <string>Don't resolve type of unrestricted columns (GEOMETRY)</string>
</property> </property>
</widget> </widget>
</item> </item>
<item row="6" column="0"> <item>
<widget class="QCheckBox" name="cb_publicSchemaOnly">
<property name="toolTip">
<string>Restrict the search to the public schema for spatial tables not in the geometry_columns table</string>
</property>
<property name="whatsThis">
<string>When searching for spatial tables that are not in the geometry_columns tables, restrict the search to tables that are in the public schema (for some databases this can save lots of time)</string>
</property>
<property name="text">
<string>Only look in the 'public' schema</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="cb_allowGeometrylessTables"> <widget class="QCheckBox" name="cb_allowGeometrylessTables">
<property name="text"> <property name="text">
<string>Also list tables with no geometry</string> <string>Also list tables with no geometry</string>
@ -255,7 +255,7 @@
</property> </property>
</widget> </widget>
</item> </item>
<item row="7" column="0"> <item>
<widget class="QCheckBox" name="cb_useEstimatedMetadata"> <widget class="QCheckBox" name="cb_useEstimatedMetadata">
<property name="toolTip"> <property name="toolTip">
<string>Use estimated table statistics for the layer metadata.</string> <string>Use estimated table statistics for the layer metadata.</string>
@ -276,27 +276,7 @@
</property> </property>
</widget> </widget>
</item> </item>
<item row="2" column="0"> <item>
<widget class="QPushButton" name="btnConnect">
<property name="text">
<string>&amp;Test Connection</string>
</property>
</widget>
</item>
<item row="5" column="0">
<widget class="QCheckBox" name="cb_publicSchemaOnly">
<property name="toolTip">
<string>Restrict the search to the public schema for spatial tables not in the geometry_columns table</string>
</property>
<property name="whatsThis">
<string>When searching for spatial tables that are not in the geometry_columns tables, restrict the search to tables that are in the public schema (for some databases this can save lots of time)</string>
</property>
<property name="text">
<string>Only look in the 'public' schema</string>
</property>
</widget>
</item>
<item row="8" column="0">
<spacer name="verticalSpacer"> <spacer name="verticalSpacer">
<property name="orientation"> <property name="orientation">
<enum>Qt::Vertical</enum> <enum>Qt::Vertical</enum>
@ -312,6 +292,9 @@
</layout> </layout>
</widget> </widget>
</item> </item>
<item row="0" column="0">
<widget class="QgsMessageBar" name="bar" native="true"/>
</item>
</layout> </layout>
</widget> </widget>
<layoutdefault spacing="6" margin="11"/> <layoutdefault spacing="6" margin="11"/>
@ -321,6 +304,12 @@
<extends>QLineEdit</extends> <extends>QLineEdit</extends>
<header>qgspasswordlineedit.h</header> <header>qgspasswordlineedit.h</header>
</customwidget> </customwidget>
<customwidget>
<class>QgsMessageBar</class>
<extends>QWidget</extends>
<header>qgsmessagebar.h</header>
<container>1</container>
</customwidget>
</customwidgets> </customwidgets>
<tabstops> <tabstops>
<tabstop>txtName</tabstop> <tabstop>txtName</tabstop>