34    disconnect( 
this, 
static_cast < void ( QComboBox::* )( 
int ) 
> ( &QComboBox::activated ), 
this, &QgsProviderConnectionComboBox::indexChanged );
 
   35    disconnect( mSortModel, &QAbstractItemModel::rowsInserted, 
this, &QgsProviderConnectionComboBox::rowsChanged );
 
   36    disconnect( mSortModel, &QAbstractItemModel::rowsRemoved, 
this, &QgsProviderConnectionComboBox::rowsChanged );
 
   43  mSortModel = 
new QgsProviderConnectionComboBoxSortModel( 
this );
 
   44  mSortModel->setSourceModel( mModel );
 
   45  mSortModel->setSortRole( Qt::DisplayRole );
 
   46  mSortModel->setSortLocaleAware( 
true );
 
   47  mSortModel->setSortCaseSensitivity( Qt::CaseInsensitive );
 
   48  mSortModel->setDynamicSortFilter( 
true );
 
   49  mSortModel->sort( 0 );
 
   51  setModel( mSortModel );
 
   53  connect( 
this, 
static_cast < void ( QComboBox::* )( 
int ) 
> ( &QComboBox::activated ), 
this, &QgsProviderConnectionComboBox::indexChanged );
 
   54  connect( mSortModel, &QAbstractItemModel::rowsInserted, 
this, &QgsProviderConnectionComboBox::rowsChanged );
 
   55  connect( mSortModel, &QAbstractItemModel::rowsRemoved, 
this, &QgsProviderConnectionComboBox::rowsChanged );
 
   73  if ( connection.isEmpty() )
 
   78      setCurrentIndex( -1 );
 
   86    const QModelIndex proxyIdx = idx.at( 0 );
 
   87    if ( proxyIdx.isValid() )
 
   89      setCurrentIndex( proxyIdx.row() );
 
   94  setCurrentIndex( -1 );
 
  100  const QModelIndex proxyIndex = mSortModel->index( currentIndex(), 0 );
 
  101  if ( !proxyIndex.isValid() )
 
  111  const QModelIndex proxyIndex = mSortModel->index( currentIndex(), 0 );
 
  112  if ( !proxyIndex.isValid() )
 
  120void QgsProviderConnectionComboBox::indexChanged( 
int i )
 
  126void QgsProviderConnectionComboBox::rowsChanged()
 
  128  if ( count() == 1 || ( mModel->
allowEmptyConnection() && count() == 2 && currentIndex() == 1 ) )
 
  133  else if ( count() == 0 )
 
  141QgsProviderConnectionComboBoxSortModel::QgsProviderConnectionComboBoxSortModel( QObject *parent )
 
  142  : QSortFilterProxyModel( parent )
 
  147bool QgsProviderConnectionComboBoxSortModel::lessThan( 
const QModelIndex &left, 
const QModelIndex &right )
 const 
  156  const QString leftStr = sourceModel()->data( left ).toString();
 
  157  const QString rightStr = sourceModel()->data( right ).toString();
 
  158  return QString::localeAwareCompare( leftStr, rightStr ) < 0;
 
QgsProviderConnectionComboBox(const QString &provider, QWidget *parent=nullptr)
Constructor for QgsProviderConnectionComboBox, for the specified provider.
 
QString currentConnectionUri() const
Returns the uri of the current connection selected in the combo box.
 
void setProvider(const QString &provider)
Sets the provider to be used.
 
void setConnection(const QString &connection)
Sets the current connection selected in the combo box.
 
bool allowEmptyConnection() const
Returns true if the combobox allows the empty connection ("not set") choice.
 
void setAllowEmptyConnection(bool allowEmpty)
Sets whether an optional empty connection ("not set") option is present in the combobox.
 
QString currentConnection() const
Returns the name of the current connection selected in the combo box.
 
void connectionChanged(const QString &connection)
Emitted whenever the currently selected connection changes.
 
A model containing registered connection names for a specific data provider.
 
bool allowEmptyConnection() const
Returns true if the model allows the empty connection ("not set") choice.
 
void setAllowEmptyConnection(bool allowEmpty)
Sets whether an optional empty connection ("not set") option is present in the model.
 
@ RoleEmpty
Entry is an empty entry.
 
@ RoleConnectionName
Connection name.
 
@ RoleUri
Connection URI string.