@@ -88,6 +88,7 @@ void QgsServerSourceSelect::populateConnectionList()
88
88
cmbConnections->insertItem (*it);
89
89
++it;
90
90
}
91
+ setConnectionListPosition ();
91
92
92
93
if (keys.begin () != keys.end ())
93
94
{
@@ -137,6 +138,7 @@ void QgsServerSourceSelect::on_btnDelete_clicked()
137
138
{
138
139
settings.remove (key);
139
140
cmbConnections->removeItem (cmbConnections->currentItem ()); // populateConnectionList();
141
+ setConnectionListPosition ();
140
142
}
141
143
}
142
144
@@ -593,7 +595,43 @@ QString QgsServerSourceSelect::selectedCrs()
593
595
}
594
596
}
595
597
598
+ void QgsServerSourceSelect::serverChanged ()
599
+ {
600
+ // Remember which server was selected.
601
+ QSettings settings;
602
+ settings.writeEntry (" /Qgis/connections-wms/selected" ,
603
+ cmbConnections->currentText ());
604
+ }
596
605
606
+ void QgsServerSourceSelect::setConnectionListPosition ()
607
+ {
608
+ QSettings settings;
609
+ QString toSelect = settings.readEntry (" /Qgis/connections-wms/selected" );
610
+ // Does toSelect exist in cmbConnections?
611
+ bool set = false ;
612
+ for (int i = 0 ; i < cmbConnections->count (); ++i)
613
+ if (cmbConnections->text (i) == toSelect)
614
+ {
615
+ cmbConnections->setCurrentItem (i);
616
+ set = true ;
617
+ break ;
618
+ }
619
+ // If we couldn't find the stored item, but there are some,
620
+ // default to the last item (this makes some sense when deleting
621
+ // items as it allows the user to repeatidly click on delete to
622
+ // remove a whole lot of items).
623
+ if (!set && cmbConnections->count () > 0 )
624
+ {
625
+ // If toSelect is null, then the selected connection wasn't found
626
+ // by QSettings, which probably means that this is the first time
627
+ // the user has used qgis with database connections, so default to
628
+ // the first in the list of connetions. Otherwise default to the last.
629
+ if (toSelect.isNull ())
630
+ cmbConnections->setCurrentItem (0 );
631
+ else
632
+ cmbConnections->setCurrentItem (cmbConnections->count ()-1 );
633
+ }
634
+ }
597
635
void QgsServerSourceSelect::showStatusMessage (QString const & theMessage)
598
636
{
599
637
labelStatus->setText (theMessage);
@@ -624,6 +662,10 @@ void QgsServerSourceSelect::showError(QgsWmsProvider * wms)
624
662
delete mv;
625
663
}
626
664
665
+ void QgsServerSourceSelect::on_cmbConnections_activated (int )
666
+ {
667
+ serverChanged ();
668
+ }
627
669
628
670
QString QgsServerSourceSelect::descriptionForEpsg (long epsg)
629
671
{
0 commit comments