Skip to content

Commit 27850fb

Browse files
authored
Merge pull request #4592 from alexbruy/messagebars-for-db
Use QgsMessageBar instead of QMessageBoxes to show result of testing connection
2 parents f69d1c2 + 2c5e52b commit 27850fb

8 files changed

+181
-180
lines changed

src/providers/db2/qgsdb2newconnection.cpp

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@ QgsDb2NewConnection::QgsDb2NewConnection( QWidget *parent, const QString &connNa
5151
txtDriver->setText( settings.value( key + "/driver" ).toString() );
5252
txtDatabase->setText( settings.value( key + "/database" ).toString() );
5353

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

132131
void QgsDb2NewConnection::on_btnConnect_clicked()
133132
{
134-
QgsDebugMsg( "DB2: TestDatabase; button clicked" );
135133
testConnection();
136134
}
137135

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

150148
QgsDb2NewConnection::~QgsDb2NewConnection()
151149
{
152-
153150
}
154151

155152
bool QgsDb2NewConnection::testConnection()
@@ -172,7 +169,8 @@ bool QgsDb2NewConnection::testConnection()
172169

173170
if ( !rc )
174171
{
175-
db2ConnectStatus -> setText( errMsg );
172+
bar->pushMessage( tr( "Error: %1." ).arg( errMsg ),
173+
QgsMessageBar::WARNING );
176174
QgsDebugMsg( "errMsg: " + errMsg );
177175
return false;
178176
}
@@ -181,18 +179,19 @@ bool QgsDb2NewConnection::testConnection()
181179
if ( errMsg.isEmpty() )
182180
{
183181
QgsDebugMsg( "connection open succeeded " + connInfo );
184-
db2ConnectStatus -> setText( QStringLiteral( "DB2 connection open succeeded" ) );
182+
bar->pushMessage( tr( "Connection to %1 was successful" ).arg( txtDatabase->text() ),
183+
QgsMessageBar::INFO );
185184
return true;
186185
}
187186
else
188187
{
189188
QgsDebugMsg( "connection open failed: " + errMsg );
190-
db2ConnectStatus -> setText( "DB2 connection failed : " + errMsg );
189+
bar->pushMessage( tr( "Connection failed: %1." ).arg( errMsg ),
190+
QgsMessageBar::WARNING );
191191
return false;
192192
}
193193
}
194194

195195
void QgsDb2NewConnection::listDatabases()
196196
{
197-
QgsDebugMsg( "DB2 New Connection Dialogue : list database" );
198197
}

src/providers/mssql/qgsmssqlnewconnection.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,6 @@ void QgsMssqlNewConnection::on_cb_trustedConnection_clicked()
145145

146146
QgsMssqlNewConnection::~QgsMssqlNewConnection()
147147
{
148-
delete bar;
149148
}
150149

151150
bool QgsMssqlNewConnection::testConnection( const QString &testDatabase )

src/providers/oracle/qgsoraclenewconnection.cpp

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -152,18 +152,15 @@ void QgsOracleNewConnection::on_btnConnect_clicked()
152152
if ( conn )
153153
{
154154
// Database successfully opened; we can now issue SQL commands.
155-
QMessageBox::information( this,
156-
tr( "Test connection" ),
157-
tr( "Connection to %1 was successful" ).arg( txtDatabase->text() ) );
158-
155+
bar->pushMessage( tr( "Connection to %1 was successful" ).arg( txtDatabase->text() ),
156+
QgsMessageBar::INFO );
159157
// free connection resources
160158
QgsOracleConnPool::instance()->releaseConnection( conn );
161159
}
162160
else
163161
{
164-
QMessageBox::information( this,
165-
tr( "Test connection" ),
166-
tr( "Connection failed - consult message log for details.\n\n" ) );
162+
bar->pushMessage( tr( "Connection failed - consult message log for details." ),
163+
QgsMessageBar::WARNING );
167164
}
168165
}
169166

src/providers/postgres/qgspgnewconnection.cpp

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,12 @@ QgsPgNewConnection::QgsPgNewConnection( QWidget *parent, const QString &connName
105105
txtName->setValidator( new QRegExpValidator( QRegExp( "[^\\/]+" ), txtName ) );
106106
}
107107
}
108+
109+
QgsPgNewConnection::~QgsPgNewConnection()
110+
{
111+
112+
}
113+
108114
//! Autoconnected SLOTS *
109115
void QgsPgNewConnection::accept()
110116
{
@@ -202,17 +208,15 @@ void QgsPgNewConnection::testConnection()
202208
if ( conn )
203209
{
204210
// Database successfully opened; we can now issue SQL commands.
205-
QMessageBox::information( this,
206-
tr( "Test connection" ),
207-
tr( "Connection to %1 was successful" ).arg( txtDatabase->text() ) );
211+
bar->pushMessage( tr( "Connection to %1 was successful" ).arg( txtDatabase->text() ),
212+
QgsMessageBar::INFO );
208213

209214
// free pg connection resources
210215
conn->unref();
211216
}
212217
else
213218
{
214-
QMessageBox::information( this,
215-
tr( "Test connection" ),
216-
tr( "Connection failed - consult message log for details.\n\n" ) );
219+
bar->pushMessage( tr( "Connection failed - consult message log for details." ),
220+
QgsMessageBar::WARNING );
217221
}
218222
}

