SatellitesDialog.cpp   SatellitesDialog.cpp 
skipping to change at line 22 skipping to change at line 22
* 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., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA. * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA.
*/ */
#include <QDebug> #include <QDebug>
#include <QTimer>
#include <QDateTime> #include <QDateTime>
#include <QUrl>
#include <QFileDialog> #include <QFileDialog>
#include <QSortFilterProxyModel>
#include <QStandardItemModel>
#include <QTimer>
#include <QUrl>
#include "StelApp.hpp" #include "StelApp.hpp"
#include "ui_satellitesDialog.h" #include "ui_satellitesDialog.h"
#include "SatellitesDialog.hpp" #include "SatellitesDialog.hpp"
#include "SatellitesImportDialog.hpp" #include "SatellitesImportDialog.hpp"
#include "Satellites.hpp" #include "Satellites.hpp"
#include "StelModuleMgr.hpp" #include "StelModuleMgr.hpp"
#include "StelObjectMgr.hpp" #include "StelObjectMgr.hpp"
#include "StelMovementMgr.hpp" #include "StelMovementMgr.hpp"
#include "StelStyle.hpp" #include "StelStyle.hpp"
#include "StelGui.hpp" #include "StelGui.hpp"
#include "StelMainGraphicsView.hpp" #include "StelMainGraphicsView.hpp"
#include "StelFileMgr.hpp" #include "StelFileMgr.hpp"
#include "StelTranslator.hpp" #include "StelTranslator.hpp"
SatellitesDialog::SatellitesDialog() : updateTimer(NULL), importWindow(0) SatellitesDialog::SatellitesDialog() :
updateTimer(0),
importWindow(0),
satellitesModel(0),
filterProxyModel(0)
{ {
ui = new Ui_satellitesDialog; ui = new Ui_satellitesDialog;
satellitesModel = new QStandardItemModel(this);
} }
SatellitesDialog::~SatellitesDialog() SatellitesDialog::~SatellitesDialog()
{ {
if (updateTimer) if (updateTimer)
{ {
updateTimer->stop(); updateTimer->stop();
delete updateTimer; delete updateTimer;
updateTimer = NULL; updateTimer = NULL;
} }
skipping to change at line 121 skipping to change at line 129
ui->orbitSegmentsSpin->setValue(Satellite::orbitLineSegments); ui->orbitSegmentsSpin->setValue(Satellite::orbitLineSegments);
ui->orbitFadeSpin->setValue(Satellite::orbitLineFadeSegments); ui->orbitFadeSpin->setValue(Satellite::orbitLineFadeSegments);
ui->orbitDurationSpin->setValue(Satellite::orbitLineSegmentDuration) ; ui->orbitDurationSpin->setValue(Satellite::orbitLineSegmentDuration) ;
connect(ui->orbitLinesGroup, SIGNAL(toggled(bool)), GETSTELMODULE(Sa tellites), SLOT(setOrbitLinesFlag(bool))); connect(ui->orbitLinesGroup, SIGNAL(toggled(bool)), GETSTELMODULE(Sa tellites), SLOT(setOrbitLinesFlag(bool)));
connect(ui->orbitSegmentsSpin, SIGNAL(valueChanged(int)), this, SLOT (setOrbitParams())); connect(ui->orbitSegmentsSpin, SIGNAL(valueChanged(int)), this, SLOT (setOrbitParams()));
connect(ui->orbitFadeSpin, SIGNAL(valueChanged(int)), this, SLOT(set OrbitParams())); connect(ui->orbitFadeSpin, SIGNAL(valueChanged(int)), this, SLOT(set OrbitParams()));
connect(ui->orbitDurationSpin, SIGNAL(valueChanged(int)), this, SLOT (setOrbitParams())); connect(ui->orbitDurationSpin, SIGNAL(valueChanged(int)), this, SLOT (setOrbitParams()));
// Satellites tab // Satellites tab
connect(ui->satellitesList, filterProxyModel = new QSortFilterProxyModel(this);
SIGNAL(currentItemChanged(QListWidgetItem*,QListWidgetItem*) filterProxyModel->setSourceModel(satellitesModel);
), filterProxyModel->setFilterCaseSensitivity(Qt::CaseInsensitive);
this, ui->satellitesList->setModel(filterProxyModel);
SLOT(updateSelectedSatelliteInfo(QListWidgetItem*,QListWidge connect(ui->lineEditSearch, SIGNAL(textEdited(QString)),
tItem*))); filterProxyModel, SLOT(setFilterWildcard(QString)));
connect(ui->satellitesList, SIGNAL(itemDoubleClicked(QListWidgetItem
*)), this, SLOT(satelliteDoubleClick(QListWidgetItem*))); QItemSelectionModel* selectionModel = ui->satellitesList->selectionM
odel();
connect(selectionModel, SIGNAL(currentRowChanged(QModelIndex,QModelI
ndex)),
this, SLOT(updateSelectedInfo(QModelIndex,QModelIndex)));
connect(ui->satellitesList, SIGNAL(doubleClicked(QModelIndex)),
this, SLOT(handleDoubleClick(QModelIndex)));
connect(ui->groupsCombo, SIGNAL(currentIndexChanged(int)), this, SLO T(listSatelliteGroup(int))); connect(ui->groupsCombo, SIGNAL(currentIndexChanged(int)), this, SLO T(listSatelliteGroup(int)));
connect(ui->saveSatellitesButton, SIGNAL(clicked()), this, SLOT(save Satellites())); connect(ui->saveSatellitesButton, SIGNAL(clicked()), this, SLOT(save Satellites()));
connect(ui->removeSatellitesButton, SIGNAL(clicked()), this, SLOT(re moveSatellites())); connect(ui->removeSatellitesButton, SIGNAL(clicked()), this, SLOT(re moveSatellites()));
connectSatelliteGuiForm(); connectSatelliteGuiForm();
importWindow = new SatellitesImportDialog(); importWindow = new SatellitesImportDialog();
connect(ui->addSatellitesButton, SIGNAL(clicked()), connect(ui->addSatellitesButton, SIGNAL(clicked()),
importWindow, SLOT(setVisible())); importWindow, SLOT(setVisible()));
connect(importWindow, SIGNAL(satellitesAccepted(TleDataList)), connect(importWindow, SIGNAL(satellitesAccepted(TleDataList)),
this, SLOT(addSatellites(TleDataList))); this, SLOT(addSatellites(TleDataList)));
skipping to change at line 152 skipping to change at line 167
// About tab // About tab
setAboutHtml(); setAboutHtml();
updateGuiFromSettings(); updateGuiFromSettings();
} }
void SatellitesDialog::listSatelliteGroup(int index) void SatellitesDialog::listSatelliteGroup(int index)
{ {
QItemSelectionModel* selectionModel = ui->satellitesList->selectionM
odel();
QModelIndexList selectedIndexes = selectionModel->selectedRows();
QVariantList prevMultiSelection; QVariantList prevMultiSelection;
foreach (QListWidgetItem* i, ui->satellitesList->selectedItems()) foreach (const QModelIndex& index, selectedIndexes)
{ {
prevMultiSelection << i->data(Qt::UserRole); prevMultiSelection << index.data(Qt::UserRole);
} }
ui->satellitesList->clear(); satellitesModel->clear();
QHash<QString,QString> satellites; QHash<QString,QString> satellites;
Satellites* plugin = GETSTELMODULE(Satellites); Satellites* plugin = GETSTELMODULE(Satellites);
QString selectedGroup = ui->groupsCombo->itemData(index).toString(); QString selectedGroup = ui->groupsCombo->itemData(index).toString();
if (selectedGroup == "all") if (selectedGroup == "all")
satellites = plugin->getSatellites(); satellites = plugin->getSatellites();
else if (selectedGroup == "visible") else if (selectedGroup == "visible")
satellites = plugin->getSatellites(QString(), Satellites::Vi sible); satellites = plugin->getSatellites(QString(), Satellites::Vi sible);
else if (selectedGroup == "notvisible") else if (selectedGroup == "notvisible")
satellites = plugin->getSatellites(QString(), Satellites::No tVisible); satellites = plugin->getSatellites(QString(), Satellites::No tVisible);
else if (selectedGroup == "newlyadded") else if (selectedGroup == "newlyadded")
satellites = plugin->getSatellites(QString(), Satellites::Ne wlyAdded); satellites = plugin->getSatellites(QString(), Satellites::Ne wlyAdded);
else if (selectedGroup == "orbiterror") else if (selectedGroup == "orbiterror")
satellites = plugin->getSatellites(QString(), Satellites::Or bitError); satellites = plugin->getSatellites(QString(), Satellites::Or bitError);
else else
satellites = plugin->getSatellites(ui->groupsCombo->currentT ext()); satellites = plugin->getSatellites(ui->groupsCombo->currentT ext());
ui->satellitesList->setSortingEnabled(false); //satellitesModel->->setSortingEnabled(false);
QHashIterator<QString,QString> i(satellites); QHashIterator<QString,QString> i(satellites);
while (i.hasNext()) while (i.hasNext())
{ {
i.next(); i.next();
QListWidgetItem* item = new QListWidgetItem(i.value()); QStandardItem* item = new QStandardItem(i.value());
item->setData(Qt::UserRole, i.key()); item->setData(i.key(), Qt::UserRole);
ui->satellitesList->addItem(item); item->setEditable(false);
} satellitesModel->appendRow(item);
ui->satellitesList->sortItems();
// If any previously selected items are still in the list after the // If a previously selected item is still in the list after
update, select them, the update, select it
QListWidgetItem* item; if (prevMultiSelection.contains(i.key()))
for (int i=0; (item = ui->satellitesList->item(i))!=NULL; i++) {
{ QModelIndex index = filterProxyModel->mapFromSource(
QVariant id = item->data(Qt::UserRole); item->index());
if (prevMultiSelection.contains(id)) //QModelIndex index = item->index();
item->setSelected(true); selectionModel->select(index, QItemSelectionModel::S
electCurrent);
}
} }
// Sort the main list (don't sort the filter model directly,
// or the displayed list will be scrambled on emptying the filter).
satellitesModel->sort(0);
QList<QListWidgetItem*> selectedItems = ui->satellitesList->selected if (selectionModel->hasSelection())
Items();
if (selectedItems.count() > 0)
{ {
// make sure the first selected item is visible... //TODO: This is stupid...
ui->satellitesList->scrollToItem(selectedItems.at(0)); for (int row = 0; row < ui->satellitesList->model()->rowCoun
t(); row++)
{
QModelIndex index = ui->satellitesList->model()->ind
ex(row, 0);
if (selectionModel->isSelected(index))
{
ui->satellitesList->scrollTo(index, QAbstrac
tItemView::PositionAtTop);
break;
}
}
} }
else if (ui->satellitesList->count() > 0) else if (ui->satellitesList->model()->rowCount() > 0)
{ {
// otherwise if there are any items in the listbox, select t // If there are any items in the listbox, scroll to the top
he first and scroll to the top QModelIndex index = ui->satellitesList->model()->index(0, 0)
ui->satellitesList->setCurrentRow(0); ;
ui->satellitesList->scrollToTop(); selectionModel->setCurrentIndex(index, QItemSelectionModel::
NoUpdate);
ui->satellitesList->scrollTo(index, QAbstractItemView::Posit
ionAtTop);
} }
} }
void SatellitesDialog::reloadSatellitesList() void SatellitesDialog::reloadSatellitesList()
{ {
listSatelliteGroup(ui->groupsCombo->currentIndex()); listSatelliteGroup(ui->groupsCombo->currentIndex());
} }
void SatellitesDialog::updateSelectedSatelliteInfo(QListWidgetItem* curItem void SatellitesDialog::updateSelectedInfo(const QModelIndex& curItem,
, const QModelIndex& prevItem)
QListWidgetItem* prevIte
m)
{ {
Q_UNUSED(prevItem); Q_UNUSED(prevItem);
if (!curItem) if (!curItem.isValid())
return; return;
QString id = curItem->data(Qt::UserRole).toString(); QString id = curItem.data(Qt::UserRole).toString();
if (id.isEmpty()) if (id.isEmpty())
return; return;
satelliteModified = false; satelliteModified = false;
SatelliteP sat = GETSTELMODULE(Satellites)->getByID(id); SatelliteP sat = GETSTELMODULE(Satellites)->getByID(id);
if (sat.isNull()) if (sat.isNull())
return; return;
if (!sat->initialized) if (!sat->initialized)
skipping to change at line 295 skipping to change at line 323
html += "<h3>" + q_("Adding new satellites") + "</h3>"; html += "<h3>" + q_("Adding new satellites") + "</h3>";
html += "<p>" + QString(q_("1. Make sure the satellite(s) you wish t o add are included in one of the URLs listed in the Sources tab of the sate llites configuration dialog. 2. Go to the Satellites tab, and click the '+' button. Select the satellite(s) you wish to add and select the \"add\" bu tton.")) + "</p>"; html += "<p>" + QString(q_("1. Make sure the satellite(s) you wish t o add are included in one of the URLs listed in the Sources tab of the sate llites configuration dialog. 2. Go to the Satellites tab, and click the '+' button. Select the satellite(s) you wish to add and select the \"add\" bu tton.")) + "</p>";
html += "<h3>" + q_("Technical notes") + "</h3>"; html += "<h3>" + q_("Technical notes") + "</h3>";
html += "<p>" + q_("Positions are calculated using the SGP4 & SDP4 m ethods, using NORAD TLE data as the input. "); html += "<p>" + q_("Positions are calculated using the SGP4 & SDP4 m ethods, using NORAD TLE data as the input. ");
html += q_("The orbital calculation code is written by Jose Luis Can ales according to the revised Spacetrack Report #3 (including Spacetrack Re port #6). "); html += q_("The orbital calculation code is written by Jose Luis Can ales according to the revised Spacetrack Report #3 (including Spacetrack Re port #6). ");
// TRANSLATORS: The numbers contain the opening and closing tag of a n HTML link // TRANSLATORS: The numbers contain the opening and closing tag of a n HTML link
html += QString(q_("See %1this document%2 for details.")).arg("<a hr ef=\"http://www.celestrak.com/publications/AIAA/2006-6753\">").arg("</a>") + "</p>"; html += QString(q_("See %1this document%2 for details.")).arg("<a hr ef=\"http://www.celestrak.com/publications/AIAA/2006-6753\">").arg("</a>") + "</p>";
html += "<h3>" + q_("Links") + "</h3>"; html += "<h3>" + q_("Links") + "</h3>";
html += "<p>" + q_("Support is provided via the Launchpad website. Be sure to put \"Satellites plugin\" in the subject when posting.") + "</p> "; html += "<p>" + QString(q_("Support is provided via the Launchpad we bsite. Be sure to put \"%1\" in the subject when posting.")).arg("Satellit es plugin") + "</p>";
html += "<p><ul>"; html += "<p><ul>";
// TRANSLATORS: The numbers contain the opening and closing tag of a n HTML link // TRANSLATORS: The numbers contain the opening and closing tag of a n HTML link
html += "<li>" + QString(q_("If you have a question, you can %1get a n answer here%2").arg("<a href=\"https://answers.launchpad.net/stellarium\" >")).arg("</a>") + "</li>"; html += "<li>" + QString(q_("If you have a question, you can %1get a n answer here%2").arg("<a href=\"https://answers.launchpad.net/stellarium\" >")).arg("</a>") + "</li>";
// TRANSLATORS: The numbers contain the opening and closing tag of a n HTML link // TRANSLATORS: The numbers contain the opening and closing tag of a n HTML link
html += "<li>" + QString(q_("Bug reports can be made %1here%2.")).ar g("<a href=\"https://bugs.launchpad.net/stellarium\">").arg("</a>") + "</li >"; html += "<li>" + QString(q_("Bug reports can be made %1here%2.")).ar g("<a href=\"https://bugs.launchpad.net/stellarium\">").arg("</a>") + "</li >";
// TRANSLATORS: The numbers contain the opening and closing tag of a n HTML link // TRANSLATORS: The numbers contain the opening and closing tag of a n HTML link
html += "<li>" + q_("If you would like to make a feature request, yo u can create a bug report, and set the severity to \"wishlist\".") + "</li> "; html += "<li>" + q_("If you would like to make a feature request, yo u can create a bug report, and set the severity to \"wishlist\".") + "</li> ";
html += "</ul></p></body></html>"; html += "</ul></p></body></html>";
StelGui* gui = dynamic_cast<StelGui*>(StelApp::getInstance().getGui( )); StelGui* gui = dynamic_cast<StelGui*>(StelApp::getInstance().getGui( ));
skipping to change at line 485 skipping to change at line 513
saveSatellites(); saveSatellites();
// Trigger re-loading the list to display the new satellites // Trigger re-loading the list to display the new satellites
int index = ui->groupsCombo->findData(QVariant("newlyadded")); int index = ui->groupsCombo->findData(QVariant("newlyadded"));
if (ui->groupsCombo->currentIndex() == index) if (ui->groupsCombo->currentIndex() == index)
listSatelliteGroup(index); listSatelliteGroup(index);
else else
ui->groupsCombo->setCurrentIndex(index); //Triggers the same operation ui->groupsCombo->setCurrentIndex(index); //Triggers the same operation
// Select the satellites that were added just now // Select the satellites that were added just now
QListWidget* list = ui->satellitesList; QItemSelectionModel* selectionModel = ui->satellitesList->selectionM
list->clearSelection(); odel();
int firstAddedIndex = -1; selectionModel->clearSelection();
QModelIndex firstSelectedIndex;
QSet<QString> newIds; QSet<QString> newIds;
foreach (const TleData& sat, newSatellites) foreach (const TleData& sat, newSatellites)
newIds.insert(sat.id); newIds.insert(sat.id);
for (int i = 0; i < list->count(); i++) for (int row = 0; row < ui->satellitesList->model()->rowCount(); row ++)
{ {
QString id = list->item(i)->data(Qt::UserRole).toString(); QModelIndex index = ui->satellitesList->model()->index(row,
0);
QString id = index.data(Qt::UserRole).toString();
if (newIds.remove(id)) if (newIds.remove(id))
{ {
list->item(i)->setSelected(true); selectionModel->select(index, QItemSelectionModel::S
if (firstAddedIndex < 0) elect);
firstAddedIndex = i; if (!firstSelectedIndex.isValid())
firstSelectedIndex = index;
} }
} }
if (firstAddedIndex >= 0) if (firstSelectedIndex.isValid())
list->scrollToItem(list->item(firstAddedIndex), ui->satellitesList->scrollTo(firstSelectedIndex, QAbstractIt
QAbstractItemView::PositionAtTop); emView::PositionAtTop);
else else
list->setCurrentRow(0); ui->satellitesList->scrollToTop();
} }
void SatellitesDialog::removeSatellites() void SatellitesDialog::removeSatellites()
{ {
QStringList idList; QStringList idList;
foreach (QListWidgetItem* i, ui->satellitesList->selectedItems()) QItemSelectionModel* selectionModel = ui->satellitesList->selectionM
odel();
QModelIndexList selectedIndexes = selectionModel->selectedRows();
foreach (const QModelIndex& index, selectedIndexes)
{ {
QString id = i->data(Qt::UserRole).toString(); QString id = index.data(Qt::UserRole).toString();
idList.append(id); idList.append(id);
} }
if (!idList.isEmpty()) if (!idList.isEmpty())
{ {
GETSTELMODULE(Satellites)->remove(idList); GETSTELMODULE(Satellites)->remove(idList);
reloadSatellitesList(); reloadSatellitesList();
saveSatellites(); saveSatellites();
} }
} }
void SatellitesDialog::setDisplayFlag(bool display) void SatellitesDialog::setDisplayFlag(bool display)
{ {
foreach (QListWidgetItem* i, ui->satellitesList->selectedItems()) QItemSelectionModel* selectionModel = ui->satellitesList->selectionM
odel();
QModelIndexList selectedIndexes = selectionModel->selectedRows();
foreach (const QModelIndex& index, selectedIndexes)
{ {
QString id = i->data(Qt::UserRole).toString(); QString id = index.data(Qt::UserRole).toString();
SatelliteP sat = GETSTELMODULE(Satellites)->getByID(id); SatelliteP sat = GETSTELMODULE(Satellites)->getByID(id);
sat->visible = display; if (sat)
sat->visible = display;
} }
reloadSatellitesList(); reloadSatellitesList();
} }
void SatellitesDialog::setOrbitFlag(bool display) void SatellitesDialog::setOrbitFlag(bool display)
{ {
foreach (QListWidgetItem* i, ui->satellitesList->selectedItems()) QItemSelectionModel* selectionModel = ui->satellitesList->selectionM
odel();
QModelIndexList selectedIndexes = selectionModel->selectedRows();
foreach (const QModelIndex& index, selectedIndexes)
{ {
QString id = i->data(Qt::UserRole).toString(); QString id = index.data(Qt::UserRole).toString();
SatelliteP sat = GETSTELMODULE(Satellites)->getByID(id); SatelliteP sat = GETSTELMODULE(Satellites)->getByID(id);
if (sat) if (sat)
sat->orbitVisible = display; sat->orbitVisible = display;
} }
reloadSatellitesList(); reloadSatellitesList();
} }
void SatellitesDialog::satelliteDoubleClick(QListWidgetItem* item) void SatellitesDialog::handleDoubleClick(const QModelIndex& index)
{ {
Satellites* SatellitesMgr = GETSTELMODULE(Satellites); Satellites* SatellitesMgr = GETSTELMODULE(Satellites);
Q_ASSERT(SatellitesMgr); Q_ASSERT(SatellitesMgr);
QString id = item->data(Qt::UserRole).toString(); QString id = index.data(Qt::UserRole).toString();
SatelliteP sat = SatellitesMgr->getByID(id); SatelliteP sat = SatellitesMgr->getByID(id);
if (sat.isNull()) if (sat.isNull())
return; return;
if (!sat->orbitValid) if (!sat->orbitValid)
return; return;
// Turn on Satellite rendering if it is not already on // Turn on Satellite rendering if it is not already on
sat->visible = true; sat->visible = true;
// If Satellites are not currently displayed, make them visible. // If Satellites are not currently displayed, make them visible.
if (!SatellitesMgr->getFlagHints()) if (!SatellitesMgr->getFlagHints())
{ {
StelGui* gui = dynamic_cast<StelGui*>(StelApp::getInstance() .getGui()); StelGui* gui = dynamic_cast<StelGui*>(StelApp::getInstance() .getGui());
QAction* setHintsAction = gui->getGuiActions("actionShow_Sat ellite_Hints"); QAction* setHintsAction = gui->getGuiActions("actionShow_Sat ellite_Hints");
Q_ASSERT(setHintsAction); Q_ASSERT(setHintsAction);
setHintsAction->setChecked(true); setHintsAction->setChecked(true);
} }
//TODO: We need to find a way to deal with duplicates... --BM StelObjectP obj = qSharedPointerDynamicCast<StelObject>(sat);
if (StelApp::getInstance().getStelObjectMgr().findAndSelect(item->te StelObjectMgr& objectMgr = StelApp::getInstance().getStelObjectMgr()
xt())) ;
if (objectMgr.setSelectedObject(obj))
{ {
GETSTELMODULE(StelMovementMgr)->autoZoomIn(); GETSTELMODULE(StelMovementMgr)->autoZoomIn();
GETSTELMODULE(StelMovementMgr)->setFlagTracking(true); GETSTELMODULE(StelMovementMgr)->setFlagTracking(true);
} }
} }
void SatellitesDialog::setOrbitParams(void) void SatellitesDialog::setOrbitParams(void)
{ {
Satellite::orbitLineSegments = ui->orbitSegmentsSpin->value(); Satellite::orbitLineSegments = ui->orbitSegmentsSpin->value();
Satellite::orbitLineFadeSegments = ui->orbitFadeSpin->value(); Satellite::orbitLineFadeSegments = ui->orbitFadeSpin->value();
 End of changes. 38 change blocks. 
69 lines changed or deleted 116 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/