LocationDialog.cpp   LocationDialog.cpp 
/* /*
* Stellarium * Stellarium
* Copyright (C) 2008 Guillaume Chereau * Copyright (C) 2008 Guillaume Chereau
* Copyright (C) 2011 Alexander Wolf
* *
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License * modify it under the terms of the GNU General Public License
* 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.
skipping to change at line 26 skipping to change at line 27
* 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, U SA.
*/ */
#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 "StelNavigator.hpp"
#include "StelModuleMgr.hpp" #include "StelModuleMgr.hpp"
#include "SolarSystem.hpp" #include "SolarSystem.hpp"
#include "Planet.hpp" #include "Planet.hpp"
#include "StelFileMgr.hpp" #include "StelFileMgr.hpp"
#include "StelLocaleMgr.hpp" #include "StelLocaleMgr.hpp"
#include "StelGui.hpp" #include "StelGui.hpp"
#include "StelGuiItems.hpp" #include "StelGuiItems.hpp"
#include <QSettings> #include <QSettings>
#include <QDebug> #include <QDebug>
skipping to change at line 63 skipping to change at line 64
void LocationDialog::languageChanged() void LocationDialog::languageChanged()
{ {
if (dialog) if (dialog)
ui->retranslateUi(dialog); ui->retranslateUi(dialog);
} }
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()->getNavig ator()->getCurrentLocation()); 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()));
// 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);
SolarSystem* ssystem = GETSTELMODULE(SolarSystem); SolarSystem* ssystem = GETSTELMODULE(SolarSystem);
ui->planetNameComboBox->insertItems(0, ssystem->getAllPlanetEnglishN ui->planetNameComboBox->insertItems(0, ssystem->getAllPlanetLocalize
ames()); dNames());
ui->countryNameComboBox->insertItems(0, StelLocaleMgr::getAllCountry Names()); ui->countryNameComboBox->insertItems(0, StelLocaleMgr::getAllCountry Names());
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()));
setFieldsFromLocation(StelApp::getInstance().getCore()->getNavigator ()->getCurrentLocation()); setFieldsFromLocation(StelApp::getInstance().getCore()->getCurrentLo cation());
const bool b = StelApp::getInstance().getCore()->getNavigator()->get const bool b = StelApp::getInstance().getCore()->getCurrentLocation(
CurrentLocation().getID() ).getID()
==StelApp::getInstance().getCore()->getNavigator()-> ==StelApp::getInstance().getCore()->getDefaultLocati
getDefaultLocationID(); onID();
ui->useAsDefaultLocationCheckBox->setChecked(b); ui->useAsDefaultLocationCheckBox->setChecked(b);
ui->useAsDefaultLocationCheckBox->setEnabled(!b); ui->useAsDefaultLocationCheckBox->setEnabled(!b);
connect(ui->useAsDefaultLocationCheckBox, SIGNAL(clicked()), this, S LOT(useAsDefaultClicked())); connect(ui->useAsDefaultLocationCheckBox, SIGNAL(clicked()), this, S LOT(useAsDefaultClicked()));
connectEditSignals(); connectEditSignals();
QTimer* refreshTimer = new QTimer(this); QTimer* refreshTimer = new QTimer(this);
connect(refreshTimer, SIGNAL(timeout()), this, SLOT(updateFromProgra m())); connect(refreshTimer, SIGNAL(timeout()), this, SLOT(updateFromProgra m()));
refreshTimer->start(200); refreshTimer->start(200);
ui->citySearchLineEdit->setFocus(); ui->citySearchLineEdit->setFocus();
} }
// Update the widget to make sure it is synchrone if the location is change d programmatically // Update the widget to make sure it is synchrone if the location is change d programmatically
void LocationDialog::updateFromProgram() void LocationDialog::updateFromProgram()
{ {
if (!dialog->isVisible()) if (!dialog->isVisible())
return; return;
// Check that the use as default check box needs to be updated // Check that the use as default check box needs to be updated
const bool b = StelApp::getInstance().getCore()->getNavigator()->get CurrentLocation().getID() == StelApp::getInstance().getCore()->getNavigator ()->getDefaultLocationID(); const bool b = StelApp::getInstance().getCore()->getCurrentLocation( ).getID() == StelApp::getInstance().getCore()->getDefaultLocationID();
if (b!=ui->useAsDefaultLocationCheckBox->isChecked()) if (b!=ui->useAsDefaultLocationCheckBox->isChecked())
{ {
ui->useAsDefaultLocationCheckBox->setChecked(b); ui->useAsDefaultLocationCheckBox->setChecked(b);
ui->useAsDefaultLocationCheckBox->setEnabled(!b); ui->useAsDefaultLocationCheckBox->setEnabled(!b);
} }
// removing this check and return... we might have the location chan ged // removing this check and return... we might have the location chan ged
// by a script or plugin, and as such we should update the map whene ver the // by a script or plugin, and as such we should update the map whene ver the
// location window is visible. // location window is visible.
if (isEditingNew==true) if (isEditingNew==true)
return; return;
const QString& key1 = StelApp::getInstance().getCore()->getNavigator ()->getCurrentLocation().getID(); const QString& key1 = StelApp::getInstance().getCore()->getCurrentLo cation().getID();
const QString& key2 = locationFromFields().getID(); const QString& key2 = locationFromFields().getID();
if (key1!=key2) if (key1!=key2)
{ {
setFieldsFromLocation(StelApp::getInstance().getCore()->getN avigator()->getCurrentLocation()); setFieldsFromLocation(StelApp::getInstance().getCore()->getC urrentLocation());
} }
} }
void LocationDialog::disconnectEditSignals() void LocationDialog::disconnectEditSignals()
{ {
disconnect(ui->longitudeSpinBox, SIGNAL(valueChanged()), this, SLOT( spinBoxChanged())); disconnect(ui->longitudeSpinBox, SIGNAL(valueChanged()), this, SLOT( spinBoxChanged()));
disconnect(ui->latitudeSpinBox, SIGNAL(valueChanged()), this, SLOT(s pinBoxChanged())); disconnect(ui->latitudeSpinBox, SIGNAL(valueChanged()), this, SLOT(s pinBoxChanged()));
disconnect(ui->altitudeSpinBox, SIGNAL(valueChanged(int)), this, SLO T(spinBoxChanged(int))); disconnect(ui->altitudeSpinBox, SIGNAL(valueChanged(int)), this, SLO T(spinBoxChanged(int)));
disconnect(ui->planetNameComboBox, SIGNAL(currentIndexChanged(const QString&)), this, SLOT(comboBoxChanged(const QString&))); disconnect(ui->planetNameComboBox, SIGNAL(currentIndexChanged(const QString&)), this, SLOT(comboBoxChanged(const QString&)));
disconnect(ui->countryNameComboBox, SIGNAL(currentIndexChanged(const QString&)), this, SLOT(comboBoxChanged(const QString&))); disconnect(ui->countryNameComboBox, SIGNAL(currentIndexChanged(const QString&)), this, SLOT(comboBoxChanged(const QString&)));
skipping to change at line 183 skipping to change at line 184
if (idx==-1) if (idx==-1)
{ {
// Use France as default // Use France as default
ui->countryNameComboBox->findText("France", Qt::MatchCaseSen sitive); ui->countryNameComboBox->findText("France", Qt::MatchCaseSen sitive);
} }
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->findText(loc.planetName, Qt::MatchCase SolarSystem* ssystem = GETSTELMODULE(SolarSystem);
Sensitive); idx = ui->planetNameComboBox->findText(ssystem->searchByEnglishName(
loc.planetName)->getNameI18n(), Qt::MatchCaseSensitive);
if (idx==-1) if (idx==-1)
{ {
// Use Earth as default // Use Earth as default
ui->planetNameComboBox->findText("Earth"); ui->planetNameComboBox->findText(ssystem->getEarth()->getNam eI18n());
} }
ui->planetNameComboBox->setCurrentIndex(idx); ui->planetNameComboBox->setCurrentIndex(idx);
setMapForLocation(loc); setMapForLocation(loc);
// Set pointer position // Set pointer position
ui->mapLabel->setCursorPos(loc.longitude, loc.latitude); ui->mapLabel->setCursorPos(loc.longitude, loc.latitude);
ui->deleteLocationFromListPushButton->setEnabled(StelApp::getInstanc e().getLocationMgr().canDeleteUserLocation(loc.getID())); ui->deleteLocationFromListPushButton->setEnabled(StelApp::getInstanc e().getLocationMgr().canDeleteUserLocation(loc.getID()));
// Reactivate edit signals // Reactivate edit signals
skipping to change at line 252 skipping to change at line 254
} }
// For caching // For caching
lastPlanet = loc.planetName; lastPlanet = loc.planetName;
lastVisionMode = StelApp::getInstance().getVisionModeNight(); lastVisionMode = StelApp::getInstance().getVisionModeNight();
} }
// Create a StelLocation instance from the fields // Create a StelLocation instance from the fields
StelLocation LocationDialog::locationFromFields() const StelLocation LocationDialog::locationFromFields() const
{ {
SolarSystem* ssystem = GETSTELMODULE(SolarSystem);
StelLocation loc; StelLocation loc;
loc.planetName = ui->planetNameComboBox->currentText(); loc.planetName = ssystem->searchByNameI18n(ui->planetNameComboBox->c urrentText())->getEnglishName();
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(); loc.country = ui->countryNameComboBox->currentText();
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());
setFieldsFromLocation(loc); setFieldsFromLocation(loc);
StelApp::getInstance().getCore()->getNavigator()->moveObserverTo(loc , 0.); StelApp::getInstance().getCore()->moveObserverTo(loc, 0.);
const bool b = loc.getID()==StelApp::getInstance().getCore()->getNav igator()->getDefaultLocationID(); const bool b = loc.getID()==StelApp::getInstance().getCore()->getDef aultLocationID();
ui->useAsDefaultLocationCheckBox->setChecked(b); ui->useAsDefaultLocationCheckBox->setChecked(b);
ui->useAsDefaultLocationCheckBox->setEnabled(!b); ui->useAsDefaultLocationCheckBox->setEnabled(!b);
} }
void LocationDialog::setPositionFromMap(double longitude, double latitude) void LocationDialog::setPositionFromMap(double longitude, double latitude)
{ {
reportEdit(); reportEdit();
StelLocation loc = locationFromFields(); StelLocation loc = locationFromFields();
loc.latitude = latitude; loc.latitude = latitude;
loc.longitude = longitude; loc.longitude = longitude;
setFieldsFromLocation(loc); setFieldsFromLocation(loc);
StelApp::getInstance().getCore()->getNavigator()->moveObserverTo(loc , 0.); StelApp::getInstance().getCore()->moveObserverTo(loc, 0.);
} }
// Called when the planet name is changed by hand // Called when the planet name is changed by hand
void LocationDialog::comboBoxChanged(const QString&) void LocationDialog::comboBoxChanged(const QString&)
{ {
reportEdit(); reportEdit();
StelLocation loc = locationFromFields(); StelLocation loc = locationFromFields();
if (loc.planetName!=StelApp::getInstance().getCore()->getNavigator() ->getCurrentLocation().planetName) if (loc.planetName!=StelApp::getInstance().getCore()->getCurrentLoca tion().planetName)
setFieldsFromLocation(loc); setFieldsFromLocation(loc);
StelApp::getInstance().getCore()->getNavigator()->moveObserverTo(loc , 0.); StelApp::getInstance().getCore()->moveObserverTo(loc, 0.);
} }
void LocationDialog::spinBoxChanged(int ) void LocationDialog::spinBoxChanged(int )
{ {
reportEdit(); reportEdit();
StelLocation loc = locationFromFields(); StelLocation loc = locationFromFields();
StelApp::getInstance().getCore()->getNavigator()->moveObserverTo(loc , 0.); StelApp::getInstance().getCore()->moveObserverTo(loc, 0.);
} }
// Called when the location name is manually changed // Called when the location name is manually changed
void LocationDialog::locationNameChanged(const QString&) void LocationDialog::locationNameChanged(const QString&)
{ {
reportEdit(); reportEdit();
} }
void LocationDialog::reportEdit() void LocationDialog::reportEdit()
{ {
skipping to change at line 366 skipping to change at line 369
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));
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()
{ {
StelApp::getInstance().getCore()->getNavigator()->setDefaultLocation StelApp::getInstance().getCore()->setDefaultLocationID(StelApp::getI
ID(StelApp::getInstance().getCore()->getNavigator()->getCurrentLocation().g nstance().getCore()->getCurrentLocation().getID());
etID()); const bool b = StelApp::getInstance().getCore()->getCurrentLocation(
const bool b = StelApp::getInstance().getCore()->getNavigator()->get ).getID()==
CurrentLocation().getID()== StelApp::getInstance().getCore()->getDefaultLocation
StelApp::getInstance().getCore()->getNavigator()->ge ID();
tDefaultLocationID();
ui->useAsDefaultLocationCheckBox->setChecked(b); ui->useAsDefaultLocationCheckBox->setChecked(b);
ui->useAsDefaultLocationCheckBox->setEnabled(!b); ui->useAsDefaultLocationCheckBox->setEnabled(!b);
} }
// Called when the user clic on the delete button // Called when the user clic on the delete button
void LocationDialog::deleteCurrentLocationFromList() void LocationDialog::deleteCurrentLocationFromList()
{ {
const StelLocation& loc = locationFromFields(); const StelLocation& loc = locationFromFields();
StelApp::getInstance().getLocationMgr().deleteUserLocation(loc.getID ()); StelApp::getInstance().getLocationMgr().deleteUserLocation(loc.getID ());
} }
 End of changes. 21 change blocks. 
30 lines changed or deleted 32 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/