Feature request #11604

DB Manager needs option to create a database connection

Added by Patrick Van Laake almost 6 years ago. Updated over 3 years ago.

Status:Closed
Priority:Low
Assignee:-
Category:DB Manager
Pull Request or Patch supplied:No Resolution:duplicate
Easy fix?:No Copied to github as #:19861

Description

The DB Manager window currently has no option to create a new database connection. To create a connection to PostgreSQL I have to use the SPIT tool, after which the newly created connection can be selected in DB Manager.

postgres-conns.png (26.6 KB) Larry Shaffer, 2016-02-08 01:19 PM

History

#1 Updated by Paolo Cavallini almost 6 years ago

No need for SPIT, you can add a connection from the Browser

#2 Updated by Giuseppe Sucameli almost 5 years ago

  • Priority changed from Normal to Low

In this moment DBManager allows to add new Spatialite connections only.

Anyway you can add new PostgreSQL connections using "Add Postgis layer" from QGIS.

#3 Updated by Larry Shaffer over 4 years ago

Adding a Postgres connection manager (for convenience) could be done in two ways:

  1. Make a manager from scratch in Python
  1. Use the Postgres provider's selectWidget() and strip out the 'Add Layer' bits
  1. Edit the QgsVectorDataProvider external plugin interface to provide a new connectionWidget() for managing just connections

The following hack-ish code works to slim the provider's current select widget down to just a connection manager GUI:

from PyQt4.QtGui import *
from PyQt4.QtCore import * 

dprovs = [d for d in QgsDataItemProviderRegistry.instance().providers() if 'postgres' in d.name()]
if dprovs:
    dpitem = dprovs[0].createDataItem('', None)

    dpitemw = dpitem.paramWidget()
    dpiteml = dpitemw.layout()

    grpbxitem = None
    for i in range(0, dpiteml.count()):
        w = dpiteml.itemAt(i).widget()
        if w and w.objectName() == 'connectionsGroupBox':
            grpbxitem = dpiteml.takeAt(i)
            break

    if grpbxitem:
        btn = grpbxitem.widget().findChild(QPushButton, 'btnConnect')
        if btn:
            btn.setVisible(False)

        dlg = QDialog()
        dlg.setWindowTitle('Postgres Connections')
        lay = QVBoxLayout()
        lay.addItem(grpbxitem)
        btnbx = QDialogButtonBox(QDialogButtonBox.Ok | QDialogButtonBox.Cancel)
        lay.addWidget(btnbx)
        btnbx.accepted.connect(dlg.accept)
        btnbx.rejected.connect(dlg.reject)
        dlg.setLayout(lay)

        if dlg.exec_():
            # refresh the Postgres tree item
            print 'accepted'

See attached screenshot. This could be implemented as an action in the contextual menu for the Postgres parent tree item and as a toolbar action.

#4 Updated by Paolo Cavallini over 3 years ago

  • Resolution set to duplicate
  • Status changed from Open to Closed

Duplicate of #4795

Also available in: Atom PDF