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 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() )
120 void QgsProviderConnectionComboBox::indexChanged(
int i )
126 void QgsProviderConnectionComboBox::rowsChanged()
128 if ( count() == 1 || ( mModel->
allowEmptyConnection() && count() == 2 && currentIndex() == 1 ) )
133 else if ( count() == 0 )
141 QgsProviderConnectionComboBoxSortModel::QgsProviderConnectionComboBoxSortModel( QObject *parent )
142 : QSortFilterProxyModel( parent )
147 bool QgsProviderConnectionComboBoxSortModel::lessThan(
const QModelIndex &left,
const QModelIndex &right )
const
156 QString leftStr = sourceModel()->data( left ).toString();
157 QString rightStr = sourceModel()->data( right ).toString();
158 return QString::localeAwareCompare( leftStr, rightStr ) < 0;