BookmarksDialog.cpp   BookmarksDialog.cpp 
skipping to change at line 29 skipping to change at line 29
#include "StelApp.hpp" #include "StelApp.hpp"
#include "StelCore.hpp" #include "StelCore.hpp"
#include "StelModuleMgr.hpp" #include "StelModuleMgr.hpp"
#include "StelMovementMgr.hpp" #include "StelMovementMgr.hpp"
#include "StelObjectMgr.hpp" #include "StelObjectMgr.hpp"
#include "StelUtils.hpp" #include "StelUtils.hpp"
#include "StelTranslator.hpp" #include "StelTranslator.hpp"
#include "StelLocaleMgr.hpp" #include "StelLocaleMgr.hpp"
#include "StelLocation.hpp" #include "StelLocation.hpp"
#include "StelLocationMgr.hpp" #include "StelLocationMgr.hpp"
#include "CustomObjectMgr.hpp"
#include "StelFileMgr.hpp" #include "StelFileMgr.hpp"
#include "StelJsonParser.hpp" #include "StelJsonParser.hpp"
#include "AngleSpinBox.hpp" #include "AngleSpinBox.hpp"
#include "NebulaMgr.hpp" #include "NebulaMgr.hpp"
#include <QFileDialog>
#include <QDir>
#include "BookmarksDialog.hpp" #include "BookmarksDialog.hpp"
#include "ui_bookmarksDialog.h" #include "ui_bookmarksDialog.h"
BookmarksDialog::BookmarksDialog(QObject *parent) BookmarksDialog::BookmarksDialog(QObject *parent)
: StelDialog("Bookmarks", parent) : StelDialog("Bookmarks", parent)
{ {
ui = new Ui_bookmarksDialogForm; ui = new Ui_bookmarksDialogForm;
core = StelApp::getInstance().getCore(); core = StelApp::getInstance().getCore();
objectMgr = GETSTELMODULE(StelObjectMgr); objectMgr = GETSTELMODULE(StelObjectMgr);
bookmarksListModel = new QStandardItemModel(0, ColumnCount); bookmarksListModel = new QStandardItemModel(0, ColumnCount);
skipping to change at line 82 skipping to change at line 86
connect(&StelApp::getInstance(), SIGNAL(languageChanged()), this, SL OT(retranslate())); connect(&StelApp::getInstance(), SIGNAL(languageChanged()), this, SL OT(retranslate()));
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->TitleBar, SIGNAL(movedTo(QPoint)), this, SLOT(handleMove dTo(QPoint)));
connect(ui->addBookmarkButton, SIGNAL(clicked()), this, SLOT(addBook markButtonPressed())); connect(ui->addBookmarkButton, SIGNAL(clicked()), this, SLOT(addBook markButtonPressed()));
connect(ui->removeBookmarkButton, SIGNAL(clicked()), this, SLOT(remo veBookmarkButtonPressed())); connect(ui->removeBookmarkButton, SIGNAL(clicked()), this, SLOT(remo veBookmarkButtonPressed()));
connect(ui->goToButton, SIGNAL(clicked()), this, SLOT(goToBookmarkBu ttonPressed())); connect(ui->goToButton, SIGNAL(clicked()), this, SLOT(goToBookmarkBu ttonPressed()));
connect(ui->clearBookmarksButton, SIGNAL(clicked()), this, SLOT(clea rBookmarksButtonPressed())); connect(ui->clearBookmarksButton, SIGNAL(clicked()), this, SLOT(clea rBookmarksButtonPressed()));
connect(ui->bookmarksTreeView, SIGNAL(doubleClicked(QModelIndex)), t his, SLOT(selectCurrentBookmark(QModelIndex))); connect(ui->bookmarksTreeView, SIGNAL(doubleClicked(QModelIndex)), t his, SLOT(selectCurrentBookmark(QModelIndex)));
connect(ui->importBookmarksButton, SIGNAL(clicked()), this, SLOT(imp
ortBookmarks()));
connect(ui->exportBookmarksButton, SIGNAL(clicked()), this, SLOT(exp
ortBookmarks()));
//Initializing the list of bookmarks //Initializing the list of bookmarks
bookmarksListModel->setColumnCount(ColumnCount); bookmarksListModel->setColumnCount(ColumnCount);
setBookmarksHeaderNames(); setBookmarksHeaderNames();
ui->bookmarksTreeView->setModel(bookmarksListModel); ui->bookmarksTreeView->setModel(bookmarksListModel);
ui->bookmarksTreeView->header()->setSectionsMovable(false); ui->bookmarksTreeView->header()->setSectionsMovable(false);
ui->bookmarksTreeView->header()->setSectionResizeMode(ColumnName, QH eaderView::ResizeToContents); ui->bookmarksTreeView->header()->setSectionResizeMode(ColumnName, QH eaderView::ResizeToContents);
ui->bookmarksTreeView->header()->setStretchLastSection(true); ui->bookmarksTreeView->header()->setStretchLastSection(true);
ui->bookmarksTreeView->hideColumn(ColumnUUID); ui->bookmarksTreeView->hideColumn(ColumnUUID);
skipping to change at line 109 skipping to change at line 116
headerStrings << q_("Object"); headerStrings << q_("Object");
headerStrings << q_("Localized name"); headerStrings << q_("Localized name");
headerStrings << q_("Date and Time"); headerStrings << q_("Date and Time");
headerStrings << q_("Location of observer"); headerStrings << q_("Location of observer");
bookmarksListModel->setHorizontalHeaderLabels(headerStrings); bookmarksListModel->setHorizontalHeaderLabels(headerStrings);
} }
void BookmarksDialog::addModelRow(int number, QString uuid, QString name, Q String nameI18n, QString Date, QString Location) void BookmarksDialog::addModelRow(int number, QString uuid, QString name, Q String nameI18n, QString Date, QString Location)
{ {
QStandardItem* tempItem = 0; QStandardItem* tempItem = Q_NULLPTR;
tempItem = new QStandardItem(uuid); tempItem = new QStandardItem(uuid);
tempItem->setEditable(false); tempItem->setEditable(false);
bookmarksListModel->setItem(number, ColumnUUID, tempItem); bookmarksListModel->setItem(number, ColumnUUID, tempItem);
tempItem = new QStandardItem(name); tempItem = new QStandardItem(name);
tempItem->setEditable(false); tempItem->setEditable(false);
bookmarksListModel->setItem(number, ColumnName, tempItem); bookmarksListModel->setItem(number, ColumnName, tempItem);
tempItem = new QStandardItem(nameI18n); tempItem = new QStandardItem(nameI18n);
skipping to change at line 147 skipping to change at line 154
void BookmarksDialog::addBookmarkButtonPressed() void BookmarksDialog::addBookmarkButtonPressed()
{ {
const QList<StelObjectP>& selected = objectMgr->getSelectedObject(); const QList<StelObjectP>& selected = objectMgr->getSelectedObject();
if (!selected.isEmpty()) if (!selected.isEmpty())
{ {
QString name = selected[0]->getEnglishName(); QString name = selected[0]->getEnglishName();
QString nameI18n = selected[0]->getNameI18n(); QString nameI18n = selected[0]->getNameI18n();
if (selected[0]->getType()=="Nebula") if (selected[0]->getType()=="Nebula")
name = GETSTELMODULE(NebulaMgr)->getLatestSelectedDS ODesignation(); name = GETSTELMODULE(NebulaMgr)->getLatestSelectedDS ODesignation();
if (!name.isEmpty()) // Don't allow adding objects without n QString raStr = "", decStr = "";
ame! bool visibleFlag = false;
if (selected[0]->getType()=="CustomObject")
{ {
bool dateTimeFlag = ui->dateTimeCheckBox->isChecked( if (name.isEmpty())
);
bool locationFlag = ui->locationCheckBox->isChecked(
);
QString JDs = "";
double JD = -1.;
if (dateTimeFlag)
{ {
JD = core->getJD(); name = "Unnamed object";
JDs = StelUtils::julianDayToISO8601String(JD nameI18n = q_("Unnamed object");
+ core->getUTCOffset(JD)/24.).replace("T", " ");
} }
float ra, dec;
StelUtils::rectToSphe(&ra, &dec, selected[0]->getJ20
00EquatorialPos(core));
raStr = StelUtils::radToHmsStr(ra, false);
decStr = StelUtils::radToDmsStr(dec, false);
if (name.contains("marker", Qt::CaseInsensitive))
visibleFlag = true;
}
QString Location = ""; bool dateTimeFlag = ui->dateTimeCheckBox->isChecked();
if (locationFlag) bool locationFlag = ui->locationCheckBox->isChecked();
{
StelLocation loc = core->getCurrentLocation( QString JDs = "";
); double JD = -1.;
if (loc.name.isEmpty())
Location = QString("%1, %2").arg(loc if (dateTimeFlag)
.latitude).arg(loc.longitude); {
else JD = core->getJD();
Location = QString("%1, %2").arg(loc JDs = StelUtils::julianDayToISO8601String(JD + core-
.name).arg(loc.country); >getUTCOffset(JD)/24.).replace("T", " ");
} }
int lastRow = bookmarksListModel->rowCount(); QString Location = "";
if (locationFlag)
{
StelLocation loc = core->getCurrentLocation();
if (loc.name.isEmpty())
Location = QString("%1, %2").arg(loc.latitud
e).arg(loc.longitude);
else
Location = QString("%1, %2").arg(loc.name).a
rg(loc.country);
}
QString uuid = QUuid::createUuid().toString(); int lastRow = bookmarksListModel->rowCount();
addModelRow(lastRow, uuid, name, nameI18n, JDs, Loca
tion);
bookmark bm; QString uuid = QUuid::createUuid().toString();
bm.name = name; addModelRow(lastRow, uuid, name, nameI18n, JDs, Location);
if (!nameI18n.isEmpty())
bm.nameI18n = nameI18n;
if (!JDs.isEmpty())
bm.jd = QString::number(JD, 'f', 6);
if (!Location.isEmpty())
bm.location = Location;
bookmarksCollection.insert(uuid, bm); bookmark bm;
bm.name = name;
if (!nameI18n.isEmpty())
bm.nameI18n = nameI18n;
if (!raStr.isEmpty())
bm.ra = raStr;
if (!decStr.isEmpty())
bm.dec = decStr;
if (!JDs.isEmpty())
bm.jd = QString::number(JD, 'f', 6);
if (!Location.isEmpty())
bm.location = Location;
if (!visibleFlag)
bm.isVisibleMarker = visibleFlag;
saveBookmarks(); bookmarksCollection.insert(uuid, bm);
}
saveBookmarks();
} }
} }
void BookmarksDialog::removeBookmarkButtonPressed() void BookmarksDialog::removeBookmarkButtonPressed()
{ {
int number = ui->bookmarksTreeView->currentIndex().row(); int number = ui->bookmarksTreeView->currentIndex().row();
QString uuid = bookmarksListModel->index(number, ColumnUUID).data(). toString(); QString uuid = bookmarksListModel->index(number, ColumnUUID).data(). toString();
bookmarksListModel->removeRow(number); bookmarksListModel->removeRow(number);
bookmarksCollection.remove(uuid); bookmarksCollection.remove(uuid);
saveBookmarks(); saveBookmarks();
skipping to change at line 235 skipping to change at line 262
if (!bm.jd.isEmpty()) if (!bm.jd.isEmpty())
{ {
core->setJD(bm.jd.toDouble()); core->setJD(bm.jd.toDouble());
} }
if (!bm.location.isEmpty()) if (!bm.location.isEmpty())
{ {
StelLocationMgr* locationMgr = &StelApp::getInstance ().getLocationMgr(); StelLocationMgr* locationMgr = &StelApp::getInstance ().getLocationMgr();
core->moveObserverTo(locationMgr->locationForString( bm.location)); core->moveObserverTo(locationMgr->locationForString( bm.location));
} }
StelMovementMgr* mvmgr = GETSTELMODULE(StelMovementMgr);
objectMgr->unSelect(); objectMgr->unSelect();
if (objectMgr->findAndSelect(bm.name)) bool status = objectMgr->findAndSelect(bm.name);
if (!bm.ra.isEmpty() && !bm.dec.isEmpty() && !status)
{
Vec3d pos;
StelUtils::spheToRect(StelUtils::getDecAngle(bm.ra.t
rimmed()), StelUtils::getDecAngle(bm.dec.trimmed()), pos);
// Add a custom object on the sky
GETSTELMODULE(CustomObjectMgr)->addCustomObject(bm.n
ame, pos, bm.isVisibleMarker);
status = objectMgr->findAndSelect(bm.name);
}
if (status)
{ {
const QList<StelObjectP> newSelected = objectMgr->ge tSelectedObject(); const QList<StelObjectP> newSelected = objectMgr->ge tSelectedObject();
if (!newSelected.empty()) if (!newSelected.empty())
{ {
StelMovementMgr* mvmgr = GETSTELMODULE(StelM ovementMgr);
mvmgr->moveToObject(newSelected[0], mvmgr->g etAutoMoveDuration()); mvmgr->moveToObject(newSelected[0], mvmgr->g etAutoMoveDuration());
mvmgr->setFlagTracking(true); mvmgr->setFlagTracking(true);
} }
} }
} }
} }
void BookmarksDialog::loadBookmarks() void BookmarksDialog::loadBookmarks()
{ {
QVariantMap map; QVariantMap map;
skipping to change at line 284 skipping to change at line 321
bm.nameI18n = nameI18n; bm.nameI18n = nameI18n;
QString JD = bookmarkData.value("jd").toString(); QString JD = bookmarkData.value("jd").toString();
if (!JD.isEmpty()) if (!JD.isEmpty())
{ {
bm.jd = JD; bm.jd = JD;
JDs = StelUtils::julianDayToISO8601String(JD.toDoubl e() + core->getUTCOffset(JD.toDouble())/24.).replace("T", " "); JDs = StelUtils::julianDayToISO8601String(JD.toDoubl e() + core->getUTCOffset(JD.toDouble())/24.).replace("T", " ");
} }
QString Location = bookmarkData.value("location").toString() ; QString Location = bookmarkData.value("location").toString() ;
if (!Location.isEmpty()) if (!Location.isEmpty())
bm.location = Location; bm.location = Location;
QString RA = bookmarkData.value("ra").toString();
if (!RA.isEmpty())
bm.ra = RA;
QString Dec = bookmarkData.value("dec").toString();
if (!Dec.isEmpty())
bm.dec = Dec;
bm.isVisibleMarker = bookmarkData.value("isVisibleMarker", f
alse).toBool();
bookmarksCollection.insert(bookmarkKey, bm); bookmarksCollection.insert(bookmarkKey, bm);
addModelRow(i, bookmarkKey, bm.name, bm.nameI18n, JDs, Locat ion); addModelRow(i, bookmarkKey, bm.name, bm.nameI18n, JDs, Locat ion);
i++; i++;
} }
} }
void BookmarksDialog::importBookmarks()
{
QString originalBookmarksFile = bookmarksJsonPath;
QString filter = "JSON (*.json)";
bookmarksJsonPath = QFileDialog::getOpenFileName(0, q_("Import bookm
arks"), QDir::homePath(), filter);
loadBookmarks();
bookmarksJsonPath = originalBookmarksFile;
saveBookmarks();
}
void BookmarksDialog::exportBookmarks()
{
QString originalBookmarksFile = bookmarksJsonPath;
QString filter = "JSON (*.json)";
bookmarksJsonPath = QFileDialog::getSaveFileName(0, q_("Export bookm
arks as..."), QDir::homePath() + "/bookmarks.json", filter);
saveBookmarks();
bookmarksJsonPath = originalBookmarksFile;
}
void BookmarksDialog::saveBookmarks() void BookmarksDialog::saveBookmarks()
{ {
if (bookmarksJsonPath.isEmpty()) if (bookmarksJsonPath.isEmpty())
{ {
qWarning() << "Bookmarks: Error saving bookmarks"; qWarning() << "Bookmarks: Error saving bookmarks";
return; return;
} }
QFile jsonFile(bookmarksJsonPath); QFile jsonFile(bookmarksJsonPath);
if(!jsonFile.open(QFile::WriteOnly|QFile::Text)) if(!jsonFile.open(QFile::WriteOnly|QFile::Text))
{ {
skipping to change at line 317 skipping to change at line 387
QHashIterator<QString, bookmark> i(bookmarksCollection); QHashIterator<QString, bookmark> i(bookmarksCollection);
while (i.hasNext()) while (i.hasNext())
{ {
i.next(); i.next();
bookmark sp = i.value(); bookmark sp = i.value();
QVariantMap bm; QVariantMap bm;
bm.insert("name", sp.name); bm.insert("name", sp.name);
if (!sp.nameI18n.isEmpty()) if (!sp.nameI18n.isEmpty())
bm.insert("nameI18n", sp.nameI18n); bm.insert("nameI18n", sp.nameI18n);
if (!sp.ra.isEmpty())
bm.insert("ra", sp.ra);
if (!sp.dec.isEmpty())
bm.insert("dec", sp.dec);
if (!sp.jd.isEmpty()) if (!sp.jd.isEmpty())
bm.insert("jd", sp.jd); bm.insert("jd", sp.jd);
if (!sp.location.isEmpty()) if (!sp.location.isEmpty())
bm.insert("location", sp.location); bm.insert("location", sp.location);
if (sp.isVisibleMarker)
bm.insert("isVisibleMarker", sp.isVisibleMarker);
bookmarksDataList.insert(i.key(), bm); bookmarksDataList.insert(i.key(), bm);
} }
QVariantMap bmList; QVariantMap bmList;
bmList.insert("bookmarks", bookmarksDataList); bmList.insert("bookmarks", bookmarksDataList);
//Convert the tree to JSON //Convert the tree to JSON
StelJsonParser::write(bmList, &jsonFile); StelJsonParser::write(bmList, &jsonFile);
jsonFile.flush(); jsonFile.flush();
 End of changes. 21 change blocks. 
44 lines changed or deleted 123 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/