Skip to content

Commit

Permalink
Merge pull request #4592 from alexbruy/messagebars-for-db
Browse files Browse the repository at this point in the history
Use QgsMessageBar instead of QMessageBoxes to show result of testing connection
  • Loading branch information
alexbruy authored Jun 5, 2017
2 parents f69d1c2 + 2c5e52b commit 27850fb
Show file tree
Hide file tree
Showing 8 changed files with 181 additions and 180 deletions.
13 changes: 6 additions & 7 deletions src/providers/db2/qgsdb2newconnection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ QgsDb2NewConnection::QgsDb2NewConnection( QWidget *parent, const QString &connNa
txtDriver->setText( settings.value( key + "/driver" ).toString() );
txtDatabase->setText( settings.value( key + "/database" ).toString() );


if ( settings.value( key + "/saveUsername" ).toString() == QLatin1String( "true" ) )
{
txtUsername->setText( settings.value( key + "/username" ).toString() );
Expand Down Expand Up @@ -131,7 +130,6 @@ void QgsDb2NewConnection::accept()

void QgsDb2NewConnection::on_btnConnect_clicked()
{
QgsDebugMsg( "DB2: TestDatabase; button clicked" );
testConnection();
}

Expand All @@ -149,7 +147,6 @@ void QgsDb2NewConnection::on_cb_trustedConnection_clicked()

QgsDb2NewConnection::~QgsDb2NewConnection()
{

}

bool QgsDb2NewConnection::testConnection()
Expand All @@ -172,7 +169,8 @@ bool QgsDb2NewConnection::testConnection()

if ( !rc )
{
db2ConnectStatus -> setText( errMsg );
bar->pushMessage( tr( "Error: %1." ).arg( errMsg ),
QgsMessageBar::WARNING );
QgsDebugMsg( "errMsg: " + errMsg );
return false;
}
Expand All @@ -181,18 +179,19 @@ bool QgsDb2NewConnection::testConnection()
if ( errMsg.isEmpty() )
{
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;
}
else
{
QgsDebugMsg( "connection open failed: " + errMsg );
db2ConnectStatus -> setText( "DB2 connection failed : " + errMsg );
bar->pushMessage( tr( "Connection failed: %1." ).arg( errMsg ),
QgsMessageBar::WARNING );
return false;
}
}

void QgsDb2NewConnection::listDatabases()
{
QgsDebugMsg( "DB2 New Connection Dialogue : list database" );
}
1 change: 0 additions & 1 deletion src/providers/mssql/qgsmssqlnewconnection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,6 @@ void QgsMssqlNewConnection::on_cb_trustedConnection_clicked()

QgsMssqlNewConnection::~QgsMssqlNewConnection()
{
delete bar;
}

bool QgsMssqlNewConnection::testConnection( const QString &testDatabase )
Expand Down
11 changes: 4 additions & 7 deletions src/providers/oracle/qgsoraclenewconnection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -152,18 +152,15 @@ void QgsOracleNewConnection::on_btnConnect_clicked()
if ( conn )
{
// Database successfully opened; we can now issue SQL commands.
QMessageBox::information( this,
tr( "Test connection" ),
tr( "Connection to %1 was successful" ).arg( txtDatabase->text() ) );

bar->pushMessage( tr( "Connection to %1 was successful" ).arg( txtDatabase->text() ),
QgsMessageBar::INFO );
// free connection resources
QgsOracleConnPool::instance()->releaseConnection( conn );
}
else
{
QMessageBox::information( this,
tr( "Test connection" ),
tr( "Connection failed - consult message log for details.\n\n" ) );
bar->pushMessage( tr( "Connection failed - consult message log for details." ),
QgsMessageBar::WARNING );
}
}

Expand Down
16 changes: 10 additions & 6 deletions src/providers/postgres/qgspgnewconnection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,12 @@ QgsPgNewConnection::QgsPgNewConnection( QWidget *parent, const QString &connName
txtName->setValidator( new QRegExpValidator( QRegExp( "[^\\/]+" ), txtName ) );
}
}