src/providers/postgres/qgspgnewconnection.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ class QgsPgNewConnection : public QDialog, private Ui::QgsPgNewConnectionBase
3232
//! Constructor
3333
QgsPgNewConnection( QWidget *parent = nullptr, const QString &connName = QString::null, Qt::WindowFlags fl = QgsGuiUtils::ModalDialogFlags );
3434

35+
~QgsPgNewConnection();
36+
3537
//! Tests the connection using the parameters supplied
3638
void testConnection();
3739
public slots:

src/ui/qgsdb2newconnectionbase.ui

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -15,23 +15,6 @@
1515
</property>
1616
<layout class="QGridLayout" name="gridLayout_3">
1717
<item row="1" column="0">
18-
<widget class="QLabel" name="db2ConnectStatus">
19-
<property name="text">
20-
<string>DB2 Connect Status: </string>
21-
</property>
22-
</widget>
23-
</item>
24-
<item row="3" column="0">
25-
<widget class="QDialogButtonBox" name="buttonBox">
26-
<property name="orientation">
27-
<enum>Qt::Horizontal</enum>
28-
</property>
29-
<property name="standardButtons">
30-
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
31-
</property>
32-
</widget>
33-
</item>
34-
<item row="0" column="0">
3518
<widget class="QGroupBox" name="groupBox">
3619
<property name="title">
3720
<string>Connection Information</string>
@@ -196,6 +179,19 @@
196179
</property>
197180
</spacer>
198181
</item>
182+
<item row="3" column="0">
183+
<widget class="QDialogButtonBox" name="buttonBox">
184+
<property name="orientation">
185+
<enum>Qt::Horizontal</enum>
186+
</property>
187+
<property name="standardButtons">
188+
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
189+
</property>
190+
</widget>
191+
</item>
192+
<item row="0" column="0">
193+
<widget class="QgsMessageBar" name="bar" native="true"/>
194+
</item>
199195
</layout>
200196
</widget>
201197
<customwidgets>
@@ -204,6 +200,12 @@
204200
<extends>QLineEdit</extends>
205201
<header>qgspasswordlineedit.h</header>
206202
</customwidget>
203+
<customwidget>
204+
<class>QgsMessageBar</class>
205+
<extends>QWidget</extends>
206+
<header>qgsmessagebar.h</header>
207+
<container>1</container>
208+
</customwidget>
207209
</customwidgets>
208210
<tabstops>
209211
<tabstop>txtName</tabstop>

src/ui/qgsoraclenewconnectionbase.ui

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<x>0</x>
88
<y>0</y>
99
<width>400</width>
10-
<height>513</height>
10+
<height>529</height>
1111
</rect>
1212
</property>
1313
<property name="sizePolicy">
@@ -41,14 +41,14 @@
4141
<property name="spacing">
4242
<number>6</number>
4343
</property>
44-
<item row="1" column="0">
44+
<item row="2" column="0">
4545
<widget class="QDialogButtonBox" name="buttonBox">
4646
<property name="standardButtons">
4747
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Help|QDialogButtonBox::Ok</set>
4848
</property>
4949
</widget>
5050
</item>
51-
<item row="0" column="0">
51+
<item row="1" column="0">
5252
<widget class="QGroupBox" name="GroupBox1">
5353
<property name="title">
5454
<string>Connection Information</string>
@@ -277,6 +277,9 @@
277277
</layout>
278278
</widget>
279279
</item>
280+
<item row="0" column="0">
281+
<widget class="QgsMessageBar" name="bar" native="true"/>
282+
</item>
280283
</layout>
281284
</widget>
282285
<layoutdefault spacing="6" margin="11"/>
@@ -286,6 +289,12 @@
286289
<extends>QLineEdit</extends>
287290
<header>qgspasswordlineedit.h</header>
288291
</customwidget>
292+
<customwidget>
293+
<class>QgsMessageBar</class>
294+
<extends>QWidget</extends>
295+
<header>qgsmessagebar.h</header>
296+
<container>1</container>
297+
</customwidget>
289298
</customwidgets>
290299
<tabstops>
291300
<tabstop>txtName</tabstop>

0 commit comments

Comments
 (0)