LocationDialog.cpp   LocationDialog.cpp 
skipping to change at line 44 skipping to change at line 44
#include "StelGui.hpp" #include "StelGui.hpp"
#include "StelGuiItems.hpp" #include "StelGuiItems.hpp"
#include <QSettings> #include <QSettings>
#include <QDebug> #include <QDebug>
#include <QFrame> #include <QFrame>
#include <QSortFilterProxyModel> #include <QSortFilterProxyModel>
#include <QTimer> #include <QTimer>
#include <QStringListModel> #include <QStringListModel>
LocationDialog::LocationDialog(QObject* parent) : StelDialog(parent), isEdi LocationDialog::LocationDialog(QObject* parent)
tingNew(false) : StelDialog(parent)
, isEditingNew(false)
, allModel(NULL)
, pickedModel(NULL)
, proxyModel(NULL)
{ {
dialogName = "Location";
ui = new Ui_locationDialogForm; ui = new Ui_locationDialogForm;
} }
LocationDialog::~LocationDialog() LocationDialog::~LocationDialog()
{ {
delete ui; delete ui;
} }
void LocationDialog::retranslate() void LocationDialog::retranslate()
{ {
skipping to change at line 81 skipping to change at line 87
// 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(retranslate())); 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->longitudeSpinBox->setMinimum(-180.0, true);
ui->longitudeSpinBox->setMaximum( 180.0, true);
ui->longitudeSpinBox->setWrapping(true);
ui->latitudeSpinBox->setDisplayFormat(AngleSpinBox::DMSSymbols); ui->latitudeSpinBox->setDisplayFormat(AngleSpinBox::DMSSymbols);
ui->latitudeSpinBox->setPrefixType(AngleSpinBox::Latitude); ui->latitudeSpinBox->setPrefixType(AngleSpinBox::Latitude);
ui->latitudeSpinBox->setMinimum(-90.0, true);
QSortFilterProxyModel *proxyModel = new QSortFilterProxyModel(this); ui->latitudeSpinBox->setMaximum( 90.0, true);
proxyModel->setSourceModel((QAbstractItemModel*)StelApp::getInstance ui->latitudeSpinBox->setWrapping(false);
().getLocationMgr().getModelAll());
//initialize list model
allModel = new QStringListModel(this);
pickedModel = new QStringListModel(this);
connect(&StelApp::getInstance().getLocationMgr(), SIGNAL(locationLis
tChanged()), this, SLOT(reloadLocations()));
reloadLocations();
proxyModel = new QSortFilterProxyModel(ui->citiesListView);
proxyModel->setSourceModel(allModel);
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);
#ifdef Q_OS_WIN #ifdef Q_OS_WIN
//Kinetic scrolling for tablet pc and pc //Kinetic scrolling for tablet pc and pc
QList<QWidget *> addscroll; QList<QWidget *> addscroll;
addscroll << ui->citiesListView; addscroll << ui->citiesListView;
installKineticScrolling(addscroll); installKineticScrolling(addscroll);
#endif #endif
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&)), connect(ui->citiesListView, SIGNAL(clicked(const QModelIndex&)),
this, SLOT(setPositionFromList(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->TitleBar, SIGNAL(movedTo(QPoint)), this, SLOT(handleMove dTo(QPoint)));
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()));
connect(ui->resetListPushButton, SIGNAL(clicked()), this, SLOT(reset CompleteList())); connect(ui->resetListPushButton, SIGNAL(clicked()), this, SLOT(reset CompleteList()));
connect(ui->countryNameComboBox, SIGNAL(activated(const QString &)), this, SLOT(filterSitesByCountry())); connect(ui->countryNameComboBox, SIGNAL(activated(const QString &)), this, SLOT(filterSitesByCountry()));
StelCore* core = StelApp::getInstance().getCore(); StelCore* core = StelApp::getInstance().getCore();
const StelLocation& currentLocation = core->getCurrentLocation(); const StelLocation& currentLocation = core->getCurrentLocation();
bool b = (currentLocation.getID() == core->getDefaultLocationID()); bool b = (currentLocation.getID() == core->getDefaultLocationID());
skipping to change at line 137 skipping to change at line 155
connect(ui->useAsDefaultLocationCheckBox, SIGNAL(clicked(bool)), thi s, SLOT(setDefaultLocation(bool))); connect(ui->useAsDefaultLocationCheckBox, SIGNAL(clicked(bool)), thi s, SLOT(setDefaultLocation(bool)));
connect(ui->pushButtonReturnToDefault, SIGNAL(clicked()), core, SLOT (returnToDefaultLocation())); connect(ui->pushButtonReturnToDefault, SIGNAL(clicked()), core, SLOT (returnToDefaultLocation()));
connectEditSignals(); connectEditSignals();
connect(core, SIGNAL(locationChanged(StelLocation)), this, SLOT(upda teFromProgram(StelLocation))); connect(core, SIGNAL(locationChanged(StelLocation)), this, SLOT(upda teFromProgram(StelLocation)));
ui->citySearchLineEdit->setFocus(); ui->citySearchLineEdit->setFocus();
} }
void LocationDialog::reloadLocations()
{
allModel->setStringList(StelApp::getInstance().getLocationMgr().getA
llMap().keys());
}
// 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(const StelLocation& currentLocation) void LocationDialog::updateFromProgram(const StelLocation& currentLocation)
{ {
if (!dialog->isVisible()) if (!dialog->isVisible())
return; return;
StelCore* stelCore = StelApp::getInstance().getCore(); StelCore* stelCore = StelApp::getInstance().getCore();
isEditingNew = false; isEditingNew = false;
skipping to change at line 163 skipping to change at line 186
updateDefaultLocationControls(b); updateDefaultLocationControls(b);
ui->pushButtonReturnToDefault->setEnabled(!b); ui->pushButtonReturnToDefault->setEnabled(!b);
} }
const QString& key1 = currentLocation.getID(); const QString& key1 = currentLocation.getID();
const QString& key2 = locationFromFields().getID(); const QString& key2 = locationFromFields().getID();
if (key1!=key2) if (key1!=key2)
{ {
setFieldsFromLocation(currentLocation); setFieldsFromLocation(currentLocation);
} }
LandscapeMgr *lmgr = GETSTELMODULE(LandscapeMgr);
if (lmgr->getFlagUseLightPollutionFromDatabase())
{
int bidx = currentLocation.bortleScaleIndex;
if (!currentLocation.planetName.contains("Earth")) // locati
on not on Earth...
bidx = 1;
if (bidx<1) // ...or it observatory, or it unknown location
bidx = currentLocation.DEFAULT_BORTLE_SCALE_INDEX;
stelCore->getSkyDrawer()->setBortleScaleIndex(bidx);
lmgr->setAtmosphereBortleLightPollution(bidx);
}
} }
void LocationDialog::disconnectEditSignals() void LocationDialog::disconnectEditSignals()
{ {
disconnect(ui->longitudeSpinBox, SIGNAL(valueChanged()), this, SLOT( setPositionFromCoords())); disconnect(ui->longitudeSpinBox, SIGNAL(valueChanged()), this, SLOT( setPositionFromCoords()));
disconnect(ui->latitudeSpinBox, SIGNAL(valueChanged()), this, SLOT(s etPositionFromCoords())); disconnect(ui->latitudeSpinBox, SIGNAL(valueChanged()), this, SLOT(s etPositionFromCoords()));
disconnect(ui->altitudeSpinBox, SIGNAL(valueChanged(int)), this, SLO T(setPositionFromCoords(int))); disconnect(ui->altitudeSpinBox, SIGNAL(valueChanged(int)), this, SLO T(setPositionFromCoords(int)));
disconnect(ui->planetNameComboBox, SIGNAL(currentIndexChanged(const QString&)), this, SLOT(moveToAnotherPlanet(const QString&))); disconnect(ui->planetNameComboBox, SIGNAL(currentIndexChanged(const QString&)), this, SLOT(moveToAnotherPlanet(const QString&)));
disconnect(ui->countryNameComboBox, SIGNAL(currentIndexChanged(const QString&)), this, SLOT(reportEdit())); disconnect(ui->countryNameComboBox, SIGNAL(currentIndexChanged(const QString&)), this, SLOT(reportEdit()));
disconnect(ui->cityNameLineEdit, SIGNAL(textEdited(const QString&)), this, SLOT(reportEdit())); disconnect(ui->cityNameLineEdit, SIGNAL(textEdited(const QString&)), this, SLOT(reportEdit()));
skipping to change at line 275 skipping to change at line 286
{ {
QString path = StelFileMgr::findFile("textures/"+p-> getTextMapName()); QString path = StelFileMgr::findFile("textures/"+p-> getTextMapName());
if (path.isEmpty()) if (path.isEmpty())
{ {
qWarning() << "ERROR - could not find planet map for " << loc.planetName; qWarning() << "ERROR - could not find planet map for " << loc.planetName;
return; return;
} }
pixmap = QPixmap(path); pixmap = QPixmap(path);
} }
} }
StelCore * core = StelApp::getInstance().getCore();
pixmap.setDevicePixelRatio(core->getCurrentStelProjectorParams().dev
icePixelsPerPixel);
ui->mapLabel->setPixmap(pixmap); ui->mapLabel->setPixmap(pixmap);
// For caching // For caching
lastPlanet = loc.planetName; lastPlanet = loc.planetName;
} }
void LocationDialog::populatePlanetList() void LocationDialog::populatePlanetList()
{ {
Q_ASSERT(ui->planetNameComboBox); Q_ASSERT(ui->planetNameComboBox);
QComboBox* planets = ui->planetNameComboBox; QComboBox* planets = ui->planetNameComboBox;
skipping to change at line 374 skipping to change at line 387
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.);
// GZ: Filter location list for nearby sites. I assume Earth locatio ns are better known. With only few locations on other planets in the list, 30 degrees seem OK. // GZ: Filter location list for nearby sites. I assume Earth locatio ns are better known. With only few locations on other planets in the list, 30 degrees seem OK.
StelApp::getInstance().getLocationMgr().pickLocationsNearby(loc.plan LocationMap results = StelApp::getInstance().getLocationMgr().pickLo
etName, longitude, latitude, loc.planetName=="Earth" ? 3.0f: 30.0f); cationsNearby(loc.planetName, longitude, latitude, loc.planetName=="Earth"
QSortFilterProxyModel *proxyModel = new QSortFilterProxyModel(this); ? 3.0f: 30.0f);
proxyModel->setSourceModel((QAbstractItemModel*)StelApp::getInstance pickedModel->setStringList(results.keys());
().getLocationMgr().getModelPicked()); proxyModel->setSourceModel(pickedModel);
proxyModel->sort(0, Qt::AscendingOrder); proxyModel->sort(0, Qt::AscendingOrder);
proxyModel->setFilterCaseSensitivity(Qt::CaseInsensitive);
ui->citiesListView->setModel(proxyModel);
ui->citySearchLineEdit->clear(); ui->citySearchLineEdit->clear();
connect(ui->citySearchLineEdit, SIGNAL(textChanged(const QString&)), proxyModel, SLOT(setFilterWildcard(const QString&)));
} }
// Called when the planet name is changed by hand // Called when the planet name is changed by hand
void LocationDialog::moveToAnotherPlanet(const QString&) void LocationDialog::moveToAnotherPlanet(const QString&)
{ {
reportEdit(); reportEdit();
StelLocation loc = locationFromFields(); StelLocation loc = locationFromFields();
StelCore* stelCore = StelApp::getInstance().getCore(); StelCore* stelCore = StelApp::getInstance().getCore();
LandscapeMgr* ls = GETSTELMODULE(LandscapeMgr); LandscapeMgr* ls = GETSTELMODULE(LandscapeMgr);
if (loc.planetName != stelCore->getCurrentLocation().planetName) if (loc.planetName != stelCore->getCurrentLocation().planetName)
skipping to change at line 406 skipping to change at line 416
// If we have a landscape for selected planet then s et it, otherwise use default landscape // If we have a landscape for selected planet then s et it, otherwise use default landscape
// Details: https://bugs.launchpad.net/stellarium/+b ug/1173254 // Details: https://bugs.launchpad.net/stellarium/+b ug/1173254
if (ls->getAllLandscapeNames().indexOf(loc.planetNam e)>0) if (ls->getAllLandscapeNames().indexOf(loc.planetNam e)>0)
ls->setCurrentLandscapeName(loc.planetName); ls->setCurrentLandscapeName(loc.planetName);
else else
ls->setCurrentLandscapeID(ls->getDefaultLand scapeID()); ls->setCurrentLandscapeID(ls->getDefaultLand scapeID());
} }
// GZ populate site list with sites only from that planet, o r full list for Earth (faster than removing the ~50 non-Earth positions...) . // GZ populate site list with sites only from that planet, o r full list for Earth (faster than removing the ~50 non-Earth positions...) .
StelLocationMgr &locMgr=StelApp::getInstance().getLocationMg r(); StelLocationMgr &locMgr=StelApp::getInstance().getLocationMg r();
QSortFilterProxyModel *proxyModel = new QSortFilterProxyMode l(this);
if (loc.planetName == "Earth") if (loc.planetName == "Earth")
{ {
proxyModel->setSourceModel((QAbstractItemModel*)locM gr.getModelAll()); proxyModel->setSourceModel(allModel);
} }
else else
{ {
locMgr.pickLocationsNearby(loc.planetName, 0.0f, 0.0 LocationMap results = locMgr.pickLocationsNearby(loc
f, 180.0f); .planetName, 0.0f, 0.0f, 180.0f);
proxyModel->setSourceModel((QAbstractItemModel*)locM pickedModel->setStringList(results.keys());
gr.getModelPicked()); proxyModel->setSourceModel(pickedModel);
} }
proxyModel->sort(0, Qt::AscendingOrder); proxyModel->sort(0, Qt::AscendingOrder);
proxyModel->setFilterCaseSensitivity(Qt::CaseInsensitive);
ui->citiesListView->setModel(proxyModel);
ui->citySearchLineEdit->clear(); ui->citySearchLineEdit->clear();
connect(ui->citySearchLineEdit, SIGNAL(textChanged(const QSt ring&)), proxyModel, SLOT(setFilterWildcard(const QString&)));
ui->citySearchLineEdit->setFocus(); ui->citySearchLineEdit->setFocus();
} }
// Planet transition time also set to null to prevent uglyness when // Planet transition time also set to null to prevent uglyness when
// "use landscape location" is enabled for that planet's landscape. --BM // "use landscape location" is enabled for that planet's landscape. --BM
// NOTE: I think it also makes sense in the other cases. --BM // NOTE: I think it also makes sense in the other cases. --BM
// FIXME: Avoid the unnecessary change of the location anyway. --BM // FIXME: Avoid the unnecessary change of the location anyway. --BM
stelCore->moveObserverTo(loc, 0., 0.); stelCore->moveObserverTo(loc, 0., 0.);
} }
void LocationDialog::setPositionFromCoords(int ) void LocationDialog::setPositionFromCoords(int )
skipping to change at line 534 skipping to change at line 541
void LocationDialog::updateDefaultLocationControls(bool currentIsDefault) void LocationDialog::updateDefaultLocationControls(bool currentIsDefault)
{ {
ui->useAsDefaultLocationCheckBox->setChecked(currentIsDefault); ui->useAsDefaultLocationCheckBox->setChecked(currentIsDefault);
ui->useAsDefaultLocationCheckBox->setEnabled(!currentIsDefault); ui->useAsDefaultLocationCheckBox->setEnabled(!currentIsDefault);
} }
// called when the user clicks on the IP Query button // called when the user clicks on the IP Query button
void LocationDialog::ipQueryLocation(bool state) void LocationDialog::ipQueryLocation(bool state)
{ {
QSettings* conf = StelApp::getInstance().getSettings();
if (state) if (state)
{ {
QSettings* conf = StelApp::getInstance().getSettings();
conf->setValue("init_location/location", "auto"); conf->setValue("init_location/location", "auto");
disconnectEditSignals(); disconnectEditSignals();
resetCompleteList(); // in case we are on Moon/Mars, we must get list back to show all (earth) locations... resetCompleteList(); // in case we are on Moon/Mars, we must get list back to show all (earth) locations...
StelLocationMgr &locMgr=StelApp::getInstance().getLocationMg r(); StelLocationMgr &locMgr=StelApp::getInstance().getLocationMg r();
locMgr.locationFromIP(); // This just triggers asynchronous lookup. locMgr.locationFromIP(); // This just triggers asynchronous lookup.
ui->useAsDefaultLocationCheckBox->setChecked(!state); ui->useAsDefaultLocationCheckBox->setChecked(!state);
ui->pushButtonReturnToDefault->setEnabled(!state); ui->pushButtonReturnToDefault->setEnabled(!state);
connectEditSignals(); connectEditSignals();
ui->citySearchLineEdit->setFocus(); ui->citySearchLineEdit->setFocus();
} }
else
conf->setValue("init_location/location", StelApp::getInstanc
e().getCore()->getCurrentLocation().getID());
} }
// called when user clicks "reset list" // called when user clicks "reset list"
void LocationDialog::resetCompleteList() void LocationDialog::resetCompleteList()
{ {
QSortFilterProxyModel *proxyModel = new QSortFilterProxyModel(this); //reset search before setting model, prevents unnecessary search in
proxyModel->setSourceModel((QAbstractItemModel*)StelApp::getInstance full list
().getLocationMgr().getModelAll());
proxyModel->sort(0, Qt::AscendingOrder);
proxyModel->setFilterCaseSensitivity(Qt::CaseInsensitive);
ui->citiesListView->setModel(proxyModel);
ui->citySearchLineEdit->clear(); ui->citySearchLineEdit->clear();
connect(ui->citySearchLineEdit, SIGNAL(textChanged(const QString&)), proxyModel, SLOT(setFilterWildcard(const QString&)));
ui->citySearchLineEdit->setFocus(); ui->citySearchLineEdit->setFocus();
proxyModel->setSourceModel(allModel);
proxyModel->sort(0, Qt::AscendingOrder);
} }
// called when user clicks in the country combobox and selects a country. T he locations in the list are updated to select only sites in that country. // called when user clicks in the country combobox and selects a country. T he locations in the list are updated to select only sites in that country.
void LocationDialog::filterSitesByCountry() void LocationDialog::filterSitesByCountry()
{ {
QString country=ui->countryNameComboBox->currentData().toString(); QString country=ui->countryNameComboBox->currentData().toString();
QSortFilterProxyModel *proxyModel = new QSortFilterProxyModel(this);
StelLocationMgr &locMgr=StelApp::getInstance().getLocationMgr(); StelLocationMgr &locMgr=StelApp::getInstance().getLocationMgr();
locMgr.pickLocationsInCountry(country); LocationMap results = locMgr.pickLocationsInCountry(country);
proxyModel->setSourceModel((QAbstractItemModel*)locMgr.getModelPicke pickedModel->setStringList(results.keys());
d()); proxyModel->setSourceModel(pickedModel);
proxyModel->sort(0, Qt::AscendingOrder); proxyModel->sort(0, Qt::AscendingOrder);
proxyModel->setFilterCaseSensitivity(Qt::CaseInsensitive);
ui->citiesListView->setModel(proxyModel);
ui->citySearchLineEdit->clear(); ui->citySearchLineEdit->clear();
connect(ui->citySearchLineEdit, SIGNAL(textChanged(const QString&)), proxyModel, SLOT(setFilterWildcard(const QString&)));
ui->citySearchLineEdit->setFocus(); ui->citySearchLineEdit->setFocus();
} }
 End of changes. 27 change blocks. 
53 lines changed or deleted 55 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/