QgsPgNewConnection::~QgsPgNewConnection()
{

}

//! Autoconnected SLOTS *
void QgsPgNewConnection::accept()
{
Expand Down Expand Up @@ -202,17 +208,15 @@ void QgsPgNewConnection::testConnection()
if ( conn )
{
// Database successfully opened; we can now issue SQL commands.
QMessageBox::information( this,
tr( "Test connection" ),
tr( "Connection to %1 was successful" ).arg( txtDatabase->text() ) );
bar->pushMessage( tr( "Connection to %1 was successful" ).arg( txtDatabase->text() ),
QgsMessageBar::INFO );

// free pg connection resources
conn->unref();
}
else
{
QMessageBox::information( this,
tr( "Test connection" ),
tr( "Connection failed - consult message log for details.\n\n" ) );
bar->pushMessage( tr( "Connection failed - consult message log for details." ),
QgsMessageBar::WARNING );
}
}
2 changes: 2 additions & 0 deletions src/providers/postgres/qgspgnewconnection.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ class QgsPgNewConnection : public QDialog, private Ui::QgsPgNewConnectionBase
//! Constructor
QgsPgNewConnection( QWidget *parent = nullptr, const QString &connName = QString::null, Qt::WindowFlags fl = QgsGuiUtils::ModalDialogFlags );

~QgsPgNewConnection();

//! Tests the connection using the parameters supplied
void testConnection();
public slots:
Expand Down
36 changes: 19 additions & 17 deletions src/ui/qgsdb2newconnectionbase.ui
Original file line number Diff line number Diff line change
Expand Up @@ -15,23 +15,6 @@
</property>
<layout class="QGridLayout" name="gridLayout_3">
<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">
<property name="title">
<string>Connection Information</string>
Expand Down Expand Up @@ -196,6 +179,19 @@
</property>
</spacer>
</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>
</widget>
<customwidgets>
Expand All @@ -204,6 +200,12 @@
<extends>QLineEdit</extends>
<header>qgspasswordlineedit.h</header>
</customwidget>
<customwidget>
<class>QgsMessageBar</class>
<extends>QWidget</extends>
<header>qgsmessagebar.h</header>
<container>1</container>
</customwidget>
</customwidgets>
<tabstops>
<tabstop>txtName</tabstop>
Expand Down
15 changes: 12 additions & 3 deletions src/ui/qgsoraclenewconnectionbase.ui
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<x>0</x>
<y>0</y>
<width>400</width>
<height>513</height>
<height>529</height>
</rect>
</property>
<property name="sizePolicy">
Expand Down Expand Up @@ -41,14 +41,14 @@
<property name="spacing">
<number>6</number>
</property>
<item row="1" column="0">
<item row="2" column="0">
<widget class="QDialogButtonBox" name="buttonBox">
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Help|QDialogButtonBox::Ok</set>
</property>
</widget>
</item>
<item row="0" column="0">
<item row="1" column="0">
<widget class="QGroupBox" name="GroupBox1">
<property name="title">
<string>Connection Information</string>
Expand Down Expand Up @@ -277,6 +277,9 @@
</layout>
</widget>
</item>
<item row="0" column="0">
<widget class="QgsMessageBar" name="bar" native="true"/>
</item>
</layout>
</widget>
<layoutdefault spacing="6" margin="11"/>
Expand All @@ -286,6 +289,12 @@
<extends>QLineEdit</extends>
<header>qgspasswordlineedit.h</header>
</customwidget>
<customwidget>
<class>QgsMessageBar</class>
<extends>QWidget</extends>
<header>qgsmessagebar.h</header>
<container>1</container>
</customwidget>
</customwidgets>
<tabstops>
<tabstop>txtName</tabstop>
Expand Down
Loading

0 comments on commit 27850fb

Please sign in to comment.