LocationDialog.cpp   LocationDialog.cpp 
skipping to change at line 23 skipping to change at line 23
* 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, U SA.
*/ */
#include "Dialog.hpp" #include "Dialog.hpp"
#include "LocationDialog.hpp" #include "LocationDialog.hpp"
#include "StelMainGraphicsView.hpp" #include "StelMainGraphicsView.hpp"
#include "LocationMgr.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 "Navigator.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 <QSettings> #include <QSettings>
#include <QDebug> #include <QDebug>
#include <QFrame> #include <QFrame>
#include <QSortFilterProxyModel> #include <QSortFilterProxyModel>
skipping to change at line 62 skipping to change at line 62
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 ation()->getCurrentLocation()); setMapForLocation(StelApp::getInstance().getCore()->getNavig ator()->getCurrentLocation());
} }
// 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);
// Init the SpinBox entries // Init the SpinBox entries
ui->longitudeSpinBox->setDisplayFormat(AngleSpinBox::DMSSymbols); ui->longitudeSpinBox->setDisplayFormat(AngleSpinBox::DMSSymbols);
skipping to change at line 98 skipping to change at line 98
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()->getNavigatio n()->getCurrentLocation()); setFieldsFromLocation(StelApp::getInstance().getCore()->getNavigator ()->getCurrentLocation());
const bool b = StelApp::getInstance().getCore()->getNavigation()->ge const bool b = StelApp::getInstance().getCore()->getNavigator()->get
tCurrentLocation().getID() CurrentLocation().getID()
==StelApp::getInstance().getCore()->getNavigation()- ==StelApp::getInstance().getCore()->getNavigator()->
>getDefaultLocationID(); getDefaultLocationID();
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();
} }
// 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()->getNavigation()->ge const bool b = StelApp::getInstance().getCore()->getNavigator()->get
tCurrentLocation().getID() CurrentLocation().getID()
==StelApp::getInstance().getCore()->getNavigation()- ==StelApp::getInstance().getCore()->getNavigator()->
>getDefaultLocationID(); 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);
} }
if (isEditingNew==true) // removing this check and return... we might have the location chan
return; ged
const QString& key1 = StelApp::getInstance().getCore()->getNavigatio // by a script or plugin, and as such we should update the map whene
n()->getCurrentLocation().getID(); ver the
// location window is visible.
//if (isEditingNew==true)
// return;
const QString& key1 = StelApp::getInstance().getCore()->getNavigator
()->getCurrentLocation().getID();
const QString& key2 = locationFromFields().getID(); const QString& key2 = locationFromFields().getID();
if (key1!=key2) if (key1!=key2)
{ {
setFieldsFromLocation(StelApp::getInstance().getCore()->getN avigation()->getCurrentLocation()); setFieldsFromLocation(StelApp::getInstance().getCore()->getN avigator()->getCurrentLocation());
} }
} }
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 160 skipping to change at line 166
{ {
connect(ui->longitudeSpinBox, SIGNAL(valueChanged()), this, SLOT(spi nBoxChanged())); connect(ui->longitudeSpinBox, SIGNAL(valueChanged()), this, SLOT(spi nBoxChanged()));
connect(ui->latitudeSpinBox, SIGNAL(valueChanged()), this, SLOT(spin BoxChanged())); connect(ui->latitudeSpinBox, SIGNAL(valueChanged()), this, SLOT(spin BoxChanged()));
connect(ui->altitudeSpinBox, SIGNAL(valueChanged(int)), this, SLOT(s pinBoxChanged(int))); connect(ui->altitudeSpinBox, SIGNAL(valueChanged(int)), this, SLOT(s pinBoxChanged(int)));
connect(ui->planetNameComboBox, SIGNAL(currentIndexChanged(const QSt ring&)), this, SLOT(comboBoxChanged(const QString&))); connect(ui->planetNameComboBox, SIGNAL(currentIndexChanged(const QSt ring&)), this, SLOT(comboBoxChanged(const QString&)));
connect(ui->countryNameComboBox, SIGNAL(currentIndexChanged(const QS tring&)), this, SLOT(comboBoxChanged(const QString&))); connect(ui->countryNameComboBox, SIGNAL(currentIndexChanged(const QS tring&)), this, SLOT(comboBoxChanged(const QString&)));
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 Location& 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->findText(loc.country);
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);
skipping to change at line 196 skipping to change at line 202
// 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
connectEditSignals(); connectEditSignals();
} }
// Update the map for the given location. // Update the map for the given location.
void LocationDialog::setMapForLocation(const Location& 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;
QPixmap pixmap; QPixmap pixmap;
QString path; QString path;
// Try to set the proper planet map image // Try to set the proper planet map image
if (loc.planetName=="Earth") if (loc.planetName=="Earth")
{ {
skipping to change at line 252 skipping to change at line 258
else else
{ {
ui->mapLabel->setPixmap(pixmap); ui->mapLabel->setPixmap(pixmap);
} }
// For caching // For caching
lastPlanet = loc.planetName; lastPlanet = loc.planetName;
lastVisionMode = StelApp::getInstance().getVisionModeNight(); lastVisionMode = StelApp::getInstance().getVisionModeNight();
} }
// Create a Location instance from the fields // Create a StelLocation instance from the fields
Location LocationDialog::locationFromFields() const StelLocation LocationDialog::locationFromFields() const
{ {
Location loc; StelLocation loc;
loc.planetName = ui->planetNameComboBox->currentText(); loc.planetName = ui->planetNameComboBox->currentText();
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);
Location loc = StelApp::getInstance().getLocationMgr().locationForSm allString(index.data().toString()); StelLocation loc = StelApp::getInstance().getLocationMgr().locationF orSmallString(index.data().toString());
setFieldsFromLocation(loc); setFieldsFromLocation(loc);
StelApp::getInstance().getCore()->getNavigation()->moveObserverTo(lo c, 0.); StelApp::getInstance().getCore()->getNavigator()->moveObserverTo(loc , 0.);
const bool b = loc.getID()==StelApp::getInstance().getCore()->getNav igation()->getDefaultLocationID(); const bool b = loc.getID()==StelApp::getInstance().getCore()->getNav igator()->getDefaultLocationID();
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();
Location loc = locationFromFields(); StelLocation loc = locationFromFields();
loc.latitude = latitude; loc.latitude = latitude;
loc.longitude = longitude; loc.longitude = longitude;
setFieldsFromLocation(loc); setFieldsFromLocation(loc);
StelApp::getInstance().getCore()->getNavigation()->moveObserverTo(lo c, 0.); StelApp::getInstance().getCore()->getNavigator()->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& text) void LocationDialog::comboBoxChanged(const QString& text)
{ {
reportEdit(); reportEdit();
Location loc = locationFromFields(); StelLocation loc = locationFromFields();
if (loc.planetName!=StelApp::getInstance().getCore()->getNavigation( if (loc.planetName!=StelApp::getInstance().getCore()->getNavigator()
)->getCurrentLocation().planetName) ->getCurrentLocation().planetName)
setFieldsFromLocation(loc); setFieldsFromLocation(loc);
StelApp::getInstance().getCore()->getNavigation()->moveObserverTo(lo c, 0.); StelApp::getInstance().getCore()->getNavigator()->moveObserverTo(loc , 0.);
} }
void LocationDialog::spinBoxChanged(int i) void LocationDialog::spinBoxChanged(int i)
{ {
reportEdit(); reportEdit();
Location loc = locationFromFields(); StelLocation loc = locationFromFields();
StelApp::getInstance().getCore()->getNavigation()->moveObserverTo(lo StelApp::getInstance().getCore()->getNavigator()->moveObserverTo(loc
c, 0.); , 0.);
} }
// Called when the location name is manually changed // Called when the location name is manually changed
void LocationDialog::locationNameChanged(const QString& text) void LocationDialog::locationNameChanged(const QString& text)
{ {
reportEdit(); 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;
} }
Location loc = locationFromFields(); StelLocation loc = locationFromFields();
if (!StelApp::getInstance().getLocationMgr().canSaveUserLocation(loc )) if (!StelApp::getInstance().getLocationMgr().canSaveUserLocation(loc ))
{ {
ui->cityNameLineEdit->setText("New Location"); ui->cityNameLineEdit->setText("New Location");
ui->cityNameLineEdit->selectAll(); ui->cityNameLineEdit->selectAll();
loc = locationFromFields(); loc = locationFromFields();
} }
ui->addLocationToListPushButton->setEnabled(isEditingNew && StelApp: :getInstance().getLocationMgr().canSaveUserLocation(loc)); ui->addLocationToListPushButton->setEnabled(isEditingNew && StelApp: :getInstance().getLocationMgr().canSaveUserLocation(loc));
ui->deleteLocationFromListPushButton->setEnabled(StelApp::getInstanc e().getLocationMgr().canDeleteUserLocation(loc.getID())); ui->deleteLocationFromListPushButton->setEnabled(StelApp::getInstanc e().getLocationMgr().canDeleteUserLocation(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 Location& 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)
skipping to change at line 359 skipping to change at line 365
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()->getNavigation()->setDefaultLocatio StelApp::getInstance().getCore()->getNavigator()->setDefaultLocation
nID(StelApp::getInstance().getCore()->getNavigation()->getCurrentLocation() ID(StelApp::getInstance().getCore()->getNavigator()->getCurrentLocation().g
.getID()); etID());
const bool b = StelApp::getInstance().getCore()->getNavigation()->ge const bool b = StelApp::getInstance().getCore()->getNavigator()->get
tCurrentLocation().getID()== CurrentLocation().getID()==
StelApp::getInstance().getCore()->getNavigation()->g StelApp::getInstance().getCore()->getNavigator()->ge
etDefaultLocationID(); 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 Location& loc = locationFromFields(); const StelLocation& loc = locationFromFields();
StelApp::getInstance().getLocationMgr().deleteUserLocation(loc.getID ()); StelApp::getInstance().getLocationMgr().deleteUserLocation(loc.getID ());
} }
 End of changes. 25 change blocks. 
44 lines changed or deleted 52 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/