LocationDialog.cpp   LocationDialog.cpp 
skipping to change at line 23 skipping to change at line 23
* 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., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA. * 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 "LandscapeMgr.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"
#include "SolarSystem.hpp" #include "SolarSystem.hpp"
#include "Planet.hpp" #include "Planet.hpp"
#include "StelFileMgr.hpp" #include "StelFileMgr.hpp"
#include "StelLocaleMgr.hpp" #include "StelLocaleMgr.hpp"
skipping to change at line 94 skipping to change at line 95
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();
populateCountryList(); 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 connect(ui->citiesListView, SIGNAL(clicked(const QModelIndex&)),
s, SLOT(listItemActivated(const QModelIndex&))); this, SLOT(setPositionFromList(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()->getCurrentLo StelCore* core = StelApp::getInstance().getCore();
cation()); const StelLocation& currentLocation = core->getCurrentLocation();
setFieldsFromLocation(currentLocation);
const bool b = StelApp::getInstance().getCore()->getCurrentLocation( const bool b = (currentLocation.getID() == core->getDefaultLocationI
).getID() D());
==StelApp::getInstance().getCore()->getDefaultLocati updateDefaultLocationControls(b);
onID(); connect(ui->useAsDefaultLocationCheckBox, SIGNAL(clicked()), this, S
ui->useAsDefaultLocationCheckBox->setChecked(b); LOT(setDefaultLocation()));
ui->useAsDefaultLocationCheckBox->setEnabled(!b); connect(ui->pushButtonReturnToDefault, SIGNAL(clicked()),
connect(ui->useAsDefaultLocationCheckBox, SIGNAL(clicked()), this, S core, SLOT(returnToDefaultLocation()));
LOT(useAsDefaultClicked()));
connectEditSignals(); connectEditSignals();
QTimer* refreshTimer = new QTimer(this); connect(core, SIGNAL(locationChanged(StelLocation)),
connect(refreshTimer, SIGNAL(timeout()), this, SLOT(updateFromProgra this, SLOT(updateFromProgram(StelLocation)));
m()));
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(const StelLocation& currentLocation)
{ {
if (!dialog->isVisible()) if (!dialog->isVisible())
return; return;
// Check that the use as default check box needs to be updated StelCore* stelCore = StelApp::getInstance().getCore();
const bool b = StelApp::getInstance().getCore()->getCurrentLocation( //const StelLocation& currentLocation = stelCore->getCurrentLocation
).getID() == StelApp::getInstance().getCore()->getDefaultLocationID(); ();
if (b!=ui->useAsDefaultLocationCheckBox->isChecked())
{
ui->useAsDefaultLocationCheckBox->setChecked(b);
ui->useAsDefaultLocationCheckBox->setEnabled(!b);
}
// removing this check and return... we might have the location chan // Hack to avoid the coord spinbox receiving the focus and triggerin
ged g
// by a script or plugin, and as such we should update the map whene // "new location" editing mode.
ver the ui->citySearchLineEdit->setFocus();
// location window is visible.
if (isEditingNew==true)
return;
const QString& key1 = StelApp::getInstance().getCore()->getCurrentLo isEditingNew = false;
cation().getID();
// Check that the use as default check box needs to be updated
// Move to setFieldsFromLocation()? --BM?
const bool b = currentLocation.getID() == stelCore->getDefaultLocati
onID();
updateDefaultLocationControls(b);
const QString& key1 = currentLocation.getID();
const QString& key2 = locationFromFields().getID(); const QString& key2 = locationFromFields().getID();
if (key1!=key2) if (key1!=key2)
{ {
setFieldsFromLocation(StelApp::getInstance().getCore()->getC urrentLocation()); setFieldsFromLocation(currentLocation);
} }
} }
void LocationDialog::disconnectEditSignals() void LocationDialog::disconnectEditSignals()
{ {
disconnect(ui->longitudeSpinBox, SIGNAL(valueChanged()), this, SLOT( disconnect(ui->longitudeSpinBox, SIGNAL(valueChanged()), this, SLOT(
spinBoxChanged())); setPositionFromCoords()));
disconnect(ui->latitudeSpinBox, SIGNAL(valueChanged()), this, SLOT(s disconnect(ui->latitudeSpinBox, SIGNAL(valueChanged()), this, SLOT(s
pinBoxChanged())); etPositionFromCoords()));
disconnect(ui->altitudeSpinBox, SIGNAL(valueChanged(int)), this, SLO disconnect(ui->altitudeSpinBox, SIGNAL(valueChanged(int)), this, SLO
T(spinBoxChanged(int))); T(setPositionFromCoords(int)));
disconnect(ui->planetNameComboBox, SIGNAL(currentIndexChanged(const disconnect(ui->planetNameComboBox, SIGNAL(currentIndexChanged(const
QString&)), this, SLOT(comboBoxChanged(const QString&))); QString&)), this, SLOT(moveToAnotherPlanet(const QString&)));
disconnect(ui->countryNameComboBox, SIGNAL(currentIndexChanged(const disconnect(ui->countryNameComboBox, SIGNAL(currentIndexChanged(const
QString&)), this, SLOT(comboBoxChanged(const QString&))); QString&)), this, SLOT(reportEdit()));
disconnect(ui->countryNameComboBox, SIGNAL(activated(const QString&) // Why an edit should be reported even if the country is not changed
), this, SLOT(comboBoxChanged(const QString&))); ? --BM
disconnect(ui->cityNameLineEdit, SIGNAL(textEdited(const QString&)), //disconnect(ui->countryNameComboBox, SIGNAL(activated(const QString
this, SLOT(locationNameChanged(const QString&))); &)), this, SLOT(comboBoxChanged(const QString&)));
disconnect(ui->cityNameLineEdit, SIGNAL(textEdited(const QString&)),
this, SLOT(reportEdit()));
} }
void LocationDialog::connectEditSignals() void LocationDialog::connectEditSignals()
{ {
connect(ui->longitudeSpinBox, SIGNAL(valueChanged()), this, SLOT(spi connect(ui->longitudeSpinBox, SIGNAL(valueChanged()), this, SLOT(set
nBoxChanged())); PositionFromCoords()));
connect(ui->latitudeSpinBox, SIGNAL(valueChanged()), this, SLOT(spin connect(ui->latitudeSpinBox, SIGNAL(valueChanged()), this, SLOT(setP
BoxChanged())); ositionFromCoords()));
connect(ui->altitudeSpinBox, SIGNAL(valueChanged(int)), this, SLOT(s connect(ui->altitudeSpinBox, SIGNAL(valueChanged(int)), this, SLOT(s
pinBoxChanged(int))); etPositionFromCoords(int)));
connect(ui->planetNameComboBox, SIGNAL(currentIndexChanged(const QSt connect(ui->planetNameComboBox, SIGNAL(currentIndexChanged(const QSt
ring&)), this, SLOT(comboBoxChanged(const QString&))); ring&)), this, SLOT(moveToAnotherPlanet(const QString&)));
connect(ui->countryNameComboBox, SIGNAL(currentIndexChanged(const QS connect(ui->countryNameComboBox, SIGNAL(currentIndexChanged(const QS
tring&)), this, SLOT(comboBoxChanged(const QString&))); tring&)), this, SLOT(reportEdit()));
connect(ui->countryNameComboBox, SIGNAL(activated(const QString&)), // Why an edit should be reported even if the country is not changed
this, SLOT(comboBoxChanged(const QString&))); ? --BM
connect(ui->cityNameLineEdit, SIGNAL(textEdited(const QString&)), th //connect(ui->countryNameComboBox, SIGNAL(activated(const QString&))
is, SLOT(locationNameChanged(const QString&))); , this, SLOT(comboBoxChanged(const QString&)));
connect(ui->cityNameLineEdit, SIGNAL(textEdited(const QString&)),
this, SLOT(reportEdit()));
} }
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->findData(loc.country, Qt::UserRol e, Qt::MatchCaseSensitive); int idx = ui->countryNameComboBox->findData(loc.country, Qt::UserRol e, Qt::MatchCaseSensitive);
if (idx==-1) if (idx==-1)
skipping to change at line 202 skipping to change at line 209
idx = ui->planetNameComboBox->findData(QVariant("Earth"), Qt ::UserRole, Qt::MatchCaseSensitive); idx = ui->planetNameComboBox->findData(QVariant("Earth"), Qt ::UserRole, Qt::MatchCaseSensitive);
} }
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()));
SolarSystem* ssm = GETSTELMODULE(SolarSystem);
PlanetP p = ssm->searchByEnglishName(loc.planetName);
LandscapeMgr* ls = GETSTELMODULE(LandscapeMgr);
ls->setFlagAtmosphere(p->hasAtmosphere());
ls->setFlagFog(p->hasAtmosphere());
// Reactivate edit signals // Reactivate edit signals
connectEditSignals(); connectEditSignals();
} }
// Update the map for the given location. // Update the map for the given location.
void LocationDialog::setMapForLocation(const StelLocation& loc) void LocationDialog::setMapForLocation(const StelLocation& loc)
{ {
// Avoids usless processing // Avoids usless processing
if (lastPlanet==loc.planetName && lastVisionMode==StelApp::getInstan ce().getVisionModeNight()) if (lastPlanet==loc.planetName && lastVisionMode==StelApp::getInstan ce().getVisionModeNight())
return; return;
skipping to change at line 330 skipping to change at line 343
loc.altitude = ui->altitudeSpinBox->value(); loc.altitude = ui->altitudeSpinBox->value();
index = ui->countryNameComboBox->currentIndex(); index = ui->countryNameComboBox->currentIndex();
if (index < 0) if (index < 0)
loc.country = QString();//As returned by QComboBox::currentT ext() loc.country = QString();//As returned by QComboBox::currentT ext()
else else
loc.country = ui->countryNameComboBox->itemData(index).toStr ing(); loc.country = ui->countryNameComboBox->itemData(index).toStr ing();
return loc; return loc;
} }
void LocationDialog::listItemActivated(const QModelIndex& index) void LocationDialog::setPositionFromList(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()->moveObserverTo(loc, 0.); StelApp::getInstance().getCore()->moveObserverTo(loc, 0.);
// This calls indirectly updateFromProgram()
const bool b = loc.getID()==StelApp::getInstance().getCore()->getDef
aultLocationID();
ui->useAsDefaultLocationCheckBox->setChecked(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()->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::moveToAnotherPlanet(const QString&)
{ {
reportEdit(); reportEdit();
StelLocation loc = locationFromFields(); StelLocation loc = locationFromFields();
if (loc.planetName!=StelApp::getInstance().getCore()->getCurrentLoca StelCore* stelCore = StelApp::getInstance().getCore();
tion().planetName) if (loc.planetName != stelCore->getCurrentLocation().planetName)
setFieldsFromLocation(loc); setFieldsFromLocation(loc);
StelApp::getInstance().getCore()->moveObserverTo(loc, 0.); stelCore->moveObserverTo(loc, 0.);
} }
void LocationDialog::spinBoxChanged(int ) void LocationDialog::setPositionFromCoords(int )
{ {
reportEdit(); reportEdit();
StelLocation loc = locationFromFields(); StelLocation loc = locationFromFields();
StelApp::getInstance().getCore()->moveObserverTo(loc, 0.); StelApp::getInstance().getCore()->moveObserverTo(loc, 0.);
//Update the position of the map pointer //Update the position of the map pointer
ui->mapLabel->setCursorPos(loc.longitude, loc.latitude); ui->mapLabel->setCursorPos(loc.longitude, loc.latitude);
} }
// Called when the location name is manually changed
void LocationDialog::locationNameChanged(const QString&)
{
reportEdit();
}
void LocationDialog::reportEdit() void LocationDialog::reportEdit()
{ {
if (isEditingNew==false) if (isEditingNew==false)
{ {
// The user starts editing manually a field, this creates au tomatically a new location // The user starts editing manually a field, this creates au tomatically a new location
// and allows to save it to the user locations list // and allows to save it to the user locations list
isEditingNew=true; isEditingNew=true;
} }
StelLocation loc = locationFromFields(); StelLocation loc = locationFromFields();
if (!StelApp::getInstance().getLocationMgr().canSaveUserLocation(loc StelLocationMgr& locationMgr = StelApp::getInstance().getLocationMgr
)) ();
bool canSave = locationMgr.canSaveUserLocation(loc);
if (!canSave)
{ {
if (ui->cityNameLineEdit->hasFocus()) if (ui->cityNameLineEdit->hasFocus())
{ {
// The user is editing the location name: don't chan ge it! // The user is editing the location name: don't chan ge it!
ui->addLocationToListPushButton->setEnabled(false); ui->addLocationToListPushButton->setEnabled(false);
ui->deleteLocationFromListPushButton->setEnabled(fal se); ui->deleteLocationFromListPushButton->setEnabled(fal se);
return; return;
} }
else else
{ {
ui->cityNameLineEdit->setText(q_("New Location")); ui->cityNameLineEdit->setText(q_("New Location"));
ui->cityNameLineEdit->selectAll(); ui->cityNameLineEdit->selectAll();
loc = locationFromFields(); loc = locationFromFields();
} }
} }
ui->addLocationToListPushButton->setEnabled(isEditingNew && StelApp: ui->addLocationToListPushButton->setEnabled(isEditingNew && canSave)
:getInstance().getLocationMgr().canSaveUserLocation(loc)); ;
ui->deleteLocationFromListPushButton->setEnabled(StelApp::getInstanc ui->deleteLocationFromListPushButton->setEnabled(locationMgr.canDele
e().getLocationMgr().canDeleteUserLocation(loc.getID())); teUserLocation(loc.getID()));
} }
// Called when the user clic on the save button // Called when the user clic on the save button
void LocationDialog::addCurrentLocationToList() void LocationDialog::addCurrentLocationToList()
{ {
const StelLocation& loc = locationFromFields(); const StelLocation& loc = locationFromFields();
ui->citySearchLineEdit->clear(); ui->citySearchLineEdit->clear();
StelApp::getInstance().getLocationMgr().saveUserLocation(loc); StelApp::getInstance().getLocationMgr().saveUserLocation(loc);
isEditingNew=false; isEditingNew=false;
ui->addLocationToListPushButton->setEnabled(false); ui->addLocationToListPushButton->setEnabled(false);
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)); setPositionFromList(model->index(i,0));
disconnectEditSignals(); disconnectEditSignals();
ui->citySearchLineEdit->setFocus(); ui->citySearchLineEdit->setFocus();
connectEditSignals(); 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::setDefaultLocation()
{ {
StelCore* core = StelApp::getInstance().getCore(); StelCore* core = StelApp::getInstance().getCore();
QString newDefaultLocationId = core->getCurrentLocation().getID();
core->setDefaultLocationID(newDefaultLocationId);
QString currentLocationId = core->getCurrentLocation().getID(); QString currentLocationId = core->getCurrentLocation().getID();
const bool show = (currentLocationId == core->getDefaultLocationID() core->setDefaultLocationID(currentLocationId);
);
// Why this code even exists? After the previous code, this should a
lways
// be true, except if setting the default location somehow fails. --
BM
bool isDefault = (currentLocationId == core->getDefaultLocationID())
;
disconnectEditSignals(); disconnectEditSignals();
ui->useAsDefaultLocationCheckBox->setChecked(show); updateDefaultLocationControls(isDefault);
ui->useAsDefaultLocationCheckBox->setEnabled(!show);
//The focus need to be switched to another control, otherwise //The focus need to be switched to another control, otherwise
//ui->latitudeSpinBox receives it and emits a valueChanged() signal when //ui->latitudeSpinBox receives it and emits a valueChanged() signal when
//the window is closed. //the window is closed.
ui->citySearchLineEdit->setFocus(); ui->citySearchLineEdit->setFocus();
connectEditSignals(); connectEditSignals();
} }
// Called when the user clic on the delete button // Called when the user clicks 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 ());
} }
void LocationDialog::updateDefaultLocationControls(bool currentIsDefault)
{
ui->useAsDefaultLocationCheckBox->setChecked(currentIsDefault);
ui->useAsDefaultLocationCheckBox->setEnabled(!currentIsDefault);
ui->pushButtonReturnToDefault->setEnabled(!currentIsDefault);
}
 End of changes. 29 change blocks. 
96 lines changed or deleted 98 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/