LocationDialog.cpp   LocationDialog.cpp 
skipping to change at line 18 skipping to change at line 18
* as published by the Free Software Foundation; either version 2 * as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version. * of the License, or (at your option) any later version.
* *
* This program is distributed in the hope that it will be useful, * This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, U SA. * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA.
*/ */
#include "Dialog.hpp" #include "Dialog.hpp"
#include "LocationDialog.hpp" #include "LocationDialog.hpp"
#include "StelLocationMgr.hpp" #include "StelLocationMgr.hpp"
#include "ui_locationDialogGui.h" #include "ui_locationDialogGui.h"
#include "StelApp.hpp" #include "StelApp.hpp"
#include "StelCore.hpp" #include "StelCore.hpp"
#include "StelModuleMgr.hpp" #include "StelModuleMgr.hpp"
skipping to change at line 54 skipping to change at line 54
{ {
ui = new Ui_locationDialogForm; ui = new Ui_locationDialogForm;
lastVisionMode = StelApp::getInstance().getVisionModeNight(); lastVisionMode = StelApp::getInstance().getVisionModeNight();
} }
LocationDialog::~LocationDialog() LocationDialog::~LocationDialog()
{ {
delete ui; delete ui;
} }
void LocationDialog::languageChanged() void LocationDialog::retranslate()
{ {
if (dialog) if (dialog)
{ {
ui->retranslateUi(dialog); ui->retranslateUi(dialog);
populatePlanetList(); populatePlanetList();
populateCountryList();
} }
} }
void LocationDialog::styleChanged() void LocationDialog::styleChanged()
{ {
// Make the map red if needed // Make the map red if needed
if (dialog) if (dialog)
setMapForLocation(StelApp::getInstance().getCore()->getCurre ntLocation()); setMapForLocation(StelApp::getInstance().getCore()->getCurre ntLocation());
} }
// Initialize the dialog widgets and connect the signals/slots // Initialize the dialog widgets and connect the signals/slots
void LocationDialog::createDialogContent() void LocationDialog::createDialogContent()
{ {
// We try to directly connect to the observer slots as much as we ca n // We try to directly connect to the observer slots as much as we ca n
ui->setupUi(dialog); ui->setupUi(dialog);
connect(&StelApp::getInstance(), SIGNAL(languageChanged()), this, SL OT(languageChanged())); connect(&StelApp::getInstance(), SIGNAL(languageChanged()), this, SL OT(retranslate()));
// Init the SpinBox entries // Init the SpinBox entries
ui->longitudeSpinBox->setDisplayFormat(AngleSpinBox::DMSSymbols); ui->longitudeSpinBox->setDisplayFormat(AngleSpinBox::DMSSymbols);
ui->longitudeSpinBox->setPrefixType(AngleSpinBox::Longitude); ui->longitudeSpinBox->setPrefixType(AngleSpinBox::Longitude);
ui->latitudeSpinBox->setDisplayFormat(AngleSpinBox::DMSSymbols); ui->latitudeSpinBox->setDisplayFormat(AngleSpinBox::DMSSymbols);
ui->latitudeSpinBox->setPrefixType(AngleSpinBox::Latitude); ui->latitudeSpinBox->setPrefixType(AngleSpinBox::Latitude);
QSortFilterProxyModel *proxyModel = new QSortFilterProxyModel(this); QSortFilterProxyModel *proxyModel = new QSortFilterProxyModel(this);
proxyModel->setSourceModel((QAbstractItemModel*)StelApp::getInstance ().getLocationMgr().getModelAll()); proxyModel->setSourceModel((QAbstractItemModel*)StelApp::getInstance ().getLocationMgr().getModelAll());
proxyModel->sort(0, Qt::AscendingOrder); proxyModel->sort(0, Qt::AscendingOrder);
proxyModel->setFilterCaseSensitivity(Qt::CaseInsensitive); proxyModel->setFilterCaseSensitivity(Qt::CaseInsensitive);
ui->citiesListView->setModel(proxyModel); ui->citiesListView->setModel(proxyModel);
populatePlanetList(); populatePlanetList();
ui->countryNameComboBox->insertItems(0, StelLocaleMgr::getAllCountry Names()); populateCountryList();
connect(ui->citySearchLineEdit, SIGNAL(textChanged(const QString&)), proxyModel, SLOT(setFilterWildcard(const QString&))); connect(ui->citySearchLineEdit, SIGNAL(textChanged(const QString&)), proxyModel, SLOT(setFilterWildcard(const QString&)));
connect(ui->citiesListView, SIGNAL(clicked(const QModelIndex&)), thi s, SLOT(listItemActivated(const QModelIndex&))); connect(ui->citiesListView, SIGNAL(clicked(const QModelIndex&)), thi s, SLOT(listItemActivated(const QModelIndex&)));
// Connect all the QT signals // Connect all the QT signals
connect(ui->closeStelWindow, SIGNAL(clicked()), this, SLOT(close())) ; connect(ui->closeStelWindow, SIGNAL(clicked()), this, SLOT(close())) ;
connect(ui->mapLabel, SIGNAL(positionChanged(double, double)), this, SLOT(setPositionFromMap(double, double))); connect(ui->mapLabel, SIGNAL(positionChanged(double, double)), this, SLOT(setPositionFromMap(double, double)));
connect(ui->addLocationToListPushButton, SIGNAL(clicked()), this, SL OT(addCurrentLocationToList())); connect(ui->addLocationToListPushButton, SIGNAL(clicked()), this, SL OT(addCurrentLocationToList()));
connect(ui->deleteLocationFromListPushButton, SIGNAL(clicked()), thi s, SLOT(deleteCurrentLocationFromList())); connect(ui->deleteLocationFromListPushButton, SIGNAL(clicked()), thi s, SLOT(deleteCurrentLocationFromList()));
skipping to change at line 175 skipping to change at line 176
connect(ui->countryNameComboBox, SIGNAL(activated(const QString&)), this, SLOT(comboBoxChanged(const QString&))); connect(ui->countryNameComboBox, SIGNAL(activated(const QString&)), this, SLOT(comboBoxChanged(const QString&)));
connect(ui->cityNameLineEdit, SIGNAL(textEdited(const QString&)), th is, SLOT(locationNameChanged(const QString&))); connect(ui->cityNameLineEdit, SIGNAL(textEdited(const QString&)), th is, SLOT(locationNameChanged(const QString&)));
} }
void LocationDialog::setFieldsFromLocation(const StelLocation& loc) void LocationDialog::setFieldsFromLocation(const StelLocation& loc)
{ {
// Deactivate edit signals // Deactivate edit signals
disconnectEditSignals(); disconnectEditSignals();
ui->cityNameLineEdit->setText(loc.name); ui->cityNameLineEdit->setText(loc.name);
int idx = ui->countryNameComboBox->findText(loc.country); int idx = ui->countryNameComboBox->findData(loc.country, Qt::UserRol e, Qt::MatchCaseSensitive);
if (idx==-1) if (idx==-1)
{ {
// Use France as default // Use France as default
ui->countryNameComboBox->findText("France", Qt::MatchCaseSen sitive); ui->countryNameComboBox->findData(QVariant("France"), Qt::Us erRole, Qt::MatchCaseSensitive);
} }
ui->countryNameComboBox->setCurrentIndex(idx); ui->countryNameComboBox->setCurrentIndex(idx);
ui->longitudeSpinBox->setDegrees(loc.longitude); ui->longitudeSpinBox->setDegrees(loc.longitude);
ui->latitudeSpinBox->setDegrees(loc.latitude); ui->latitudeSpinBox->setDegrees(loc.latitude);
ui->altitudeSpinBox->setValue(loc.altitude); ui->altitudeSpinBox->setValue(loc.altitude);
idx = ui->planetNameComboBox->findData(loc.planetName, Qt::UserRole, Qt::MatchCaseSensitive); idx = ui->planetNameComboBox->findData(loc.planetName, Qt::UserRole, Qt::MatchCaseSensitive);
if (idx==-1) if (idx==-1)
{ {
skipping to change at line 276 skipping to change at line 277
planets->clear(); planets->clear();
//For each planet, display the localized name and store the original as user //For each planet, display the localized name and store the original as user
//data. Unfortunately, there's no other way to do this than with a c ycle. //data. Unfortunately, there's no other way to do this than with a c ycle.
foreach(const QString& name, planetNames) foreach(const QString& name, planetNames)
{ {
planets->addItem(q_(name), name); planets->addItem(q_(name), name);
} }
//Restore the selection //Restore the selection
index = planets->findData(selectedPlanetId, Qt::UserRole, Qt::MatchC aseSensitive); index = planets->findData(selectedPlanetId, Qt::UserRole, Qt::MatchC aseSensitive);
planets->setCurrentIndex(index); planets->setCurrentIndex(index);
planets->model()->sort(0);
planets->blockSignals(false); planets->blockSignals(false);
} }
void LocationDialog::populateCountryList()
{
Q_ASSERT(ui);
Q_ASSERT(ui->countryNameComboBox);
QComboBox* countries = ui->countryNameComboBox;
QStringList countryNames(StelLocaleMgr::getAllCountryNames());
//Save the current selection to be restored later
countries->blockSignals(true);
int index = countries->currentIndex();
QVariant selectedCountryId = countries->itemData(index);
countries->clear();
//For each country, display the localized name and store the origina
l as user
//data. Unfortunately, there's no other way to do this than with a c
ycle.
foreach(const QString& name, countryNames)
{
countries->addItem(q_(name), name);
}
//Restore the selection
index = countries->findData(selectedCountryId, Qt::UserRole, Qt::Mat
chCaseSensitive);
countries->setCurrentIndex(index);
countries->model()->sort(0);
countries->blockSignals(false);
}
// Create a StelLocation instance from the fields // Create a StelLocation instance from the fields
StelLocation LocationDialog::locationFromFields() const StelLocation LocationDialog::locationFromFields() const
{ {
StelLocation loc; StelLocation loc;
int index = ui->planetNameComboBox->currentIndex(); int index = ui->planetNameComboBox->currentIndex();
if (index < 0) if (index < 0)
loc.planetName = QString();//As returned by QComboBox::curre ntText() loc.planetName = QString();//As returned by QComboBox::curre ntText()
else else
loc.planetName = ui->planetNameComboBox->itemData(index).toS tring(); loc.planetName = ui->planetNameComboBox->itemData(index).toS tring();
loc.name = ui->cityNameLineEdit->text(); loc.name = ui->cityNameLineEdit->text();
loc.latitude = ui->latitudeSpinBox->valueDegrees(); loc.latitude = ui->latitudeSpinBox->valueDegrees();
loc.longitude = ui->longitudeSpinBox->valueDegrees(); loc.longitude = ui->longitudeSpinBox->valueDegrees();
loc.altitude = ui->altitudeSpinBox->value(); loc.altitude = ui->altitudeSpinBox->value();
loc.country = ui->countryNameComboBox->currentText(); index = ui->countryNameComboBox->currentIndex();
if (index < 0)
loc.country = QString();//As returned by QComboBox::currentT
ext()
else
loc.country = ui->countryNameComboBox->itemData(index).toStr
ing();
return loc; return loc;
} }
void LocationDialog::listItemActivated(const QModelIndex& index) void LocationDialog::listItemActivated(const QModelIndex& index)
{ {
isEditingNew=false; isEditingNew=false;
ui->addLocationToListPushButton->setEnabled(false); ui->addLocationToListPushButton->setEnabled(false);
StelLocation loc = StelApp::getInstance().getLocationMgr().locationF orSmallString(index.data().toString()); StelLocation loc = StelApp::getInstance().getLocationMgr().locationF orSmallString(index.data().toString());
skipping to change at line 394 skipping to change at line 428
const QAbstractItemModel* model = ui->citiesListView->model(); const QAbstractItemModel* model = ui->citiesListView->model();
const QString id = loc.getID(); const QString id = loc.getID();
for (int i=0;i<model->rowCount();++i) for (int i=0;i<model->rowCount();++i)
{ {
if (model->index(i,0).data()==id) if (model->index(i,0).data()==id)
{ {
ui->citiesListView->scrollTo(model->index(i,0)); ui->citiesListView->scrollTo(model->index(i,0));
ui->citiesListView->selectionModel()->select(model-> index(i,0), QItemSelectionModel::ClearAndSelect|QItemSelectionModel::Rows); ui->citiesListView->selectionModel()->select(model-> index(i,0), QItemSelectionModel::ClearAndSelect|QItemSelectionModel::Rows);
listItemActivated(model->index(i,0)); listItemActivated(model->index(i,0));
disconnectEditSignals();
ui->citySearchLineEdit->setFocus();
connectEditSignals();
break; break;
} }
} }
} }
// Called when the user wants to use the current location as default // Called when the user wants to use the current location as default
void LocationDialog::useAsDefaultClicked() void LocationDialog::useAsDefaultClicked()
{ {
StelCore* core = StelApp::getInstance().getCore(); StelCore* core = StelApp::getInstance().getCore();
QString newDefaultLocationId = core->getCurrentLocation().getID(); QString newDefaultLocationId = core->getCurrentLocation().getID();
 End of changes. 11 change blocks. 
7 lines changed or deleted 49 lines changed or added

This html diff was produced by rfcdiff 1.41. The latest version is available from http://tools.ietf.org/tools/rfcdiff/